Search in sources :

Example 1 with FileNfsACLUpdateParams

use of com.emc.storageos.model.file.FileNfsACLUpdateParams in project coprhd-controller by CoprHD.

the class FileOrchestrationDeviceController method addStepsToReplicateNFSACLs.

/**
 * Child workflow for replicating source file system NFS ACL to target system.
 *
 * @param systemTarget
 *            - URI of target StorageSystem where source CIFS shares has to be replicated.
 * @param fsURI
 *            -URI of the source FileSystem
 * @param taskId
 */
public void addStepsToReplicateNFSACLs(URI systemTarget, URI fsURI, String taskId) {
    s_logger.info("Generating steps for Replicating NFS ACLs to Target Cluster");
    FileNfsACLUpdateParams params = null;
    FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
    FileShare targetFileShare = null;
    Workflow workflow = 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_ACLS_TO_TARGET_WF_NAME, false, taskId, completer);
        Map<String, List<NfsACE>> sourceFSACLMap = FileOrchestrationUtils.queryNFSACL(sourceFileShare, s_dbClient);
        Map<String, List<NfsACE>> targetFSACLMap = FileOrchestrationUtils.queryNFSACL(targetFileShare, s_dbClient);
        if (!sourceFSACLMap.isEmpty() && targetFSACLMap.isEmpty()) {
            // target share doesn't have any ACLs but corresponding share on source does have ACL
            s_logger.info("Target NFS doesn't have any ACL but corresponding NFS on source does have ACL.");
            for (String fsPath : sourceFSACLMap.keySet()) {
                List<NfsACE> aclToAdd = null;
                params = FileOrchestrationUtils.getFileNfsACLUpdateParamWithSubDir(fsPath, sourceFileShare);
                aclToAdd = sourceFSACLMap.get(fsPath);
                params.setAcesToAdd(aclToAdd);
                s_logger.info("Invoking updateNFSACL on FS: {}, with {}", targetFileShare.getName(), params);
                updateNFSACLOnTarget(workflow, systemTarget, targetFileShare, params);
            }
        } else if (!targetFSACLMap.isEmpty() && sourceFSACLMap.isEmpty()) {
            s_logger.info("Source NFS doesn't have any ACL but corresponding NFS on target has ACL.");
            for (String fsPath : targetFSACLMap.keySet()) {
                List<NfsACE> aclToDelete = null;
                params = FileOrchestrationUtils.getFileNfsACLUpdateParamWithSubDir(fsPath, targetFileShare);
                aclToDelete = targetFSACLMap.get(fsPath);
                // TO FIX COP-26361 DU case
                // params.setAcesToDelete(aclToDelete);
                s_logger.info("Invoking updateNFSACL on FS: {}, with {}", targetFileShare.getName(), params);
                updateNFSACLOnTarget(workflow, systemTarget, targetFileShare, params);
            }
        } else if (!sourceFSACLMap.isEmpty() && !targetFSACLMap.isEmpty()) {
            // both source and target FS have some ACL
            for (String sourceFSACLPath : sourceFSACLMap.keySet()) {
                List<NfsACE> aclToAdd = new ArrayList<NfsACE>();
                List<NfsACE> aclToDelete = new ArrayList<NfsACE>();
                List<NfsACE> aclToModify = new ArrayList<NfsACE>();
                // Segregate source and target NFS ACL
                params = FileOrchestrationUtils.getFileNfsACLUpdateParamWithSubDir(sourceFSACLPath, sourceFileShare);
                List<NfsACE> sourceNFSACL = sourceFSACLMap.get(sourceFSACLPath);
                if (sourceNFSACL == null) {
                    sourceNFSACL = new ArrayList<NfsACE>();
                }
                String subDir = params.getSubDir();
                String targetFSACLPath = targetFileShare.getPath();
                if (subDir != null) {
                    targetFSACLPath += "/" + subDir;
                }
                List<NfsACE> targetNFSACL = targetFSACLMap.get(targetFSACLPath);
                if (targetNFSACL == null) {
                    targetNFSACL = new ArrayList<NfsACE>();
                }
                HashMap<String, NfsACE> sourceUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(sourceNFSACL);
                HashMap<String, NfsACE> targetUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(targetNFSACL);
                // ACL To Add
                for (String sourceACEUser : sourceUserToNFSACLMap.keySet()) {
                    if (targetUserToNFSACLMap.get(sourceACEUser) == null) {
                        NfsACE nfsACE = sourceUserToNFSACLMap.get(sourceACEUser);
                        aclToAdd.add(nfsACE);
                    }
                }
                // ACL To Delete
                for (String targetACEUser : targetUserToNFSACLMap.keySet()) {
                    if (sourceUserToNFSACLMap.get(targetACEUser) == null) {
                        aclToDelete.add(targetUserToNFSACLMap.get(targetACEUser));
                    }
                }
                // ACL to Modify
                targetNFSACL.removeAll(aclToDelete);
                sourceNFSACL.removeAll(aclToAdd);
                sourceUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(sourceNFSACL);
                targetUserToNFSACLMap = FileOrchestrationUtils.getUserToNFSACEMap(targetNFSACL);
                for (String sourceACEUser : sourceUserToNFSACLMap.keySet()) {
                    NfsACE targetACE = targetUserToNFSACLMap.get(sourceACEUser);
                    NfsACE sourceACE = sourceUserToNFSACLMap.get(sourceACEUser);
                    if (targetACE != null && (!targetACE.getPermissions().equals(sourceACE.getPermissions()) || !targetACE.getPermissionType().equals(sourceACE.getPermissionType()))) {
                        targetACE.setPermissions(sourceACE.getPermissions());
                        targetACE.setPermissionType(sourceACE.getPermissionType());
                        aclToModify.add(targetACE);
                    }
                }
                if (!aclToAdd.isEmpty()) {
                    params.setAcesToAdd(aclToAdd);
                }
                if (!aclToDelete.isEmpty()) {
                // TO FIX COP-26361 DU case
                // params.setAcesToDelete(aclToDelete);
                }
                if (!aclToModify.isEmpty()) {
                    params.setAcesToModify(aclToModify);
                }
                if (!params.retrieveAllACL().isEmpty()) {
                    s_logger.info("Invoking updateNFSACL on FS: {}, with {}", targetFileShare.getName(), params);
                    updateNFSACLOnTarget(workflow, systemTarget, targetFileShare, params);
                }
            }
        }
        String successMessage = String.format("Replicating source file system : %s, NFS ACL to target file system finished successfully", sourceFileShare.getLabel());
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error("Could not replicate source filesystem NFS ACL : " + fsURI, ex);
        String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
        ServiceError serviceError = DeviceControllerException.errors.updateFileShareNFSACLFailed(fsURI.toString(), opName, ex);
        completer.error(s_dbClient, this._locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) NfsACE(com.emc.storageos.model.file.NfsACE) FileNfsACLUpdateParams(com.emc.storageos.model.file.FileNfsACLUpdateParams) ArrayList(java.util.ArrayList) Workflow(com.emc.storageos.workflow.Workflow) 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) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with FileNfsACLUpdateParams

