Search in sources :

Example 1 with ECSNamespaceRepGroup

use of com.emc.storageos.ecs.api.ECSNamespaceRepGroup 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)1 ObjectNamespace (com.emc.storageos.db.client.model.ObjectNamespace)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 ECSApi (com.emc.storageos.ecs.api.ECSApi)1 ECSException (com.emc.storageos.ecs.api.ECSException)1 ECSNamespaceRepGroup (com.emc.storageos.ecs.api.ECSNamespaceRepGroup)1 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)1 ECSCollectionException (com.emc.storageos.plugins.metering.ecs.ECSCollectionException)1 SMIPluginException (com.emc.storageos.plugins.metering.smis.SMIPluginException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1