use of com.emc.sa.service.vipr.file.tasks.UpdateFileSnapshotExport in project coprhd-controller by CoprHD.
the class FileStorageUtils method updateFileSnapshotExport.
public static String updateFileSnapshotExport(URI fileSnapshotId, String subDirectory, FileExportRule[] fileExportRules) {
List<ExportRule> exportRuleList = getFileSnapshotExportRules(fileSnapshotId, false, subDirectory);
Set<String> existingRuleSet = Sets.newHashSet();
for (ExportRule rule : exportRuleList) {
existingRuleSet.add(rule.getSecFlavor());
}
List<ExportRule> exportRuleListToAdd = Lists.newArrayList();
List<ExportRule> exportRuleListToModify = Lists.newArrayList();
for (FileExportRule rule : fileExportRules) {
ExportRule exportRule = new ExportRule();
exportRule.setFsID(fileSnapshotId);
exportRule.setSecFlavor(rule.security);
String rootUserMapping = rule.rootUserMapping;
String domain = rule.domain;
if (StringUtils.isNotBlank(domain)) {
rootUserMapping = domain.trim() + "\\" + rootUserMapping.trim();
}
exportRule.setAnon(rootUserMapping);
Set<String> exportHosts = new HashSet<String>(rule.exportHosts);
switch(rule.getPermission()) {
case "ro":
exportRule.setReadOnlyHosts(exportHosts);
break;
case "rw":
exportRule.setReadWriteHosts(exportHosts);
break;
case "root":
exportRule.setRootHosts(exportHosts);
break;
default:
break;
}
if (existingRuleSet.contains(exportRule.getSecFlavor())) {
exportRuleListToModify.add(exportRule);
} else {
exportRuleListToAdd.add(exportRule);
}
}
SnapshotExportUpdateParams params = new SnapshotExportUpdateParams();
if (!exportRuleListToAdd.isEmpty()) {
ExportRules exportRulesToAdd = new ExportRules();
exportRulesToAdd.setExportRules(exportRuleListToAdd);
params.setExportRulesToAdd(exportRulesToAdd);
}
if (!exportRuleListToModify.isEmpty()) {
ExportRules exportRulesToModify = new ExportRules();
exportRulesToModify.setExportRules(exportRuleListToModify);
params.setExportRulesToModify(exportRulesToModify);
}
Task<FileSnapshotRestRep> task = execute(new UpdateFileSnapshotExport(fileSnapshotId, subDirectory, params));
addAffectedResource(task);
String exportId = task.getResourceId().toString();
logInfo("file.storage.export.task", exportId, task.getOpId());
return exportId;
}
Aggregations