use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class VNXUnityFileStorageDevice 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 = getVnxUnityClient(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 UnityExport 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 UnityExport 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 UnityExport 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 UnityExport 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 NetAppClusterModeDevice method validateExportArgs.
// Validate the export arguments for the NetApp Cluster-mode
//
// The root user mapping must be an integer or the value 'nobody'. Since
// 'nobody' is the default value on the NetApp, it does not need to be sent.
// The CLI only accepts UIDs (integer values).
private void validateExportArgs(List<FileExport> exports) throws ControllerException {
String rootUser = "";
for (FileExport exp : exports) {
// Validate the root user mapping
_log.info("FileExport:Clients:" + exp.getClients() + ":SPName:" + exp.getStoragePortName() + ":SP:" + exp.getStoragePort() + ":rootusermapping:" + exp.getRootUserMapping() + ":perm:" + exp.getPermissions() + ":protocol:" + exp.getProtocol() + ":security:" + exp.getSecurityType() + ":subDir:" + exp.getPath());
rootUser = exp.getRootUserMapping();
try {
if (!rootUser.equalsIgnoreCase(USER_NONE) && !rootUser.equalsIgnoreCase(ROOT_PERM)) {
Integer.parseInt(rootUser);
}
} catch (NumberFormatException nfe) {
throw new DeviceControllerException("Invalid Root User Mapping {0} ", new Object[] { nfe });
}
}
}
use of com.emc.storageos.db.client.model.FileExport in project coprhd-controller by CoprHD.
the class NetAppClusterModeDevice method doUnexport.
@Override
public BiosCommandResult doUnexport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
BiosCommandResult result = new BiosCommandResult();
try {
_log.info("NetAppClusterModeDevice doUnexport: {} - start", args.getFileObjId());
if (!args.getFileOperation()) {
_log.error("NetAppClusterModeDevice::doUnexport {} : Snapshot unexport is not Supported", args.getSnapshotId());
ServiceError serviceError = DeviceControllerErrors.netappc.unableToUnexportSnapshot();
serviceError.setMessage(genDetailedMessage("doUnExport", args.getSnapshotId().toString(), "Snapshot unexport is not Supported"));
result = BiosCommandResult.createErrorResult(serviceError);
return result;
}
for (int expCount = 0; expCount < exportList.size(); expCount++) {
FileExport export = exportList.get(expCount);
String portGroup = findSVMName(args.getFs());
NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
if (export.getPermissions() == null) {
export.setPermissions(RO_PERM);
}
String mountPath = export.getMountPath();
String exportPath = export.getPath();
if (!ncApi.unexportFS(exportPath, mountPath)) {
_log.error("NetAppClusterModeDevice::doUnexport {} failed", args.getFsId());
ServiceError serviceError = DeviceControllerErrors.netappc.unableToUnexportFileSystem();
serviceError.setMessage(genDetailedMessage("doUnexport", args.getFsId().toString()));
result = BiosCommandResult.createErrorResult(serviceError);
return result;
} else {
_log.info("NetAppClusterModeDevice doUnexport {} - completed", args.getFsId());
result = BiosCommandResult.createSuccessfulResult();
}
}
} catch (NetAppCException e) {
_log.error("NetAppClusterModeDevice::doUnexport failed with a NetAppCException", e);
ServiceError serviceError = DeviceControllerErrors.netappc.unableToUnexportFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
} catch (Exception e) {
_log.error("NetAppClusterModeDevice::doUnexport failed with an Exception", e);
ServiceError serviceError = DeviceControllerErrors.netappc.unableToUnexportFileSystem();
serviceError.setMessage(e.getLocalizedMessage());
result = BiosCommandResult.createErrorResult(serviceError);
}
_log.info("NetAppClusterModeDevice doUnexport {} - complete", args.getFileObjId());
return result;
}
use of com.emc.storageos.db.client.model.FileExport 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.db.client.model.FileExport 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;
}
Aggregations