use of com.emc.storageos.model.file.FileNfsACLUpdateParams in project coprhd-controller by CoprHD.

the class FileSystems method saveNfsAce.

@FlashException(referrer = { "fileSystem" })
public static void saveNfsAce(NfsACLForm nfsACL) {
    String name = params.get("name");
    String type = params.get("type");
    String domain = params.get("domain");
    String subDir = params.get("subDir");
    String fsMountPath = params.get("fsMountPath");
    String fileSystemId = params.get("fileSystemId");
    Set<String> permissions = nfsACL.permissions;
    String permissionType = nfsACL.permissionType;
    String strPer = "";
    nfsACL.validate("nfsACL");
    if (Validation.hasErrors()) {
        Common.handleError();
    }
    for (String permission : permissions) {
        strPer = strPer + permission.toLowerCase() + ",";
    }
    strPer = strPer.substring(0, strPer.length() - 1);
    List<NfsACE> aces = Lists.newArrayList();
    NfsACE nfsAce = new NfsACE();
    nfsAce.setType(type.toLowerCase());
    nfsAce.setUser(name);
    nfsAce.setPermissions(strPer);
    nfsAce.setPermissionType(permissionType);
    if (domain != null && !"".equals(domain) && !"null".equals(domain)) {
        nfsAce.setDomain(domain);
    }
    aces.add(nfsAce);
    FileNfsACLUpdateParams input = new FileNfsACLUpdateParams();
    input.setAcesToModify(aces);
    if (subDir != null && !"null".equals(subDir)) {
        input.setSubDir(subDir);
    }
    ViPRCoreClient client = BourneUtil.getViprClient();
    client.fileSystems().updateNfsACL(uri(fileSystemId), input);
    listNfsAcl(fileSystemId, fsMountPath, subDir);
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) NfsACE(com.emc.storageos.model.file.NfsACE) FileNfsACLUpdateParams(com.emc.storageos.model.file.FileNfsACLUpdateParams) FlashException(controllers.util.FlashException)

