Search in sources :

Example 41 with BlockSnapshot

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

the class ExportGroupService method validateDuplicateRPBlockSnapshotsForExport.

/**
 * Validates the list of BlockObjects for RecoverPoint bookmarks that reference
 * the same consistency group and RP site.
 *
 * @param blockObjURIs the list of BlockObject URIs.
 */
private void validateDuplicateRPBlockSnapshotsForExport(List<URI> blockObjURIs) {
    Map<URI, List<String>> cgToRpSiteMap = new HashMap<URI, List<String>>();
    for (URI blockObjectURI : blockObjURIs) {
        if (URIUtil.isType(blockObjectURI, BlockSnapshot.class)) {
            BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, blockObjectURI);
            if (TechnologyType.RP.name().equalsIgnoreCase(snapshot.getTechnologyType()) && !NullColumnValueGetter.isNullURI(snapshot.getConsistencyGroup())) {
                // Check to see if there is an RP bookmark that references
                // the same RP copy and consistency group.
                List<String> rpSites = cgToRpSiteMap.get(snapshot.getConsistencyGroup());
                if (rpSites == null) {
                    // Initialize the list of RP sites
                    rpSites = new ArrayList<String>();
                    cgToRpSiteMap.put(snapshot.getConsistencyGroup(), rpSites);
                }
                if (rpSites.contains(snapshot.getEmInternalSiteName())) {
                    // Request is trying to export 2 RP bookmarks for the same target copy and
                    // consistency group.
                    BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, snapshot.getConsistencyGroup());
                    String rpCopyName = RPHelper.getCgCopyName(_dbClient, cg, snapshot.getVirtualArray(), false);
                    throw APIException.badRequests.duplicateRpBookmarkExport(rpCopyName, cg.getLabel());
                } else {
                    rpSites.add(snapshot.getEmInternalSiteName());
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 42 with BlockSnapshot

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

the class DefaultBlockServiceApiImpl method establishVolumeAndSnapshotGroupRelation.

/**
 * {@inheritDoc}
 *
 * @throws ControllerException
 */
@Override
public TaskResourceRep establishVolumeAndSnapshotGroupRelation(StorageSystem storageSystem, Volume sourceVolume, BlockSnapshot snapshot, String taskId) throws ControllerException {
    _log.info("START establish Volume and Snapshot group relation");
    // Create the task on the block snapshot
    Operation op = _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), taskId, ResourceOperationTypeEnum.ESTABLISH_VOLUME_SNAPSHOT);
    snapshot.getOpStatus().put(taskId, op);
    try {
        BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
        controller.establishVolumeAndSnapshotGroupRelation(storageSystem.getId(), sourceVolume.getId(), snapshot.getId(), taskId);
    } catch (ControllerException e) {
        String errorMsg = String.format("Failed to establish group relation between volume group and snapshot group." + "Source volume: %s, Snapshot: %s", sourceVolume.getId(), snapshot.getId());
        _log.error(errorMsg, e);
        _dbClient.error(BlockSnapshot.class, snapshot.getId(), taskId, e);
    }
    return toTask(snapshot, taskId, op);
}
Also used : ControllerException(com.emc.storageos.volumecontroller.ControllerException) BlockController(com.emc.storageos.volumecontroller.BlockController) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Operation(com.emc.storageos.db.client.model.Operation)

Example 43 with BlockSnapshot

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

the class VolumeGroupService method performVolumeGroupSnapshotOperation.

/*
     * Wrapper of BlockConsistencyGroupService methods for snapshot operations
     *
     * @param volumeGroupId
     * @param param
     * @return a TaskList
     */
private TaskList performVolumeGroupSnapshotOperation(final URI volumeGroupId, final VolumeGroupSnapshotOperationParam param, OperationTypeEnum opType) {
    Map<String, List<BlockSnapshot>> snapsetToSnapshots = getSnapshotsGroupedBySnapset(volumeGroupId, param);
    // validate that it's ok to do the snapshot operation
    validateSnapshotOperation(volumeGroupId, snapsetToSnapshots, opType);
    auditOp(opType, true, AuditLogManager.AUDITOP_BEGIN, volumeGroupId.toString(), param.getSnapshots());
    TaskList taskList = new TaskList();
    Set<Entry<String, List<BlockSnapshot>>> entrySet = snapsetToSnapshots.entrySet();
    for (Entry<String, List<BlockSnapshot>> entry : entrySet) {
        Table<URI, String, BlockSnapshot> storageRgToSnapshot = ControllerUtils.getSnapshotForStorageReplicationGroup(entry.getValue());
        for (Cell<URI, String, BlockSnapshot> cell : storageRgToSnapshot.cellSet()) {
            log.info("{} for replication group {}", opType.getDescription(), cell.getColumnKey());
            try {
                BlockSnapshot snapshot = cell.getValue();
                URI cgUri = snapshot.getConsistencyGroup();
                URI snapshotUri = snapshot.getId();
                switch(opType) {
                    case ACTIVATE_VOLUME_GROUP_SNAPSHOT:
                        taskList.addTask(_blockConsistencyGroupService.activateConsistencyGroupSnapshot(cgUri, snapshotUri));
                        break;
                    case RESTORE_VOLUME_GROUP_SNAPSHOT:
                        taskList.addTask(_blockConsistencyGroupService.restoreConsistencyGroupSnapshot(cgUri, snapshotUri));
                        break;
                    case RESYNCHRONIZE_VOLUME_GROUP_SNAPSHOT:
                        taskList.addTask(_blockConsistencyGroupService.resynchronizeConsistencyGroupSnapshot(cgUri, snapshotUri));
                        break;
                    case DEACTIVATE_VOLUME_GROUP_SNAPSHOT:
                        TaskList cgTaskList = _blockConsistencyGroupService.deactivateConsistencyGroupSnapshot(cgUri, snapshotUri);
                        List<TaskResourceRep> taskResourceRepList = cgTaskList.getTaskList();
                        if (taskResourceRepList != null && !taskResourceRepList.isEmpty()) {
                            for (TaskResourceRep taskResRep : taskResourceRepList) {
                                taskList.addTask(taskResRep);
                            }
                        }
                        break;
                    default:
                        log.error("Unsupported operation {}", opType.getDescription());
                        break;
                }
            } catch (InternalException | APIException e) {
                log.error("Exception on {} for replication group {}: {}", opType.getDescription(), cell.getColumnKey(), e.getMessage());
            }
        }
    }
    auditOp(opType, true, AuditLogManager.AUDITOP_END, volumeGroupId.toString(), param.getSnapshots());
    return taskList;
}
Also used : TaskList(com.emc.storageos.model.TaskList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Entry(java.util.Map.Entry) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BlockSnapshotSessionList(com.emc.storageos.model.block.BlockSnapshotSessionList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) NamedVolumeGroupsList(com.emc.storageos.model.block.NamedVolumeGroupsList) HostList(com.emc.storageos.model.host.HostList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ClusterList(com.emc.storageos.model.host.cluster.ClusterList) VolumeGroupList(com.emc.storageos.model.application.VolumeGroupList) List(java.util.List) NamedVolumesList(com.emc.storageos.model.block.NamedVolumesList) VolumeGroupCopySetList(com.emc.storageos.model.application.VolumeGroupCopySetList) SnapshotList(com.emc.storageos.model.SnapshotList)

Example 44 with BlockSnapshot

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

the class VolumeGroupService method getUnlinkTargetIdsForSession.

/**
 * Gets the unlink target ids for the given session.
 *
 * @param param the VolumeGroupSnapshotSessionUnlinkTargetsParam
 * @param session the snap session
 * @return the unlink target id params for session
 */
private List<SnapshotSessionUnlinkTargetParam> getUnlinkTargetIdsForSession(final VolumeGroupSnapshotSessionUnlinkTargetsParam param, BlockSnapshotSession session) {
    List<SnapshotSessionUnlinkTargetParam> targetIds = new ArrayList<SnapshotSessionUnlinkTargetParam>();
    List<URI> selectedURIs = new ArrayList<URI>();
    StringSet sessionTargets = session.getLinkedTargets();
    if (param.getLinkedTargets() != null && !param.getLinkedTargets().isEmpty()) {
        for (SnapshotSessionUnlinkTargetParam unlinkTarget : param.getLinkedTargets()) {
            URI snapURI = unlinkTarget.getId();
            // Snapshot session targets are represented by BlockSnapshot instances in ViPR.
            ArgValidator.checkFieldUriType(snapURI, BlockSnapshot.class, "id");
            BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapURI);
            ArgValidator.checkEntityNotNull(snap, snapURI, isIdEmbeddedInURL(snapURI));
            if (sessionTargets != null && sessionTargets.contains(snapURI.toString())) {
                targetIds.add(unlinkTarget);
                selectedURIs.add(snapURI);
            }
        }
    } else {
        ArgValidator.checkFieldNotEmpty(param.getTargetName(), "target_name");
        for (String linkedTgtId : session.getLinkedTargets()) {
            URI snapURI = URI.create(linkedTgtId);
            BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapURI);
            if (StringUtils.equals(param.getTargetName(), snap.getSnapsetLabel())) {
                SnapshotSessionUnlinkTargetParam unlinkTarget = new SnapshotSessionUnlinkTargetParam();
                unlinkTarget.setId(snap.getId());
                unlinkTarget.setDeleteTarget(param.getDeleteTarget() == null ? false : param.getDeleteTarget());
                targetIds.add(unlinkTarget);
                selectedURIs.add(snapURI);
            }
        }
    }
    log.info(String.format("Target ids for snapshot session %s : %s", session.getLabel(), Joiner.on(',').join(selectedURIs)));
    if (targetIds.isEmpty()) {
        // None of the provided target belong to this snapshot session.
        throw APIException.badRequests.snapshotSessionDoesNotHaveAnyTargets(session.getId().toString());
    }
    return targetIds;
}
Also used : SnapshotSessionUnlinkTargetParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)

