Search in sources :

Example 1 with FileExportUpdateParams

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Workflow(com.emc.storageos.workflow.Workflow) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) FileWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FileWorkflowCompleter) FileExportUpdateParams(com.emc.storageos.model.file.FileExportUpdateParams) ExportRules(com.emc.storageos.model.file.ExportRules) ExportRule(com.emc.storageos.model.file.ExportRule) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

FSExportMap (com.emc.storageos.db.client.model.FSExportMap)1 FileShare (com.emc.storageos.db.client.model.FileShare)1 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 ExportRule (com.emc.storageos.model.file.ExportRule)1 ExportRules (com.emc.storageos.model.file.ExportRules)1 FileExportUpdateParams (com.emc.storageos.model.file.FileExportUpdateParams)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 ControllerException (com.emc.storageos.volumecontroller.ControllerException)1 FileWorkflowCompleter (com.emc.storageos.volumecontroller.impl.file.FileWorkflowCompleter)1 Workflow (com.emc.storageos.workflow.Workflow)1 WorkflowException (com.emc.storageos.workflow.WorkflowException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1