use of org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock in project so by onap.
the class ExecuteActivity method execute.
@Override
public void execute(DelegateExecution execution) throws Exception {
final String requestId = (String) execution.getVariable(G_REQUEST_ID);
WorkflowException workflowException;
String handlingCode;
try {
Boolean workflowSyncAckSent = (Boolean) execution.getVariable(WORKFLOW_SYNC_ACK_SENT);
if (workflowSyncAckSent == null || workflowSyncAckSent == false) {
workflowActionBBTasks.sendSyncAck(execution);
execution.setVariable(WORKFLOW_SYNC_ACK_SENT, Boolean.TRUE);
}
final String implementationString = execution.getBpmnModelElementInstance().getAttributeValue(SERVICE_TASK_IMPLEMENTATION_ATTRIBUTE);
logger.debug("activity implementation String: {}", implementationString);
if (!implementationString.startsWith(ACTIVITY_PREFIX)) {
buildAndThrowException(execution, "Implementation attribute has a wrong format");
}
String activityName = implementationString.replaceFirst(ACTIVITY_PREFIX, "");
logger.info("activityName is: {}", activityName);
BuildingBlock buildingBlock = buildBuildingBlock(activityName);
ExecuteBuildingBlock executeBuildingBlock = buildExecuteBuildingBlock(execution, requestId, buildingBlock);
Map<String, Object> variables = new HashMap<>();
if (execution.getVariables() != null) {
execution.getVariables().forEach((key, value) -> {
if (value instanceof Serializable) {
variables.put(key, value);
}
});
}
variables.put(BUILDING_BLOCK, executeBuildingBlock);
variables.put(G_REQUEST_ID, requestId);
variables.put(RETRY_COUNT, 1);
variables.put(A_LA_CARTE, true);
variables.put(SUPPRESS_ROLLBACK, true);
ProcessInstanceWithVariables buildingBlockResult = runtimeService.createProcessInstanceByKey(EXECUTE_BUILDING_BLOCK).setVariables(variables).executeWithVariablesInReturn();
VariableMap variableMap = buildingBlockResult.getVariables();
workflowException = (WorkflowException) variableMap.get(WORKFLOW_EXCEPTION);
if (workflowException != null) {
logger.error("Workflow exception is: {}", workflowException.getErrorMessage());
}
handlingCode = (String) variableMap.get(HANDLING_CODE);
logger.debug("Handling code: " + handlingCode);
execution.setVariable(WORKFLOW_EXCEPTION, workflowException);
} catch (Exception e) {
logger.error("BPMN exception on activity execution: " + e.getMessage());
workflowException = new WorkflowException(EXECUTE_BUILDING_BLOCK, 7000, e.getMessage());
handlingCode = ABORT_HANDLING_CODE;
}
if (workflowException != null && handlingCode != null && handlingCode.equals(ABORT_HANDLING_CODE)) {
logger.debug("Aborting execution of the custom workflow");
buildAndThrowException(execution, workflowException.getErrorMessage());
}
}
use of org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock in project so by onap.
the class ExecuteActivity method buildExecuteBuildingBlock.
protected ExecuteBuildingBlock buildExecuteBuildingBlock(DelegateExecution execution, String requestId, BuildingBlock buildingBlock) throws IOException {
WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
workflowResourceIds.setServiceInstanceId((String) execution.getVariable(SERVICE_INSTANCE_ID));
workflowResourceIds.setVnfId((String) execution.getVariable(VNF_ID));
String bpmnRequest = (String) execution.getVariable(G_BPMN_REQUEST);
ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class);
RequestDetails requestDetails = sIRequest.getRequestDetails();
return new ExecuteBuildingBlock().setaLaCarte(true).setRequestAction((String) execution.getVariable(G_ACTION)).setResourceId((String) execution.getVariable(VNF_ID)).setVnfType((String) execution.getVariable(VNF_TYPE)).setWorkflowResourceIds(workflowResourceIds).setRequestId(requestId).setBuildingBlock(buildingBlock).setRequestDetails(requestDetails);
}
use of org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock in project so by onap.
the class WorkflowAction method getConfigBuildingBlocks.
protected List<ExecuteBuildingBlock> getConfigBuildingBlocks(ConfigBuildingBlocksDataObject dataObj) throws AAIEntityNotFoundException, VnfcMultipleRelationshipException {
List<ExecuteBuildingBlock> flowsToExecuteConfigs = new ArrayList<>();
List<OrchestrationFlow> result = dataObj.getOrchFlows().stream().filter(item -> item.getFlowName().contains(FABRIC_CONFIGURATION)).collect(Collectors.toList());
String vnfId = dataObj.getWorkflowResourceIds().getVnfId();
String vfModuleId = dataObj.getWorkflowResourceIds().getVfModuleId();
String vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
String vfModuleCustomizationUUID;
org.onap.aai.domain.yang.VfModule aaiVfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId);
if (aaiVfModule == null) {
logger.error("No matching VfModule is found in Generic-Vnf in AAI for vnfId: {} and vfModuleId : {}", vnfId, vfModuleId);
throw new AAIEntityNotFoundException("No matching VfModule is found in Generic-Vnf in AAI for vnfId: " + vnfId + " and vfModuleId : " + vfModuleId);
} else {
vfModuleCustomizationUUID = aaiVfModule.getModelCustomizationId();
}
String replaceVfModuleCustomizationUUID = "";
String replaceVnfModuleCustomizationUUID = "";
boolean isReplace = false;
if (dataObj.getRequestAction().equalsIgnoreCase("replaceInstance") || dataObj.getRequestAction().equalsIgnoreCase("replaceInstanceRetainAssignments")) {
for (RelatedInstanceList relatedInstList : dataObj.getRequestDetails().getRelatedInstanceList()) {
RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
replaceVnfModuleCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
}
}
replaceVfModuleCustomizationUUID = dataObj.getRequestDetails().getModelInfo().getModelCustomizationId();
isReplace = true;
}
List<org.onap.aai.domain.yang.Vnfc> vnfcs = getRelatedResourcesInVfModule(vnfId, vfModuleId, org.onap.aai.domain.yang.Vnfc.class, Types.VNFC);
for (org.onap.aai.domain.yang.Vnfc vnfc : vnfcs) {
WorkflowResourceIds workflowIdsCopy = SerializationUtils.clone(dataObj.getWorkflowResourceIds());
org.onap.aai.domain.yang.Configuration configuration = getRelatedResourcesInVnfc(vnfc, org.onap.aai.domain.yang.Configuration.class, Types.CONFIGURATION);
if (configuration == null) {
logger.warn(String.format("No configuration found for VNFC %s in AAI", vnfc.getVnfcName()));
continue;
}
workflowIdsCopy.setConfigurationId(configuration.getConfigurationId());
for (OrchestrationFlow orchFlow : result) {
if (!isReplace || (isReplace && (orchFlow.getFlowName().contains("Delete")))) {
if (!isReplace) {
dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID);
dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID);
} else {
if (orchFlow.getFlowName().contains("Delete")) {
dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID);
dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID);
} else {
dataObj.getResourceKey().setVfModuleCustomizationId(replaceVfModuleCustomizationUUID);
dataObj.getResourceKey().setVnfCustomizationId(replaceVnfModuleCustomizationUUID);
}
}
dataObj.getResourceKey().setCvnfModuleCustomizationId(vnfc.getModelCustomizationId());
String vnfcName = vnfc.getVnfcName();
if (vnfcName == null || vnfcName.isEmpty()) {
buildAndThrowException(dataObj.getExecution(), "Exception in create execution list " + ": VnfcName does not exist or is null while there is a configuration for the vfModule", new Exception("Vnfc and Configuration do not match"));
}
ExecuteBuildingBlock ebb = executeBuildingBlockBuilder.buildExecuteBuildingBlock(orchFlow, dataObj.getRequestId(), dataObj.getResourceKey(), dataObj.getApiVersion(), dataObj.getResourceId(), dataObj.getRequestAction(), dataObj.isaLaCarte(), dataObj.getVnfType(), workflowIdsCopy, dataObj.getRequestDetails(), false, null, vnfcName, true, null);
flowsToExecuteConfigs.add(ebb);
}
}
}
return flowsToExecuteConfigs;
}
use of org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock in project so by onap.
the class WorkflowActionBBTasks method getExecuteBBForConfig.
protected ExecuteBuildingBlock getExecuteBBForConfig(String bbName, ExecuteBuildingBlock ebb, String configurationId, ConfigurationResourceKeys configurationResourceKeys) {
BuildingBlock buildingBlock = new BuildingBlock().setBpmnFlowName(bbName).setMsoId(UUID.randomUUID().toString());
WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(ebb.getWorkflowResourceIds());
workflowResourceIds.setConfigurationId(configurationId);
return new ExecuteBuildingBlock().setaLaCarte(ebb.isaLaCarte()).setApiVersion(ebb.getApiVersion()).setRequestAction(ebb.getRequestAction()).setVnfType(ebb.getVnfType()).setRequestId(ebb.getRequestId()).setRequestDetails(ebb.getRequestDetails()).setBuildingBlock(buildingBlock).setWorkflowResourceIds(workflowResourceIds).setConfigurationResourceKeys(configurationResourceKeys);
}
use of org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock in project so by onap.
the class WorkflowActionBBTasks method selectBB.
public void selectBB(DelegateExecution execution) {
try {
List<ExecuteBuildingBlock> flowsToExecute = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
execution.setVariable("MacroRollback", false);
try {
flowManipulatorListenerRunner.modifyFlows(flowsToExecute, new DelegateExecutionImpl(execution));
} catch (NullPointerException ex) {
workflowAction.buildAndThrowException(execution, "Error in FlowManipulator Modify Flows", ex);
}
int currentSequence = (int) execution.getVariable(BBConstants.G_CURRENT_SEQUENCE);
boolean completed = false;
if (currentSequence < flowsToExecute.size()) {
ExecuteBuildingBlock ebb = flowsToExecute.get(currentSequence);
execution.setVariable("buildingBlock", ebb);
execution.setVariable(BBConstants.G_CURRENT_SEQUENCE, currentSequence + 1);
} else {
completed = true;
}
execution.setVariable(COMPLETED, completed);
} catch (Exception e) {
workflowAction.buildAndThrowException(execution, "Internal Error occured during selectBB", e);
}
}
Aggregations