Search in sources :

Example 11 with BlockMirror

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

the class BlockService method stopMirrors.

/**
 * Stop the specified mirror(s) for the source volume
 *
 * @param id
 *            the URN of a ViPR Source volume
 * @param copyID
 *            Copy volume ID, none specified stops all copies
 *
 * @return TaskList
 */
private TaskList stopMirrors(URI id, URI copyID) {
    ArgValidator.checkFieldUriType(id, Volume.class, "id");
    Volume sourceVolume = queryVolumeResource(id);
    ArgValidator.checkEntity(sourceVolume, id, true);
    StringSet mirrors = sourceVolume.getMirrors();
    if (mirrors == null || mirrors.isEmpty()) {
        throw APIException.badRequests.invalidParameterVolumeHasNoContinuousCopies(sourceVolume.getId());
    }
    ArrayList<URI> mirrorList = null;
    if (copyID != null) {
        ArgValidator.checkFieldUriType(copyID, BlockMirror.class, "copyID");
        BlockMirror mirror = queryMirror(copyID);
        ArgValidator.checkEntity(mirror, copyID, true);
        if (!mirror.getSource().getURI().equals(id)) {
            throw APIException.badRequests.invalidParameterBlockCopyDoesNotBelongToVolume(copyID, id);
        } else {
            mirrorList = new ArrayList();
            mirrorList.add(mirror.getId());
        }
    }
    String task = UUID.randomUUID().toString();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, sourceVolume.getStorageController());
    BlockServiceApi blockServiceApi = getBlockServiceImpl("mirror");
    return blockServiceApi.stopNativeContinuousCopies(storageSystem, sourceVolume, mirrorList, task);
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 12 with BlockMirror

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

the class BlockService method establishVolumeMirrorGroupRelation.

private TaskResourceRep establishVolumeMirrorGroupRelation(URI id, Copy copy, String op) throws InternalException {
    URI copyID = copy.getCopyID();
    ArgValidator.checkFieldUriType(copyID, BlockMirror.class, "copyID");
    // Get the volume associated with the URI
    Volume volume = queryVolumeResource(id);
    BlockMirror mirror = queryMirror(copyID);
    ArgValidator.checkEntity(volume, id, true);
    ArgValidator.checkEntity(mirror, copyID, true);
    StringSet mirrors = volume.getMirrors();
    if (mirrors == null || mirrors.isEmpty()) {
        throw APIException.badRequests.invalidParameterVolumeHasNoContinuousCopies(id);
    }
    if (!mirror.getSource().getURI().equals(id)) {
        throw APIException.badRequests.invalidParameterBlockCopyDoesNotBelongToVolume(copyID, id);
    }
    if (!volume.hasConsistencyGroup() || !mirror.hasConsistencyGroup()) {
        throw APIException.badRequests.blockObjectHasNoConsistencyGroup();
    }
    String task = UUID.randomUUID().toString();
    Operation status = new Operation();
    status.setResourceType(ProtectionOp.getResourceOperationTypeEnum(op));
    _dbClient.createTaskOpStatus(Volume.class, volume.getId(), task, status);
    auditOp(OperationTypeEnum.ESTABLISH_VOLUME_MIRROR, true, AuditLogManager.AUDITOP_BEGIN, mirrors);
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, volume.getStorageController());
    BlockServiceApi blockServiceApi = getBlockServiceImpl("mirror");
    return blockServiceApi.establishVolumeAndNativeContinuousCopyGroupRelation(system, volume, mirror, task);
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 13 with BlockMirror

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

the class BlockService method deactivateMirror.

