Search in sources :

Example 41 with VPlexApiException

use of com.emc.storageos.vplex.api.VPlexApiException in project coprhd-controller by CoprHD.

the class VPlexDeviceController method storageViewRemoveInitiators.

/**
 * Workflow step to remove an initiator from a single Storage View as given by the ExportMask URI.
 * Note there is a dependence on ExportMask name equaling the Storage View name.
 * Note that arguments must match storageViewRemoveInitiatorsMethod above (except stepId).
 *
 * @param vplexURI
 *            -- URI of Vplex Storage System.
 * @param exportGroupURI
 *            -- URI of Export Group.
 * @param exportMaskURI
 *            -- URI of one ExportMask. Call only processes indicaated mask.
 * @param initiatorURIs
 *            -- URIs of Initiators to be removed.
 * @param targetURIs
 *            -- optional targets to be removed from the Storage View.
 *            If non null, a list of URIs for VPlex front-end ports that will be removed from Storage View.
 * @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 storageViewRemoveInitiators(URI vplexURI, URI exportGroupURI, URI exportMaskURI, List<URI> initiatorURIs, List<URI> targetURIs, TaskCompleter taskCompleter, String rollbackContextKey, String stepId) throws WorkflowException {
    ExportMaskRemoveInitiatorCompleter completer = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        List<URI> initiatorIdsToProcess = new ArrayList<>(initiatorURIs);
        completer = new ExportMaskRemoveInitiatorCompleter(exportGroupURI, exportMaskURI, initiatorURIs, stepId);
        StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        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 (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> addedInitiators = new ArrayList<>();
                if (context.getOperations() != null) {
                    _log.info("Handling removeInitiators 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_INITIATORS_TO_STORAGE_VIEW.equals(operation.getOperation())) {
                            addedInitiators = (List<URI>) operation.getArgs().get(0);
                            _log.info("Removing initiators {} as part of rollback", Joiner.on(',').join(addedInitiators));
                        }
                    }
                }
                // Update the initiators in the task completer such that we update the export mask/group correctly
                for (URI initiator : initiatorIdsToProcess) {
                    if (addedInitiators == null || !addedInitiators.contains(initiator)) {
                        completer.removeInitiator(initiator);
                    }
                }
                if (addedInitiators == null || addedInitiators.isEmpty()) {
                    _log.info("There was no context found for add initiator. 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.
                initiatorIdsToProcess.clear();
                initiatorIdsToProcess.addAll(addedInitiators);
            }
        }
        // validate the remove initiator operation against the export mask 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...");
        }
        ExportMaskValidationContext ctx = new ExportMaskValidationContext();
        ctx.setStorage(vplex);
        ctx.setExportMask(exportMask);
        ctx.setBlockObjects(volumeURIList, _dbClient);
        ctx.setAllowExceptions(!WorkflowService.getInstance().isStepInRollbackState(stepId));
        validator.removeInitiators(ctx).validate();
        // Invoke artificial failure to simulate invalid storageview name on vplex
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_060);
        // removing all storage ports but leaving the existing initiators and volumes.
        if (!exportMask.hasAnyExistingInitiators() && !exportMask.hasAnyExistingVolumes()) {
            if (targetURIs != null && targetURIs.isEmpty() == false) {
                List<PortInfo> targetPortInfos = new ArrayList<PortInfo>();
                List<URI> targetsAddedToStorageView = 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);
                    targetsAddedToStorageView.add(target);
                }
                if (!targetPortInfos.isEmpty()) {
                    // Remove the targets from the VPLEX
                    client.removeTargetsFromStorageView(exportMask.getMaskName(), targetPortInfos);
                }
            }
        }
        // Update the initiators in the ExportMask.
        List<PortInfo> initiatorPortInfo = new ArrayList<PortInfo>();
        for (URI initiatorURI : initiatorIdsToProcess) {
            Initiator initiator = getDataObject(Initiator.class, initiatorURI, _dbClient);
            // We don't want to remove existing initiator, unless this is a rollback step
            if (exportMask.hasExistingInitiator(initiator) && !WorkflowService.getInstance().isStepInRollbackState(stepId)) {
                continue;
            }
            PortInfo portInfo = new PortInfo(initiator.getInitiatorPort().toUpperCase().replaceAll(":", ""), initiator.getInitiatorNode().toUpperCase().replaceAll(":", ""), initiator.getLabel(), getVPlexInitiatorType(initiator));
            initiatorPortInfo.add(portInfo);
        }
        // Remove the initiators if there aren't any existing volumes, unless this is a rollback step or validation is disabled.
        if (!initiatorPortInfo.isEmpty() && (!exportMask.hasAnyExistingVolumes() || !validatorConfig.isValidationEnabled() || WorkflowService.getInstance().isStepInRollbackState(stepId))) {
            String lockName = null;
            boolean lockAcquired = false;
            try {
                ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
                String clusterId = ConnectivityUtil.getVplexClusterForVarray(exportGroup.getVirtualArray(), vplexURI, _dbClient);
                lockName = _vplexApiLockManager.getLockName(vplexURI, clusterId);
                lockAcquired = _vplexApiLockManager.acquireLock(lockName, LockTimeoutValue.get(LockType.VPLEX_API_LIB));
                if (!lockAcquired) {
                    throw VPlexApiException.exceptions.couldNotObtainConcurrencyLock(vplex.getLabel());
                }
                // Remove the targets from the VPLEX
                // Test mechanism to invoke a failure. No-op on production systems.
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_016);
                client.removeInitiatorsFromStorageView(exportMask.getMaskName(), vplexClusterName, initiatorPortInfo);
            } finally {
                if (lockAcquired) {
                    _vplexApiLockManager.releaseLock(lockName);
                }
            }
        }
        completer.ready(_dbClient);
    } catch (VPlexApiException vae) {
        _log.error("Exception removing initiator from Storage View: " + vae.getMessage(), vae);
        failStep(completer, stepId, vae);
    } catch (Exception ex) {
        _log.error("Exception removing initiator from Storage View: " + ex.getMessage(), ex);
        String opName = ResourceOperationTypeEnum.DELETE_STORAGE_VIEW_INITIATOR.getName();
        ServiceError serviceError = VPlexApiException.errors.storageViewRemoveInitiatorFailed(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) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) 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 42 with VPlexApiException

use of com.emc.storageos.vplex.api.VPlexApiException in project coprhd-controller by CoprHD.

the class VPlexDeviceController method promoteMirror.

/**
 * This method creates the virtual volume from the detached mirror device.
 *
 * @param vplexURI
 *            The vplex storage system URI
 * @param vplexMirrorURI
 *            The URI of the vplex mirror that needs to be promoted to the virtual volume
 * @param promoteVolumeURI
 *            The URI of the volume will be used as a promoted vplex volume
 * @param stepId
 *            The worflow stepId
 *
 * @throws WorkflowException
 *             When an error occurs updating the workflow step
 *             state.
 */
