use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExportCreateCompleter method complete.
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
try {
super.complete(dbClient, status, coded);
ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
Operation operation = new Operation();
switch(status) {
case error:
operation.error(coded);
break;
case ready:
operation.ready();
break;
case suspended_no_error:
operation.suspendedNoError();
break;
case suspended_error:
operation.suspendedError(coded);
break;
default:
break;
}
exportGroup.getOpStatus().updateTaskStatus(getOpId(), operation);
// then make sure that the inactive flag is set to true
if (!hasActiveMasks(dbClient, exportGroup)) {
exportGroup.setInactive(status != Operation.Status.ready && status != Operation.Status.suspended_no_error);
}
// In the case of RecoverPoint bookmark exports, the volumes map could contain additional objects
// that are being exported. Adding the object references to the ExportGroup here, ensures it aligns
// with the ExportMask objects.
_log.info(String.format("Adding block objects %s to export group %s.", volumeMap, exportGroup.getId()));
exportGroup.addVolumes(volumeMap);
dbClient.updateObject(exportGroup);
_log.info("export_create completer: done");
_log.info(String.format("Done ExportMaskCreate - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
recordBlockExportOperation(dbClient, OperationTypeEnum.CREATE_EXPORT_GROUP, status, eventMessage(status, exportGroup), exportGroup);
} catch (Exception e) {
_log.error(String.format("Failed updating status for ExportMaskCreate - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
}
}
use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExportMaskAddInitiatorCompleter method updateDatabase.
/**
* Update the export mask and export group with the initiators are ports
*
* @param dbClient
* dbclient
* @param uris
* uris of Initiators and storage ports
*/
private void updateDatabase(DbClient dbClient, Collection<URI> uris) {
List<URI> targetURIs = _targetURIs;
List<URI> initiatorURIs = _initiatorURIs;
// initiators that appear in the context.
if (uris != null && !uris.isEmpty()) {
targetURIs = URIUtil.getURIsofType(uris, Initiator.class);
initiatorURIs = URIUtil.getURIsofType(uris, StoragePort.class);
}
ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
ExportMask exportMask = (getMask() != null) ? dbClient.queryObject(ExportMask.class, getMask()) : null;
if (exportMask != null) {
// Update the initiator tracking containers
exportMask.addToUserCreatedInitiators(dbClient.queryObject(Initiator.class, initiatorURIs));
// Save the initiators to the ExportMask
for (URI initiatorURI : initiatorURIs) {
Initiator initiator = dbClient.queryObject(Initiator.class, initiatorURI);
if (initiator != null) {
exportMask.removeFromExistingInitiators(initiator);
exportMask.addInitiator(initiator);
exportGroup.addInitiator(initiator);
} else {
_log.warn("Initiator {} does not exist.", initiatorURI);
}
}
// Save the target StoragePort URIs to the ExportMask
for (URI newTarget : targetURIs) {
exportMask.addTarget(newTarget);
}
dbClient.updateObject(exportMask);
}
ExportUtils.reconcileExportGroupsHLUs(dbClient, exportGroup);
dbClient.updateObject(exportGroup);
}
use of com.emc.storageos.db.client.model.ExportGroup 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.ExportGroup 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);
}
}
use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExportMaskRemoveInitiatorCompleter 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;
boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(getOpId());
if ((status == Operation.Status.error) && (isRollback) && (coded instanceof ServiceError)) {
ServiceError error = (ServiceError) coded;
String originalMessage = error.getMessage();
StorageSystem storageSystem = exportMask != null ? dbClient.queryObject(StorageSystem.class, exportMask.getStorageDevice()) : null;
List<Initiator> initiators = dbClient.queryObject(Initiator.class, _initiatorURIs);
StringBuffer initiatorsJoined = new StringBuffer();
if (initiators != null && !initiators.isEmpty()) {
Iterator<Initiator> initIter = initiators.iterator();
while (initIter.hasNext()) {
Initiator initiator = initIter.next();
initiatorsJoined.append(initiator.forDisplay());
if (initIter.hasNext()) {
initiatorsJoined.append(",");
}
}
}
String additionMessage = String.format("Rollback encountered problems removing initiator(s) %s from export mask %s on storage system %s and may require manual clean up", initiatorsJoined.toString(), exportMask.getMaskName(), storageSystem != null ? storageSystem.forDisplay() : "Unknown");
String updatedMessage = String.format("%s\n%s", originalMessage, additionMessage);
error.setMessage(updatedMessage);
}
if (exportMask != null && (status == Operation.Status.ready || isRollback)) {
List<Initiator> initiators = dbClient.queryObject(Initiator.class, _initiatorURIs);
List<URI> targetPorts = ExportUtils.getRemoveInitiatorStoragePorts(exportMask, initiators, dbClient);
exportMask.removeInitiators(initiators);
exportMask.removeFromUserCreatedInitiators(initiators);
if (exportMask.getExistingInitiators() != null && exportMask.getExistingInitiators().isEmpty()) {
exportMask.setExistingInitiators(null);
}
if (exportMask.getInitiators() == null || exportMask.getInitiators().isEmpty()) {
exportGroup.removeExportMask(exportMask.getId());
dbClient.removeObject(exportMask);
dbClient.updateObject(exportGroup);
} else {
if (targetPorts != null && !targetPorts.isEmpty()) {
for (URI targetPort : targetPorts) {
exportMask.removeTarget(targetPort);
}
}
removeUnusedTargets(exportMask);
dbClient.updateObject(exportMask);
}
_log.info(String.format("Done ExportMaskRemoveInitiator - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
}
} catch (Exception e) {
_log.error(String.format("Failed updating status for ExportMaskRemoveInitiator - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
} finally {
super.complete(dbClient, status, coded);
}
}
Aggregations