Search in sources :

Example 1 with AbstractStorageDriver

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);
        }
    }
}
Also used : ExternalBlockStorageDevice(com.emc.storageos.volumecontroller.impl.externaldevice.ExternalBlockStorageDevice) HashMap(java.util.HashMap) AbstractStorageDriver(com.emc.storageos.storagedriver.AbstractStorageDriver) StorageSystemType(com.emc.storageos.db.client.model.StorageSystemType) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) BeansException(org.springframework.beans.BeansException)

Example 2 with AbstractStorageDriver

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());
    }
}
Also used : StorageSystemViewObject(com.emc.storageos.plugins.StorageSystemViewObject) ArrayList(java.util.ArrayList) AbstractStorageDriver(com.emc.storageos.storagedriver.AbstractStorageDriver) StorageProvider(com.emc.storageos.storagedriver.model.StorageProvider) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ExternalDeviceCollectionException(com.emc.storageos.volumecontroller.impl.externaldevice.ExternalDeviceCollectionException) DriverTask(com.emc.storageos.storagedriver.DriverTask) ExternalDeviceCollectionException(com.emc.storageos.volumecontroller.impl.externaldevice.ExternalDeviceCollectionException) StorageSystem(com.emc.storageos.storagedriver.model.StorageSystem)

Example 3 with AbstractStorageDriver

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;
}
Also used : HashMap(java.util.HashMap) AbstractStorageDriver(com.emc.storageos.storagedriver.AbstractStorageDriver) StorageSystemType(com.emc.storageos.db.client.model.StorageSystemType) URI(java.net.URI) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ExternalDeviceCollectionException(com.emc.storageos.volumecontroller.impl.externaldevice.ExternalDeviceCollectionException)

Example 4 with AbstractStorageDriver

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;
    }
}
Also used : AbstractStorageDriver(com.emc.storageos.storagedriver.AbstractStorageDriver)

Example 5 with AbstractStorageDriver

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;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) StoragePort(com.emc.storageos.storagedriver.model.StoragePort) AbstractStorageDriver(com.emc.storageos.storagedriver.AbstractStorageDriver) ExternalDeviceCollectionException(com.emc.storageos.volumecontroller.impl.externaldevice.ExternalDeviceCollectionException) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap)

Aggregations

AbstractStorageDriver (com.emc.storageos.storagedriver.AbstractStorageDriver)6 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)4 ExternalDeviceCollectionException (com.emc.storageos.volumecontroller.impl.externaldevice.ExternalDeviceCollectionException)3 HashMap (java.util.HashMap)3 StorageSystemType (com.emc.storageos.db.client.model.StorageSystemType)2 ArrayList (java.util.ArrayList)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 StringMap (com.emc.storageos.db.client.model.StringMap)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 StorageSystemViewObject (com.emc.storageos.plugins.StorageSystemViewObject)1 BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)1 DriverTask (com.emc.storageos.storagedriver.DriverTask)1 StoragePort (com.emc.storageos.storagedriver.model.StoragePort)1 StorageProvider (com.emc.storageos.storagedriver.model.StorageProvider)1 StorageSystem (com.emc.storageos.storagedriver.model.StorageSystem)1 ExternalBlockStorageDevice (com.emc.storageos.volumecontroller.impl.externaldevice.ExternalBlockStorageDevice)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1