use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileCommunicationInterface method discoverUnManagedNewExports.
private void discoverUnManagedNewExports(AccessProfile profile) {
URI storageSystemId = profile.getSystemId();
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
if (null == storageSystem) {
return;
}
storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.IN_PROGRESS.toString());
String detailedStatusMessage = "Discovery of NetApp Unmanaged Exports started";
// Used to Save the rules to DB
List<UnManagedFileExportRule> newUnManagedExportRules = new ArrayList<UnManagedFileExportRule>();
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 {
List<Map<String, String>> fileSystemInfo = netAppApi.listVolumeInfo(null, attrs);
List<VFilerInfo> vFilers = netAppApi.listVFilers(null);
// Get exports on the array and loop through each export.
List<ExportsRuleInfo> exports = netAppApi.listNFSExportRules(null);
// Verification Utility
UnManagedExportVerificationUtility validationUtility = new UnManagedExportVerificationUtility(_dbClient);
for (ExportsRuleInfo deviceExport : exports) {
String filesystem = deviceExport.getPathname();
_logger.info("Export Path {}", filesystem);
String nativeId = null;
if (!filesystem.startsWith(VOL_ROOT_NO_SLASH)) {
nativeId = VOL_ROOT_NO_SLASH + filesystem;
} else {
nativeId = filesystem;
}
// Ignore export for root volume and don't pull it into ViPR db.
if (filesystem.contains(ROOT_VOL)) {
_logger.info("Ignore exports for root volume {} on NTP array", filesystem);
continue;
}
// Ignore export for snapshots and don't pull it into ViPR db.
if (filesystem.contains(SNAPSHOT)) {
_logger.info("Ignore exports for snapshot {}", filesystem);
continue;
}
nativeId = getFSPathIfSubDirectoryExport(nativeId);
String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), nativeId);
UnManagedFileSystem unManagedFs = checkUnManagedFileSystemExistsInDB(fsUnManagedFsNativeGuid);
boolean fsAlreadyExists = unManagedFs == null ? false : true;
// Used as for rules validation
List<UnManagedFileExportRule> unManagedExportRules = new ArrayList<UnManagedFileExportRule>();
if (fsAlreadyExists) {
_logger.debug("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);
}
UnManagedFSExportMap tempUnManagedExpMap = new UnManagedFSExportMap();
// create the export map for FS
createExportMap(deviceExport, tempUnManagedExpMap, addr);
if (tempUnManagedExpMap.size() > 0) {
unManagedFs.setFsUnManagedExportMap(tempUnManagedExpMap);
_logger.debug("Export map for NetApp UMFS {} = {}", unManagedFs.getLabel(), unManagedFs.getFsUnManagedExportMap());
}
List<UnManagedFileExportRule> exportRules = applyAllSecurityRules(deviceExport, addr, unManagedFs.getId());
_logger.info("Number of export rules discovered for file system {} is {}", unManagedFs.getId(), exportRules.size());
for (UnManagedFileExportRule dbExportRule : exportRules) {
_logger.info("Un Managed File Export Rule : {}", dbExportRule);
String fsExportRulenativeId = dbExportRule.getFsExportIndex();
_logger.info("Native Id using to build Native Guid {}", fsExportRulenativeId);
String fsUnManagedFileExportRuleNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileExportRule(storageSystem, fsExportRulenativeId);
_logger.info("Native GUID {}", fsUnManagedFileExportRuleNativeGuid);
dbExportRule.setNativeGuid(fsUnManagedFileExportRuleNativeGuid);
// dbExportRule.setFileSystemId(unManagedFs.getId());
dbExportRule.setId(URIUtil.createId(UnManagedFileExportRule.class));
// Build all export rules list.
unManagedExportRules.add(dbExportRule);
}
// apply as per API SVC Validations.
if (!unManagedExportRules.isEmpty()) {
boolean isAllRulesValid = validationUtility.validateUnManagedExportRules(unManagedExportRules, false);
if (isAllRulesValid) {
_logger.info("Validating rules success for export {}", filesystem);
for (UnManagedFileExportRule exportRule : unManagedExportRules) {
UnManagedFileExportRule existingRule = checkUnManagedFsExportRuleExistsInDB(_dbClient, exportRule.getNativeGuid());
if (existingRule == null) {
newUnManagedExportRules.add(exportRule);
} else {
// Remove the existing rule.
existingRule.setInactive(true);
_dbClient.persistObject(existingRule);
newUnManagedExportRules.add(exportRule);
}
}
unManagedFs.setHasExports(true);
unManagedFs.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), TRUE);
_dbClient.persistObject(unManagedFs);
_logger.info("File System {} has Exports and their size is {}", unManagedFs.getId(), newUnManagedExportRules.size());
} else {
_logger.warn("Validating rules failed for export {}. Ignroing to import these rules into ViPR DB", filesystem);
unManagedFs.setInactive(true);
_dbClient.persistObject(unManagedFs);
}
}
// Adding this additional logic to avoid OOM
if (newUnManagedExportRules.size() == MAX_UMFS_RECORD_SIZE) {
_logger.info("Saving Number of UnManagedFileExportRule(s) {}", newUnManagedExportRules.size());
_partitionManager.updateInBatches(newUnManagedExportRules, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_EXPORT_RULE);
newUnManagedExportRules.clear();
}
} else {
_logger.info("FileSystem " + unManagedFs + "is not present in ViPR DB. Hence ignoring " + deviceExport + " export");
}
}
if (!newUnManagedExportRules.isEmpty()) {
_logger.info("Saving Number of UnManagedFileExportRule(s) {}", newUnManagedExportRules.size());
_partitionManager.updateInBatches(newUnManagedExportRules, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_EXPORT_RULE);
}
storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.toString());
// discovery succeeds
detailedStatusMessage = String.format("Discovery completed successfully for NetApp: %s", storageSystemId.toString());
} catch (NetAppException ve) {
if (null != storageSystem) {
cleanupDiscovery(storageSystem);
storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
}
_logger.error("discoverStorage failed. Storage system: " + storageSystemId);
} catch (Exception e) {
if (null != storageSystem) {
cleanupDiscovery(storageSystem);
storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
}
_logger.error("discoverStorage failed. Storage system: " + storageSystemId, 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 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 NetAppException
*/
private void discoverFilerInfo(StorageSystem system) throws NetAppFileCollectionException {
_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>();
NetAppApi nApi = new NetAppApi.Builder(system.getIpAddress(), system.getPortNumber(), system.getUsername(), system.getPassword()).https(true).build();
try {
systemInfo = nApi.systemInfo();
systemVer = nApi.systemVer();
if ((null == systemInfo) || (systemInfo.size() <= 0)) {
_logger.error("Failed to retrieve NetApp Filer info!");
system.setReachableStatus(false);
return;
}
if ((null == systemVer) || (systemVer.size() <= 0)) {
_logger.error("Failed to retrieve NetApp 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("NetApp Filer discovery for storage system {} complete", system.getId());
} catch (Exception e) {
_logger.error("Failed to retrieve NetApp Filer info!");
system.setReachableStatus(false);
String msg = "exception occurred while attempting to retrieve NetApp filer information. Storage system: " + system.getIpAddress() + " " + e.getMessage();
_logger.error(msg);
throw new NetAppFileCollectionException(msg);
}
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doCreateFS.
@Override
public BiosCommandResult doCreateFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppFileStorageDevice doCreateFS - start");
if (null == args.getFsName()) {
_log.error("NetAppFileStorageDevice::doCreateFS failed: Filesystem name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateFileSystem();
serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
if (null == args.getPoolNativeId()) {
_log.error("NetAppFileStorageDevice::doCreateFS failed: PoolNativeId either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateFileSystem();
serviceError.setMessage(FileSystemConstants.FS_ERR_POOL_NATIVE_ID_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
if (null == args.getFsCapacity()) {
_log.error("NetAppFileStorageDevice::doCreateFS failed: Filesystem capacity is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateFileSystem();
serviceError.setMessage(FileSystemConstants.FS_ERR_FS_CAPACITY_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
String nativeId;
if (args.getFsName().startsWith(VOL_ROOT)) {
nativeId = args.getFsName();
} else {
nativeId = VOL_ROOT + args.getFsName();
}
args.setFsNativeId(nativeId);
String fsNativeGuid = NativeGUIDGenerator.generateNativeGuid(storage.getSystemType(), storage.getSerialNumber(), nativeId);
args.setFsNativeGuid(fsNativeGuid);
String portGroup = findVfilerName(args.getFs());
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
Long fsSize = args.getFsCapacity() / BYTESPERMB;
String strFsSize = fsSize.toString() + "m";
if (!nApi.createFS(args.getFsName(), args.getPoolNativeId(), strFsSize, args.getThinProvision())) {
_log.error("NetAppFileStorageDevice doCreateFS {} - failed", args.getFsName());
BiosCommandResult rollbackResult = doDeleteFS(storage, args);
if (rollbackResult.isCommandSuccess()) {
_log.info("NetAppFileStorageDevice doCreateFS rollback completed failed for fs, {}", args.getFsName());
} else {
_log.error("NetAppFileStorageDevice doCreateFS rollback failed for fs, {} with {}.", args.getFsName(), rollbackResult.getMessage());
}
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateFileSystem();
result = BiosCommandResult.createErrorResult(serviceError);
} else {
_log.info("NetAppFileStorageDevice doCreateFS {} - complete", args.getFsName());
// Set FS path and Mount Path information
args.setFsPath(nativeId);
args.setFsMountPath(nativeId);
result = BiosCommandResult.createSuccessfulResult();
}
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doCreateFS failed with a NetAppException", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doCreateFS failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
return result;
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doUnexport.
@Override
public BiosCommandResult doUnexport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppFileStorageDevice doUnexport: {} - start", args.getFileObjId());
for (int expCount = 0; expCount < exportList.size(); expCount++) {
FileExport export = exportList.get(expCount);
String portGroup = findVfilerName(args.getFs());
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
if (export.getPermissions() == null) {
export.setPermissions("ro");
}
String mountPath = export.getMountPath();
String exportPath = export.getPath();
if (!nApi.unexportFS(exportPath, mountPath)) {
_log.error("NetAppFileStorageDevice::doUnexport {} failed", args.getFileObjId());
ServiceError serviceError = DeviceControllerErrors.netapp.unableToUnexportFileSystem();
serviceError.setMessage(genDetailedMessage("doUnexport", args.getFileObjId().toString()));
result = BiosCommandResult.createErrorResult(serviceError);
return result;
} else {
_log.info("NetAppFileStorageDevice doUnexport {} - completed", args.getFileObjId());
result = BiosCommandResult.createSuccessfulResult();
}
}
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doUnexport failed with a NetAppException", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToUnexportFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doUnexport failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToUnexportFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
_log.info("NetAppFileStorageDevice doUnexport {} - complete", args.getFileObjId());
return result;
}
use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doDeleteQuotaDirectory.
@Override
public BiosCommandResult doDeleteQuotaDirectory(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppFileStorageDevice doDeleteQuotaDirectory - start");
// Using NetApp terminology here
String volName = args.getFsName();
String qtreeName = args.getQuotaDirectoryName();
if (null == volName) {
_log.error("NetAppFileStorageDevice::doDeleteQuotaDirectory failed: Filesystem name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteQtree();
serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
if (null == qtreeName) {
_log.error("NetAppFileStorageDevice::doCreateQuotaDirectory failed: Qtree name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteQtree();
serviceError.setMessage(FileSystemConstants.FS_ERR_QUOTADIR_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
String portGroup = findVfilerName(args.getFs());
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
nApi.deleteQtree(qtreeName, volName, portGroup);
result = BiosCommandResult.createSuccessfulResult();
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doDeleteQuotaDirectory failed with a NetAppException", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteQtree();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doDeleteQuotaDirectory failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteQtree();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
return result;
}
Aggregations