// Start
startService(clusterName, serviceName, false, false);
Cluster cluster = clusters.getCluster(clusterName);
Service s = cluster.getService(serviceName);
Assert.assertEquals(State.STARTED, s.getDesiredState());
ServiceComponentHost scHost = s.getServiceComponent("DATANODE").getServiceComponentHost("h2");
Assert.assertEquals(HostComponentAdminState.INSERVICE, scHost.getComponentAdminState());
// Decommission one datanode
Map<String, String> params = new HashMap<String, String>(){{
put("test", "test");
put("excluded_hosts", "h2");
put("align_maintenance_state", "true");
}};
RequestResourceFilter resourceFilter = new RequestResourceFilter("HDFS", "NAMENODE", null);
ExecuteActionRequest request = new ExecuteActionRequest(clusterName, "DECOMMISSION", params);
request.getResourceFilters().add(resourceFilter);
Map<String, String> requestProperties = new HashMap<String, String>();
requestProperties.put(REQUEST_CONTEXT_PROPERTY, "Called from a test");
RequestStatusResponse response = controller.createAction(request,
requestProperties);
List<HostRoleCommand> storedTasks = actionDB.getRequestTasks(response.getRequestId());
ExecutionCommand execCmd = storedTasks.get(0).getExecutionCommandWrapper
().getExecutionCommand();
Assert.assertNotNull(storedTasks);
Assert.assertNotNull(execCmd.getConfigurationTags().get("hdfs-site"));
Assert.assertEquals(1, storedTasks.size());
Assert.assertEquals(HostComponentAdminState.DECOMMISSIONED, scHost.getComponentAdminState());
Assert.assertEquals(MaintenanceState.ON, scHost.getMaintenanceState());
HostRoleCommand command = storedTasks.get(0);
Assert.assertEquals(Role.NAMENODE, command.getRole());
Assert.assertEquals(RoleCommand.CUSTOM_COMMAND, command.getRoleCommand());
Map<String, Set<String>> cInfo = execCmd.getClusterHostInfo();
Assert.assertTrue(cInfo.containsKey("decom_dn_hosts"));
Assert.assertTrue(cInfo.get("decom_dn_hosts").size() == 1);
Assert.assertEquals("h2",
cInfo.get("all_hosts").toArray()[Integer.parseInt(cInfo.get("decom_dn_hosts").iterator().next())]);
Assert.assertEquals("DECOMMISSION", execCmd.getHostLevelParams().get("custom_command"));
// Decommission the other datanode
params = new HashMap<String, String>(){{
put("test", "test");
put("excluded_hosts", "h1");
put("align_maintenance_state", "true");
}};
resourceFilter = new RequestResourceFilter("HDFS", "NAMENODE", null);
request = new ExecuteActionRequest(clusterName, "DECOMMISSION", params);
request.getResourceFilters().add(resourceFilter);
response = controller.createAction(request,
requestProperties);
storedTasks = actionDB.getRequestTasks(response.getRequestId());
execCmd = storedTasks.get(0).getExecutionCommandWrapper
().getExecutionCommand();
Map<String, String> cmdParams = execCmd.getCommandParams();
Assert.assertTrue(cmdParams.containsKey("update_exclude_file_only"));
Assert.assertTrue(cmdParams.get("update_exclude_file_only").equals("false"));
Assert.assertNotNull(storedTasks);
Assert.assertEquals(1, storedTasks.size());
Assert.assertEquals(HostComponentAdminState.DECOMMISSIONED, scHost.getComponentAdminState());
Assert.assertEquals(MaintenanceState.ON, scHost.getMaintenanceState());
cInfo = execCmd.getClusterHostInfo();
Assert.assertTrue(cInfo.containsKey("decom_dn_hosts"));
Assert.assertEquals("0,1", cInfo.get("decom_dn_hosts").iterator().next());
Assert.assertEquals("DECOMMISSION", execCmd.getHostLevelParams().get("custom_command"));
// Recommission the other datanode (while adding NameNode HA)
createServiceComponentHost(clusterName, serviceName, componentName1,
host2, null);
ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceName,
componentName1, host2, State.INSTALLED.toString());
Set<ServiceComponentHostRequest> requests = new HashSet<ServiceComponentHostRequest>();
requests.add(r);
controller.updateHostComponents(requests, Collections.<String, String>emptyMap(), true);
s.getServiceComponent(componentName1).getServiceComponentHost(host2).setState(State.INSTALLED);
r = new ServiceComponentHostRequest(clusterName, serviceName,
componentName1, host2, State.STARTED.toString());
requests.clear();
requests.add(r);
controller.updateHostComponents(requests, Collections.<String, String>emptyMap(), true);
s.getServiceComponent(componentName1).getServiceComponentHost(host2).setState(State.STARTED);
params = new HashMap<String, String>(){{
put("test", "test");
put("included_hosts", "h1 , h2");
put("align_maintenance_state", "true");
}};
resourceFilter = new RequestResourceFilter("HDFS", "NAMENODE", null);
request = new ExecuteActionRequest(clusterName, "DECOMMISSION", params);
request.getResourceFilters().add(resourceFilter);
response = controller.createAction(request,
requestProperties);
storedTasks = actionDB.getRequestTasks(response.getRequestId());
Assert.assertNotNull(storedTasks);
scHost = s.getServiceComponent("DATANODE").getServiceComponentHost("h2");
Assert.assertEquals(HostComponentAdminState.INSERVICE, scHost.getComponentAdminState());
Assert.assertEquals(MaintenanceState.OFF, scHost.getMaintenanceState());
execCmd = storedTasks.get(0).getExecutionCommandWrapper
().getExecutionCommand();
Assert.assertNotNull(storedTasks);