use of com.emc.storageos.netappc.NetAppClusterApi in project coprhd-controller by CoprHD.
the class NetAppClusterModeCommIntf method discoverStoragePools.
/**
* Discover the storage pools for NetApp Cluster mode array
*
* @param system
* Storage system information
* @return Map of new and existing storage pools
* @throws NetAppCException
*/
private Map<String, List<StoragePool>> discoverStoragePools(StorageSystem system, List<StoragePool> poolsToMatchWithVpool) throws NetAppCException {
Map<String, List<StoragePool>> storagePools = new HashMap<String, List<StoragePool>>();
List<StoragePool> newPools = new ArrayList<StoragePool>();
List<StoragePool> existingPools = new ArrayList<StoragePool>();
_logger.info("Start storage pool discovery for storage system {}", system.getId());
try {
NetAppClusterApi netAppCApi = new NetAppClusterApi.Builder(system.getIpAddress(), system.getPortNumber(), system.getUsername(), system.getPassword()).https(true).build();
List<AggregateInfo> pools = netAppCApi.listClusterAggregates(null);
for (AggregateInfo netAppPool : pools) {
StoragePool pool = null;
URIQueryResultList results = new URIQueryResultList();
String poolNativeGuid = NativeGUIDGenerator.generateNativeGuid(system, netAppPool.getName(), NativeGUIDGenerator.POOL);
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePoolByNativeGuidConstraint(poolNativeGuid), results);
if (results.iterator().hasNext()) {
StoragePool tmpPool = _dbClient.queryObject(StoragePool.class, results.iterator().next());
if (tmpPool.getStorageDevice().equals(system.getId())) {
pool = tmpPool;
}
}
if (pool == null) {
pool = new StoragePool();
pool.setId(URIUtil.createId(StoragePool.class));
pool.setLabel(poolNativeGuid);
pool.setNativeGuid(poolNativeGuid);
pool.setPoolServiceType(PoolServiceType.file.toString());
pool.setStorageDevice(system.getId());
pool.setOperationalStatus(StoragePool.PoolOperationalStatus.READY.toString());
StringSet protocols = new StringSet();
protocols.add("NFS");
protocols.add("CIFS");
pool.setProtocols(protocols);
pool.setPoolName(netAppPool.getName());
pool.setNativeId(netAppPool.getName());
pool.setSupportedResourceTypes(StoragePool.SupportedResourceTypes.THIN_AND_THICK.toString());
Map<String, String> params = new HashMap<String, String>();
params.put(StoragePool.ControllerParam.PoolType.name(), "File Pool");
pool.addControllerParams(params);
pool.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
_logger.info("Creating new storage pool using NativeGuid : {}", poolNativeGuid);
newPools.add(pool);
} else {
existingPools.add(pool);
}
// Update Pool details with new discovery run
pool.setTotalCapacity(netAppPool.getSizeTotal() / BYTESCONVERTER);
pool.setFreeCapacity(netAppPool.getSizeAvailable() / BYTESCONVERTER);
pool.setSubscribedCapacity(netAppPool.getSizeUsed() / BYTESCONVERTER);
if (ImplicitPoolMatcher.checkPoolPropertiesChanged(pool.getCompatibilityStatus(), DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name()) || ImplicitPoolMatcher.checkPoolPropertiesChanged(pool.getDiscoveryStatus(), DiscoveryStatus.VISIBLE.name())) {
poolsToMatchWithVpool.add(pool);
}
pool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
pool.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
}
} catch (NumberFormatException e) {
_logger.error("Data Format Exception: Discovery of storage pools failed for storage system {} for {}", system.getId(), e);
NetAppCException ntpe = new NetAppCException("Storage pool discovery data error for storage system " + system.getId());
ntpe.initCause(e);
throw ntpe;
}
_logger.info("Storage pool discovery for storage system {} complete", system.getId());
storagePools.put(NEW, newPools);
storagePools.put(EXISTING, existingPools);
return storagePools;
}
use of com.emc.storageos.netappc.NetAppClusterApi in project coprhd-controller by CoprHD.
the class NetAppClusterModeCommIntf method discoverUmanagedFileSystems.
private void discoverUmanagedFileSystems(AccessProfile profile) {
URI storageSystemId = profile.getSystemId();
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
if (null == storageSystem) {
return;
}
String detailedStatusMessage = "Discovery of NetApp Cluster Mode Unmanaged FileSystem started";
List<UnManagedFileSystem> unManagedFileSystems = new ArrayList<UnManagedFileSystem>();
List<UnManagedFileSystem> existingUnManagedFileSystems = new ArrayList<UnManagedFileSystem>();
int newFileSystemsCount = 0;
int existingFileSystemsCount = 0;
Set<URI> allDiscoveredUnManagedFileSystems = new HashSet<URI>();
NetAppClusterApi netAppCApi = new NetAppClusterApi.Builder(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword()).https(true).build();
Collection<String> attrs = new ArrayList<String>();
for (String property : ntpPropertiesList) {
attrs.add(SupportedNtpFileSystemInformation.getFileSystemInformation(property));
}
try {
StoragePort storagePort = getStoragePortPool(storageSystem);
URIQueryResultList storagePoolURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePoolConstraint(storageSystem.getId()), storagePoolURIs);
HashMap<String, StoragePool> pools = new HashMap();
Iterator<URI> poolsItr = storagePoolURIs.iterator();
while (poolsItr.hasNext()) {
URI storagePoolURI = poolsItr.next();
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolURI);
pools.put(storagePool.getNativeGuid(), storagePool);
}
// Retrieve all the file system and SVM info.
List<Map<String, String>> fileSystemInfo = netAppCApi.listVolumeInfo(null, attrs);
List<StorageVirtualMachineInfo> svms = netAppCApi.listSVM();
for (Map<String, String> fileSystemChar : fileSystemInfo) {
String poolName = fileSystemChar.get(SupportedNtpFileSystemInformation.getFileSystemInformation(SupportedNtpFileSystemInformation.STORAGE_POOL.toString()));
String filesystem = fileSystemChar.get(SupportedNtpFileSystemInformation.getFileSystemInformation(SupportedNtpFileSystemInformation.NAME.toString()));
boolean isSVMRootVolume = Boolean.valueOf(fileSystemChar.get(SupportedNtpFileSystemInformation.getFileSystemInformation(SupportedNtpFileSystemInformation.IS_SVM_ROOT.toString())));
boolean isNodeRootVolume = Boolean.valueOf(fileSystemChar.get(SupportedNtpFileSystemInformation.getFileSystemInformation(SupportedNtpFileSystemInformation.IS_NODE_ROOT.toString())));
String path = fileSystemChar.get(SupportedNtpFileSystemInformation.getFileSystemInformation(SupportedNtpFileSystemInformation.PATH.toString()));
String state = fileSystemChar.get(SupportedNtpFileSystemInformation.getFileSystemInformation(SupportedNtpFileSystemInformation.STATE.toString()));
String poolNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, poolName, NativeGUIDGenerator.POOL);
StoragePool pool = pools.get(poolNativeGuid);
String nativeId;
if ("".equals(filesystem)) {
continue;
}
if (filesystem.startsWith(VOL_ROOT)) {
nativeId = filesystem;
} else {
nativeId = VOL_ROOT + filesystem;
}
String fsNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem.getSystemType(), storageSystem.getSerialNumber(), nativeId);
// Ignore export for root volume and don't pull it into ViPR db.
if (isNodeRootVolume || isSVMRootVolume) {
_logger.info("Ignore and not discover root" + filesystem + "on NTP array");
continue;
}
// Ignore volume that is offline and don't pull it into ViPR db.
if (state.equalsIgnoreCase(VOLUME_STATE_OFFLINE)) {
_logger.info("Ignoring volume " + filesystem + " as it is offline");
continue;
}
// to create an UnManaged Filesystems.
if (checkStorageFileSystemExistsInDB(fsNativeGuid)) {
continue;
}
_logger.debug("retrieve info for file system: " + filesystem);
String svm = getOwningSVM(filesystem, fileSystemInfo);
String address = getSVMAddress(svm, svms);
if (svm != null && !svm.isEmpty()) {
// Need to use storage port for SVM.
String portNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, address, NativeGUIDGenerator.PORT);
storagePort = getSVMStoragePort(storageSystem, portNativeGuid, svm);
}
String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), nativeId);
UnManagedFileSystem unManagedFs = checkUnManagedFileSystemExistsInDB(fsUnManagedFsNativeGuid);
boolean alreadyExist = unManagedFs == null ? false : true;
unManagedFs = createUnManagedFileSystem(unManagedFs, profile, fsUnManagedFsNativeGuid, nativeId, storageSystem, pool, filesystem, storagePort, fileSystemChar);
if (alreadyExist) {
existingUnManagedFileSystems.add(unManagedFs);
existingFileSystemsCount++;
} else {
unManagedFileSystems.add(unManagedFs);
newFileSystemsCount++;
}
allDiscoveredUnManagedFileSystems.add(unManagedFs.getId());
/**
* Persist 200 objects and clear them to avoid memory issue
*/
validateListSizeLimitAndPersist(unManagedFileSystems, existingUnManagedFileSystems, Constants.DEFAULT_PARTITION_SIZE * 2);
}
// Process those active unmanaged fs objects available in database but not in newly discovered items, to
// mark them inactive.
markUnManagedFSObjectsInActive(storageSystem, allDiscoveredUnManagedFileSystems);
_logger.info("New unmanaged NetappC file systems count: {}", newFileSystemsCount);
_logger.info("Update unmanaged NetappC file systems count: {}", existingFileSystemsCount);
if (!unManagedFileSystems.isEmpty()) {
// Add UnManagedFileSystem
_partitionManager.insertInBatches(unManagedFileSystems, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILESYSTEM);
}
if (!existingUnManagedFileSystems.isEmpty()) {
// Update UnManagedFilesystem
_partitionManager.updateAndReIndexInBatches(existingUnManagedFileSystems, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILESYSTEM);
}
// discovery succeeds
detailedStatusMessage = String.format("Discovery completed successfully for NetAppC: %s", storageSystemId.toString());
} catch (NetAppCException ve) {
if (null != storageSystem) {
cleanupDiscovery(storageSystem);
}
_logger.error("discoverStorage failed. Storage system: " + storageSystemId);
throw ve;
} catch (Exception e) {
if (null != storageSystem) {
cleanupDiscovery(storageSystem);
}
_logger.error("discoverStorage failed. Storage system: " + storageSystemId, e);
throw NetAppCException.exceptions.discoveryFailed(storageSystemId.toString(), e);
} finally {
if (storageSystem != null) {
try {
// set detailed message
storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
_dbClient.persistObject(storageSystem);
} catch (Exception ex) {
_logger.error("Error while persisting object to DB", ex);
}
}
}
}
use of com.emc.storageos.netappc.NetAppClusterApi in project coprhd-controller by CoprHD.
the class NetAppClusterModeCommIntf method discoverUmanagedFileQuotaDirectory.
private void discoverUmanagedFileQuotaDirectory(AccessProfile profile) {
URI storageSystemId = profile.getSystemId();
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
if (null == storageSystem) {
return;
}
NetAppClusterApi netAppCApi = new NetAppClusterApi.Builder(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword()).https(true).build();
try {
// Retrieve all the qtree info.
List<Qtree> qtrees = netAppCApi.listQtrees();
List<Quota> quotas;
try {
// Currently there are no API's available to check the quota status in general
// TODO check weather quota is on before doing this call
quotas = netAppCApi.listQuotas();
} catch (Exception e) {
_logger.error("Error while fetching quotas", e.getMessage());
return;
}
if (quotas != null) {
Map<String, Qtree> qTreeNameQTreeMap = new HashMap<>();
qtrees.forEach(qtree -> {
if (qtree.getQtree() != null && !qtree.getQtree().equals("")) {
qTreeNameQTreeMap.put(qtree.getVolume() + qtree.getQtree(), qtree);
}
});
List<UnManagedFileQuotaDirectory> unManagedFileQuotaDirectories = new ArrayList<>();
List<UnManagedFileQuotaDirectory> existingUnManagedFileQuotaDirectories = new ArrayList<>();
String tempVolume = null;
String tempQuotaTree = null;
String tempQuotaTarget = null;
for (Quota quota : quotas) {
/* Temporary fix TODO
* Fix for situations where QuotaTree is null
* Extracting QuotaTree id from quotaTarget.
*/
if ("".equals(quota.getQtree())) {
tempQuotaTarget = quota.getQuotaTarget();
tempVolume = quota.getVolume();
if (!"".equals(tempVolume)) {
Pattern pattern = Pattern.compile(tempVolume + "/(.*$)");
Matcher matcher = pattern.matcher(tempQuotaTarget);
if (matcher.find()) {
tempQuotaTree = matcher.group(1);
}
if ("".equals(tempQuotaTree)) {
continue;
}
quota.setQtree(tempQuotaTree);
} else {
continue;
}
}
String fsNativeId;
if (quota.getVolume().startsWith(VOL_ROOT)) {
fsNativeId = quota.getVolume();
} else {
fsNativeId = VOL_ROOT + quota.getVolume();
}
if (fsNativeId.contains(ROOT_VOL)) {
_logger.info("Ignore and not discover root filesystem on NTP array");
continue;
}
String fsNativeGUID = NativeGUIDGenerator.generateNativeGuid(storageSystem.getSystemType(), storageSystem.getSerialNumber(), fsNativeId);
String nativeGUID = NativeGUIDGenerator.generateNativeGuidForQuotaDir(storageSystem.getSystemType(), storageSystem.getSerialNumber(), quota.getQtree(), quota.getVolume());
String nativeUnmanagedGUID = NativeGUIDGenerator.generateNativeGuidForUnManagedQuotaDir(storageSystem.getSystemType(), storageSystem.getSerialNumber(), quota.getQtree(), quota.getVolume());
if (checkStorageQuotaDirectoryExistsInDB(nativeGUID)) {
continue;
}
UnManagedFileQuotaDirectory unManagedFileQuotaDirectory = new UnManagedFileQuotaDirectory();
unManagedFileQuotaDirectory.setId(URIUtil.createId(UnManagedFileQuotaDirectory.class));
unManagedFileQuotaDirectory.setLabel(quota.getQtree());
unManagedFileQuotaDirectory.setNativeGuid(nativeUnmanagedGUID);
unManagedFileQuotaDirectory.setParentFSNativeGuid(fsNativeGUID);
unManagedFileQuotaDirectory.setNativeId("/vol/" + quota.getVolume() + "/" + quota.getQtree());
if ("enabled".equals(qTreeNameQTreeMap.get(quota.getVolume() + quota.getQtree()).getOplocks())) {
unManagedFileQuotaDirectory.setOpLock(true);
}
unManagedFileQuotaDirectory.setSize(Long.valueOf(quota.getDiskLimit()));
if (!checkUnManagedQuotaDirectoryExistsInDB(nativeUnmanagedGUID)) {
unManagedFileQuotaDirectories.add(unManagedFileQuotaDirectory);
} else {
existingUnManagedFileQuotaDirectories.add(unManagedFileQuotaDirectory);
}
}
if (!unManagedFileQuotaDirectories.isEmpty()) {
_partitionManager.insertInBatches(unManagedFileQuotaDirectories, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILEQUOTADIR);
}
if (!existingUnManagedFileQuotaDirectories.isEmpty()) {
_partitionManager.updateAndReIndexInBatches(existingUnManagedFileQuotaDirectories, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILEQUOTADIR);
}
}
} catch (NetAppException ve) {
if (null != storageSystem) {
cleanupDiscovery(storageSystem);
}
_logger.error("discoverStorage failed. Storage system: " + storageSystemId);
throw ve;
} catch (Exception e) {
if (null != storageSystem) {
cleanupDiscovery(storageSystem);
}
_logger.error("discoverStorage failed. Storage system: " + storageSystemId, e);
throw NetAppException.exceptions.discoveryFailed(storageSystemId.toString(), e);
}
}
use of com.emc.storageos.netappc.NetAppClusterApi in project coprhd-controller by CoprHD.
the class NetAppClusterModeCommIntf method discoverFilerInfo.
/**
* Discover the Control Station for the specified NTAP File storage array.
* Since the StorageSystem object currently exists, this method updates
* information in the object.
*
* @param system
* @throws NetAppCException
*/
private void discoverFilerInfo(StorageSystem system) throws NetAppCException {
_logger.info("Start Control Station discovery for storage system {}", system.getId());
Map<String, String> systemInfo = new HashMap<String, String>();
Map<String, String> systemVer = new HashMap<String, String>();
NetAppClusterApi ncApi = new NetAppClusterApi.Builder(system.getIpAddress(), system.getPortNumber(), system.getUsername(), system.getPassword()).https(true).build();
try {
systemInfo = ncApi.clusterSystemInfo();
systemVer = ncApi.systemVer();
if ((null == systemInfo) || (systemInfo.size() <= 0)) {
_logger.error("Failed to retrieve NetAppC Filer info!");
system.setReachableStatus(false);
return;
}
if ((null == systemVer) || (systemVer.size() <= 0)) {
_logger.error("Failed to retrieve NetAppC Filer info!");
system.setReachableStatus(false);
return;
}
system.setReachableStatus(true);
system.setSerialNumber(systemInfo.get(SYSTEM_SERIAL_NUM));
String sysNativeGuid = NativeGUIDGenerator.generateNativeGuid(system);
system.setNativeGuid(sysNativeGuid);
system.setFirmwareVersion(systemVer.get(SYSTEM_FIRMWARE_REL));
_logger.info("NetAppC Filer discovery for storage system {} complete", system.getId());
} catch (Exception e) {
_logger.error("Failed to retrieve NetAppC Filer info!");
system.setReachableStatus(false);
String msg = "exception occurred while attempting to retrieve NetAppC filer information. Storage system: " + system.getIpAddress() + " " + e.getMessage();
_logger.error(msg);
throw new NetAppCException(msg);
}
}
Aggregations