Example 3 with FileNfsACLUpdateParams

use of com.emc.storageos.model.file.FileNfsACLUpdateParams in project coprhd-controller by CoprHD.

the class FileSystems method createNfsAclParams.

private static FileNfsACLUpdateParams createNfsAclParams(String formData) {
    String[] uiAcls = formData.split(",");
    List<NfsACE> aces = Lists.newArrayList();
    for (String uiAce : uiAcls) {
        String[] uiData = uiAce.split("~~~");
        String uiType = uiData[0];
        String uiName = uiData[1];
        String uiDomain = uiData[2];
        String uiPermissions = uiData[3];
        String uiPermissiontype = uiData[4];
        NfsACE nfsAce = new NfsACE();
        nfsAce.setUser(uiName);
        if (uiDomain != null && !"".equals(uiDomain) && !"null".equals(uiDomain)) {
            nfsAce.setDomain(uiDomain);
        }
        if (uiType != null && !"".equals(uiType) && !"null".equals(uiType)) {
            nfsAce.setType(uiType);
        }
        if (uiPermissions != null && !"".equals(uiPermissions) && !"null".equals(uiPermissions)) {
            nfsAce.setPermissions(uiPermissions.replaceAll("/", ","));
        }
        nfsAce.setPermissionType(uiPermissiontype);
        aces.add(nfsAce);
    }
    FileNfsACLUpdateParams input = new FileNfsACLUpdateParams();
    input.setAcesToAdd(aces);
    return input;
}
Also used : NfsACE(com.emc.storageos.model.file.NfsACE) FileNfsACLUpdateParams(com.emc.storageos.model.file.FileNfsACLUpdateParams)

Example 4 with FileNfsACLUpdateParams

use of com.emc.storageos.model.file.FileNfsACLUpdateParams in project coprhd-controller by CoprHD.

the class FileSystems method addSubDirAndNfsAcl.

public static void addSubDirAndNfsAcl(String formAccessControlList, String fileSystem, String subDir) {
    if (formAccessControlList == null || "".equals(formAccessControlList)) {
        flash.error(MessagesUtils.get("resources.filesystem.share.acl.invalid.settings"), null);
        fileSystem(fileSystem);
    }
    FileNfsACLUpdateParams input = createNfsAclParams(formAccessControlList);
    if (subDir != null && !"null".equals(subDir) && !subDir.isEmpty()) {
        input.setSubDir(subDir);
    }
    ViPRCoreClient client = BourneUtil.getViprClient();
    try {
        client.fileSystems().updateNfsACL(uri(fileSystem), input);
    } catch (Exception e) {
        flash.error(e.getMessage(), null);
        fileSystem(fileSystem);
    }
    flash.success(MessagesUtils.get(ADDED));
    fileSystem(fileSystem);
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) FileNfsACLUpdateParams(com.emc.storageos.model.file.FileNfsACLUpdateParams) ViPRHttpException(com.emc.vipr.client.exceptions.ViPRHttpException) FlashException(controllers.util.FlashException) ServiceErrorException(com.emc.vipr.client.exceptions.ServiceErrorException)

Example 5 with FileNfsACLUpdateParams

use of com.emc.storageos.model.file.FileNfsACLUpdateParams in project coprhd-controller by CoprHD.

the class FileOrchestrationUtils method getFileNfsACLUpdateParamWithSubDir.

public static FileNfsACLUpdateParams getFileNfsACLUpdateParamWithSubDir(String fsPath, FileShare fs) {
    FileNfsACLUpdateParams params = new FileNfsACLUpdateParams();
    if (!fsPath.equals(fs.getPath())) {
        // Sub directory NFS ACL
        String subDir = fsPath.split(fs.getPath())[1];
        params.setSubDir(subDir.substring(1));
    }
    return params;
}
Also used : FileNfsACLUpdateParams(com.emc.storageos.model.file.FileNfsACLUpdateParams)

Aggregations

FileNfsACLUpdateParams (com.emc.storageos.model.file.FileNfsACLUpdateParams)7 NfsACE (com.emc.storageos.model.file.NfsACE)4 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)4 FlashException (controllers.util.FlashException)4 ServiceErrorException (com.emc.vipr.client.exceptions.ServiceErrorException)2 ViPRHttpException (com.emc.vipr.client.exceptions.ViPRHttpException)2 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 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 List (java.util.List)1