Example 45 with BlockSnapshot

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

the class VolumeGroupService method getVolumeGroupSnapshotSets.

/*
     * get all snapshot sets associated with the volume group
     */
private VolumeGroupCopySetList getVolumeGroupSnapshotSets(VolumeGroup volumeGroup) {
    // get all volumes
    List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
    VolumeGroupCopySetList copySetList = new VolumeGroupCopySetList();
    Set<String> copySets = copySetList.getCopySets();
    // get snapshots for each volume in the group
    for (Volume volume : volumes) {
        if (volume.isVPlexVolume(_dbClient)) {
            volume = VPlexUtil.getVPLEXBackendVolume(volume, true, _dbClient);
            if (volume == null || volume.getInactive()) {
                log.warn("Cannot find backend volume for VPLEX volume {}", volume.getLabel());
                continue;
            }
        }
        URIQueryResultList snapshotURIs = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeSnapshotConstraint(volume.getId()), snapshotURIs);
        if (!snapshotURIs.iterator().hasNext()) {
            continue;
        }
        List<BlockSnapshot> snapshots = _dbClient.queryObject(BlockSnapshot.class, snapshotURIs);
        for (BlockSnapshot snapshot : snapshots) {
            if (snapshot != null && !snapshot.getInactive()) {
                String snapsetLabel = snapshot.getSnapsetLabel();
                if (NullColumnValueGetter.isNotNullValue(snapsetLabel)) {
                    copySets.add(snapsetLabel);
                }
            }
        }
    }
    return copySetList;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VolumeGroupCopySetList(com.emc.storageos.model.application.VolumeGroupCopySetList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)401 Volume (com.emc.storageos.db.client.model.Volume)215 URI (java.net.URI)209 ArrayList (java.util.ArrayList)112 NamedURI (com.emc.storageos.db.client.model.NamedURI)110 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)106 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)91 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)63 BlockObject (com.emc.storageos.db.client.model.BlockObject)63 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)55 CIMObjectPath (javax.cim.CIMObjectPath)51 StringSet (com.emc.storageos.db.client.model.StringSet)49 HashMap (java.util.HashMap)48 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)46 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)41 WBEMException (javax.wbem.WBEMException)38 Produces (javax.ws.rs.Produces)36 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)35 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)33 Path (javax.ws.rs.Path)33