Search in sources :

Example 31 with ServiceError

use of com.emc.storageos.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.

the class FileOrchestrationDeviceController method updateShareACLs.

@Override
public void updateShareACLs(URI storage, URI uri, String shareName, CifsShareACLUpdateParams param, String opId) throws ControllerException {
    FileObject fileObj = null;
    String stepDescription = null;
    String successMessage = null;
    String opName = null;
    TaskCompleter completer = null;
    if (URIUtil.isType(uri, FileShare.class)) {
        completer = new FileWorkflowCompleter(uri, opId);
        fileObj = s_dbClient.queryObject(FileShare.class, uri);
        stepDescription = String.format("Updating file system : %s share : %s  ACLs: %s", uri, shareName, param.toString());
        successMessage = String.format("Updating file system : %s share : %s  ACLs: %s finished successfully.", uri, shareName, param.toString());
        opName = ResourceOperationTypeEnum.UPDATE_FILE_SYSTEM_SHARE_ACL.getName();
    } else {
        completer = new FileSnapshotWorkflowCompleter(uri, opId);
        fileObj = s_dbClient.queryObject(Snapshot.class, uri);
        stepDescription = String.format("Updating file system snapshot : %s share : %s  ACLs: %s", uri, shareName, param.toString());
        successMessage = String.format("Updating file system snapshot : %s share : %s  ACLs: %s finished successfully.", uri, shareName, param.toString());
        opName = ResourceOperationTypeEnum.UPDATE_FILE_SNAPSHOT_SHARE_ACL.getName();
    }
    try {
        Workflow workflow = _workflowService.getNewWorkflow(this, UPDATE_FILESYSTEM_CIFS_SHARE_ACLS_WF_NAME, false, opId, completer);
        String shareACLUpdateStep = workflow.createStepId();
        Object[] args = new Object[] { storage, uri, shareName, param };
        _fileDeviceController.createMethod(workflow, null, UPDATE_FILESYSTEM_SHARE_ACLS_METHOD, shareACLUpdateStep, stepDescription, storage, args);
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error(String.format("Updating file system : %s share : %s  ACLs: %s failed.", uri, shareName, param.toString()), ex);
        ServiceError serviceError = DeviceControllerException.errors.updateFileShareCIFSACLsFailed(fileObj.toString(), opName, ex);
        completer.error(s_dbClient, _locker, serviceError);
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FileWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FileWorkflowCompleter) FileSnapshotWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FileSnapshotWorkflowCompleter) Workflow(com.emc.storageos.workflow.Workflow) FileObject(com.emc.storageos.db.client.model.FileObject) FileObject(com.emc.storageos.db.client.model.FileObject) VNXeFSSnapshotTaskCompleter(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFSSnapshotTaskCompleter) MirrorFileFailoverTaskCompleter(com.emc.storageos.volumecontroller.impl.file.MirrorFileFailoverTaskCompleter) MirrorFileFailbackTaskCompleter(com.emc.storageos.volumecontroller.impl.file.MirrorFileFailbackTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) 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)

Example 32 with ServiceError

use of com.emc.storageos.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.

the class FileOrchestrationDeviceController method deleteFileSystems.

/*
     * (non-Javadoc)
     * 
     * @see com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController#deleteFileSystems(java.util.List,
     * java.lang.String)
     */
/**
 * Deletes one or more filesystem.
 *
 * @param fileDescriptors
 * @param taskId
 * @throws ControllerException
 */
