use of com.emc.storageos.db.client.model.OpStatusMap in project coprhd-controller by CoprHD.
the class VPlexDeviceController method findPromotedVolumeForMirror.
private Volume findPromotedVolumeForMirror(URI vplexMirrorURI, List<URI> promotees) {
VplexMirror mirror = _dbClient.queryObject(VplexMirror.class, vplexMirrorURI);
List<Volume> promotedVolumes = _dbClient.queryObject(Volume.class, promotees);
for (Volume promotee : promotedVolumes) {
OpStatusMap statusMap = promotee.getOpStatus();
for (Map.Entry<String, Operation> entry : statusMap.entrySet()) {
Operation operation = entry.getValue();
if (operation.getAssociatedResourcesField().contains(mirror.getId().toString())) {
return promotee;
}
}
}
throw new IllegalStateException("No volume available for the promotion of mirror " + mirror.getId());
}
use of com.emc.storageos.db.client.model.OpStatusMap in project coprhd-controller by CoprHD.
the class VNXeBlockRestoreSnapshotJob method updateStatus.
public void updateStatus(JobContext jobContext) throws Exception {
DbClient dbClient = jobContext.getDbClient();
try {
if (_status == JobStatus.IN_PROGRESS) {
return;
}
String opId = getTaskCompleter().getOpId();
_logger.info(String.format("Updating status of job %s to %s", opId, _status.name()));
URI snapId = getTaskCompleter().getId();
BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapId);
StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
if (_status == JobStatus.SUCCESS && snapshotObj != null) {
VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
ParametersOut output = vnxeJob.getParametersOut();
// get the id of the backup snapshot created before restore operation
String backUpSnapId = output.getBackup().getId();
if (snapshotObj.getConsistencyGroup() != null) {
VNXeLunGroupSnap backupSnap = vnxeApiClient.getLunGroupSnapshot(backUpSnapId);
List<VNXeLun> groupLuns = vnxeApiClient.getLunByStorageResourceId(backupSnap.getStorageResource().getId());
// Create a snapshot corresponding to the backup snap for each volume in the consistency group
URI cgID = snapshotObj.getConsistencyGroup();
List<Volume> cgVolumes = getCGVolumes(cgID.toString(), dbClient);
final List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
for (Volume vol : cgVolumes) {
final BlockSnapshot newSnap = getSnapshotFromVol(vol, backupSnap.getName());
newSnap.setOpStatus(new OpStatusMap());
snapshotList.add(newSnap);
volumeToSnapMap.put(vol.getNativeId(), newSnap);
}
// Add vnxe information to the new snapshots
for (VNXeLun groupLun : groupLuns) {
BlockSnapshot snapshot = volumeToSnapMap.get(groupLun.getId());
if (snapshot == null) {
_logger.info("No snapshot found for the vnxe lun - ", groupLun.getId());
continue;
}
snapshot.setNativeId(backUpSnapId);
snapshot.setReplicationGroupInstance(backUpSnapId);
processSnapshot(snapshot, storage, groupLun, dbClient);
}
dbClient.createObject(snapshotList);
} else {
VNXeLunSnap backupSnap = vnxeApiClient.getLunSnapshot(backUpSnapId);
VNXeLun lun = vnxeApiClient.getLun(backupSnap.getLun().getId());
Volume vol = dbClient.queryObject(Volume.class, snapshotObj.getParent());
final BlockSnapshot newSnap = getSnapshotFromVol(vol, backupSnap.getName());
newSnap.setNativeId(backUpSnapId);
processSnapshot(newSnap, storage, lun, dbClient);
}
getTaskCompleter().ready(dbClient);
} else if (_status == JobStatus.FAILED && snapshotObj != null) {
_logger.info(String.format("Task %s failed to restore volume snapshot: %s", opId, snapshotObj.getLabel()));
}
} catch (Exception e) {
_logger.error("Caught an exception while trying to updateStatus for VNXeBlockRestoreSnapshotJob", e);
setErrorStatus("Encountered an internal error during snapshot restore job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.db.client.model.OpStatusMap in project coprhd-controller by CoprHD.
the class VNXeRestoreFileSystemSnapshotJob method syncSnapshots.
private void syncSnapshots(DbClient dbClient, FileShare fsObj, VNXeApiClient vnxeApiClient) {
// Retrieve all snapshots from DB that belong to this file system
URIQueryResultList results = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(fsObj.getId()), results);
// Setup snapshot name-object map
Map<String, Snapshot> snapshotsInDB = new ConcurrentHashMap<String, Snapshot>();
while (results.iterator().hasNext()) {
URI uri = results.iterator().next();
Snapshot snap = dbClient.queryObject(Snapshot.class, uri);
String nativeId = snap.getNativeId();
if (nativeId == null || nativeId.isEmpty()) {
// no nativeId set in the snap, remove it from db.
snap.setInactive(true);
dbClient.persistObject(snap);
_logger.info("No nativeId, removing the snapshot: {}", snap.getId());
continue;
} else {
snapshotsInDB.put(nativeId, snap);
}
}
// Retrieve list of valid snapshot names from the device
List<VNXeFileSystemSnap> snapshots = vnxeApiClient.getFileSystemSnaps(fsObj.getNativeId());
List<String> snapIdsOnDevice = new ArrayList<String>();
for (VNXeFileSystemSnap snap : snapshots) {
snapIdsOnDevice.add(snap.getId());
}
// Iterate through the snapshots in the DB and if name not found in
// the list returned by the device, mark snapshot in DB as inactive
Set<String> snapshotNativeIds = snapshotsInDB.keySet();
for (String snapshotId : snapshotNativeIds) {
if (!snapIdsOnDevice.contains(snapshotId)) {
_logger.info("Removing the snapshot: {}", snapshotId);
snapshotsInDB.get(snapshotId).setInactive(true);
dbClient.persistObject(snapshotsInDB.get(snapshotId));
}
}
// newly discovered snapshot to the DB.
for (VNXeFileSystemSnap snap : snapshots) {
if (!snapshotNativeIds.contains(snap.getId())) {
_logger.info("adding the snapshot: {}", snap.getId());
Snapshot newSnap = new Snapshot();
newSnap.setCreationTime(Calendar.getInstance());
newSnap.setId(URIUtil.createId(Snapshot.class));
newSnap.setParent(new NamedURI(fsObj.getId(), fsObj.getLabel()));
newSnap.setLabel(snap.getName());
newSnap.setOpStatus(new OpStatusMap());
newSnap.setProject(new NamedURI(fsObj.getProject().getURI(), fsObj.getProject().getName()));
newSnap.setNativeId(snap.getId());
try {
newSnap.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(dbClient, newSnap));
} catch (IOException e) {
_logger.info("Exception while setting snap's nativeGUID");
}
}
}
}
use of com.emc.storageos.db.client.model.OpStatusMap in project coprhd-controller by CoprHD.
the class VNXUnityRestoreSnapshotJob method updateStatus.
public void updateStatus(JobContext jobContext) throws Exception {
DbClient dbClient = jobContext.getDbClient();
try {
if (_status == JobStatus.IN_PROGRESS) {
return;
}
String opId = getTaskCompleter().getOpId();
_logger.info(String.format("Updating status of job %s to %s", opId, _status.name()));
URI snapId = getTaskCompleter().getId();
BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapId);
URI projectUri = snapshotObj.getProject().getURI();
StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
if (_status == JobStatus.SUCCESS && snapshotObj != null) {
VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
ParametersOut output = vnxeJob.getParametersOut();
// get the id of the backup snapshot created before restore operation
String backUpSnapId = output.getBackup().getId();
Snap backupSnap = vnxeApiClient.getSnapshot(backUpSnapId);
if (NullColumnValueGetter.isNotNullValue(snapshotObj.getReplicationGroupInstance())) {
List<BlockSnapshot> snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshotObj, dbClient);
// Create a snapshot corresponding to the backup snap for each volume in the consistency group
final List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
int count = 1;
String setLabel = backupSnap.getName();
for (BlockSnapshot snapshot : snapshots) {
BlockObject parent = BlockObject.fetch(dbClient, snapshot.getParent().getURI());
String label = String.format("%s-%s", setLabel, count++);
final BlockSnapshot newSnap = initSnapshot(parent, label, setLabel, projectUri);
newSnap.setOpStatus(new OpStatusMap());
snapshotList.add(newSnap);
volumeToSnapMap.put(parent.getNativeId(), newSnap);
}
List<Snap> snaps = vnxeApiClient.getSnapshotsBySnapGroup(backUpSnapId);
for (Snap snap : snaps) {
String lunId = snap.getLun().getId();
BlockSnapshot snapshot = volumeToSnapMap.get(lunId);
snapshot.setReplicationGroupInstance(backUpSnapId);
createSnapshot(snapshot, snap, storage, dbClient);
}
} else {
Volume vol = dbClient.queryObject(Volume.class, snapshotObj.getParent());
final BlockSnapshot newSnap = initSnapshot(vol, backupSnap.getName(), backupSnap.getName(), projectUri);
createSnapshot(newSnap, backupSnap, storage, dbClient);
}
getTaskCompleter().ready(dbClient);
} else if (_status == JobStatus.FAILED && snapshotObj != null) {
_logger.info(String.format("Task %s failed to restore volume snapshot: %s", opId, snapshotObj.getLabel()));
}
} catch (Exception e) {
_logger.error("Caught an exception while trying to updateStatus for VNXeBlockRestoreSnapshotJob", e);
setErrorStatus("Encountered an internal error during snapshot restore job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.db.client.model.OpStatusMap in project coprhd-controller by CoprHD.
the class SmisBlockSnapshotSessionUnlinkTargetJob method promoteSnapshotsToVolume.
/**
* Promotes a list of BlockSnapshot instances to their Volume equivalents. For BlockSnapshot
* instances that are part of a target ReplicationGroup, a BlockConsistencyGroup shall be created
* as part of the promotion.
*
* @param snapshots List of BlockSnapshot instances.
* @param dbClient Database client.
*/
private void promoteSnapshotsToVolume(List<BlockSnapshot> snapshots, DbClient dbClient) {
Map<String, BlockConsistencyGroup> groupCache = new HashMap<>();
for (BlockSnapshot snapshot : snapshots) {
// We check to make sure there is not already a volume with the
// native GUID of the snapshot. This could be the case if we are
// unlinking a target after restoring a source volume from a
// linked target volume. In that case, a linked target was created
// to represent the source volume and now we are unlinking that
// linked target. The volume in this case already exists.
List<Volume> volumesWithNativeId = CustomQueryUtility.getActiveVolumeByNativeGuid(dbClient, snapshot.getNativeGuid());
if (volumesWithNativeId.isEmpty()) {
URI cgId = getBlockConsistencyGroupForPromotedSnapshot(snapshot, groupCache, dbClient);
URI sourceObjURI = snapshot.getParent().getURI();
if (URIUtil.isType(sourceObjURI, Volume.class)) {
Volume sourceVolume = dbClient.queryObject(Volume.class, sourceObjURI);
// Create a new volume to represent the former snapshot target.
// We get what we can from the snapshot and for what is not
// available in the snapshot, we get from the source.
Volume volume = new Volume();
volume.setId(URIUtil.createId(Volume.class));
volume.setCreationTime(snapshot.getCreationTime());
volume.setWWN(snapshot.getWWN());
volume.setNativeGuid(snapshot.getNativeGuid());
volume.setNativeId(snapshot.getNativeId());
volume.setLabel(snapshot.getLabel());
volume.setDeviceLabel(snapshot.getDeviceLabel());
volume.setAlternateName(snapshot.getAlternateName());
volume.setSyncActive(true);
volume.setAccessState(sourceVolume.getAccessState());
volume.setCapacity(sourceVolume.getCapacity());
volume.setProvisionedCapacity(snapshot.getProvisionedCapacity());
volume.setAllocatedCapacity(snapshot.getAllocatedCapacity());
volume.setThinlyProvisioned(sourceVolume.getThinlyProvisioned());
// It is understood that this is not necessary true.
volume.setVirtualPool(sourceVolume.getVirtualPool());
volume.setVirtualArray(snapshot.getVirtualArray());
volume.setProject(snapshot.getProject());
volume.setTenant(sourceVolume.getTenant());
volume.setStorageController(snapshot.getStorageController());
volume.setSystemType(snapshot.getSystemType());
// It is understood that this is not necessarily true.
volume.setPool(sourceVolume.getPool());
StringSet protocols = new StringSet();
protocols.addAll(snapshot.getProtocol());
volume.setProtocol(protocols);
volume.setOpStatus(new OpStatusMap());
volume.setConsistencyGroup(cgId);
String repGrpInstance = snapshot.getReplicationGroupInstance();
if (!NullColumnValueGetter.isNullValue(repGrpInstance)) {
volume.setReplicationGroupInstance(repGrpInstance.substring(repGrpInstance.indexOf("+") + 1));
}
dbClient.createObject(volume);
}
}
}
}
Aggregations