@Test
  public void testResourceFiltersWithCustomCommands() 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);
    Config config1 = cf.createNew(cluster, "global", "version1",
      new HashMap<String, String>() {{
        put("key1", "value1");
      }}, new HashMap<>());

    Config config2 = 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);

    mapred.getServiceComponent(Role.RESOURCEMANAGER.name()).addServiceComponentHost(host2);

    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");
    requestProperties.put("command_retry_enabled", "true");
    requestProperties.put("log_output", "false");

    // Test multiple restarts
    List<RequestResourceFilter> resourceFilters = new ArrayList<>();
    RequestResourceFilter resourceFilter = new RequestResourceFilter("HDFS",
      Role.DATANODE.name(), new ArrayList<String>() {{ add(host1); add(host2); }});
    resourceFilters.add(resourceFilter);
    resourceFilter = new RequestResourceFilter("YARN",
      Role.RESOURCEMANAGER.name(), new ArrayList<String>() {{ add(host2); }});
    resourceFilters.add(resourceFilter);

    ExecuteActionRequest request = new ExecuteActionRequest(cluster1, "RESTART", null, resourceFilters, null, params, false);

    RequestStatusResponse response = controller.createAction(request, requestProperties);
    Assert.assertEquals(3, response.getTasks().size());
    List<HostRoleCommand> storedTasks = actionDB.getRequestTasks(response.getRequestId());

    Assert.assertNotNull(storedTasks);
    int expectedRestartCount = 0;
    for (HostRoleCommand hrc : storedTasks) {
      Assert.assertEquals("RESTART", hrc.getCustomCommandName());

      Map<String, String> cParams = hrc.getExecutionCommandWrapper().getExecutionCommand().getCommandParams();
      Assert.assertEquals("Expect retry to be set", true, cParams.containsKey("command_retry_enabled"));
      Assert.assertEquals("Expect max duration to be set", true, cParams.containsKey("max_duration_for_retries"));
      Assert.assertEquals("Expect max duration to be 600", "600", cParams.get("max_duration_for_retries"));
      Assert.assertEquals("Expect retry to be true", "true", cParams.get("command_retry_enabled"));
      Assert.assertEquals("Expect log_output to be set", true, cParams.containsKey("log_output"));
      Assert.assertEquals("Expect log_output to be false", "false", cParams.get("log_output"));

      if (hrc.getHostName().equals(host1) && hrc.getRole().equals(Role.DATANODE)) {
        expectedRestartCount++;
      } else if(hrc.getHostName().equals(host2)) {
        if (hrc.getRole().equals(Role.DATANODE)) {
          expectedRestartCount++;
        } else if (hrc.getRole().equals(Role.RESOURCEMANAGER)) {
          expectedRestartCount++;
        }
      }
    }

    Assert.assertEquals("Restart 2 datanodes and 1 Resourcemanager.", 3,
        expectedRestartCount);
    Assert.assertEquals(requestProperties.get(REQUEST_CONTEXT_PROPERTY), response.getRequestContext());

    requestProperties.put("max_duration_for_retries", "423");
    response = controller.createAction(request, requestProperties);
    Assert.assertEquals(3, response.getTasks().size());
    storedTasks = actionDB.getRequestTasks(response.getRequestId());

    Assert.assertNotNull(storedTasks);
    for (HostRoleCommand hrc : storedTasks) {
      Assert.assertEquals("RESTART", hrc.getCustomCommandName());

      Map<String, String> cParams = hrc.getExecutionCommandWrapper().getExecutionCommand().getCommandParams();
      Assert.assertEquals("Expect retry to be set", true, cParams.containsKey("command_retry_enabled"));
      Assert.assertEquals("Expect max duration to be set", true, cParams.containsKey("max_duration_for_retries"));
      Assert.assertEquals("Expect max duration to be 423", "423", cParams.get("max_duration_for_retries"));
      Assert.assertEquals("Expect retry to be true", "true", cParams.get("command_retry_enabled"));
    }

    requestProperties.remove("max_duration_for_retries");
    requestProperties.remove("command_retry_enabled");
    response = controller.createAction(request, requestProperties);
    Assert.assertEquals(3, response.getTasks().size());
    storedTasks = actionDB.getRequestTasks(response.getRequestId());

    Assert.assertNotNull(storedTasks);
    for (HostRoleCommand hrc : storedTasks) {
      Assert.assertEquals("RESTART", hrc.getCustomCommandName());

      Map<String, String> cParams = hrc.getExecutionCommandWrapper().getExecutionCommand().getCommandParams();
      Assert.assertEquals("Expect retry to be set", false, cParams.containsKey("command_retry_enabled"));
      Assert.assertEquals("Expect max duration to be set", false, cParams.containsKey("max_duration_for_retries"));
    }

    // Test service checks - specific host
    resourceFilters.clear();
    resourceFilter = new RequestResourceFilter("HDFS", null,
      new ArrayList<String>() {{ add(host1); }});
    resourceFilters.add(resourceFilter);
    request = new ExecuteActionRequest(cluster1, Role.HDFS_SERVICE_CHECK.name(),
      null, resourceFilters, null, null, false);
    response = controller.createAction(request, requestProperties);

    Assert.assertEquals(1, response.getTasks().size());
    storedTasks = actionDB.getRequestTasks(response.getRequestId());
    Assert.assertNotNull(storedTasks);
    Assert.assertEquals(Role.HDFS_SERVICE_CHECK.name(),
        storedTasks.get(0).getRole().name());
    Assert.assertEquals(host1, storedTasks.get(0).getHostName());
    Assert.assertEquals(requestProperties.get(REQUEST_CONTEXT_PROPERTY), response.getRequestContext());

    Assert.assertEquals(State.STARTED, cluster.getService("HDFS").getServiceComponent(Role.DATANODE.name()).getServiceComponentHost(host1).getDesiredState());
    Assert.assertEquals(State.STARTED, cluster.getService("HDFS").getServiceComponent(Role.DATANODE.name()).getServiceComponentHost(host2).getDesiredState());
    Assert.assertEquals(State.STARTED, cluster.getService("YARN").getServiceComponent(Role.RESOURCEMANAGER.name()).getServiceComponentHost(host2).getDesiredState());
  }
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