Search in sources :

Example 1 with CifsShareACLUpdateParams

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

Aggregations

FileShare (com.emc.storageos.db.client.model.FileShare)1 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)1 SMBShareMap (com.emc.storageos.db.client.model.SMBShareMap)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 CifsShareACLUpdateParams (com.emc.storageos.model.file.CifsShareACLUpdateParams)1 ShareACL (com.emc.storageos.model.file.ShareACL)1 ShareACLs (com.emc.storageos.model.file.ShareACLs)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