use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorDeactivateCompleter in project coprhd-controller by CoprHD.
the class BlockDeviceController method deactivateMirror.
/**
* An orchestration controller method for detaching and deleting a mirror
*
* @param storage
* URI of storage controller.
* @param mirrorList
* List of URIs of block mirrors
* @param promotees
* List of URIs of promoted volumes
* @param isCG
* CG mirror or not
* @param opId
* Operation ID
* @throws ControllerException
*/
@Override
public void deactivateMirror(URI storage, List<URI> mirrorList, List<URI> promotees, Boolean isCG, String opId) throws ControllerException {
_log.info("deactivateMirror: START");
TaskCompleter taskCompleter = null;
String mirrorStr = Joiner.on("\t").join(mirrorList);
try {
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storage);
Workflow workflow = _workflowService.getNewWorkflow(this, "deactivateMirror", true, opId);
taskCompleter = new BlockMirrorDeactivateCompleter(mirrorList, promotees, opId);
ControllerUtils.checkMirrorConsistencyGroup(mirrorList, _dbClient, taskCompleter);
String detachStep = workflow.createStepId();
Workflow.Method detach = detachMirrorMethod(storage, mirrorList, isCG);
workflow.createStep("deactivate", "detaching mirror volume: " + mirrorStr, null, storage, storageSystem.getSystemType(), getClass(), detach, null, detachStep);
// for single volume mirror, the mirror will be deleted
List<URI> mirrorsToDelete = mirrorList;
// for group mirror, find mirrors to be deleted and mirrors to be promoted, and do the promotion
if (isCG) {
mirrorsToDelete = new ArrayList<URI>();
List<Volume> promotedVolumes = _dbClient.queryObject(Volume.class, promotees);
List<URI> orderedMirrorsToPromote = new ArrayList<URI>();
List<URI> orderedPromotedVolumes = new ArrayList<URI>();
for (URI mirror : mirrorList) {
URI promotedVolume = null;
for (Volume promotee : promotedVolumes) {
OpStatusMap statusMap = promotee.getOpStatus();
for (Map.Entry<String, Operation> entry : statusMap.entrySet()) {
Operation operation = entry.getValue();
if (operation.getAssociatedResourcesField().contains(mirror.toString())) {
promotedVolume = promotee.getId();
}
}
}
if (promotedVolume != null) {
orderedMirrorsToPromote.add(mirror);
orderedPromotedVolumes.add(promotedVolume);
} else {
mirrorsToDelete.add(mirror);
}
}
if (!orderedMirrorsToPromote.isEmpty()) {
// Create a step for promoting the mirrors.
String stepId = workflow.createStep(PROMOTE_MIRROR_STEP_GROUP, String.format("Promote mirrors : %s", Joiner.on("\t").join(orderedMirrorsToPromote)), detachStep, storage, storageSystem.getSystemType(), this.getClass(), promoteMirrorMethod(orderedMirrorsToPromote, orderedPromotedVolumes, isCG), null, null);
}
}
String deleteStep = workflow.createStepId();
Workflow.Method delete = deleteMirrorMethod(storage, mirrorsToDelete, isCG);
workflow.createStep("deactivate", "deleting mirror volume: " + Joiner.on("\t").join(mirrorsToDelete), detachStep, storage, storageSystem.getSystemType(), getClass(), delete, null, deleteStep);
String successMessage = String.format("Successfully deactivated mirror %s on StorageArray %s", mirrorStr, storage);
workflow.executePlan(taskCompleter, successMessage);
} catch (Exception e) {
if (_log.isErrorEnabled()) {
String msg = String.format("Deactivate mirror failed for mirror %s", mirrorStr);
_log.error(msg);
}
if (taskCompleter != null) {
String opName = ResourceOperationTypeEnum.DEACTIVATE_VOLUME_MIRROR.getName();
ServiceError serviceError = DeviceControllerException.errors.jobFailedOp(opName);
taskCompleter.error(_dbClient, serviceError);
} else {
throw DeviceControllerException.exceptions.deactivateMirrorFailed(e);
}
}
}
Aggregations