use of com.emc.storageos.model.file.ExportRules in project coprhd-controller by CoprHD.
the class FileDeviceController method doCRUDExports.
private void doCRUDExports(FileExportUpdateParams param, FileShare fs, FileDeviceInputOutput args) throws Exception {
try {
// create new exports
ExportRules exportRules = param.getExportRulesToAdd();
List<ExportRule> rules;
if (exportRules != null) {
rules = exportRules.getExportRules();
if (rules != null && !rules.isEmpty()) {
for (ExportRule exportRule : rules) {
FileExportRule rule = new FileExportRule();
rule.setId(URIUtil.createId(FileExportRule.class));
copyPropertiesToSave(rule, exportRule, fs, args);
_log.info("Storing New DB Export Rule {}", rule);
_dbClient.createObject(rule);
}
}
}
// Modify Existing Exports
exportRules = param.getExportRulesToModify();
if (exportRules != null) {
rules = exportRules.getExportRules();
if (rules != null && !rules.isEmpty()) {
for (ExportRule exportRule : rules) {
FileExportRule rule = new FileExportRule();
// Copy the properties to build the index id to query DB for existing Export Rule
copyPropertiesToSave(rule, exportRule, fs, args);
rule = getAvailableExportRule(rule, args);
// Remove the existing and create the new one.
// Don't Update the existing one as persist object will create a new StringSet rather
// it updates the existing one with new information and upon keeping/appending to old one.
rule.setInactive(true);
_log.info("Removing Existing DB Export Rule {}", rule);
_dbClient.updateObject(rule);
FileExportRule newRule = new FileExportRule();
newRule.setId(URIUtil.createId(FileExportRule.class));
// Now, Copy the properties again into the rule came out of DB, before updating.
copyPropertiesToSave(newRule, exportRule, fs, args);
_log.info("Storing New DB Export Rule {}", newRule);
_dbClient.createObject(newRule);
}
}
}
// Delete Existing Exports
exportRules = param.getExportRulesToDelete();
if (exportRules != null) {
rules = exportRules.getExportRules();
if (rules != null && !rules.isEmpty()) {
for (ExportRule exportRule : rules) {
FileExportRule rule = new FileExportRule();
copyPropertiesToSave(rule, exportRule, fs, args);
rule = getAvailableExportRule(rule, args);
rule.setInactive(true);
_log.info("Marking DB Export Rule Inactive {}", rule);
_dbClient.updateObject(rule);
}
}
// Delete the ExportMap entry if there are no export rules for this file system or sub directory
FSExportMap fsNFSExportMap = fs.getFsExports();
ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(fs.getId());
List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileExportRule.class, containmentConstraint);
Set<String> fileExportMapKeys = fsNFSExportMap.keySet();
Iterator<String> keySetIterator = fileExportMapKeys.iterator();
HashSet<String> keystoRemove = new HashSet<String>();
while (keySetIterator.hasNext()) {
String fileExportMapKey = keySetIterator.next();
FileExport fileExport = fsNFSExportMap.get(fileExportMapKey);
boolean exportRuleExists = false;
for (FileExportRule fileExportRule : fileExportRules) {
if (fileExportRule.getExportPath().equals(fileExport.getMountPath())) {
exportRuleExists = true;
break;
}
}
if (!exportRuleExists) {
keystoRemove.add(fileExportMapKey);
}
}
for (String key : keystoRemove) {
_log.info("Deleting file export map entry : {} for key : {}", fsNFSExportMap.get(key), key);
fsNFSExportMap.remove(key);
}
_dbClient.updateObject(fs);
}
} catch (Exception e) {
_log.info("Error While executing CRUD Operations {}", e);
}
}
Aggregations