Search in sources :

Example 1 with StorageProvider

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

Aggregations

BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)1 StorageSystemViewObject (com.emc.storageos.plugins.StorageSystemViewObject)1 AbstractStorageDriver (com.emc.storageos.storagedriver.AbstractStorageDriver)1 DriverTask (com.emc.storageos.storagedriver.DriverTask)1 StorageProvider (com.emc.storageos.storagedriver.model.StorageProvider)1 StorageSystem (com.emc.storageos.storagedriver.model.StorageSystem)1 ExternalDeviceCollectionException (com.emc.storageos.volumecontroller.impl.externaldevice.ExternalDeviceCollectionException)1 ArrayList (java.util.ArrayList)1