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());
}
}
}
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations