@Test
  @Ignore
  //TODO this test becomes unstable after this patch, not reproducible locally but fails in apache jenkins jobs
  //investigate and reenable
  public void testGetExecutionCommandWithClusterEnvForRetry() throws Exception {
    String cluster1 = getUniqueName();
    createCluster(cluster1);
    Cluster cluster = clusters.getCluster(cluster1);
    clusters.getCluster(cluster1)
        .setDesiredStackVersion(new StackId("HDP-0.1"));
    String serviceName = "HDFS";
    createService(cluster1, serviceName, null);
    String componentName1 = "NAMENODE";
    String componentName2 = "DATANODE";
    String componentName3 = "HDFS_CLIENT";
    createServiceComponent(cluster1, serviceName, componentName1,
                           State.INIT);
    createServiceComponent(cluster1, serviceName, componentName2,
                           State.INIT);
    createServiceComponent(cluster1, serviceName, componentName3,
                           State.INIT);

    String host1 = getUniqueName();
    String host2 = getUniqueName();

    addHostToCluster(host1, cluster1);
    addHostToCluster(host2, cluster1);

    Map<String, String> configs = new HashMap<>();
    configs.put("a", "b");
    configs.put("command_retry_enabled", "true");
    configs.put("command_retry_max_time_in_sec", "5");
    configs.put("commands_to_retry", "INSTALL");

    ConfigurationRequest cr1;
    cr1 = new ConfigurationRequest(cluster1, "cluster-env","version1",
                                   configs, null);

    ClusterRequest crReq = new ClusterRequest(cluster.getClusterId(), cluster1, null, null);
    crReq.setDesiredConfig(Collections.singletonList(cr1));
    controller.updateClusters(Collections.singleton(crReq), null);

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

    createServiceComponentHost(cluster1, serviceName, componentName2,
                               host1, null);
    createServiceComponentHost(cluster1, serviceName, componentName2,
                               host2, null);
    createServiceComponentHost(cluster1, serviceName, componentName3,
                               host1, null);
    createServiceComponentHost(cluster1, serviceName, componentName3,
                               host2, null);

    // issue an install command, expect retry is enabled
    ServiceComponentHostRequest
        schr =
        new ServiceComponentHostRequest(cluster1, "HDFS", "DATANODE", host2, "INSTALLED");
    Map<String, String> requestProps = new HashMap<>();
    requestProps.put("phase", "INITIAL_INSTALL");
    RequestStatusResponse rsr = updateHostComponents(Collections.singleton(schr), requestProps, false);

    List<Stage> stages = actionDB.getAllStages(rsr.getRequestId());
    Assert.assertEquals(1, stages.size());
    Stage stage = stages.iterator().next();
    List<ExecutionCommandWrapper> execWrappers = stage.getExecutionCommands(host2);
    Assert.assertEquals(1, execWrappers.size());
    ExecutionCommandWrapper execWrapper = execWrappers.iterator().next();
    ExecutionCommand ec = execWrapper.getExecutionCommand();
    Map<String, Map<String, String>> configurations = ec.getConfigurations();
    assertNotNull(configurations);
    assertEquals(1, configurations.size());
    assertTrue(configurations.containsKey("cluster-env"));
    assertTrue(ec.getCommandParams().containsKey("max_duration_for_retries"));
    assertEquals("5", ec.getCommandParams().get("max_duration_for_retries"));
    assertTrue(ec.getCommandParams().containsKey("command_retry_enabled"));
    assertEquals("true", ec.getCommandParams().get("command_retry_enabled"));

    for (ServiceComponentHost sch : clusters.getCluster(cluster1).getServiceComponentHosts(host2)) {
      sch.setState(State.INSTALLED);
    }

    // issue an start command but no retry as phase is only INITIAL_INSTALL
    schr = new ServiceComponentHostRequest(cluster1, "HDFS", "DATANODE", host2, "STARTED");
    rsr = updateHostComponents(Collections.singleton(schr), requestProps, false);
    stages = actionDB.getAllStages(rsr.getRequestId());
    Assert.assertEquals(1, stages.size());
    stage = stages.iterator().next();
    execWrappers = stage.getExecutionCommands(host2);
    Assert.assertEquals(1, execWrappers.size());
    execWrapper = execWrappers.iterator().next();
    ec = execWrapper.getExecutionCommand();
    configurations = ec.getConfigurations();
    assertNotNull(configurations);
    assertEquals(1, configurations.size());
    assertTrue(configurations.containsKey("cluster-env"));
    assertTrue(ec.getCommandParams().containsKey("max_duration_for_retries"));
    assertEquals("5", ec.getCommandParams().get("max_duration_for_retries"));
    assertTrue(ec.getCommandParams().containsKey("command_retry_enabled"));
    assertEquals("false", ec.getCommandParams().get("command_retry_enabled"));

    configs.put("command_retry_enabled", "true");
    configs.put("command_retry_max_time_in_sec", "12");
    configs.put("commands_to_retry", "START");

    cr1 = new ConfigurationRequest(cluster1, "cluster-env","version2",
                                   configs, null);
    crReq = new ClusterRequest(cluster.getClusterId(), cluster1, null, null);
    crReq.setDesiredConfig(Collections.singletonList(cr1));
    controller.updateClusters(Collections.singleton(crReq), null);

    // issue an start command and retry is expected
    requestProps.put("phase", "INITIAL_START");
    schr = new ServiceComponentHostRequest(cluster1, "HDFS", "DATANODE", host2, "STARTED");
    rsr = updateHostComponents(Collections.singleton(schr), requestProps, false);
    stages = actionDB.getAllStages(rsr.getRequestId());
    Assert.assertEquals(1, stages.size());
    stage = stages.iterator().next();
    execWrappers = stage.getExecutionCommands(host2);
    Assert.assertEquals(1, execWrappers.size());
    execWrapper = execWrappers.iterator().next();
    ec = execWrapper.getExecutionCommand();
    configurations = ec.getConfigurations();
    assertNotNull(configurations);
    assertEquals(1, configurations.size());
    assertTrue(configurations.containsKey("cluster-env"));
    assertTrue(ec.getCommandParams().containsKey("max_duration_for_retries"));
    assertEquals("12", ec.getCommandParams().get("max_duration_for_retries"));
    assertTrue(ec.getCommandParams().containsKey("command_retry_enabled"));
    assertEquals("true", ec.getCommandParams().get("command_retry_enabled"));

    // issue an start command and retry is expected but bad cluster-env
    configs.put("command_retry_enabled", "asdf");
    configs.put("command_retry_max_time_in_sec", "-5");
    configs.put("commands_to_retry2", "START");

    cr1 = new ConfigurationRequest(cluster1, "cluster-env","version3",
                                   configs, null);
    crReq = new ClusterRequest(cluster.getClusterId(), cluster1, null, null);
    crReq.setDesiredConfig(Collections.singletonList(cr1));
    controller.updateClusters(Collections.singleton(crReq), null);

    requestProps.put("phase", "INITIAL_START");
    schr = new ServiceComponentHostRequest(cluster1, "HDFS", "DATANODE", host2, "STARTED");
    rsr = updateHostComponents(Collections.singleton(schr), requestProps, false);
    stages = actionDB.getAllStages(rsr.getRequestId());
    Assert.assertEquals(1, stages.size());
    stage = stages.iterator().next();
    execWrappers = stage.getExecutionCommands(host2);
    Assert.assertEquals(1, execWrappers.size());
    execWrapper = execWrappers.iterator().next();
    ec = execWrapper.getExecutionCommand();
    configurations = ec.getConfigurations();
    assertNotNull(configurations);
    assertEquals(1, configurations.size());
    assertTrue(configurations.containsKey("cluster-env"));
    assertTrue(ec.getCommandParams().containsKey("max_duration_for_retries"));
    assertEquals("0", ec.getCommandParams().get("max_duration_for_retries"));
    assertTrue(ec.getCommandParams().containsKey("command_retry_enabled"));
    assertEquals("false", ec.getCommandParams().get("command_retry_enabled"));
  }
Allows to set maintenanceStateHelper. For use when there is anything to test
with maintenance mode.
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java