Search in sources :

Example 51 with ExportOrchestrationTask

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask in project coprhd-controller by CoprHD.

the class CephMaskingOrchestrator method exportGroupRemoveInitiators.

@Override
public void exportGroupRemoveInitiators(URI storageURI, URI exportGroupURI, List<URI> initiatorURIs, String token) throws Exception {
    ExportOrchestrationTask taskCompleter = new ExportOrchestrationTask(exportGroupURI, token);
    try {
        ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
        StorageSystem storage = _dbClient.queryObject(StorageSystem.class, storageURI);
        if (initiatorURIs != null && !initiatorURIs.isEmpty() && exportGroup != null && exportGroup.getExportMasks() != null) {
            // Set up workflow steps.
            Workflow workflow = _workflowService.getNewWorkflow(MaskingWorkflowEntryPoints.getInstance(), "exportGroupRemoveInitiators", true, token, taskCompleter);
            // Create a mapping of ExportMask URI to initiators to remove
            Map<URI, List<URI>> exportToInitiatorsToRemove = new HashMap<>();
            Map<URI, List<URI>> exportToVolumesToRemove = new HashMap<>();
            Map<URI, Integer> volumeMap = null;
            List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(_dbClient, exportGroup);
            for (ExportMask exportMask : exportMasks) {
                if (exportMask == null) {
                    continue;
                }
                for (URI initiatorURI : initiatorURIs) {
                    Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorURI);
                    if (initiator == null || !exportMask.hasInitiator(initiatorURI.toString())) {
                        continue;
                    }
                    if (ExportUtils.getInitiatorExportGroups(initiator, _dbClient).size() == 1) {
                        List<URI> initiators = exportToInitiatorsToRemove.get(exportGroupURI);
                        if (initiators == null) {
                            initiators = new ArrayList<>();
                            exportToInitiatorsToRemove.put(exportMask.getId(), initiators);
                        }
                        initiators.add(initiatorURI);
                    } else {
                        if (volumeMap == null) {
                            volumeMap = ExportUtils.getExportGroupVolumeMap(_dbClient, storage, exportGroup);
                        }
                        List<URI> volumeURIs = exportToVolumesToRemove.get(exportGroupURI);
                        if (volumeURIs == null) {
                            volumeURIs = new ArrayList<>();
                            exportToVolumesToRemove.put(exportMask.getId(), volumeURIs);
                        }
                        for (URI volumeURI : volumeMap.keySet()) {
                            // Only add to the remove list for the ExportMask if
                            // the EM is not being shared with another ExportGroup
                            Integer count = ExportUtils.getNumberOfExportGroupsWithVolume(initiator, volumeURI, _dbClient);
                            if (count == 1) {
                                volumeURIs.add(volumeURI);
                            }
                        }
                    }
                }
            }
            // Generate the remove initiators steps for the entries that were determined above
            for (Map.Entry<URI, List<URI>> toRemoveInits : exportToInitiatorsToRemove.entrySet()) {
                ExportMask exportMask = _dbClient.queryObject(ExportMask.class, toRemoveInits.getKey());
                if (exportMask != null) {
                    List<URI> removeInitURIs = toRemoveInits.getValue();
                    List<String> exportMaskInitiatorURIs = new ArrayList<>(exportMask.getInitiators());
                    for (URI uri : removeInitURIs) {
                        exportMaskInitiatorURIs.remove(uri.toString());
                    }
                    if (exportMaskInitiatorURIs.isEmpty()) {
                        _log.info(String.format("Adding step to delete ExportMask %s", exportMask.getMaskName()));
                        generateExportMaskDeleteWorkflow(workflow, null, storage, exportGroup, exportMask, null, null, taskCompleter);
                    } else {
                        _log.info(String.format("Adding step to remove initiators %s from ExportMask %s", Joiner.on(',').join(removeInitURIs), exportMask.getMaskName()));
                        generateExportMaskRemoveInitiatorsWorkflow(workflow, null, storage, exportGroup, exportMask, removeInitURIs, null, true);
                    }
                }
            }
            // from an ExportGroup that contains more than one host/initiator
            for (Map.Entry<URI, List<URI>> toRemoveVols : exportToVolumesToRemove.entrySet()) {
                ExportMask exportMask = _dbClient.queryObject(ExportMask.class, toRemoveVols.getKey());
                List<URI> removeVolumeURIs = toRemoveVols.getValue();
                if (exportMask != null && !removeVolumeURIs.isEmpty()) {
                    List<String> exportMaskVolumeURIs = new ArrayList<>(exportMask.getVolumes().keySet());
                    for (URI uri : removeVolumeURIs) {
                        exportMaskVolumeURIs.remove(uri.toString());
                    }
                    if (exportMaskVolumeURIs.isEmpty()) {
                        _log.info(String.format("Adding step to delete ExportMask %s", exportMask.getMaskName()));
                        generateExportMaskDeleteWorkflow(workflow, null, storage, exportGroup, exportMask, null, null, taskCompleter);
                    } else {
                        _log.info(String.format("Adding step to remove volumes %s from ExportMask %s", Joiner.on(',').join(removeVolumeURIs), exportMask.getMaskName()));
                        generateExportMaskRemoveVolumesWorkflow(workflow, null, storage, exportGroup, exportMask, removeVolumeURIs, null, taskCompleter);
                    }
                }
            }
            String successMessage = String.format("ExportGroup remove initiators successfully applied for StorageArray %s", storage.getLabel());
            workflow.executePlan(taskCompleter, successMessage);
        } else {
            taskCompleter.ready(_dbClient);
        }
    } catch (DeviceControllerException dex) {
        taskCompleter.error(_dbClient, DeviceControllerErrors.ceph.operationFailed("exportGroupRemoveInitiators", dex.getMessage()));
    } catch (Exception ex) {
        _log.error("ExportGroup Orchestration failed.", ex);
        taskCompleter.error(_dbClient, DeviceControllerErrors.ceph.operationFailed("exportGroupRemoveInitiators", ex.getMessage()));
    }
}
Also used : HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) Workflow(com.emc.storageos.workflow.Workflow) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) 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)

