use of com.emc.storageos.netapp.NetAppException in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method deleteExportRules.
@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
List<ExportRule> allExports = args.getExistingDBExportRules();
String subDir = args.getSubDirectory();
boolean allDirs = args.isAllDir();
FileShare fs = args.getFs();
String exportPath;
String subDirExportPath = "";
subDir = args.getSubDirectory();
if (!args.getFileOperation()) {
exportPath = args.getSnapshotPath();
if (subDir != null && subDir.length() > 0) {
subDirExportPath = args.getSnapshotPath() + "/" + subDir;
}
} else {
exportPath = args.getFs().getPath();
if (subDir != null && subDir.length() > 0) {
subDirExportPath = args.getFs().getPath() + "/" + subDir;
}
}
_log.info("exportPath : {}", exportPath);
args.setExportPath(exportPath);
_log.info("Number of existing exports found {}", allExports.size());
try {
if (allDirs) {
Set<String> allPaths = new HashSet<String>();
// ALL EXPORTS
_log.info("Deleting all exports specific to filesystem at device and rules from DB including sub dirs rules and exports");
for (ExportRule rule : allExports) {
allPaths.add(rule.getExportPath());
}
for (String path : allPaths) {
_log.info("deleting export path : {} ", path);
nApi.deleteNFSExport(path);
}
} else if (subDir != null && !subDir.isEmpty()) {
// Filter for a specific Sub Directory export
_log.info("Deleting all subdir exports rules at ViPR and sub directory export at device {}", subDir);
for (ExportRule rule : allExports) {
if (rule.getExportPath().endsWith("/" + subDir)) {
nApi.deleteNFSExport(subDirExportPath);
break;
}
}
} else {
// Filter for No SUBDIR - main export rules with no sub dirs
_log.info("Deleting all export rules from DB and export at device not included sub dirs");
nApi.deleteNFSExport(exportPath);
}
} catch (NetAppException e) {
_log.info("Exception:" + e.getMessage());
throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
}
_log.info("NetAppFileStorageDevice exportFS {} - complete", args.getFsId());
result.setCommandSuccess(true);
result.setCommandStatus(Operation.Status.ready.name());
return result;
}
use of com.emc.storageos.netapp.NetAppException in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method doShare.
/**
* Creates FileShare CIFS/SMB shares
*
* @param StorageSystem storage
* @param SMBFileShare smbFileShare
* @return BiosCommandResult
* @throws ControllerException
*/
@Override
public BiosCommandResult doShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
// To be in-sync with isilon implementation, currently forceGroup is
// set to null which will set the group name as "everyone" by default.
String forceGroup = null;
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppFileStorageDevice doShare - start");
SMBShareMap smbShareMap = args.getFileObjShares();
SMBFileShare existingShare = (smbShareMap == null) ? null : smbShareMap.get(smbFileShare.getName());
Boolean modOrCreateShareSuccess;
if (existingShare != null) {
modOrCreateShareSuccess = modifyNtpShare(storage, args, smbFileShare, forceGroup, existingShare);
} else {
modOrCreateShareSuccess = createNtpShare(storage, args, smbFileShare, forceGroup);
}
if (modOrCreateShareSuccess.booleanValue() == true) {
_log.info("NetAppFileStorageDevice doShare {} - complete", smbFileShare.getName());
// Update the collection.
if (args.getFileObjShares() == null) {
args.initFileObjShares();
}
// set Mount Point
smbFileShare.setMountPoint(smbFileShare.getNetBIOSName(), smbFileShare.getStoragePortNetworkId(), smbFileShare.getStoragePortName(), smbFileShare.getName());
args.getFileObjShares().put(smbFileShare.getName(), smbFileShare);
result = BiosCommandResult.createSuccessfulResult();
} else {
_log.error("NetAppFileStorageDevice doShare {} - failed", smbFileShare.getName());
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateFileShare();
result = BiosCommandResult.createErrorResult(serviceError);
}
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doShare failed with a NetAppException", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateFileShare();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doShare failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateFileShare();
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 doSnapshotFS.
@Override
public BiosCommandResult doSnapshotFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppFileStorageDevice doSnapshotFS - start");
if (null == args.getFsName()) {
_log.error("NetAppFileStorageDevice::doSnapshotFS failed: Filesystem name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
if (null == args.getSnapshotName()) {
_log.error("NetAppFileStorageDevice::doSnapshotFS failed: Snapshot name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
serviceError.setMessage(FileSystemConstants.FS_ERR_SNAPSHOT_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
boolean failedStatus = false;
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
if (!nApi.createSnapshot(args.getFsName(), args.getSnapshotName())) {
failedStatus = true;
}
if (failedStatus == true) {
_log.error("NetAppFileStorageDevice doSnapshotFS {} - failed", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
serviceError.setMessage(genDetailedMessage("doSnapshotFS", args.getFsName()));
result = BiosCommandResult.createErrorResult(serviceError);
} else {
_log.info("doSnapshotFS - Snapshot, {} was successfully created for filesystem, {} ", args.getSnapshotName(), args.getFsName());
// Set snapshot Path and MountPath information
args.setSnapshotMountPath(getSnapshotMountPath(args.getFsMountPath(), args.getSnapshotName()));
args.setSnapshotPath(getSnapshotPath(args.getFsPath(), args.getSnapshotName()));
args.setSnapNativeId(args.getSnapshotName());
result = BiosCommandResult.createSuccessfulResult();
}
} catch (NetAppException e) {
_log.error("NetAppFileStorageDevice::doSnapshotFS failed with a NetAppException", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppFileStorageDevice::doSnapshotFS failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netapp.unableToCreateSnapshot();
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 getFSSnapshotList.
// Get FS snapshot list from the array.
@Override
public BiosCommandResult getFSSnapshotList(StorageSystem storage, FileDeviceInputOutput args, List<String> dbSnapshots) throws ControllerException {
if (null == args.getFsName()) {
throw new DeviceControllerException("Filesystem name is either missing or empty", new Object[] {});
}
_log.info("NetAppFileStorageDevice getFSSnapshotList: {} - start", args.getFsName());
BiosCommandResult result = new BiosCommandResult();
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
try {
List<String> deviceSnapshots = nApi.listSnapshots(args.getFsName());
if (deviceSnapshots == null) {
_log.warn("NetAppFileStorageDevice getFSSnapshotList {} - failed", args.getFsId());
result.setCommandSuccess(false);
result.setMessage("NetAppFileStorageDevice getFSSnapshotList failed for FS {}" + args.getFsName());
result.setCommandStatus(Operation.Status.error.name());
} else {
for (String deviceSnapshotName : deviceSnapshots) {
dbSnapshots.add(deviceSnapshotName);
}
_log.info("NetAppFileStorageDevice getFSSnapshotList - successful for filesystem, {} ", args.getFsName());
result.setCommandSuccess(true);
result.setCommandStatus(Operation.Status.ready.name());
result.setMessage("List of snapshots for FS " + args.getFsName() + " was successfully retreived from device ");
}
} catch (NetAppException e) {
String[] params = { storage.getId().toString(), args.getFsName() };
throw new DeviceControllerException("Failed to retrieve list of snapshots from device {1} for filesystem {2}", params);
}
return result;
}
use of com.emc.storageos.netapp.NetAppException in project coprhd-controller by CoprHD.
the class NetAppFileStorageDevice method updateExportRules.
@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
// Requested Export Rules
List<ExportRule> exportAdd = args.getExportRulesToAdd();
List<ExportRule> exportDelete = args.getExportRulesToDelete();
List<ExportRule> exportModify = args.getExportRulesToModify();
// To be processed export rules
List<ExportRule> exportsToRemove = new ArrayList<>();
List<ExportRule> exportsToAdd = new ArrayList<>();
String exportPath;
String subDir = args.getSubDirectory();
if (!args.getFileOperation()) {
exportPath = args.getSnapshotPath();
if (subDir != null && subDir.length() > 0) {
exportPath = args.getSnapshotPath() + "/" + subDir;
}
} else {
exportPath = args.getFs().getPath();
if (subDir != null && subDir.length() > 0) {
exportPath = args.getFs().getPath() + "/" + subDir;
}
}
_log.info("exportPath : {}", exportPath);
args.setExportPath(exportPath);
// ALL EXPORTS
List<ExportRule> existingDBExportRule = args.getExistingDBExportRules();
List<ExportRule> exportsToprocess = new ArrayList<>();
for (ExportRule rule : existingDBExportRule) {
if (rule.getExportPath().equalsIgnoreCase(exportPath)) {
exportsToprocess.add(rule);
}
}
_log.info("Number of existng Rules found {}", exportsToprocess.size());
// Handle Modified export Rules
if (exportsToprocess != null && !exportsToprocess.isEmpty()) {
for (ExportRule existingRule : exportsToprocess) {
for (ExportRule modifiedrule : exportModify) {
if (modifiedrule.getSecFlavor().equals(existingRule.getSecFlavor())) {
_log.info("Modifying Export Rule from {}, To {}", existingRule, modifiedrule);
// use a separate list to avoid concurrent modification exception for now.
exportsToRemove.add(existingRule);
exportsToAdd.add(modifiedrule);
}
}
}
// Handle Add export Rules
if (exportAdd != null && !exportAdd.isEmpty()) {
for (ExportRule newExport : exportAdd) {
_log.info("Adding Export Rule {}", newExport);
exportsToAdd.add(newExport);
}
}
// Handle Delete export Rules
if (exportDelete != null && !exportDelete.isEmpty()) {
for (ExportRule existingRule : exportsToprocess) {
for (ExportRule oldExport : exportDelete) {
if (oldExport.getSecFlavor().equals(existingRule.getSecFlavor())) {
_log.info("Deleting Export Rule {}", existingRule);
exportsToRemove.add(existingRule);
}
}
}
}
// No of exports found to remove from the list
_log.info("No of exports found to remove from the existing exports list {}", exportsToRemove.size());
exportsToprocess.removeAll(exportsToRemove);
_log.info("No of exports found to add to the existing exports list {}", exportsToAdd.size());
exportsToprocess.addAll(exportsToAdd);
if (exportsToprocess.isEmpty() && !exportsToRemove.isEmpty()) {
// If all exports rules deleted, export will get deleted too. So set back to its defaults
ExportRule rule = new ExportRule();
rule.setSecFlavor("sys");
rule.setAnon("root");
java.util.Set<String> roHosts = new HashSet<>();
roHosts.add("Default");
rule.setReadOnlyHosts(roHosts);
exportsToprocess.add(rule);
}
} else {
if (exportsToprocess == null) {
exportsToprocess = new ArrayList<>();
}
exportsToprocess.addAll(exportAdd);
exportsToprocess.addAll(exportModify);
}
// if only delete provided with no existing rules -- How do we handle this? [GOPI]
_log.info("Number of Export Rules to update after processing found {}", exportsToprocess.size());
BiosCommandResult result = new BiosCommandResult();
try {
String portGroup = null;
if (args.getFileOperation() == true) {
FileShare fileshare = args.getFs();
portGroup = findVfilerName(fileshare);
} else {
// Get the FS from the snapshot
URI snapshotUID = args.getSnapshotId();
Snapshot snapshot = _dbClient.queryObject(Snapshot.class, snapshotUID);
FileShare fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
portGroup = findVfilerName(fileshare);
}
NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
if (!nApi.modifyNFSShare(exportPath, exportsToprocess)) {
_log.error("NetAppFileStorageDevice updateFSExportRules {} - failed", args.getFsId());
result.setMessage("NetAppFileStorageDevice updateFSExportRules {} - failed");
result.setCommandStatus(Operation.Status.error.name());
return result;
}
if ((args.getFileOperation() == true) && args.getSubDirectory() == null) {
nApi.setQtreemode(exportPath, UNIX_QTREE_SETTING);
}
} catch (NetAppException e) {
_log.info("Exception:" + e.getMessage());
throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
}
_log.info("NetAppFileStorageDevice updateFSExportRules {} - complete", args.getFsId());
result.setCommandSuccess(true);
result.setCommandStatus(Operation.Status.ready.name());
return result;
}
Aggregations