Search in sources :

Example 11 with ExportOperationContext

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

the class VPlexDeviceController method storageViewAddVolumes.

/**
 * Method for adding volumes to a single ExportMask.
 *
 * @param vplexURI
 * @param exportGroupURI
 * @param exportMaskURI
 * @param volumeMap
 * @param opId
 * @throws ControllerException
 */
public void storageViewAddVolumes(URI vplexURI, URI exportGroupURI, URI exportMaskURI, Map<URI, Integer> volumeMap, String opId) throws ControllerException {
    String volListStr = "";
    ExportMaskAddVolumeCompleter completer = null;
    try {
        WorkflowStepCompleter.stepExecuting(opId);
        completer = new ExportMaskAddVolumeCompleter(exportGroupURI, exportMaskURI, volumeMap, opId);
        ExportOperationContext context = new VplexExportOperationContext();
        // Prime the context object
        completer.updateWorkflowStepContext(context);
        volListStr = Joiner.on(',').join(volumeMap.keySet());
        StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
        ExportMask exportMask = getDataObject(ExportMask.class, exportMaskURI, _dbClient);
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_001);
        VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
        // Need to massage the map to fit the API
        List<BlockObject> volumes = new ArrayList<BlockObject>();
        Map<String, Integer> deviceLabelToHLU = new HashMap<String, Integer>();
        boolean duplicateHLU = false;
        List<URI> volumesToAdd = new ArrayList<URI>();
        String vplexClusterName = VPlexUtil.getVplexClusterName(exportMask, vplexURI, client, _dbClient);
        VPlexStorageViewInfo storageView = client.getStorageView(vplexClusterName, exportMask.getMaskName());
        VPlexControllerUtils.refreshExportMask(_dbClient, storageView, exportMask, VPlexControllerUtils.getTargetPortToPwwnMap(client, vplexClusterName), _networkDeviceController);
        exportMask = getDataObject(ExportMask.class, exportMaskURI, _dbClient);
        for (Map.Entry<URI, Integer> entry : volumeMap.entrySet()) {
            if (exportMask.hasVolume(entry.getKey())) {
                _log.info(String.format("Volume %s is already in Exportmask %s %s hence skipping adding volume again. This must be shared exportmask. ", entry.getKey(), exportMask.getMaskName(), exportMask.getId()));
                continue;
            }
            Integer requestedHLU = entry.getValue();
            // If user have provided specific HLU for volume, then check if its already in use
            if (requestedHLU.intValue() != VPlexApiConstants.LUN_UNASSIGNED && exportMask.anyVolumeHasHLU(requestedHLU.toString())) {
                String message = String.format("Failed to add Volumes %s to ExportMask %s", volListStr, exportMaskURI);
                _log.error(message);
                String opName = ResourceOperationTypeEnum.ADD_EXPORT_VOLUME.getName();
                ServiceError serviceError = VPlexApiException.errors.exportHasExistingVolumeWithRequestedHLU(entry.getKey().toString(), requestedHLU.toString(), opName);
                failStep(completer, opId, serviceError);
                duplicateHLU = true;
                break;
            }
            BlockObject vol = Volume.fetchExportMaskBlockObject(_dbClient, entry.getKey());
            volumes.add(vol);
            deviceLabelToHLU.put(vol.getDeviceLabel(), requestedHLU);
            volumesToAdd.add(entry.getKey());
        }
        // If duplicate HLU are found then return, completer is set to error above
        if (duplicateHLU) {
            return;
        }
        // If deviceLabelToHLU map is empty then volumes already exists in the storage view hence return.
        if (deviceLabelToHLU.isEmpty()) {
            completer.ready(_dbClient);
            return;
        }
        VPlexStorageViewInfo svInfo = client.addVirtualVolumesToStorageView(exportMask.getMaskName(), vplexClusterName, deviceLabelToHLU);
        ExportOperationContext.insertContextOperation(completer, VplexExportOperationContext.OPERATION_ADD_VOLUMES_TO_STORAGE_VIEW, volumesToAdd);
        // When VPLEX volumes are exported to a storage view, they get a WWN,
        // so set the WWN from the returned storage view information.
        Map<URI, Integer> updatedVolumeMap = new HashMap<URI, Integer>();
        for (BlockObject volume : volumes) {
            String deviceLabel = volume.getDeviceLabel();
            String wwn = svInfo.getWWNForStorageViewVolume(volume.getDeviceLabel());
            volume.setWWN(wwn);
            _dbClient.updateObject(volume);
            updatedVolumeMap.put(volume.getId(), svInfo.getHLUForStorageViewVolume(deviceLabel));
            // user.
            if (exportMask.hasExistingVolume(wwn)) {
                _log.info("wwn {} has been added to the storage view {} by the user, but it " + "was already in existing volumes, removing from existing volumes.", wwn, exportMask.forDisplay());
                exportMask.removeFromExistingVolumes(wwn);
            }
            exportMask.addToUserCreatedVolumes(volume);
        }
        // We also need to update the volume/lun id map in the export mask
        // to those assigned by the VPLEX.
        _log.info("Updating volume/lun map in export mask {}", exportMask.getId());
        exportMask.addVolumes(updatedVolumeMap);
        _dbClient.updateObject(exportMask);
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_002);
        completer.ready(_dbClient);
    } catch (VPlexApiException vae) {
        String message = String.format("Failed to add Volumes %s to ExportMask %s", volListStr, exportMaskURI);
        _log.error(message, vae);
        failStep(completer, opId, vae);
    } catch (Exception ex) {
        String message = String.format("Failed to add Volumes %s to ExportMask %s", volListStr, exportMaskURI);
        _log.error(message, ex);
        String opName = ResourceOperationTypeEnum.ADD_EXPORT_VOLUME.getName();
        ServiceError serviceError = VPlexApiException.errors.exportGroupAddVolumesFailed(volListStr, exportGroupURI.toString(), opName, ex);
        failStep(completer, opId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VPlexStorageViewInfo(com.emc.storageos.vplex.api.VPlexStorageViewInfo) HashMap(java.util.HashMap) 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) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) ExportMaskAddVolumeCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportMaskAddVolumeCompleter) Map(java.util.Map) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 12 with ExportOperationContext

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

