use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class VolumeIngestionUtil method setupSnapParentRelations.
/**
* Setup relationships between a snapshot and its parent BlockObject.
*
* @param snapshot the snapshot BlockObject
* @param parentVolume the snapshot's parent BlockObject
* @param dbClient a reference to the database client
*/
public static void setupSnapParentRelations(BlockObject snapshot, BlockObject parentVolume, DbClient dbClient) {
_logger.info("Setting up relationship between snapshot {} ({}) and parent {} ({})", new Object[] { snapshot.getLabel(), snapshot.getId(), parentVolume.getLabel(), parentVolume.getId() });
((BlockSnapshot) snapshot).setSourceNativeId(parentVolume.getNativeId());
((BlockSnapshot) snapshot).setParent(new NamedURI(parentVolume.getId(), parentVolume.getLabel()));
snapshot.setProtocol(new StringSet());
snapshot.getProtocol().addAll(parentVolume.getProtocol());
URI cgUri = parentVolume.getConsistencyGroup();
// Do not associate parent's CG if it is a RP protected parent volume
boolean isRP = (parentVolume instanceof Volume && ((Volume) parentVolume).checkForRp()) || (parentVolume instanceof BlockSnapshot && ((BlockSnapshot) parentVolume).getProtectionController() != null);
if (!isRP && cgUri != null) {
snapshot.setConsistencyGroup(cgUri);
}
// TODO - check how to populate snapsetlabel if in consistency group
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class VolumeIngestionUtil method clearReplicaFlagsInIngestionContext.
/**
* Clear the flags of replicas which have been updated during the ingestion process
*
* @param requestContext current unManagedVolume Ingestion context.
* @param volumes RP volumes
* @param dbClient database client
*/
public static void clearReplicaFlagsInIngestionContext(IngestionRequestContext requestContext, List<Volume> volumes, DbClient dbClient) {
// We need to look for all snapshots and snapshot session in the contexts related to the rp volumes and its backend volumes and
// clear their flags.
_logger.info("Clearing flags of replicas in the context");
List<String> rpVolumes = new ArrayList<String>();
for (Volume volume : volumes) {
rpVolumes.add(volume.getId().toString());
if (RPHelper.isVPlexVolume(volume, dbClient) && volume.getAssociatedVolumes() != null && !volume.getAssociatedVolumes().isEmpty()) {
StringSet associatedVolumes = volume.getAssociatedVolumes();
rpVolumes.addAll(associatedVolumes);
}
}
for (VolumeIngestionContext volumeIngestionContext : requestContext.getRootIngestionRequestContext().getProcessedUnManagedVolumeMap().values()) {
if (volumeIngestionContext instanceof IngestionRequestContext) {
for (Set<DataObject> objectsToBeUpdated : ((IngestionRequestContext) volumeIngestionContext).getDataObjectsToBeUpdatedMap().values()) {
for (DataObject o : objectsToBeUpdated) {
boolean rpBlockSnapshot = (o instanceof BlockSnapshot && rpVolumes.contains(((BlockSnapshot) o).getParent().getURI().toString()));
boolean rpBlockSnapshotSession = (o instanceof BlockSnapshotSession && rpVolumes.contains(((BlockSnapshotSession) o).getParent().getURI().toString()));
if (rpBlockSnapshot || rpBlockSnapshotSession) {
_logger.info(String.format("Clearing internal volume flag of %s %s of RP volume ", (rpBlockSnapshot ? "BlockSnapshot" : "BlockSnapshotSession"), o.getLabel()));
o.clearInternalFlags(BlockIngestOrchestrator.INTERNAL_VOLUME_FLAGS);
}
}
}
}
}
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class VolumeIngestionUtil method clearSnapshotsFlags.
/**
* Clear the flags of the snapshots of the RP volume
*
* @param requestContext current unManagedVolume Ingestion context.
* @param volumes the Volume Objects to clear flags on
* @param updatedObjects a Set of DataObjects to be updated in the database at the end of ingestion
* @param dbClient - dbClient reference.
*/
public static void clearSnapshotsFlags(IngestionRequestContext requestContext, Volume volume, Set<DataObject> updatedObjects, DbClient dbClient) {
URIQueryResultList snapshotURIs = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeSnapshotConstraint(volume.getId()), snapshotURIs);
Iterator<BlockSnapshot> snapshotsIterator = dbClient.queryIterativeObjects(BlockSnapshot.class, snapshotURIs);
while (snapshotsIterator.hasNext()) {
BlockSnapshot snap = snapshotsIterator.next();
_logger.info("Clearing internal volume flag of snapshot {} of RP volume {}", snap.getLabel(), volume.getLabel());
snap.clearInternalFlags(BlockIngestOrchestrator.INTERNAL_VOLUME_FLAGS);
updatedObjects.add(snap);
}
// clear the flags of any snapshots created in the context
for (BlockObject createdObject : requestContext.getBlockObjectsToBeCreatedMap().values()) {
if (createdObject instanceof BlockSnapshot) {
BlockSnapshot snapshot = (BlockSnapshot) createdObject;
if (snapshot.getParent() != null && volume.getId().equals(snapshot.getParent().getURI())) {
_logger.info("Clearing internal volume flag of snapshot {} of RP volume {}", snapshot.getLabel(), volume.getLabel());
snapshot.clearInternalFlags(BlockIngestOrchestrator.INTERNAL_VOLUME_FLAGS);
}
}
}
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockDeviceController method restoreVolumeStep.
public boolean restoreVolumeStep(URI storage, URI pool, URI volume, URI snapshot, Boolean updateOpStatus, String opId) throws ControllerException {
TaskCompleter completer = null;
try {
StorageSystem storageDevice = _dbClient.queryObject(StorageSystem.class, storage);
BlockSnapshot snapObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
completer = new BlockSnapshotRestoreCompleter(snapObj, opId, updateOpStatus);
getDevice(storageDevice.getSystemType()).doRestoreFromSnapshot(storageDevice, volume, snapshot, completer);
} catch (Exception e) {
_log.error(String.format("restoreVolume failed - storage: %s, pool: %s, volume: %s, snapshot: %s", storage.toString(), pool.toString(), volume.toString(), snapshot.toString()));
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
completer.error(_dbClient, serviceError);
doFailTask(BlockSnapshot.class, snapshot, opId, serviceError);
WorkflowStepCompleter.stepFailed(opId, serviceError);
return false;
}
return true;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockDeviceController method rollbackListSnapshot.
public void rollbackListSnapshot(URI storage, List<URI> snapshotList, String taskId) {
WorkflowStepCompleter.stepExecuting(taskId);
try {
List<BlockSnapshot> snapshotsNoRollback = new ArrayList<BlockSnapshot>();
List<BlockSnapshot> snapshotsToRollback = new ArrayList<BlockSnapshot>();
Iterator<BlockSnapshot> itr = _dbClient.queryIterativeObjects(BlockSnapshot.class, snapshotList);
while (itr.hasNext()) {
BlockSnapshot snapshot = itr.next();
if (snapshot != null && !snapshot.getInactive()) {
if (isNullOrEmpty(snapshot.getNativeId())) {
snapshot.setInactive(true);
snapshotsNoRollback.add(snapshot);
} else {
snapshotsToRollback.add(snapshot);
}
}
}
if (!snapshotsNoRollback.isEmpty()) {
_dbClient.updateObject(snapshotsNoRollback);
}
if (!snapshotsToRollback.isEmpty()) {
List<URI> snapshotURIsToRollback = new ArrayList<URI>(transform(snapshotsToRollback, fctnDataObjectToID()));
String snapshotNativeIds = Joiner.on(", ").join(transform(snapshotsToRollback, fctnBlockObjectToNativeID()));
_log.info("Attempting to delete {} for rollback", snapshotNativeIds);
for (URI snapshotURI : snapshotURIsToRollback) {
deleteSelectedSnapshot(storage, snapshotURI, generateStepIdForDependentCallDuringRollback());
}
}
WorkflowStepCompleter.stepSucceded(taskId);
} catch (InternalException ie) {
_log.error(String.format("rollbackListSnapshot failed - Array:%s, Snapshots:%s", storage, Joiner.on("\t").join(snapshotList)));
doFailTask(BlockSnapshot.class, snapshotList, taskId, ie);
WorkflowStepCompleter.stepFailed(taskId, ie);
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(taskId, serviceError);
doFailTask(BlockSnapshot.class, snapshotList, taskId, serviceError);
}
}
Aggregations