Search in sources :

Example 1 with Workflow

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

the class RPDeviceController method createSnapshot.

/*
     * (non-Javadoc)
     * 
     * @see com.emc.storageos.protectioncontroller.RPController#createSnapshot(java.net.URI, java.net.URI, java.util.List,
     * java.lang.Boolean, java.lang.Boolean, java.lang.String)
     */
@Override
public void createSnapshot(URI protectionDevice, URI storageURI, List<URI> snapshotList, Boolean createInactive, Boolean readOnly, String opId) throws InternalException {
    TaskCompleter completer = new BlockSnapshotCreateCompleter(snapshotList, opId);
    // if snapshot is part of a CG, add CG id to the completer
    List<BlockSnapshot> snapshots = _dbClient.queryObject(BlockSnapshot.class, snapshotList);
    ControllerUtils.checkSnapshotsInConsistencyGroup(snapshots, _dbClient, completer);
    Map<URI, Integer> snapshotMap = new HashMap<URI, Integer>();
    try {
        ProtectionSystem system = null;
        system = _dbClient.queryObject(ProtectionSystem.class, protectionDevice);
        // Verify non-null storage device returned from the database client.
        if (system == null) {
            throw DeviceControllerExceptions.recoverpoint.failedConnectingForMonitoring(protectionDevice);
        }
        // Make sure we have at least 1 snap/bookmark otherwise there is nothing to create
        if (snapshotList == null || snapshotList.isEmpty()) {
            throw DeviceControllerExceptions.recoverpoint.failedToFindExpectedBookmarks();
        }
        // A temporary date/time stamp
        String snapshotName = VIPR_SNAPSHOT_PREFIX + new SimpleDateFormat("yyMMdd-HHmmss").format(new java.util.Date());
        Set<String> volumeWWNs = new HashSet<String>();
        boolean rpBookmarkOnly = false;
        for (URI snapshotID : snapshotList) {
            // create a snapshot map, a map is required to re-use the existing enable image access method.
            // using a lun number of -1 for all snaps, this value is not used, hence ok to use that value.
            snapshotMap.put(snapshotID, ExportGroup.LUN_UNASSIGNED);
        }
        // Get the volume associated with this snapshot.
        // Note we could have multiple snapshots in this request depending on the number of targets for the
        // source. We only need 1 of the snapshots to create the bookmark on RP. So just grab the
        // first one in the list.
        BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotList.get(0));
        if (snapshot.getEmName() != null) {
            rpBookmarkOnly = true;
            snapshotName = snapshot.getEmName();
        }
        Volume volume = _dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
        // if not, then the "volume" object is a regular block volume that is RP protected.
        if (Volume.checkForVplexBackEndVolume(_dbClient, volume)) {
            volumeWWNs.add(RPHelper.getRPWWn(Volume.fetchVplexVolume(_dbClient, volume).getId(), _dbClient));
        } else {
            volumeWWNs.add(RPHelper.getRPWWn(volume.getId(), _dbClient));
        }
        // Create a new token/taskid and use that in the workflow.
        // Multiple threads entering this method might collide with each others workflows in cassandra if the taskid
        // is not unique.
        String newToken = UUID.randomUUID().toString();
        // Set up workflow steps.
        Workflow workflow = _workflowService.getNewWorkflow(this, "createSnapshot", true, newToken);
        // Step 1 - Create a RP bookmark
        String waitFor = addCreateBookmarkStep(workflow, snapshotList, system, snapshotName, volumeWWNs, rpBookmarkOnly, null);
        if (!rpBookmarkOnly) {
            // Local array snap, additional steps required for snap operation
            // Step 2 - Enable image access
            waitFor = addEnableImageAccessStep(workflow, system, snapshotMap, waitFor);
            // Step 3 - Invoke block storage doCreateSnapshot
            waitFor = addCreateBlockSnapshotStep(workflow, waitFor, storageURI, snapshotList, createInactive, readOnly, system);
            // Step 4 - Disable image access
            addBlockSnapshotDisableImageAccessStep(workflow, waitFor, snapshotList, system);
        } else {
            _log.info("RP Bookmark only requested...");
        }
        String successMessage = String.format("Successfully created snapshot for %s", Joiner.on(",").join(snapshotList));
        workflow.executePlan(completer, successMessage);
    } catch (InternalException e) {
        _log.error("Operation failed with Exception: ", e);
        if (completer != null) {
            completer.error(_dbClient, e);
        }
    } catch (Exception e) {
        _log.error("Operation failed with Exception: ", e);
        if (completer != null) {
            completer.error(_dbClient, DeviceControllerException.errors.jobFailed(e));
        }
    }
}
Also used : HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Workflow(com.emc.storageos.workflow.Workflow) BlockSnapshotCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) Date(java.util.Date) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) LockRetryException(com.emc.storageos.locking.LockRetryException) FunctionalAPIActionFailedException_Exception(com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) FunctionalAPIInternalError_Exception(com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroupUpdateTaskCompleter(com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) VolumeVpoolChangeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeVpoolChangeTaskCompleter) RPCGProtectionTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.RPCGProtectionTaskCompleter) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet)

