Search in sources :

Example 36 with ExportOperationContext

use of com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext in project coprhd-controller by CoprHD.

the class VPlexDeviceController method storageViewAddStoragePortsRollback.

/**
 * Rollback entry point. This is a wrapper around the storageViewRemoveStoragePorts
 * operation, which requires that we extract the export context using the roll back token
 * that's passed in and store it in the current step's context.
 *
 * @param vplexURI
 *            -- URI of VPlex StorageSystem
 * @param exportURI
 *            -- ExportGroup URI
 * @param maskURI
 *            -- ExportMask URI
 * @param targetURIs
 *            -- list of targets URIs
 * @param rollbackContextKey
 *            -- Context token
 * @param stepId
 *            -- Workflow step id.
 * @throws DeviceControllerException
 */
public void storageViewAddStoragePortsRollback(URI vplexURI, URI exportURI, URI maskURI, List<URI> targetURIs, String rollbackContextKey, String stepId) throws DeviceControllerException {
    // in order to only perform rollback of operations we successfully performed.
    try {
        ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(rollbackContextKey);
        WorkflowService.getInstance().storeStepData(stepId, context);
    } catch (ClassCastException e) {
        _log.info("Step {} has stored step data other than ExportOperationContext. Exception: {}", stepId, e);
    }
    storageViewRemoveStoragePorts(vplexURI, exportURI, maskURI, targetURIs, rollbackContextKey, stepId);
}
Also used : ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext)

Example 37 with ExportOperationContext

use of com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext in project coprhd-controller by CoprHD.

the class VPlexDeviceController method storageViewRemoveVolumes.

/**
 * @param client
 *            -- VPlexApiClient used for communication
 * @param exportGroupURI
 *            -- Export Group
 * @param exportMaskURI
 *            -- ExportMask corresponding to the StorageView
 * @param volumeURIList
 *            -- URI of virtual volumes
 * @param parentStepId
 *            -- Workflow parent step id
 * @param taskCompleter
 *            -- the task completer, used to find the rollback context,
 *               which will be non-null in the case of rollback
 * @param rollbackContextKey
 *            context key for rollback processing
 * @param stepId
 *            -- Workflow step id
 * @throws WorkflowException
 */
public void storageViewRemoveVolumes(URI vplexURI, URI exportGroupURI, URI exportMaskURI, List<URI> volumeURIList, String parentStepId, TaskCompleter taskCompleter, String rollbackContextKey, String stepId) throws WorkflowException {
    ExportMaskRemoveVolumeCompleter completer = null;
    ExportGroup exportGroup = null;
    ExportMask exportMask = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        List<URI> volumeIdsToProcess = new ArrayList<>(volumeURIList);
        exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
        exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        completer = new ExportMaskRemoveVolumeCompleter(exportGroup.getId(), exportMask.getId(), volumeURIList, stepId);
        // get the context from the task completer, in case this is a rollback.
        if (taskCompleter != null && rollbackContextKey != null) {
            ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(rollbackContextKey);
            if (context != null) {
                // a non-null context means this step is running as part of a rollback.
                List<URI> addedVolumes = new ArrayList<>();
                if (context.getOperations() != null) {
                    _log.info("Handling removeVolumes as a result of rollback");
                    ListIterator<ExportOperationContextOperation> li = context.getOperations().listIterator(context.getOperations().size());
                    while (li.hasPrevious()) {
                        ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
                        if (operation != null && VplexExportOperationContext.OPERATION_ADD_VOLUMES_TO_STORAGE_VIEW.equals(operation.getOperation())) {
                            addedVolumes = (List<URI>) operation.getArgs().get(0);
                            _log.info("Removing volumes {} as part of rollback", Joiner.on(',').join(addedVolumes));
                        }
                    }
                    if (addedVolumes == null || addedVolumes.isEmpty()) {
                        _log.info("There was no context found for add volumes. So there is nothing to rollback.");
                        completer.ready(_dbClient);
                        return;
                    }
                }
                // change the list of initiators to process to the
                // list that successfully were added during addInitiators.
                volumeIdsToProcess.clear();
                volumeIdsToProcess.addAll(addedVolumes);
            }
        }
        StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
        VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
        // Removes the specified volumes from the storage view
        // and updates the export mask.
        removeVolumesFromStorageViewAndMask(client, exportMask, volumeIdsToProcess, parentStepId);
        completer.ready(_dbClient);
    } catch (VPlexApiException vae) {
        _log.error("Exception removing volumes from Storage View: " + vae.getMessage(), vae);
        failStep(completer, stepId, vae);
    } catch (Exception ex) {
        _log.error("Exception removing volumes from Storage View: " + ex.getMessage(), ex);
        String opName = ResourceOperationTypeEnum.REMOVE_STORAGE_VIEW_VOLUME.getName();
        ServiceError serviceError = VPlexApiException.errors.storageViewRemoveVolumeFailed(exportMask != null ? exportMask.getMaskName() : "none", opName, ex);
        failStep(completer, stepId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) ExportOperationContextOperation(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation) ExportMaskRemoveVolumeCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportMaskRemoveVolumeCompleter) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 38 with ExportOperationContext

