Search in sources :

Example 26 with ShareACL

use of com.emc.storageos.model.file.ShareACL 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 27 with ShareACL

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

the class FileOrchestrationUtils method queryShareACLs.

/**
 * This method queries ACLs for File System share.
 *
 * @param shareName Name of the share.
 * @param fs URI of the file system.
 * @param dbClient
 * @return ListShareACL
 */
public static List<ShareACL> queryShareACLs(String shareName, URI fs, DbClient dbClient) {
    List<ShareACL> aclList = new ArrayList<ShareACL>();
    ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileCifsShareAclsConstraint(fs);
    List<CifsShareACL> shareAclList = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, CifsShareACL.class, containmentConstraint);
    if (shareAclList != null) {
        Iterator<CifsShareACL> shareAclIter = shareAclList.iterator();
        while (shareAclIter.hasNext()) {
            CifsShareACL dbShareAcl = shareAclIter.next();
            if (shareName.equals(dbShareAcl.getShareName())) {
                ShareACL acl = new ShareACL();
                acl.setShareName(shareName);
                acl.setDomain(dbShareAcl.getDomain());
                acl.setUser(dbShareAcl.getUser());
                acl.setGroup(dbShareAcl.getGroup());
                acl.setPermission(dbShareAcl.getPermission());
                acl.setFileSystemId(fs);
                aclList.add(acl);
            }
        }
    }
    return aclList;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) ShareACL(com.emc.storageos.model.file.ShareACL) CifsShareACL(com.emc.storageos.db.client.model.CifsShareACL) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL) CifsShareACL(com.emc.storageos.db.client.model.CifsShareACL)

Example 28 with ShareACL

use of com.emc.storageos.model.file.ShareACL 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 29 with ShareACL

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

the class FileSnapshots method listSnapshotAclJson.

/**
 * This method called during population of Datatable for ACL data.
 *
 * @param aclURL
 *            URL of the file system share.
 */
public static void listSnapshotAclJson(String aclURL) {
    String snapshotId = null;
    String shareName = null;
    if (StringUtils.isNotBlank(aclURL)) {
        String[] parts = aclURL.split("/");
        if (parts.length == 7) {
            snapshotId = parts[3];
            shareName = parts[5];
        }
    }
    ViPRCoreClient client = BourneUtil.getViprClient();
    List<ShareACL> shareAcls = client.fileSnapshots().getShareACLs(uri(snapshotId), shareName);
    List<ShareACLDataTable.SnapshotAclInfo> acl = Lists.newArrayList();
    for (ShareACL shareAcl : shareAcls) {
        String userOrGroup = shareAcl.getUser();
        String type = SnapshotShareACLForm.USER;
        if (shareAcl.getGroup() != null && shareAcl.getGroup() != "") {
            type = SnapshotShareACLForm.GROUP;
            userOrGroup = shareAcl.getGroup();
        }
        acl.add(new ShareACLDataTable.SnapshotAclInfo(userOrGroup, type, shareAcl.getPermission(), snapshotId, shareName, shareAcl.getDomain()));
    }
    renderJSON(DataTablesSupport.createJSON(acl, params));
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) ShareACL(com.emc.storageos.model.file.ShareACL) ShareACLDataTable(models.datatable.ShareACLDataTable)

Example 30 with ShareACL

use of com.emc.storageos.model.file.ShareACL 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

ShareACL (com.emc.storageos.model.file.ShareACL)36 ArrayList (java.util.ArrayList)22 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)13 ShareACLs (com.emc.storageos.model.file.ShareACLs)13 ControllerException (com.emc.storageos.volumecontroller.ControllerException)13 CifsShareACL (com.emc.storageos.db.client.model.CifsShareACL)10 NetAppException (com.emc.storageos.netapp.NetAppException)9 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)7 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)7 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)5 NetAppCException (com.emc.storageos.netappc.NetAppCException)4 CifsAcl (com.iwave.ext.netapp.model.CifsAcl)4 NFSShareACL (com.emc.storageos.db.client.model.NFSShareACL)3 IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)3 IsilonSMBShare (com.emc.storageos.isilon.restapi.IsilonSMBShare)3 Permission (com.emc.storageos.isilon.restapi.IsilonSMBShare.Permission)3 ShareACLOperationErrorType (com.emc.storageos.model.file.CifsShareACLUpdateParams.ShareACLOperationErrorType)3 FileCifsShareACLUpdateParams (com.emc.storageos.model.file.FileCifsShareACLUpdateParams)3 NetAppApi (com.emc.storageos.netapp.NetAppApi)3 NetAppClusterApi (com.emc.storageos.netappc.NetAppClusterApi)3