Search in sources :

Example 1 with ECSCollectionException

use of com.emc.storageos.plugins.metering.ecs.ECSCollectionException in project coprhd-controller by CoprHD.

the class ECSCommunicationInterface method discover.

/**
 * Get storage pool and storage ports
 */
@Override
public void discover(AccessProfile accessProfile) throws BaseCollectionException {
    URI storageSystemId = null;
    StorageSystem storageSystem = null;
    String detailedStatusMessage = "Unknown Status";
    long startTime = System.currentTimeMillis();
    _logger.info("ECSCommunicationInterface:discover Access Profile Details :" + accessProfile.toString());
    try {
        storageSystemId = accessProfile.getSystemId();
        storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
        // try to connect to the ECS
        ECSApi ecsApi = getECSDevice(storageSystem);
        String authToken = ecsApi.getAuthToken();
        if (authToken.isEmpty()) {
            throw ECSException.exceptions.discoverFailed("Could not obtain authToken");
        }
        // Make sure user is system admin before proceeding to discovery
        if (!ecsApi.isSystemAdmin()) {
            _logger.error("User:" + accessProfile.getUserName() + "dont have privileges to access Elastic Cloud Storage: " + accessProfile.getIpAddress());
            _logger.error("Discovery failed");
            throw ECSException.exceptions.discoverFailed("User is not ECS System Admin");
        }
        String ecsVersion = ecsApi.getECSVersion();
        String ecsSerialNumber = ecsApi.getECSSerialNum();
        // Get details of storage system
        String nativeGuid = NativeGUIDGenerator.generateNativeGuid(DiscoveredDataObject.Type.ecs.toString(), ecsSerialNumber);
        storageSystem.setNativeGuid(nativeGuid);
        storageSystem.setSerialNumber(ecsSerialNumber);
        storageSystem.setFirmwareVersion(ecsVersion);
        storageSystem.setUsername(accessProfile.getUserName());
        storageSystem.setPassword(accessProfile.getPassword());
        storageSystem.setPortNumber(accessProfile.getPortNumber());
        storageSystem.setIpAddress(accessProfile.getIpAddress());
        storageSystem.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
        storageSystem.setReachableStatus(true);
        storageSystem.setInactive(false);
        _dbClient.persistObject(storageSystem);
        // Discover storage pools
        Map<String, List<StoragePool>> allPools = new HashMap<String, List<StoragePool>>();
        List<StoragePool> newPools = new ArrayList<StoragePool>();
        List<StoragePool> existingPools = new ArrayList<StoragePool>();
        StoragePool storagePool;
        List<ECSStoragePool> ecsStoragePools = ecsApi.getStoragePools();
        for (ECSStoragePool ecsPool : ecsStoragePools) {
            // Check if this storage pool was already discovered
            storagePool = null;
            String storagePoolNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, ecsPool.getId(), NativeGUIDGenerator.POOL);
            @SuppressWarnings("deprecation") List<URI> poolURIs = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePoolByNativeGuidConstraint(storagePoolNativeGuid));
            for (URI poolUri : poolURIs) {
                StoragePool pool = _dbClient.queryObject(StoragePool.class, poolUri);
                if (!pool.getInactive() && pool.getStorageDevice().equals(storageSystemId)) {
                    storagePool = pool;
                    break;
                }
            }
            if (storagePool == null) {
                storagePool = new StoragePool();
                storagePool.setId(URIUtil.createId(StoragePool.class));
                storagePool.setNativeId(ecsPool.getId());
                storagePool.setNativeGuid(storagePoolNativeGuid);
                storagePool.setLabel(storagePoolNativeGuid);
                storagePool.setPoolClassName("ECS Pool");
                storagePool.setStorageDevice(storageSystem.getId());
                StringSet protocols = new StringSet();
                protocols.add("S3");
                protocols.add("Swift");
                protocols.add("Atmos");
                storagePool.setProtocols(protocols);
                storagePool.setPoolName(ecsPool.getName());
                storagePool.setOperationalStatus(StoragePool.PoolOperationalStatus.READY.toString());
                storagePool.setPoolServiceType(PoolServiceType.object.toString());
                storagePool.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
                storagePool.setSupportedResourceTypes(StoragePool.SupportedResourceTypes.THICK_ONLY.toString());
                storagePool.setFreeCapacity(ecsPool.getFreeCapacity() * BYTESCONVERTER * BYTESCONVERTER);
                storagePool.setTotalCapacity(ecsPool.getTotalCapacity() * BYTESCONVERTER * BYTESCONVERTER);
                storagePool.setInactive(false);
                storagePool.setDataCenters(ecsPool.getTotalDataCenters());
                _logger.info("Creating new ECS storage pool using NativeId : {}", storagePoolNativeGuid);
                storagePool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
                storagePool.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
                newPools.add(storagePool);
            } else {
                existingPools.add(storagePool);
            }
        }
        allPools.put(NEW, newPools);
        allPools.put(EXISTING, existingPools);
        _logger.info("No of newly discovered pools {}", allPools.get(NEW).size());
        _logger.info("No of existing discovered pools {}", allPools.get(EXISTING).size());
        if (!allPools.get(NEW).isEmpty()) {
            _dbClient.createObject(allPools.get(NEW));
        }
        if (!allPools.get(EXISTING).isEmpty()) {
            _dbClient.persistObject(allPools.get(EXISTING));
        }
        // Get storage ports
        HashMap<String, List<StoragePort>> storagePorts = new HashMap<String, List<StoragePort>>();
        List<StoragePort> newStoragePorts = new ArrayList<StoragePort>();
        List<StoragePort> existingStoragePorts = new ArrayList<StoragePort>();
        List<ECSStoragePort> ecsStoragePorts = ecsApi.getStoragePort(storageSystem.getIpAddress());
        for (ECSStoragePort ecsPort : ecsStoragePorts) {
            StoragePort storagePort = null;
            String portNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, ecsPort.getIpAddress(), NativeGUIDGenerator.PORT);
            // Check if storage port was already discovered
            @SuppressWarnings("deprecation") List<URI> portURIs = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortByNativeGuidConstraint(portNativeGuid));
            for (URI portUri : portURIs) {
                StoragePort port = _dbClient.queryObject(StoragePort.class, portUri);
                if (port.getStorageDevice().equals(storageSystemId) && !port.getInactive()) {
                    storagePort = port;
                    break;
                }
            }
            if (storagePort == null) {
                // Create new port
                storagePort = new StoragePort();
                storagePort.setId(URIUtil.createId(StoragePort.class));
                storagePort.setTransportType("IP");
                storagePort.setNativeGuid(portNativeGuid);
                storagePort.setLabel(portNativeGuid);
                storagePort.setStorageDevice(storageSystemId);
                storagePort.setPortNetworkId(ecsPort.getIpAddress().toLowerCase());
                storagePort.setPortName(ecsPort.getName());
                storagePort.setLabel(ecsPort.getName());
                storagePort.setPortGroup(ecsPort.getName());
                storagePort.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
                storagePort.setOperationalStatus(StoragePort.OperationalStatus.OK.toString());
                _logger.info("Creating new storage port using NativeGuid : {}", portNativeGuid);
                newStoragePorts.add(storagePort);
            } else {
                existingStoragePorts.add(storagePort);
            }
            storagePort.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
            storagePort.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
        }
        storagePorts.put(NEW, newStoragePorts);
        storagePorts.put(EXISTING, existingStoragePorts);
        _logger.info("No of newly discovered ports {}", storagePorts.get(NEW).size());
        _logger.info("No of existing discovered ports {}", storagePorts.get(EXISTING).size());
        if (!storagePorts.get(NEW).isEmpty()) {
            _dbClient.createObject(storagePorts.get(NEW));
        }
        if (!storagePorts.get(EXISTING).isEmpty()) {
            _dbClient.persistObject(storagePorts.get(EXISTING));
        }
        // Discover ECS Namespaces
        List<ObjectNamespace> allNamespaces = new ArrayList<ObjectNamespace>();
        Map<String, List<ObjectNamespace>> bothNamespaces = discoverNamespaces(storageSystem);
        _logger.info("No of newly discovered namespaces {}", bothNamespaces.get(NEW).size());
        _logger.info("No of existing discovered namespaces {}", bothNamespaces.get(EXISTING).size());
        if (bothNamespaces != null && !bothNamespaces.get(NEW).isEmpty()) {
            allNamespaces.addAll(bothNamespaces.get(NEW));
            _dbClient.createObject(bothNamespaces.get(NEW));
        }
        if (bothNamespaces != null && !bothNamespaces.get(EXISTING).isEmpty()) {
            allNamespaces.addAll(bothNamespaces.get(EXISTING));
            _dbClient.updateObject(bothNamespaces.get(EXISTING));
        }
        // Some namespaces might have been deleted
        DiscoveryUtils.checkNamespacesNotVisible(allNamespaces, _dbClient, storageSystemId);
        _completer.statusPending(_dbClient, "Completed namespace discovery");
        // Discovery success
        detailedStatusMessage = String.format("Discovery completed successfully for ECS: %s", storageSystemId.toString());
    } catch (Exception e) {
        if (storageSystem != null) {
            cleanupDiscovery(storageSystem);
        }
        detailedStatusMessage = String.format("Discovery failed for Storage System ECS %s: because %s", storageSystemId.toString(), e.getLocalizedMessage());
        _logger.error(detailedStatusMessage, e);
        throw new ECSCollectionException(false, ServiceCode.DISCOVERY_ERROR, null, detailedStatusMessage, null, null);
    } finally {
        if (storageSystem != null) {
            try {
                // set detailed message
                storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.persistObject(storageSystem);
            } catch (DatabaseException ex) {
                _logger.error("Error while persisting object to DB", ex);
            }
        }
        long totalTime = System.currentTimeMillis() - startTime;
        _logger.info(String.format("Discovery of ECS Storage System %s took %f seconds", accessProfile.getIpAddress(), (double) totalTime / (double) 1000));
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) ECSStoragePool(com.emc.storageos.ecs.api.ECSStoragePool) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) StringSet(com.emc.storageos.db.client.model.StringSet) ECSStoragePort(com.emc.storageos.ecs.api.ECSStoragePort) ArrayList(java.util.ArrayList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) ECSStoragePort(com.emc.storageos.ecs.api.ECSStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ECSCollectionException(com.emc.storageos.plugins.metering.ecs.ECSCollectionException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) SMIPluginException(com.emc.storageos.plugins.metering.smis.SMIPluginException) ECSException(com.emc.storageos.ecs.api.ECSException) ECSApi(com.emc.storageos.ecs.api.ECSApi) ECSStoragePool(com.emc.storageos.ecs.api.ECSStoragePool) ObjectNamespace(com.emc.storageos.db.client.model.ObjectNamespace) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ECSCollectionException(com.emc.storageos.plugins.metering.ecs.ECSCollectionException)

Example 2 with ECSCollectionException

use of com.emc.storageos.plugins.metering.ecs.ECSCollectionException in project coprhd-controller by CoprHD.

the class ECSCommunicationInterface method discoverNamespaces.

/**
 * Discover ECS Namespaces with details
 * @param storageSystem
 * @return existing and new marked namespace list
 * @throws ECSCollectionException
 */
private Map<String, List<ObjectNamespace>> discoverNamespaces(StorageSystem storageSystem) throws Exception {
    URI storageSystemId = storageSystem.getId();
    List<String> namespaceIdList = new ArrayList<String>();
    Map<String, List<ObjectNamespace>> bothNamespaces = new HashMap<String, List<ObjectNamespace>>();
    List<ObjectNamespace> newNamespaces = new ArrayList<ObjectNamespace>();
    List<ObjectNamespace> existingNamespaces = new ArrayList<ObjectNamespace>();
    try {
        _logger.info("discover namespace information for storage system {} - start", storageSystemId);
        ECSApi ecsApi = getECSDevice(storageSystem);
        ObjectNamespace ecsNamespace = null;
        // Discover list of all namespaces
        namespaceIdList = ecsApi.getNamespaces();
        for (String nsId : namespaceIdList) {
            // Check if this namespace was already discovered
            ecsNamespace = null;
            String nsNativeGuid = NativeGUIDGenerator.generateNativeGuidForNamespace(storageSystem, nsId, NativeGUIDGenerator.NAMESPACE);
            URIQueryResultList uriQueryList = new URIQueryResultList();
            _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getObjectNamespaceByNativeGuidConstraint(nsNativeGuid), uriQueryList);
            // Even if the namespace GUID is duplicated, URI-storageSystemId is unique
            Iterator<ObjectNamespace> nsItr = _dbClient.queryIterativeObjects(ObjectNamespace.class, uriQueryList);
            while (nsItr.hasNext()) {
                ObjectNamespace ns = nsItr.next();
                if (ns.getStorageDevice().equals(storageSystemId)) {
                    ecsNamespace = ns;
                    break;
                }
            }
            if (ecsNamespace == null) {
                // New namespace, not discovered
                ecsNamespace = new ObjectNamespace();
                ecsNamespace.setId(URIUtil.createId(ObjectNamespace.class));
                ecsNamespace.setNativeId(nsId);
                ecsNamespace.setNativeGuid(nsNativeGuid);
                ecsNamespace.setLabel(nsNativeGuid);
                ecsNamespace.setStorageDevice(storageSystemId);
                // Now obtain the complete namespace details
                ECSNamespaceRepGroup nsGroup = ecsApi.getNamespaceDetails(nsId);
                ecsNamespace.setPoolType(nsGroup.getRgType());
                StringSet repGroups = new StringSet();
                for (String rg : nsGroup.getReplicationGroups()) {
                    repGroups.add(rg);
                }
                ecsNamespace.setStoragePools(repGroups);
                ecsNamespace.setNsName(nsGroup.getNamespaceName());
                ecsNamespace.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
                // Check if this newly discovered namespace is already mapped with a tenant
                // Upgrade from 2.4 to 2.5
                ecsNamespace.setMapped(false);
                List<URI> allTenantURI = _dbClient.queryByType(TenantOrg.class, true);
                Iterator<TenantOrg> tnItr = _dbClient.queryIterativeObjects(TenantOrg.class, allTenantURI);
                while (tnItr.hasNext()) {
                    TenantOrg ten = tnItr.next();
                    if (ten.getNamespace() != null && !ten.getNamespace().isEmpty() && ten.getNamespace().equalsIgnoreCase(nsId)) {
                        ecsNamespace.setTenant(ten.getId());
                        ecsNamespace.setMapped(true);
                        break;
                    }
                }
                _logger.info("Creating new namespace with NativeGuid : {}", nsNativeGuid);
                newNamespaces.add(ecsNamespace);
            } else {
                existingNamespaces.add(ecsNamespace);
            }
        }
        bothNamespaces.put(NEW, newNamespaces);
        bothNamespaces.put(EXISTING, existingNamespaces);
        _logger.info("discoverNamespaces for storage system {} - complete", storageSystemId);
        return bothNamespaces;
    } catch (Exception e) {
        _logger.error("discoverNamespaces failed. Storage system: {}", storageSystemId, e);
        throw e;
    }
}
Also used : ECSNamespaceRepGroup(com.emc.storageos.ecs.api.ECSNamespaceRepGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ECSCollectionException(com.emc.storageos.plugins.metering.ecs.ECSCollectionException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) SMIPluginException(com.emc.storageos.plugins.metering.smis.SMIPluginException) ECSException(com.emc.storageos.ecs.api.ECSException) ECSApi(com.emc.storageos.ecs.api.ECSApi) StringSet(com.emc.storageos.db.client.model.StringSet) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) ArrayList(java.util.ArrayList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ObjectNamespace(com.emc.storageos.db.client.model.ObjectNamespace)

Aggregations

URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 ObjectNamespace (com.emc.storageos.db.client.model.ObjectNamespace)2 StringSet (com.emc.storageos.db.client.model.StringSet)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 ECSApi (com.emc.storageos.ecs.api.ECSApi)2 ECSException (com.emc.storageos.ecs.api.ECSException)2 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)2 ECSCollectionException (com.emc.storageos.plugins.metering.ecs.ECSCollectionException)2 SMIPluginException (com.emc.storageos.plugins.metering.smis.SMIPluginException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 StoragePool (com.emc.storageos.db.client.model.StoragePool)1 StoragePort (com.emc.storageos.db.client.model.StoragePort)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)1 ECSNamespaceRepGroup (com.emc.storageos.ecs.api.ECSNamespaceRepGroup)1 ECSStoragePool (com.emc.storageos.ecs.api.ECSStoragePool)1