use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapshotDeleteCompleter method createCompleter.
/**
* This method is for creating the BlockSnapshotDeleteCompleter. This a bit unique from
* the other completers because of the way that we need to complete the task. For the
* case of CG snapshots, there will be multiple BlockSnapshots associated, even though
* the request to delete the snapshot was against only one of the CG snaps. Here we will
* make sure that the task completer has references to all the CG snaps, so that they
* can be referred to in the completer. Main reason is that if a BlockSnapshot is marked
* inactive, it can no longer be retrieved using AltIndex queries.
*
* @param dbClient [in] - DbClient for querying ViPR DB
* @param snapshot [in] - BlockSnapshot object
* @param task [in] - Task UUID for the snapshot delete operation
* @return a new BlockSnapshotDeleteCompleter object
*/
public static BlockSnapshotDeleteCompleter createCompleter(DbClient dbClient, BlockSnapshot snapshot, String task) {
BlockSnapshotDeleteCompleter completer = new BlockSnapshotDeleteCompleter(snapshot, task);
if (snapshot.getConsistencyGroup() != null) {
// For snapshot based on a consistency group, set status and send
// events for all related snaps
List<URI> snapIds = new ArrayList<URI>();
List<BlockSnapshot> snaps = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, dbClient);
for (BlockSnapshot snap : snaps) {
snapIds.add(snap.getId());
}
completer.addIds(snapIds);
}
return completer;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapshotRestoreCompleter method complete.
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
try {
BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, getId());
Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
if (_updateAndRecordOp) {
if (snapshot.getConsistencyGroup() != null) {
// For snapshot based on a consistency group, set status and send
// events for all related snaps
List<BlockSnapshot> snaps = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, dbClient);
for (BlockSnapshot snap : snaps) {
URI uri = snap.getId();
BlockSnapshot it = dbClient.queryObject(BlockSnapshot.class, uri);
switch(status) {
case error:
dbClient.error(BlockSnapshot.class, uri, getOpId(), coded);
break;
default:
dbClient.ready(BlockSnapshot.class, uri, getOpId());
}
recordBlockSnapshotOperation(dbClient, OperationTypeEnum.RESTORE_VOLUME_SNAPSHOT, status, eventMessage(status, volume, it), it, volume);
_log.info(String.format("Completed CG snapshot restore of snap %s (%s), with status %s", it.getLabel(), uri.toString(), status.name()));
}
} else {
switch(status) {
case error:
dbClient.error(BlockSnapshot.class, getId(), getOpId(), coded);
break;
default:
dbClient.ready(BlockSnapshot.class, getId(), getOpId());
}
recordBlockSnapshotOperation(dbClient, OperationTypeEnum.RESTORE_VOLUME_SNAPSHOT, status, eventMessage(status, volume, snapshot), snapshot, volume);
}
}
_log.info("Done SnapshotRestore {}, with Status: {}", getOpId(), status.name());
super.complete(dbClient, status, coded);
} catch (Exception e) {
_log.error("Failed updating status. SnapshotRestore {}, for task " + getOpId(), getId(), e);
}
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapshotResyncCompleter method complete.
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
try {
BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, getId());
Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
if (_updateAndRecordOp) {
if (snapshot.getConsistencyGroup() != null) {
// For snapshot based on a consistency group, set status and send
// events for all related snaps
List<BlockSnapshot> snaps = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, dbClient);
for (BlockSnapshot snap : snaps) {
URI uri = snap.getId();
BlockSnapshot it = dbClient.queryObject(BlockSnapshot.class, uri);
switch(status) {
case error:
dbClient.error(BlockSnapshot.class, uri, getOpId(), coded);
break;
default:
dbClient.ready(BlockSnapshot.class, uri, getOpId());
}
recordBlockSnapshotOperation(dbClient, OperationTypeEnum.RESYNCHRONIZE_VOLUME_SNAPSHOT, status, eventMessage(status, volume, it), it, volume);
_log.info(String.format("Completed CG snapshot resynchronization of snap %s (%s), with status %s", it.getLabel(), uri.toString(), status.name()));
}
} else {
switch(status) {
case error:
dbClient.error(BlockSnapshot.class, getId(), getOpId(), coded);
break;
default:
dbClient.ready(BlockSnapshot.class, getId(), getOpId());
}
recordBlockSnapshotOperation(dbClient, OperationTypeEnum.RESYNCHRONIZE_VOLUME_SNAPSHOT, status, eventMessage(status, volume, snapshot), snapshot, volume);
}
}
_log.info("Done Resync Snapshot {}, with Status: {}", getOpId(), status.name());
super.complete(dbClient, status, coded);
} catch (Exception e) {
_log.error("Failed updating status. SnapshotResync {}, for task " + getOpId(), getId(), e);
}
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionCompleter method getAllSnapshots.
/**
* When this completer is handling multiple snapshots from different replication groups,
* this method gathers all related snapshots for each snapshot and returns them in a list.
*
* @param dbClient Database client.
* @return List of all snapshots, including each of their related snapshots.
*/
public List<BlockSnapshot> getAllSnapshots(DbClient dbClient) {
List<BlockSnapshot> result = new ArrayList<>();
Iterator<BlockSnapshot> iterator = dbClient.queryIterativeObjects(BlockSnapshot.class, _snapshotURIs);
while (iterator.hasNext()) {
BlockSnapshot snapshot = iterator.next();
result.addAll(getRelatedSnapshots(snapshot, dbClient));
}
return result;
}
use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionCreateCompleter method complete.
/**
* {@inheritDoc}
*/
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
try {
BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, getId());
// Update the status map of the snapshot session.
switch(status) {
case error:
// Mark any linked targets inactive. This would not
// normally case when failing to create a snapshot
// session as targets are not linked when a new
// snapshot session is prepared in ViPR. However,
// it could be the case when restoring a source volume
// form a linked target.
StringSet linkedTargets = snapSession.getLinkedTargets();
if ((linkedTargets != null) && (!linkedTargets.isEmpty())) {
for (String linkedTarget : linkedTargets) {
BlockSnapshot target = dbClient.queryObject(BlockSnapshot.class, URI.create(linkedTarget));
if (target != null) {
target.setInactive(true);
dbClient.updateObject(target);
}
}
}
// Mark ViPR snapshot session inactive on error.
snapSession.setInactive(true);
dbClient.updateObject(snapSession);
break;
case ready:
break;
default:
String errMsg = String.format("Unexpected status %s for completer for step %s", status.name(), getOpId());
s_logger.info(errMsg);
throw DeviceControllerException.exceptions.unexpectedCondition(errMsg);
}
s_logger.info("Done snapshot session create step {} with status: {}", getOpId(), status.name());
} catch (Exception e) {
s_logger.error("Failed updating status for snapshot session create step {}", getOpId(), e);
} finally {
super.complete(dbClient, status, coded);
}
}
Aggregations