use of com.emc.storageos.volumecontroller.impl.BiosCommandResult in project coprhd-controller by CoprHD.
the class NetAppClusterModeDevice method doExport.
@Override
public BiosCommandResult doExport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
_log.info("NetAppClusterModeDevice doExport - start");
// Verify inputs.
validateExportArgs(exportList);
List<String> rootHosts = new ArrayList<String>();
List<String> rwHosts = new ArrayList<String>();
List<String> roHosts = new ArrayList<String>();
BiosCommandResult result = new BiosCommandResult();
if (args.getFileObjExports() == null || args.getFileObjExports().isEmpty()) {
args.initFileObjExports();
}
FSExportMap existingExpMap = args.getFileObjExports();
List<FileExport> existingExportList = new ArrayList<FileExport>();
FileExport existingExport = null;
Iterator<String> it = existingExpMap.keySet().iterator();
while (it.hasNext()) {
existingExport = existingExpMap.get(it.next());
if (existingExport.getMountPath().equals(args.getFsMountPath())) {
_log.info("Existing export FileExport key : {} ", existingExport.getFileExportKey());
existingExportList.add(existingExport);
}
}
// If it's a sub-directory no need to take existing hosts.
boolean isSubDir = checkIfSubDirectory(args.getFsMountPath(), exportList.get(0).getMountPath());
if (isSubDir) {
existingExportList = null;
if (exportList.get(0).getMountPath().contains(SNAPSHOT)) {
_log.error("NetAppClusterModeDevice::doExport {} : Snapshot export is not Supported", args.getSnapshotId());
ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportSnapshot();
serviceError.setMessage(genDetailedMessage("doExport", args.getSnapshotId().toString(), "Snapshot export is not Supported"));
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
}
// TODO: Revisit once new Data Model for Exports is implemented.
Map<String, List<String>> existingHosts = null;
if ((null != existingExportList) && (!existingExportList.isEmpty())) {
existingHosts = sortHostsFromCurrentExports(existingExportList);
}
if (null != existingHosts) {
if ((null != existingHosts.get(ROOT_HOSTS)) && (!existingHosts.get(ROOT_HOSTS).isEmpty())) {
addNewHostsOnly(rootHosts, existingHosts.get(ROOT_HOSTS));
}
if ((null != existingHosts.get(RW_HOSTS)) && (!existingHosts.get(RW_HOSTS).isEmpty())) {
addNewHostsOnly(rwHosts, existingHosts.get(RW_HOSTS));
}
if ((null != existingHosts.get(RO_HOSTS)) && (!existingHosts.get(RO_HOSTS).isEmpty())) {
addNewHostsOnly(roHosts, existingHosts.get(RO_HOSTS));
}
}
try {
for (int expCount = 0; expCount < exportList.size(); expCount++) {
FileExport export = exportList.get(expCount);
FileExport fileExport = new FileExport(export.getClients(), export.getStoragePortName(), export.getMountPoint(), export.getSecurityType(), export.getPermissions(), export.getRootUserMapping(), export.getProtocol(), export.getStoragePort(), export.getPath(), export.getMountPath(), export.getSubDirectory(), export.getComments());
String portGroup = null;
FileShare fileshare = null;
if (args.getFileOperation() == true) {
fileshare = args.getFs();
portGroup = findSVMName(fileshare);
} else {
_log.error("NetAppClusterModeDevice::doExport {} : Snapshot export is not Supported", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportSnapshot();
serviceError.setMessage(genDetailedMessage("doExport", args.getSnapshotId().toString(), "Snapshot export is not Supported"));
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
List<String> endpointsList = export.getClients();
if (endpointsList == null) {
_log.error("NetAppClusterModeDevice::doExport {} failed: No endpoints specified", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
serviceError.setMessage(FileSystemConstants.FS_ERR_NO_ENDPOINTS_SPECIFIED);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
sortNewEndPoints(rootHosts, rwHosts, roHosts, endpointsList, export.getPermissions());
String root_user = export.getRootUserMapping();
String mountPath = export.getMountPath();
String exportPath = export.getPath();
String fsName = fileshare.getName();
String qtreeName = null;
if (isSubDir) {
if (ncApi.isQtree(fileshare.getName(), export.getSubDirectory())) {
qtreeName = export.getSubDirectory();
exportPath = constructQtreePath(fileshare.getName(), export.getSubDirectory());
} else {
_log.error("NetAppClusterModeDevice::doExport {} : Sub-directory export is not Supported", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
serviceError.setMessage(genDetailedMessage("doExport", args.getFsId().toString(), "Sub-directory export is not Supported"));
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
}
if (!ncApi.exportFS(fsName, qtreeName, exportPath, mountPath, rootHosts, rwHosts, roHosts, root_user, export.getSecurityType())) {
_log.error("NetAppClusterModeDevice::doExport {} failed", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
serviceError.setMessage(genDetailedMessage("doExport", args.getFsId().toString()));
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
args.getFileObjExports().put(fileExport.getFileExportKey(), fileExport);
result = BiosCommandResult.createSuccessfulResult();
}
} catch (NetAppCException e) {
_log.error("NetAppClusterModeDevice::doExport failed with a NetAppCException", e);
ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppClusterModeDevice::doExport failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
_log.info("NetAppClusterModeDevice::doExport {} - complete", args.getFsId());
return result;
}
use of com.emc.storageos.volumecontroller.impl.BiosCommandResult in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method getPhysicalInventory.
@Override
public BiosCommandResult getPhysicalInventory(StorageSystem storage) {
BiosCommandResult result = new BiosCommandResult();
result.setCommandSuccess(true);
return result;
}
use of com.emc.storageos.volumecontroller.impl.BiosCommandResult in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method doModifyFS.
@Override
public BiosCommandResult doModifyFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
result.setCommandSuccess(false);
result.setCommandStatus(Operation.Status.error.name());
result.setMessage("Modify FS NOT supported for VNX.");
return result;
}
use of com.emc.storageos.volumecontroller.impl.BiosCommandResult in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method doExpandFS.
@Override
public BiosCommandResult doExpandFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
_log.info("Call FileSystem Expand");
// For the request to succeed to expand, the system must be mounted.
// Below snippet helps to verify whether FS Mounted or not.
// Note : Since, Every Export will mount the FileSystem at first, we
// should do cross check as below whether file system is already mounted or not
// using FSExportMap and SMBShareMap
// If FileShare mounted then Mount is not required
boolean isMountRequired = !(args.isFileShareMounted());
_log.info("Mount required or not, to expand requested FileSystem {}", isMountRequired);
Long newFsExpandSize = args.getNewFSCapacity();
if (args.getNewFSCapacity() % BYTESPERMB == 0) {
newFsExpandSize = newFsExpandSize / BYTESPERMB;
} else {
newFsExpandSize = newFsExpandSize / BYTESPERMB + 1;
}
_log.info("FileSystem new size translation : {} : {}", args.getNewFSCapacity(), args.getFsCapacity());
XMLApiResult result = null;
ApplicationContext context = null;
try {
context = loadContext();
VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
if (null == vnxComm) {
throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
}
result = vnxComm.expandFS(storage, args.getFs(), newFsExpandSize, isMountRequired, args.getThinProvision());
} catch (VNXException e) {
throw new DeviceControllerException(e);
} finally {
clearContext(context);
}
BiosCommandResult cmdResult = null;
if (result.isCommandSuccess()) {
cmdResult = BiosCommandResult.createSuccessfulResult();
} else {
cmdResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToExpandFileSystem(result.getMessage()));
}
return cmdResult;
}
use of com.emc.storageos.volumecontroller.impl.BiosCommandResult in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method updateExportRules.
@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
XMLApiResult result = null;
ApplicationContext context = null;
// 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);
try {
// add the new export rule from the array into the update request.
Map<String, ExportRule> arrayExportRuleMap = extraExportRuleFromArray(storage, args);
if (!arrayExportRuleMap.isEmpty()) {
if (exportModify != null) {
// merge the end point for which sec flavor is common.
for (ExportRule exportRule : exportModify) {
ExportRule arrayExportRule = arrayExportRuleMap.remove(exportRule.getSecFlavor());
if (arrayExportRule != null) {
if (exportRule.getReadOnlyHosts() != null) {
exportRule.getReadOnlyHosts().addAll(arrayExportRule.getReadOnlyHosts());
} else {
exportRule.setReadOnlyHosts(arrayExportRule.getReadOnlyHosts());
}
if (exportRule.getReadWriteHosts() != null) {
exportRule.getReadWriteHosts().addAll(arrayExportRule.getReadWriteHosts());
} else {
exportRule.setReadWriteHosts(arrayExportRule.getReadWriteHosts());
}
if (exportRule.getRootHosts() != null) {
exportRule.getRootHosts().addAll(arrayExportRule.getRootHosts());
} else {
exportRule.setRootHosts(arrayExportRule.getRootHosts());
}
}
}
// now add the remaining export rule
exportModify.addAll(arrayExportRuleMap.values());
} else {
// if exportModify is null then create a new export rule and add
exportModify = new ArrayList<ExportRule>();
exportModify.addAll(arrayExportRuleMap.values());
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
_log.error("Not able to fetch latest Export rule from backend array.", e);
}
// 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());
// If there are no Export rules and add is allowed
if (!exportsToprocess.isEmpty() || (exportAdd != null && !exportAdd.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 modifications 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);
// Figure out mounted or not
SMBShareMap shares = args.getFs().getSMBFileShares();
boolean isMounted = true;
if (exportsToprocess.isEmpty() && (shares == null || (shares != null && shares.isEmpty()))) {
isMounted = false;
}
// Mounting is only necessary for FileSystem and not snapshot for the first time export
if (!args.getFileOperation()) {
isMounted = false;
}
// To be compatible with existing export creating an empty list
List<String> newPaths = new ArrayList<String>();
newPaths.add(exportPath);
try {
context = loadContext();
VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
if (null == vnxComm) {
throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
}
// Get DataMover Name and whether it is virtual
StorageHADomain dm = this.getDataMover(args.getFs());
if (dm == null) {
Exception e = new Exception("VNX File Export Failed Data Mover not found");
throw VNXException.exceptions.createExportFailed("VNX File Export Failed Data Mover not found", e);
}
List<VNXFileExport> exportList = new ArrayList<VNXFileExport>();
for (ExportRule rule : exportsToprocess) {
VNXFileExport vnxExp = null;
// update the comment
String comments = rule.getComments();
String protocol = "nfs";
if (rule.getReadOnlyHosts() != null && !rule.getReadOnlyHosts().isEmpty()) {
vnxExp = new VNXFileExport(new ArrayList<String>(rule.getReadOnlyHosts()), dm.getName(), exportPath, rule.getSecFlavor(), "ro", rule.getAnon(), protocol, args.getFs().getStoragePort().toString(), subDir, comments);
exportList.add(vnxExp);
}
if (rule.getReadWriteHosts() != null && !rule.getReadWriteHosts().isEmpty()) {
vnxExp = new VNXFileExport(new ArrayList<String>(rule.getReadWriteHosts()), dm.getName(), exportPath, rule.getSecFlavor(), "rw", rule.getAnon(), protocol, args.getFs().getStoragePort().toString(), subDir, comments);
exportList.add(vnxExp);
}
if (rule.getRootHosts() != null && !rule.getRootHosts().isEmpty()) {
vnxExp = new VNXFileExport(new ArrayList<String>(rule.getRootHosts()), dm.getName(), exportPath, rule.getSecFlavor(), "root", rule.getAnon(), protocol, args.getFs().getStoragePort().toString(), subDir, comments);
exportList.add(vnxExp);
}
}
// existing VNXComm API. This is required to read the subsequent information down the line.
if ((exportList != null && exportList.isEmpty()) && (exportsToRemove != null && !exportsToRemove.isEmpty())) {
_log.info("Requested to remove all export rules");
VNXFileExport vnxExp = new VNXFileExport(new ArrayList<String>(), dm.getName(), exportPath, "", "root", "", "", args.getFs().getStoragePort().toString(), subDir, "");
exportList.add(vnxExp);
}
// List<VNXFileExport> vnxExports = getVNXFileExports(newExpList);
if (args.getFileOperation()) {
// Perform FileSystem export
result = vnxComm.doExport(storage, dm, exportList, newPaths, args.getFileObj(), args.getFsNativeId(), isMounted);
} else {
// perform Snapshot export
result = vnxComm.doExport(storage, dm, exportList, newPaths, args.getFileObj(), args.getSnapNativeId(), isMounted);
}
if (result.isCommandSuccess()) {
_log.info("updateExportRules result.isCommandSuccess true");
}
} catch (VNXException e) {
throw VNXException.exceptions.createExportFailed("VNX File Export Failed", e);
} finally {
clearContext(context);
}
}
BiosCommandResult cmdResult = null;
if (result.isCommandSuccess()) {
cmdResult = BiosCommandResult.createSuccessfulResult();
} else {
cmdResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToUpdateExport(result.getMessage()));
}
return cmdResult;
}
Aggregations