Search in sources :

Example 21 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class FileDeviceController method delete.

@Override
public void delete(URI storage, URI pool, URI uri, boolean forceDelete, String deleteType, String opId) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(uri, opId);
    StorageSystem storageObj = null;
    FileObject fileObject = null;
    FileShare fsObj = null;
    Snapshot snapshotObj = null;
    try {
        storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        String[] params = { storage.toString(), uri.toString(), String.valueOf(forceDelete), deleteType };
        _log.info("Delete : storage : {}, URI : {}, forceDelete : {}, delete_type : {} ", params);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        boolean isFile = false;
        args.setOpId(opId);
        if (URIUtil.isType(uri, FileShare.class)) {
            isFile = true;
            args.setForceDelete(forceDelete);
            fsObj = _dbClient.queryObject(FileShare.class, uri);
            setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
            fileObject = fsObj;
            args.addFileShare(fsObj);
            args.setFileOperation(isFile);
            BiosCommandResult result;
            WorkflowStepCompleter.stepExecuting(opId);
            if (FileControllerConstants.DeleteTypeEnum.VIPR_ONLY.toString().equalsIgnoreCase(deleteType) && !fsObj.getInactive()) {
                result = BiosCommandResult.createSuccessfulResult();
            } else {
                if (!fsObj.getInactive()) {
                    // Acquire lock for VNXFILE Storage System
                    acquireStepLock(storageObj, opId);
                    result = getDevice(storageObj.getSystemType()).doDeleteFS(storageObj, args);
                } else {
                    result = BiosCommandResult.createSuccessfulResult();
                }
            }
            // In case of VNXe
            if (result.getCommandPending()) {
                return;
            }
            fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
            if (result.isCommandSuccess() && (FileControllerConstants.DeleteTypeEnum.FULL.toString().equalsIgnoreCase(deleteType))) {
                fsObj.setInactive(true);
                if (forceDelete) {
                    // Delete Snapshot and its references from DB
                    doDeleteSnapshotsFromDB(fsObj, true, null, args);
                    args.addQuotaDirectory(null);
                    // Delete Quota Directory from DB
                    doFSDeleteQuotaDirsFromDB(args);
                    // Delete CIFS Share ACLs from DB
                    deleteShareACLsFromDB(args);
                    // Delete Export Rules from DB
                    doDeleteExportRulesFromDB(true, null, args);
                    // Remove FileShare Reference from File Policy
                    doDeletePolicyReferenceFromDB(fsObj);
                }
                WorkflowStepCompleter.stepSucceded(opId);
            } else if (!result.getCommandPending() && FileControllerConstants.DeleteTypeEnum.FULL.toString().equalsIgnoreCase(deleteType)) {
                WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
            }
            if (result.isCommandSuccess() && (FileControllerConstants.DeleteTypeEnum.VIPR_ONLY.toString().equalsIgnoreCase(deleteType))) {
                boolean snapshotsExist = snapshotsExistsOnFS(fsObj);
                boolean quotaDirsExist = quotaDirectoriesExistsOnFS(fsObj);
                boolean policyExists = fileProtectionPoliciesExistsOnFS(fsObj);
                boolean fsCheck = getDevice(storageObj.getSystemType()).doCheckFSExists(storageObj, args);
                if (fsCheck) {
                    String errMsg = null;
                    if (snapshotsExist) {
                        errMsg = new String("delete file system from ViPR database failed because snapshots exist for file system " + fsObj.getLabel() + " and once deleted the snapshot cannot be ingested into ViPR");
                    } else if (quotaDirsExist && !quotaDirectoryIngestionSupported(storageObj.getSystemType())) {
                        errMsg = new String("delete file system from ViPR database failed because quota directories exist for file system " + fsObj.getLabel() + " and once deleted the quota directory cannot be ingested into ViPR");
                    } else if (policyExists) {
                        errMsg = new String("delete file system from ViPR database failed because file protection policies exist for file system " + fsObj.getLabel() + " and once deleted the policy cannot be ingested into ViPR");
                    }
                    if (errMsg != null) {
                        _log.error(errMsg);
                        final ServiceCoded serviceCoded = DeviceControllerException.errors.jobFailedOpMsg(OperationTypeEnum.DELETE_FILE_SYSTEM.toString(), errMsg);
                        result = BiosCommandResult.createErrorResult(serviceCoded);
                        fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
                        recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM, result.isCommandSuccess(), "", "", fsObj, storageObj);
                        _dbClient.updateObject(fsObj);
                        WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
                        return;
                    }
                }
                // Delete Snapshot and its references from DB
                doDeleteSnapshotsFromDB(fsObj, true, null, args);
                args.addQuotaDirectory(null);
                doFSDeleteQuotaDirsFromDB(args);
                deleteShareACLsFromDB(args);
                doDeleteExportRulesFromDB(true, null, args);
                // Remove FileShare Reference from File Policy
                doDeletePolicyReferenceFromDB(fsObj);
                SMBShareMap cifsSharesMap = fsObj.getSMBFileShares();
                if (cifsSharesMap != null && !cifsSharesMap.isEmpty()) {
                    cifsSharesMap.clear();
                }
                fsObj.setInactive(true);
                WorkflowStepCompleter.stepSucceded(opId);
            } else if (!result.getCommandPending() && FileControllerConstants.DeleteTypeEnum.VIPR_ONLY.toString().equalsIgnoreCase(deleteType)) {
                WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
            }
            _dbClient.updateObject(fsObj);
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM, result.isCommandSuccess(), "", "", fsObj, storageObj);
        } else {
            snapshotObj = _dbClient.queryObject(Snapshot.class, uri);
            fileObject = snapshotObj;
            args.addSnapshot(snapshotObj);
            fsObj = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
            setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
            args.addFileShare(fsObj);
            args.setFileOperation(isFile);
            WorkflowStepCompleter.stepExecuting(opId);
            // Acquire lock for VNXFILE Storage System
            acquireStepLock(storageObj, opId);
            BiosCommandResult result = getDevice(storageObj.getSystemType()).doDeleteSnapshot(storageObj, args);
            if (result.getCommandPending()) {
                return;
            }
            if (!result.isCommandSuccess() && !result.getCommandPending()) {
                WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
            }
            snapshotObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
            if (result.isCommandSuccess()) {
                WorkflowStepCompleter.stepSucceded(opId);
                snapshotObj.setInactive(true);
                // delete the corresponding export rules if available.
                args.addSnapshot(snapshotObj);
                doDeleteExportRulesFromDB(true, null, args);
            }
            _dbClient.updateObject(snapshotObj);
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SNAPSHOT, result.isCommandSuccess(), "", "", snapshotObj, fsObj, storageObj);
        }
    } catch (Exception e) {
        String[] params = { storage.toString(), uri.toString(), String.valueOf(forceDelete), e.getMessage() };
        _log.error("Unable to delete file system or snapshot: storage {}, FS/snapshot {}, forceDelete {}: {}", params);
        updateTaskStatus(opId, fileObject, e);
        // work flow fail for fileshare delete
        if (URIUtil.isType(uri, FileShare.class)) {
            ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
            WorkflowStepCompleter.stepFailed(opId, serviceError);
        }
        if (URIUtil.isType(uri, FileShare.class)) {
            if ((fsObj != null) && (storageObj != null)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM, false, e.getMessage(), "", fsObj, storageObj);
            }
        } else {
            if ((fsObj != null) && (storageObj != null) && (snapshotObj != null)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fsObj, storageObj);
            }
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) Snapshot(com.emc.storageos.db.client.model.Snapshot) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) FileObject(com.emc.storageos.db.client.model.FileObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 22 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class NativeGUIDGenerator method generateNativeGuidForQuotaDir.

public static String generateNativeGuidForQuotaDir(DbClient dbClient, String quotaDirName, URI fsURI) throws IOException {
    FileShare fs = dbClient.queryObject(FileShare.class, fsURI);
    StorageSystem device = dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    return String.format("%s+%s+%s+" + QUOTADIRECTORY + "+%s", _deviceTypeMap.get(device.getSystemType()), device.getSerialNumber(), fs.getName(), quotaDirName);
}
Also used : FileShare(com.emc.storageos.db.client.model.FileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 23 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class FileOrchestrationDeviceController method failbackFileSystem.

@Override
public void failbackFileSystem(URI fsURI, StoragePort nfsPort, StoragePort cifsPort, boolean replicateConfiguration, String taskId) throws ControllerException {
    FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
    Workflow workflow = null;
    String stepDescription = null;
    try {
        FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
        List<String> targetfileUris = new ArrayList<String>();
        targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
        FileShare targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        StorageSystem systemSource = s_dbClient.queryObject(StorageSystem.class, sourceFileShare.getStorageDevice());
        workflow = this._workflowService.getNewWorkflow(this, FAILBACK_FILESYSTEMS_WF_NAME, false, taskId, completer);
        // Failback from Target File System
        s_logger.info("Generating steps for Failback Source File System from Target");
        String failbackStep = workflow.createStepId();
        stepDescription = String.format("Failback to source file System : %s from target system : %s.", sourceFileShare.getName(), targetFileShare.getName());
        Workflow.Method failbackMethod = new Workflow.Method(FAILBACK_FILE_SYSTEM_METHOD, systemSource.getId(), sourceFileShare.getId());
        String waitForFailback = workflow.createStep(null, stepDescription, null, systemSource.getId(), systemSource.getSystemType(), getClass(), failbackMethod, null, failbackStep);
        // Replicate directory quota setting
        stepDescription = String.format("Replicating directory quota settings from source file system : %s to file target system : %s", sourceFileShare.getId(), targetFileShare.getId());
        Workflow.Method replicateDirQuotaSettingsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_DIRECTORY_QUOTA_SETTINGS_METHOD, systemSource.getId(), targetFileShare.getId());
        String replicateDirQuotaSettingsStep = workflow.createStepId();
        workflow.createStep(null, stepDescription, waitForFailback, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateDirQuotaSettingsMethod, null, replicateDirQuotaSettingsStep);
        if (replicateConfiguration) {
            Map<String, List<NfsACE>> sourceNFSACL = FileOrchestrationUtils.queryNFSACL(sourceFileShare, s_dbClient);
            Map<String, List<NfsACE>> targetNFSACL = FileOrchestrationUtils.queryNFSACL(targetFileShare, s_dbClient);
            if (!sourceNFSACL.isEmpty() || !targetNFSACL.isEmpty()) {
                stepDescription = String.format("Replicating NFS ACL from source file system : %s to file target system : %s", sourceFileShare.getId(), targetFileShare.getId());
                Workflow.Method replicateNFSACLsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_ACLS_METHOD, systemSource.getId(), targetFileShare.getId());
                String replicateNFSACLsStep = workflow.createStepId();
                workflow.createStep(null, stepDescription, waitForFailback, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateNFSACLsMethod, null, replicateNFSACLsStep);
            }
            // Replicate NFS export and rules to Target Cluster.
            FSExportMap targetnfsExportMap = targetFileShare.getFsExports();
            FSExportMap sourcenfsExportMap = sourceFileShare.getFsExports();
            if (!(targetnfsExportMap == null && sourcenfsExportMap == null)) {
                // Both source and target export map shouldn't be null
                stepDescription = String.format("Replicating NFS exports from target file system : %s to source file system : %s", targetFileShare.getId(), sourceFileShare.getId());
                Workflow.Method replicateNFSExportMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_EXPORT_METHOD, systemSource.getId(), targetFileShare.getId(), nfsPort);
                String replicateNFSExportStep = workflow.createStepId();
                String waitForExport = workflow.createStep(null, stepDescription, waitForFailback, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateNFSExportMethod, null, replicateNFSExportStep);
                stepDescription = String.format("Replicating NFS export rules from target file system : %s to source file system : %s", targetFileShare.getId(), sourceFileShare.getId());
                Workflow.Method replicateNFSExportRulesMethod = new Workflow.Method(REPLICATE_FILESYSTEM_NFS_EXPORT_RULE_METHOD, systemSource.getId(), targetFileShare.getId());
                String replicateNFSExportRulesStep = workflow.createStepId();
                workflow.createStep(null, stepDescription, waitForExport, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateNFSExportRulesMethod, null, replicateNFSExportRulesStep);
            }
            // Replicate CIFS shares and ACLs from Target File System to Source.
            SMBShareMap targetSMBShareMap = targetFileShare.getSMBFileShares();
            SMBShareMap sourceSMBShareMap = sourceFileShare.getSMBFileShares();
            if (!(targetSMBShareMap == null && sourceSMBShareMap == null)) {
                // Both source and target share map shouldn't be null
                stepDescription = String.format("Replicating CIFS shares from target file system : %s to file source system : %s", targetFileShare.getId(), sourceFileShare.getId());
                Workflow.Method replicateCIFSShareMethod = new Workflow.Method(REPLICATE_FILESYSTEM_CIFS_SHARES_METHOD, systemSource.getId(), targetFileShare.getId(), cifsPort);
                String replicateCIFSShareStep = workflow.createStepId();
                String waitForShare = workflow.createStep(null, stepDescription, waitForFailback, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateCIFSShareMethod, null, replicateCIFSShareStep);
                stepDescription = String.format("Replicating CIFS share ACLs from target file system : %s to source file system : %s", targetFileShare.getId(), sourceFileShare.getId());
                Workflow.Method replicateCIFSShareACLsMethod = new Workflow.Method(REPLICATE_FILESYSTEM_CIFS_SHARE_ACLS_METHOD, systemSource.getId(), targetFileShare.getId());
                String replicateCIFSShareACLsStep = workflow.createStepId();
                workflow.createStep(null, stepDescription, waitForShare, systemSource.getId(), systemSource.getSystemType(), getClass(), replicateCIFSShareACLsMethod, null, replicateCIFSShareACLsStep);
            }
        }
        String successMessage = "Failback FileSystem successful for: " + sourceFileShare.getLabel();
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error("Could not failback filesystems: " + fsURI, ex);
        String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILBACK.getName();
        ServiceError serviceError = DeviceControllerException.errors.createFileSharesFailed(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) 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) List(java.util.List) ArrayList(java.util.ArrayList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 24 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class FileOrchestrationDeviceController method assignFilePolicyToFileSystem.

@Override
public void assignFilePolicyToFileSystem(FilePolicy filePolicy, List<FileDescriptor> fileDescriptors, String taskId) throws ControllerException {
    FileShare sourceFS = null;
    Workflow workflow = null;
    List<URI> fsURIs = FileDescriptor.getFileSystemURIs(fileDescriptors);
    FileSystemAssignPolicyWorkflowCompleter completer = new FileSystemAssignPolicyWorkflowCompleter(filePolicy.getId(), fsURIs, taskId);
    try {
        workflow = _workflowService.getNewWorkflow(this, ASSIGN_FILE_POLICY_TO_FS_WF_NAME, false, taskId);
        String waitFor = null;
        s_logger.info("Generating steps for creating mirror filesystems...");
        for (FileDescriptor fileDescriptor : fileDescriptors) {
            if (fileDescriptor.getType().toString().equals(FileDescriptor.Type.FILE_EXISTING_MIRROR_SOURCE.name()) || fileDescriptor.getType().toString().equals(FileDescriptor.Type.FILE_EXISTING_SOURCE.name())) {
                sourceFS = s_dbClient.queryObject(FileShare.class, fileDescriptor.getFsURI());
                break;
            }
        }
        // then we have to create mirror file system first..
        if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
            waitFor = _fileDeviceController.addStepsForCreateFileSystems(workflow, waitFor, fileDescriptors, taskId);
        }
        // 2. Apply the file protection policy
        String stepDescription = String.format("applying file policy : %s  for file system : %s", filePolicy.getId(), sourceFS.getId());
        String applyFilePolicyStep = workflow.createStepId();
        Object[] args = new Object[] { sourceFS.getStorageDevice(), sourceFS.getId(), filePolicy.getId() };
        _fileDeviceController.createMethod(workflow, waitFor, APPLY_FILE_POLICY_METHOD, applyFilePolicyStep, stepDescription, sourceFS.getStorageDevice(), args);
        // Finish up and execute the plan.
        String successMessage = String.format("Assigning file policy : %s, to file system: %s successful.", filePolicy.getId(), sourceFS.getId());
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error(String.format("Assigning file policy : %s to file system : %s failed", filePolicy.getId(), sourceFS.getId()), ex);
        ServiceError serviceError = DeviceControllerException.errors.assignFilePolicyFailed(filePolicy.toString(), FilePolicyApplyLevel.file_system.name(), ex);
        completer.error(s_dbClient, _locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FileSystemAssignPolicyWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FileSystemAssignPolicyWorkflowCompleter) Workflow(com.emc.storageos.workflow.Workflow) FileObject(com.emc.storageos.db.client.model.FileObject) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) 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)

Example 25 with FileShare

use of com.emc.storageos.db.client.model.FileShare 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)

Aggregations

FileShare (com.emc.storageos.db.client.model.FileShare)289 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)155 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)107 URI (java.net.URI)93 ArrayList (java.util.ArrayList)79 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)73 ControllerException (com.emc.storageos.volumecontroller.ControllerException)65 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)61 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)57 Operation (com.emc.storageos.db.client.model.Operation)56 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)56 URISyntaxException (java.net.URISyntaxException)56 Path (javax.ws.rs.Path)56 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)52 Produces (javax.ws.rs.Produces)51 Snapshot (com.emc.storageos.db.client.model.Snapshot)50 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)49 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)45 WorkflowException (com.emc.storageos.workflow.WorkflowException)42 NamedURI (com.emc.storageos.db.client.model.NamedURI)36