use of com.emc.storageos.storagedriver.AbstractStorageDriver in project coprhd-controller by CoprHD.
the class ControllerServiceImpl method initExternalBlockStorageDevice.
private void initExternalBlockStorageDevice(List<StorageSystemType> types) {
ExternalBlockStorageDevice blockDevice = (ExternalBlockStorageDevice) getBean(StorageDriverManager.EXTERNAL_STORAGE_DEVICE);
// key: storage system type name, value: driver instance
Map<String, AbstractStorageDriver> blockDeviceDrivers = blockDevice.getDrivers();
// key: main class name, value: driver instance
Map<String, AbstractStorageDriver> cachedDriverInstances = new HashMap<String, AbstractStorageDriver>();
for (StorageSystemType type : types) {
String typeName = type.getStorageTypeName();
String metaType = type.getMetaType();
if (!StringUtils.equals(metaType, StorageSystemType.META_TYPE.BLOCK.toString())) {
// TODO for now it seems that we only support block type driver
// In future, to support file/object or other type, we need add more codes here
_log.info("Skip load info of {}, for its type is {} which is not supported for now", typeName, metaType);
continue;
}
String className = type.getDriverClassName();
// provider and managed system should use the same driver instance
if (cachedDriverInstances.containsKey(className)) {
blockDeviceDrivers.put(typeName, cachedDriverInstances.get(className));
_log.info("Driver info for storage system type {} has been set into externalBlockStorageDevice instance", typeName);
continue;
}
String mainClassName = type.getDriverClassName();
try {
AbstractStorageDriver driverInstance = (AbstractStorageDriver) Class.forName(mainClassName).newInstance();
blockDeviceDrivers.put(typeName, driverInstance);
cachedDriverInstances.put(className, driverInstance);
_log.info("Driver info for storage system type {} has been set into externalBlockStorageDevice instance", typeName);
} catch (Exception e) {
_log.error("Error happened when instantiating class {}", mainClassName);
}
}
}
use of com.emc.storageos.storagedriver.AbstractStorageDriver in project coprhd-controller by CoprHD.
the class ExternalDeviceCommunicationInterface method scan.
@Override
public void scan(AccessProfile accessProfile) throws BaseCollectionException {
// Initialize driver instance for storage provider,
// call driver to scan the provider to get list of managed storage systems,
// update the system with this information.
_log.info("Scanning started for provider: {}", accessProfile.getSystemId());
com.emc.storageos.db.client.model.StorageProvider.ConnectionStatus cxnStatus = com.emc.storageos.db.client.model.StorageProvider.ConnectionStatus.CONNECTED;
// Get discovery driver class based on storage device type
String deviceType = accessProfile.getSystemType();
AbstractStorageDriver driver = getDriver(deviceType);
if (driver == null) {
String errorMsg = String.format("No driver entry defined for device type: %s . ", deviceType);
_log.info(errorMsg);
throw new ExternalDeviceCollectionException(false, ServiceCode.DISCOVERY_ERROR, null, errorMsg, null, null);
}
com.emc.storageos.db.client.model.StorageProvider storageProvider = null;
try {
storageProvider = _dbClient.queryObject(com.emc.storageos.db.client.model.StorageProvider.class, accessProfile.getSystemId());
String username = storageProvider.getUserName();
String password = storageProvider.getPassword();
String hostName = storageProvider.getIPAddress();
Integer portNumber = storageProvider.getPortNumber();
String providerType = storageProvider.getInterfaceType();
Boolean useSsl = storageProvider.getUseSSL();
String msg = String.format("Storage provider info: type: %s, host: %s, port: %s, user: %s, useSsl: %s", providerType, hostName, portNumber, username, useSsl);
_log.info(msg);
StorageProvider driverProvider = new StorageProvider();
// initialize driver provider
driverProvider.setProviderHost(hostName);
driverProvider.setPortNumber(portNumber);
driverProvider.setUsername(username);
driverProvider.setPassword(password);
driverProvider.setUseSSL(useSsl);
// call the driver
List<StorageSystem> systems = new ArrayList<>();
DriverTask task = driver.discoverStorageProvider(driverProvider, systems);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
// process results, populate cache
_log.info("Scan: found {} systems for provider {}", systems.size(), accessProfile.getSystemId());
// update provider with scan info
storageProvider.setVersionString(driverProvider.getProviderVersion());
if (driverProvider.isSupportedVersion()) {
storageProvider.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
} else {
storageProvider.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.INCOMPATIBLE.name());
String errorMsg = String.format("Storage provider %s has version %s which is not supported by driver", storageProvider.getIPAddress(), storageProvider.getVersionString());
throw new ExternalDeviceCollectionException(false, ServiceCode.DISCOVERY_ERROR, null, errorMsg, null, null);
}
// process storage system cache
Map<String, StorageSystemViewObject> storageSystemsCache = accessProfile.getCache();
for (StorageSystem driverStorageSystem : systems) {
String systemType = driverStorageSystem.getSystemType();
String nativeGuid = NativeGUIDGenerator.generateNativeGuid(systemType, driverStorageSystem.getNativeId());
StorageSystemViewObject storageSystemView = storageSystemsCache.get(nativeGuid);
if (storageSystemView == null) {
storageSystemView = new StorageSystemViewObject();
}
storageSystemView.setDeviceType(systemType);
storageSystemView.addprovider(accessProfile.getSystemId().toString());
storageSystemView.setProperty(StorageSystemViewObject.SERIAL_NUMBER, driverStorageSystem.getSerialNumber());
storageSystemView.setProperty(StorageSystemViewObject.VERSION, driverStorageSystem.getFirmwareVersion());
storageSystemView.setProperty(StorageSystemViewObject.STORAGE_NAME, driverStorageSystem.getNativeId());
storageSystemsCache.put(nativeGuid, storageSystemView);
_log.info(String.format("Info for storage system %s (provider ip %s): type: %s, nativeGuid: %s", driverStorageSystem.getSerialNumber(), accessProfile.getIpAddress(), systemType, nativeGuid));
}
} else {
// task status is not ready
String errorMsg = String.format("Failed to scan provider %s of type %s. \n" + " Driver task message: %s", accessProfile.getSystemId(), accessProfile.getSystemType(), task.getMessage());
throw new ExternalDeviceCollectionException(false, ServiceCode.DISCOVERY_ERROR, null, errorMsg, null, null);
}
} catch (Exception ex) {
_log.error("Error scanning provider: {} of type: {} .", accessProfile.getIpAddress(), accessProfile.getSystemType(), ex);
cxnStatus = com.emc.storageos.db.client.model.StorageProvider.ConnectionStatus.NOTCONNECTED;
throw ex;
} finally {
if (storageProvider != null) {
storageProvider.setConnectionStatus(cxnStatus.name());
_dbClient.updateObject(storageProvider);
}
_log.info("Completed scan of {} provider: ", accessProfile.getSystemType(), accessProfile.getIpAddress());
}
}
use of com.emc.storageos.storagedriver.AbstractStorageDriver in project coprhd-controller by CoprHD.
the class ExternalDeviceCommunicationInterface method initDrivers.
private void initDrivers() {
if (initialized) {
return;
}
List<URI> ids = _dbClient.queryByType(StorageSystemType.class, true);
Iterator<StorageSystemType> it = _dbClient.queryIterativeObjects(StorageSystemType.class, ids);
Map<String, AbstractStorageDriver> cachedDriverInstances = new HashMap<>();
while (it.hasNext()) {
StorageSystemType type = it.next();
if (type.getIsNative() == null || type.getIsNative()) {
continue;
}
if (!StringUtils.equals(type.getMetaType(), StorageSystemType.META_TYPE.BLOCK.toString())) {
continue;
}
String typeName = type.getStorageTypeName();
String className = type.getDriverClassName();
// provider and managed system should use the same driver instance
if (cachedDriverInstances.containsKey(className)) {
drivers.put(typeName, cachedDriverInstances.get(className));
_log.info("Driver info for storage system type {} has been set into externaldevice instance", typeName);
continue;
}
String mainClassName = type.getDriverClassName();
try {
AbstractStorageDriver driverInstance = (AbstractStorageDriver) Class.forName(mainClassName).newInstance();
drivers.put(typeName, driverInstance);
cachedDriverInstances.put(className, driverInstance);
_log.info("Driver info for storage system type {} has been set into externaldevice instance", typeName);
} catch (Exception e) {
_log.error("Error happened when instantiating class {}", mainClassName);
}
}
initialized = true;
}
use of com.emc.storageos.storagedriver.AbstractStorageDriver in project coprhd-controller by CoprHD.
the class ExternalDeviceCommunicationInterface method getDriver.
/**
* Get device driver based on the driver type.
* @param driverType
* @return driver
*/
private synchronized AbstractStorageDriver getDriver(String driverType) {
// look up driver
AbstractStorageDriver discoveryDriver = discoveryDrivers.get(driverType);
if (discoveryDriver != null) {
return discoveryDriver;
} else {
// init driver
AbstractStorageDriver driver = drivers.get(driverType);
if (driver == null) {
initDrivers();
driver = drivers.get(driverType);
if (driver == null) {
_log.info("No driver entry defined for device type: {} . ", driverType);
return null;
}
}
init(driver);
discoveryDrivers.put(driverType, driver);
return driver;
}
}
use of com.emc.storageos.storagedriver.AbstractStorageDriver in project coprhd-controller by CoprHD.
the class ExternalDeviceCommunicationInterface method discover.
@Override
public void discover(AccessProfile accessProfile) throws BaseCollectionException {
// Get discovery driver class based on storage device type
String deviceType = accessProfile.getSystemType();
AbstractStorageDriver driver = getDriver(deviceType);
if (driver == null) {
String errorMsg = String.format("No driver entry defined for device type: %s . ", deviceType);
_log.info(errorMsg);
throw new ExternalDeviceCollectionException(false, ServiceCode.DISCOVERY_ERROR, null, errorMsg, null, null);
}
try {
if (null != accessProfile.getnamespace() && (accessProfile.getnamespace().equals(com.emc.storageos.db.client.model.StorageSystem.Discovery_Namespaces.UNMANAGED_VOLUMES.toString()))) {
discoverUnManagedBlockObjects(driver, accessProfile);
_completer.statusReady(_dbClient, "Completed unmanaged block object discovery");
} else if (null != accessProfile.getnamespace() && (accessProfile.getnamespace().equals(com.emc.storageos.db.client.model.StorageSystem.Discovery_Namespaces.UNMANAGED_FILESYSTEMS.toString()))) {
_log.warn("Discovery of unmanaged file systems is not supported for external storage system of type {}", accessProfile.getSystemType());
} else {
// discover storage system
discoverStorageSystem(driver, accessProfile);
_completer.statusPending(_dbClient, "Completed storage system discovery");
// discover storage pools
List<com.emc.storageos.db.client.model.StoragePool> storagePools = discoverStoragePools(driver, accessProfile);
List<com.emc.storageos.db.client.model.StoragePool> storagePoolsToMatchWithVpools = new ArrayList<>();
storagePoolsToMatchWithVpools.addAll(storagePools);
List<com.emc.storageos.db.client.model.StoragePool> notVisiblePools = DiscoveryUtils.checkStoragePoolsNotVisible(storagePools, _dbClient, accessProfile.getSystemId());
storagePoolsToMatchWithVpools.addAll(notVisiblePools);
_completer.statusPending(_dbClient, "Completed storage pools discovery");
// discover ports
List<com.emc.storageos.db.client.model.StoragePort> allPorts = new ArrayList<>();
Set<Network> networksToUpdate = new HashSet<>();
Map<String, List<com.emc.storageos.db.client.model.StoragePort>> ports = discoverStoragePorts(driver, networksToUpdate, accessProfile);
_log.info("No of newly discovered ports {}", ports.get(NEW).size());
_log.info("No of existing discovered ports {}", ports.get(EXISTING).size());
if (null != ports && !ports.get(NEW).isEmpty()) {
allPorts.addAll(ports.get(NEW));
_dbClient.createObject(ports.get(NEW));
}
if (null != ports && !ports.get(EXISTING).isEmpty()) {
allPorts.addAll(ports.get(EXISTING));
_dbClient.updateObject(ports.get(EXISTING));
}
if (!networksToUpdate.isEmpty()) {
_dbClient.updateObject(networksToUpdate);
}
List<com.emc.storageos.db.client.model.StoragePort> notVisiblePorts = DiscoveryUtils.checkStoragePortsNotVisible(allPorts, _dbClient, accessProfile.getSystemId());
List<com.emc.storageos.db.client.model.StoragePort> allExistPorts = new ArrayList<>(ports.get(EXISTING));
allExistPorts.addAll(notVisiblePorts);
_completer.statusPending(_dbClient, "Completed port discovery");
StoragePortAssociationHelper.runUpdatePortAssociationsProcess(ports.get(NEW), allExistPorts, _dbClient, _coordinator, storagePoolsToMatchWithVpools);
_completer.statusReady(_dbClient, "Completed storage discovery");
}
} catch (BaseCollectionException bEx) {
_completer.error(_dbClient, bEx);
throw bEx;
}
}
Aggregations