Search in sources :

Example 16 with ExportOrchestrationTask

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

the class ScaleIOMaskingOrchestrator method exportGroupRemoveInitiators.

@Override
public void exportGroupRemoveInitiators(URI storageURI, URI exportGroupURI, List<URI> initiatorURIs, String token) throws Exception {
    /*
         * foreach ScaleOI volume in ExportGroup
         * foreach initiator in list
         * 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);
        if (initiatorURIs != null && !initiatorURIs.isEmpty() && exportGroup != null && exportGroup.getExportMasks() != null) {
            // Set up workflow steps.
            Workflow workflow = _workflowService.getNewWorkflow(MaskingWorkflowEntryPoints.getInstance(), "exportGroupRemoveInitiators", true, token);
            // 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, null);
                    } 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, null, removeInitURIs, 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, null);
                    } 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, null);
                    }
                }
            }
            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.scaleio.encounteredAnExceptionFromScaleIOOperation("exportGroupRemoveInitiators", dex.getMessage()));
    } catch (Exception ex) {
        _log.error("ExportGroup Orchestration failed.", ex);
        taskCompleter.error(_dbClient, DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("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 17 with ExportOrchestrationTask

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

the class HDSMaskingOrchestrator method determineExportGroupCreateSteps.

/**
 * Routine contains logic to create an export mask on the array
 *
 * @param workflow
 *            - Workflow object to create steps against
 * @param previousStep
 *            - [optional] Identifier of workflow step to wait for
 * @param device
 *            - BlockStorageDevice implementation
 * @param storage
 *            - StorageSystem object representing the underlying array
 * @param exportGroup
 *            - ExportGroup object representing Bourne-level masking
 * @param initiatorURIs
 *            - List of Initiator URIs
 * @param volumeMap
 *            - Map of Volume URIs to requested Integer HLUs
 * @param zoningStepNeeded
 *            - Not required ofr HDS
 * @param token
 *            - Identifier for the operation
 *
 * @throws Exception
 */
@Override
public boolean determineExportGroupCreateSteps(Workflow workflow, String previousStep, BlockStorageDevice device, StorageSystem storage, ExportGroup exportGroup, List<URI> initiatorURIs, Map<URI, Integer> volumeMap, boolean zoningStepNeeded, String token) throws Exception {
    Map<String, URI> portNameToInitiatorURI = new HashMap<String, URI>();
    List<URI> volumeURIs = new ArrayList<URI>();
    volumeURIs.addAll(volumeMap.keySet());
    Map<URI, URI> hostToExistingExportMaskMap = new HashMap<URI, URI>();
    List<URI> hostURIs = new ArrayList<URI>();
    List<String> portNames = new ArrayList<String>();
    // Only update the ports of a mask that we created.
    // TODO COP-22395:
    // Make sure the caller to this method (the caller that assembles the steps) adds the initiator list to
    // send down here. (then remove the log)
    List<Initiator> initiators = null;
    if (initiatorURIs != null && !initiatorURIs.isEmpty()) {
        initiators = _dbClient.queryObject(Initiator.class, initiatorURIs);
    } else {
        _log.warn("Internal warning: Need to add the initiatorURIs to the call that assembles this step for validation to occur.");
    }
    // Populate the port WWN/IQNs (portNames) and the
    // mapping of the WWN/IQNs to Initiator URIs
    processInitiators(exportGroup, initiatorURIs, portNames, portNameToInitiatorURI, hostURIs);
    // We always want to have the full list of initiators for the hosts involved in
    // this export. This will allow the export operation to always find any
    // existing exports for a given host.
    queryHostInitiatorsAndAddToList(portNames, portNameToInitiatorURI, initiatorURIs, hostURIs);
    // Find the export masks that are associated with any or all the ports in
    // portNames. We will have to do processing differently based on whether
    // or there is an existing ExportMasks.
    Map<String, Set<URI>> matchingExportMaskURIs = device.findExportMasks(storage, portNames, false);
    boolean masksWithStoragePortFromVArrayFound = false;
    Set<String> storagePortURIsAssociatedWithVArrayAndStorageArray = ExportMaskUtils.getStoragePortUrisAssociatedWithVarrayAndStorageArray(storage.getId(), exportGroup.getVirtualArray(), _dbClient);
    Set<String> checkMasks = mergeWithExportGroupMaskURIs(exportGroup, matchingExportMaskURIs.values());
    for (String maskURIStr : checkMasks) {
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, URI.create(maskURIStr));
        // Check if there are any storage ports in the mask which are part of varray, if not found discard this mask
        if (Sets.intersection(storagePortURIsAssociatedWithVArrayAndStorageArray, exportMask.getStoragePorts()).isEmpty()) {
            for (Map.Entry<String, Set<URI>> entry : matchingExportMaskURIs.entrySet()) {
                entry.getValue().remove(exportMask.getId());
            }
            continue;
        } else {
            masksWithStoragePortFromVArrayFound = true;
        }
    }
    if (matchingExportMaskURIs.isEmpty() || !masksWithStoragePortFromVArrayFound) {
        _log.info(String.format("No existing mask found w/ initiators { %s }", Joiner.on(",").join(portNames)));
        createNewExportMaskWorkflowForInitiators(initiatorURIs, exportGroup, workflow, volumeMap, storage, token, previousStep);
    } else {
        _log.info(String.format("Mask(s) found w/ initiators {%s}. " + "MatchingExportMaskURIs {%s}, portNameToInitiators {%s}", Joiner.on(",").join(portNames), Joiner.on(",").join(matchingExportMaskURIs.values()), Joiner.on(",").join(portNameToInitiatorURI.entrySet())));
        // There are some initiators that already exist. We need to create a
        // workflow that create new masking containers or updates masking
        // containers as necessary.
        // These data structures will be used to track new initiators - ones
        // that don't already exist on the array
        List<URI> initiatorURIsCopy = new ArrayList<URI>();
        initiatorURIsCopy.addAll(initiatorURIs);
        // This loop will determine a list of volumes to update per export mask
        Map<URI, Map<URI, Integer>> existingMasksToUpdateWithNewVolumes = new HashMap<URI, Map<URI, Integer>>();
        Map<URI, Set<Initiator>> existingMasksToUpdateWithNewInitiators = new HashMap<URI, Set<Initiator>>();
        for (Map.Entry<String, Set<URI>> entry : matchingExportMaskURIs.entrySet()) {
            URI initiatorURI = portNameToInitiatorURI.get(entry.getKey());
            Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorURI);
            // Keep track of those initiators that have been found to exist already
            // in some export mask on the array
            initiatorURIsCopy.remove(initiatorURI);
            // Get a list of the ExportMasks that were matched to the initiator
            List<URI> exportMaskURIs = new ArrayList<URI>();
            exportMaskURIs.addAll(entry.getValue());
            List<ExportMask> masks = _dbClient.queryObject(ExportMask.class, exportMaskURIs);
            _log.info(String.format("initiator %s masks {%s}", initiator.getInitiatorPort(), Joiner.on(',').join(exportMaskURIs)));
            for (ExportMask mask : masks) {
                // Check if there are any storage ports in the mask which are part of varray, if not found discard this mask
                if (Sets.intersection(storagePortURIsAssociatedWithVArrayAndStorageArray, mask.getStoragePorts()).isEmpty())
                    continue;
                if (null == mask.getMaskName()) {
                    String maskName = ExportMaskUtils.getMaskName(_dbClient, initiators, exportGroup, storage);
                    _log.info("Generated mask name: {}", maskName);
                    mask.setMaskName(maskName);
                }
                _log.info(String.format("mask %s has initiator %s", mask.getMaskName(), initiator.getInitiatorPort()));
                if (mask.getCreatedBySystem()) {
                    _log.info(String.format("initiator %s is in persisted mask %s", initiator.getInitiatorPort(), mask.getMaskName()));
                    // in our export group, because we would simply add to them.
                    if (mask.getInitiators() != null) {
                        for (String existingMaskInitiatorStr : mask.getInitiators()) {
                            // Now look at it from a different angle. Which one of our export group initiators
                            // are NOT in the current mask? And if so, if it belongs to the same host as an existing
                            // one,
                            // we should add it to this mask.
                            Iterator<URI> initiatorIter = initiatorURIsCopy.iterator();
                            while (initiatorIter.hasNext()) {
                                Initiator initiatorCopy = _dbClient.queryObject(Initiator.class, initiatorIter.next());
                                if (initiatorCopy != null && initiatorCopy.getId() != null && !mask.hasInitiator(initiatorCopy.getId().toString())) {
                                    Initiator existingMaskInitiator = _dbClient.queryObject(Initiator.class, URI.create(existingMaskInitiatorStr));
                                    if (existingMaskInitiator != null && initiatorCopy.getHost() != null && initiatorCopy.getHost().equals(existingMaskInitiator.getHost())) {
                                        // Add to the list of initiators we need to add to this mask
                                        Set<Initiator> existingMaskInitiators = existingMasksToUpdateWithNewInitiators.get(mask.getId());
                                        if (existingMaskInitiators == null) {
                                            existingMaskInitiators = new HashSet<Initiator>();
                                            existingMasksToUpdateWithNewInitiators.put(mask.getId(), existingMaskInitiators);
                                        }
                                        existingMaskInitiators.add(initiatorCopy);
                                        // remove this from the list of initiators we'll
                                        initiatorIter.remove();
                                    // make a new mask from
                                    }
                                }
                            }
                        }
                    }
                } else {
                    // Insert this initiator into the mask's list of initiators managed by the system.
                    // This will get persisted below.
                    mask.addInitiator(initiator);
                    if (!NullColumnValueGetter.isNullURI(initiator.getHost())) {
                        hostToExistingExportMaskMap.put(initiator.getHost(), mask.getId());
                    }
                }
                // if it doesn't then we'll add it to the list of volumes to add.
                for (URI boURI : volumeURIs) {
                    BlockObject bo = BlockObject.fetch(_dbClient, boURI);
                    if (!mask.hasExistingVolume(bo)) {
                        _log.info(String.format("volume %s is not in mask %s", bo.getNativeGuid(), mask.getMaskName()));
                        // The volume doesn't exist, so we have to add it to
                        // the masking container.
                        Map<URI, Integer> newVolumes = existingMasksToUpdateWithNewVolumes.get(mask.getId());
                        if (newVolumes == null) {
                            newVolumes = new HashMap<URI, Integer>();
                            existingMasksToUpdateWithNewVolumes.put(mask.getId(), newVolumes);
                        }
                        // Check if the requested HLU for the volume is
                        // already taken by a pre-existing volume.
                        Integer requestedHLU = volumeMap.get(bo.getId());
                        StringMap existingVolumesInMask = mask.getExistingVolumes();
                        if (existingVolumesInMask != null && requestedHLU.intValue() != ExportGroup.LUN_UNASSIGNED && !ExportGroup.LUN_UNASSIGNED_DECIMAL_STR.equals(requestedHLU.toString()) && existingVolumesInMask.containsValue(requestedHLU.toString())) {
                            ExportOrchestrationTask completer = new ExportOrchestrationTask(exportGroup.getId(), token);
                            ServiceError serviceError = DeviceControllerException.errors.exportHasExistingVolumeWithRequestedHLU(boURI.toString(), requestedHLU.toString());
                            completer.error(_dbClient, serviceError);
                            return false;
                        }
                        newVolumes.put(bo.getId(), requestedHLU);
                        mask.addToUserCreatedVolumes(bo);
                    }
                }
                // Update the list of volumes and initiators for the mask
                Map<URI, Integer> volumeMapForExistingMask = existingMasksToUpdateWithNewVolumes.get(mask.getId());
                if (volumeMapForExistingMask != null && !volumeMapForExistingMask.isEmpty()) {
                    mask.addVolumes(volumeMapForExistingMask);
                }
                Set<Initiator> initiatorSetForExistingMask = existingMasksToUpdateWithNewInitiators.get(mask.getId());
                if (initiatorSetForExistingMask != null && initiatorSetForExistingMask.isEmpty()) {
                    mask.addInitiators(initiatorSetForExistingMask);
                }
                updateZoningMap(exportGroup, mask);
                _dbClient.updateObject(mask);
                // TODO: All export group modifications should be moved to completers
                exportGroup.addExportMask(mask.getId());
                _dbClient.updateObject(exportGroup);
            }
        }
        // The initiatorURIsCopy was used in the foreach initiator loop to see
        // which initiators already exist in a mask. If it is non-empty,
        // then it means there are initiators that are new,
        // so let's add them to the main tracker
        Map<URI, List<URI>> hostInitiatorMap = new HashMap<URI, List<URI>>();
        if (!initiatorURIsCopy.isEmpty()) {
            for (URI newExportMaskInitiator : initiatorURIsCopy) {
                Initiator initiator = _dbClient.queryObject(Initiator.class, newExportMaskInitiator);
                List<URI> initiatorSet = hostInitiatorMap.get(initiator.getHost());
                if (initiatorSet == null) {
                    initiatorSet = new ArrayList<URI>();
                    hostInitiatorMap.put(initiator.getHost(), initiatorSet);
                }
                initiatorSet.add(initiator.getId());
                _log.info(String.format("host = %s, " + "initiators to add: %d, " + "existingMasksToUpdateWithNewVolumes.size = %d", initiator.getHost(), hostInitiatorMap.get(initiator.getHost()).size(), existingMasksToUpdateWithNewVolumes.size()));
            }
        }
        _log.info(String.format("existingMasksToUpdateWithNewVolumes.size = %d", existingMasksToUpdateWithNewVolumes.size()));
        // and/or add volumes to existing masks.
        if (!hostInitiatorMap.isEmpty()) {
            for (URI hostID : hostInitiatorMap.keySet()) {
                // associated with that host to the list
                if (hostToExistingExportMaskMap.containsKey(hostID)) {
                    URI existingExportMaskURI = hostToExistingExportMaskMap.get(hostID);
                    Set<Initiator> toAddInits = new HashSet<Initiator>();
                    List<URI> hostInitaitorList = hostInitiatorMap.get(hostID);
                    for (URI initURI : hostInitaitorList) {
                        Initiator initiator = _dbClient.queryObject(Initiator.class, initURI);
                        if (!initiator.getInactive()) {
                            toAddInits.add(initiator);
                        }
                    }
                    _log.info(String.format("Need to add new initiators to existing mask %s, %s", existingExportMaskURI.toString(), Joiner.on(',').join(hostInitaitorList)));
                    existingMasksToUpdateWithNewInitiators.put(existingExportMaskURI, toAddInits);
                    continue;
                }
                // We have some brand new initiators, let's add them to new masks
                _log.info(String.format("new export masks %s", Joiner.on(",").join(hostInitiatorMap.get(hostID))));
                generateExportMaskCreateWorkflow(workflow, previousStep, storage, exportGroup, hostInitiatorMap.get(hostID), volumeMap, token);
            }
        }
        Map<URI, String> stepMap = new HashMap<URI, String>();
        for (Map.Entry<URI, Map<URI, Integer>> entry : existingMasksToUpdateWithNewVolumes.entrySet()) {
            ExportMask mask = _dbClient.queryObject(ExportMask.class, entry.getKey());
            Map<URI, Integer> volumesToAdd = entry.getValue();
            _log.info(String.format("adding these volumes %s to mask %s", Joiner.on(",").join(volumesToAdd.keySet()), mask.getMaskName()));
            stepMap.put(entry.getKey(), generateExportMaskAddVolumesWorkflow(workflow, null, storage, exportGroup, mask, volumesToAdd, null));
        }
        for (Entry<URI, Set<Initiator>> entry : existingMasksToUpdateWithNewInitiators.entrySet()) {
            ExportMask mask = _dbClient.queryObject(ExportMask.class, entry.getKey());
            Set<Initiator> initiatorsToAdd = entry.getValue();
            List<URI> initiatorsURIs = new ArrayList<URI>();
            for (Initiator initiator : initiatorsToAdd) {
                initiatorsURIs.add(initiator.getId());
            }
            _log.info(String.format("adding these initiators %s to mask %s", Joiner.on(",").join(initiatorsURIs), mask.getMaskName()));
            previousStep = stepMap.get(entry.getKey()) == null ? previousStep : stepMap.get(entry.getKey());
            generateExportMaskAddInitiatorsWorkflow(workflow, previousStep, storage, exportGroup, mask, initiatorsURIs, null, token);
        }
    }
    return true;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) List(java.util.List) BlockObject(com.emc.storageos.db.client.model.BlockObject) HashSet(java.util.HashSet) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) HashMap(java.util.HashMap) Map(java.util.Map) StringMap(com.emc.storageos.db.client.model.StringMap) ExportOrchestrationTask(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask)

