Search in sources :

Example 6 with FCTN_MIRROR_TO_URI

use of com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI in project coprhd-controller by CoprHD.

the class BlockMirrorServiceApiImpl method resumeNativeContinuousCopies.

/**
 * {@inheritDoc}
 */
@Override
public TaskList resumeNativeContinuousCopies(StorageSystem storageSystem, Volume sourceVolume, List<BlockMirror> blockMirrors, String taskId) throws ControllerException {
    _log.info("START resume native continuous copies");
    TaskList taskList = new TaskList();
    List<URI> resumedMirrors = new ArrayList<URI>();
    List<URI> mirrorURIs = new ArrayList<URI>();
    Map<BlockMirror, Volume> groupMirrorSourceMap = null;
    List<BlockMirror> mirrorsToProcess = null;
    boolean isCG = sourceVolume.isInCG();
    if (isCG) {
        if (blockMirrors == null) {
            for (String uriStr : sourceVolume.getMirrors()) {
                BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, URI.create(uriStr));
                if (mirrorIsResumable(mirror)) {
                    groupMirrorSourceMap = getGroupMirrorSourceMap(mirror, sourceVolume);
                    // only process one mirror group
                    break;
                }
            }
        } else {
            groupMirrorSourceMap = getGroupMirrorSourceMap(blockMirrors.get(0), sourceVolume);
        }
        if (groupMirrorSourceMap == null || groupMirrorSourceMap.isEmpty()) {
            Operation op = new Operation();
            op.ready();
            op.setResourceType(ResourceOperationTypeEnum.RESUME_VOLUME_MIRROR);
            op.setMessage("No continuous copy can be resumed");
            _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, op);
            taskList.getTaskList().add(toTask(sourceVolume, taskId, op));
            return taskList;
        }
        mirrorsToProcess = new ArrayList<BlockMirror>(groupMirrorSourceMap.keySet());
        mirrorURIs = new ArrayList<URI>(transform(mirrorsToProcess, FCTN_MIRROR_TO_URI));
    } else {
        // Assume all continuous copies are to be resumed
        mirrorsToProcess = blockMirrors;
        if (mirrorsToProcess == null) {
            mirrorsToProcess = new ArrayList<BlockMirror>();
            for (String uriStr : sourceVolume.getMirrors()) {
                BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, URI.create(uriStr));
                mirrorsToProcess.add(mirror);
            }
        }
        for (BlockMirror mirror : mirrorsToProcess) {
            if (mirrorIsPausable(mirror) || mirrorIsResynchronizing(mirror)) {
                // extract mirrors that are in resume state or resynchronizing
                resumedMirrors.add(mirror.getId());
            } else if (!mirrorIsResumable(mirror)) {
                throw APIException.badRequests.cannotResumeContinuousCopyWithSyncState(mirror.getId(), mirror.getSyncState(), sourceVolume.getId());
            }
            mirrorURIs.add(mirror.getId());
        }
    }
    /*
         * if all mirrors are resumed/resynchronizing, then there is no task to do.
         * Return a successful task
         */
    if (!resumedMirrors.isEmpty() && mirrorURIs.isEmpty()) {
        // If the mirrors is already resumed or resynchronizing, there would be no need to queue another request to
        // resume it again.
        Operation op = new Operation();
        op.setResourceType(ResourceOperationTypeEnum.RESUME_VOLUME_MIRROR);
        op.setAssociatedResourcesField(Joiner.on(',').join(resumedMirrors));
        op.ready("The continuous copies are already resumed or resynchronizing");
        _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, op);
        taskList.getTaskList().add(toTask(sourceVolume, taskId, op));
    } else {
        if (!isCG) {
            Collection<String> mirrorTargetIds = Collections2.transform(mirrorsToProcess, FCTN_VOLUME_URI_TO_STR);
            String mirrorTargetCommaDelimList = Joiner.on(',').join(mirrorTargetIds);
            Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.RESUME_VOLUME_MIRROR, mirrorTargetCommaDelimList);
            taskList.getTaskList().add(toTask(sourceVolume, mirrorsToProcess, taskId, op));
        } else {
            populateTaskList(sourceVolume, groupMirrorSourceMap, taskList, taskId, ResourceOperationTypeEnum.RESUME_VOLUME_MIRROR);
        }
        try {
            BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
            controller.resumeNativeContinuousCopies(storageSystem.getId(), mirrorURIs, taskId);
        } catch (ControllerException e) {
            String errorMsg = format("Failed to resume continuous copies for source volume %s", sourceVolume.getId());
            _log.error(errorMsg, e);
            _dbClient.error(Volume.class, sourceVolume.getId(), taskId, e);
        }
    }
    return taskList;
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) BlockController(com.emc.storageos.volumecontroller.BlockController) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) 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) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI) Volume(com.emc.storageos.db.client.model.Volume)

Aggregations

BlockMirror (com.emc.storageos.db.client.model.BlockMirror)6 NamedURI (com.emc.storageos.db.client.model.NamedURI)6 FCTN_MIRROR_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)6 ControllerException (com.emc.storageos.volumecontroller.ControllerException)6 URI (java.net.URI)6 ArrayList (java.util.ArrayList)6 Volume (com.emc.storageos.db.client.model.Volume)5 Operation (com.emc.storageos.db.client.model.Operation)4 FCTN_STRING_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI)4 TaskList (com.emc.storageos.model.TaskList)4 BlockController (com.emc.storageos.volumecontroller.BlockController)4 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)3 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)2 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)2 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)2 WorkflowException (com.emc.storageos.workflow.WorkflowException)2 List (java.util.List)2