use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method netAppDeleteNFSExports.
private Boolean netAppDeleteNFSExports(StorageSystem storage, FSExportMap exportMap) throws NetAppException {
int failedCount = 0;
Iterator<Map.Entry<String, FileExport>> it = exportMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, FileExport> entry = it.next();
String key = entry.getKey();
FileExport fsExport = entry.getValue();
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
if (!nApi.deleteNFS(fsExport.getPath())) {
failedCount++;
} else {
exportMap.remove(key);
}
}
if (failedCount > 0) {
return false;
} else {
return true;
}
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileCommunicationInterface method discoverStoragePools.
private Map<String, List<StoragePool>> discoverStoragePools(StorageSystem system, List<StoragePool> poolsToMatchWithVpool) throws NetAppFileCollectionException, NetAppException {
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 {
NetAppApi netAppApi = new NetAppApi.Builder(system.getIpAddress(), system.getPortNumber(), system.getUsername(), system.getPassword()).https(true).build();
List<AggregateInfo> pools = netAppApi.listAggregates(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);
NetAppFileCollectionException ntpe = new NetAppFileCollectionException("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.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileCommunicationInterface method collectStatisticsInformation.
@Override
public void collectStatisticsInformation(AccessProfile accessProfile) throws BaseCollectionException {
URI storageSystemId = null;
String fsName = null;
try {
_logger.info("Metering for {} using ip {}", accessProfile.getSystemId(), accessProfile.getIpAddress());
String arrayIp = accessProfile.getIpAddress();
String arrayUser = accessProfile.getUserName();
String arrayPassword = accessProfile.getPassword();
int arrayPort = accessProfile.getPortNumber();
NetAppApi netAppApi = new NetAppApi.Builder(arrayIp, arrayPort, arrayUser, arrayPassword).https(true).build();
long latestSampleTime = accessProfile.getLastSampleTime();
storageSystemId = accessProfile.getSystemId();
StorageSystem NetAppArray = _dbClient.queryObject(StorageSystem.class, storageSystemId);
String serialNumber = NetAppArray.getSerialNumber();
String deviceType = NetAppArray.getSystemType();
initializeKeyMap(accessProfile);
List<Stat> stats = new ArrayList<Stat>();
ZeroRecordGenerator zeroRecordGenerator = new FileZeroRecordGenerator();
CassandraInsertion statsColumnInjector = new FileDBInsertion();
/* Get Stats from the NTAP array */
List<Map<String, String>> usageStats = new ArrayList<Map<String, String>>();
NetAppStatsRecorder recorder = new NetAppStatsRecorder(zeroRecordGenerator, statsColumnInjector);
_keyMap.put(Constants._TimeCollected, System.currentTimeMillis());
Map<String, Number> metrics = new ConcurrentHashMap<String, Number>();
List<URI> storageSystemIds = new ArrayList<URI>();
storageSystemIds.add(storageSystemId);
List<FileShare> fsObjs = _dbClient.queryObjectField(FileShare.class, Constants.STORAGE_DEVICE, storageSystemIds);
List<URI> fsUris = zeroRecordGenerator.extractVolumesOrFileSharesFromDB(storageSystemId, _dbClient, FileShare.class);
for (URI fsUri : fsUris) {
FileShare fsObj = _dbClient.queryObject(FileShare.class, fsUri);
if (fsObj.getInactive()) {
continue;
}
fsName = fsObj.getName();
String fsNativeGuid = NativeGUIDGenerator.generateNativeGuid(deviceType, serialNumber, fsObj.getPath());
try {
usageStats = netAppApi.listVolumeInfo(fsName, null);
for (Map<String, String> map : usageStats) {
/*
* TODO: usageStats usually contains a single element. If
* the list consists of multiple elements, all but one
* element will get overwritten.
*/
metrics.put(Constants.SIZE_TOTAL, 0);
if (map.get(Constants.SIZE_TOTAL) != null) {
metrics.put(Constants.SIZE_TOTAL, Long.valueOf(map.get(Constants.SIZE_TOTAL)));
}
metrics.put(Constants.SIZE_USED, 0);
if (map.get(Constants.SIZE_USED) != null) {
metrics.put(Constants.SIZE_USED, Long.valueOf(map.get(Constants.SIZE_USED)));
}
/*
* TODO: Bytes per block on NTAP is hard coded for now. If
* possible, we should to get this from the array.
*/
Long snapshotBytesReserved = 0L;
if (map.get(Constants.SNAPSHOT_BLOCKS_RESERVED) != null) {
snapshotBytesReserved = Long.valueOf(map.get(Constants.SNAPSHOT_BLOCKS_RESERVED)) * Constants.NETAPP_BYTES_PER_BLOCK;
}
metrics.put(Constants.SNAPSHOT_BYTES_RESERVED, snapshotBytesReserved);
Integer snapshotCount = _dbClient.countObjects(Snapshot.class, Constants.PARENT, fsObj.getId());
metrics.put(Constants.SNAPSHOT_COUNT, snapshotCount);
Stat stat = recorder.addUsageStat(fsNativeGuid, _keyMap, metrics);
if (stat != null) {
stats.add(stat);
// Persists the file system, only if change in used capacity.
if (fsObj.getUsedCapacity() != stat.getAllocatedCapacity()) {
fsObj.setUsedCapacity(stat.getAllocatedCapacity());
_dbClient.persistObject(fsObj);
}
}
}
} catch (NetAppException ne) {
String arg = fsName.toString() + ", " + accessProfile.getIpAddress().toString() + ", " + accessProfile.getSystemType().toString();
_logger.info("Failed to retrieve stats for FileShare, Syste, Type: {}", arg);
}
}
if (!stats.isEmpty()) {
zeroRecordGenerator.identifyRecordstobeZeroed(_keyMap, stats, FileShare.class);
persistStatsInDB(stats);
latestSampleTime = System.currentTimeMillis();
accessProfile.setLastSampleTime(latestSampleTime);
}
_logger.info("Done metering device {}", storageSystemId);
} catch (Exception e) {
String message = "collectStatisticsInformation failed. Storage system: " + storageSystemId;
_logger.error(message, e);
throw NetAppException.exceptions.collectStatsFailed(accessProfile.getIpAddress(), accessProfile.getSystemType(), message);
}
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileCommunicationInterface method discoverUnManagedCifsShares.
/**
* discover the unmanaged cifs shares and add shares to vipr db
*
* @param profile
*/
private void discoverUnManagedCifsShares(AccessProfile profile) {
URI systemId = profile.getSystemId();
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, systemId);
if (null == storageSystem) {
return;
}
String detailedStatusMessage = "Discovery of NetApp Unmanaged Cifs shares started";
NetAppApi netAppApi = new NetAppApi.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 {
// Used to Save the Acl to DB
List<UnManagedCifsShareACL> unManagedCifsShareACLList = new ArrayList<UnManagedCifsShareACL>();
List<UnManagedCifsShareACL> oldunManagedCifsShareACLList = new ArrayList<UnManagedCifsShareACL>();
List<Map<String, String>> fileSystemInfo = netAppApi.listVolumeInfo(null, attrs);
List<VFilerInfo> vFilers = netAppApi.listVFilers(null);
// Get All cifs shares and ACLs
List<Map<String, String>> listShares = netAppApi.listShares(null);
if (listShares != null && !listShares.isEmpty()) {
_logger.info("total no of shares in netapp system (s) {}", listShares.size());
}
HashSet<UnManagedSMBFileShare> unManagedSMBFileShareHashSet = null;
// prepare the unmanagedSmbshare
HashMap<String, HashSet<UnManagedSMBFileShare>> unMangedSMBFileShareMapSet = getAllCifsShares(listShares);
for (String key : unMangedSMBFileShareMapSet.keySet()) {
String filesystem = key;
unManagedSMBFileShareHashSet = unMangedSMBFileShareMapSet.get(key);
_logger.info("FileSystem Path {}", filesystem);
String nativeId = null;
if (!filesystem.startsWith(VOL_ROOT_NO_SLASH)) {
nativeId = VOL_ROOT_NO_SLASH + filesystem;
} else {
nativeId = filesystem;
}
// Ignore root volume and don't pull it into ViPR db.
if (filesystem.contains(ROOT_VOL)) {
_logger.info("Ignore and not discover root filesystem {} on NTP array", filesystem);
continue;
}
// Ignore snapshots and don't pull it into ViPR db.
if (filesystem.contains(SNAPSHOT)) {
_logger.info("Ignore exports for snapshot {}", filesystem);
continue;
}
String shareNativeId = getFSPathIfSubDirectoryExport(nativeId);
String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), shareNativeId);
UnManagedFileSystem unManagedFs = checkUnManagedFileSystemExistsInDB(fsUnManagedFsNativeGuid);
boolean fsAlreadyExists = unManagedFs == null ? false : true;
if (fsAlreadyExists) {
_logger.info("retrieve info for file system: " + filesystem);
String vFiler = getOwningVfiler(filesystem, fileSystemInfo);
if (vFiler != null && !vFiler.equalsIgnoreCase(DEFAULT_FILER)) {
_logger.info("Ignoring {} because it is owned by {}", filesystem, vFiler);
continue;
}
String addr = null;
if (vFiler == null || vFiler.isEmpty()) {
// No vfilers, use system storage port
StoragePort port = getStoragePortPool(storageSystem);
addr = port.getPortName();
} else {
// Use IP address of vFiler.
addr = getVfilerAddress(vFiler, vFilers);
}
UnManagedSMBShareMap tempUnManagedSMBShareMap = new UnManagedSMBShareMap();
// add smb shares to FS object
createShareMap(unManagedSMBFileShareHashSet, tempUnManagedSMBShareMap, addr, nativeId);
// add shares to fs object
if (!tempUnManagedSMBShareMap.isEmpty() && tempUnManagedSMBShareMap.size() > 0) {
unManagedFs.setUnManagedSmbShareMap(tempUnManagedSMBShareMap);
unManagedFs.setHasShares(true);
unManagedFs.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), TRUE);
_logger.debug("SMB Share map for NetApp UMFS {} = {}", unManagedFs.getLabel(), unManagedFs.getUnManagedSmbShareMap());
}
List<UnManagedCifsShareACL> tempUnManagedCifsShareAclList = getACLs(unManagedSMBFileShareHashSet, netAppApi, unManagedFs.getId());
// get the acl details for given fileshare
UnManagedCifsShareACL existingACL = null;
for (UnManagedCifsShareACL unManagedCifsShareACL : tempUnManagedCifsShareAclList) {
_logger.info("Unmanaged File share acls : {}", unManagedCifsShareACL);
String fsShareNativeId = unManagedCifsShareACL.getFileSystemShareACLIndex();
_logger.info("UMFS Share ACL index {}", fsShareNativeId);
String fsUnManagedFileShareNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileShare(storageSystem, fsShareNativeId);
_logger.info("Native GUID {}", fsUnManagedFileShareNativeGuid);
unManagedCifsShareACL.setNativeGuid(fsUnManagedFileShareNativeGuid);
// Check whether the CIFS share ACL was present in ViPR DB.
existingACL = checkUnManagedFsCifsACLExistsInDB(_dbClient, unManagedCifsShareACL.getNativeGuid());
if (existingACL == null) {
unManagedCifsShareACLList.add(unManagedCifsShareACL);
} else {
// delete the existing acl
existingACL.setInactive(true);
oldunManagedCifsShareACLList.add(existingACL);
// then add new acl
unManagedCifsShareACLList.add(unManagedCifsShareACL);
}
}
// save the object
{
_dbClient.persistObject(unManagedFs);
_logger.info("File System {} has Shares and their Count is {}", unManagedFs.getId(), tempUnManagedSMBShareMap.size());
}
// Adding this additional logic to avoid OOM
if (!unManagedCifsShareACLList.isEmpty() && unManagedCifsShareACLList.size() >= MAX_UMFS_RECORD_SIZE) {
_logger.info("Saving Number of New UnManagedCifsShareACL(s) {}", unManagedCifsShareACLList.size());
_dbClient.createObject(unManagedCifsShareACLList);
unManagedCifsShareACLList.clear();
}
if (!oldunManagedCifsShareACLList.isEmpty() && oldunManagedCifsShareACLList.size() >= MAX_UMFS_RECORD_SIZE) {
_logger.info("Update Number of Old UnManagedCifsShareACL(s) {}", oldunManagedCifsShareACLList.size());
_dbClient.persistObject(oldunManagedCifsShareACLList);
oldunManagedCifsShareACLList.clear();
}
} else {
_logger.info("FileSystem " + unManagedFs + "is not present in ViPR DB. Hence ignoring " + filesystem + " share");
}
}
//
if (!unManagedCifsShareACLList.isEmpty()) {
_logger.info("Saving Number of New UnManagedCifsShareACL(s) {}", unManagedCifsShareACLList.size());
_dbClient.createObject(unManagedCifsShareACLList);
}
if (!oldunManagedCifsShareACLList.isEmpty()) {
_logger.info("Saving Number of Old UnManagedCifsShareACL(s) {}", oldunManagedCifsShareACLList.size());
_dbClient.persistObject(oldunManagedCifsShareACLList);
}
storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.toString());
// discovery succeeds
detailedStatusMessage = String.format("Discovery completed successfully for NetApp: %s", systemId.toString());
} catch (NetAppException ve) {
if (null != storageSystem) {
cleanupDiscovery(storageSystem);
storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
}
_logger.error("discoverStorage failed. Storage system: " + systemId);
} catch (Exception e) {
if (null != storageSystem) {
cleanupDiscovery(storageSystem);
storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
}
_logger.error("discoverStorage failed. Storage system: " + systemId, 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.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileCommunicationInterface method discoverPortGroups.
private HashMap<String, List<StorageHADomain>> discoverPortGroups(StorageSystem system, List<VFilerInfo> virtualFilers) throws NetAppFileCollectionException {
HashMap<String, List<StorageHADomain>> portGroups = new HashMap<String, List<StorageHADomain>>();
List<StorageHADomain> newPortGroups = new ArrayList<StorageHADomain>();
List<StorageHADomain> existingPortGroups = new ArrayList<StorageHADomain>();
_logger.info("Start port group discovery (vfilers) for storage system {}", system.getId());
NetAppApi netAppApi = new NetAppApi.Builder(system.getIpAddress(), system.getPortNumber(), system.getUsername(), system.getPassword()).https(true).build();
StorageHADomain portGroup = null;
List<VFilerInfo> vFilers = netAppApi.listVFilers(null);
if (null == vFilers || vFilers.isEmpty()) {
// Check if default port group was previously created.
URIQueryResultList results = new URIQueryResultList();
String adapterNativeGuid = NativeGUIDGenerator.generateNativeGuid(system, DEFAULT_FILER, NativeGUIDGenerator.ADAPTER);
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStorageHADomainByNativeGuidConstraint(adapterNativeGuid), results);
if (results.iterator().hasNext()) {
StorageHADomain tmpGroup = _dbClient.queryObject(StorageHADomain.class, results.iterator().next());
if (tmpGroup.getStorageDeviceURI().equals(system.getId())) {
portGroup = tmpGroup;
_logger.debug("Found existing port group {} ", tmpGroup.getName());
}
}
if (portGroup == null) {
portGroup = new StorageHADomain();
portGroup.setId(URIUtil.createId(StorageHADomain.class));
portGroup.setName("NetApp");
portGroup.setVirtual(false);
portGroup.setNativeGuid(adapterNativeGuid);
portGroup.setStorageDeviceURI(system.getId());
StringSet protocols = new StringSet();
protocols.add(StorageProtocol.File.NFS.name());
protocols.add(StorageProtocol.File.CIFS.name());
portGroup.setFileSharingProtocols(protocols);
newPortGroups.add(portGroup);
} else {
existingPortGroups.add(portGroup);
}
} else {
_logger.debug("Number vFilers fouund: {}", vFilers.size());
virtualFilers.addAll(vFilers);
StringSet protocols = new StringSet();
protocols.add(StorageProtocol.File.NFS.name());
protocols.add(StorageProtocol.File.CIFS.name());
for (VFilerInfo vf : vFilers) {
_logger.debug("vFiler name: {}", vf.getName());
// Check if port group was previously discovered
URIQueryResultList results = new URIQueryResultList();
String adapterNativeGuid = NativeGUIDGenerator.generateNativeGuid(system, vf.getName(), NativeGUIDGenerator.ADAPTER);
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStorageHADomainByNativeGuidConstraint(adapterNativeGuid), results);
portGroup = null;
if (results.iterator().hasNext()) {
StorageHADomain tmpGroup = _dbClient.queryObject(StorageHADomain.class, results.iterator().next());
if (tmpGroup.getStorageDeviceURI().equals(system.getId())) {
portGroup = tmpGroup;
_logger.debug("Found duplicate {} ", vf.getName());
}
}
if (portGroup == null) {
portGroup = new StorageHADomain();
portGroup.setId(URIUtil.createId(StorageHADomain.class));
portGroup.setName(vf.getName());
portGroup.setVirtual(true);
portGroup.setAdapterType(StorageHADomain.HADomainType.VIRTUAL.toString());
portGroup.setNativeGuid(adapterNativeGuid);
portGroup.setStorageDeviceURI(system.getId());
portGroup.setFileSharingProtocols(protocols);
newPortGroups.add(portGroup);
} else {
existingPortGroups.add(portGroup);
}
}
}
portGroups.put(NEW, newPortGroups);
portGroups.put(EXISTING, existingPortGroups);
return portGroups;
}
Aggregations