use of com.emc.storageos.model.file.MountInfo in project coprhd-controller by CoprHD.
the class FileDeviceController method CheckIfExportIsMounted.
public void CheckIfExportIsMounted(URI fsId, String subDir, boolean allDirs, String opId) {
WorkflowStepCompleter.stepExecuting(opId);
List<MountInfo> mountList = FileOperationUtils.queryDBFSMounts(fsId, _dbClient);
if (mountList == null || mountList.isEmpty()) {
WorkflowStepCompleter.stepSucceded(opId);
}
if (allDirs) {
WorkflowStepCompleter.stepFailed(opId, APIException.badRequests.cannotDeleteDuetoExistingMounts());
}
if (subDir != null) {
for (MountInfo mount : mountList) {
if (subDir.equalsIgnoreCase(mount.getSubDirectory())) {
WorkflowStepCompleter.stepFailed(opId, APIException.badRequests.cannotDeleteDuetoExistingMounts());
}
}
} else {
for (MountInfo mount : mountList) {
if (StringUtils.isEmpty(mount.getSubDirectory())) {
WorkflowStepCompleter.stepFailed(opId, APIException.badRequests.cannotDeleteDuetoExistingMounts());
}
}
}
WorkflowStepCompleter.stepSucceded(opId);
}
use of com.emc.storageos.model.file.MountInfo in project coprhd-controller by CoprHD.
the class FileDeviceController method getRulesToUnmount.
private List<MountInfo> getRulesToUnmount(ExportRules rules, List<MountInfo> mountList, URI fsId, String subDir) {
List<MountInfo> unmountList = new ArrayList<MountInfo>();
List<ExportRule> exportList = new ArrayList<ExportRule>();
exportList.addAll(rules.getExportRules());
Map<ExportRule, List<String>> filteredExports = filterExportRules(exportList, FileOperationUtils.getExportRules(fsId, false, subDir, _dbClient));
for (MountInfo mount : mountList) {
String hostname = _dbClient.queryObject(Host.class, mount.getHostId()).getHostName();
if (StringUtils.isEmpty(subDir) && StringUtils.isEmpty(mount.getSubDirectory()) || (!StringUtils.isEmpty(mount.getSubDirectory()) && mount.getSubDirectory().equals(subDir))) {
for (Entry<ExportRule, List<String>> rule : filteredExports.entrySet()) {
if (rule.getValue().contains(hostname) && rule.getKey().getSecFlavor().equals(mount.getSecurityType())) {
unmountList.add(mount);
}
}
}
}
return unmountList;
}
use of com.emc.storageos.model.file.MountInfo in project coprhd-controller by CoprHD.
the class FileDeviceController method getAllMountedExports.
public List<MountInfo> getAllMountedExports(URI id, String subDir, boolean allDirs) {
List<MountInfo> mountList = FileOperationUtils.queryDBFSMounts(id, _dbClient);
List<MountInfo> unmountList = new ArrayList<MountInfo>();
if (allDirs) {
return mountList;
}
for (MountInfo mount : mountList) {
if ((StringUtils.isEmpty(mount.getSubDirectory()) && StringUtils.isEmpty(subDir)) || (!StringUtils.isEmpty(subDir) && subDir.equalsIgnoreCase(mount.getSubDirectory()))) {
unmountList.add(mount);
}
}
return unmountList;
}
use of com.emc.storageos.model.file.MountInfo in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method deleteExportRules.
@Override
public void deleteExportRules(URI storage, URI uri, boolean allDirs, String subDirs, boolean unmountExport, String opId) throws ControllerException {
FileObject fileObj = null;
String stepDescription = null;
String successMessage = null;
String opName = null;
TaskCompleter completer = null;
if (URIUtil.isType(uri, FileShare.class)) {
completer = new FileWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(FileShare.class, uri);
stepDescription = String.format("Deleting export rules for file system : %s ", uri);
successMessage = String.format("Deleting export rules for file system : %s finished successfully.", uri);
opName = ResourceOperationTypeEnum.UNEXPORT_FILE_SYSTEM.getName();
} else {
completer = new FileSnapshotWorkflowCompleter(uri, opId);
fileObj = s_dbClient.queryObject(Snapshot.class, uri);
stepDescription = String.format("Deleting export rules for file system snapshot : %s ", uri);
successMessage = String.format("Deleting export rules for file system snapshot : %s finished successfully.", uri);
opName = ResourceOperationTypeEnum.UNEXPORT_FILE_SNAPSHOT.getName();
}
try {
Workflow workflow = _workflowService.getNewWorkflow(this, DELETE_FILESYSTEM_EXPORT_RULES_WF_NAME, false, opId, completer);
String waitFor = null;
// Check if the export should be unmounted before deleting
if (unmountExport) {
// get all the mounts and generate steps for unmounting them
List<MountInfo> mountList = _fileDeviceController.getAllMountedExports(uri, subDirs, allDirs);
for (MountInfo mount : mountList) {
Object[] args = new Object[] { mount.getHostId(), mount.getFsId(), mount.getMountPath() };
waitFor = _fileDeviceController.createMethod(workflow, waitFor, UNMOUNT_FILESYSTEM_EXPORT_METHOD, null, "Unmounting path:" + mount.getMountPath(), storage, args);
}
} else if (URIUtil.isType(uri, FileShare.class)) {
// Check if the export is mounted and throw an error if mounted
Object[] args = new Object[] { uri, subDirs, allDirs };
waitFor = _fileDeviceController.createMethod(workflow, waitFor, CHECK_IF_EXPORT_IS_MOUNTED, null, "Checking if the export is mounted", storage, args);
}
Object[] args = new Object[] { storage, uri, allDirs, subDirs };
_fileDeviceController.createMethod(workflow, waitFor, DELETE_FILESYSTEM_EXPORT_RULES, null, stepDescription, storage, args);
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error(String.format("Deleting export rules for file system snapshot : %s failed. ", uri), ex);
ServiceError serviceError = DeviceControllerException.errors.deleteExportRuleFailed(fileObj.toString(), opName, ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
use of com.emc.storageos.model.file.MountInfo in project coprhd-controller by CoprHD.
the class FileOperationUtils method queryDBFSMounts.
public static List<MountInfo> queryDBFSMounts(URI fsId, DbClient dbClient) {
_log.info("Querying File System mounts using FsId {}", fsId);
List<MountInfo> fsMounts = new ArrayList<MountInfo>();
try {
ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileMountsConstraint(fsId);
List<FileMountInfo> fsDBMounts = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, FileMountInfo.class, containmentConstraint);
if (fsDBMounts != null && !fsDBMounts.isEmpty()) {
for (FileMountInfo dbMount : fsDBMounts) {
MountInfo mountInfo = new MountInfo();
getMountInfo(dbMount, mountInfo);
fsMounts.add(mountInfo);
}
}
return fsMounts;
} catch (Exception e) {
_log.error("Error while querying {}", e);
}
return fsMounts;
}
Aggregations