/**
 * Deactivate continuous copies for given source volume
 *
 * NOTE: This is an asynchronous operation.
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Source volume
 * @param param
 *            List of copies to deactivate
 * @param type {@link DefaultValue} FULL
 *            Possible type of deletion
 *            <ul>
 *            <li>FULL</li>
 *            <li>VIPR_ONLY</li>
 *            </ul>
 *            if type is FULL, ViPR deletes the continuous copy from storage array and removes from ViPR data base.
 *            if type is VIPR_ONLY, ViPR removes the continuous copy only from ViPR data base and leaves the continuous copy on storage
 *            array as it is.
 *
 * @brief Delete continuous copies
 * @return TaskList
 *
 * @throws ControllerException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList deactivateMirror(@PathParam("id") URI id, CopiesParam param, @DefaultValue("FULL") @QueryParam("type") String deleteType) throws ControllerException {
    TaskList taskList = new TaskList();
    // Validate the source volume URI
    ArgValidator.checkFieldUriType(id, Volume.class, "id");
    Volume volume = _dbClient.queryObject(Volume.class, id);
    // Make sure that we don't have some pending
    // operation against the volume
    checkForPendingTasks(Arrays.asList(volume.getTenant().getURI()), Arrays.asList(volume));
    // Validate the list of copies
    ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
    boolean vplexVolume = checkIfVolumeIsForVplex(id);
    // Process the list of copies
    for (Copy copy : param.getCopies()) {
        // Validate the copy ID
        URI copyID = copy.getCopyID();
        ArgValidator.checkUri(copyID);
        // Validate a copy type was passed
        ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
        if (TechnologyType.NATIVE.toString().equalsIgnoreCase(copy.getType())) {
            String task = UUID.randomUUID().toString();
            StorageSystem device;
            String mirrorLabel;
            URI mirrorURI;
            BlockServiceApi blockServiceApi;
            if (vplexVolume) {
                VplexMirror mirror = queryVplexMirror(copyID);
                ArgValidator.checkEntity(mirror, mirror.getId(), isIdEmbeddedInURL(copyID));
                if (!mirror.getSource().getURI().equals(id)) {
                    throw APIException.badRequests.mirrorDoesNotBelongToVolume(copyID, id);
                }
                mirrorLabel = mirror.getLabel();
                mirrorURI = mirror.getId();
                device = _dbClient.queryObject(StorageSystem.class, mirror.getStorageController());
                blockServiceApi = getBlockServiceImpl(DiscoveredDataObject.Type.vplex.name());
            } else {
                BlockMirror mirror = queryMirror(copyID);
                ArgValidator.checkEntity(mirror, mirror.getId(), isIdEmbeddedInURL(copyID));
                if (!mirror.getSource().getURI().equals(id)) {
                    throw APIException.badRequests.mirrorDoesNotBelongToVolume(copyID, id);
                }
                mirrorLabel = mirror.getLabel();
                mirrorURI = mirror.getId();
                device = _dbClient.queryObject(StorageSystem.class, mirror.getStorageController());
                blockServiceApi = getBlockServiceImpl("mirror");
            }
            // Deactivate the mirror
            TaskList deactivateTaskList = blockServiceApi.deactivateMirror(device, mirrorURI, task, deleteType);
            // Create the audit log message
            String opStage = VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType) ? null : AuditLogManager.AUDITOP_BEGIN;
            boolean opStatus = true;
            for (TaskResourceRep resultTask : deactivateTaskList.getTaskList()) {
                if (Operation.Status.error.name().equals(resultTask.getState())) {
                    opStatus = false;
                    break;
                }
            }
            auditOp(OperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, opStatus, opStage, copyID.toString(), mirrorLabel);
            // Add tasks for this copy
            taskList.getTaskList().addAll(deactivateTaskList.getTaskList());
        } else {
            throw APIException.badRequests.invalidCopyType(copy.getType());
        }
    }
    return taskList;
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) Copy(com.emc.storageos.model.block.Copy) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 14 with BlockMirror

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

the class VPlexBlockServiceApiImpl method updateConsistencyGroup.

/**
 * {@inheritDoc}
 */
