@Test
  @Ignore
  public void testDisableAndDeleteStates() throws Exception {
    Map<String,String> mapRequestProps = new HashMap<>();

    String cluster1 = getUniqueName();

    AmbariManagementController amc = injector.getInstance(AmbariManagementController.class);
    Clusters clusters = injector.getInstance(Clusters.class);
    Gson gson = new Gson();

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

    clusters.addHost(host1);
    clusters.addHost(host2);
    clusters.addHost(host3);
    Host host = clusters.getHost("host1");
    setOsFamily(host, "redhat", "5.9");
    clusters.updateHostMappings(host);
    host = clusters.getHost("host2");
    setOsFamily(host, "redhat", "5.9");
    clusters.updateHostMappings(host);
    host = clusters.getHost("host3");
    setOsFamily(host, "redhat", "5.9");
    clusters.updateHostMappings(host);

    ClusterRequest clusterRequest = new ClusterRequest(null, cluster1, "HDP-1.2.0", null);
    amc.createCluster(clusterRequest);

    Set<ServiceRequest> serviceRequests = new HashSet<>();
    serviceRequests.add(new ServiceRequest(cluster1, "HDFS", repositoryVersion120.getId(), null));
    serviceRequests.add(new ServiceRequest(cluster1, "HIVE", repositoryVersion120.getId(), null));

    ServiceResourceProviderTest.createServices(amc, repositoryVersionDAO, serviceRequests);

    Type confType = new TypeToken<Map<String, String>>() {}.getType();

    ConfigurationRequest configurationRequest = new ConfigurationRequest(cluster1, "core-site", "version1",
        gson.fromJson("{ \"fs.default.name\" : \"localhost:8020\"}", confType), null);
    amc.createConfiguration(configurationRequest);

    configurationRequest = new ConfigurationRequest(cluster1, "hdfs-site", "version1",
        gson.fromJson("{ \"dfs.datanode.data.dir.perm\" : \"750\"}", confType), null);
    amc.createConfiguration(configurationRequest);

    configurationRequest = new ConfigurationRequest(cluster1, "global", "version1",
        gson.fromJson("{ \"hive.server2.enable.doAs\" : \"true\"}", confType), null);
    amc.createConfiguration(configurationRequest);

    Assert.assertTrue(clusters.getCluster(cluster1).getDesiredConfigs().containsKey("hive-site"));

    serviceRequests.clear();
    serviceRequests.add(new ServiceRequest(cluster1, "HDFS", repositoryVersion120.getId(), null));

    ServiceResourceProviderTest.updateServices(amc, serviceRequests, mapRequestProps, true, false);

    Set<ServiceComponentRequest> serviceComponentRequests = new HashSet<>();
    serviceComponentRequests.add(new ServiceComponentRequest(cluster1, "HDFS", "NAMENODE", null));
    serviceComponentRequests.add(new ServiceComponentRequest(cluster1, "HDFS", "SECONDARY_NAMENODE", null));
    serviceComponentRequests.add(new ServiceComponentRequest(cluster1, "HDFS", "DATANODE", null));
    serviceComponentRequests.add(new ServiceComponentRequest(cluster1, "HDFS", "HDFS_CLIENT", null));

    ComponentResourceProviderTest.createComponents(amc, serviceComponentRequests);

    Set<HostRequest> hostRequests = new HashSet<>();
    hostRequests.add(new HostRequest(host1, cluster1));
    hostRequests.add(new HostRequest(host2, cluster1));
    hostRequests.add(new HostRequest(host3, cluster1));

    HostResourceProviderTest.createHosts(amc, hostRequests);

    Set<ServiceComponentHostRequest> componentHostRequests = new HashSet<>();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "DATANODE", host1, null));
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "NAMENODE", host1, null));
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "SECONDARY_NAMENODE", host1, null));
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "DATANODE", host2, null));
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "DATANODE", host3, null));


    amc.createHostComponents(componentHostRequests);

    serviceRequests.clear();
    serviceRequests.add(new ServiceRequest(cluster1, "HDFS", repositoryVersion120.getId(), "INSTALLED"));
    ServiceResourceProviderTest.updateServices(amc, serviceRequests, mapRequestProps, true, false);

    Cluster cluster = clusters.getCluster(cluster1);
    Map<String, ServiceComponentHost> namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
    org.junit.Assert.assertEquals(1, namenodes.size());

    ServiceComponentHost componentHost = namenodes.get(host1);

    Map<String, ServiceComponentHost> hostComponents = cluster.getService("HDFS").getServiceComponent("DATANODE").getServiceComponentHosts();
    for (Map.Entry<String, ServiceComponentHost> entry : hostComponents.entrySet()) {
      ServiceComponentHost cHost = entry.getValue();
      cHost.handleEvent(new ServiceComponentHostInstallEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis(), "HDP-1.2.0"));
      cHost.handleEvent(new ServiceComponentHostOpSucceededEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis()));
    }
    hostComponents = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
    for (Map.Entry<String, ServiceComponentHost> entry : hostComponents.entrySet()) {
      ServiceComponentHost cHost = entry.getValue();
      cHost.handleEvent(new ServiceComponentHostInstallEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis(), "HDP-1.2.0"));
      cHost.handleEvent(new ServiceComponentHostOpSucceededEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis()));
    }
    hostComponents = cluster.getService("HDFS").getServiceComponent("SECONDARY_NAMENODE").getServiceComponentHosts();
    for (Map.Entry<String, ServiceComponentHost> entry : hostComponents.entrySet()) {
      ServiceComponentHost cHost = entry.getValue();
      cHost.handleEvent(new ServiceComponentHostInstallEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis(), "HDP-1.2.0"));
      cHost.handleEvent(new ServiceComponentHostOpSucceededEvent(cHost.getServiceComponentName(), cHost.getHostName(), System.currentTimeMillis()));
    }

    componentHostRequests.clear();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "NAMENODE", host1, "DISABLED"));

    updateHostComponents(amc, componentHostRequests, mapRequestProps, true);

    Assert.assertEquals(State.DISABLED, componentHost.getState());

    componentHostRequests.clear();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "NAMENODE", host1, "INSTALLED"));

    updateHostComponents(amc, componentHostRequests, mapRequestProps, true);

    Assert.assertEquals(State.INSTALLED, componentHost.getState());

    componentHostRequests.clear();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "NAMENODE", host1, "DISABLED"));

    updateHostComponents(amc, componentHostRequests, mapRequestProps, true);

    Assert.assertEquals(State.DISABLED, componentHost.getState());

    componentHostRequests.clear();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "NAMENODE", host2, null));

    amc.createHostComponents(componentHostRequests);

    componentHostRequests.clear();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "NAMENODE", host2, "INSTALLED"));

    updateHostComponents(amc, componentHostRequests, mapRequestProps, true);

    namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
    Assert.assertEquals(2, namenodes.size());

    componentHost = namenodes.get(host2);
    componentHost.handleEvent(new ServiceComponentHostInstallEvent(componentHost.getServiceComponentName(), componentHost.getHostName(), System.currentTimeMillis(), "HDP-1.2.0"));
    componentHost.handleEvent(new ServiceComponentHostOpSucceededEvent(componentHost.getServiceComponentName(), componentHost.getHostName(), System.currentTimeMillis()));

    serviceRequests.clear();
    serviceRequests.add(new ServiceRequest(cluster1, "HDFS", repositoryVersion120.getId(), "STARTED"));

    RequestStatusResponse response = ServiceResourceProviderTest.updateServices(amc, serviceRequests,
        mapRequestProps, true, false);
    for (ShortTaskStatus shortTaskStatus : response.getTasks()) {
      assertFalse(host1.equals(shortTaskStatus.getHostName()) && "NAMENODE".equals(shortTaskStatus.getRole()));
    }

    componentHostRequests.clear();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "NAMENODE", host1, null));

    amc.deleteHostComponents(componentHostRequests);

    namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
    org.junit.Assert.assertEquals(1, namenodes.size());

    // testing the behavior for runSmokeTest flag
    // piggybacking on this test to avoid setting up the mock cluster
    testRunSmokeTestFlag(mapRequestProps, amc, serviceRequests);

    // should be able to add the host component back
    componentHostRequests.clear();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "NAMENODE", host1, null));
    amc.createHostComponents(componentHostRequests);
    namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
    assertEquals(2, namenodes.size());

    // make INSTALLED again
    componentHost = namenodes.get(host1);
    componentHost.handleEvent(new ServiceComponentHostInstallEvent(componentHost.getServiceComponentName(), componentHost.getHostName(), System.currentTimeMillis(), "HDP-1.2.0"));
    componentHost.handleEvent(new ServiceComponentHostOpSucceededEvent(componentHost.getServiceComponentName(), componentHost.getHostName(), System.currentTimeMillis()));
    componentHostRequests.clear();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "NAMENODE", host1, "INSTALLED"));
    updateHostComponents(amc, componentHostRequests, mapRequestProps, true);
    assertEquals(State.INSTALLED, namenodes.get(host1).getState());

    // make unknown
    ServiceComponentHost sch = null;
    for (ServiceComponentHost tmp : cluster.getServiceComponentHosts(host2)) {
      if (tmp.getServiceComponentName().equals("DATANODE")) {
        tmp.setState(State.UNKNOWN);
        sch = tmp;
      }
    }
    assertNotNull(sch);

    // make disabled
    componentHostRequests.clear();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "DATANODE", host2, "DISABLED"));
    updateHostComponents(amc, componentHostRequests, mapRequestProps, false);
    org.junit.Assert.assertEquals(State.DISABLED, sch.getState());

    // State should not be changed if componentHostRequests are empty
    componentHostRequests.clear();
    mapRequestProps.put(RequestOperationLevel.OPERATION_CLUSTER_ID,cluster1);
    updateHostComponents(amc, componentHostRequests, mapRequestProps, false);
    org.junit.Assert.assertEquals(State.DISABLED, sch.getState());
    mapRequestProps.clear();

    // ServiceComponentHost remains in disabled after service stop
    assertEquals(sch.getServiceComponentName(),"DATANODE");
    serviceRequests.clear();
    serviceRequests.add(new ServiceRequest(cluster1, "HDFS", repositoryVersion120.getId(), "INSTALLED"));
    ServiceResourceProviderTest.updateServices(amc, serviceRequests,
      mapRequestProps, true, false);
    assertEquals(State.DISABLED, sch.getState());

    // ServiceComponentHost remains in disabled after service start
    serviceRequests.clear();
    serviceRequests.add(new ServiceRequest(cluster1, "HDFS", repositoryVersion120.getId(), "STARTED"));
    ServiceResourceProviderTest.updateServices(amc, serviceRequests,
      mapRequestProps, true, false);
    assertEquals(State.DISABLED, sch.getState());

    // confirm delete
    componentHostRequests.clear();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "DATANODE", host2, null));
    amc.deleteHostComponents(componentHostRequests);

    sch = null;
    for (ServiceComponentHost tmp : cluster.getServiceComponentHosts(host2)) {
      if (tmp.getServiceComponentName().equals("DATANODE")) {
        sch = tmp;
      }
    }
    org.junit.Assert.assertNull(sch);

    /*
    *Test remove service
    */
    serviceRequests.clear();
    serviceRequests.add(new ServiceRequest(cluster1, "HDFS", repositoryVersion120.getId(), "INSTALLED"));
    ServiceResourceProviderTest.updateServices(amc, serviceRequests, mapRequestProps, true, false);
    serviceRequests.clear();
    serviceRequests.add(new ServiceRequest(cluster1, null, null, null, null));
    org.junit.Assert.assertEquals(2, ServiceResourceProviderTest.getServices(amc, serviceRequests).size());
    serviceRequests.clear();
    serviceRequests.add(new ServiceRequest(cluster1, "HDFS", repositoryVersion120.getId(), null));
    serviceRequests.add(new ServiceRequest(cluster1, "HIVE", repositoryVersion120.getId(), null));
    ServiceResourceProviderTest.deleteServices(amc, serviceRequests);
    serviceRequests.clear();
    serviceRequests.add(new ServiceRequest(cluster1, null, null, null, null));
    org.junit.Assert.assertEquals(0, ServiceResourceProviderTest.getServices(amc, serviceRequests).size());

    /*
    *Test add service again
    */
    serviceRequests.clear();
    serviceRequests.add(new ServiceRequest(cluster1, "HDFS", repositoryVersion120.getId(), null));

    ServiceResourceProviderTest.createServices(amc, repositoryVersionDAO, serviceRequests);

    org.junit.Assert.assertEquals(1, ServiceResourceProviderTest.getServices(amc, serviceRequests).size());
    //Create new configs
    configurationRequest = new ConfigurationRequest(cluster1, "core-site", "version2",
        gson.fromJson("{ \"fs.default.name\" : \"localhost:8020\"}", confType), null);
    amc.createConfiguration(configurationRequest);
    configurationRequest = new ConfigurationRequest(cluster1, "hdfs-site", "version2",
        gson.fromJson("{ \"dfs.datanode.data.dir.perm\" : \"750\"}", confType), null);
    amc.createConfiguration(configurationRequest);
    configurationRequest = new ConfigurationRequest(cluster1, "global", "version2",
        gson.fromJson("{ \"hbase_hdfs_root_dir\" : \"/apps/hbase/\"}", confType), null);
    amc.createConfiguration(configurationRequest);
    //Add configs to service
    serviceRequests.clear();
    serviceRequests.add(new ServiceRequest(cluster1, "HDFS", repositoryVersion120.getId(), null));
    ServiceResourceProviderTest.updateServices(amc, serviceRequests, mapRequestProps, true, false);
    //Crate service components
    serviceComponentRequests = new HashSet<>();
    serviceComponentRequests.add(new ServiceComponentRequest(cluster1, "HDFS", "NAMENODE", null));
    serviceComponentRequests.add(new ServiceComponentRequest(cluster1, "HDFS", "SECONDARY_NAMENODE", null));
    serviceComponentRequests.add(new ServiceComponentRequest(cluster1, "HDFS", "DATANODE", null));
    serviceComponentRequests.add(new ServiceComponentRequest(cluster1, "HDFS", "HDFS_CLIENT", null));
    ComponentResourceProviderTest.createComponents(amc, serviceComponentRequests);

    //Create ServiceComponentHosts
    componentHostRequests = new HashSet<>();
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "DATANODE", "host1", null));
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "NAMENODE", "host1", null));
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "SECONDARY_NAMENODE", host1, null));
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "DATANODE", "host2", null));
    componentHostRequests.add(new ServiceComponentHostRequest(cluster1, null, "DATANODE", "host3", null));
    amc.createHostComponents(componentHostRequests);


    namenodes = cluster.getService("HDFS").getServiceComponent("NAMENODE").getServiceComponentHosts();
    org.junit.Assert.assertEquals(1, namenodes.size());
    Map<String, ServiceComponentHost> datanodes = cluster.getService("HDFS").getServiceComponent("DATANODE").getServiceComponentHosts();
    org.junit.Assert.assertEquals(3, datanodes.size());
    Map<String, ServiceComponentHost> namenodes2 = cluster.getService("HDFS").getServiceComponent("SECONDARY_NAMENODE").getServiceComponentHosts();
    org.junit.Assert.assertEquals(1, namenodes2.size());

  }
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