Search in sources :

Example 6 with ShareACLs

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

the class FileOrchestrationDeviceController method addStepsToReplicateCIFSShareACLs.

/**
 * Child workflow for replicating source file system CIFS ACLs 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 addStepsToReplicateCIFSShareACLs(URI systemTarget, URI fsURI, String taskId) {
    s_logger.info("Generating steps for Replicating CIFS share ACLs to Target Cluster");
    CifsShareACLUpdateParams params;
    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_CIFS_SHARE_ACLS_TO_TARGET_WF_NAME, false, taskId, completer);
        SMBShareMap sourceSMBShareMap = sourceFileShare.getSMBFileShares();
        if (sourceSMBShareMap != null) {
            List<SMBFileShare> sourceSMBShares = new ArrayList<SMBFileShare>(sourceSMBShareMap.values());
            for (SMBFileShare sourceSMBShare : sourceSMBShares) {
                List<ShareACL> sourceShareACLs = FileOrchestrationUtils.queryShareACLs(sourceSMBShare.getName(), sourceFileShare.getId(), s_dbClient);
                List<ShareACL> targetShareACLs = FileOrchestrationUtils.queryShareACLs(sourceSMBShare.getName(), targetFileShare.getId(), s_dbClient);
                if (!sourceShareACLs.isEmpty() && targetShareACLs.isEmpty()) {
                    // target share doesn't have any ACLs but corresponding share on source does have ACL
                    params = new CifsShareACLUpdateParams();
                    ShareACLs shareACLs = new ShareACLs();
                    shareACLs.setShareACLs(sourceShareACLs);
                    params.setAclsToAdd(shareACLs);
                    updateCIFSShareACLOnTarget(workflow, systemTarget, targetFileShare, sourceSMBShare, params);
                } else if (!targetShareACLs.isEmpty() && sourceShareACLs.isEmpty()) {
                    // source share doesn't have any ACLs but corresponding share on target does have ACL
                    params = new CifsShareACLUpdateParams();
                    ShareACLs shareACLs = new ShareACLs();
                    shareACLs.setShareACLs(targetShareACLs);
                    // TO FIX COP-26361 DU case
                    // params.setAclsToDelete(shareACLs);
                    updateCIFSShareACLOnTarget(workflow, systemTarget, targetFileShare, sourceSMBShare, params);
                } else if (!targetShareACLs.isEmpty() && !sourceShareACLs.isEmpty()) {
                    // both source and target share have some ACL
                    List<ShareACL> shareACLsToAdd = new ArrayList<ShareACL>();
                    List<ShareACL> shareACLsToDelete = new ArrayList<ShareACL>();
                    List<ShareACL> shareACLsToModify = new ArrayList<ShareACL>();
                    HashMap<String, ShareACL> sourceShareACLMap = FileOrchestrationUtils.getShareACLMap(sourceShareACLs);
                    HashMap<String, ShareACL> targetShareACLMap = FileOrchestrationUtils.getShareACLMap(targetShareACLs);
                    // ACLs To Add
                    for (String sourceACLName : sourceShareACLMap.keySet()) {
                        if (targetShareACLMap.get(sourceACLName) == null) {
                            ShareACL shareACL = sourceShareACLMap.get(sourceACLName);
                            shareACL.setFileSystemId(targetFileShare.getId());
                            shareACLsToAdd.add(shareACL);
                        }
                    }
                    // ACLs To Delete
                    for (String targetACLName : targetShareACLMap.keySet()) {
                        if (sourceShareACLMap.get(targetACLName) == null) {
                            shareACLsToDelete.add(targetShareACLMap.get(targetACLName));
                        }
                    }
                    // ACLs to Modify
                    targetShareACLs.removeAll(shareACLsToDelete);
                    sourceShareACLs.removeAll(shareACLsToAdd);
                    sourceShareACLMap = FileOrchestrationUtils.getShareACLMap(sourceShareACLs);
                    targetShareACLMap = FileOrchestrationUtils.getShareACLMap(targetShareACLs);
                    for (String sourceACLName : sourceShareACLMap.keySet()) {
                        if (targetShareACLMap.get(sourceACLName) != null && !targetShareACLMap.get(sourceACLName).getPermission().equals(sourceShareACLMap.get(sourceACLName).getPermission())) {
                            ShareACL shareACL = targetShareACLMap.get(sourceACLName);
                            shareACL.setPermission(sourceShareACLMap.get(sourceACLName).getPermission());
                            shareACLsToModify.add(shareACL);
                        }
                    }
                    params = new CifsShareACLUpdateParams();
                    if (!shareACLsToAdd.isEmpty()) {
                        ShareACLs addShareACLs = new ShareACLs();
                        addShareACLs.setShareACLs(shareACLsToAdd);
                        params.setAclsToAdd(addShareACLs);
                    }
                    if (!shareACLsToDelete.isEmpty()) {
                        ShareACLs deleteShareACLs = new ShareACLs();
                        deleteShareACLs.setShareACLs(shareACLsToDelete);
                    // TO FIX COP-26361 DU case
                    // params.setAclsToDelete(deleteShareACLs);
                    }
                    if (!shareACLsToModify.isEmpty()) {
                        ShareACLs modifyShareACLs = new ShareACLs();
                        modifyShareACLs.setShareACLs(shareACLsToModify);
                        params.setAclsToModify(modifyShareACLs);
                    }
                    if (params.retrieveAllACLs() != null && !params.retrieveAllACLs().isEmpty()) {
                        updateCIFSShareACLOnTarget(workflow, systemTarget, targetFileShare, sourceSMBShare, params);
                    }
                }
            }
        }
        String successMessage = String.format("Replicating source File System : %s, CIFS Shares ACLs to Target System finished successfully", sourceFileShare.getLabel());
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error("Could not replicate source filesystem CIFS shares ACLs : " + fsURI, ex);
        String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
        ServiceError serviceError = DeviceControllerException.errors.updateFileShareCIFSACLsFailed(fsURI.toString(), opName, ex);
        completer.error(s_dbClient, this._locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) ArrayList(java.util.ArrayList) CifsShareACLUpdateParams(com.emc.storageos.model.file.CifsShareACLUpdateParams) Workflow(com.emc.storageos.workflow.Workflow) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) ShareACL(com.emc.storageos.model.file.ShareACL) 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) ShareACLs(com.emc.storageos.model.file.ShareACLs) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 7 with ShareACLs

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

the class FileService method getShareACLs.

/**
 * Get File Share ACLs
 *
 * @param id
 *            the file system URI
 * @param shareName
 *            name of the share
 * @brief Show the ACLs for a file share
 * @return ShareACLs
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares/{shareName}/acl")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public ShareACLs getShareACLs(@PathParam("id") URI id, @PathParam("shareName") String shareName) {
    _log.info("Request recieved to get ACLs with Id: {}  shareName: {}", id, shareName);
    // Validate the FS id
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    ArgValidator.checkFieldNotNull(shareName, "shareName");
    FileShare fs = queryResource(id);
    if (!CifsShareUtility.doesShareExist(fs, shareName)) {
        _log.error("CIFS share does not exist {}", shareName);
        throw APIException.notFound.invalidParameterObjectHasNoSuchShare(fs.getId(), shareName);
    }
    ShareACLs acls = new ShareACLs();
    CifsShareUtility util = new CifsShareUtility(_dbClient, fs, null, shareName);
    List<ShareACL> shareAclList = util.queryExistingShareACLs();
    _log.info("Number of existing ACLs found : {} ", shareAclList.size());
    if (!shareAclList.isEmpty()) {
        acls.setShareACLs(shareAclList);
    }
    return acls;
}
Also used : ShareACLs(com.emc.storageos.model.file.ShareACLs) CifsShareUtility(com.emc.storageos.api.service.impl.resource.utils.CifsShareUtility) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) ShareACL(com.emc.storageos.model.file.ShareACL) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 8 with ShareACLs

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

the class SetFileSnapshotShareACL method doExecute.

@Override
protected Task<FileSnapshotRestRep> doExecute() throws Exception {
    SnapshotCifsShareACLUpdateParams aclUpdate = new SnapshotCifsShareACLUpdateParams();
    ShareACLs shareACLs = FileStorageUtils.createShareACLs(acls);
    aclUpdate.setAclsToAdd(shareACLs);
    return getClient().fileSnapshots().updateShareACL(fileSystemId, shareName, aclUpdate);
}
Also used : SnapshotCifsShareACLUpdateParams(com.emc.storageos.model.file.SnapshotCifsShareACLUpdateParams) ShareACLs(com.emc.storageos.model.file.ShareACLs)

Example 9 with ShareACLs

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

the class SetFileSystemShareACL method doExecute.

@Override
protected Task<FileShareRestRep> doExecute() throws Exception {
    FileCifsShareACLUpdateParams aclUpdate = new FileCifsShareACLUpdateParams();
    ShareACLs aclsToAdd = FileStorageUtils.createShareACLs(acls);
    aclUpdate.setAclsToAdd(aclsToAdd);
    return getClient().fileSystems().updateShareACL(fileSystemId, shareName, aclUpdate);
}
Also used : FileCifsShareACLUpdateParams(com.emc.storageos.model.file.FileCifsShareACLUpdateParams) ShareACLs(com.emc.storageos.model.file.ShareACLs)

Example 10 with ShareACLs

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

the class FileSystems method createCifsShareAclParams.

private static FileCifsShareACLUpdateParams createCifsShareAclParams(String formData) {
    String[] uiAcls = formData.split(",");
    List<ShareACL> acls = new ArrayList<ShareACL>();
    for (String uiAce : uiAcls) {
        String[] uiData = uiAce.split("~~~");
        String uiType = uiData[0];
        String uiName = uiData[1];
        String uiDomain = uiData[2];
        String uiPermission = uiData[3];
        ShareACL shareAcl = new ShareACL();
        if ("GROUP".equalsIgnoreCase(uiType)) {
            shareAcl.setGroup(uiName);
        } else {
            shareAcl.setUser(uiName);
        }
        shareAcl.setPermission(uiPermission);
        if (uiDomain != null && !"".equals(uiDomain)) {
            shareAcl.setDomain(uiDomain);
        }
        acls.add(shareAcl);
    }
    FileCifsShareACLUpdateParams input = new FileCifsShareACLUpdateParams();
    ShareACLs aclsToAdd = new ShareACLs();
    aclsToAdd.setShareACLs(acls);
    input.setAclsToAdd(aclsToAdd);
    return input;
}
Also used : FileCifsShareACLUpdateParams(com.emc.storageos.model.file.FileCifsShareACLUpdateParams) ShareACLs(com.emc.storageos.model.file.ShareACLs) ArrayList(java.util.ArrayList) ShareACL(com.emc.storageos.model.file.ShareACL)

Aggregations

ShareACLs (com.emc.storageos.model.file.ShareACLs)16 ShareACL (com.emc.storageos.model.file.ShareACL)13 ArrayList (java.util.ArrayList)7 CifsShareACL (com.emc.storageos.db.client.model.CifsShareACL)4 FileCifsShareACLUpdateParams (com.emc.storageos.model.file.FileCifsShareACLUpdateParams)4 ShareACLOperationErrorType (com.emc.storageos.model.file.CifsShareACLUpdateParams.ShareACLOperationErrorType)3 SnapshotCifsShareACLUpdateParams (com.emc.storageos.model.file.SnapshotCifsShareACLUpdateParams)3 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)3 FlashException (controllers.util.FlashException)3 CifsShareUtility (com.emc.storageos.api.service.impl.resource.utils.CifsShareUtility)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2 ControllerException (com.emc.storageos.volumecontroller.ControllerException)2 WorkflowException (com.emc.storageos.workflow.WorkflowException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2