use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.
the class VmaxSnapshotOperations method restoreSnapshotSession.
/**
* {@inheritDoc}
*/
@SuppressWarnings("rawtypes")
@Override
public void restoreSnapshotSession(StorageSystem system, URI snapSessionURI, TaskCompleter completer) throws DeviceControllerException {
if (system.checkIfVmax3()) {
// Only supported for VMAX3 storage systems.
try {
_log.info("Restore snapshot session {} START", snapSessionURI);
BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
String syncAspectPath = snapSession.getSessionInstance();
CIMObjectPath settingsStatePath = null;
BlockObject sourceObj = null;
if (snapSession.hasConsistencyGroup() && NullColumnValueGetter.isNotNullValue(snapSession.getReplicationGroupInstance())) {
_log.info("Restoring group snapshot session");
// We need a single source volume for the session.
BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, snapSession.getConsistencyGroup());
List<Volume> nativeVolumes = BlockConsistencyGroupUtils.getActiveNativeVolumesInCG(cg, _dbClient);
// get source group name from the session.
String sourceGroupName = snapSession.getReplicationGroupInstance();
settingsStatePath = _cimPath.getGroupSynchronizedSettingsPath(system, sourceGroupName, syncAspectPath);
for (Volume volume : nativeVolumes) {
if (sourceGroupName.equals(volume.getReplicationGroupInstance())) {
sourceObj = volume;
// get source volume which matches session's RG name
break;
}
}
} else {
_log.info("Restoring single volume snapshot session");
sourceObj = BlockObject.fetch(_dbClient, snapSession.getParent().getURI());
CIMObjectPath sourcePath = _cimPath.getVolumePath(system, sourceObj.getNativeId());
settingsStatePath = _cimPath.getSyncSettingsPath(system, sourcePath, syncAspectPath);
}
// Terminate restore sessions.
terminateAnyRestoreSessions(system, null, sourceObj.getId(), completer);
// Invoke SMI-S method to restore snapshot session.
CIMObjectPath replicationSvcPath = _cimPath.getControllerReplicationSvcPath(system);
CIMArgument[] inArgs = null;
CIMArgument[] outArgs = new CIMArgument[5];
inArgs = _helper.getRestoreFromSettingsStateInputArguments(settingsStatePath, true);
_helper.invokeMethod(system, replicationSvcPath, SmisConstants.MODIFY_SETTINGS_DEFINE_STATE, inArgs, outArgs);
CIMObjectPath jobPath = _cimPath.getCimObjectPathFromOutputArgs(outArgs, SmisConstants.JOB);
ControllerServiceImpl.enqueueJob(new QueueJob(new SmisBlockSnapshotSessionRestoreJob(jobPath, system.getId(), completer)));
} catch (Exception e) {
_log.error("Exception restoring snapshot session", e);
ServiceError error = DeviceControllerErrors.smis.unableToCallStorageProvider(e.getMessage());
completer.error(_dbClient, error);
}
} else {
throw DeviceControllerException.exceptions.blockDeviceOperationNotSupported();
}
}
use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.
the class SmisBlockSnapshotSessionCGCreateJob method updateStatus.
@Override
public void updateStatus(JobContext jobContext) throws Exception {
JobStatus jobStatus = getJobStatus();
CloseableIterator<CIMObjectPath> syncAspectIter = null;
CloseableIterator<CIMObjectPath> settingsStateIter = null;
try {
DbClient dbClient = jobContext.getDbClient();
if (jobStatus == JobStatus.IN_PROGRESS) {
return;
}
if (jobStatus == JobStatus.SUCCESS) {
log.info("Post-processing successful snapshot session group creation for task ", getTaskCompleter().getOpId());
// Get the snapshot sessions.
Iterator<BlockSnapshotSession> iterator = dbClient.queryIterativeObjects(BlockSnapshotSession.class, getTaskCompleter().getIds(), true);
List<BlockSnapshotSession> snapSessions = Lists.newArrayList(iterator);
// Update Settings instance for the session.
CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
syncAspectIter = client.associatorNames(getCimJob(), null, SmisConstants.SYMM_SYNCHRONIZATION_ASPECT_FOR_SOURCE_GROUP, null, null);
if (syncAspectIter.hasNext()) {
CIMObjectPath syncAspectPath = syncAspectIter.next();
String instanceId = syncAspectPath.getKeyValue(Constants.INSTANCEID).toString();
log.info("SynchronizationAspectForSourceGroup instance id is {}", instanceId);
for (BlockSnapshotSession snapSession : snapSessions) {
snapSession.setSessionInstance(instanceId);
}
dbClient.updateObject(snapSessions);
}
} else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
log.info("Failed to create snapshot session for task ", getTaskCompleter().getOpId());
}
} catch (Exception e) {
setPostProcessingErrorStatus("Encountered an internal error in create snapshot session job status processing: " + e.getMessage());
log.error("Encountered an internal error in create snapshot session job status processing", e);
} finally {
if (syncAspectIter != null) {
syncAspectIter.close();
}
if (settingsStateIter != null) {
settingsStateIter.close();
}
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.
the class SmisBlockSnapshotSessionCreateJob method updateStatus.
/**
* {@inheritDoc}
*/
@Override
public void updateStatus(JobContext jobContext) throws Exception {
JobStatus jobStatus = getJobStatus();
CloseableIterator<CIMObjectPath> syncAspectIter = null;
CloseableIterator<CIMObjectPath> settingsStateIter = null;
try {
DbClient dbClient = jobContext.getDbClient();
if (jobStatus == JobStatus.IN_PROGRESS) {
return;
}
if (jobStatus == JobStatus.SUCCESS) {
s_logger.info("Post-processing successful snapshot session creation for task ", getTaskCompleter().getOpId());
// Get the snapshot session.
BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, getTaskCompleter().getId());
// Update Settings instance for the session.
CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
syncAspectIter = client.associatorNames(getCimJob(), null, SmisConstants.SYMM_SYNCHRONIZATION_ASPECT_FOR_SOURCE, null, null);
if (syncAspectIter.hasNext()) {
CIMObjectPath syncAspectPath = syncAspectIter.next();
String instanceId = syncAspectPath.getKeyValue(Constants.INSTANCEID).toString();
s_logger.info("SynchronizationAspect instance id is {}", instanceId);
snapSession.setSessionInstance(instanceId);
dbClient.updateObject(snapSession);
}
} else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
s_logger.info("Failed to create snapshot session for task ", getTaskCompleter().getOpId());
}
} catch (Exception e) {
setPostProcessingErrorStatus("Encountered an internal error in create snapshot session job status processing: " + e.getMessage());
s_logger.error("Encountered an internal error in create snapshot session job status processing", e);
} finally {
if (syncAspectIter != null) {
syncAspectIter.close();
}
if (settingsStateIter != null) {
settingsStateIter.close();
}
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.
the class SmisCreateListReplicaJob method updateSnapshotSessionLinkedTargets.
/**
* If the snapshot is found to be part of a ReplicationGroup containing linked targets to
* an existing BlockSnapshotSession, we must update it with the ID of this snapshot.
*
* @param snapshot BlockSnapshot being added
* @param dbClient Database client
*/
private void updateSnapshotSessionLinkedTargets(BlockSnapshot snapshot, DbClient dbClient) {
List<BlockSnapshot> snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, dbClient);
if (snapshots == null || snapshots.isEmpty()) {
return;
}
// Check if existing ReplicationGroup members are linked targets for a BlockSnapshotSession
for (BlockSnapshot existing : snapshots) {
List<BlockSnapshotSession> sessions = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getLinkedTargetSnapshotSessionConstraint(existing.getId()));
if (!sessions.isEmpty()) {
BlockSnapshotSession session = sessions.get(0);
session.getLinkedTargets().add(snapshot.getId().toString());
dbClient.updateObject(session);
break;
}
}
}
use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.
the class SRDFUtils method CheckIfVolumeHasReplica.
/**
* Checks if a volume has snapshot, snapshot session, or clone or mirror associated.
*/
private boolean CheckIfVolumeHasReplica(Volume volume) {
boolean forceAdd = false;
URI volumeURI = volume.getId();
URIQueryResultList list = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeSnapshotConstraint(volumeURI), list);
Iterator<URI> it = list.iterator();
while (it.hasNext()) {
URI snapshotID = it.next();
BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotID);
if (snapshot != null) {
log.debug("There are Snapshot(s) available for volume {}", volumeURI);
forceAdd = true;
break;
}
}
// Check snapshot sessions also.
if (!forceAdd) {
List<BlockSnapshotSession> snapSessions = queryActiveResourcesByConstraint(dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(volumeURI));
if (!snapSessions.isEmpty()) {
log.debug("There are snapshot sessions available on volume {}", volumeURI);
forceAdd = true;
}
}
if (!forceAdd) {
// TODO ignore DETACHED clones?
URIQueryResultList cloneList = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getAssociatedSourceVolumeConstraint(volumeURI), cloneList);
Iterator<URI> iter = cloneList.iterator();
while (iter.hasNext()) {
URI cloneID = iter.next();
Volume clone = dbClient.queryObject(Volume.class, cloneID);
if (clone != null) {
log.debug("There are Clone(s) available for volume {}", volumeURI);
forceAdd = true;
break;
}
}
}
if (!forceAdd) {
URIQueryResultList mirrorList = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeBlockMirrorConstraint(volumeURI), mirrorList);
Iterator<URI> itr = mirrorList.iterator();
while (itr.hasNext()) {
URI mirrorID = itr.next();
BlockMirror mirror = dbClient.queryObject(BlockMirror.class, mirrorID);
if (mirror != null) {
log.debug("There are Mirror(s) available for volume {}", volumeURI);
forceAdd = true;
break;
}
}
}
return forceAdd;
}
Aggregations