Search in sources :

Example 96 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider 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)

Example 97 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class ControllerUtils method isVmaxUsing81SMIS.

/**
 * Check whether the given storage system is managed by SMI 8.1 or later
 *
 * @param storage
 * @param dbClient
 * @return true if the version is at least 8.1
 */
public static boolean isVmaxUsing81SMIS(StorageSystem storage, DbClient dbClient) {
    if (storage != null && !NullColumnValueGetter.isNullURI(storage.getActiveProviderURI())) {
        StorageProvider provider = dbClient.queryObject(StorageProvider.class, storage.getActiveProviderURI());
        if (provider != null && provider.getVersionString() != null) {
            String providerVersion = provider.getVersionString().replaceFirst("[^\\d]", "");
            String[] provStr = providerVersion.split(Constants.SMIS_DOT_REGEX);
            int major = Integer.parseInt(provStr[0]);
            int minor = Integer.parseInt(provStr[1]);
            return major > SMIS_MAJOR_VERSION || major == SMIS_MAJOR_VERSION && minor >= SMIS_MINOR_VERSION;
        }
    }
    return false;
}
Also used : StorageProvider(com.emc.storageos.db.client.model.StorageProvider) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

Aggregations

StorageProvider (com.emc.storageos.db.client.model.StorageProvider)97 URI (java.net.URI)44 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)26 ArrayList (java.util.ArrayList)24 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)23 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)19 Produces (javax.ws.rs.Produces)19 IOException (java.io.IOException)18 StringSet (com.emc.storageos.db.client.model.StringSet)17 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)15 Path (javax.ws.rs.Path)15 Consumes (javax.ws.rs.Consumes)11 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)10 MapStorageProvider (com.emc.storageos.api.mapper.functions.MapStorageProvider)8 StorageSystemViewObject (com.emc.storageos.plugins.StorageSystemViewObject)8 GET (javax.ws.rs.GET)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 AsyncTask (com.emc.storageos.volumecontroller.AsyncTask)7 BlockController (com.emc.storageos.volumecontroller.BlockController)7