@Test
  public void testResourceFiltersWithCustomActions() throws Exception, AuthorizationException {
    String cluster1 = getUniqueName();
    final String host1 = getUniqueName();
    final String host2 = getUniqueName();
    final String host3 = getUniqueName();

    setupClusterWithHosts(cluster1, "HDP-2.0.6",
      new ArrayList<String>() {{
        add(host1);
        add(host2);
        add(host3);
      }},
      "centos6");

    Cluster cluster = clusters.getCluster(cluster1);
    cluster.setDesiredStackVersion(new StackId("HDP-2.0.6"));
    cluster.setCurrentStackVersion(new StackId("HDP-2.0.6"));

    RepositoryVersionEntity repositoryVersion = repositoryVersion206;

    ConfigFactory cf = injector.getInstance(ConfigFactory.class);
    cf.createNew(cluster, "global", "version1",
      new HashMap<String, String>() {{
        put("key1", "value1");
      }}, new HashMap<>());

    cf.createNew(cluster, "core-site", "version1",
      new HashMap<String, String>() {{
        put("key1", "value1");
      }}, new HashMap<>());

    Service hdfs = cluster.addService("HDFS", repositoryVersion);
    Service mapred = cluster.addService("YARN", repositoryVersion);

    hdfs.addServiceComponent(Role.HDFS_CLIENT.name());
    hdfs.addServiceComponent(Role.NAMENODE.name());
    hdfs.addServiceComponent(Role.DATANODE.name());

    mapred.addServiceComponent(Role.RESOURCEMANAGER.name());

    hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost(host1);
    hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(host1);
    hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(host1);
    hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(host2);

    String action1 = getUniqueName();

    controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition(
      action1, ActionType.SYSTEM, "", "HDFS", "", "Some custom action.",
      TargetHostType.ALL, Integer.valueOf("10010"), null));

    Map<String, String> params = new HashMap<String, String>() {{
      put("test", "test");
    }};

    Map<String, String> requestProperties = new HashMap<>();
    requestProperties.put(REQUEST_CONTEXT_PROPERTY, "Called from a test");

    List<RequestResourceFilter> resourceFilters = new ArrayList<>();
    ArrayList<String> hosts = new ArrayList<String>() {{ add(host2); }};
    RequestResourceFilter resourceFilter1 = new RequestResourceFilter("HDFS", "DATANODE", hosts);

    hosts = new ArrayList<String>() {{ add(host1); }};
    RequestResourceFilter resourceFilter2 = new RequestResourceFilter("HDFS", "NAMENODE", hosts);

    resourceFilters.add(resourceFilter1);
    resourceFilters.add(resourceFilter2);

    ExecuteActionRequest actionRequest = new ExecuteActionRequest(cluster1, null, action1, resourceFilters, null, params, false);
    RequestStatusResponse response = null;
    try {
      controller.createAction(actionRequest, requestProperties);
    } catch (Exception ae) {
      LOG.info("Expected exception.", ae);
      Assert.assertTrue(ae.getMessage().contains("Custom action definition only " +
        "allows one resource filter to be specified"));
    }
    resourceFilters.remove(resourceFilter1);
    actionRequest = new ExecuteActionRequest(cluster1, null, action1, resourceFilters, null, params, false);
    response = controller.createAction(actionRequest, requestProperties);

    assertEquals(1, response.getTasks().size());
    HostRoleCommand nnCommand = null;

    for (HostRoleCommand hrc : actionDB.getRequestTasks(response.getRequestId())) {
      if (hrc.getHostName().equals(host1)) {
        nnCommand = hrc;
      }
    }

    Assert.assertNotNull(nnCommand);
    ExecutionCommand cmd = nnCommand.getExecutionCommandWrapper().getExecutionCommand();
    Assert.assertEquals(action1, cmd.getRole());
    Assert.assertEquals("10010", cmd.getCommandParams().get("command_timeout"));
    Type type = new TypeToken<Map<String, String>>(){}.getType();
    for (Stage stage : actionDB.getAllStages(response.getRequestId())){
      Map<String, String> commandParamsStage = StageUtils.getGson().fromJson(stage.getCommandParamsStage(), type);
      Assert.assertTrue(commandParamsStage.containsKey("test"));
    }
    Assert.assertEquals(requestProperties.get(REQUEST_CONTEXT_PROPERTY), response.getRequestContext());
  }
Create a cluster with a service, and verify that the request tasks have the correct output log and error log paths.
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java