String CLUSTER_NAME = "c1";
String HOST1 = "h1";
String HOST2 = "h2";
try {
Clusters clusters = injector.getInstance(Clusters.class);
clusters.addHost(HOST1);
Host host = clusters.getHost(HOST1);
host.setOsType("centos6");
host.persist();
clusters.addHost(HOST2);
host = clusters.getHost(HOST2);
host.setOsType("centos6");
host.persist();
AmbariManagementController amc = injector.getInstance(AmbariManagementController.class);
ClusterRequest cr = new ClusterRequest(null, CLUSTER_NAME, STACK_ID, null);
amc.createCluster(cr);
ConfigurationRequest configRequest = new ConfigurationRequest(CLUSTER_NAME, "global", "version1",
new HashMap<String, String>() {{ put("a", "b"); }});
cr.setDesiredConfig(configRequest);
amc.updateClusters(Collections.singleton(cr), new HashMap<String, String>());
// add some hosts
Set<HostRequest> hrs = new HashSet<HostRequest>();
hrs.add(new HostRequest(HOST1, CLUSTER_NAME, null));
HostResourceProviderTest.createHosts(amc, hrs);
Set<ServiceRequest> serviceRequests = new HashSet<ServiceRequest>();
serviceRequests.add(new ServiceRequest(CLUSTER_NAME, "HDFS", null));
serviceRequests.add(new ServiceRequest(CLUSTER_NAME, "MAPREDUCE2", null));
serviceRequests.add(new ServiceRequest(CLUSTER_NAME, "YARN", null));
ServiceResourceProviderTest.createServices(amc, serviceRequests);
Set<ServiceComponentRequest> serviceComponentRequests = new HashSet<ServiceComponentRequest>();
serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "NAMENODE", null));
serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "SECONDARY_NAMENODE", null));
serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "DATANODE", null));
serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "MAPREDUCE2", "HISTORYSERVER", null));
serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "YARN", "RESOURCEMANAGER", null));
serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "YARN", "NODEMANAGER", null));
serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, "HDFS", "HDFS_CLIENT", null));
ComponentResourceProviderTest.createComponents(amc, serviceComponentRequests);
Set<ServiceComponentHostRequest> componentHostRequests = new HashSet<ServiceComponentHostRequest>();
componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "DATANODE", HOST1, null));
componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "NAMENODE", HOST1, null));
componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "SECONDARY_NAMENODE", HOST1, null));
componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "HISTORYSERVER", HOST1, null));
componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "RESOURCEMANAGER", HOST1, null));
componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "NODEMANAGER", HOST1, null));
componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, null, "HDFS_CLIENT", HOST1, null));
amc.createHostComponents(componentHostRequests);
RequestResourceFilter resourceFilter = new RequestResourceFilter("HDFS", null, null);
ExecuteActionRequest ar = new ExecuteActionRequest(CLUSTER_NAME, Role.HDFS_SERVICE_CHECK.name(), null);
ar.getResourceFilters().add(resourceFilter);
amc.createAction(ar, null);
// change mind, delete the cluster
amc.deleteCluster(cr);
assertNotNull(clusters.getHost(HOST1));
assertNotNull(clusters.getHost(HOST2));
HostDAO dao = injector.getInstance(HostDAO.class);
assertNotNull(dao.findByName(HOST1));
assertNotNull(dao.findByName(HOST2));