Search in sources :

Example 1 with FileSystemAssignPolicyWorkflowCompleter

use of com.emc.storageos.volumecontroller.impl.file.FileSystemAssignPolicyWorkflowCompleter 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)

Aggregations

FileObject (com.emc.storageos.db.client.model.FileObject)1 FileShare (com.emc.storageos.db.client.model.FileShare)1 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)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 FileSystemAssignPolicyWorkflowCompleter (com.emc.storageos.volumecontroller.impl.file.FileSystemAssignPolicyWorkflowCompleter)1 Workflow (com.emc.storageos.workflow.Workflow)1 WorkflowException (com.emc.storageos.workflow.WorkflowException)1 URI (java.net.URI)1