use of com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext in project coprhd-controller by CoprHD.

the class VPlexDeviceController method storageViewRemoveStoragePorts.

/**
 * Workflow Step to remove storage ports from Storage View.
 * Note arguments (except stepId) must match storageViewRemoveStoragePortsMethod above.
 *
 * @param vplexURI
 *            -- URI of VPlex StorageSystem
 * @param exportURI
 *            -- ExportGroup URI
 * @param maskURI
 *            -- ExportMask URI.
 * @param targetURIs
 *            -- list of targets URIs (VPLEX FE ports) to be removed.
 *            If non null, the targets (VPlex front end ports) indicated by the targetURIs will be removed
 *            from the Storage View.
 * @param rollbackContextKey
 *            -- Context token for rollback processing
 * @param stepId
 *            -- Workflow step id.
 * @throws WorkflowException
 */
public void storageViewRemoveStoragePorts(URI vplexURI, URI exportURI, URI maskURI, List<URI> targetURIs, String rollbackContextKey, String stepId) throws DeviceControllerException {
    ExportMaskRemoveInitiatorCompleter completer = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        completer = new ExportMaskRemoveInitiatorCompleter(exportURI, maskURI, new ArrayList<URI>(), stepId);
        StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, maskURI);
        VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
        String vplexClusterName = VPlexUtil.getVplexClusterName(exportMask, vplexURI, client, _dbClient);
        Map<String, String> targetPortMap = VPlexControllerUtils.getTargetPortToPwwnMap(client, vplexClusterName);
        VPlexStorageViewInfo storageView = client.getStorageView(vplexClusterName, exportMask.getMaskName());
        _log.info("Refreshing ExportMask {}", exportMask.getMaskName());
        VPlexControllerUtils.refreshExportMask(_dbClient, storageView, exportMask, targetPortMap, _networkDeviceController);
        // get the context from the task completer, in case this is a rollback.
        if (rollbackContextKey != null) {
            ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(rollbackContextKey);
            if (context != null) {
                // a non-null context means this step is running as part of a rollback.
                List<URI> addedTargets = new ArrayList<>();
                if (context.getOperations() != null) {
                    _log.info("Handling storageViewRemoveStoragePorts as a result of rollback");
                    ListIterator<ExportOperationContextOperation> li = context.getOperations().listIterator(context.getOperations().size());
                    while (li.hasPrevious()) {
                        ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
                        if (operation != null && VplexExportOperationContext.OPERATION_ADD_TARGETS_TO_STORAGE_VIEW.equals(operation.getOperation())) {
                            addedTargets = (List<URI>) operation.getArgs().get(0);
                            _log.info(String.format("Removing target port(s) %s from storage view %s as part of rollback", Joiner.on(',').join(addedTargets), exportMask.getMaskName()));
                        }
                    }
                }
                if (addedTargets == null || addedTargets.isEmpty()) {
                    _log.info("There was no context found for add target. So there is nothing to rollback.");
                    completer.ready(_dbClient);
                    return;
                }
                // Change the list of targets to process to the list
                // that successfully were added during addStoragePorts.
                targetURIs.clear();
                targetURIs.addAll(addedTargets);
            }
        }
        // validate the remove storage port operation against the export mask volumes
        // this is conceptually the same as remove initiators, so will validate with volumes
        List<URI> volumeURIList = (exportMask.getUserAddedVolumes() != null) ? URIUtil.toURIList(exportMask.getUserAddedVolumes().values()) : new ArrayList<URI>();
        if (volumeURIList.isEmpty()) {
            _log.warn("volume URI list for validating remove initiators is empty...");
        }
        // removing all storage ports but leaving the existing initiators and volumes.
        if (!exportMask.hasAnyExistingInitiators() && !exportMask.hasAnyExistingVolumes()) {
            ExportMaskValidationContext ctx = new ExportMaskValidationContext();
            ctx.setStorage(vplex);
            ctx.setExportMask(exportMask);
            ctx.setBlockObjects(volumeURIList, _dbClient);
            ctx.setAllowExceptions(!WorkflowService.getInstance().isStepInRollbackState(stepId));
            validator.removeInitiators(ctx).validate();
            if (targetURIs != null && targetURIs.isEmpty() == false) {
                List<PortInfo> targetPortInfos = new ArrayList<PortInfo>();
                List<URI> targetsToRemoveFromStorageView = new ArrayList<URI>();
                for (URI target : targetURIs) {
                    // Do not try to remove a port twice.
                    if (!exportMask.getStoragePorts().contains(target.toString())) {
                        continue;
                    }
                    // Build the PortInfo structure for the port to be added
                    StoragePort port = getDataObject(StoragePort.class, target, _dbClient);
                    PortInfo pi = new PortInfo(port.getPortNetworkId().toUpperCase().replaceAll(":", ""), null, port.getPortName(), null);
                    targetPortInfos.add(pi);
                    targetsToRemoveFromStorageView.add(target);
                }
                if (!targetPortInfos.isEmpty()) {
                    // Remove the targets from the VPLEX
                    client.removeTargetsFromStorageView(exportMask.getMaskName(), targetPortInfos);
                    // Remove the targets to the database.
                    for (URI target : targetsToRemoveFromStorageView) {
                        exportMask.removeTarget(target);
                    }
                    _dbClient.updateObject(exportMask);
                }
            }
        }
        completer.ready(_dbClient);
    } catch (VPlexApiException vae) {
        _log.error("Exception removing storage ports from Storage View: " + vae.getMessage(), vae);
        failStep(completer, stepId, vae);
    } catch (Exception ex) {
        _log.error("Exception removing storage ports from Storage View: " + ex.getMessage(), ex);
        String opName = ResourceOperationTypeEnum.DELETE_STORAGE_VIEW_STORAGEPORTS.getName();
        ServiceError serviceError = VPlexApiException.errors.storageViewRemoveStoragePortFailed(opName, ex);
        failStep(completer, stepId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VPlexStorageViewInfo(com.emc.storageos.vplex.api.VPlexStorageViewInfo) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) ExportMaskRemoveInitiatorCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportMaskRemoveInitiatorCompleter) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) PortInfo(com.emc.storageos.vplex.api.clientdata.PortInfo) ExportMaskValidationContext(com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) ExportOperationContextOperation(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 39 with ExportOperationContext

use of com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext in project coprhd-controller by CoprHD.

the class MaskingWorkflowEntryPoints method rollbackExportGroupAddInitiators.

/**
 * Rollback entry point. This is a wrapper around the exportRemoveInitiators
 * operation, which requires that we create a specific completer using the token
 * that's passed in. This token is generated by the rollback processing.
 *
 * @param storageURI
 *            [in] - StorageSystem URI
 * @param exportGroupURI
 *            [in] - ExportGroup URI
 * @param exportMaskURI
 *            [in] - ExportMask URI
 * @param volumeURIs
 *            [in] - Impacted volume URIs
 * @param initiatorURIs
 *            [in] - List of Initiator URIs
 * @param contextKey
 *            [in] - context token
 * @param token
 *            [in] - String token generated by the rollback processing
 * @throws ControllerException
 */
public void rollbackExportGroupAddInitiators(URI storageURI, URI exportGroupURI, URI exportMaskURI, List<URI> volumeURIs, List<URI> initiatorURIs, String contextKey, String token) throws ControllerException {
    ExportTaskCompleter taskCompleter = new ExportMaskRemoveInitiatorCompleter(exportGroupURI, exportMaskURI, initiatorURIs, token);
    try {
        ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(contextKey);
        WorkflowService.getInstance().storeStepData(token, context);
    } catch (ClassCastException e) {
        _log.info("Step {} has stored step data other than ExportOperationContext. Exception: {}", token, e);
    }
    doExportGroupRemoveInitiators(storageURI, exportGroupURI, exportMaskURI, volumeURIs, initiatorURIs, true, taskCompleter, token);
}
Also used : ExportTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportTaskCompleter) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) ExportMaskRemoveInitiatorCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportMaskRemoveInitiatorCompleter)

Aggregations

ExportOperationContext (com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext)39 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)33 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)33 ExportMask (com.emc.storageos.db.client.model.ExportMask)29 ArrayList (java.util.ArrayList)28 URI (java.net.URI)24 Initiator (com.emc.storageos.db.client.model.Initiator)17 ExportOperationContextOperation (com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation)14 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)13 ExportMaskValidationContext (com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext)13 WBEMException (javax.wbem.WBEMException)13 HashSet (java.util.HashSet)12 ListIterator (java.util.ListIterator)10 BlockObject (com.emc.storageos.db.client.model.BlockObject)9 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)7 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)7 ControllerException (com.emc.storageos.volumecontroller.ControllerException)7 VPlexApiException (com.emc.storageos.vplex.api.VPlexApiException)7 WorkflowException (com.emc.storageos.workflow.WorkflowException)7