Search in sources :

Example 1 with ExportRemoveInitiatorCompleter

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportRemoveInitiatorCompleter in project coprhd-controller by CoprHD.

the class BlockStorageDeviceTest method testExportRemoveInitiators.

@Test
public void testExportRemoveInitiators() {
    ExportGroup exportGroup = getExportGroup();
    ExportMask exportMask = getExportMask();
    List<Initiator> initiators = getInitiators();
    List<URI> initiatorURIs = new ArrayList<URI>();
    List<Initiator> initiatorArgs = new ArrayList<Initiator>();
    for (Initiator initiator : initiators) {
        if (initiator.getInitiatorPort().endsWith("1")) {
            initiatorURIs.add(initiator.getId());
            initiatorArgs.add(initiator);
        }
    }
    String token = UUID.randomUUID().toString() + UUID.randomUUID().toString();
    ExportTaskCompleter taskCompleter = new ExportRemoveInitiatorCompleter(exportGroup.getId(), initiatorURIs, token);
    _deviceController.doExportRemoveInitiators(_storageSystem, exportMask, null, initiators, null, taskCompleter);
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ExportTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportTaskCompleter) Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) ExportRemoveInitiatorCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportRemoveInitiatorCompleter) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Test(org.junit.Test)

Example 2 with ExportRemoveInitiatorCompleter

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportRemoveInitiatorCompleter in project coprhd-controller by CoprHD.

the class VPlexDeviceController method exportGroupRemoveInitiators.

/*
     * (non-Javadoc)
     *
     * @see com.emc.storageos.volumecontroller.impl.vplex.VplexController#exportRemoveInitiator(java.net.URI,
     * java.net.URI, java.net.URI,
     * java.lang.String)
     */
@Override
public void exportGroupRemoveInitiators(URI vplexURI, URI exportURI, List<URI> initiatorURIs, String opId) throws ControllerException {
    try {
        StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
        ExportGroup exportGroup = getDataObject(ExportGroup.class, exportURI, _dbClient);
        ExportRemoveInitiatorCompleter completer = new ExportRemoveInitiatorCompleter(exportURI, initiatorURIs, opId);
        Workflow workflow = _workflowService.getNewWorkflow(this, "exportRemoveInitiator", true, opId);
        // true if Workflow has a Step
        boolean hasStep = false;
        Initiator firstInitiator = _dbClient.queryObject(Initiator.class, initiatorURIs.get(0));
        StringBuffer errorMessages = new StringBuffer();
        boolean isValidationNeeded = validatorConfig.isValidationEnabled() && !ExportUtils.checkIfInitiatorsForRP(Arrays.asList(firstInitiator));
        _log.info("Orchestration level validation needed : {}", isValidationNeeded);
        _log.info("starting remove initiators for export group: " + exportGroup.toString());
        _log.info("request is to remove these initiators: " + initiatorURIs);
        initiatorURIs = VPlexUtil.filterInitiatorsForVplex(_dbClient, initiatorURIs);
        // get a map of host URI to a list of Initiators in that Host
        Map<URI, List<Initiator>> hostInitiatorsMap = VPlexUtil.makeHostInitiatorsMap(initiatorURIs, _dbClient);
        VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
        // Loop, processing each host separately.
        for (URI hostURI : hostInitiatorsMap.keySet()) {
            _log.info("setting up initiator removal for host " + hostURI);
            // Get the initiators (and initiator URIs) for this host
            List<Initiator> initiators = hostInitiatorsMap.get(hostURI);
            // Find the ExportMask for my host.
            List<ExportMask> exportMasks = getExportMaskForHost(exportGroup, hostURI, vplexURI);
            if (exportMasks == null || exportMasks.isEmpty()) {
                // If there is no ExportMask for this host, there is nothing to do.
                _log.info("No export mask found for hostURI: " + hostURI);
                continue;
            }
            String lastStep = null;
            List<URI> initiatorsAlreadyRemovedFromExportGroup = new ArrayList<URI>();
            for (ExportMask exportMask : exportMasks) {
                _log.info("adding remove initiators steps for " + "export mask / storage view: " + exportMask.getMaskName());
                String vplexClusterName = VPlexUtil.getVplexClusterName(exportMask, vplexURI, client, _dbClient);
                Map<String, String> targetPortToPwwnMap = VPlexControllerUtils.getTargetPortToPwwnMap(client, vplexClusterName);
                VPlexStorageViewInfo storageView = client.getStorageView(vplexClusterName, exportMask.getMaskName());
                _log.info("Refreshing ExportMask {}", exportMask.getMaskName());
                VPlexControllerUtils.refreshExportMask(_dbClient, storageView, exportMask, targetPortToPwwnMap, _networkDeviceController);
                // initiator filter logic is move inside addStepsForRemoveInitiators and addStepsForInitiatorRemoval as
                // it is not required for zone related operation.
                // 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(opId));
                validator.removeInitiators(ctx).validate();
                lastStep = addStepsForRemoveInitiators(vplex, workflow, completer, exportGroup, exportMask, initiators, hostURI, initiatorsAlreadyRemovedFromExportGroup, errorMessages, lastStep);
                if (lastStep != null) {
                    hasStep = true;
                }
            }
        }
        String message = errorMessages.toString();
        if (isValidationNeeded && !message.isEmpty()) {
            _log.error("Error Message {}", errorMessages);
            List<String> initiatorNames = new ArrayList<String>();
            for (URI initiatorURI : initiatorURIs) {
                Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorURI);
                if (initiator != null) {
                    String normalizedName = Initiator.normalizePort(initiator.getInitiatorPort());
                    initiatorNames.add(normalizedName);
                } else {
                    _log.warn("no initiator found for URI {}", initiatorURI);
                }
            }
            throw DeviceControllerException.exceptions.removeInitiatorValidationError(Joiner.on(", ").join(initiatorNames), vplex.getLabel(), message);
        }
        // Fire off the workflow if there were initiators to delete. Otherwise just fire completer.
        if (hasStep) {
            workflow.executePlan(completer, "Successfully removed initiators: " + initiatorURIs.toString());
        } else {
            _log.info(String.format("No updates to ExportMasks needed... complete"));
            completer.ready(_dbClient);
        }
    } catch (VPlexApiException vae) {
        _log.error("Exception in exportRemoveInitiators: " + initiatorURIs.toString(), vae);
        WorkflowStepCompleter.stepFailed(opId, vae);
    } catch (Exception ex) {
        _log.error("Exception in exportRemoveInitiators: " + initiatorURIs.toString(), ex);
        String opName = ResourceOperationTypeEnum.DELETE_EXPORT_INITIATOR.getName();
        ServiceError serviceError = VPlexApiException.errors.exportGroupRemoveInitiatorsFailed(opName, ex);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
    }
}
Also used : VPlexStorageViewInfo(com.emc.storageos.vplex.api.VPlexStorageViewInfo) ExportRemoveInitiatorCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportRemoveInitiatorCompleter) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) 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) ExportMask(com.emc.storageos.db.client.model.ExportMask) Workflow(com.emc.storageos.workflow.Workflow) 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) ExportMaskValidationContext(com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient)