Example 2 with Workflow

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

the class RPDeviceController method exportGroupDelete.

/*
     * RPDeviceController.exportGroupDelete()
     * 
     * This method is a mini-orchestration of all of the steps necessary to delete an export group.
     * 
     * This controller does not service block devices for export, only RP bookmark snapshots.
     * 
     * The method is responsible for performing the following steps:
     * - Call the block controller to delete the export of the target volumes
     * - Disable the bookmarks associated with the snapshots.
     * 
     * @param protectionDevice The RP System used to manage the protection
     * 
     * @param exportgroupID The export group
     * 
     * @param token The task object associated with the volume creation task that we piggy-back our events on
     */
@Override
public void exportGroupDelete(URI protectionDevice, URI exportGroupID, String token) throws InternalException {
    TaskCompleter taskCompleter = null;
    try {
        // Grab the RP System information; we'll need it to talk to the RP client
        ProtectionSystem rpSystem = getRPSystem(protectionDevice);
        taskCompleter = new RPCGExportDeleteCompleter(exportGroupID, token);
        // Create a new token/taskid and use that in the workflow. Multiple threads entering this method might
        // collide with each others
        // workflows in cassandra if the taskid is not unique.
        String newToken = UUID.randomUUID().toString();
        // Set up workflow steps.
        Workflow workflow = _workflowService.getNewWorkflow(this, "exportGroupDelete", true, newToken);
        // Task 1: deactivate the bookmarks
        // 
        // Disable image access on the target volumes
        // This is important to do first because:
        // After the export group is deleted (in the next step), we may not have access to the object.
        // If export delete itself were to fail, it's good that we at least got this step done. Easier to remediate.
        addDisableImageAccessSteps(workflow, rpSystem, exportGroupID);
        // Task 2: Export Delete Volumes
        // 
        // Delete of the export group with the volumes associated with the snapshots to the host
        addExportSnapshotDeleteSteps(workflow, rpSystem, exportGroupID);
        // Execute the plan and allow the WorkflowExecutor to fire the taskCompleter.
        String successMessage = String.format("Workflow of Export Group %s Delete successfully created", exportGroupID);
        workflow.executePlan(taskCompleter, successMessage);
    } catch (InternalException e) {
        _log.error("Operation failed with Exception: ", e);
        if (taskCompleter != null) {
            taskCompleter.error(_dbClient, e);
        }
    } catch (Exception e) {
        _log.error("Operation failed with Exception: ", e);
        if (taskCompleter != null) {
            taskCompleter.error(_dbClient, DeviceControllerException.errors.jobFailed(e));
        }
    }
}
Also used : RPCGExportDeleteCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.RPCGExportDeleteCompleter) Workflow(com.emc.storageos.workflow.Workflow) VolumeGroupUpdateTaskCompleter(com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) VolumeVpoolChangeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeVpoolChangeTaskCompleter) RPCGProtectionTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.RPCGProtectionTaskCompleter) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) LockRetryException(com.emc.storageos.locking.LockRetryException) FunctionalAPIActionFailedException_Exception(com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) FunctionalAPIInternalError_Exception(com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 3 with Workflow

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

the class RPDeviceController method exportGroupCreate.

/*
     * RPDeviceController.exportGroupCreate()
     * 
     * This method is a mini-orchestration of all of the steps necessary to create an export based on
     * a Bourne Snapshot object associated with a RecoverPoint bookmark.
     * 
     * This controller does not service block devices for export, only RP bookmark snapshots.
     * 
     * The method is responsible for performing the following steps:
     * - Enable the volumes to a specific bookmark.
     * - Call the block controller to export the target volume
     * 
     * @param protectionDevice The RP System used to manage the protection
     * 
     * @param exportgroupID The export group
     * 
     * @param snapshots snapshot list
     * 
     * @param initatorURIs initiators to send to the block controller
     * 
     * @param token The task object
     */
@Override
public void exportGroupCreate(URI protectionDevice, URI exportGroupID, List<URI> initiatorURIs, Map<URI, Integer> snapshots, String token) throws ControllerException {
    TaskCompleter taskCompleter = null;
    try {
        // Grab the RP System information; we'll need it to talk to the RP client
        ProtectionSystem rpSystem = getRPSystem(protectionDevice);
        taskCompleter = new RPCGExportCompleter(exportGroupID, token);
        // Ensure the bookmarks actually exist before creating the export group
        searchForBookmarks(protectionDevice, snapshots.keySet());
        // Create a new token/taskid and use that in the workflow. Multiple threads entering this method might
        // collide with each others
        // workflows in cassandra if the taskid is not unique.
        String newToken = UUID.randomUUID().toString();
        // Set up workflow steps.
        Workflow workflow = _workflowService.getNewWorkflow(this, "exportGroupCreate", true, newToken);
        // Tasks 1: Activate the bookmarks
        // 
        // Enable image access on the target volumes
        addEnableImageAccessStep(workflow, rpSystem, snapshots, null);
        // Tasks 2: Export Volumes
        // 
        // Export the volumes associated with the snapshots to the host
        addExportSnapshotSteps(workflow, rpSystem, exportGroupID, snapshots, initiatorURIs);
        // Execute the plan and allow the WorkflowExecutor to fire the taskCompleter.
        String successMessage = String.format("Workflow of Export Group %s successfully created", exportGroupID);
        workflow.executePlan(taskCompleter, successMessage);
    } catch (InternalException e) {
        _log.error("Operation failed with Exception: ", e);
        if (taskCompleter != null) {
            taskCompleter.error(_dbClient, e);
        }
    } catch (Exception e) {
        _log.error("Operation failed with Exception: ", e);
        if (taskCompleter != null) {
            taskCompleter.error(_dbClient, DeviceControllerException.errors.jobFailed(e));
        }
    }
}
Also used : Workflow(com.emc.storageos.workflow.Workflow) RPCGExportCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.RPCGExportCompleter) VolumeGroupUpdateTaskCompleter(com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) VolumeVpoolChangeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeVpoolChangeTaskCompleter) RPCGProtectionTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.RPCGProtectionTaskCompleter) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) LockRetryException(com.emc.storageos.locking.LockRetryException) FunctionalAPIActionFailedException_Exception(com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) FunctionalAPIInternalError_Exception(com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 4 with Workflow

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

the class RPDeviceController method exportOrchestrationSteps.

/**
 * @param volumeDescriptors
 *            - Volume descriptors
 * @param rpSystemId
 *            - RP system
 * @param taskId
 *            - task ID
 * @return - True on success, false otherwise
 * @throws InternalException
 */
public boolean exportOrchestrationSteps(List<VolumeDescriptor> volumeDescriptors, URI rpSystemId, String taskId) throws InternalException {
    List<URI> volUris = VolumeDescriptor.getVolumeURIs(volumeDescriptors);
    RPCGExportOrchestrationCompleter completer = new RPCGExportOrchestrationCompleter(volUris, taskId);
    Workflow workflow = null;
    boolean lockException = false;
    Map<URI, Set<URI>> exportGroupVolumesAdded = new HashMap<URI, Set<URI>>();
    exportGroupsCreated = new ArrayList<URI>();
    final String COMPUTE_RESOURCE_CLUSTER = "cluster";
    try {
        final String workflowKey = "rpExportOrchestration";
        if (!WorkflowService.getInstance().hasWorkflowBeenCreated(taskId, workflowKey)) {
            // Generate the Workflow.
            workflow = _workflowService.getNewWorkflow(this, EXPORT_ORCHESTRATOR_WF_NAME, true, taskId);
            // the wait for key returned by previous call
            String waitFor = null;
            ProtectionSystem rpSystem = _dbClient.queryObject(ProtectionSystem.class, rpSystemId);
            // Get the CG Params based on the volume descriptors
            CGRequestParams params = this.getCGRequestParams(volumeDescriptors, rpSystem);
            updateCGParams(params);
            _log.info("Start adding RP Export Volumes steps....");
            // Get the RP Exports from the CGRequestParams object
            Collection<RPExport> rpExports = generateStorageSystemExportMaps(params, volumeDescriptors);
            Map<String, Set<URI>> rpSiteInitiatorsMap = getRPSiteInitiators(rpSystem, rpExports);
            // Acquire all the RP lock keys needed for export before we start assembling the export groups.
            acquireRPLockKeysForExport(taskId, rpExports, rpSiteInitiatorsMap);
            // or create a new one.
            for (RPExport rpExport : rpExports) {
                URI storageSystemURI = rpExport.getStorageSystem();
                String internalSiteName = rpExport.getRpSite();
                URI varrayURI = rpExport.getVarray();
                List<URI> volumes = rpExport.getVolumes();
                List<URI> initiatorSet = new ArrayList<URI>();
                String rpSiteName = (rpSystem.getRpSiteNames() != null) ? rpSystem.getRpSiteNames().get(internalSiteName) : internalSiteName;
                StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
                VirtualArray varray = _dbClient.queryObject(VirtualArray.class, varrayURI);
                _log.info("--------------------");
                _log.info(String.format("RP Export: StorageSystem = [%s] RPSite = [%s] VirtualArray = [%s]", storageSystem.getLabel(), rpSiteName, varray.getLabel()));
                boolean isJournalExport = rpExport.getIsJournalExport();
                String exportGroupGeneratedName = RPHelper.generateExportGroupName(rpSystem, storageSystem, internalSiteName, varray, isJournalExport);
                // Setup the export group - we may or may not need to create it, but we need to have everything ready in case we do
                ExportGroup exportGroup = RPHelper.createRPExportGroup(exportGroupGeneratedName, varray, _dbClient.queryObject(Project.class, params.getProject()), 0, isJournalExport);
                // Get the initiators of the RP Cluster (all of the RPAs on one side of a configuration)
                Map<String, Map<String, String>> rpaWWNs = RPHelper.getRecoverPointClient(rpSystem).getInitiatorWWNs(internalSiteName);
                if (rpaWWNs == null || rpaWWNs.isEmpty()) {
                    throw DeviceControllerExceptions.recoverpoint.noInitiatorsFoundOnRPAs();
                }
                // Convert to initiator object
                List<Initiator> initiators = new ArrayList<Initiator>();
                for (String rpaId : rpaWWNs.keySet()) {
                    for (Map.Entry<String, String> rpaWWN : rpaWWNs.get(rpaId).entrySet()) {
                        Initiator initiator = ExportUtils.getInitiator(rpaWWN.getKey(), _dbClient);
                        initiators.add(initiator);
                    }
                }
                // We need to find and distill only those RP initiators that correspond to the network of the
                // storage
                // system and
                // that network has front end port from the storage system.
                // In certain lab environments, its quite possible that there are 2 networks one for the storage
                // system
                // FE ports and one for
                // the BE ports.
                // In such configs, RP initiators will be spread across those 2 networks. RP controller does not
                // care
                // about storage system
                // back-end ports, so
                // we will ignore those initiators that are connected to a network that has only storage system back
                // end
                // port connectivity.
                Map<URI, Set<Initiator>> rpNetworkToInitiatorsMap = new HashMap<URI, Set<Initiator>>();
                Set<URI> rpSiteInitiatorUris = rpSiteInitiatorsMap.get(internalSiteName);
                if (rpSiteInitiatorUris != null) {
                    for (URI rpSiteInitiatorUri : rpSiteInitiatorUris) {
                        Initiator rpSiteInitiator = _dbClient.queryObject(Initiator.class, rpSiteInitiatorUri);
                        URI rpInitiatorNetworkURI = getInitiatorNetwork(exportGroup, rpSiteInitiator);
                        if (rpInitiatorNetworkURI != null) {
                            if (rpNetworkToInitiatorsMap.get(rpInitiatorNetworkURI) == null) {
                                rpNetworkToInitiatorsMap.put(rpInitiatorNetworkURI, new HashSet<Initiator>());
                            }
                            rpNetworkToInitiatorsMap.get(rpInitiatorNetworkURI).add(rpSiteInitiator);
                            _log.info(String.format("RP Initiator [%s] found on network: [%s]", rpSiteInitiator.getInitiatorPort(), rpInitiatorNetworkURI.toASCIIString()));
                        } else {
                            _log.info(String.format("RP Initiator [%s] was not found on any network. Excluding from automated exports", rpSiteInitiator.getInitiatorPort()));
                        }
                    }
                }
                // Compute numPaths. This is how its done:
                // We know the RP site and the Network/TransportZone it is on.
                // Determine all the storage ports for the storage array for all the networks they are on.
                // Next, if we find the network for the RP site in the above list, return all the storage ports
                // corresponding to that.
                // For RP we will try and use as many Storage ports as possible.
                Map<URI, List<StoragePort>> initiatorPortMap = getInitiatorPortsForArray(rpNetworkToInitiatorsMap, storageSystemURI, varrayURI, rpSiteName);
                for (URI networkURI : initiatorPortMap.keySet()) {
                    for (StoragePort storagePort : initiatorPortMap.get(networkURI)) {
                        _log.info(String.format("Network : [%s] - Port : [%s]", networkURI.toString(), storagePort.getLabel()));
                    }
                }
                int numPaths = computeNumPaths(initiatorPortMap, varrayURI, storageSystem);
                _log.info("Total paths = " + numPaths);
                // Stems from above comment where we distill the RP network and the initiators in that network.
                List<Initiator> initiatorList = new ArrayList<Initiator>();
                for (URI rpNetworkURI : rpNetworkToInitiatorsMap.keySet()) {
                    if (initiatorPortMap.containsKey(rpNetworkURI)) {
                        initiatorList.addAll(rpNetworkToInitiatorsMap.get(rpNetworkURI));
                    }
                }
                for (Initiator initiator : initiatorList) {
                    initiatorSet.add(initiator.getId());
                }
                // See if the export group already exists
                ExportGroup exportGroupInDB = exportGroupExistsInDB(exportGroup);
                boolean addExportGroupToDB = false;
                if (exportGroupInDB != null) {
                    exportGroup = exportGroupInDB;
                    // If the export already exists, check to see if any of the volumes have already been exported.
                    // No
                    // need to
                    // re-export volumes.
                    List<URI> volumesToRemove = new ArrayList<URI>();
                    for (URI volumeURI : volumes) {
                        if (exportGroup.getVolumes() != null && !exportGroup.getVolumes().isEmpty() && exportGroup.getVolumes().containsKey(volumeURI.toString())) {
                            _log.info(String.format("Volume [%s] already exported to export group [%s], " + "it will be not be re-exported", volumeURI.toString(), exportGroup.getGeneratedName()));
                            volumesToRemove.add(volumeURI);
                        }
                    }
                    // Remove volumes if they have already been exported
                    if (!volumesToRemove.isEmpty()) {
                        volumes.removeAll(volumesToRemove);
                    }
                    // nothing else needs to be done here.
                    if (volumes.isEmpty()) {
                        _log.info(String.format("No volumes needed to be exported to export group [%s], continue", exportGroup.getGeneratedName()));
                        continue;
                    }
                } else {
                    addExportGroupToDB = true;
                }
                // Add volumes to the export group
                Map<URI, Integer> volumesToAdd = new HashMap<URI, Integer>();
                for (URI volumeID : volumes) {
                    exportGroup.addVolume(volumeID, ExportGroup.LUN_UNASSIGNED);
                    volumesToAdd.put(volumeID, ExportGroup.LUN_UNASSIGNED);
                }
                // Keep track of volumes added to export group
                if (!volumesToAdd.isEmpty()) {
                    exportGroupVolumesAdded.put(exportGroup.getId(), volumesToAdd.keySet());
                }
                // volume
                if (rpExport.getComputeResource() != null) {
                    URI computeResource = rpExport.getComputeResource();
                    _log.info(String.format("RP Export: ComputeResource : %s", computeResource.toString()));
                    if (computeResource.toString().toLowerCase().contains(COMPUTE_RESOURCE_CLUSTER)) {
                        Cluster cluster = _dbClient.queryObject(Cluster.class, computeResource);
                        exportGroup.addCluster(cluster);
                    } else {
                        Host host = _dbClient.queryObject(Host.class, rpExport.getComputeResource());
                        exportGroup.addHost(host);
                    }
                }
                // Persist the export group
                if (addExportGroupToDB) {
                    exportGroup.addInitiators(initiatorSet);
                    exportGroup.setNumPaths(numPaths);
                    _dbClient.createObject(exportGroup);
                    // Keep track of newly created EGs in case of rollback
                    exportGroupsCreated.add(exportGroup.getId());
                } else {
                    _dbClient.updateObject(exportGroup);
                }
                // If the export group already exists, add the volumes to it, otherwise create a brand new
                // export group.
                StringBuilder buffer = new StringBuilder();
                buffer.append(String.format(DASHED_NEWLINE));
                if (!addExportGroupToDB) {
                    buffer.append(String.format("Adding volumes to existing Export Group for Storage System [%s], RP Site [%s], Virtual Array [%s]%n", storageSystem.getLabel(), rpSiteName, varray.getLabel()));
                    buffer.append(String.format("Export Group name is : [%s]%n", exportGroup.getGeneratedName()));
                    buffer.append(String.format("Export Group will have these volumes added: [%s]%n", Joiner.on(',').join(volumes)));
                    buffer.append(String.format(DASHED_NEWLINE));
                    _log.info(buffer.toString());
                    waitFor = _exportWfUtils.generateExportGroupAddVolumes(workflow, STEP_EXPORT_GROUP, waitFor, storageSystemURI, exportGroup.getId(), volumesToAdd);
                    _log.info("Added Export Group add volumes step in workflow");
                } else {
                    buffer.append(String.format("Creating new Export Group for Storage System [%s], RP Site [%s], Virtual Array [%s]%n", storageSystem.getLabel(), rpSiteName, varray.getLabel()));
                    buffer.append(String.format("Export Group name is: [%s]%n", exportGroup.getGeneratedName()));
                    buffer.append(String.format("Export Group will have these initiators: [%s]%n", Joiner.on(',').join(initiatorSet)));
                    buffer.append(String.format("Export Group will have these volumes added: [%s]%n", Joiner.on(',').join(volumes)));
                    buffer.append(String.format(DASHED_NEWLINE));
                    _log.info(buffer.toString());
                    String exportStep = workflow.createStepId();
                    initTaskStatus(exportGroup, exportStep, Operation.Status.pending, "create export");
                    waitFor = _exportWfUtils.generateExportGroupCreateWorkflow(workflow, STEP_EXPORT_GROUP, waitFor, storageSystemURI, exportGroup.getId(), volumesToAdd, initiatorSet);
                    _log.info("Added Export Group create step in workflow. New Export Group Id: " + exportGroup.getId());
                }
            }
            String successMessage = "Export orchestration completed successfully";
            // Finish up and execute the plan.
            // The Workflow will handle the TaskCompleter
            Object[] callbackArgs = new Object[] { volUris };
            workflow.executePlan(completer, successMessage, new WorkflowCallback(), callbackArgs, null, null);
            // Mark this workflow as created/executed so we don't do it again on retry/resume
            WorkflowService.getInstance().markWorkflowBeenCreated(taskId, workflowKey);
        }
    } catch (LockRetryException ex) {
        /**
         * Added this catch block to mark the current workflow as completed so that lock retry will not get exception while creating new
         * workflow using the same taskid.
         */
        _log.warn(String.format("Lock retry exception key: %s remaining time %d", ex.getLockIdentifier(), ex.getRemainingWaitTimeSeconds()));
        if (workflow != null && !NullColumnValueGetter.isNullURI(workflow.getWorkflowURI()) && workflow.getWorkflowState() == WorkflowState.CREATED) {
            com.emc.storageos.db.client.model.Workflow wf = _dbClient.queryObject(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI());
            if (!wf.getCompleted()) {
                _log.error("Marking the status to completed for the newly created workflow {}", wf.getId());
                wf.setCompleted(true);
                _dbClient.updateObject(wf);
            }
        }
        throw ex;
    } catch (Exception ex) {
        _log.error("Could not create volumes: " + volUris, ex);
        // Rollback ViPR level RP export group changes
        rpExportGroupRollback();
        if (workflow != null) {
            _workflowService.releaseAllWorkflowLocks(workflow);
        }
        String opName = ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME.getName();
        ServiceError serviceError = null;
        if (lockException) {
            serviceError = DeviceControllerException.errors.createVolumesAborted(volUris.toString(), ex);
        } else {
            serviceError = DeviceControllerException.errors.createVolumesFailed(volUris.toString(), opName, ex);
        }
        completer.error(_dbClient, _locker, serviceError);
        return false;
    }
    _log.info("End adding RP Export Volumes steps.");
    return true;
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) RPCGExportOrchestrationCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.RPCGExportOrchestrationCompleter) Initiator(com.emc.storageos.db.client.model.Initiator) ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePort(com.emc.storageos.db.client.model.StoragePort) Workflow(com.emc.storageos.workflow.Workflow) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) LockRetryException(com.emc.storageos.locking.LockRetryException) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) LockRetryException(com.emc.storageos.locking.LockRetryException) FunctionalAPIActionFailedException_Exception(com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) FunctionalAPIInternalError_Exception(com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Project(com.emc.storageos.db.client.model.Project) CGRequestParams(com.emc.storageos.recoverpoint.requests.CGRequestParams) BlockObject(com.emc.storageos.db.client.model.BlockObject) DataObject(com.emc.storageos.db.client.model.DataObject) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap)

