Search in sources :

Example 36 with WorkflowException

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

the class VPlexConsistencyGroupManager method addVolumesToCG.

/**
 * The method called by the workflow to add VPLEX volumes to a VPLEX
 * consistency group.
 *
 * @param vplexURI The URI of the VPLEX storage system.
 * @param cgURI The URI of the consistency group.
 * @param vplexVolumeURIs The URIs of the volumes to be added to the
 *            consistency group.
 * @param stepId The workflow step id.
 *
 * @throws WorkflowException When an error occurs updating the workflow step
 *             state.
 */
public void addVolumesToCG(URI vplexURI, URI cgURI, List<URI> vplexVolumeURIs, String stepId) throws WorkflowException {
    try {
        // Update workflow step.
        WorkflowStepCompleter.stepExecuting(stepId);
        log.info("Updated workflow step state to execute for add volumes to consistency group.");
        // Get the API client.
        StorageSystem vplexSystem = getDataObject(StorageSystem.class, vplexURI, dbClient);
        VPlexApiClient client = getVPlexAPIClient(vplexApiFactory, vplexSystem, dbClient);
        log.info("Got VPLEX API client.");
        Volume firstVPlexVolume = getDataObject(Volume.class, vplexVolumeURIs.get(0), dbClient);
        String cgName = getVplexCgName(firstVPlexVolume, cgURI);
        // Get the names of the volumes to be added.
        List<Volume> vplexVolumes = new ArrayList<Volume>();
        List<String> vplexVolumeNames = new ArrayList<String>();
        for (URI vplexVolumeURI : vplexVolumeURIs) {
            Volume vplexVolume = getDataObject(Volume.class, vplexVolumeURI, dbClient);
            vplexVolumes.add(vplexVolume);
            vplexVolumeNames.add(vplexVolume.getDeviceLabel());
            log.info("VPLEX volume:" + vplexVolume.getDeviceLabel());
        }
        log.info("Got VPLEX volume names.");
        long startTime = System.currentTimeMillis();
        // Add the volumes to the CG.
        client.addVolumesToConsistencyGroup(cgName, vplexVolumeNames);
        long elapsed = System.currentTimeMillis() - startTime;
        log.info(String.format("TIMER: Adding %s virtual volume(s) %s to the consistency group %s took %f seconds", vplexVolumeNames.size(), vplexVolumeNames, cgName, (double) elapsed / (double) 1000));
        // adding volumes to a CG after volume creation.
        for (Volume vplexVolume : vplexVolumes) {
            vplexVolume.setConsistencyGroup(cgURI);
            dbClient.updateObject(vplexVolume);
        }
        // Update workflow step state to success.
        WorkflowStepCompleter.stepSucceded(stepId);
        log.info("Updated workflow step state to success for add volumes to consistency group.");
    } catch (VPlexApiException vae) {
        log.error("Exception adding volumes to consistency group: " + vae.getMessage(), vae);
        WorkflowStepCompleter.stepFailed(stepId, vae);
    } catch (Exception ex) {
        log.error("Exception adding volumes to consistency group: " + ex.getMessage(), ex);
        ServiceError svcError = VPlexApiException.errors.jobFailed(ex);
        WorkflowStepCompleter.stepFailed(stepId, svcError);
    }
}
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) ArrayList(java.util.ArrayList) URI(java.net.URI) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 37 with WorkflowException

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

the class VPlexConsistencyGroupManager method removeVplexVolumesFromSRDFTargetCG.

/**
 * Removes volumes from SRDF Target.
 * @param vplexURI
 * @param vplexVolumeURIs
 * @param stepId
 * @throws WorkflowException
 */
