use of com.emc.storageos.vnx.xmlapi.XMLApiResult 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.vnx.xmlapi.XMLApiResult 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;
}
use of com.emc.storageos.vnx.xmlapi.XMLApiResult in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method doUnexport.
@Override
public BiosCommandResult doUnexport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
_log.info("doUnExport " + args.getOperationType());
_log.info("Call FileShare UnExport");
XMLApiResult result = null;
ApplicationContext context = null;
try {
context = loadContext();
VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
if (null == vnxComm) {
throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
}
for (int expCount = 0; expCount < exportList.size(); expCount++) {
List<String> endPoints = new ArrayList<String>();
FileExport export = exportList.get(expCount);
String exportEntryKey = FileExport.exportLookupKey(export.getProtocol(), export.getSecurityType(), export.getPermissions(), export.getRootUserMapping(), export.getPath());
FileExport fileExport = args.getFileObjExports().get(exportEntryKey);
if (fileExport != null) {
endPoints.addAll(fileExport.getClients());
}
export.setClients(endPoints);
_log.info("FileExport:" + export.getClients() + ":" + export.getStoragePortName() + ":" + export.getStoragePort() + ":" + export.getRootUserMapping() + ":" + export.getPermissions() + ":" + export.getProtocol() + ":" + export.getSecurityType() + ":" + export.getMountPoint() + ":" + export.getPath());
}
List<VNXFileExport> vnxExps = getVNXFileExports(exportList);
result = vnxComm.doUnexport(storage, vnxExps.get(0), args, false);
} 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.unableToUnexportFileSystem(result.getMessage()));
}
return cmdResult;
}
use of com.emc.storageos.vnx.xmlapi.XMLApiResult in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method doDeleteQuotaDirectory.
@Override
public BiosCommandResult doDeleteQuotaDirectory(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
ApplicationContext context = null;
XMLApiResult apiResult = null;
try {
_log.info("VNXFileStorageDeviceXML doDeleteQuotaDirectory - start");
String fsName = args.getFsName();
String quotaTreetreeName = args.getQuotaDirectoryName();
QuotaDirectory quotaDir = args.getQuotaDirectory();
if (null == fsName) {
_log.error("VNXFileStorageDeviceXML::doDeleteQuotaDirectory failed: Filesystem name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.vnx.unableToDeleteQuotaDir();
serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
if (null == quotaTreetreeName) {
_log.error("VNXFileStorageDeviceXML::doDeleteQuotaDirectory failed: Quota Tree name is either missing or empty");
ServiceError serviceError = DeviceControllerErrors.vnx.unableToDeleteQuotaDir();
serviceError.setMessage(FileSystemConstants.FS_ERR_QUOTADIR_NAME_MISSING_OR_EMPTY);
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
_log.info("FSName: {}", args.getFsName());
_log.info("Quota tree name: {}", args.getQuotaDirectoryName());
boolean isMountRequired = !(args.isFileShareMounted());
_log.info("Mount required or not, to delete quota dir requested {}", isMountRequired);
// Load the context
context = loadContext();
VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
if (null == vnxComm) {
throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
}
// we can't delete quota, if the filsystem is not mount, We should changes quota cmd
apiResult = vnxComm.deleteQuotaDirectory(storage, args.getFsName(), quotaTreetreeName, true, isMountRequired);
if (apiResult.isCommandSuccess()) {
result = BiosCommandResult.createSuccessfulResult();
}
_log.info("doDeleteQuotaDirectory call result : {}", apiResult.isCommandSuccess());
} 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.unableToDeleteQuotaDir());
}
return cmdResult;
}
use of com.emc.storageos.vnx.xmlapi.XMLApiResult in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method doDeleteSnapshot.
@Override
public BiosCommandResult doDeleteSnapshot(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
// generate checkpoint baseline name
_log.info("FileShare, Snapshot {} {}", args.getFsUUID(), args.getSnapshotId());
_log.info("FSName: {}", args.getFsName());
_log.info("SnapShotName: {}", args.getSnapshotName());
_log.info("SnapShotBaseline: {}", args.getSnapshotCheckPointBaseline());
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.doDeleteSnapshot(storage, args.getSnapNativeId(), args.getSnapshotName(), true);
} 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.unableToDeleteFileSnapshot(result.getMessage()));
}
return cmdResult;
}
Aggregations