Example 5 with Workflow

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

the class RPDeviceController method addPreVolumeExpandSteps.

/**
 * RP specific workflow steps required prior to expanding the underlying volume are added here.
 * Ex. RP CG remove replication sets.
 *
 * @param workflow
 * @param volURI
 * @param expandVolURIs
 * @param taskId
 * @return
 * @throws WorkflowException
 */
public String addPreVolumeExpandSteps(Workflow workflow, List<VolumeDescriptor> volumeDescriptors, String taskId) throws WorkflowException {
    // Just grab a legit target volume that already has an assigned protection controller.
    // This will work for all operations, adding, removing, vpool change, etc.
    List<VolumeDescriptor> protectionControllerDescriptors = VolumeDescriptor.filterByType(volumeDescriptors, new VolumeDescriptor.Type[] { VolumeDescriptor.Type.RP_TARGET, VolumeDescriptor.Type.RP_VPLEX_VIRT_TARGET }, new VolumeDescriptor.Type[] {});
    // If there are no RP volumes, just return
    if (protectionControllerDescriptors.isEmpty()) {
        return null;
    }
    // Grab any volume from the list so we can grab the protection system, which will be the same for all volumes.
    Volume volume = _dbClient.queryObject(Volume.class, protectionControllerDescriptors.get(0).getVolumeURI());
    ProtectionSystem rpSystem = _dbClient.queryObject(ProtectionSystem.class, volume.getProtectionController());
    // Get only the RP volumes from the descriptors.
    List<VolumeDescriptor> volumeDescriptorsTypeFilter = VolumeDescriptor.filterByType(volumeDescriptors, new VolumeDescriptor.Type[] { VolumeDescriptor.Type.RP_SOURCE, VolumeDescriptor.Type.RP_EXISTING_SOURCE, VolumeDescriptor.Type.RP_VPLEX_VIRT_SOURCE }, new VolumeDescriptor.Type[] {});
    // If there are no RP volumes, just return
    if (volumeDescriptorsTypeFilter.isEmpty()) {
        return null;
    }
    for (VolumeDescriptor descriptor : volumeDescriptorsTypeFilter) {
        URI volURI = descriptor.getVolumeURI();
        ProtectionSystem rp = _dbClient.queryObject(ProtectionSystem.class, volume.getProtectionController());
        Map<String, RecreateReplicationSetRequestParams> rsetParams = new HashMap<String, RecreateReplicationSetRequestParams>();
        RecreateReplicationSetRequestParams rsetParam = getReplicationSettings(rpSystem, volURI);
        rsetParams.put(RPHelper.getRPWWn(volURI, _dbClient), rsetParam);
        String stepId = workflow.createStepId();
        Workflow.Method deleteRsetExecuteMethod = new Workflow.Method(METHOD_DELETE_RSET_STEP, rpSystem.getId(), Arrays.asList(volURI));
        Workflow.Method deleteRsetRollbackeMethod = new Workflow.Method(METHOD_DELETE_RSET_ROLLBACK_STEP, rpSystem.getId(), Arrays.asList(volURI), rsetParams);
        workflow.createStep(STEP_PRE_VOLUME_EXPAND, "Pre volume expand, delete replication set subtask for RP: " + volURI.toString(), null, rpSystem.getId(), rp.getSystemType(), this.getClass(), deleteRsetExecuteMethod, deleteRsetRollbackeMethod, stepId);
        _log.info("addPreVolumeExpandSteps Replication Set in workflow");
    }
    return STEP_PRE_VOLUME_EXPAND;
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) Volume(com.emc.storageos.db.client.model.Volume) HashMap(java.util.HashMap) Workflow(com.emc.storageos.workflow.Workflow) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) RecreateReplicationSetRequestParams(com.emc.storageos.recoverpoint.requests.RecreateReplicationSetRequestParams)

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