CmServiceDef hdfsService = cluster.serviceDefOfType("HDFS");
for (CmRoleDef roleDef : hdfsService.getRoles()) {
if (roleDef.getType().getDisplayName().equals("HDFS_FAILOVER_CONTROLLER") && roleDef.isActive()) {
executeAndReport("Initialize High Availability state in Zookeeper", apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName())
.getRoleCommandsResource(hdfsService.getName())
.hdfsInitializeAutoFailoverCommand(new ApiRoleNameList(ImmutableList.<String>builder().add(roleDef.getName()).build())),
INVALID_PROGRESS, cluster.getCurrentReport(), reportQueue, false);
break;
}
}
// Start JournalNodes
ApiRoleNameList jnRoles = new ApiRoleNameList();
for (CmRoleDef roleDef : hdfsService.getRoles()) {
if (roleDef.getType().getDisplayName().equals("HDFS_JOURNALNODE")) {
jnRoles.add(roleDef.getName());
}
}
executeAndReport("Starting JournalNodes", apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName())
.getRoleCommandsResource(hdfsService.getName()).startCommand(jnRoles),
INVALID_PROGRESS, cluster.getCurrentReport(), reportQueue, false);
/*
1) Format active NN
2) Intialize shared edits directory of NameNode
3) Start active NN
*/
for (CmRoleDef roleDef : hdfsService.getRoles()) {
if (roleDef.getType().getDisplayName().equals("HDFS_NAMENODE") && roleDef.isActive()) {
ApiRoleNameList nnRoles = new ApiRoleNameList();
nnRoles.add(roleDef.getName());
try {
executeAndReport("Formatting Active Namenode",
apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName())
.getRoleCommandsResource(hdfsService.getName()).formatCommand(nnRoles),
INVALID_PROGRESS, cluster.getCurrentReport(), reportQueue, false);
} catch (Exception e){
// ignore
}
try {
executeAndReport("Initializing Shared Edits Directory of Namenode",
apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName())
.getRoleCommandsResource(hdfsService.getName()).hdfsInitializeSharedDirCommand(nnRoles),
INVALID_PROGRESS, cluster.getCurrentReport(), reportQueue, false);
} catch (Exception e) {
// ignore
}
executeAndReport("Starting Active Namenode", apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName())
.getRoleCommandsResource(hdfsService.getName()).startCommand(nnRoles),
INVALID_PROGRESS, cluster.getCurrentReport(), reportQueue, true);
break;
}
}
// Wait for active NameNode start up
Thread.sleep(10 * 1000); // TODO: wait until standby NN started responding to RPCs
/*
1) Bootstrapping standby NN
2) Start standby NN
*/
for (CmRoleDef roleDef : hdfsService.getRoles()) {
if (roleDef.getType().getDisplayName().equals("HDFS_NAMENODE") && !roleDef.isActive()) {
ApiRoleNameList nnRoles = new ApiRoleNameList();
nnRoles.add(roleDef.getName());
executeAndReport("Boostrapping Standby Namenode",
apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName())
.getRoleCommandsResource(hdfsService.getName()).hdfsBootstrapStandByCommand(nnRoles),
INVALID_PROGRESS, cluster.getCurrentReport(), reportQueue, true);
executeAndReport("Starting Standby Namenode", apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName())
.getRoleCommandsResource(hdfsService.getName()).startCommand(nnRoles),
INVALID_PROGRESS, cluster.getCurrentReport(), reportQueue, true);
break;
}
}
// Start Failover controllers
List<String> failOverRoles = new ArrayList<String>();
for (CmRoleDef roleDef : hdfsService.getRoles()) {
if (roleDef.getType().getDisplayName().equals("HDFS_FAILOVER_CONTROLLER")) {
failOverRoles.add(roleDef.getName());
}
}
executeAndReport("Starting Failover Controllers", apiResourceRootV6.getClustersResource().getServicesResource(cluster.getName())
.getRoleCommandsResource(hdfsService.getName()).startCommand(new ApiRoleNameList(failOverRoles)),
INVALID_PROGRESS, cluster.getCurrentReport(), reportQueue, true);
// Wait for standby NameNode start up
Thread.sleep(10 * 1000); // TODO: wait until standby NN started responding to RPCs