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);
}
}
Aggregations