use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class VNXFileStorageDeviceXML method getVNXFileExports.
private List<VNXFileExport> getVNXFileExports(FSExportMap existingExps) {
List<VNXFileExport> vnxExports = new ArrayList<VNXFileExport>();
if (existingExps != null && !existingExps.isEmpty()) {
for (FileExport cur : existingExps.values()) {
_log.debug("Added export sec, perm {} {}", cur.getSecurityType(), cur.getPermissions());
_log.debug(" anon,path {} {}", cur.getRootUserMapping(), cur.getPath());
VNXFileExport vnxExp = new VNXFileExport(cur.getClients(), cur.getStoragePortName(), cur.getPath(), cur.getSecurityType(), cur.getPermissions(), cur.getRootUserMapping(), cur.getProtocol(), cur.getStoragePort(), cur.getSubDirectory(), cur.getComments());
vnxExports.add(vnxExp);
}
}
return vnxExports;
}
use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class VNXeStorageDevice method deleteExportRules.
@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) {
List<ExportRule> allExports = args.getExistingDBExportRules();
String subDir = args.getSubDirectory();
boolean allDirs = args.isAllDir();
VNXeCommandJob job = null;
VNXeFileTaskCompleter completer = null;
boolean isFile = args.getFileOperation();
boolean ifRulePresent = false;
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;
}
}
_logger.info("exportPath : {}", exportPath);
args.setExportPath(exportPath);
_logger.info("Number of existing exports found {}", allExports.size());
try {
VNXeApiClient apiClient = getVnxeClient(storage);
if (allDirs) {
// ALL EXPORTS
_logger.info("Deleting all exports specific to filesystem at device and rules from DB including sub dirs rules and exports");
for (ExportRule rule : allExports) {
FileShareExport fsExport = null;
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 vnxeShareId = rule.getDeviceExportId();
_logger.info("Delete IsilonExport id {} for path {}", rule.getDeviceExportId(), rule.getExportPath());
if (isFile) {
String fsId = args.getFs().getNativeId();
job = apiClient.removeNfsShare(vnxeShareId, fsId);
} else {
job = apiClient.deleteNfsShareForSnapshot(vnxeShareId);
}
if (job != null) {
if (isFile) {
completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
} else {
completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
}
VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, rule.getExportPath(), isFile);
ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
} else {
_logger.error("No job returned from exportFileSystem");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", "No Job returned from deleteFileSystem");
return BiosCommandResult.createErrorResult(error);
}
}
} else if (subDir != null && !subDir.isEmpty()) {
// Filter for a specific Sub Directory export
_logger.info("Deleting all subdir exports rules at ViPR and sub directory export at device {}", subDir);
FileShareExport fsExport = null;
String vnxeShareId = null;
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(subDirExportPath)) {
exp = export;
break;
}
}
fsExport = new FileShareExport(exp);
}
for (ExportRule rule : allExports) {
_logger.info("Delete IsilonExport id for path {} f containing subdirectory {}", rule.getDeviceExportId() + ":" + rule.getExportPath(), subDir);
if (rule.getExportPath().equalsIgnoreCase(subDirExportPath)) {
ifRulePresent = true;
vnxeShareId = rule.getDeviceExportId();
}
}
if (!ifRulePresent) {
if (fsExport != null) {
vnxeShareId = fsExport.getIsilonId();
}
}
_logger.info("Delete IsilonExport id {} for path {}", vnxeShareId, subDirExportPath);
if (isFile) {
String fsId = args.getFs().getNativeId();
job = apiClient.removeNfsShare(vnxeShareId, fsId);
} else {
job = apiClient.deleteNfsShareForSnapshot(vnxeShareId);
}
if (job != null) {
if (isFile) {
completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
} else {
completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
}
VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, subDirExportPath, isFile);
ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
} else {
_logger.error("No job returned from exportFileSystem");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", "No Job returned from deleteFileSystem");
return BiosCommandResult.createErrorResult(error);
}
} else {
// Filter for No SUBDIR - main export rules with no sub dirs
_logger.info("Deleting all export rules from DB and export at device not included sub dirs");
FileShareExport fsExport = null;
String vnxeShareId = null;
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;
break;
}
}
fsExport = new FileShareExport(exp);
}
for (ExportRule rule : allExports) {
if (rule.getExportPath().equalsIgnoreCase(exportPath)) {
ifRulePresent = true;
vnxeShareId = rule.getDeviceExportId();
}
}
if (!ifRulePresent) {
if (fsExport != null) {
vnxeShareId = fsExport.getIsilonId();
}
}
_logger.info("Delete IsilonExport id {} for path {}", vnxeShareId, fsExport.getPath());
if (isFile) {
String fsId = args.getFs().getNativeId();
job = apiClient.removeNfsShare(vnxeShareId, fsId);
} else {
job = apiClient.deleteNfsShareForSnapshot(vnxeShareId);
}
if (job != null) {
if (isFile) {
completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
} else {
completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
}
VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, fsExport.getPath(), isFile);
ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
} else {
_logger.error("No job returned from exportFileSystem");
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", "No Job returned from deleteFileSystem");
return BiosCommandResult.createErrorResult(error);
}
}
} catch (VNXeException e) {
_logger.error("Unexport file system got the exception", e);
if (completer != null) {
completer.error(_dbClient, e);
}
return BiosCommandResult.createErrorResult(e);
} catch (Exception ex) {
_logger.error("Delete file system got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", ex.getMessage());
if (completer != null) {
completer.error(_dbClient, error);
}
return BiosCommandResult.createErrorResult(error);
}
if (job != null) {
StringBuilder logMsgBuilder = new StringBuilder(String.format("Unexport filesystem job submitted - Array:%s, fileSystem: %s", storage.getSerialNumber(), args.getFsName()));
_logger.info(logMsgBuilder.toString());
return BiosCommandResult.createPendingResult();
} else {
StringBuilder logMsgBuilder = new StringBuilder(String.format("No export found - Array:%s, fileSystem: %s", storage.getSerialNumber(), args.getFsName()));
_logger.info(logMsgBuilder.toString());
return BiosCommandResult.createSuccessfulResult();
}
}
use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class VNXeModifyExportJob method updateSnapshotExport.
private void updateSnapshotExport(Snapshot snapObj, DbClient dbClient, FileExport newExport) {
_logger.info("updating file export. ");
FSExportMap exports = snapObj.getFsExports();
if (exports == null) {
exports = new FSExportMap();
}
FileExport exportToBeUpdated = exports.get(newExport.getFileExportKey());
if (exportToBeUpdated != null) {
List<String> clients = new ArrayList<String>();
if (rule.getReadOnlyHosts() != null) {
clients.addAll(rule.getReadOnlyHosts());
}
if (rule.getReadWriteHosts() != null) {
clients.addAll(rule.getReadWriteHosts());
}
if (rule.getRootHosts() != null) {
clients.addAll(rule.getRootHosts());
}
exportToBeUpdated.setClients(clients);
exports.put(newExport.getFileExportKey(), exportToBeUpdated);
snapObj.setFsExports(exports);
dbClient.persistObject(snapObj);
}
}
use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class VNXeModifyExportJob method updateStatus.
/**
* Called to update the job status when the export file system job completes.
*
* @param jobContext The job context.
*/
@Override
public void updateStatus(JobContext jobContext) throws Exception {
DbClient dbClient = jobContext.getDbClient();
try {
if (_status == JobStatus.IN_PROGRESS) {
return;
}
VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
String opId = getTaskCompleter().getOpId();
StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, _status.name()));
FileShare fsObj = null;
Snapshot snapObj = null;
URI objId = getTaskCompleter().getId();
StorageSystem storageObj = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
if (_status == JobStatus.SUCCESS) {
_isSuccess = true;
FileExport newExport = null;
if (exportInfo != null) {
newExport = exportInfo.getFileExport();
}
VNXeNfsShare nfsShare = null;
if (isFile) {
fsObj = dbClient.queryObject(FileShare.class, objId);
nfsShare = vnxeApiClient.getNfsShareById(rule.getDeviceExportId());
// nfsShare = vnxeApiClient.findNfsShare(fsObj.getNativeId(), shareName);
updateExportRules(vnxeApiClient, dbClient, fsObj, nfsShare);
if (newExport != null) {
updateFSExport(fsObj, dbClient, newExport);
}
} else {
snapObj = dbClient.queryObject(Snapshot.class, objId);
fsObj = dbClient.queryObject(FileShare.class, snapObj.getParent().getURI());
nfsShare = vnxeApiClient.findSnapNfsShare(snapObj.getNativeId(), shareName);
updateExportRules(vnxeApiClient, dbClient, fsObj, nfsShare);
if (newExport != null) {
updateSnapshotExport(snapObj, dbClient, newExport);
}
}
} else if (_status == JobStatus.FAILED) {
// cleanupFSExport(fsObj, dbClient);
logMsgBuilder.append("\n");
logMsgBuilder.append(String.format("Task %s failed to update export rules: %s", opId, objId.toString()));
}
_logger.info(logMsgBuilder.toString());
if (isFile) {
FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SYSTEM, _isSuccess, logMsgBuilder.toString(), "", fsObj, storageObj);
} else {
FileDeviceController.recordFileDeviceOperation(dbClient, OperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SNAPSHOT, _isSuccess, logMsgBuilder.toString(), "", snapObj, fsObj, storageObj);
}
} catch (Exception e) {
_logger.error("Caught an exception while trying to updateStatus for VNXeModifyExportJob", e);
setErrorStatus("Encountered an internal error during update export rules job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class VNXeUnexportFileSystemJob method updateSnapExport.
private Snapshot updateSnapExport(DbClient dbClient, VNXeApiClient apiClient) {
URI snapId = getTaskCompleter().getId();
Snapshot snapObj = dbClient.queryObject(Snapshot.class, snapId);
FSExportMap exports = snapObj.getFsExports();
if (exports == null) {
_logger.info("No exports found in the file system. ");
return snapObj;
}
if (exportInfo != null) {
FileExport export = exportInfo.getFileExport();
FileExport existExport = exports.get(export.getFileExportKey());
if (existExport != null) {
exports.remove(existExport.getFileExportKey());
dbClient.persistObject(snapObj);
}
}
return snapObj;
}
Aggregations