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());
}
}
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;
}
Aggregations