use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class VolumeGroupService method getVolumeGroupSnapshotsForSet.
/**
* List snapshots in a snapshot set for a volume group
*
* @prereq none
* @param volumeGroupId The URI of the volume group
* @brief List snapshots in snapshot set for a volume group
* @return SnapshotList
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/copy-sets")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public SnapshotList getVolumeGroupSnapshotsForSet(@PathParam("id") final URI volumeGroupId, final VolumeGroupCopySetParam param) {
// query volume group
final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
// validate replica operation for volume group
validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT);
// validate copy set name
String copySetName = param.getCopySetName();
ArgValidator.checkFieldNotEmpty(copySetName, COPY_SET_NAME_FIELD);
// get all volumes
List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
// get the snapshots for each volume in the group
SnapshotList snapshotList = new SnapshotList();
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());
}
}
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()) {
if (copySetName.equals(snapshot.getSnapsetLabel())) {
snapshotList.getSnapList().add(toNamedRelatedResource(snapshot));
}
}
}
}
return snapshotList;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class VolumeGroupService method getRelinkTargetIdsForSession.
/**
* Gets the relink target ids for the given session.
*
* @param param the VolumeGroupSnapshotSessionRelinkTargetsParam
* @param session the snap session
* @param numberOfRequestedSessions the number of requested sessions
* @return the relink target ids for session
*/
private List<URI> getRelinkTargetIdsForSession(final VolumeGroupSnapshotSessionRelinkTargetsParam param, BlockSnapshotSession session, int numberOfRequestedSessions) {
List<URI> targetIds = new ArrayList<URI>();
if (param.getLinkedTargetIds() != null && !param.getLinkedTargetIds().isEmpty() && numberOfRequestedSessions == 1) {
/**
* It could be a request from user to re-link targets to different snap sessions.
* So, don't filter given targets based on snap session.
*
* Re-linking different targets to a snap session can be done for only one
* Replication group at a time.
*/
targetIds = param.getLinkedTargetIds();
} else {
/**
* Re-link to same linked targets
*/
StringSet sessionTargets = session.getLinkedTargets();
if (param.getLinkedTargetIds() != null && !param.getLinkedTargetIds().isEmpty()) {
for (URI snapURI : param.getLinkedTargetIds()) {
// 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(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())) {
targetIds.add(snapURI);
}
}
}
}
log.info(String.format("Target ids for snapshot session %s : %s", session.getLabel(), Joiner.on(',').join(targetIds)));
if (targetIds.isEmpty()) {
// None of the provided target belong to this snapshot session.
throw APIException.badRequests.snapshotSessionDoesNotHaveAnyTargetsInGivenList(session.getId().toString());
}
return targetIds;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockIngestOrchestrator method decorateCGInfoInVolumes.
/**
* Decorates the BlockConsistencyGroup information in all other volumes ingested in the UnManagedConsistencyGroup
* managed objects.
*
* For each unmanaged volume in unmanaged cg,
* 1. We verify whether the BlockObject is available in the current createdBlockObjects in context or not.
* If it is available, then set the CG properties
* Else, verify in the current updatedBlockObjects in context.
* 2. If the blockObject is available in updateBlockObjects, then update CG properties.
* Else, blockObject might have ingested in previous requests, so, we should check from DB.
* If blockObject is in DB, update CG properties else log a warning message.
*
* @param cg - cg object
* @param blockObject - BlockObject to decorate
* @param requestContext - current context of unmanagedVolume
* @param unManagedVolume - current unmanagedVolume to ingest
*/
protected void decorateCGInfoInVolumes(BlockConsistencyGroup cg, BlockObject blockObject, IngestionRequestContext requestContext, UnManagedVolume unManagedVolume) {
UnManagedConsistencyGroup umcg = requestContext.findUnManagedConsistencyGroup(cg.getLabel());
Set<DataObject> blockObjectsToUpdate = new HashSet<DataObject>();
if (null != umcg && null != umcg.getManagedVolumesMap() && !umcg.getManagedVolumesMap().isEmpty()) {
for (Entry<String, String> managedVolumeEntry : umcg.getManagedVolumesMap().entrySet()) {
BlockObject bo = requestContext.getRootIngestionRequestContext().findCreatedBlockObject(managedVolumeEntry.getKey());
if (bo == null) {
// Next look in the updated objects.
bo = (BlockObject) requestContext.findInUpdatedObjects(URI.create(managedVolumeEntry.getKey()));
}
if (bo == null) {
// Finally look in the DB itself. It may be from a previous ingestion operation.
bo = BlockObject.fetch(_dbClient, URI.create(managedVolumeEntry.getValue()));
// If blockObject is still not exists
if (null == bo) {
_logger.warn("Volume {} is not yet ingested. Hence skipping", managedVolumeEntry.getKey());
continue;
}
blockObjectsToUpdate.add(bo);
}
bo.setConsistencyGroup(cg.getId());
// Set the replication group instance only if it is not already populated during the block object's ingestion.
if (bo.getReplicationGroupInstance() == null || bo.getReplicationGroupInstance().isEmpty()) {
bo.setReplicationGroupInstance(cg.getLabel());
}
}
if (!blockObjectsToUpdate.isEmpty()) {
requestContext.getDataObjectsToBeUpdatedMap().put(unManagedVolume.getNativeGuid(), blockObjectsToUpdate);
}
}
blockObject.setConsistencyGroup(cg.getId());
blockObject.setReplicationGroupInstance(cg.getLabel());
if (blockObject instanceof BlockSnapshot) {
// Check if the unmanaged volume has SNAPSHOT_CONSISTENCY_GROUP_NAME property populated. If yes,
// use that for replicationGroupInstance
String snapsetName = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.SNAPSHOT_CONSISTENCY_GROUP_NAME.toString(), unManagedVolume.getVolumeInformation());
if (snapsetName != null && !snapsetName.isEmpty()) {
blockObject.setReplicationGroupInstance(snapsetName);
}
}
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapIngestOrchestrator method ingestBlockObjects.
@Override
public <T extends BlockObject> T ingestBlockObjects(IngestionRequestContext requestContext, Class<T> clazz) throws IngestionException {
UnManagedVolume unManagedVolume = requestContext.getCurrentUnmanagedVolume();
boolean unManagedVolumeExported = requestContext.getVolumeContext().isVolumeExported();
BlockSnapshot snapShot = null;
String snapNativeGuid = unManagedVolume.getNativeGuid().replace(NativeGUIDGenerator.UN_MANAGED_VOLUME, NativeGUIDGenerator.VOLUME);
snapShot = VolumeIngestionUtil.checkSnapShotExistsInDB(snapNativeGuid, _dbClient);
// Check if ingested volume has exportmasks pending for ingestion.
if (isExportIngestionPending(snapShot, unManagedVolume.getId(), unManagedVolumeExported)) {
return clazz.cast(snapShot);
}
if (null == snapShot) {
// @TODO Need to revisit this. In 8.x provider, Replication Group is
// automatically created when a volume is associated to a
// StorageGroup.
// checkUnManagedVolumeAddedToCG(unManagedVolume, virtualArray,
// tenant, project, vPool);
checkVolumeExportState(unManagedVolume, unManagedVolumeExported);
VolumeIngestionUtil.checkUnManagedResourceIngestable(unManagedVolume);
snapShot = createSnapshot(requestContext, snapNativeGuid);
// See if this is a linked target for existing block snapshot sessions.
if (!NullColumnValueGetter.isNullValue(snapShot.getSettingsInstance())) {
URIQueryResultList queryResults = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getBlockSnapshotSessionBySessionInstance(snapShot.getSettingsInstance()), queryResults);
Iterator<URI> queryResultsIter = queryResults.iterator();
while (queryResultsIter.hasNext()) {
BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, queryResultsIter.next());
StringSet linkedTargets = snapSession.getLinkedTargets();
if ((linkedTargets != null)) {
linkedTargets.add(snapShot.getId().toString());
} else {
linkedTargets = new StringSet();
linkedTargets.add(snapShot.getId().toString());
snapSession.setLinkedTargets(linkedTargets);
}
_dbClient.updateObject(snapSession);
}
}
}
// Run this logic always when Volume is NO_PUBLIC_ACCESS
if (markUnManagedVolumeInactive(requestContext, snapShot)) {
_logger.info("All the related replicas and parent of unManagedVolume {} has been ingested ", unManagedVolume.getNativeGuid());
// mark inactive if this is not to be exported. Else, mark as inactive after successful export
if (!unManagedVolumeExported) {
unManagedVolume.setInactive(true);
requestContext.getUnManagedVolumesToBeDeleted().add(unManagedVolume);
}
} else {
_logger.info("Not all the parent/replicas of unManagedVolume {} have been ingested , hence marking as internal", unManagedVolume.getNativeGuid());
snapShot.addInternalFlags(INTERNAL_VOLUME_FLAGS);
}
return clazz.cast(snapShot);
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapIngestOrchestrator method createSnapshot.
private BlockSnapshot createSnapshot(IngestionRequestContext requestContext, String nativeGuid) throws IngestionException {
UnManagedVolume unManagedVolume = requestContext.getCurrentUnmanagedVolume();
BlockSnapshot snapShot = new BlockSnapshot();
snapShot.setId(URIUtil.createId(BlockSnapshot.class));
snapShot.setNativeGuid(nativeGuid);
updateBlockObjectNativeIds(snapShot, unManagedVolume);
StringSetMap unManagedVolumeInformation = unManagedVolume.getVolumeInformation();
String deviceLabel = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.DEVICE_LABEL.toString(), unManagedVolumeInformation);
if (null == deviceLabel || deviceLabel.trim().isEmpty()) {
deviceLabel = nativeGuid;
}
// In case of XIO snaps, the snapshots belong to a snapset which represents the snapshot CG. This will be
// populated in SNAPSHOT_CONSISTENCY_GROUP_NAME
// The same is applicable to external device snapshots
String snapsetName = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.SNAPSHOT_CONSISTENCY_GROUP_NAME.toString(), unManagedVolumeInformation);
if (null == snapsetName || snapsetName.trim().isEmpty()) {
snapsetName = deviceLabel;
}
snapShot.setSnapsetLabel(snapsetName);
snapShot.setStorageController(requestContext.getStorageSystem().getId());
String systemType = requestContext.getStorageSystem().checkIfVmax3() ? DiscoveredDataObject.Type.vmax3.name() : requestContext.getStorageSystem().getSystemType();
snapShot.setSystemType(systemType);
snapShot.setVirtualArray(requestContext.getVarray(unManagedVolume).getId());
snapShot.setProject(new NamedURI(requestContext.getProject().getId(), snapShot.getLabel()));
snapShot.setWWN(unManagedVolume.getWwn());
String allocatedCapacity = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.ALLOCATED_CAPACITY.toString(), unManagedVolume.getVolumeInformation());
String provisionedCapacity = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.PROVISIONED_CAPACITY.toString(), unManagedVolume.getVolumeInformation());
snapShot.setAllocatedCapacity(Long.parseLong(allocatedCapacity));
snapShot.setProvisionedCapacity(Long.parseLong(provisionedCapacity));
String syncActive = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.IS_SYNC_ACTIVE.toString(), unManagedVolume.getVolumeInformation());
Boolean isSyncActive = (null != syncActive) ? Boolean.parseBoolean(syncActive) : false;
snapShot.setIsSyncActive(isSyncActive);
String readOnly = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.IS_READ_ONLY.toString(), unManagedVolume.getVolumeInformation());
Boolean isReadOnly = (null != readOnly) ? Boolean.parseBoolean(readOnly) : false;
snapShot.setIsReadOnly(isReadOnly);
String settingsInstance = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.SETTINGS_INSTANCE.toString(), unManagedVolume.getVolumeInformation());
snapShot.setSettingsInstance(settingsInstance);
String needsCopyToTarget = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.NEEDS_COPY_TO_TARGET.toString(), unManagedVolumeInformation);
Boolean isNeedsCopyToTarget = (null != needsCopyToTarget) ? Boolean.parseBoolean(needsCopyToTarget) : false;
snapShot.setNeedsCopyToTarget(isNeedsCopyToTarget);
String techType = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.TECHNOLOGY_TYPE.toString(), unManagedVolumeInformation);
snapShot.setTechnologyType(techType);
BlockConsistencyGroup cg = getConsistencyGroup(unManagedVolume, snapShot, requestContext, _dbClient);
if (null != cg) {
requestContext.getVolumeContext().getCGObjectsToCreateMap().put(cg.getLabel(), cg);
decorateCGInfoInVolumes(cg, snapShot, requestContext, unManagedVolume);
}
return snapShot;
}
Aggregations