Example 52 with ExportOrchestrationTask

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask in project coprhd-controller by CoprHD.

the class CephMaskingOrchestrator method exportGroupRemoveVolumes.

@Override
public void exportGroupRemoveVolumes(URI storageURI, URI exportGroupURI, List<URI> volumeURIs, String token) throws Exception {
    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, taskCompleter);
            // Generate a mapping of volume URIs to the # of
            // ExportGroups that it is associated with
            List<URI> initiatorURIs = StringSetUtil.stringSetToUriList(exportGroup.getInitiators());
            Map<URI, Map<URI, Integer>> exportMaskToVolumeCount = ExportMaskUtils.mapExportMaskToVolumeShareCount(_dbClient, volumeURIs, initiatorURIs);
            // Generate a mapping of the ExportMask URI to a list volumes to
            // remove from that ExportMask
            Map<URI, List<URI>> exportToRemoveVolumesList = new HashMap<>();
            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, taskCompleter);
            }
            String successMsgTemplate = "ExportGroup remove volumes successfully applied for StorageArray %s";
            workflow.executePlan(taskCompleter, String.format(successMsgTemplate, storage.getLabel()));
        } else {
            taskCompleter.ready(_dbClient);
        }
    } catch (DeviceControllerException dex) {
        taskCompleter.error(_dbClient, DeviceControllerErrors.ceph.operationFailed("exportGroupRemoveVolumes", dex.getMessage()));
    } catch (Exception ex) {
        _log.error("ExportGroup Orchestration failed.", ex);
        taskCompleter.error(_dbClient, DeviceControllerErrors.ceph.operationFailed("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)

Example 53 with ExportOrchestrationTask

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask in project coprhd-controller by CoprHD.

the class CephMaskingOrchestrator method exportGroupAddInitiators.

@Override
public void exportGroupAddInitiators(URI storageURI, URI exportGroupURI, List<URI> initiatorURIs, String token) throws Exception {
    ExportOrchestrationTask taskCompleter = new ExportOrchestrationTask(exportGroupURI, token);
    try {
        ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
        StorageSystem storage = _dbClient.queryObject(StorageSystem.class, storageURI);
        if (initiatorURIs != null && !initiatorURIs.isEmpty()) {
            // Set up workflow steps.
            Workflow workflow = _workflowService.getNewWorkflow(MaskingWorkflowEntryPoints.getInstance(), "exportGroupAddInitiators", true, token, taskCompleter);
            // Populate the portNames and the mapping of the portNames to Initiator URIs
            Map<String, URI> portNameToInitiatorURI = new HashMap<>();
            List<URI> hostURIs = new ArrayList<>();
            List<String> portNames = new ArrayList<>();
            processInitiators(exportGroup, initiatorURIs, portNames, portNameToInitiatorURI, hostURIs);
            List<URI> initiatorURIsToPlace = new ArrayList<>(initiatorURIs);
            Map<String, List<URI>> computeResourceToInitiators = mapInitiatorsToComputeResource(exportGroup, initiatorURIs);
            Set<URI> partialMasks = new HashSet<>();
            Map<String, Set<URI>> initiatorToExport = determineInitiatorToExportMaskPlacements(exportGroup, storageURI, computeResourceToInitiators, Collections.EMPTY_MAP, portNameToInitiatorURI, partialMasks);
            Map<URI, List<URI>> exportToInitiators = toExportMaskToInitiatorURIs(initiatorToExport, portNameToInitiatorURI);
            Map<URI, Integer> volumesToAdd = ExportUtils.getExportGroupVolumeMap(_dbClient, storage, exportGroup);
            for (Map.Entry<URI, List<URI>> toAddInitiators : exportToInitiators.entrySet()) {
                ExportMask exportMask = _dbClient.queryObject(ExportMask.class, toAddInitiators.getKey());
                if (exportMask == null || exportMask.getInactive()) {
                    continue;
                }
                for (URI toAddInitiator : toAddInitiators.getValue()) {
                    if (!exportMask.hasInitiator(toAddInitiator.toString())) {
                        _log.info(String.format("Add step to add initiator %s to ExportMask %s", toAddInitiator.toString(), exportMask.getMaskName()));
                        generateExportMaskAddInitiatorsWorkflow(workflow, null, storage, exportGroup, exportMask, toAddInitiators.getValue(), null, null);
                    } else if (volumesToAdd != null && volumesToAdd.size() > 0) {
                        _log.info(String.format("Add step to add volumes %s to ExportMask %s", Joiner.on(',').join(volumesToAdd.entrySet()), exportMask.getMaskName()));
                        generateExportMaskAddVolumesWorkflow(workflow, null, storage, exportGroup, exportMask, volumesToAdd, null);
                    }
                    initiatorURIsToPlace.remove(toAddInitiator);
                }
            }
            // If there are any new initiators that weren't already known to the system previously, add them now.
            if (!initiatorURIsToPlace.isEmpty() && volumesToAdd != null) {
                Map<String, List<URI>> newComputeResources = mapInitiatorsToComputeResource(exportGroup, initiatorURIsToPlace);
                _log.info(String.format("Need to create ExportMasks for these compute resources %s", Joiner.on(',').join(newComputeResources.entrySet())));
                for (Map.Entry<String, List<URI>> toCreate : newComputeResources.entrySet()) {
                    generateExportMaskCreateWorkflow(workflow, null, storage, exportGroup, toCreate.getValue(), volumesToAdd, null);
                }
            }
            String successMessage = String.format("ExportGroup add initiators successfully applied for StorageArray %s", storage.getLabel());
            workflow.executePlan(taskCompleter, successMessage);
        } else {
            taskCompleter.ready(_dbClient);
        }
    } catch (DeviceControllerException dex) {
        taskCompleter.error(_dbClient, DeviceControllerErrors.ceph.operationFailed("exportGroupAddInitiators", dex.getMessage()));
    } catch (Exception ex) {
        _log.error("ExportGroup Orchestration failed.", ex);
        taskCompleter.error(_dbClient, DeviceControllerErrors.ceph.operationFailed("exportGroupAddInitiators", ex.getMessage()));
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) ArrayList(java.util.ArrayList) List(java.util.List) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet) ExportMask(com.emc.storageos.db.client.model.ExportMask) Workflow(com.emc.storageos.workflow.Workflow) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) HashMap(java.util.HashMap) Map(java.util.Map) ExportOrchestrationTask(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask)

Aggregations

ExportOrchestrationTask (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask)53 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)46 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)44 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)42 Workflow (com.emc.storageos.workflow.Workflow)40 ExportMask (com.emc.storageos.db.client.model.ExportMask)39 URI (java.net.URI)39 ArrayList (java.util.ArrayList)36 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)33 HashMap (java.util.HashMap)31 List (java.util.List)28 Map (java.util.Map)25 Initiator (com.emc.storageos.db.client.model.Initiator)20 HashSet (java.util.HashSet)19 BlockObject (com.emc.storageos.db.client.model.BlockObject)17 BlockStorageDevice (com.emc.storageos.volumecontroller.BlockStorageDevice)16 ExportTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportTaskCompleter)16 Set (java.util.Set)15 StringMap (com.emc.storageos.db.client.model.StringMap)12 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)7