Example 3 with ExportRemoveInitiatorCompleter

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportRemoveInitiatorCompleter in project coprhd-controller by CoprHD.

the class BlockStorageDeviceTest method testExportRemoveInitiator.

@Test
public void testExportRemoveInitiator() {
    ExportGroup exportGroup = getExportGroup();
    ExportMask exportMask = getExportMask();
    Initiator initiator = getInitiators().get(0);
    ;
    List<URI> initiatorURIs = new ArrayList<URI>(1);
    initiatorURIs.add(initiator.getId());
    String token = UUID.randomUUID().toString() + UUID.randomUUID().toString();
    ExportTaskCompleter taskCompleter = new ExportRemoveInitiatorCompleter(exportGroup.getId(), initiatorURIs, token);
    _deviceController.doExportRemoveInitiator(_storageSystem, exportMask, null, initiator, null, taskCompleter);
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ExportTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportTaskCompleter) Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) ExportRemoveInitiatorCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportRemoveInitiatorCompleter) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Test(org.junit.Test)

Aggregations

ExportGroup (com.emc.storageos.db.client.model.ExportGroup)3 ExportMask (com.emc.storageos.db.client.model.ExportMask)3 Initiator (com.emc.storageos.db.client.model.Initiator)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)3 ExportRemoveInitiatorCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportRemoveInitiatorCompleter)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 ExportTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportTaskCompleter)2 Test (org.junit.Test)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 ApplicationAddVolumeList (com.emc.storageos.volumecontroller.ApplicationAddVolumeList)1 ControllerException (com.emc.storageos.volumecontroller.ControllerException)1 ExportMaskValidationContext (com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext)1 VPlexApiClient (com.emc.storageos.vplex.api.VPlexApiClient)1