Search in sources :

Example 96 with Workflow

use of com.emc.storageos.workflow.Workflow in project coprhd-controller by CoprHD.

the class ScaleIOMaskingOrchestrator method exportGroupCreate.

@Override
public void exportGroupCreate(URI storageURI, URI exportGroupURI, List<URI> initiatorURIs, Map<URI, Integer> volumeMap, 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(), "exportGroupCreate", true, token);
            // Create a mapping of ExportMasks to Add Volumes to or
            // add to a list of new Exports to create
            Map<URI, Map<URI, Integer>> exportMaskToVolumesToAdd = new HashMap<>();
            List<URI> newInitiators = new ArrayList<>();
            List<Initiator> initiators = _dbClient.queryObject(Initiator.class, initiatorURIs);
            for (Initiator initiator : initiators) {
                List<ExportMask> exportMasks = ExportUtils.getInitiatorExportMasks(initiator, _dbClient);
                if (exportMasks == null || exportMasks.isEmpty()) {
                    newInitiators.add(initiator.getId());
                } else {
                    for (ExportMask exportMask : exportMasks) {
                        exportMaskToVolumesToAdd.put(exportMask.getId(), volumeMap);
                    }
                }
            }
            Map<String, List<URI>> computeResourceToInitiators = mapInitiatorsToComputeResource(exportGroup, newInitiators);
            log.info(String.format("Need to create ExportMasks for these compute resources %s", Joiner.on(',').join(computeResourceToInitiators.entrySet())));
            // there aren't any already existing ExportMask for them
            for (Map.Entry<String, List<URI>> toCreate : computeResourceToInitiators.entrySet()) {
                generateExportMaskCreateWorkflow(workflow, null, storage, exportGroup, toCreate.getValue(), volumeMap, token);
            }
            log.info(String.format("Need to add volumes for these ExportMasks %s", exportMaskToVolumesToAdd.entrySet()));
            // concept ExportMasks.
            for (Map.Entry<URI, Map<URI, Integer>> toAddVolumes : exportMaskToVolumesToAdd.entrySet()) {
                ExportMask exportMask = _dbClient.queryObject(ExportMask.class, toAddVolumes.getKey());
                generateExportMaskAddVolumesWorkflow(workflow, null, storage, exportGroup, exportMask, toAddVolumes.getValue(), null);
            }
            String successMessage = String.format("ExportGroup successfully applied for StorageArray %s", storage.getLabel());
            workflow.executePlan(taskCompleter, successMessage);
        } else {
            taskCompleter.ready(_dbClient);
        }
    } catch (DeviceControllerException dex) {
        taskCompleter.error(_dbClient, DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("exportGroupCreate", dex.getMessage()));
    } catch (Exception ex) {
        _log.error("ExportGroup Orchestration failed.", ex);
        taskCompleter.error(_dbClient, DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("exportGroupCreate", 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 97 with Workflow

use of com.emc.storageos.workflow.Workflow 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 98 with Workflow

use of com.emc.storageos.workflow.Workflow in project coprhd-controller by CoprHD.

the class ExportWorkflowUtils method generateExportGroupAddVolumes.

public String generateExportGroupAddVolumes(Workflow workflow, String wfGroupId, String waitFor, URI storage, URI export, Map<URI, Integer> volumeMap) throws WorkflowException {
    DiscoveredSystemObject storageSystem = getStorageSystem(_dbClient, storage);
    Workflow.Method rollback = rollbackMethodNullMethod();
    if (export != null) {
        ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, export);
        // with RP+VPlex. This allows the RP orchestration sub-workflow to rollback correctly.
        if (DiscoveredDataObject.Type.vplex.name().equals(storageSystem.getSystemType()) && exportGroup.checkInternalFlags(Flag.RECOVERPOINT)) {
            List<URI> volumeList = new ArrayList<URI>();
            volumeList.addAll(volumeMap.keySet());
            rollback = ExportWorkflowEntryPoints.exportRemoveVolumesMethod(storage, export, volumeList);
        }
    }
    Workflow.Method method = ExportWorkflowEntryPoints.exportAddVolumesMethod(storage, export, volumeMap);
    return newWorkflowStep(workflow, wfGroupId, String.format("Adding volumes to export (%s) on storage array %s", export, storageSystem.getNativeGuid()), storageSystem, method, rollback, waitFor, null);
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ArrayList(java.util.ArrayList) Workflow(com.emc.storageos.workflow.Workflow) DiscoveredSystemObject(com.emc.storageos.db.client.model.DiscoveredSystemObject) URI(java.net.URI)

Example 99 with Workflow

use of com.emc.storageos.workflow.Workflow in project coprhd-controller by CoprHD.

the class ExportWorkflowUtils method generateChangeAutoTieringPolicy.

/**
 * Generate a Workflow Step to change the Auto-tiering policy for the volumes
 * in a specific Export Mask.
 *
 * @param workflow the workflow
 * @param wfGroupId - Workflow group for the Step
 * @param waitFor - Wait on this step/group to complete in the workflow before execution
 * @param storageURI the storage system uri
 * @param volumeURIs the volume uris
 * @param newVpoolURI the new vpool uri
 * @param oldVpoolURI the old vpool uri *
 * @return stepId for the generated workflow Step
 * @throws ControllerException the controller exception
 */
public String generateChangeAutoTieringPolicy(Workflow workflow, String wfGroupId, String waitFor, URI storageURI, List<URI> volumeURIs, URI newVpoolURI, URI oldVpoolURI) throws ControllerException {
    DiscoveredSystemObject storageSystem = getStorageSystem(_dbClient, storageURI);
    Workflow.Method method = ExportWorkflowEntryPoints.changeAutoTieringPolicyMethod(storageURI, volumeURIs, newVpoolURI, false);
    // same method is called as a roll back step by passing old vPool.
    // boolean is passed to differentiate it.
    Workflow.Method rollback = ExportWorkflowEntryPoints.changeAutoTieringPolicyMethod(storageURI, volumeURIs, oldVpoolURI, true);
    return newWorkflowStep(workflow, wfGroupId, String.format("Updating Auto-tiering Policy on storage array %s (%s, args) for volumes %s", storageSystem.getNativeGuid(), storageURI, Joiner.on("\t").join(volumeURIs)), storageSystem, method, rollback, waitFor, null);
}
Also used : Workflow(com.emc.storageos.workflow.Workflow) DiscoveredSystemObject(com.emc.storageos.db.client.model.DiscoveredSystemObject)

Example 100 with Workflow

use of com.emc.storageos.workflow.Workflow in project coprhd-controller by CoprHD.

the class ExportWorkflowUtils method generateExportGroupChangePortWorkflow.

/**
 * Generate step for change port group
 *
 * @param workflow - Workflow
 * @param wfGroupId - Workflow group Id
 * @param exportGroupURI - Export group URI
 * @param portGroupURI - New port group URI
 * @param exportMaskURIs - The URI list of affected export masks in the export group
 * @param waitForApproval - If wait until approval
 * @return - The generated step
 * @throws ControllerException
 */
public String generateExportGroupChangePortWorkflow(Workflow workflow, String wfGroupId, URI exportGroupURI, URI portGroupURI, List<URI> exportMaskURIs, boolean waitForApproval) throws ControllerException {
    Workflow.Method rollbackMethod = rollbackMethodNullMethod();
    ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
    StoragePortGroup portGroup = _dbClient.queryObject(StoragePortGroup.class, portGroupURI);
    DiscoveredSystemObject system = _dbClient.queryObject(StorageSystem.class, portGroup.getStorageDevice());
    Workflow.Method method = ExportWorkflowEntryPoints.exportChangePortGroupMethod(system.getId(), exportGroupURI, portGroupURI, exportMaskURIs, waitForApproval);
    String stepDescription = String.format("Change port group to %s for the export group %s", portGroup.getNativeGuid(), exportGroup.getLabel());
    return newWorkflowStep(workflow, wfGroupId, stepDescription, system, method, rollbackMethod, null);
}
Also used : StoragePortGroup(com.emc.storageos.db.client.model.StoragePortGroup) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Workflow(com.emc.storageos.workflow.Workflow) DiscoveredSystemObject(com.emc.storageos.db.client.model.DiscoveredSystemObject)

Aggregations

Workflow (com.emc.storageos.workflow.Workflow)285 URI (java.net.URI)204 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)171 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)127 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)126 ControllerException (com.emc.storageos.volumecontroller.ControllerException)126 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)124 ArrayList (java.util.ArrayList)123 WorkflowException (com.emc.storageos.workflow.WorkflowException)119 NamedURI (com.emc.storageos.db.client.model.NamedURI)102 Volume (com.emc.storageos.db.client.model.Volume)76 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)72 HashMap (java.util.HashMap)66 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)65 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)61 ExportMask (com.emc.storageos.db.client.model.ExportMask)54 ExportTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportTaskCompleter)54 List (java.util.List)54 BlockObject (com.emc.storageos.db.client.model.BlockObject)41 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)41