Example 18 with ExportOrchestrationTask

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

the class HDSMaskingOrchestrator method exportGroupAddVolumes.

@Override
public void exportGroupAddVolumes(URI storageURI, URI exportGroupURI, Map<URI, Integer> volumeMap, String token) throws Exception {
    ExportOrchestrationTask taskCompleter = null;
    try {
        BlockStorageDevice device = getDevice();
        taskCompleter = new ExportOrchestrationTask(exportGroupURI, token);
        StorageSystem storage = _dbClient.queryObject(StorageSystem.class, storageURI);
        ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
        boolean anyVolumesAdded = false;
        boolean createdNewMask = false;
        if (exportGroup != null && exportGroup.getExportMasks() != null) {
            // Set up workflow steps.
            Workflow workflow = _workflowService.getNewWorkflow(MaskingWorkflowEntryPoints.getInstance(), "exportGroupAddVolumes", true, token);
            List<ExportMask> exportMasksToZoneAddVolumes = new ArrayList<ExportMask>();
            List<URI> volumesToZoneAddVolumes = new ArrayList<URI>();
            List<URI> exportMasksToZoneCreate = new ArrayList<URI>();
            Map<URI, Integer> volumesToZoneCreate = new HashMap<URI, Integer>();
            // Add the volume to all the ExportMasks that are contained in the
            // ExportGroup. The volumes should be added only if they don't
            // already exist for the ExportMask.
            Collection<URI> initiatorURIs = Collections2.transform(exportGroup.getInitiators(), CommonTransformerFunctions.FCTN_STRING_TO_URI);
            List<URI> hostURIs = new ArrayList<URI>();
            Map<String, URI> portNameToInitiatorURI = new HashMap<String, URI>();
            List<String> portNames = new ArrayList<String>();
            processInitiators(exportGroup, initiatorURIs, portNames, portNameToInitiatorURI, hostURIs);
            // We always want to have the full list of initiators for the hosts involved in
            // this export. This will allow the export operation to always find any
            // existing exports for a given host.
            queryHostInitiatorsAndAddToList(portNames, portNameToInitiatorURI, initiatorURIs, hostURIs);
            Map<String, Set<URI>> foundMatches = device.findExportMasks(storage, portNames, false);
            Set<String> checkMasks = mergeWithExportGroupMaskURIs(exportGroup, foundMatches.values());
            Set<String> storagePortURIsAssociatedWithVArrayAndStorageArray = ExportMaskUtils.getStoragePortUrisAssociatedWithVarrayAndStorageArray(storageURI, exportGroup.getVirtualArray(), _dbClient);
            for (String maskURIStr : checkMasks) {
                ExportMask exportMask = _dbClient.queryObject(ExportMask.class, URI.create(maskURIStr));
                // Check if there are any storage ports in the mask which are part of varray, if not found discard this mask
                if (Sets.intersection(storagePortURIsAssociatedWithVArrayAndStorageArray, exportMask.getStoragePorts()).isEmpty()) {
                    continue;
                }
                _log.info(String.format("Checking mask %s", exportMask.getMaskName()));
                if (!exportMask.getInactive() && exportMask.getStorageDevice().equals(storageURI)) {
                    exportMask = device.refreshExportMask(storage, exportMask);
                    // BlockStorageDevice level, so that it has up-to-date
                    // info from the array
                    Map<URI, Integer> volumesToAdd = getVolumesToAdd(volumeMap, exportMask, exportGroup, token);
                    // Not able to get VolumesToAdd due to error condition so, return
                    if (null == volumesToAdd) {
                        return;
                    }
                    _log.info(String.format("Mask %s, adding volumes %s", exportMask.getMaskName(), Joiner.on(',').join(volumesToAdd.entrySet())));
                    if (volumesToAdd.size() > 0) {
                        exportMasksToZoneAddVolumes.add(exportMask);
                        volumesToZoneAddVolumes.addAll(volumesToAdd.keySet());
                        // Make sure the zoning map is getting updated for user-created masks
                        updateZoningMap(exportGroup, exportMask, true);
                        generateExportMaskAddVolumesWorkflow(workflow, EXPORT_GROUP_ZONING_TASK, storage, exportGroup, exportMask, volumesToAdd, null);
                        anyVolumesAdded = true;
                        // associated it with the ExportGroup.
                        if (!exportGroup.hasMask(exportMask.getId())) {
                            exportGroup.addExportMask(exportMask.getId());
                            _dbClient.updateObject(exportGroup);
                        }
                    }
                }
            }
            if (!anyVolumesAdded) {
                // masks and if there are initiators for the export.
                if (!ExportMaskUtils.hasExportMaskForStorageAndVArray(_dbClient, exportGroup, storageURI) && exportGroup.hasInitiators()) {
                    _log.info("No existing masks to which the requested volumes can be added. Creating a new mask");
                    List<URI> initiators = StringSetUtil.stringSetToUriList(exportGroup.getInitiators());
                    Map<String, List<URI>> hostInitiatorMap = mapInitiatorsToComputeResource(exportGroup, initiators);
                    if (!hostInitiatorMap.isEmpty()) {
                        for (Map.Entry<String, List<URI>> resourceEntry : hostInitiatorMap.entrySet()) {
                            String computeKey = resourceEntry.getKey();
                            List<URI> computeInitiatorURIs = resourceEntry.getValue();
                            _log.info(String.format("New export masks for %s", computeKey));
                            GenExportMaskCreateWorkflowResult result = generateExportMaskCreateWorkflow(workflow, EXPORT_GROUP_ZONING_TASK, storage, exportGroup, computeInitiatorURIs, volumeMap, token);
                            exportMasksToZoneCreate.add(result.getMaskURI());
                            volumesToZoneCreate.putAll(volumeMap);
                        }
                        createdNewMask = true;
                    }
                }
            }
            if (!exportMasksToZoneAddVolumes.isEmpty()) {
                generateZoningAddVolumesWorkflow(workflow, null, exportGroup, exportMasksToZoneAddVolumes, volumesToZoneAddVolumes);
            }
            if (!exportMasksToZoneCreate.isEmpty()) {
                generateZoningCreateWorkflow(workflow, null, exportGroup, exportMasksToZoneCreate, volumesToZoneCreate);
            }
            String successMessage = String.format("Successfully added volumes to export on StorageArray %s", storage.getLabel());
            workflow.executePlan(taskCompleter, successMessage);
        } else {
            if (exportGroup.hasInitiators()) {
                _log.info("There are no masks for this export. Need to create anew.");
                List<URI> initiatorURIs = new ArrayList<URI>();
                for (String initiatorURIStr : exportGroup.getInitiators()) {
                    initiatorURIs.add(URI.create(initiatorURIStr));
                }
                // Invoke the export group create operation,
                // which should in turn create a workflow operations to
                // create the export for the newly added volume(s).
                exportGroupCreate(storageURI, exportGroupURI, initiatorURIs, volumeMap, token);
                anyVolumesAdded = true;
            } else {
                _log.warn("There are no initiator for export group: " + exportGroup.getLabel());
            }
        }
        if (!anyVolumesAdded && !createdNewMask) {
            taskCompleter.ready(_dbClient);
            _log.info("No volumes pushed to array because either they already exist " + "or there were no initiators added to the export yet.");
        }
    } catch (Exception ex) {
        _log.error("ExportGroup Orchestration failed.", ex);
        // TODO add service code here
        if (taskCompleter != null) {
            ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(ex.getMessage(), ex);
            taskCompleter.error(_dbClient, serviceError);
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) BlockStorageDevice(com.emc.storageos.volumecontroller.BlockStorageDevice) ArrayList(java.util.ArrayList) List(java.util.List) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) 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) StringMap(com.emc.storageos.db.client.model.StringMap) ExportOrchestrationTask(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask)