@Override
public TaskResourceRep updateConsistencyGroup(StorageSystem cgStorageSystem, List<Volume> cgVolumes, BlockConsistencyGroup consistencyGroup, List<URI> addVolumesList, List<URI> removeVolumesList, String taskId) throws ControllerException {
    // addVolumesList could be volumes, or full copies, or snapshots or mirrors.
    List<URI> addVolumes = new ArrayList<URI>();
    List<URI> addSnapshots = new ArrayList<URI>();
    List<URI> addFullcopies = new ArrayList<URI>();
    for (URI volumeURI : addVolumesList) {
        BlockObject blockObject = BlockObject.fetch(_dbClient, volumeURI);
        if (blockObject instanceof BlockMirror) {
            throw APIException.badRequests.actionNotApplicableForVplexVolumeMirrors(ResourceOperationTypeEnum.UPDATE_CONSISTENCY_GROUP.name());
        } else if (blockObject instanceof BlockSnapshot) {
            addSnapshots.add(volumeURI);
        } else if (blockObject instanceof Volume) {
            boolean isFullCopy = ControllerUtils.isVolumeFullCopy((Volume) blockObject, _dbClient);
            if (isFullCopy) {
                addFullcopies.add(volumeURI);
            } else {
                addVolumes.add(volumeURI);
            }
        }
    }
    if ((!addVolumes.isEmpty() && (!addSnapshots.isEmpty() || !addFullcopies.isEmpty())) || (!addSnapshots.isEmpty() && !addFullcopies.isEmpty())) {
        throw APIException.badRequests.cantUpdateCGWithMixedBlockObjects(consistencyGroup.getLabel());
    }
    // group.
    if (!addVolumes.isEmpty()) {
        Iterator<Volume> cgVolumesIter = cgVolumes.iterator();
        if (cgVolumesIter.hasNext()) {
            Volume cgVolume = cgVolumesIter.next();
            VirtualPool cgVPool = _permissionsHelper.getObjectById(cgVolume.getVirtualPool(), VirtualPool.class);
            URI cgVArrayURI = cgVolume.getVirtualArray();
            String cgHAType = cgVPool.getHighAvailability();
            for (URI volumeURI : addVolumes) {
                Volume addVolume = _permissionsHelper.getObjectById(volumeURI, Volume.class);
                VirtualPool addVolumeVPool = _permissionsHelper.getObjectById(addVolume.getVirtualPool(), VirtualPool.class);
                if (!addVolumeVPool.getHighAvailability().equals(cgHAType)) {
                    throw APIException.badRequests.invalidParameterConsistencyGroupVolumeHasIncorrectHighAvailability(cgVolume.getId(), cgHAType);
                } else if (!cgVArrayURI.equals(addVolume.getVirtualArray())) {
                    throw APIException.badRequests.invalidParameterConsistencyGroupVolumeHasIncorrectVArray(cgVolume.getId(), cgVArrayURI);
                }
            }
        }
        // Check if the volumes have been in the CG, and not ingestion case
        if (consistencyGroup.getTypes().contains(Types.LOCAL.toString()) && !cgVolumes.isEmpty()) {
            Set<String> cgVolumesURISet = new HashSet<String>();
            for (Volume cgVolume : cgVolumes) {
                cgVolumesURISet.add(cgVolume.getId().toString());
            }
            Iterator<URI> iter = addVolumes.iterator();
            while (iter.hasNext()) {
                if (cgVolumesURISet.contains(iter.next().toString())) {
                    iter.remove();
                }
            }
            if (addVolumes.isEmpty()) {
                // All volumes in the addVolumes list have been in the CG. return success
                s_logger.info("The volumes have been added to the CG");
                Operation op = new Operation();
                op.setResourceType(ResourceOperationTypeEnum.UPDATE_CONSISTENCY_GROUP);
                op.ready("Volumes have been added to the consistency group");
                _dbClient.createTaskOpStatus(BlockConsistencyGroup.class, consistencyGroup.getId(), taskId, op);
                return toTask(consistencyGroup, taskId, op);
            }
        }
    }
    // Only add snapshot or full copies to CG if backend volumes are from the same storage system.
    if (!addSnapshots.isEmpty() || !addFullcopies.isEmpty()) {
        if (!VPlexUtil.isVPLEXCGBackendVolumesInSameStorage(cgVolumes, _dbClient)) {
            throw APIException.badRequests.cantUpdateCGWithReplicaFromMultipleSystems(consistencyGroup.getLabel());
        }
    }
    Operation op = _dbClient.createTaskOpStatus(BlockConsistencyGroup.class, consistencyGroup.getId(), taskId, ResourceOperationTypeEnum.UPDATE_CONSISTENCY_GROUP);
    // When adding snapshots to CG, just call block implementation.
    if (!addSnapshots.isEmpty()) {
        BlockSnapshot snapshot = _permissionsHelper.getObjectById(addSnapshots.get(0), BlockSnapshot.class);
        URI systemURI = snapshot.getStorageController();
        StorageSystem system = _permissionsHelper.getObjectById(systemURI, StorageSystem.class);
        BlockController controller = getController(BlockController.class, system.getSystemType());
        controller.updateConsistencyGroup(system.getId(), consistencyGroup.getId(), addVolumesList, removeVolumesList, taskId);
        return toTask(consistencyGroup, taskId, op);
    }
    // all the virtual volumes in the CG have to be selected.
    if (!addVolumes.isEmpty()) {
        verifyAddVolumesToIngestedCG(consistencyGroup, addVolumes);
    }
    if (!addFullcopies.isEmpty()) {
        addVolumes.addAll(addFullcopies);
    }
    // Get VPlex controller
    VPlexController controller = getController();
    controller.updateConsistencyGroup(cgStorageSystem.getId(), consistencyGroup.getId(), addVolumes, removeVolumesList, taskId);
    return toTask(consistencyGroup, taskId, op);
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) VPlexController(com.emc.storageos.vplexcontroller.VPlexController) BlockController(com.emc.storageos.volumecontroller.BlockController) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FCTN_VPLEX_MIRROR_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_VPLEX_MIRROR_TO_URI) Volume(com.emc.storageos.db.client.model.Volume) BlockObject(com.emc.storageos.db.client.model.BlockObject) HashSet(java.util.HashSet) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 15 with BlockMirror

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

the class BlockServiceUtils method getActiveMirrorsForVolume.

/**
 * Return a list of active BlockMirror URI's that are known to be active
 * (in Synchronized state).
 *
 * @param volume Volume to check for mirrors against
 * @param dbClient A reference to a database client.
 *
 * @return List of active BlockMirror URI's
 */
public static List<URI> getActiveMirrorsForVolume(Volume volume, DbClient dbClient) {
    List<URI> activeMirrorURIs = new ArrayList<>();
    if (hasMirrors(volume)) {
        Collection<URI> mirrorUris = transform(volume.getMirrors(), FCTN_STRING_TO_URI);
        List<BlockMirror> mirrors = dbClient.queryObject(BlockMirror.class, mirrorUris);
        for (BlockMirror mirror : mirrors) {
            if (!FRACTURED.toString().equalsIgnoreCase(mirror.getSyncState())) {
                activeMirrorURIs.add(mirror.getId());
            }
        }
    }
    return activeMirrorURIs;
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) ArrayList(java.util.ArrayList) URI(java.net.URI) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI)

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