public void promoteMirror(URI vplexURI, URI vplexMirrorURI, URI promoteVolumeURI, String stepId) throws WorkflowException {
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplexURI, _dbClient);
        VplexMirror vplexMirror = getDataObject(VplexMirror.class, vplexMirrorURI, _dbClient);
        Volume sourceVplexVolume = getDataObject(Volume.class, vplexMirror.getSource().getURI(), _dbClient);
        Volume promoteVolume = _dbClient.queryObject(Volume.class, promoteVolumeURI);
        // Find virtual volume that should have been created when we did detach mirror.
        // Virtual volume is created with the same name as the device name.
        VPlexVirtualVolumeInfo vvInfo = client.findVirtualVolume(vplexMirror.getDeviceLabel(), null);
        // Get the backend volume for this promoted VPLEX volume.
        StringSet assocVolumes = vplexMirror.getAssociatedVolumes();
        // Get the ViPR label for the promoted VPLEX volume.
        String promotedLabel = String.format("%s-%s", sourceVplexVolume.getLabel(), vplexMirror.getLabel());
        // Rename the vplex volume created using device detach mirror. If custom naming is enabled
        // generate the custom name, else the name follows the default naming convention and must
        // be renamed to append the "_vol" suffix.
        String newVolumeName = null;
        try {
            if (CustomVolumeNamingUtils.isCustomVolumeNamingEnabled(customConfigHandler, DiscoveredDataObject.Type.vplex.name())) {
                String customConfigName = CustomConfigConstants.CUSTOM_VOLUME_NAME;
                Project project = _dbClient.queryObject(Project.class, promoteVolume.getProject().getURI());
                TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, promoteVolume.getTenant().getURI());
                DataSource customNameDataSource = CustomVolumeNamingUtils.getCustomConfigDataSource(project, tenant, promotedLabel, vvInfo.getWwn(), null, dataSourceFactory, customConfigName, _dbClient);
                if (customNameDataSource != null) {
                    newVolumeName = CustomVolumeNamingUtils.getCustomName(customConfigHandler, customConfigName, customNameDataSource, DiscoveredDataObject.Type.vplex.name());
                }
                // Rename the vplex volume created using device detach mirror,
                vvInfo = CustomVolumeNamingUtils.renameVolumeOnVPlex(vvInfo, newVolumeName, client);
                promotedLabel = newVolumeName;
            } else {
                // Build the name for volume so as to rename the vplex volume that is created
                // with the same name as the device name to follow the name pattern _vol
                // as the suffix for the vplex volumes
                StringBuilder volumeNameBuilder = new StringBuilder();
                volumeNameBuilder.append(vplexMirror.getDeviceLabel());
                volumeNameBuilder.append(VPlexApiConstants.VIRTUAL_VOLUME_SUFFIX);
                newVolumeName = volumeNameBuilder.toString();
                // Rename the vplex volume created using device detach mirror,
                vvInfo = CustomVolumeNamingUtils.renameVolumeOnVPlex(vvInfo, newVolumeName, client);
            }
        } catch (Exception e) {
            _log.warn(String.format("Error renaming promoted VPLEX volume %s", promoteVolumeURI), e);
        }
        _log.info(String.format("Renamed promoted virtual volume: %s path: %s", vvInfo.getName(), vvInfo.getPath()));
        // Fill in the details for the promoted vplex volume
        promoteVolume.setLabel(promotedLabel);
        promoteVolume.setNativeId(vvInfo.getPath());
        promoteVolume.setNativeGuid(vvInfo.getPath());
        promoteVolume.setDeviceLabel(vvInfo.getName());
        promoteVolume.setThinlyProvisioned(vvInfo.isThinEnabled());
        promoteVolume.setWWN(vvInfo.getWwn());
        // For Vplex virtual volumes set allocated capacity to 0 (cop-18608)
        promoteVolume.setAllocatedCapacity(0L);
        promoteVolume.setCapacity(vplexMirror.getCapacity());
        promoteVolume.setProvisionedCapacity(vplexMirror.getProvisionedCapacity());
        promoteVolume.setVirtualPool(vplexMirror.getVirtualPool());
        promoteVolume.setVirtualArray(vplexMirror.getVirtualArray());
        promoteVolume.setStorageController(vplexMirror.getStorageController());
        promoteVolume.setSystemType(DiscoveredDataObject.Type.vplex.name());
        promoteVolume.setPool(NullColumnValueGetter.getNullURI());
        promoteVolume.setAssociatedVolumes(new StringSet(assocVolumes));
        promoteVolume.setThinlyProvisioned(vplexMirror.getThinlyProvisioned());
        promoteVolume.setThinVolumePreAllocationSize(vplexMirror.getThinPreAllocationSize());
        // VPLEX volumes created by VIPR have syncActive set to true hence setting same value for promoted vplex
        // volumes
        promoteVolume.setSyncActive(true);
        // Also, we update the name portion of the project and tenant URIs
        // to reflect the new name. This is necessary because the API
        // to search for volumes by project, extracts the name portion of the
        // project URI to get the volume name.
        NamedURI namedURI = promoteVolume.getProject();
        namedURI.setName(promotedLabel);
        promoteVolume.setProject(namedURI);
        namedURI = promoteVolume.getTenant();
        namedURI.setName(promotedLabel);
        promoteVolume.setTenant(namedURI);
        // Remove mirror from the source VPLEX volume
        sourceVplexVolume.getMirrors().remove(vplexMirror.getId().toString());
        _dbClient.updateObject(sourceVplexVolume);
        // Delete the mirror object
        _dbClient.removeObject(vplexMirror);
        // Persist changes for the newly promoted volume
        _dbClient.updateObject(promoteVolume);
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (VPlexApiException vae) {
        _log.error("Exception promoting mirror volume: " + vae.getMessage(), vae);
        WorkflowStepCompleter.stepFailed(stepId, vae);
    } catch (Exception ex) {
        _log.error("Exception promoting mirror volume: " + ex.getMessage(), ex);
        ServiceError serviceError = VPlexApiException.errors.promoteMirrorFailed(ex);
        WorkflowStepCompleter.stepFailed(stepId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) NamedURI(com.emc.storageos.db.client.model.NamedURI) VPlexVirtualVolumeInfo(com.emc.storageos.vplex.api.VPlexVirtualVolumeInfo) 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) DataSource(com.emc.storageos.customconfigcontroller.DataSource) Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) StringSet(com.emc.storageos.db.client.model.StringSet) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) VplexMirror(com.emc.storageos.db.client.model.VplexMirror)

