use of com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter in project coprhd-controller by CoprHD.
the class VNXeStorageDevice method updateExportRules.
@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) {
// 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<>();
List<ExportRule> newExportsForDelete = new ArrayList<>();
VNXeFileTaskCompleter completer = null;
VNXeApiClient apiClient = getVnxeClient(storage);
String subDir = args.getSubDirectory();
// ALL EXPORTS
List<ExportRule> exportsToprocess = args.getExistingDBExportRules();
Map<String, ArrayList<ExportRule>> existingExportsMapped = new HashMap();
try {
String exportPath;
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;
}
}
_logger.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
_logger.error("Not able to fetch latest Export rule from backend array.", e);
}
if (exportsToprocess == null) {
exportsToprocess = new ArrayList<>();
}
_logger.info("Number of existng Rules found {}", exportsToprocess.size());
// Process Exports
for (ExportRule existingRule : exportsToprocess) {
ArrayList<ExportRule> exps = existingExportsMapped.get(existingRule.getExportPath());
if (exps == null) {
exps = new ArrayList<>();
}
exps.add(existingRule);
_logger.info("Checking existing export for {} : exps : {}", existingRule.getExportPath(), exps);
existingExportsMapped.put(existingRule.getExportPath(), exps);
}
// Handle Add export Rules
if (exportAdd != null && !exportAdd.isEmpty()) {
// Check for existing exports for the export path including subdirectory
ArrayList<ExportRule> exps = existingExportsMapped.get(exportPath);
if (exps != null && !exps.isEmpty()) {
_logger.error("Adding export rules is not supported as there can be only one export rule for VNXe.");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("updateExportRules", "Adding export rule is not supported for VNXe");
return BiosCommandResult.createErrorResult(error);
}
}
// Handle Modified export Rules
if (!exportsToprocess.isEmpty()) {
if (subDir != null && !subDir.isEmpty()) {
for (ExportRule existingRule : exportsToprocess) {
if (existingRule.getExportPath().endsWith("/" + subDir)) {
// Filter for a specific Sub Directory export
_logger.info("Updating all subdir exports rules at ViPR and sub directory export at device {}", subDir);
processModifyRules(exportModify, existingRule, exportsToRemove, exportsToAdd);
} else {
exportsToRemove.add(existingRule);
}
}
// Handle Delete export Rules
if (exportDelete != null && !exportDelete.isEmpty()) {
for (ExportRule existingRule : exportsToprocess) {
if (existingRule.getExportPath().endsWith("/" + subDir)) {
processDeleteRules(exportDelete, existingRule, exportsToRemove, newExportsForDelete);
} else {
exportsToRemove.add(existingRule);
}
}
exportsToAdd.addAll(newExportsForDelete);
}
} else {
for (ExportRule existingRule : exportsToprocess) {
if (existingRule.getExportPath().equalsIgnoreCase(exportPath)) {
processModifyRules(exportModify, existingRule, exportsToRemove, exportsToAdd);
} else {
exportsToRemove.add(existingRule);
}
}
// Handle Delete export Rules
if (exportDelete != null && !exportDelete.isEmpty()) {
for (ExportRule existingRule : exportsToprocess) {
if (existingRule.getExportPath().equalsIgnoreCase(exportPath)) {
processDeleteRules(exportDelete, existingRule, exportsToRemove, newExportsForDelete);
} else {
exportsToRemove.add(existingRule);
}
}
exportsToAdd.addAll(newExportsForDelete);
}
}
// No of exports found to remove from the list
_logger.info("No of exports found to remove from the existing exports list {}", exportsToRemove.size());
exportsToprocess.removeAll(exportsToRemove);
_logger.info("No of exports found to add to the existing exports list {}", exportsToAdd.size());
exportsToprocess.addAll(exportsToAdd);
} else {
// This is valid only if no rules to modify exists
if (exportAdd != null && !exportAdd.isEmpty()) {
for (ExportRule newExport : exportAdd) {
if (args.getFileObjExports() != null) {
Collection<FileExport> expList = args.getFileObjExports().values();
Iterator<FileExport> it = expList.iterator();
FileExport exp = null;
while (it.hasNext()) {
FileExport export = it.next();
if (export.getPath().equalsIgnoreCase(exportPath)) {
exp = export;
}
}
if (exp != null) {
if (exp.getIsilonId() != null) {
newExport.setDeviceExportId(exp.getIsilonId());
}
if (exp.getNativeId() != null) {
newExport.setDeviceExportId(exp.getNativeId());
}
}
}
_logger.info("Add Export Rule {}", newExport);
newExport.setExportPath(exportPath);
exportsToAdd.add(newExport);
}
}
exportsToprocess.addAll(exportsToAdd);
}
_logger.info("exportPath : {}", exportPath);
args.setExportPath(exportPath);
VNXeCommandJob job = null;
for (ExportRule rule : exportsToprocess) {
AccessEnum access = null;
List<String> roHosts = null;
List<String> rwHosts = null;
List<String> rootHosts = null;
String path = "/";
String subdirName = "";
String mountPathFs = args.getFsMountPath();
String shareName = null;
FileShareExport fsExport = null;
boolean isDeleteRule = false;
if (args.getFileObjExports() != null) {
Collection<FileExport> expList = args.getFileObjExports().values();
Iterator<FileExport> it = expList.iterator();
FileExport exp = null;
while (it.hasNext()) {
FileExport export = it.next();
if (export.getPath().equalsIgnoreCase(rule.getExportPath())) {
exp = export;
}
}
fsExport = new FileShareExport(exp);
}
String mountPathArg = rule.getExportPath();
if (rule.getReadWriteHosts() != null && !rule.getReadWriteHosts().isEmpty()) {
access = AccessEnum.READWRITE;
if (rwHosts == null) {
rwHosts = new ArrayList<String>();
}
rwHosts.addAll(rule.getReadWriteHosts());
}
if (rule.getReadOnlyHosts() != null && !rule.getReadOnlyHosts().isEmpty()) {
access = AccessEnum.READ;
if (roHosts == null) {
roHosts = new ArrayList<String>();
}
roHosts.addAll(rule.getReadOnlyHosts());
}
if (rule.getRootHosts() != null && !rule.getRootHosts().isEmpty()) {
access = AccessEnum.ROOT;
if (rootHosts == null) {
rootHosts = new ArrayList<String>();
}
rootHosts.addAll(rule.getRootHosts());
}
if (newExportsForDelete.contains(rule)) {
isDeleteRule = true;
}
if (args.getFileOperation()) {
if (!mountPathArg.equals(mountPathFs)) {
// subdirectory specified.
subdirName = mountPathArg.substring(mountPathFs.length() + 1);
path += subdirName;
}
if (isDeleteRule) {
job = apiClient.removeNfsShare(rule.getDeviceExportId(), args.getFs().getNativeId());
if (job != null) {
completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, args.getExportPath(), true);
ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
} else {
_logger.error("No job returned from unexport FileSystem");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("UnExportFileSystem", "No Job returned from UnExportFileSystem");
return BiosCommandResult.createErrorResult(error);
}
} else {
job = apiClient.exportFileSystem(args.getFs().getNativeId(), roHosts, rwHosts, rootHosts, access, path, null, rule.getDeviceExportId(), null);
if (job != null) {
completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
VNXeModifyExportJob modifyExportJob = new VNXeModifyExportJob(job.getId(), storage.getId(), completer, rule, fsExport, args.getExportPath(), args.getFileOperation(), isDeleteRule, shareName);
ControllerServiceImpl.enqueueJob(new QueueJob(modifyExportJob));
} else {
_logger.error("No job returned from updateExportRules");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("updateExportRules", "No Job returned from updateExportRules");
return BiosCommandResult.createErrorResult(error);
}
}
} else {
shareName = VNXeUtils.buildNfsShareName(args.getSnapshotName(), path);
if (isDeleteRule) {
job = apiClient.deleteNfsShareForSnapshot(rule.getDeviceExportId());
if (job != null) {
completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, rule.getExportPath(), false);
ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
} else {
_logger.error("No job returned from unexportFileSystem Snapshot");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("UnExportFileSystem", "No Job returned from UnExportFileSystem");
return BiosCommandResult.createErrorResult(error);
}
} else {
job = apiClient.createNfsShareForSnap(args.getSnapNativeId(), roHosts, rwHosts, rootHosts, access, path, shareName, null);
if (job != null) {
completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
VNXeModifyExportJob modifyExportJob = new VNXeModifyExportJob(job.getId(), storage.getId(), completer, rule, fsExport, args.getExportPath(), args.getFileOperation(), isDeleteRule, shareName);
ControllerServiceImpl.enqueueJob(new QueueJob(modifyExportJob));
} else {
_logger.error("No job returned from updateExportRules");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("updateExportRules", "No Job returned from updateExportRules");
return BiosCommandResult.createErrorResult(error);
}
}
}
}
} catch (VNXeException e) {
_logger.error("updateExportRules got the exception", e);
if (completer != null) {
completer.error(_dbClient, e);
}
return BiosCommandResult.createErrorResult(e);
} catch (Exception ex) {
_logger.error("updateExportRules got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("updateExportRules", ex.getMessage());
if (completer != null) {
completer.error(_dbClient, error);
}
return BiosCommandResult.createErrorResult(error);
}
_logger.info("UpdateExportRules job submitted");
return BiosCommandResult.createPendingResult();
}
use of com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter in project coprhd-controller by CoprHD.
the class VNXeStorageDevice method doDeleteSnapshot.
@Override
public BiosCommandResult doDeleteSnapshot(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
_logger.info("Deleting file system {} snapshot {} ", args.getFsName(), args.getSnapshotLabel());
VNXeApiClient apiClient = getVnxeClient(storage);
VNXeCommandJob job = null;
VNXeFileTaskCompleter completer = null;
try {
job = apiClient.deleteFileSystemSnap(args.getSnapNativeId());
if (job != null) {
completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
VNXeDeleteFileSystemSnapshotJob snapJob = new VNXeDeleteFileSystemSnapshotJob(job.getId(), storage.getId(), completer);
ControllerServiceImpl.enqueueJob(new QueueJob(snapJob));
} else {
_logger.error("No job returned from deleteFileSystemSnap");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("snapshotFileSystem", "No Job returned from deleteFileSystemSnap");
return BiosCommandResult.createErrorResult(error);
}
} catch (VNXeException e) {
_logger.error("Delete file system snapshot got the exception", e);
if (completer != null) {
completer.error(_dbClient, e);
}
return BiosCommandResult.createErrorResult(e);
} catch (Exception ex) {
_logger.error("Delete file system snpashot got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystemSnapshot", ex.getMessage());
if (completer != null) {
completer.error(_dbClient, error);
}
return BiosCommandResult.createErrorResult(error);
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete filesystem snapshot job submitted - Array:%s, fileSystem: %s, snapshot: %s", storage.getSerialNumber(), args.getFsName(), args.getSnapshotName()));
_logger.info(logMsgBuilder.toString());
return BiosCommandResult.createPendingResult();
}
use of com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDevice method doDeleteSnapshot.
@Override
public BiosCommandResult doDeleteSnapshot(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
_logger.info("Deleting file system {} snapshot {} ", args.getFsName(), args.getSnapshotLabel());
VNXeApiClient apiClient = getVnxUnityClient(storage);
VNXeCommandJob job = null;
VNXeFileTaskCompleter completer = null;
try {
job = apiClient.deleteFileSystemSnap(args.getSnapNativeId());
if (job != null) {
completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
VNXeDeleteFileSystemSnapshotJob snapJob = new VNXeDeleteFileSystemSnapshotJob(job.getId(), storage.getId(), completer);
ControllerServiceImpl.enqueueJob(new QueueJob(snapJob));
} else {
_logger.error("No job returned from deleteFileSystemSnap");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("snapshotFileSystem", "No Job returned from deleteFileSystemSnap");
return BiosCommandResult.createErrorResult(error);
}
} catch (VNXeException e) {
_logger.error("Delete file system snapshot got the exception", e);
if (completer != null) {
completer.error(dbClient, e);
}
return BiosCommandResult.createErrorResult(e);
} catch (Exception ex) {
_logger.error("Delete file system snpashot got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystemSnapshot", ex.getMessage());
if (completer != null) {
completer.error(dbClient, error);
}
return BiosCommandResult.createErrorResult(error);
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete filesystem snapshot job submitted - Array:%s, fileSystem: %s, snapshot: %s", storage.getSerialNumber(), args.getFsName(), args.getSnapshotName()));
_logger.info(logMsgBuilder.toString());
return BiosCommandResult.createPendingResult();
}
use of com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDevice method doExpandFS.
@Override
public BiosCommandResult doExpandFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
_logger.info("expanding file system: ", args.getFsName());
VNXeApiClient apiClient = getVnxUnityClient(storage);
VNXeCommandJob job = null;
VNXeFileTaskCompleter completer = null;
try {
job = apiClient.expandFileSystem(args.getFsNativeId(), args.getNewFSCapacity());
if (job != null) {
completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
VNXeExpandFileSystemJob expandFSJob = new VNXeExpandFileSystemJob(job.getId(), storage.getId(), completer);
ControllerServiceImpl.enqueueJob(new QueueJob(expandFSJob));
} else {
_logger.error("No job returned from expandFileSystem");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("expandFileSystem", "No Job returned from expandFileSystem");
return BiosCommandResult.createErrorResult(error);
}
} catch (VNXeException e) {
_logger.error("Expand file system got the exception", e);
if (completer != null) {
completer.error(dbClient, e);
}
return BiosCommandResult.createErrorResult(e);
} catch (Exception ex) {
_logger.error("Expand file system got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("ExpandFileSystem", ex.getMessage());
if (completer != null) {
completer.error(dbClient, error);
}
return BiosCommandResult.createErrorResult(error);
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Expand filesystem job submitted - Array:%s, fileSystem: %s, new size: %d", storage.getSerialNumber(), args.getFsName(), args.getNewFSCapacity()));
_logger.info(logMsgBuilder.toString());
return BiosCommandResult.createPendingResult();
}
use of com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDevice method doShare.
@Override
public BiosCommandResult doShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
_logger.info("creating smbShare: " + smbFileShare.getName());
VNXeApiClient apiClient = getVnxUnityClient(storage);
String permission = smbFileShare.getPermission();
String shareName = smbFileShare.getName();
String path = "/";
VNXeCommandJob job = null;
VNXeFileTaskCompleter completer = null;
FileSMBShare newShare = new FileSMBShare(smbFileShare);
String absolutePath = smbFileShare.getPath();
newShare.setStoragePortNetworkId(smbFileShare.getStoragePortNetworkId());
newShare.setStoragePortName(smbFileShare.getStoragePortName());
try {
if (args.getFileOperation()) {
if (newShare.isSubDirPath()) {
String basePath = args.getFsPath();
/*
* The below line will allow us to get the relative path of subdir
* For example: absolutePath = /vnxeShare1/subdir1
* Then, the below line will assign path = subdir
* VNXe takes the relative path of the sub-directory. Not the absolute path
*/
path = "/" + new File(basePath).toURI().relativize(new File(absolutePath).toURI()).getPath();
}
String fsNativeId = args.getFs().getNativeId();
_logger.info("Creating CIFS share for path {}", path);
job = apiClient.createCIFSShare(fsNativeId, shareName, permission, path);
if (job != null) {
newShare.setNetBIOSName(apiClient.getNetBios());
completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
VNXeCreateShareJob createShareJob = new VNXeCreateShareJob(job.getId(), storage.getId(), completer, newShare, true);
ControllerServiceImpl.enqueueJob(new QueueJob(createShareJob));
} else {
_logger.error("No job returned from creaetCifsShare");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("createShare", "No Job returned");
return BiosCommandResult.createErrorResult(error);
}
} else {
// create share for a snapshot
if (newShare.isSubDirPath()) {
String basePath = args.getSnapshotPath();
/*
* The below line will allow us to get the relative path of subdir
* For example: absolutePath = /vnxeShare1/subdir1
* Then, the below line will assign path = subdir
* VNXe takes the relative path of the sub-directory. Not the absolute path
*/
path = "/" + new File(basePath).toURI().relativize(new File(absolutePath).toURI()).getPath();
}
String fsNativeId = args.getFs().getNativeId();
String snapId = args.getSnapNativeId();
job = apiClient.createCifsShareForSnap(snapId, shareName, permission, path, fsNativeId);
if (job != null) {
newShare.setNetBIOSName(apiClient.getNetBios());
completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
VNXeCreateShareJob createShareJob = new VNXeCreateShareJob(job.getId(), storage.getId(), completer, newShare, false);
ControllerServiceImpl.enqueueJob(new QueueJob(createShareJob));
} else {
_logger.error("No job returned from creaetCifsShare");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("createShare", "No Job returned");
return BiosCommandResult.createErrorResult(error);
}
}
} catch (VNXeException e) {
_logger.error("Create share got the exception", e);
if (completer != null) {
completer.error(dbClient, e);
}
return BiosCommandResult.createErrorResult(e);
} catch (Exception ex) {
_logger.error("create share got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("create share", ex.getMessage());
if (completer != null) {
completer.error(dbClient, error);
}
return BiosCommandResult.createErrorResult(error);
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Create share job submitted - Array:%s, share: %s", storage.getSerialNumber(), smbFileShare.getName()));
_logger.info(logMsgBuilder.toString());
return BiosCommandResult.createPendingResult();
}
Aggregations