use of org.onap.so.client.exception.OrchestrationStatusValidationException in project so by onap.
the class OrchestrationStatusValidator method getOrchestrationStatus.
private OrchestrationStatus getOrchestrationStatus(BuildingBlockExecution execution, String buildingBlockFlowName, BuildingBlockDetail buildingBlockDetail) throws BBObjectNotFoundException, OrchestrationStatusValidationException {
OrchestrationStatus orchestrationStatus = null;
switch(buildingBlockDetail.getResourceType()) {
case SERVICE:
ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
orchestrationStatus = serviceInstance.getOrchestrationStatus();
break;
case VNF:
GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
orchestrationStatus = genericVnf.getOrchestrationStatus();
break;
case VF_MODULE:
VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
orchestrationStatus = vfModule.getOrchestrationStatus();
break;
case VOLUME_GROUP:
VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
orchestrationStatus = volumeGroup.getOrchestrationStatus();
break;
case NETWORK:
L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
orchestrationStatus = network.getOrchestrationStatus();
break;
case NETWORK_COLLECTION:
Collection networkCollection = getNetworkCollection(execution);
orchestrationStatus = networkCollection.getOrchestrationStatus();
break;
case CONFIGURATION:
Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
orchestrationStatus = configuration.getOrchestrationStatus();
break;
case INSTANCE_GROUP:
InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
orchestrationStatus = instanceGroup.getOrchestrationStatus();
break;
case NO_VALIDATE:
// short circuit and exit method
execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, OrchestrationStatusValidationDirective.VALIDATION_SKIPPED);
break;
default:
// code
throw new OrchestrationStatusValidationException(String.format(UNKNOWN_RESOURCE_TYPE, buildingBlockFlowName, buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction()));
}
return orchestrationStatus;
}
use of org.onap.so.client.exception.OrchestrationStatusValidationException in project so by onap.
the class OrchestrationStatusValidator method validateOrchestrationStatus.
/**
* This method validate's the status of the OrchestrationStatus against the buildingBlockDetail ResourceType
*/
public void validateOrchestrationStatus(BuildingBlockExecution execution) {
try {
execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, null);
String buildingBlockFlowName = execution.getFlowToBeCalled();
BuildingBlockDetail buildingBlockDetail = catalogDbClient.getBuildingBlockDetail(buildingBlockFlowName);
if (buildingBlockDetail == null) {
throw new OrchestrationStatusValidationException(String.format(BUILDING_BLOCK_DETAIL_NOT_FOUND, buildingBlockFlowName));
}
OrchestrationStatus orchestrationStatus = getOrchestrationStatus(execution, buildingBlockFlowName, buildingBlockDetail);
if (buildingBlockDetail.getResourceType().equals(ResourceType.NO_VALIDATE)) {
return;
}
if (orchestrationStatus == null) {
throw new OrchestrationStatusValidationException("The resource's orchstration status is null. Cannot perform task on a null orchestration status");
}
OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = catalogDbClient.getOrchestrationStatusStateTransitionDirective(buildingBlockDetail.getResourceType(), orchestrationStatus, buildingBlockDetail.getTargetAction());
if (orchestrationStatusStateTransitionDirective.getFlowDirective() == OrchestrationStatusValidationDirective.FAIL) {
throw new OrchestrationStatusValidationException(String.format(ORCHESTRATION_VALIDATION_FAIL, buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction(), orchestrationStatus));
}
execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, orchestrationStatusStateTransitionDirective.getFlowDirective());
if (buildingBlockFlowName.matches("Create(.*)|Delete(.*)") && orchestrationStatusStateTransitionDirective.getFlowDirective() == OrchestrationStatusValidationDirective.SILENT_SUCCESS) {
updatedResourceStatus(execution, buildingBlockDetail);
}
} catch (BBObjectNotFoundException ex) {
logger.error("Error occurred for bb object notfound in OrchestrationStatusValidator validateOrchestrationStatus ", ex);
if (execution.getFlowToBeCalled().contains("Unassign")) {
execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, OrchestrationStatusValidationDirective.SILENT_SUCCESS);
} else {
exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex);
}
} catch (Exception e) {
logger.error("Exception occurred", e);
exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e);
}
}
Aggregations