Example 43 with VPlexApiException

use of com.emc.storageos.vplex.api.VPlexApiException in project coprhd-controller by CoprHD.

the class VPlexDeviceController method deleteMirrorDevice.

/**
 * Do the delete of a VPlex mirror device .
 * This is called as a Workflow Step.
 * NOTE: The parameters here must match deleteMirrorDeviceMethod above (except stepId).
 *
 * @param vplexURI
 *            URI of the VPlex StorageSystem
 * @param vplexMirrorURI
 *            URI of the mirror to be deleted
 * @param stepId
 *            The stepId used for completion.
 *
 * @throws WorkflowException
 *             When an error occurs updating the workflow step
 *             state.
 */
public void deleteMirrorDevice(URI vplexURI, URI vplexMirrorURI, String stepId) throws WorkflowException {
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplexURI, _dbClient);
        VplexMirror vplexMirror = getDataObject(VplexMirror.class, vplexMirrorURI, _dbClient);
        if (vplexMirror.getDeviceLabel() != null) {
            // Call to delete mirror device
            client.deleteLocalDevice(vplexMirror.getDeviceLabel());
            if (vplexMirror.getSource() != null && vplexMirror.getSource().getURI() != null) {
                Volume vplexVolume = getDataObject(Volume.class, vplexMirror.getSource().getURI(), _dbClient);
                StorageSystem vplexSystem = getDataObject(StorageSystem.class, vplexURI, _dbClient);
                updateThinProperty(client, vplexSystem, vplexVolume);
            }
            // Record VPLEX mirror delete event.
            recordBourneVplexMirrorEvent(vplexMirrorURI, OperationTypeEnum.DELETE_VOLUME_MIRROR.getEvType(true), Operation.Status.ready, OperationTypeEnum.DELETE_VOLUME_MIRROR.getDescription());
        } else {
            _log.info("It seems vplex mirror {} was never created, so just move to the next step.", vplexMirror.getLabel());
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (VPlexApiException vae) {
        _log.error("Exception deleting VPlex Virtual Volume: " + vae.getMessage(), vae);
        recordBourneVplexMirrorEvent(vplexMirrorURI, OperationTypeEnum.DELETE_VOLUME_MIRROR.getEvType(true), Operation.Status.error, OperationTypeEnum.DELETE_VOLUME_MIRROR.getDescription());
        WorkflowStepCompleter.stepFailed(stepId, vae);
    } catch (Exception ex) {
        _log.error("Exception deleting VPlex Virtual Volume: " + ex.getMessage(), ex);
        String opName = ResourceOperationTypeEnum.DELETE_VPLEX_LOCAL_MIRROR.getName();
        ServiceError serviceError = VPlexApiException.errors.deleteMirrorFailed(opName, ex);
        recordBourneVplexMirrorEvent(vplexMirrorURI, OperationTypeEnum.DELETE_VOLUME_MIRROR.getEvType(true), Operation.Status.error, OperationTypeEnum.DELETE_VOLUME_MIRROR.getDescription());
        WorkflowStepCompleter.stepFailed(stepId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 44 with VPlexApiException

use of com.emc.storageos.vplex.api.VPlexApiException in project coprhd-controller by CoprHD.

the class VPlexDeviceController method rollbackCreateVirtualVolumes.

/**
 * Rollback any virtual volumes previously created.
 *
 * @param vplexURI
 * @param vplexVolumeURIs
 * @param executeStepId
 *            - step Id of the execute step; used to retrieve rollback data.
 * @param stepId
 * @throws WorkflowException
 */
public void rollbackCreateVirtualVolumes(URI vplexURI, List<URI> vplexVolumeURIs, String executeStepId, String stepId) throws WorkflowException {
    try {
        List<List<VolumeInfo>> rollbackData = (List<List<VolumeInfo>>) _workflowService.loadStepData(executeStepId);
        if (rollbackData != null) {
            WorkflowStepCompleter.stepExecuting(stepId);
            // Get the API client.
            StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
            VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
            // For each virtual volume attempted, try and rollback.
            for (List<VolumeInfo> rollbackList : rollbackData) {
                client.deleteVirtualVolume(rollbackList);
            }
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (VPlexApiException vae) {
        _log.error("Exception rollback VPlex Virtual Volume create: " + vae.getLocalizedMessage(), vae);
        WorkflowStepCompleter.stepFailed(stepId, vae);
    } catch (Exception ex) {
        _log.error("Exception rollback VPlex Virtual Volume create: " + ex.getLocalizedMessage(), ex);
        ServiceError serviceError = VPlexApiException.errors.createVirtualVolumesRollbackFailed(stepId, ex);
        WorkflowStepCompleter.stepFailed(stepId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) VolumeInfo(com.emc.storageos.vplex.api.clientdata.VolumeInfo) VPlexVirtualVolumeInfo(com.emc.storageos.vplex.api.VPlexVirtualVolumeInfo) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 45 with VPlexApiException

use of com.emc.storageos.vplex.api.VPlexApiException in project coprhd-controller by CoprHD.

the class VPlexDeviceController method addStepsForDeleteVolumes.

/*
     * (non-Javadoc)
     *
     * @see com.emc.storageos.volumecontroller.impl.vplex.VplexController#deleteVolumes(java.net.URI, java.util.List,
     * java.lang.String)
     * <p>
     * NOTE: The VolumeDescriptor list will not include the underlying Volumes. These have to be
     * added to the VolumeDescriptor list before returning.
     */
@Override
public String addStepsForDeleteVolumes(Workflow workflow, String waitFor, List<VolumeDescriptor> volumes, String taskId) throws ControllerException {
    try {
        // Filter to get only the VPlex volumes.
        List<VolumeDescriptor> vplexVolumes = VolumeDescriptor.filterByType(volumes, new VolumeDescriptor.Type[] { VolumeDescriptor.Type.VPLEX_VIRT_VOLUME }, new VolumeDescriptor.Type[] {});
        // If there are no VPlex volumes, just return
        if (vplexVolumes.isEmpty()) {
            return waitFor;
        }
        // Check to see if there are any volumes flagged to not be fully deleted.
        // This will still remove the volume from its VPLEX CG and also clean up
        // any Mirrors but will leave the Virtual Volume intact on the VPLEX.
        List<VolumeDescriptor> doNotDeleteDescriptors = VolumeDescriptor.getDoNotDeleteDescriptors(vplexVolumes);
        List<URI> doNotFullyDeleteVolumeList = VolumeDescriptor.getVolumeURIs(doNotDeleteDescriptors);
        List<URI> allVplexVolumeURIs = VolumeDescriptor.getVolumeURIs(vplexVolumes);
        // Segregate by device.
        Map<URI, List<VolumeDescriptor>> vplexMap = VolumeDescriptor.getDeviceMap(vplexVolumes);
        // but subsequent steps will wait on all the delete virtual volumes operations to complete.
        for (URI vplexURI : vplexMap.keySet()) {
            String nextStepWaitFor = waitFor;
            StorageSystem vplexSystem = getDataObject(StorageSystem.class, vplexURI, _dbClient);
            // First validate that the backend volumes for these VPLEX volumes are
            // the actual volumes used by the VPLEX volume on the VPLEX system. We
            // add this verification in case changes were made outside ViPR, such
            // as a migration, that caused the backend volumes to change. We don't
            // want to delete a backend volume that may in fact be used some other
            // VPLEX volume.
            List<URI> vplexVolumeURIs = VolumeDescriptor.getVolumeURIs(vplexMap.get(vplexURI));
            for (URI vplexVolumeURI : vplexVolumeURIs) {
                Volume vplexVolume = _dbClient.queryObject(Volume.class, vplexVolumeURI);
                if (vplexVolume == null || vplexVolume.getInactive() == true) {
                    continue;
                }
                // Skip validation if the volume was never successfully created.
                if (vplexVolume.getDeviceLabel() == null) {
                    _log.info("Volume {} with Id {} was never created on the VPLEX as device label is null " + "hence skip validation on delete", vplexVolume.getLabel(), vplexVolume.getId());
                    continue;
                }
                // backend volume deletion failed.
                try {
                    VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplexSystem, _dbClient);
                    client.findVirtualVolume(vplexVolume.getDeviceLabel(), vplexVolume.getNativeId());
                } catch (VPlexApiException ex) {
                    if (ex.getServiceCode() == ServiceCode.VPLEX_CANT_FIND_REQUESTED_VOLUME) {
                        _log.info("VPlex virtual volume: " + vplexVolume.getNativeId() + " has already been deleted; will skip validation");
                        continue;
                    } else {
                        _log.error("Exception finding Virtual Volume", ex);
                        throw ex;
                    }
                }
                createWorkflowStepToValidateVPlexVolume(workflow, vplexSystem, vplexVolumeURI, waitFor);
                nextStepWaitFor = VALIDATE_VPLEX_VOLUME_STEP;
            }
            // If there are VPlex Volumes fronting SRDF targets, handle them.
            // They will need to be removed from the CG that represents the SRDF targets.
            List<URI> volsForTargetCG = VPlexSrdfUtil.returnVplexSrdfTargets(_dbClient, vplexVolumeURIs);
            if (!volsForTargetCG.isEmpty()) {
                URI volURI = volsForTargetCG.get(0);
                Volume vol = VPlexControllerUtils.getDataObject(Volume.class, volURI, _dbClient);
                ConsistencyGroupManager consistencyGroupManager = getConsistencyGroupManager(vol);
                nextStepWaitFor = consistencyGroupManager.addStepsForRemovingVolumesFromSRDFTargetCG(workflow, vplexSystem, volsForTargetCG, nextStepWaitFor);
            }
            workflow.createStep(VPLEX_STEP, String.format("Delete VPlex Virtual Volumes:%n%s", BlockDeviceController.getVolumesMsg(_dbClient, vplexVolumeURIs)), nextStepWaitFor, vplexURI, DiscoveredDataObject.Type.vplex.name(), this.getClass(), deleteVirtualVolumesMethod(vplexURI, vplexVolumeURIs, doNotFullyDeleteVolumeList), rollbackMethodNullMethod(), null);
        }
        // Make a Map of array URI to StorageSystem
        Map<URI, StorageSystem> arrayMap = new HashMap<URI, StorageSystem>();
        // Make a Map of StorageSystem to a list of Volume URIs to be deleted for the next Step.
        Map<URI, List<URI>> arrayVolumesMap = new HashMap<URI, List<URI>>();
        // Make a list of ExportGroups that is used.
        List<URI> exportGroupList = new ArrayList<URI>();
        // Create a series of steps to remove the volume from the Export Groups.
        // We leave the Export Groups, anticipating they will be used for other
        // volumes or used later.
        List<URI> backendVolURIs = new ArrayList<URI>();
        for (URI vplexVolumeURI : allVplexVolumeURIs) {
            Volume vplexVolume = _dbClient.queryObject(Volume.class, vplexVolumeURI);
            if ((vplexVolume == null) || (vplexVolume.getInactive()) || (vplexVolume.isIngestedVolumeWithoutBackend(_dbClient)) || doNotFullyDeleteVolumeList.contains(vplexVolumeURI)) {
                continue;
            }
            if (null == vplexVolume.getAssociatedVolumes()) {
                _log.warn("VPLEX volume {} has no backend volumes. It was possibly ingested 'Virtual Volume Only'.", vplexVolume.forDisplay());
            } else {
                for (String assocVolumeId : vplexVolume.getAssociatedVolumes()) {
                    URI assocVolumeURI = new URI(assocVolumeId);
                    Volume volume = _dbClient.queryObject(Volume.class, assocVolumeURI);
                    if (volume == null || volume.getInactive() == true) {
                        continue;
                    }
                    StorageSystem array = arrayMap.get(volume.getStorageController());
                    if (array == null) {
                        array = _dbClient.queryObject(StorageSystem.class, volume.getStorageController());
                        arrayMap.put(array.getId(), array);
                    }
                    if (arrayVolumesMap.get(array.getId()) == null) {
                        arrayVolumesMap.put(array.getId(), new ArrayList<URI>());
                    }
                    arrayVolumesMap.get(array.getId()).add(volume.getId());
                    backendVolURIs.add(volume.getId());
                }
            }
            // hence the backend volume for that mirror needs to be deleted as well.
            if (vplexVolume.getMirrors() != null && !(vplexVolume.getMirrors().isEmpty())) {
                for (String mirrorId : vplexVolume.getMirrors()) {
                    VplexMirror vplexMirror = _dbClient.queryObject(VplexMirror.class, URI.create(mirrorId));
                    if (vplexMirror == null || vplexMirror.getInactive() == true || vplexMirror.getAssociatedVolumes() == null) {
                        continue;
                    }
                    for (String assocVolumeId : vplexMirror.getAssociatedVolumes()) {
                        URI assocVolumeURI = new URI(assocVolumeId);
                        Volume volume = _dbClient.queryObject(Volume.class, assocVolumeURI);
                        if (volume == null || volume.getInactive() == true) {
                            continue;
                        }
                        StorageSystem array = arrayMap.get(volume.getStorageController());
                        if (array == null) {
                            array = _dbClient.queryObject(StorageSystem.class, volume.getStorageController());
                            arrayMap.put(array.getId(), array);
                        }
                        if (arrayVolumesMap.get(array.getId()) == null) {
                            arrayVolumesMap.put(array.getId(), new ArrayList<URI>());
                        }
                        arrayVolumesMap.get(array.getId()).add(volume.getId());
                        backendVolURIs.add(volume.getId());
                    }
                }
            }
        }
        waitFor = VPLEX_STEP;
        if (vplexAddUnexportVolumeWfSteps(workflow, VPLEX_STEP, backendVolURIs, exportGroupList)) {
            waitFor = UNEXPORT_STEP;
        }
        return waitFor;
    } catch (Exception ex) {
        throw VPlexApiException.exceptions.addStepsForDeleteVolumesFailed(ex);
    }
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) HashMap(java.util.HashMap) 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) Volume(com.emc.storageos.db.client.model.Volume) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

VPlexApiException (com.emc.storageos.vplex.api.VPlexApiException)59 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)53 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)43 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)43 ControllerException (com.emc.storageos.volumecontroller.ControllerException)43 WorkflowException (com.emc.storageos.workflow.WorkflowException)43 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)41 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)41 VPlexApiClient (com.emc.storageos.vplex.api.VPlexApiClient)40 URI (java.net.URI)39 ArrayList (java.util.ArrayList)39 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)34 IOException (java.io.IOException)34 URISyntaxException (java.net.URISyntaxException)34 ExportMask (com.emc.storageos.db.client.model.ExportMask)26 Volume (com.emc.storageos.db.client.model.Volume)25 NamedURI (com.emc.storageos.db.client.model.NamedURI)21 Initiator (com.emc.storageos.db.client.model.Initiator)20 BlockStorageDevice (com.emc.storageos.volumecontroller.BlockStorageDevice)14 VPlexVirtualVolumeInfo (com.emc.storageos.vplex.api.VPlexVirtualVolumeInfo)12