Search in sources :

Example 1 with FilePolicyUnAssignWorkflowCompleter

use of com.emc.storageos.volumecontroller.impl.file.FilePolicyUnAssignWorkflowCompleter in project coprhd-controller by CoprHD.

the class FileOrchestrationDeviceController method unassignFilePolicy.

@Override
public void unassignFilePolicy(URI policy, Set<URI> unassignFrom, String taskId) throws InternalException {
    FilePolicy filePolicy = s_dbClient.queryObject(FilePolicy.class, policy);
    FilePolicyUnAssignWorkflowCompleter completer = new FilePolicyUnAssignWorkflowCompleter(policy, unassignFrom, taskId);
    try {
        Workflow workflow = _workflowService.getNewWorkflow(this, UNASSIGN_FILE_POLICY_WF_NAME, false, taskId, completer);
        completer.setWorkFlowId(workflow.getWorkflowURI());
        s_logger.info("Generating steps for unassigning file policy {} from resources", policy);
        Set<String> policyResources = filePolicy.getPolicyStorageResources();
        if (policyResources != null && !policyResources.isEmpty()) {
            for (URI uri : unassignFrom) {
                for (String policyResource : policyResources) {
                    PolicyStorageResource policyStorage = s_dbClient.queryObject(PolicyStorageResource.class, URI.create(policyResource));
                    if (policyStorage.getAppliedAt().toString().equals(uri.toString())) {
                        StorageSystem storageSystem = s_dbClient.queryObject(StorageSystem.class, policyStorage.getStorageSystem());
                        String stepId = workflow.createStepId();
                        String stepDes = String.format("unassigning file policy : %s,  from resource: %s,", filePolicy.getId(), uri);
                        Object[] args = new Object[] { storageSystem.getId(), policy, policyStorage.getId() };
                        _fileDeviceController.createMethod(workflow, null, UNASSIGN_FILE_POLICY_METHOD, stepId, stepDes, storageSystem.getId(), args);
                    }
                }
            }
        } else {
            s_logger.info("file policy {} is not applied to any storage system", policy);
            for (URI uri : unassignFrom) {
                filePolicy.removeAssignedResources(uri);
                FileOrchestrationUtils.updateUnAssignedResource(filePolicy, uri, s_dbClient);
            }
            // If no other resources are assigned to replication policy
            // Remove the replication topology from the policy
            FileOrchestrationUtils.removeTopologyInfo(filePolicy, s_dbClient);
            s_dbClient.updateObject(filePolicy);
            s_logger.info("Unassigning file policy: {} from resources: {} finished successfully", policy.toString(), unassignFrom.toString());
        }
        String successMessage = String.format("unassigning file policy : %s,  from resources: %s finsihed successfully,", filePolicy.getId(), unassignFrom);
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error(String.format("unassigning file policy : %s,  from resource: %s failed,", filePolicy.getId(), unassignFrom), ex);
        ServiceError serviceError = DeviceControllerException.errors.unassignFilePolicyFailed(policy.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) FilePolicyUnAssignWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FilePolicyUnAssignWorkflowCompleter) Workflow(com.emc.storageos.workflow.Workflow) FileObject(com.emc.storageos.db.client.model.FileObject) URI(java.net.URI) 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)

Aggregations

FileObject (com.emc.storageos.db.client.model.FileObject)1 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)1 PolicyStorageResource (com.emc.storageos.db.client.model.PolicyStorageResource)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)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 FilePolicyUnAssignWorkflowCompleter (com.emc.storageos.volumecontroller.impl.file.FilePolicyUnAssignWorkflowCompleter)1 Workflow (com.emc.storageos.workflow.Workflow)1 WorkflowException (com.emc.storageos.workflow.WorkflowException)1 URI (java.net.URI)1