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;
}
}
Aggregations