Search in sources :

Example 6 with BlockMirror

use of com.emc.storageos.db.client.model.BlockMirror in project coprhd-controller by CoprHD.

the class BlockConsistencyGroupService method verifyAddReplicaToCG.

/**
 * Validates the replicas to be added to Consistency group.
 * - verifies that the replicas are not internal objects,
 * - checks if the given CG is its source volume's CG,
 * - validates that the replica is not in any other CG,
 * - verifies the project for the replicas to be added is same
 * as the project for the consistency group.
 */
private void verifyAddReplicaToCG(URI blockURI, BlockConsistencyGroup cg, StorageSystem cgStorageSystem) {
    BlockObject blockObject = BlockObject.fetch(_dbClient, blockURI);
    // Don't allow partially ingested object to be added to CG.
    BlockServiceUtils.validateNotAnInternalBlockObject(blockObject, false);
    URI sourceVolumeURI = null;
    URI blockProjectURI = null;
    if (blockObject instanceof BlockSnapshot) {
        BlockSnapshot snapshot = (BlockSnapshot) blockObject;
        blockProjectURI = snapshot.getProject().getURI();
        sourceVolumeURI = snapshot.getParent().getURI();
    } else if (blockObject instanceof BlockMirror) {
        BlockMirror mirror = (BlockMirror) blockObject;
        blockProjectURI = mirror.getProject().getURI();
        sourceVolumeURI = mirror.getSource().getURI();
    } else if (blockObject instanceof Volume) {
        Volume volume = (Volume) blockObject;
        blockProjectURI = volume.getProject().getURI();
        sourceVolumeURI = volume.getAssociatedSourceVolume();
    }
    // check if the given CG is its source volume's CG
    Volume sourceVolume = null;
    if (!NullColumnValueGetter.isNullURI(sourceVolumeURI)) {
        sourceVolume = _dbClient.queryObject(Volume.class, sourceVolumeURI);
    }
    if (sourceVolume == null || !cg.getId().equals(sourceVolume.getConsistencyGroup())) {
        throw APIException.badRequests.invalidParameterSourceVolumeNotInGivenConsistencyGroup(sourceVolumeURI, cg.getId());
    }
    // Validate that the replica is not in any other CG.
    if (!NullColumnValueGetter.isNullURI(blockObject.getConsistencyGroup()) && !cg.getId().equals(blockObject.getConsistencyGroup())) {
        throw APIException.badRequests.invalidParameterVolumeAlreadyInAConsistencyGroup(cg.getId(), blockObject.getConsistencyGroup());
    }
    // Verify the project for the replicas to be added is same
    // as the project for the consistency group.
    URI cgProjectURI = cg.getProject().getURI();
    if (!blockProjectURI.equals(cgProjectURI)) {
        List<Project> projects = _dbClient.queryObjectField(Project.class, "label", Arrays.asList(cgProjectURI, blockProjectURI));
        throw APIException.badRequests.consistencyGroupAddVolumeThatIsInDifferentProject(blockObject.getLabel(), projects.get(0).getLabel(), projects.get(1).getLabel());
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) BlockMirror(com.emc.storageos.db.client.model.BlockMirror) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 7 with BlockMirror

use of com.emc.storageos.db.client.model.BlockMirror in project coprhd-controller by CoprHD.

the class BlockMirrorServiceApiImpl method getGroupMirrorSourceMap.

private Map<BlockMirror, Volume> getGroupMirrorSourceMap(BlockMirror mirror, Volume sourceVolume) {
    Map<BlockMirror, Volume> mirrorSourceMap = new HashMap<BlockMirror, Volume>();
    if (sourceVolume.isInCG()) {
        URIQueryResultList queryResults = new URIQueryResultList();
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getMirrorReplicationGroupInstanceConstraint(mirror.getReplicationGroupInstance()), queryResults);
        Iterator<URI> resultsIter = queryResults.iterator();
        while (resultsIter.hasNext()) {
            URI uri = resultsIter.next();
            if (uri.equals(mirror.getId())) {
                mirrorSourceMap.put(mirror, sourceVolume);
            } else {
                BlockMirror obj = _dbClient.queryObject(BlockMirror.class, uri);
                mirrorSourceMap.put(obj, _dbClient.queryObject(Volume.class, obj.getSource()));
            }
        }
    }
    return mirrorSourceMap;
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) Volume(com.emc.storageos.db.client.model.Volume) HashMap(java.util.HashMap) 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) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 8 with BlockMirror

use of com.emc.storageos.db.client.model.BlockMirror in project coprhd-controller by CoprHD.

the class BlockMirrorServiceApiImpl method pauseNativeContinuousCopies.

/**
 * {@inheritDoc}
 *
 * @throws ControllerException
 */
