use of com.emc.storageos.model.file.FileExportUpdateParams in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method addStepsToReplicateNFSExportRules.
/**
* Child workflow for replicating source file system NFS export Rules to target.
*
* @param systemTarget
* - URI of target StorageSystem where source NFS shares has to be replicated.
* @param fsURI
* -URI of the source FileSystem
* @param taskId
*/
public void addStepsToReplicateNFSExportRules(URI systemTarget, URI fsURI, String taskId) {
s_logger.info("Generating steps for Replicating NFS export rules to Target Cluster");
FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
Workflow workflow = null;
FileShare targetFileShare = null;
try {
FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
if (sourceFileShare.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
List<String> targetfileUris = new ArrayList<String>();
targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
} else {
targetFileShare = s_dbClient.queryObject(FileShare.class, sourceFileShare.getParentFileShare());
}
workflow = this._workflowService.getNewWorkflow(this, REPLICATE_NFS_EXPORT_RULES_TO_TARGET_WF_NAME, false, taskId, completer);
FSExportMap sourceFSExportMap = sourceFileShare.getFsExports();
FSExportMap targetFSExportMap = targetFileShare.getFsExports();
if (sourceFSExportMap == null && targetFSExportMap != null) {
// There are no export rule on source but there are on target!!
List<ExportRule> exportRulesToDelete;
HashMap<String, List<ExportRule>> targetExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(targetFileShare, s_dbClient);
for (String exportPath : targetExportRuleMap.keySet()) {
FileExportUpdateParams params = new FileExportUpdateParams();
if (exportPath.equals(targetFileShare.getPath())) {
// File system export rules....
exportRulesToDelete = targetExportRuleMap.get(targetFileShare.getPath());
} else {
// Sub directory export rules....
String subDir = exportPath.split(targetFileShare.getPath())[1];
exportRulesToDelete = targetExportRuleMap.get(targetFileShare.getPath() + subDir);
params.setSubDir(subDir.substring(1));
}
ExportRules deleteExportRules = new ExportRules();
deleteExportRules.setExportRules(exportRulesToDelete);
params.setExportRulesToDelete(deleteExportRules);
updateFSExportRulesOnTarget(workflow, systemTarget, targetFileShare, exportPath, params);
}
} else if (targetFSExportMap != null && sourceFSExportMap != null) {
// Both source and target have export rules!!
HashMap<String, List<ExportRule>> sourceExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(sourceFileShare, s_dbClient);
HashMap<String, List<ExportRule>> targetExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(targetFileShare, s_dbClient);
for (String exportPath : sourceExportRuleMap.keySet()) {
FileExportUpdateParams params = new FileExportUpdateParams();
List<ExportRule> exportRulesToAdd = new ArrayList<ExportRule>();
List<ExportRule> exportRulesToDelete = new ArrayList<ExportRule>();
List<ExportRule> exportRulesToModify = new ArrayList<ExportRule>();
List<ExportRule> sourceExportRules;
List<ExportRule> targetExportRules;
HashMap<String, ExportRule> srcExportRuleSecFlvMap;
HashMap<String, ExportRule> trgtExportRuleSecFlvMap;
if (exportPath.equals(sourceFileShare.getPath())) {
// File system export rules....
sourceExportRules = sourceExportRuleMap.get(exportPath);
targetExportRules = targetExportRuleMap.get(targetFileShare.getPath());
} else {
// Sub directory export rules....
sourceExportRules = sourceExportRuleMap.get(exportPath);
String subDir = exportPath.split(sourceFileShare.getPath())[1];
targetExportRules = targetExportRuleMap.get(targetFileShare.getPath() + subDir);
params.setSubDir(subDir.substring(1));
}
if (sourceExportRules != null && targetExportRules != null) {
srcExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(sourceExportRules);
trgtExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(targetExportRules);
FileOrchestrationUtils.checkForExportRuleToAdd(sourceFileShare, targetFileShare, srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToAdd);
FileOrchestrationUtils.checkForExportRuleToDelete(srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToDelete);
sourceExportRules.removeAll(exportRulesToAdd);
targetExportRules.removeAll(exportRulesToDelete);
srcExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(sourceExportRules);
trgtExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(targetExportRules);
FileOrchestrationUtils.checkForExportRuleToModify(srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToModify);
if (!exportRulesToAdd.isEmpty()) {
ExportRules addExportRules = new ExportRules();
addExportRules.setExportRules(exportRulesToAdd);
params.setExportRulesToAdd(addExportRules);
}
if (!exportRulesToDelete.isEmpty()) {
ExportRules deleteExportRules = new ExportRules();
deleteExportRules.setExportRules(exportRulesToDelete);
params.setExportRulesToDelete(deleteExportRules);
}
if (!exportRulesToModify.isEmpty()) {
ExportRules modifyExportRules = new ExportRules();
modifyExportRules.setExportRules(exportRulesToModify);
params.setExportRulesToModify(modifyExportRules);
}
if (params.retrieveAllExports() != null && !params.retrieveAllExports().isEmpty()) {
updateFSExportRulesOnTarget(workflow, systemTarget, targetFileShare, exportPath, params);
}
}
}
}
String successMessage = String.format("Replicating source File System : %s, NFS Exports Rules to Target System finished successfully", sourceFileShare.getLabel());
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error("Could not replicate source filesystem NFS Exports Rules : " + fsURI, ex);
String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
ServiceError serviceError = DeviceControllerException.errors.updateFileShareExportRulesFailed(fsURI.toString(), opName, ex);
completer.error(s_dbClient, this._locker, serviceError);
}
}
Aggregations