Search in sources :

Example 71 with ExportMask

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);
    }
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 72 with ExportMask

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);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ExportMask(com.emc.storageos.db.client.model.ExportMask) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 73 with ExportMask

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);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 74 with ExportMask

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);
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) List(java.util.List) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 75 with ExportMask

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()));
    }
}
Also used : HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) Workflow(com.emc.storageos.workflow.Workflow) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportOrchestrationTask(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

ExportMask (com.emc.storageos.db.client.model.ExportMask)368 URI (java.net.URI)274 ArrayList (java.util.ArrayList)224 Initiator (com.emc.storageos.db.client.model.Initiator)155 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)140 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)134 HashMap (java.util.HashMap)128 HashSet (java.util.HashSet)121 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)107 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)102 List (java.util.List)79 StringSet (com.emc.storageos.db.client.model.StringSet)68 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)65 Map (java.util.Map)65 StringMap (com.emc.storageos.db.client.model.StringMap)60 BlockObject (com.emc.storageos.db.client.model.BlockObject)56 NamedURI (com.emc.storageos.db.client.model.NamedURI)56 Workflow (com.emc.storageos.workflow.Workflow)54 Set (java.util.Set)51 Volume (com.emc.storageos.db.client.model.Volume)44