@Override
public TaskList pauseNativeContinuousCopies(StorageSystem storageSystem, Volume sourceVolume, List<BlockMirror> blockMirrors, Boolean sync, String taskId) throws ControllerException {
    TaskList taskList = new TaskList();
    List<URI> mirrorUris = new ArrayList<>();
    // Assume all continuous copies are to be paused
    List<BlockMirror> pausedMirrors = new ArrayList<>();
    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 (mirrorIsPausable(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.FRACTURE_VOLUME_MIRROR);
            op.setMessage("No continuous copy can be paused");
            _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 paused
        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 (mirrorIsResumable(mirror)) {
                // extract mirrors that are in "paused" state
                pausedMirrors.add(mirror);
            } else if (!mirrorIsPausable(mirror)) {
                // if there is a mirror is not in paused state, and not pausable, throw exception
                throw APIException.badRequests.cannotPauseContinuousCopyWithSyncState(mirror.getId(), mirror.getSyncState(), sourceVolume.getId());
            } else if (mirrorIsResynchronizing(mirror)) {
                throw APIException.badRequests.cannotPauseContinuousCopyWhileResynchronizing(mirror.getId(), mirror.getSyncState(), sourceVolume.getId());
            } else {
                // otherwise, place mirror a list... get ready to pause
                mirrorUris.add(mirror.getId());
            }
        }
    }
    /*
         * if all mirrors are paused, then there is no task to do.
         * Return a successful task
         */
    if (!pausedMirrors.isEmpty() && mirrorUris.isEmpty()) {
        // If the mirrors is already paused, there would be no need to queue another request to activate it again.
        Operation op = new Operation();
        op.ready();
        op.setResourceType(ResourceOperationTypeEnum.FRACTURE_VOLUME_MIRROR);
        op.setMessage("The continuous copies are already paused");
        _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.FRACTURE_VOLUME_MIRROR, mirrorTargetCommaDelimList);
            taskList.getTaskList().add(toTask(sourceVolume, mirrorsToProcess, taskId, op));
        } else {
            populateTaskList(sourceVolume, groupMirrorSourceMap, taskList, taskId, ResourceOperationTypeEnum.FRACTURE_VOLUME_MIRROR);
        }
        try {
            BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
            controller.pauseNativeContinuousCopies(storageSystem.getId(), mirrorUris, sync, taskId);
        } catch (ControllerException e) {
            String errorMsg = format("Failed to pause 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)

Example 9 with BlockMirror

use of com.emc.storageos.db.client.model.BlockMirror in project coprhd-controller by CoprHD.

the class BlockMirrorServiceApiImpl method deactivateMirror.

/**
 * {@inheritDoc}
 *
 * @throws ControllerException
 */
@SuppressWarnings("unchecked")
@Override
public TaskList deactivateMirror(StorageSystem storageSystem, URI mirrorURI, String taskId, String deleteType) throws ControllerException {
    _log.info("START: deactivate mirror");
    TaskList taskList = new TaskList();
    BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, mirrorURI);
    Volume sourceVolume = _dbClient.queryObject(Volume.class, mirror.getSource().getURI());
    List<URI> mirrorURIs = new ArrayList<URI>();
    boolean isCG = sourceVolume.isInCG();
    List<URI> promotees = null;
    if (isCG) {
        // for group mirrors, deactivate task will detach and delete the mirror that user asked to deactivate, and
        // promote other mirrors
        // in the group
        Map<BlockMirror, Volume> groupMirrorSourceMap = getGroupMirrorSourceMap(mirror, sourceVolume);
        mirrorURIs = new ArrayList<URI>(transform(new ArrayList<BlockMirror>(groupMirrorSourceMap.keySet()), FCTN_MIRROR_TO_URI));
        if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType)) {
            // Create a task for each source/mirror pair.
            for (Entry<BlockMirror, Volume> entry : groupMirrorSourceMap.entrySet()) {
                Operation op = _dbClient.createTaskOpStatus(Volume.class, entry.getValue().getId(), taskId, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, entry.getKey().getId().toString());
                taskList.getTaskList().add(toTask(entry.getValue(), Arrays.asList(entry.getKey()), taskId, op));
            }
        } else {
            // deactivate (detach and delete) mirrorURI
            Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, mirrorURI.toString());
            taskList.getTaskList().add(toTask(sourceVolume, Arrays.asList(mirror), taskId, op));
            // detach and promote other mirrors in the group
            groupMirrorSourceMap.remove(mirror);
            populateTaskList(sourceVolume, groupMirrorSourceMap, taskList, taskId, ResourceOperationTypeEnum.DETACH_BLOCK_MIRROR);
            // detached mirrors (except the one deleted), will be promoted to regular block volumes
            promotees = preparePromotedVolumes(new ArrayList<BlockMirror>(groupMirrorSourceMap.keySet()), taskList, taskId);
        }
    } else {
        // for single volume mirror, deactivate task will detach and delete the mirror
        mirrorURIs = Arrays.asList(mirror.getId());
        Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, mirror.getId().toString());
        taskList.getTaskList().add(toTask(sourceVolume, Arrays.asList(mirror), taskId, op));
    }
    try {
        if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType)) {
            _log.info("Perform ViPR-only delete for mirrors %s", mirrorURIs);
            // Perform any database cleanup that is required.
            cleanupForViPROnlyMirrorDelete(mirrorURIs);
            // Mark them inactive.
            _dbClient.markForDeletion(_dbClient.queryObject(BlockMirror.class, mirrorURIs));
            // Update the task status for each snapshot to successfully completed.
            for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
                Volume taskVolume = _dbClient.queryObject(Volume.class, taskResourceRep.getResource().getId());
                Operation op = taskVolume.getOpStatus().get(taskId);
                op.ready("Continuous copy succesfully deleted from ViPR");
                taskVolume.getOpStatus().updateTaskStatus(taskId, op);
                _dbClient.updateObject(taskVolume);
            }
        } else {
            BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
            controller.deactivateMirror(storageSystem.getId(), mirrorURIs, promotees, isCG, taskId);
        }
    } catch (ControllerException e) {
        String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirror.getId().toString(), e.getMessage());
        _log.error(errorMsg);
        for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(errorMsg);
            _dbClient.error(URIUtil.getModelClass(taskResourceRep.getResource().getId()), taskResourceRep.getResource().getId(), taskId, e);
        }
        // Mark the mirrors that would have been promoted inactive.
        if (promotees != null && !promotees.isEmpty()) {
            List<Volume> volumes = _dbClient.queryObject(Volume.class, promotees);
            for (Volume volume : volumes) {
                volume.setInactive(true);
            }
            _dbClient.updateObject(volumes);
        }
    } catch (Exception e) {
        String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirror.getId().toString(), e.getMessage());
        _log.error(errorMsg);
        ServiceCoded sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
        for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
            taskResourceRep.setState(Operation.Status.error.name());
            taskResourceRep.setMessage(sc.getMessage());
            _dbClient.error(URIUtil.getModelClass(taskResourceRep.getResource().getId()), taskResourceRep.getResource().getId(), taskId, sc);
        }
        // Mark the mirrors that would have been promoted inactive.
        if (promotees != null && !promotees.isEmpty()) {
            List<Volume> volumes = _dbClient.queryObject(Volume.class, promotees);
            for (Volume volume : volumes) {
                volume.setInactive(true);
            }
            _dbClient.updateObject(volumes);
        }
    }
    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) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) 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) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) List(java.util.List) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 10 with BlockMirror