the class VPlexDeviceController method storageViewAddVolumesRollback.

/**
 * Rollback entry point. This is a wrapper around the exportRemoveVolumes
 * 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 vplexURI
 *            [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 rollbackContextKey
 *            [in] - context token
 * @param token
 *            [in] - String token generated by the rollback processing
 * @throws ControllerException
 */
public void storageViewAddVolumesRollback(URI vplexURI, URI exportGroupURI, URI exportMaskURI, List<URI> volumeURIs, String rollbackContextKey, String token) throws ControllerException {
    TaskCompleter taskCompleter = new ExportMaskRemoveVolumeCompleter(exportGroupURI, exportMaskURI, volumeURIs, token);
    // in order to only perform rollback of operations we successfully performed.
    try {
        ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(rollbackContextKey);
        WorkflowService.getInstance().storeStepData(token, context);
        storageViewRemoveVolumes(vplexURI, exportGroupURI, exportMaskURI, volumeURIs, rollbackContextKey, taskCompleter, rollbackContextKey, token);
    } catch (Exception e) {
        String message = String.format("Failed to remove Volume(s) %s on rollback from ExportGroup %s", Joiner.on(",").join(volumeURIs), exportGroupURI);
        _log.error(message, e);
        String opName = ResourceOperationTypeEnum.DELETE_EXPORT_VOLUME.getName();
        ServiceError serviceError = VPlexApiException.errors.exportGroupRemoveVolumesFailed(Joiner.on(",").join(volumeURIs), exportGroupURI.toString(), opName, e);
        taskCompleter.error(_dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) ExportTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportTaskCompleter) MigrationTaskCompleter(com.emc.storageos.vplexcontroller.completers.MigrationTaskCompleter) CloneTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.CloneTaskCompleter) MigrationOperationTaskCompleter(com.emc.storageos.vplexcontroller.completers.MigrationOperationTaskCompleter) CacheStatusTaskCompleter(com.emc.storageos.vplexcontroller.completers.CacheStatusTaskCompleter) VplexMirrorTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VplexMirrorTaskCompleter) VolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter) VolumeGroupUpdateTaskCompleter(com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) WorkflowTaskCompleter(com.emc.storageos.workflow.WorkflowTaskCompleter) 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) ExportMaskRemoveVolumeCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportMaskRemoveVolumeCompleter)

Example 13 with ExportOperationContext

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

the class VPlexDeviceController method storageViewAddInitiatorsRollback.

/**
 * 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 vplexURI
 *            [in] - StorageSystem URI
 * @param exportGroupURI
 *            [in] - ExportGroup URI
 * @param exportMaskURI
 *            [in] - ExportMask URI
 * @param initiatorURIs
 *            [in] - List of Initiator URIs
 * @param targetURIs
 *            [in] - List of storage port URIs
 * @param rollbackContextKey
 *            [in] - context token
 * @param token
 *            [in] - String token generated by the rollback processing
 * @throws ControllerException
 */
public void storageViewAddInitiatorsRollback(URI vplexURI, URI exportGroupURI, URI exportMaskURI, List<URI> initiatorURIs, List<URI> targetURIs, String rollbackContextKey, String token) throws ControllerException {
    ExportTaskCompleter taskCompleter = new ExportMaskRemoveInitiatorCompleter(exportGroupURI, exportMaskURI, initiatorURIs, token);
    // in order to only perform rollback of operations we successfully performed.
    try {
        ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(rollbackContextKey);
        WorkflowService.getInstance().storeStepData(token, context);
    } catch (ClassCastException e) {
        _log.info("Step {} has stored step data other than ExportOperationContext. Exception: {}", token, e);
    }
    storageViewRemoveInitiators(vplexURI, exportGroupURI, exportMaskURI, initiatorURIs, targetURIs, taskCompleter, rollbackContextKey, 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)

Example 14 with ExportOperationContext

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

the class VPlexDeviceController method storageViewAddStoragePorts.

/**
 * Workflow Step to add storage port(s) to Storage View.
 * Note arguments (except stepId) must match storageViewAddStoragePortsMethod 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 added.
 *            If not null, the targets (VPlex front end ports) indicated by the targetURIs will be added
 *            to the Storage View making sure they do belong to zoningMap storagePorts.
 *            If null, then ports are calculated from the zoningMap.
 * @param completer the ExportMaskAddInitiatorCompleter
 * @param stepId
 *            -- Workflow step id.
 * @throws WorkflowException
 */
public void storageViewAddStoragePorts(URI vplexURI, URI exportURI, URI maskURI, List<URI> targetURIs, ExportMaskAddInitiatorCompleter completer, String stepId) throws DeviceControllerException {
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        ExportOperationContext context = new VplexExportOperationContext();
        // Prime the context object
        completer.updateWorkflowStepContext(context);
        StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
        ExportGroup exportGroup = getDataObject(ExportGroup.class, exportURI, _dbClient);
        VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
        List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(_dbClient, exportGroup, vplexURI);
        for (ExportMask exportMask : exportMasks) {
            // If a specific ExportMask is to be processed, ignore any others.
            if (maskURI != null && !exportMask.getId().equals(maskURI)) {
                continue;
            }
            ArrayList<URI> filteredTargetURIs = new ArrayList<URI>();
            // Filter or get targets from the zoning map
            if (exportMask.getZoningMap() != null) {
                Set<String> zoningMapTargets = BlockStorageScheduler.getTargetIdsFromAssignments(exportMask.getZoningMap());
                List<URI> zoningMapTargetURIs = StringSetUtil.stringSetToUriList(zoningMapTargets);
                if (targetURIs == null || targetURIs.isEmpty()) {
                    // Add all storage ports from the zoning map
                    if (zoningMapTargetURIs != null && !zoningMapTargetURIs.isEmpty()) {
                        filteredTargetURIs.addAll(zoningMapTargetURIs);
                    }
                } else {
                    // Log any ports not in the zoning map.
                    for (URI targetURI : targetURIs) {
                        filteredTargetURIs.add(targetURI);
                        if (zoningMapTargetURIs.contains(targetURI)) {
                            _log.info(String.format("Target %s not in zoning map", targetURI));
                        }
                    }
                }
            }
            // Add new targets if specified
            if (filteredTargetURIs != null && filteredTargetURIs.isEmpty() == false) {
                List<PortInfo> targetPortInfos = new ArrayList<PortInfo>();
                List<URI> targetsAddedToStorageView = new ArrayList<URI>();
                for (URI target : filteredTargetURIs) {
                    // Do not try to add 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()) {
                    // Add the targets on the VPLEX
                    client.addTargetsToStorageView(exportMask.getMaskName(), targetPortInfos);
                    ExportOperationContext.insertContextOperation(completer, VplexExportOperationContext.OPERATION_ADD_TARGETS_TO_STORAGE_VIEW, targetsAddedToStorageView);
                    // Add the targets to the database.
                    for (URI target : targetsAddedToStorageView) {
                        exportMask.addTarget(target);
                    }
                    _dbClient.updateObject(exportMask);
                }
            }
        }
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_083);
        completer.ready(_dbClient);
    } catch (VPlexApiException vae) {
        _log.error("VPlexApiException adding storagePorts to Storage View: " + vae.getMessage(), vae);
        failStep(completer, stepId, vae);
    } catch (Exception ex) {
        _log.error("Exception adding storagePorts to Storage View: " + ex.getMessage(), ex);
        String opName = ResourceOperationTypeEnum.ADD_STORAGE_VIEW_STORAGEPORTS.getName();
        ServiceError serviceError = VPlexApiException.errors.storageViewAddStoragePortFailed(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) StoragePort(com.emc.storageos.db.client.model.StoragePort) 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) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 15 with ExportOperationContext

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

