use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.
the class FileDeviceController method filterExportRules.
private Map<ExportRule, List<String>> filterExportRules(List<ExportRule> newExportList, List<ExportRule> existingExportList) {
Map<ExportRule, List<String>> filteredExports = new HashMap<ExportRule, List<String>>();
_log.info("filtering export rules");
for (ExportRule newExport : newExportList) {
for (ExportRule oldExport : existingExportList) {
if (newExport.getSecFlavor().equalsIgnoreCase(oldExport.getSecFlavor())) {
List<String> hosts = new ArrayList<String>();
if (oldExport.getReadOnlyHosts() != null) {
hosts.addAll(oldExport.getReadOnlyHosts());
}
if (oldExport.getReadWriteHosts() != null) {
hosts.addAll(oldExport.getReadWriteHosts());
}
if (oldExport.getRootHosts() != null) {
hosts.addAll(oldExport.getRootHosts());
}
if (newExport.getReadOnlyHosts() != null) {
hosts.removeAll(newExport.getReadOnlyHosts());
}
if (newExport.getReadWriteHosts() != null) {
hosts.removeAll(newExport.getReadWriteHosts());
}
if (newExport.getRootHosts() != null) {
hosts.removeAll(newExport.getRootHosts());
}
filteredExports.put(oldExport, hosts);
}
}
}
return filteredExports;
}
use of com.emc.storageos.model.file.ExportRule 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.ExportRule in project coprhd-controller by CoprHD.
the class FileDeviceController method deleteExportRules.
@Override
public void deleteExportRules(URI storage, URI fileUri, boolean allDirs, String subDir, String opId) throws ControllerException {
ControllerUtils.setThreadLocalLogData(fileUri, opId);
FileObject fsObj = null;
FileDeviceInputOutput args = new FileDeviceInputOutput();
FileShare fs = null;
Snapshot snapshotObj = null;
StorageSystem storageObj = null;
boolean isFile = false;
try {
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
// File
if (URIUtil.isType(fileUri, FileShare.class)) {
isFile = true;
fs = _dbClient.queryObject(FileShare.class, fileUri);
setVirtualNASinArgs(fs.getVirtualNAS(), args);
fsObj = fs;
args.addFSFileObject(fs);
StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
args.addStoragePool(pool);
args.setAllDir(allDirs);
args.setSubDirectory(subDir);
} else {
// Snapshot
snapshotObj = _dbClient.queryObject(Snapshot.class, fileUri);
fsObj = snapshotObj;
fs = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
setVirtualNASinArgs(fs.getVirtualNAS(), args);
args.addFileShare(fs);
args.addSnapshotFileObject(snapshotObj);
StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
args.addStoragePool(pool);
args.setAllDir(true);
args.setSubDirectory(null);
}
args.setFileOperation(isFile);
args.setOpId(opId);
List<ExportRule> existingExportRules = queryExports(args);
args.setExistingDBExportRules(existingExportRules);
// Do the Operation on device.
_log.info("Delete Export Rules : request received for {}, with allDirs : {}, subDir : {}", new Object[] { fs.getId(), allDirs, subDir });
acquireStepLock(storageObj, opId);
WorkflowStepCompleter.stepExecuting(opId);
BiosCommandResult result = getDevice(storageObj.getSystemType()).deleteExportRules(storageObj, args);
if (result.isCommandSuccess()) {
// Update Database
doDeleteExportRulesFromDB(allDirs, subDir, args);
doDeleteExportsFromFSObjMap(allDirs, subDir, args);
WorkflowStepCompleter.stepSucceded(opId);
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
// Audit & Update the task status
String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
if (isFile) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SYSTEM, result.isCommandSuccess(), eventMsg, "", fs, storageObj);
} else {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, result.isCommandSuccess(), eventMsg, "", snapshotObj, fs, storageObj);
}
_dbClient.updateObject(fsObj);
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
String[] params = { storage.toString(), fileUri.toString() };
_log.error("Unable to export file system or snapshot: storage {}, FS/snapshot URI {}", params);
if ((fsObj != null) && (storageObj != null)) {
if (URIUtil.isType(fileUri, FileShare.class)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SYSTEM, false, e.getMessage(), "", fs, storageObj);
} else {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fs, storageObj);
}
}
updateTaskStatus(opId, fsObj, e);
}
}
use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.
the class FileOrchestrationUtils method getFSExportRuleMap.
/**
* This method generates export map for the file system export rules.
*
* @param fs File System Object
* @param dbClient
* @return
*/
public static HashMap<String, List<ExportRule>> getFSExportRuleMap(FileShare fs, DbClient dbClient) {
ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(fs.getId());
List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, FileExportRule.class, containmentConstraint);
HashMap<String, List<ExportRule>> exportRulesMap = new HashMap<String, List<ExportRule>>();
for (FileExportRule fileExportRule : fileExportRules) {
if (exportRulesMap.get(fileExportRule.getExportPath()) == null) {
List<ExportRule> exportRules = new ArrayList<ExportRule>();
ExportRule exportRule = convertFileExportRuleToExportRule(fileExportRule);
exportRules.add(exportRule);
exportRulesMap.put(fileExportRule.getExportPath(), exportRules);
} else {
List<ExportRule> exportRules = exportRulesMap.get(fileExportRule.getExportPath());
ExportRule exportRule = convertFileExportRuleToExportRule(fileExportRule);
exportRules.add(exportRule);
}
}
return exportRulesMap;
}
use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.
the class FileOrchestrationUtils method checkForExportRuleToAdd.
/**
* This method checks for export rules that has to added on target file system
*
* @param sourceFileShare
* @param targetFileShare
* @param sourceExportRuleMap
* @param targetExportRuleMap
* @param exportRulesToAdd
*/
public static void checkForExportRuleToAdd(FileShare sourceFileShare, FileShare targetFileShare, HashMap<String, ExportRule> sourceExportRuleMap, HashMap<String, ExportRule> targetExportRuleMap, List<ExportRule> exportRulesToAdd) {
for (String secFlavour : sourceExportRuleMap.keySet()) {
if (!targetExportRuleMap.containsKey(secFlavour)) {
ExportRule sourceExportRule = sourceExportRuleMap.get(secFlavour);
ExportRule exportRule = new ExportRule();
exportRule.setFsID(targetFileShare.getId());
if (sourceExportRule.getExportPath().equals(sourceFileShare.getPath())) {
exportRule.setExportPath(targetFileShare.getPath());
} else {
ArrayList<String> subdirName = new ArrayList<String>();
subdirName.add(sourceExportRule.getExportPath().split(sourceFileShare.getPath())[1]);
exportRule.setExportPath(targetFileShare.getPath() + subdirName.get(0));
}
exportRule.setAnon(sourceExportRule.getAnon());
exportRule.setReadOnlyHosts(sourceExportRule.getReadOnlyHosts());
exportRule.setRootHosts(sourceExportRule.getRootHosts());
exportRule.setReadWriteHosts(sourceExportRule.getReadWriteHosts());
exportRule.setSecFlavor(sourceExportRule.getSecFlavor());
exportRulesToAdd.add(exportRule);
}
}
}
Aggregations