use of com.emc.storageos.db.client.model.BlockMirror in project coprhd-controller by CoprHD.

the class BlockService method getMirror.

/**
 * Show details for a specific continuous copy
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Source volume
 * @param mid
 *            Continuous copy URI
 *
 * @brief Show continuous copy
 * @return BlockMirrorRestRep
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/{mid}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public BlockMirrorRestRep getMirror(@PathParam("id") URI id, @PathParam("mid") URI mid) {
    ArgValidator.checkFieldUriType(id, Volume.class, "id");
    boolean vplexVolume = checkIfVolumeIsForVplex(id);
    BlockMirrorRestRep mirrorRestRep = null;
    if (vplexVolume) {
        ArgValidator.checkFieldUriType(mid, VplexMirror.class, "mid");
        VplexMirror mirror = queryVplexMirror(mid);
        if (!mirror.getSource().getURI().equals(id)) {
            throw APIException.badRequests.invalidParameterVolumeMirrorMismatch(mid, id);
        }
        mirrorRestRep = map(mirror);
    } else {
        queryResource(id);
        ArgValidator.checkFieldUriType(mid, BlockMirror.class, "mid");
        BlockMirror mirror = queryMirror(mid);
        if (!mirror.getSource().getURI().equals(id)) {
            throw APIException.badRequests.invalidParameterVolumeMirrorMismatch(mid, id);
        }
        mirrorRestRep = map(_dbClient, mirror);
    }
    return mirrorRestRep;
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) BlockMirrorRestRep(com.emc.storageos.model.block.BlockMirrorRestRep) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) SOURCE_TO_TARGET(com.emc.storageos.model.block.Copy.SyncDirection.SOURCE_TO_TARGET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

BlockMirror (com.emc.storageos.db.client.model.BlockMirror)115 Volume (com.emc.storageos.db.client.model.Volume)77 URI (java.net.URI)49 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)43 ArrayList (java.util.ArrayList)33 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)30 NamedURI (com.emc.storageos.db.client.model.NamedURI)29 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)28 CIMObjectPath (javax.cim.CIMObjectPath)26 CIMInstance (javax.cim.CIMInstance)16 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)15 FCTN_MIRROR_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI)15 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)15 CIMArgument (javax.cim.CIMArgument)14 WBEMException (javax.wbem.WBEMException)14 BlockObject (com.emc.storageos.db.client.model.BlockObject)12 StringSet (com.emc.storageos.db.client.model.StringSet)12 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)11 ControllerException (com.emc.storageos.volumecontroller.ControllerException)10 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)9