use of com.emc.storageos.netapp.NetAppException in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doExpandFS.
@Override
public BiosCommandResult doExpandFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppFileStorageDevice doExpandFS - start");
long newFsExpandSize = args.getNewFSCapacity();
String volumeName = args.getFsName();
if (args.getNewFSCapacity() % BYTESPERMB == 0) {
newFsExpandSize = newFsExpandSize / BYTESPERMB;
} else {
newFsExpandSize = newFsExpandSize / BYTESPERMB + 1;
}
_log.info("FileSystem new size translation : {} : {}", args.getNewFSCapacity(), newFsExpandSize);
String strNewFsSize = String.valueOf(newFsExpandSize) + "m";
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
if (!nApi.setVolumeSize(volumeName, strNewFsSize)) {
_log.error("NetAppFileStorageDevice doExpandFS - failed");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToExpandFileSystem();
result = BiosCommandResult.createErrorResult(serviceError);
} else {
_log.info("NetAppFileStorageDevice doExpandFS - complete");
result = BiosCommandResult.createSuccessfulResult();
}
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doExpandFS failed with a NetAppException", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToExpandFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doExpandFS failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToExpandFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
return result;
}
use of com.emc.storageos.netapp.NetAppException in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doCheckFSExists.
/**
* Checking a file system: - Check if the FS exists on Array or not
*
* @param StorageSystem storage
* @param args FileDeviceInputOutput
* @return boolean true if exists else false
* @throws ControllerException
*/
@Override
public boolean doCheckFSExists(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
_log.info("checking file system existence on array: ", args.getFsName());
boolean isFSExists = true;
try {
String portGroup = findVfilerName(args.getFs());
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
List<String> fs = nApi.listFileSystems();
if (!fs.isEmpty() && fs.contains(args.getFsName())) {
isFSExists = true;
} else {
isFSExists = false;
}
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doCheckFSExists failed with an Exception", e);
}
return isFSExists;
}
use of com.emc.storageos.netapp.NetAppException 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.netapp.NetAppException 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.NetAppException 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);
}
}
}
}
Aggregations