Search in sources :

Example 1 with BlockMirrorDeactivateCompleter

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);
        }
    }
}
Also used : BlockMirrorDeactivateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorDeactivateCompleter) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ArrayList(java.util.ArrayList) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Workflow(com.emc.storageos.workflow.Workflow) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) FCTN_MIRROR_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DataBindingException(javax.xml.bind.DataBindingException) Volume(com.emc.storageos.db.client.model.Volume) ScanTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.ScanTaskCompleter) BlockSnapshotEstablishGroupTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotEstablishGroupTaskCompleter) BlockMirrorTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorTaskCompleter) CloneTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.CloneTaskCompleter) ApplicationTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ApplicationTaskCompleter) SimpleTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.SimpleTaskCompleter) VolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter) DiscoverTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.DiscoverTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) MultiVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter) Map(java.util.Map) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

NamedURI (com.emc.storageos.db.client.model.NamedURI)1 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)1 Operation (com.emc.storageos.db.client.model.Operation)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 Volume (com.emc.storageos.db.client.model.Volume)1 FCTN_MIRROR_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 ControllerException (com.emc.storageos.volumecontroller.ControllerException)1 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)1 ApplicationTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ApplicationTaskCompleter)1 BlockMirrorDeactivateCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorDeactivateCompleter)1 BlockMirrorTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorTaskCompleter)1 BlockSnapshotEstablishGroupTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotEstablishGroupTaskCompleter)1 CloneTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.CloneTaskCompleter)1 MultiVolumeTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter)1 SimpleTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.SimpleTaskCompleter)1