@Override
public void deleteFileSystems(List<FileDescriptor> fileDescriptors, String taskId) throws ControllerException {
    List<URI> fileShareUris = FileDescriptor.getFileSystemURIs(fileDescriptors);
    FileDeleteWorkflowCompleter completer = new FileDeleteWorkflowCompleter(fileShareUris, taskId);
    Workflow workflow = null;
    try {
        // Generate the Workflow.
        workflow = _workflowService.getNewWorkflow(this, DELETE_FILESYSTEMS_WF_NAME, false, taskId);
        // call the FileDeviceController to add its delete methods.
        _fileDeviceController.addStepsForDeleteFileSystems(workflow, null, fileDescriptors, taskId);
        // Finish up and execute the plan.
        // The Workflow will handle the TaskCompleter
        String successMessage = "Delete FileShares successful for: " + fileShareUris.toString();
        Object[] callbackArgs = new Object[] { fileShareUris };
        workflow.executePlan(completer, successMessage, new WorkflowCallback(), callbackArgs, null, null);
    } catch (Exception ex) {
        s_logger.error("Could not delete FileShares: " + fileShareUris, ex);
        releaseWorkflowLocks(workflow);
        String opName = ResourceOperationTypeEnum.DELETE_FILE_SYSTEM.getName();
        ServiceError serviceError = DeviceControllerException.errors.deleteFileSharesFailed(fileShareUris.toString(), opName, ex);
        completer.error(s_dbClient, _locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FileDeleteWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FileDeleteWorkflowCompleter) Workflow(com.emc.storageos.workflow.Workflow) FileObject(com.emc.storageos.db.client.model.FileObject) 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 33 with ServiceError

use of com.emc.storageos.svcs.errorhandling.model.ServiceError in project coprhd-controller by CoprHD.

the class FileOrchestrationDeviceController method updateFileProtectionPolicy.

@Override
public void updateFileProtectionPolicy(URI policy, FilePolicyUpdateParam param, String taskId) {
    FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, policy);
    String opName = ResourceOperationTypeEnum.UPDATE_FILE_PROTECTION_POLICY.getName();
    FileProtectionPolicyUpdateCompleter completer = new FileProtectionPolicyUpdateCompleter(policy, taskId);
    try {
        String waitFor = null;
        Workflow workflow = _workflowService.getNewWorkflow(this, UPDATE_FILE_POLICY_WF_NAME, false, taskId, completer);
        completer.setWorkFlowId(workflow.getWorkflowURI());
        // Get the file policy storage resources!!!
        List<PolicyStorageResource> policyStorageResources = FileOrchestrationUtils.getFilePolicyStorageResources(s_dbClient, filePolicy);
        if (policyStorageResources != null && !policyStorageResources.isEmpty()) {
            s_logger.info("Generating steps for updating file policy {} ", filePolicy.getFilePolicyName());
            for (PolicyStorageResource policyStorageRes : policyStorageResources) {
                StorageSystem system = s_dbClient.queryObject(StorageSystem.class, policyStorageRes.getStorageSystem());
                String stepId = workflow.createStepId();
                String stepDes = String.format("Updating policy on storage system %s, at path: %s", system.getLabel(), policyStorageRes.getResourcePath());
                Object[] args = new Object[] { policyStorageRes.getStorageSystem(), policy, policyStorageRes.getId(), param };
                // Try to update all storage system policies
                // Dont use waitFor for next step!!!
                _fileDeviceController.createMethod(workflow, waitFor, UPDATE_STORAGE_SYSTEM_FILE_PROTECTION_POLICY_METHOD, stepId, stepDes, policyStorageRes.getStorageSystem(), args);
            }
            String successMessage = String.format("Updating file policy {} is successful.", filePolicy.getFilePolicyName());
            workflow.executePlan(completer, successMessage);
        } else {
            s_logger.info("No File Policy Storage resource for policy {} to update", filePolicy.getFilePolicyName());
        }
    } catch (Exception ex) {
        s_logger.error(String.format("Updating file protection policy {} failed", filePolicy.getFilePolicyName()), ex);
        ServiceError serviceError = DeviceControllerException.errors.updateFilePolicyFailed(filePolicy.toString(), ex);
        completer.error(s_dbClient, _locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileProtectionPolicyUpdateCompleter(com.emc.storageos.volumecontroller.impl.file.FileProtectionPolicyUpdateCompleter) Workflow(com.emc.storageos.workflow.Workflow) FileObject(com.emc.storageos.db.client.model.FileObject) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 34 with ServiceError

use of com.emc.storageos.svcs.errorhandling.model.ServiceError 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 35 with ServiceError

use of com.emc.storageos.svcs.errorhandling.model.ServiceError 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

ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)707 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)625 ControllerException (com.emc.storageos.volumecontroller.ControllerException)345 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)289 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)270 WorkflowException (com.emc.storageos.workflow.WorkflowException)258 URI (java.net.URI)250 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)246 ArrayList (java.util.ArrayList)238 Volume (com.emc.storageos.db.client.model.Volume)206 Workflow (com.emc.storageos.workflow.Workflow)127 WBEMException (javax.wbem.WBEMException)124 CIMObjectPath (javax.cim.CIMObjectPath)118 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)113 ExportMask (com.emc.storageos.db.client.model.ExportMask)107 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)105 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)104 URISyntaxException (java.net.URISyntaxException)94 HashMap (java.util.HashMap)86 NamedURI (com.emc.storageos.db.client.model.NamedURI)82