JobConstants.GROUP_NAME_JOB_PARAM);
String targetNode =
getJobParameters(chunkContext).getString(
JobConstants.SUB_JOB_NODE_NAME);
VcVirtualMachine vm = null;
try {
vm = healService.checkNodeStatus(clusterName, groupName, targetNode);
} catch (Exception e) {
putIntoJobExecutionContext(chunkContext,
JobConstants.CURRENT_ERROR_MESSAGE, e.getMessage());
throw e;
}
// need to create replace vm to recover disk fix
if (vm == null) {
// find bad disks
List<DiskSpec> badDisks = healService.getBadDisks(targetNode);
AuAssert.check(!badDisks.isEmpty());
// find replacements for bad disks
logger.debug("get replacements for bad disks");
List<DiskSpec> replacements;
try {
replacements =
healService.getReplacementDisks(clusterName, groupName,
targetNode, badDisks);
AuAssert.check(badDisks.size() == replacements.size());
} catch (Exception e) {
putIntoJobExecutionContext(chunkContext,
JobConstants.CURRENT_ERROR_MESSAGE, e.getMessage());
throw e;
}
logger.debug("get replacement disk set for recovery "
+ replacements.toString());
jobExecutionStatusHolder.setCurrentStepProgress(
getJobExecutionId(chunkContext), 0.3);
// clone and recover
logger.debug("start recovering bad vm " + targetNode);
try {
VcVirtualMachine newVm =
healService.createReplacementVm(clusterName, groupName,
targetNode, replacements);
// assert, if creation failed, exception should be thrown from previous method
if (newVm != null) {
logger.info("created replacement vm " + newVm.getId()
+ " for node " + targetNode);
putIntoJobExecutionContext(chunkContext,
JobConstants.REPLACE_VM_ID, newVm.getId());
} else {
logger.error("failed creating replacement vm for node "
+ targetNode);
throw ClusterHealServiceException
.FAILED_CREATE_REPLACEMENT_VM(targetNode);