use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method doCreateClone.
@Override
public void doCreateClone(StorageSystem storageSystem, URI volume, URI clone, Boolean createInactive, TaskCompleter taskCompleter) {
Volume cloneObject = null;
DriverTask task = null;
try {
cloneObject = dbClient.queryObject(Volume.class, clone);
BlockObject sourceVolume = BlockObject.fetch(dbClient, volume);
VolumeClone driverClone = new VolumeClone();
if (sourceVolume instanceof Volume) {
driverClone.setSourceType(VolumeClone.SourceType.VOLUME);
} else if (sourceVolume instanceof BlockSnapshot) {
driverClone.setSourceType(VolumeClone.SourceType.SNAPSHOT);
} else {
cloneObject.setInactive(true);
dbClient.updateObject(cloneObject);
String errorMsg = String.format("doCreateClone -- Failed to create volume clone: unexpected source type %s .", sourceVolume.getClass().getSimpleName());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", errorMsg);
taskCompleter.error(dbClient, serviceError);
return;
}
// Prepare driver clone
driverClone.setParentId(sourceVolume.getNativeId());
driverClone.setStorageSystemId(storageSystem.getNativeId());
driverClone.setDisplayName(cloneObject.getLabel());
driverClone.setRequestedCapacity(cloneObject.getCapacity());
driverClone.setThinlyProvisioned(cloneObject.getThinlyProvisioned());
// Call driver
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
List<VolumeClone> driverClones = new ArrayList<>();
driverClones.add(driverClone);
task = driver.createVolumeClone(Collections.unmodifiableList(driverClones), null);
if (!isTaskInTerminalState(task.getStatus())) {
// If the task is not in a terminal state and will be completed asynchronously
// create a job to monitor the progress of the request and update the clone
// volume and call the completer as appropriate based on the result of the request.
CreateVolumeCloneExternalDeviceJob job = new CreateVolumeCloneExternalDeviceJob(storageSystem.getId(), clone, task.getTaskId(), taskCompleter);
ControllerServiceImpl.enqueueJob(new QueueJob(job));
} else if (task.getStatus() == DriverTask.TaskStatus.READY) {
// Update clone
String msg = String.format("doCreateClone -- Created volume clone: %s .", task.getMessage());
_log.info(msg);
VolumeClone driverCloneResult = driverClones.get(0);
ExternalDeviceUtils.updateNewlyCreatedClone(cloneObject, driverCloneResult, dbClient);
taskCompleter.ready(dbClient);
} else {
cloneObject.setInactive(true);
dbClient.updateObject(cloneObject);
String errorMsg = String.format("doCreateClone -- Failed to create volume clone: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception e) {
if (cloneObject != null) {
cloneObject.setInactive(true);
dbClient.updateObject(cloneObject);
}
_log.error("Failed to create volume clone. ", e);
ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", e.getMessage());
taskCompleter.error(dbClient, serviceError);
} finally {
try {
if (task == null || isTaskInTerminalState(task.getStatus())) {
StoragePool dbPool = dbClient.queryObject(StoragePool.class, cloneObject.getPool());
updateStoragePoolCapacity(dbPool, storageSystem, Collections.singletonList(clone), dbClient);
}
} catch (Exception ex) {
_log.error("Failed to update storage pool {} after create clone operation completion.", cloneObject.getPool(), ex);
}
}
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionRestoreWorkflowCompleter method complete.
/**
* {@inheritDoc}
*/
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
URI snapSessionURI = getId();
try {
if (_updateOpStatus) {
BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
List<BlockObject> allSources = getAllSources(snapSession, dbClient);
BlockObject sourceObj = allSources.get(0);
// Record the results.
recordBlockSnapshotSessionOperation(dbClient, OperationTypeEnum.RESTORE_SNAPSHOT_SESSION, status, snapSession, sourceObj);
// Update the status map of the snapshot session.
switch(status) {
case error:
setErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId(), coded);
break;
case ready:
setReadyOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId());
break;
case suspended_error:
setSuspendedErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId(), coded);
break;
case suspended_no_error:
setSuspendedNoErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId());
break;
default:
String errMsg = String.format("Unexpected status %s for completer for task %s", status.name(), getOpId());
s_logger.info(errMsg);
throw DeviceControllerException.exceptions.unexpectedCondition(errMsg);
}
}
s_logger.info("Done restore snapshot session task {} with status: {}", getOpId(), status.name());
} catch (Exception e) {
s_logger.error("Failed updating status for restore snapshot session task {}", getOpId(), e);
} finally {
super.complete(dbClient, status, coded);
}
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionUnlinkTargetsWorkflowCompleter method complete.
/**
* {@inheritDoc}
*/
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
URI snapSessionURI = getId();
try {
BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
List<BlockObject> allSources = getAllSources(snapSession, dbClient);
BlockObject sourceObj = allSources.get(0);
// Record the results.
recordBlockSnapshotSessionOperation(dbClient, _opType, status, snapSession, sourceObj);
// Update the status map of the snapshot session.
switch(status) {
case error:
setErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI, coded);
break;
case ready:
setReadyOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI);
break;
case suspended_error:
setSuspendedErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI, coded);
break;
case suspended_no_error:
setSuspendedNoErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI);
break;
default:
String errMsg = String.format("Unexpected status %s for completer for task %s", status.name(), getOpId());
s_logger.info(errMsg);
throw DeviceControllerException.exceptions.unexpectedCondition(errMsg);
}
s_logger.info("Done unlink targets from snapshot session task {} with status: {}", getOpId(), status.name());
} catch (Exception e) {
s_logger.error("Failed updating status for unlink targets from snapshot session task {}", getOpId(), e);
} finally {
super.complete(dbClient, status, coded);
}
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class ExportMaskAddVolumeCompleter method complete.
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
try {
ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
ExportMask exportMask = (getMask() != null) ? dbClient.queryObject(ExportMask.class, getMask()) : null;
if (exportMask == null) {
_log.warn("Export mask was null for task {}", getOpId());
return;
}
if (shouldUpdateDatabase(status)) {
for (URI volumeURI : _volumes) {
BlockObject volume = BlockObject.fetch(dbClient, volumeURI);
_log.info(String.format("Done ExportMaskAddVolume - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
exportMask.removeFromExistingVolumes(volume);
exportMask.addToUserCreatedVolumes(volume);
}
exportMask.setCreatedBySystem(true);
ExportMaskUtils.setExportMaskResource(dbClient, exportGroup, exportMask);
exportMask.addVolumes(_volumeMap);
if (getExportGroups() != null && !getExportGroups().isEmpty()) {
List<ExportGroup> egs = dbClient.queryObject(ExportGroup.class, getExportGroups());
for (ExportGroup eg : egs) {
eg.addExportMask(exportMask.getId());
ExportUtils.reconcileHLUs(dbClient, eg, exportMask, _volumeMap);
}
dbClient.updateObject(egs);
} else {
exportGroup.addExportMask(exportMask.getId());
ExportUtils.reconcileHLUs(dbClient, exportGroup, exportMask, _volumeMap);
dbClient.updateObject(exportGroup);
}
dbClient.updateObject(exportMask);
updatePortGroupVolumeCount(exportMask.getPortGroup(), dbClient);
// on rollback if subsequent steps in the workflow fail.
if (_forgetStepId != null) {
@SuppressWarnings("unchecked") Set<URI> maskedVolumeURIs = (Set<URI>) WorkflowService.getInstance().loadWorkflowData(_forgetStepId, "forget");
if (maskedVolumeURIs == null) {
maskedVolumeURIs = new HashSet<>();
maskedVolumeURIs.addAll(_volumes);
} else {
maskedVolumeURIs.addAll(_volumes);
}
WorkflowService.getInstance().storeWorkflowData(_forgetStepId, "forget", maskedVolumeURIs);
}
}
} catch (Exception e) {
_log.error(String.format("Failed updating status for ExportMaskAddVolume - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
} finally {
super.complete(dbClient, status, coded);
}
}
use of com.emc.storageos.db.client.model.BlockObject in project coprhd-controller by CoprHD.
the class ExportMaskCreateCompleter method complete.
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
try {
ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
ExportMask exportMask = (getMask() != null) ? dbClient.queryObject(ExportMask.class, getMask()) : null;
if (exportMask != null && status == Operation.Status.ready) {
List<Initiator> initiators = dbClient.queryObject(Initiator.class, _initiatorURIs);
exportMask.addInitiators(initiators);
StorageSystem system = dbClient.queryObject(StorageSystem.class, exportMask.getStorageDevice());
exportMask.addToUserCreatedInitiators(initiators);
exportMask.addVolumes(_volumeMap);
if (Type.xtremio.toString().equalsIgnoreCase(system.getSystemType())) {
// XtremIO case, wwn's are updated only during export.
// Clean up the existing volumes in export Mask which will have dummy wwns after provisioning.
// The code below this method addToUserCreatedVolumes adds back the volumes with right wwns.
_log.info("Cleaning existing xtremio volumes with dummy wwns");
exportMask.getUserAddedVolumes().clear();
}
for (URI boURI : _volumeMap.keySet()) {
BlockObject blockObject = BlockObject.fetch(dbClient, boURI);
exportMask.addToUserCreatedVolumes(blockObject);
// CTRL-11544: Set the hlu in the export group too
if (exportMask.getCreatedBySystem() && exportMask.getVolumes() != null) {
String hlu = exportMask.getVolumes().get(boURI.toString());
exportGroup.addVolume(boURI, Integer.parseInt(hlu));
}
}
ExportUtils.reconcileHLUs(dbClient, exportGroup, exportMask, _volumeMap);
dbClient.updateObject(exportMask);
exportGroup.addExportMask(exportMask.getId());
dbClient.updateObject(exportGroup);
updatePortGroupVolumeCount(exportMask.getPortGroup(), dbClient);
}
_log.info(String.format("Done ExportMaskCreate - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
} catch (Exception e) {
_log.error(String.format("Failed updating status for ExportMaskCreate - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
} finally {
super.complete(dbClient, status, coded);
}
}
Aggregations