use of com.emc.storageos.db.client.model.ExportMask in project coprhd-controller by CoprHD.
the class ExportMaskRemovePathsCompleter method complete.
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
try {
if (status == Operation.Status.ready) {
ExportMask exportMask = dbClient.queryObject(ExportMask.class, getMask());
if (removedTargets != null && !removedTargets.isEmpty()) {
for (URI target : removedTargets) {
exportMask.removeTarget(target);
}
}
if (removedInitiators != null && !removedInitiators.isEmpty()) {
exportMask.removeInitiatorURIs(removedInitiators);
exportMask.removeFromUserAddedInitiatorsByURI(removedInitiators);
}
dbClient.updateObject(exportMask);
}
} catch (Exception e) {
_log.error(String.format("Failed updating status for ExportMaskRemovePaths - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
} finally {
super.complete(dbClient, status, coded);
}
}
use of com.emc.storageos.db.client.model.ExportMask in project coprhd-controller by CoprHD.
the class ExportRemoveVolumesOnAdoptedMaskCompleter method complete.
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
try {
URI exportMaskUri = getMask();
ExportMask exportMask = (exportMaskUri != null) ? dbClient.queryObject(ExportMask.class, getMask()) : null;
ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
for (URI volumeURI : _volumes) {
BlockObject volume = BlockObject.fetch(dbClient, volumeURI);
if (exportMask != null && status == Operation.Status.ready) {
exportMask.removeFromUserCreatedVolumes(volume);
exportMask.removeVolume(volume.getId());
}
}
if (exportMask != null) {
URI pgURI = exportMask.getPortGroup();
if (exportMask.getVolumes() == null || exportMask.getVolumes().isEmpty()) {
exportGroup.removeExportMask(exportMask.getId());
dbClient.markForDeletion(exportMask);
dbClient.updateObject(exportGroup);
} else {
dbClient.updateObject(exportMask);
}
updatePortGroupVolumeCount(pgURI, dbClient);
}
_log.info(String.format("Done ExportMaskRemoveVolume - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
} catch (Exception e) {
_log.error(String.format("Failed updating status for ExportMaskRemoveVolume - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
} finally {
super.complete(dbClient, status, coded);
}
}
use of com.emc.storageos.db.client.model.ExportMask in project coprhd-controller by CoprHD.
the class RollbackExportGroupCreateCompleter 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 ((status == Operation.Status.error) && (coded instanceof ServiceError)) {
ServiceError error = (ServiceError) coded;
String originalMessage = error.getMessage();
StorageSystem storageSystem = exportMask != null ? dbClient.queryObject(StorageSystem.class, exportMask.getStorageDevice()) : null;
String additionMessage = String.format("Rollback encountered problems cleaning up export mask %s on storage system %s and may require manual clean up", exportMask.getMaskName(), storageSystem != null ? storageSystem.forDisplay() : "Unknown");
String updatedMessage = String.format("%s\n%s", originalMessage, additionMessage);
error.setMessage(updatedMessage);
}
if (exportMask != null) {
URI pgURI = exportMask.getPortGroup();
// clean up export group
exportGroup.removeExportMask(exportMask.getId());
dbClient.updateObject(exportGroup);
List<URI> boURIs = new ArrayList<>();
// part of export group then we should remove that volumes
for (String emUri : exportGroup.getExportMasks()) {
if (URIUtil.isValid(emUri) && !emUri.equals(exportMask.getId())) {
ExportMask em = dbClient.queryObject(ExportMask.class, URI.create(emUri));
if (em != null) {
for (String boURI : em.getUserAddedVolumes().values()) {
if (URIUtil.isValid(boURI)) {
boURIs.add(URI.create(boURI));
}
}
}
}
}
exportMask.removeFromUserAddedVolumesByURI(boURIs);
dbClient.updateObject(exportMask);
// if its not used anywhere and is system created delete it
if (ExportMaskUtils.getExportGroups(dbClient, exportMask.getId()).isEmpty() && exportMask.getCreatedBySystem() && !exportMask.hasAnyVolumes()) {
dbClient.markForDeletion(exportMask);
}
updatePortGroupVolumeCount(pgURI, dbClient);
}
_log.info(String.format("Done RollbackExportGroupCreate - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
} catch (Exception e) {
_log.error(String.format("Failed updating status for RollbackExportGroupCreate - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
} finally {
super.complete(dbClient, status, coded);
}
}
use of com.emc.storageos.db.client.model.ExportMask in project coprhd-controller by CoprHD.
the class ZoningRemovePathsCompleter method complete.
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
try {
if (status == Operation.Status.ready && !exportMaskAdjustedPathMap.isEmpty()) {
for (Map.Entry<URI, Map<URI, List<URI>>> maskPathEntry : exportMaskAdjustedPathMap.entrySet()) {
URI maskURI = maskPathEntry.getKey();
Map<URI, List<URI>> zoningPaths = maskPathEntry.getValue();
ExportMask exportMask = dbClient.queryObject(ExportMask.class, maskURI);
// update zoning map
StringSetMap zoningMap = exportMask.getZoningMap();
zoningMap.clear();
for (Map.Entry<URI, List<URI>> zoningPath : zoningPaths.entrySet()) {
zoningMap.put(zoningPath.getKey().toString(), StringSetUtil.uriListToStringSet(zoningPath.getValue()));
}
dbClient.updateObject(exportMask);
}
}
} catch (Exception e) {
log.error(String.format("Failed updating status for ZoningRemovePaths - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
} finally {
super.complete(dbClient, status, coded);
}
}
use of com.emc.storageos.db.client.model.ExportMask in project coprhd-controller by CoprHD.
the class ScaleIOMaskingOrchestrator method exportGroupRemoveVolumes.
@Override
public void exportGroupRemoveVolumes(URI storageURI, URI exportGroupURI, List<URI> volumeURIs, String token) throws Exception {
/*
* foreach volume in list
* foreach initiator in ExportGroup
* if volume not used in another ExportGroup with same initiator
* scli unmap --volume volid --sdc initiator.sdcid
*/
ExportOrchestrationTask taskCompleter = new ExportOrchestrationTask(exportGroupURI, token);
try {
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
StorageSystem storage = _dbClient.queryObject(StorageSystem.class, storageURI);
List<ExportMask> masks = ExportMaskUtils.getExportMasks(_dbClient, exportGroup, storageURI);
if (masks != null && !masks.isEmpty()) {
// Set up workflow steps.
Workflow workflow = _workflowService.getNewWorkflow(MaskingWorkflowEntryPoints.getInstance(), "exportGroupRemoveVolumes", true, token);
// Generate a list of Initiators
List<URI> initiatorURIs = StringSetUtil.stringSetToUriList(exportGroup.getInitiators());
Map<URI, List<URI>> exportToRemoveVolumesList = new HashMap<>();
// Generate a mapping of volume URIs to the # of
// ExportGroups that it is associated with
Map<URI, Map<URI, Integer>> exportMaskToVolumeCount = ExportMaskUtils.mapExportMaskToVolumeShareCount(_dbClient, volumeURIs, initiatorURIs);
// remove from that ExportMask
for (ExportMask exportMask : masks) {
Map<URI, Integer> volumeToCountMap = exportMaskToVolumeCount.get(exportMask.getId());
if (volumeToCountMap == null) {
continue;
}
for (Map.Entry<URI, Integer> it : volumeToCountMap.entrySet()) {
URI volumeURI = it.getKey();
Integer numberOfExportGroupsVolumesIsIn = it.getValue();
if (numberOfExportGroupsVolumesIsIn == 1) {
List<URI> volumesToRemove = exportToRemoveVolumesList.get(exportMask.getId());
if (volumesToRemove == null) {
volumesToRemove = new ArrayList<>();
exportToRemoveVolumesList.put(exportMask.getId(), volumesToRemove);
}
volumesToRemove.add(volumeURI);
}
}
}
// generate a step to remove the volumes from the ExportMask
for (Map.Entry<URI, List<URI>> entry : exportToRemoveVolumesList.entrySet()) {
ExportMask exportMask = _dbClient.queryObject(ExportMask.class, entry.getKey());
log.info(String.format("Adding step to remove volumes %s from ExportMask %s", Joiner.on(',').join(entry.getValue()), exportMask.getMaskName()));
generateExportMaskRemoveVolumesWorkflow(workflow, null, storage, exportGroup, exportMask, entry.getValue(), null, null);
}
String successMessage = String.format("ExportGroup remove volumes successfully applied for StorageArray %s", storage.getLabel());
workflow.executePlan(taskCompleter, successMessage);
} else {
taskCompleter.ready(_dbClient);
}
} catch (DeviceControllerException dex) {
taskCompleter.error(_dbClient, DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("exportGroupRemoveVolumes", dex.getMessage()));
} catch (Exception ex) {
_log.error("ExportGroup Orchestration failed.", ex);
taskCompleter.error(_dbClient, DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("exportGroupRemoveVolumes", ex.getMessage()));
}
}
Aggregations