Example 19 with ExportOrchestrationTask

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

the class HDSMaskingOrchestrator method exportGroupCreate.

/**
 * Create storage level masking components to support the requested
 * ExportGroup object. This operation will be flexible enough to take into
 * account initiators that are in some already existent in some
 * StorageGroup. In such a case, the underlying masking component will be
 * "adopted" by the ExportGroup. Further operations against the "adopted"
 * mask will only allow for addition and removal of those initiators/volumes
 * that were added by a Bourne request. Existing initiators/volumes will be
 * maintained.
 *
 * @param storageURI
 *            - URI referencing underlying storage array
 * @param exportGroupURI
 *            - URI referencing Bourne-level masking, ExportGroup
 * @param initiatorURIs
 *            - List of Initiator URIs
 * @param volumeMap
 *            - Map of Volume URIs to requested Integer URI
 * @param token
 *            - Identifier for operation
 * @throws Exception
 */
@Override
public void exportGroupCreate(URI storageURI, URI exportGroupURI, List<URI> initiatorURIs, Map<URI, Integer> volumeMap, String token) throws Exception {
    ExportOrchestrationTask taskCompleter = null;
    try {
        BlockStorageDevice device = getDevice();
        ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
        StorageSystem storage = _dbClient.queryObject(StorageSystem.class, storageURI);
        taskCompleter = new ExportOrchestrationTask(exportGroupURI, token);
        if (initiatorURIs != null && !initiatorURIs.isEmpty()) {
            _log.info("export_create: initiator list non-empty");
            // Set up workflow steps.
            Workflow workflow = _workflowService.getNewWorkflow(MaskingWorkflowEntryPoints.getInstance(), "exportGroupCreate", true, token);
            // Create two steps, one for Zoning, one for the ExportGroup actions.
            // This step is for zoning. It is not specific to a single
            // NetworkSystem, as it will look at all the initiators and targets and compute
            // the zones required (which might be on multiple NetworkSystems.)
            boolean createdSteps = determineExportGroupCreateSteps(workflow, null, device, storage, exportGroup, initiatorURIs, volumeMap, false, token);
            String zoningStep = generateDeviceSpecificZoningCreateWorkflow(workflow, EXPORT_GROUP_MASKING_TASK, exportGroup, null, volumeMap);
            if (createdSteps && null != zoningStep) {
                // Execute the plan and allow the WorkflowExecutor to fire the
                // taskCompleter.
                String successMessage = String.format("ExportGroup successfully applied for StorageArray %s", storage.getLabel());
                workflow.executePlan(taskCompleter, successMessage);
            }
        } else {
            _log.info("export_create: initiator list");
            taskCompleter.ready(_dbClient);
        }
    } catch (DeviceControllerException dex) {
        if (taskCompleter != null) {
            taskCompleter.error(_dbClient, DeviceControllerException.errors.vmaxExportGroupCreateError(dex.getMessage()));
        }
    } catch (Exception ex) {
        _log.error("ExportGroup Orchestration failed.", ex);
        // TODO add service code here
        if (taskCompleter != null) {
            ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(ex.getMessage(), ex);
            taskCompleter.error(_dbClient, serviceError);
        }
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BlockStorageDevice(com.emc.storageos.volumecontroller.BlockStorageDevice) Workflow(com.emc.storageos.workflow.Workflow) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportOrchestrationTask(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 20 with ExportOrchestrationTask

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

the class MaskingWorkflowEntryPoints method rollbackChangePortGroupDeleteMask.

/**
 * Roll back change port group delete mask
 *
 * @param storageURI
 * @param exportGroupURI
 * @param exportMaskURI
 * @param contextKey
 * @param token
 * @throws ControllerException
 */
public void rollbackChangePortGroupDeleteMask(URI storageURI, URI exportGroupURI, URI exportMaskURI, String token) throws ControllerException {
    _log.info("Roll back change port group delete mask");
    ExportTaskCompleter taskCompleter = new ExportOrchestrationTask(exportGroupURI, token);
    StorageSystem storage = _dbClient.queryObject(StorageSystem.class, storageURI);
    getDevice(storage).rollbackChangePortGroupRemovePaths(storage, exportGroupURI, exportMaskURI, taskCompleter);
}
Also used : ExportTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportTaskCompleter) ExportOrchestrationTask(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

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