the class XtremIOExportOperations method removeInitiators.

@Override
public void removeInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<Initiator> initiators, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("{} removeInitiators START...", storage.getSerialNumber());
    boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
    if (isRollback) {
        _log.info("Handling removeInitiators as a result of rollback");
        List<Initiator> addedInitiators = new ArrayList<Initiator>();
        // Get the context from the task completer.
        ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(taskCompleter.getOpId());
        if (context != null && context.getOperations() != null) {
            ListIterator li = context.getOperations().listIterator(context.getOperations().size());
            while (li.hasPrevious()) {
                ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
                if (operation != null && XtremIOExportOperationContext.OPERATION_ADD_INITIATORS_TO_INITIATOR_GROUP.equals(operation.getOperation())) {
                    addedInitiators = (List<Initiator>) 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 (Initiator initiator : initiators) {
            if (addedInitiators == null || !addedInitiators.contains(initiator)) {
                ((ExportMaskRemoveInitiatorCompleter) taskCompleter).removeInitiator(initiator.getId());
            }
        }
        initiators = addedInitiators;
        if (initiators == null || initiators.isEmpty()) {
            _log.info("There was no context found for add initiator. So there is nothing to rollback.");
            taskCompleter.ready(dbClient);
            return;
        }
    }
    ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
    if (exportMask == null || exportMask.getInactive()) {
        throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskURI);
    }
    XtremIOClient client = null;
    // if host Name is not available in at least one of the initiator, then set it to
    // Default_IG;
    List<String> failedIGs = new ArrayList<String>();
    ArrayListMultimap<String, Initiator> groupInitiatorsByIG = ArrayListMultimap.create();
    try {
        String hostName = null;
        String clusterName = null;
        client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        String xioClusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        Iterator<Initiator> iniItr = initiators.iterator();
        while (iniItr.hasNext()) {
            Initiator initiator = iniItr.next();
            String igName = null;
            if (null != initiator.getHostName()) {
                // initiators already grouped by Host
                hostName = initiator.getHostName();
                clusterName = initiator.getClusterName();
            }
            igName = XtremIOProvUtils.getIGNameForInitiator(initiator, storage.getSerialNumber(), client, xioClusterName);
            if (igName != null && !igName.isEmpty()) {
                groupInitiatorsByIG.put(igName, initiator);
            } else {
                // initiator not found in Array, remove from DB
                exportMask.removeFromExistingInitiators(initiator);
                exportMask.removeFromUserCreatedInitiators(initiator);
                iniItr.remove();
            }
        }
        // We need to look at all related initiators from the affected EM. We can use this list
        // to then find all related volumes across all EMs. This will allow us to properly
        // perform our validations.
        List<Initiator> relatedInitiators = new ArrayList<Initiator>();
        if (exportMask.getInitiators() != null && !exportMask.getInitiators().isEmpty()) {
            Collection<URI> relatedInitiatorURIs = Collections2.transform(exportMask.getInitiators(), CommonTransformerFunctions.FCTN_STRING_TO_URI);
            relatedInitiators.addAll(dbClient.queryObject(Initiator.class, relatedInitiatorURIs));
        } else {
            relatedInitiators.addAll(initiators);
        }
        Set<URI> allRelatedVolumes = new HashSet<URI>();
        allRelatedVolumes.addAll(findAllRelatedExportMaskVolumesForInitiator(relatedInitiators, exportMask.getStorageDevice()));
        _log.info("removeInitiators: Export mask id: {}", exportMaskURI);
        if (!CollectionUtils.isEmpty(allRelatedVolumes)) {
            _log.info("removeInitiators: volumes : {}", Joiner.on(',').join(allRelatedVolumes));
        }
        _log.info("removeInitiators: initiators : {}", Joiner.on(',').join(initiators));
        _log.info("removeInitiators: targets : {}", Joiner.on(',').join(targets));
        _log.info("List of  IGs found {} with size : {}", Joiner.on(",").join(groupInitiatorsByIG.asMap().entrySet()), groupInitiatorsByIG.size());
        ExportMaskValidationContext ctx = new ExportMaskValidationContext();
        ctx.setStorage(storage);
        ctx.setExportMask(exportMask);
        ctx.setBlockObjects(allRelatedVolumes, dbClient);
        ctx.setAllowExceptions(!isRollback);
        XtremIOExportMaskVolumesValidator volumeValidator = (XtremIOExportMaskVolumesValidator) validator.removeInitiators(ctx);
        volumeValidator.setIgNames(groupInitiatorsByIG.keySet());
        volumeValidator.validate();
        // lun map
        for (Initiator initiator : initiators) {
            try {
                client.deleteInitiator(initiator.getMappedInitiatorName(storage.getSerialNumber()), xioClusterName);
                exportMask.removeFromExistingInitiators(initiator);
                exportMask.removeFromUserCreatedInitiators(initiator);
            } catch (Exception e) {
                failedIGs.add(initiator.getLabel().concat(XtremIOConstants.DASH).concat(e.getMessage()));
                _log.warn("Removal of Initiator {} failed", initiator.getLabel(), e);
            }
        }
        dbClient.updateObject(exportMask);
        if (!failedIGs.isEmpty()) {
            String errMsg = "Export Operations failed deleting these initiators: ".concat(Joiner.on(", ").join(failedIGs));
            ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(errMsg, null);
            taskCompleter.error(dbClient, serviceError);
            return;
        }
        // Clean IGs if empty
        deleteInitiatorGroup(groupInitiatorsByIG, client, xioClusterName);
        // delete IG Folder as well if IGs are empty
        deleteInitiatorGroupFolder(client, xioClusterName, clusterName, hostName, storage);
        taskCompleter.ready(dbClient);
    } catch (Exception ex) {
        _log.error("Problem in removeInitiators: ", ex);
        ServiceError serviceError = DeviceControllerErrors.xtremio.operationFailed("removeInitiators", ex.getMessage());
        taskCompleter.error(dbClient, serviceError);
        return;
    }
    _log.info("{} removeInitiators END...", storage.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) XtremIOExportMaskVolumesValidator(com.emc.storageos.volumecontroller.impl.validators.xtremio.XtremIOExportMaskVolumesValidator) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) ExportMaskRemoveInitiatorCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportMaskRemoveInitiatorCompleter) URI(java.net.URI) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportMaskValidationContext(com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext) XtremIOInitiator(com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) ExportOperationContextOperation(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HashSet(java.util.HashSet)

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