public void removeVplexVolumesFromSRDFTargetCG(URI vplexURI, List<URI> vplexVolumeURIs, String stepId) throws WorkflowException {
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        Volume protoVolume = dbClient.queryObject(Volume.class, vplexVolumeURIs.get(0));
        if (NullColumnValueGetter.isNullURI(protoVolume.getConsistencyGroup())) {
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, protoVolume.getConsistencyGroup());
        if (consistencyGroup == null) {
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        // Remove the volumes from the ConsistencyGroup. Returns a codedError if failure.
        ServiceCoded codedError = removeVolumesFromCGInternal(vplexURI, protoVolume.getConsistencyGroup(), vplexVolumeURIs);
        if (codedError != null) {
            WorkflowStepCompleter.stepFailed(stepId, codedError);
            return;
        }
        // Determine if there are any remaining Vplex volumes in the consistency group.
        List<Volume> vplexVolumesInCG = BlockConsistencyGroupUtils.getActiveVplexVolumesInCG(consistencyGroup, dbClient, null);
        if (vplexVolumesInCG.isEmpty()) {
            ClusterConsistencyGroupWrapper clusterCGWrapper = getClusterConsistencyGroup(protoVolume, consistencyGroup);
            // No vplex volumes left, clean up the Vplex part of the consistency group.
            // deleteCG will call the step completer.
            deleteCG(vplexURI, consistencyGroup.getId(), clusterCGWrapper.getCgName(), clusterCGWrapper.getClusterName(), false, stepId);
        } else {
            // Vplex volumes left... we're finished.
            WorkflowStepCompleter.stepSucceded(stepId);
        }
    } catch (Exception ex) {
        log.info("Exception removing Vplex volumes from SRDF Target CG: " + ex.getMessage(), ex);
        ServiceError svcError = VPlexApiException.errors.jobFailed(ex);
        WorkflowStepCompleter.stepFailed(stepId, svcError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ClusterConsistencyGroupWrapper(com.emc.storageos.volumecontroller.impl.utils.ClusterConsistencyGroupWrapper) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 38 with WorkflowException

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

the class BlockDeviceController method addStorageSystem.

/**
 * {@inheritDoc}
 *
 * @throws WorkflowException
 */
@Override
public void addStorageSystem(URI storage, URI[] providers, boolean activeProvider, String opId) throws ControllerException {
    if (providers == null) {
        return;
    }
    String allProviders = Joiner.on("\t").join(providers);
    DiscoverTaskCompleter completer = new DiscoverTaskCompleter(StorageSystem.class, storage, opId, ControllerServiceImpl.DISCOVERY);
    StringBuilder failedProviders = new StringBuilder();
    boolean exceptionIntercepted = false;
    boolean needDiscovery = false;
    boolean acquiredLock = false;
    try {
        acquiredLock = ControllerServiceImpl.Lock.SCAN_COLLECTION_LOCK.acquire(SCAN_LOCK_TIMEOUT);
    } catch (Exception ex) {
        _log.error("Exception while acquiring a lock ", ex);
        acquiredLock = false;
    }
    if (acquiredLock) {
        try {
            StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storage);
            for (int ii = 0; ii < providers.length; ii++) {
                try {
                    StorageProvider providerSMIS = _dbClient.queryObject(StorageProvider.class, providers[ii]);
                    if (providerSMIS == null) {
                        throw DeviceControllerException.exceptions.entityNullOrEmpty(null);
                    }
                    if (providerSMIS.getInactive()) {
                        throw DeviceControllerException.exceptions.entityInactive(providerSMIS.getId());
                    }
                    boolean found = scanProvider(providerSMIS, storageSystem, activeProvider && ii == 0, opId);
                    if (!found) {
                        if (storageSystem.getSystemType().equals(Type.vnxblock.toString()) && StringUtils.isNotBlank(storageSystem.getIpAddress())) {
                            String system = addStorageToSMIS(storageSystem, providerSMIS);
                            if (!system.equalsIgnoreCase(storageSystem.getNativeGuid())) {
                                throw DeviceControllerException.exceptions.addStorageSystemFailed(storageSystem.getNativeGuid(), providerSMIS.getId().toString());
                            }
                            providerSMIS.addStorageSystem(_dbClient, storageSystem, activeProvider && ii == 0);
                            if (activeProvider && ii == 0) {
                                providerSMIS.removeDecommissionedSystem(_dbClient, storageSystem.getNativeGuid());
                            }
                            storageSystem.setReachableStatus(true);
                            _dbClient.updateObject(storageSystem);
                        } else {
                            throw DeviceControllerException.exceptions.scanFailedToFindSystem(providerSMIS.getId().toString(), storageSystem.getNativeGuid());
                        }
                    } else {
                        storageSystem.setReachableStatus(true);
                        _dbClient.updateObject(storageSystem);
                    }
                    if (providers.length > 1) {
                        completer.statusPending(_dbClient, "Adding storage to SMIS Providers : completed " + (ii + 1) + " providers out of " + providers.length);
                    }
                } catch (Exception ex) {
                    // any type of exceptions for a particular provider
                    _log.error("Failed to add storage from the following provider: " + providers[ii], ex);
                    failedProviders.append(providers[ii]).append(' ');
                    exceptionIntercepted = true;
                }
            }
            if (activeProvider) {
                updateActiveProvider(storageSystem);
                _dbClient.updateObject(storageSystem);
            }
            DecommissionedResource.removeDecommissionedFlag(_dbClient, storageSystem.getNativeGuid(), StorageSystem.class);
            if (exceptionIntercepted) {
                String opName = ResourceOperationTypeEnum.ADD_STORAGE_SYSTEM.getName();
                ServiceError serviceError = DeviceControllerException.errors.jobFailedOp(opName);
                completer.error(_dbClient, serviceError);
            } else {
                recordBourneStorageEvent(RecordableEventManager.EventType.StorageDeviceAdded, storageSystem, "Added SMI-S Storage");
                _log.info("Storage is added to the SMI-S providers: ");
                if (activeProvider) {
                    needDiscovery = true;
                    storageSystem.setLastDiscoveryRunTime(new Long(0));
                    completer.statusPending(_dbClient, "Storage is added to the specified SMI-S providers : " + allProviders);
                    // We need to set timer back to 0 to indicate that it is a new system ready for discovery.
                    _dbClient.updateObject(storageSystem);
                } else {
                    completer.ready(_dbClient);
                }
            }
        } catch (Exception outEx) {
            exceptionIntercepted = true;
            _log.error("Failed to add SMIS providers", outEx);
            ServiceError serviceError = DeviceControllerException.errors.jobFailed(outEx);
            completer.error(_dbClient, serviceError);
        } finally {
            try {
                ControllerServiceImpl.Lock.SCAN_COLLECTION_LOCK.release();
            } catch (Exception ex) {
                _log.error("Failed to release SCAN lock; scanning might become disabled", ex);
            }
            if (needDiscovery && !exceptionIntercepted) {
                try {
                    ControllerServiceImpl.scheduleDiscoverJobs(new AsyncTask[] { new AsyncTask(StorageSystem.class, storage, opId) }, Lock.DISCOVER_COLLECTION_LOCK, ControllerServiceImpl.DISCOVERY);
                } catch (Exception ex) {
                    _log.error("Failed to start discovery : " + storage, ex);
                }
            }
        }
    } else {
        String opName = ResourceOperationTypeEnum.ADD_STORAGE_SYSTEM.getName();
        ServiceError serviceError = DeviceControllerException.errors.jobFailedOp(opName);
        completer.error(_dbClient, serviceError);
        _log.debug("Not able to Acquire Scanning lock-->{}", Thread.currentThread().getId());
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) DiscoverTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.DiscoverTaskCompleter) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DataBindingException(javax.xml.bind.DataBindingException) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

WorkflowException (com.emc.storageos.workflow.WorkflowException)38 ControllerException (com.emc.storageos.volumecontroller.ControllerException)36 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)34 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)34 VPlexApiException (com.emc.storageos.vplex.api.VPlexApiException)34 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)31 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)31 VPlexApiClient (com.emc.storageos.vplex.api.VPlexApiClient)29 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)27 IOException (java.io.IOException)27 URISyntaxException (java.net.URISyntaxException)27 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)26 Volume (com.emc.storageos.db.client.model.Volume)24 URI (java.net.URI)21 ArrayList (java.util.ArrayList)18 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 VPlexVirtualVolumeInfo (com.emc.storageos.vplex.api.VPlexVirtualVolumeInfo)10 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)8 VplexMirror (com.emc.storageos.db.client.model.VplexMirror)8 ExportMask (com.emc.storageos.db.client.model.ExportMask)7