From 4891eedd15cff1e582d052843eb8c11a14c5d836 Mon Sep 17 00:00:00 2001 From: "Smokowski, Steven" Date: Tue, 24 Sep 2019 14:57:51 -0400 Subject: Update Resume Logic and Add Workflow Listeners Updated with the error log messages Changed the code to do string compare for eventName update workflowaction to only persist if not resume Issue-ID: SO-2363 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I139f2427ae0f0253a15cc51003318686568cb514 --- .../validation/WorkflowActionCompletion.java | 25 ++ .../validation/WorkflowActionListener.java | 44 ++++ .../validation/WorkflowActionListenerRunner.java | 64 +++++ .../tasks/BBInputSetupUtils.java | 28 +-- .../so/bpmn/core/plugins/AsyncTaskExecutor.java | 21 ++ .../core/plugins/AsyncTaskExecutorListener.java | 42 ++++ .../core/plugins/BPMNProcessCompletePlugin.java | 51 ++++ .../subprocess/BuildingBlock/WorkflowActionBB.bpmn | 258 ++++++++++++--------- .../DoCompareServiceInstanceDataTest.groovy | 20 ++ .../workflow/tasks/FlowCompletionTasks.java | 15 +- .../workflow/tasks/WorkflowAction.java | 10 +- .../workflow/tasks/WorkflowActionTest.java | 16 +- 12 files changed, 444 insertions(+), 150 deletions(-) create mode 100644 bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionCompletion.java create mode 100644 bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionListener.java create mode 100644 bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionListenerRunner.java create mode 100644 bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutor.java create mode 100644 bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutorListener.java create mode 100644 bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/BPMNProcessCompletePlugin.java (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionCompletion.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionCompletion.java new file mode 100644 index 0000000000..1018d7f025 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionCompletion.java @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.common.listener.validation; + +public interface WorkflowActionCompletion extends WorkflowActionListener { + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionListener.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionListener.java new file mode 100644 index 0000000000..4788c55053 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionListener.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.common.listener.validation; + +import org.camunda.bpm.engine.delegate.DelegateExecution; + +public interface WorkflowActionListener { + + /** + * Should this listener run for given bb + * + * @return + * + */ + public boolean shouldRunFor(String bbName, String eventName); + + /** + * Determines whether or not the listener should be executed + * + * + * @param execution + * @return + */ + public void executeListener(DelegateExecution execution); + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionListenerRunner.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionListenerRunner.java new file mode 100644 index 0000000000..806c1b835d --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/listener/validation/WorkflowActionListenerRunner.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.common.listener.validation; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import javax.annotation.PostConstruct; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.listener.ListenerRunner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + + + +@Component +public class WorkflowActionListenerRunner extends ListenerRunner { + + private static Logger logger = LoggerFactory.getLogger(WorkflowActionListenerRunner.class); + + protected List workflowActionListeners; + + @PostConstruct + protected void init() { + workflowActionListeners = new ArrayList<>(Optional + .ofNullable(context.getBeansOfType(WorkflowActionListener.class)).orElse(new HashMap<>()).values()); + } + + public void executeAsyncListeners(String bbName, DelegateExecution execution, String eventName) { + try { + logger.info("NotifyingWorkflowActionListeners"); + runNotifications(workflowActionListeners, bbName, execution, eventName); + } catch (Exception e) { + logger.error("Error in Notifying Workflow Action Listeners", e); + } + } + + protected void runNotifications(List listeners, String bbName, + DelegateExecution execution, String eventName) { + List filtered = + filterListeners(listeners, (item -> item.shouldRunFor(bbName, eventName))); + filtered.forEach(item -> item.executeListener(execution)); + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java index dcb9e08d0b..fcac86b251 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java @@ -23,9 +23,7 @@ package org.onap.so.bpmn.servicedecomposition.tasks; import java.io.IOException; -import java.io.ObjectOutputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Optional; @@ -76,12 +74,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.type.TypeFactory; @Component("BBInputSetupUtils") public class BBInputSetupUtils { @@ -177,39 +174,32 @@ public class BBInputSetupUtils { } public InfraActiveRequests loadOriginalInfraActiveRequestById(String requestId) { - return this.requestsDbClient.getInfraActiveRequestbyRequestId( this.requestsDbClient.getInfraActiveRequestbyRequestId(requestId).getOriginalRequestId()); } public List loadOriginalFlowExecutionPath(String requestId) { - - List asList = null; if (requestId != null) { - InfraActiveRequests request = loadInfraActiveRequestById(requestId); - if (request.getOriginalRequestId() != null) { - RequestProcessingData requestProcessingData = this.requestsDbClient.getRequestProcessingDataBySoRequestIdAndName( request.getOriginalRequestId(), PROCESSING_DATA_NAME_EXECUTION_FLOWS); - - ObjectMapper om = new ObjectMapper(); try { - ExecuteBuildingBlock[] asArray = - om.readValue(requestProcessingData.getValue(), ExecuteBuildingBlock[].class); - asList = Arrays.asList(asArray); + ObjectMapper om = new ObjectMapper(); + TypeFactory typeFactory = objectMapper.getTypeFactory(); + return om.readValue(requestProcessingData.getValue(), + typeFactory.constructCollectionType(List.class, ExecuteBuildingBlock.class)); } catch (Exception e) { logger.error(DATA_LOAD_ERROR, e); + throw new RuntimeException("Error Loading Original Request Data", e); } + } else { + throw new RuntimeException("Original Request Id is null for record: " + requestId); } - } else { - logger.debug(REQUEST_ERROR); + throw new RuntimeException("Null Request Id Passed in"); } - - return asList; } public Service getCatalogServiceByModelUUID(String modelUUID) { diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutor.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutor.java new file mode 100644 index 0000000000..56526c7f89 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutor.java @@ -0,0 +1,21 @@ +package org.onap.so.bpmn.core.plugins; + +import org.camunda.bpm.engine.delegate.ExecutionListener; +import org.camunda.bpm.engine.impl.bpmn.parser.AbstractBpmnParseListener; +import org.camunda.bpm.engine.impl.pvm.process.ActivityImpl; +import org.camunda.bpm.engine.impl.pvm.process.ScopeImpl; +import org.camunda.bpm.engine.impl.util.xml.Element; +import org.springframework.stereotype.Component; + +@Component +public class AsyncTaskExecutor extends AbstractBpmnParseListener { + + private void injectTaskExecutorExecutionListener(ActivityImpl activity) { + activity.addListener(ExecutionListener.EVENTNAME_END, new AsyncTaskExecutorListener()); + } + + @Override + public void parseEndEvent(Element endEventElement, ScopeImpl scope, ActivityImpl activity) { + injectTaskExecutorExecutionListener(activity); + } +} diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutorListener.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutorListener.java new file mode 100644 index 0000000000..94f4b313d4 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutorListener.java @@ -0,0 +1,42 @@ +package org.onap.so.bpmn.core.plugins; + +import org.camunda.bpm.engine.RepositoryService; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.ExecutionListener; +import org.onap.so.bpmn.common.listener.validation.WorkflowActionListenerRunner; +import org.onap.so.spring.SpringContextHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AsyncTaskExecutorListener implements ExecutionListener { + private final Logger logger = LoggerFactory.getLogger(AsyncTaskExecutorListener.class); + + + private WorkflowActionListenerRunner listenerRunner; + + @Override + public void notify(DelegateExecution execution) throws Exception { + if (!isBlank(execution.getCurrentActivityName())) { + try { + String id = execution.getId(); + if (id != null) { + RepositoryService repositoryService = execution.getProcessEngineServices().getRepositoryService(); + String processName = repositoryService.createProcessDefinitionQuery() + .processDefinitionId(execution.getProcessDefinitionId()).singleResult().getName(); + logger.info("ProcessName : {}", processName); + if (processName != null) { + listenerRunner = + SpringContextHelper.getAppContext().getBean(WorkflowActionListenerRunner.class); + listenerRunner.executeAsyncListeners(processName, execution, ExecutionListener.EVENTNAME_END); + } + } + } catch (Exception e) { + logger.error("Error occured in executing Complete Task Listeners", e); + } + } + } + + private boolean isBlank(Object object) { + return object == null || "".equals(object.toString().trim()); + } +} diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/BPMNProcessCompletePlugin.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/BPMNProcessCompletePlugin.java new file mode 100644 index 0000000000..96c6af42ed --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/BPMNProcessCompletePlugin.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.core.plugins; + +import java.util.ArrayList; +import java.util.List; +import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParseListener; +import org.camunda.bpm.engine.impl.cfg.AbstractProcessEnginePlugin; +import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + + +@Component +public class BPMNProcessCompletePlugin extends AbstractProcessEnginePlugin { + + @Autowired + private AsyncTaskExecutor asyncTaskExecutor; + + @Override + public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) { + List preParseListeners = processEngineConfiguration.getCustomPreBPMNParseListeners(); + if (preParseListeners == null) { + preParseListeners = new ArrayList<>(); + processEngineConfiguration.setCustomPreBPMNParseListeners(preParseListeners); + } + preParseListeners.add(asyncTaskExecutor); + } + +} diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn index efdee8601e..bb900420e3 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/WorkflowActionBB.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_15s0okp @@ -46,7 +46,7 @@ SequenceFlow_0l7kaba - ${execution.getVariable("completed")==true&&execution.getVariable("isRollback")==false&&execution.getVariable("handlingCode")=="Success"} + SequenceFlow_15s0okp @@ -54,7 +54,7 @@ SequenceFlow_0sckerv - SequenceFlow_1wb59ic + SequenceFlow_1lrz41x SequenceFlow_0kf5sen @@ -83,7 +83,7 @@ - ${execution.getVariable("isTopLevelFlow")==true&&execution.getVariable("sentSyncResponse")==false} + @@ -92,10 +92,10 @@ - ${execution.getVariable("handlingCode")=="Rollback"||execution.getVariable("handlingCode")=="RollbackToAssigned"||execution.getVariable("handlingCode")=="RollbackToCreated"} + - ${execution.getVariable("isRollbackNeeded")==true} + SequenceFlow_0v588sm @@ -104,7 +104,7 @@ - ${execution.getVariable("handlingCode")=="Abort"} + SequenceFlow_02ksbt0 @@ -115,7 +115,6 @@ SequenceFlow_1r570x3 - SequenceFlow_01j184u @@ -128,7 +127,7 @@ - ${execution.getVariable("isTopLevelFlow")==false} + SequenceFlow_11530ei @@ -137,7 +136,7 @@ - ${execution.getVariable("isTopLevelFlow")==false} + SequenceFlow_1m2eezj @@ -145,13 +144,13 @@ SequenceFlow_0kf5sen - ${execution.getVariable("isTopLevelFlow")==false} + SequenceFlow_1ui67mc - ${execution.getVariable("isRollbackNeeded")==false} + SequenceFlow_11dlyzt @@ -159,7 +158,7 @@ SequenceFlow_1ui67mc - ${execution.getVariable("completed")==true&&execution.getVariable("isRollback")==true&&execution.getVariable("handlingCode")=="Success"} + @@ -186,7 +185,7 @@ SequenceFlow_0unbew4 - SequenceFlow_1wb59ic + SequenceFlow_0etawv5 SequenceFlow_1tfizxf @@ -196,6 +195,19 @@ + + SequenceFlow_1lrz41x + SequenceFlow_0etawv5 + SequenceFlow_0ilo6lo + + + + + + + SequenceFlow_0ilo6lo + + @@ -213,8 +225,8 @@ - - + + @@ -223,8 +235,8 @@ - - + + @@ -239,9 +251,9 @@ - - - + + + @@ -250,15 +262,15 @@ - + - - - + + + @@ -279,16 +291,16 @@ - - - + + + - - + + @@ -297,16 +309,16 @@ - - + + - - - + + + @@ -321,28 +333,19 @@ - - - - + + + + - - - - - - - - - - - - - + + + + @@ -357,16 +360,16 @@ - - - + + + - + - - + + @@ -378,16 +381,16 @@ - - - + + + - - + + @@ -399,10 +402,10 @@ - - - - + + + + @@ -414,9 +417,9 @@ - - - + + + @@ -428,33 +431,33 @@ - - - - + + + + - - + + - - + + - - - - + + + + @@ -466,25 +469,25 @@ - - - - + + + + - - - + + + - - + + @@ -511,15 +514,15 @@ - - + + - - + + @@ -528,25 +531,25 @@ - - + + - - - + + + - - - - + + + + @@ -558,27 +561,60 @@ - - + + - - + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceDataTest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceDataTest.groovy index afbace76d6..715a7dff6d 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceDataTest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareServiceInstanceDataTest.groovy @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + package org.onap.so.bpmn.infrastructure.scripts import org.camunda.bpm.engine.delegate.BpmnError diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasks.java index e809ecd0ae..206942fcb1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/FlowCompletionTasks.java @@ -20,27 +20,14 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; -import java.util.ArrayList; -import java.util.List; -import org.camunda.bpm.engine.delegate.BpmnError; -import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse; -import org.onap.so.bpmn.common.workflow.context.WorkflowContextHolder; import org.onap.so.bpmn.core.WorkflowException; -import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; -import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; -import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; -import org.onap.so.serviceinstancebeans.RequestReferences; -import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; @Component public class FlowCompletionTasks { @@ -50,7 +37,9 @@ public class FlowCompletionTasks { @Autowired private RequestsDbClient requestDbclient; + public void updateRequestDbStatus(BuildingBlockExecution execution) { + try { String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId(); InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 1f07166b60..11c6455474 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -197,7 +197,9 @@ public class WorkflowAction { suppressRollback = false; } execution.setVariable("suppressRollback", suppressRollback); + boolean isResume = false; if (isUriResume(uri)) { + isResume = true; logger.debug("replacing URI {}", uri); uri = bbInputSetupUtils.loadOriginalInfraActiveRequestById(requestId).getRequestUrl(); logger.debug("for RESUME with original value {}", uri); @@ -225,6 +227,12 @@ public class WorkflowAction { if (flowsToExecute == null) { buildAndThrowException(execution, "Could not resume Macro flow. Error loading execution path."); } + } else if (aLaCarte && isResume) { + flowsToExecute = bbInputSetupUtils.loadOriginalFlowExecutionPath(requestId); + if (flowsToExecute == null) { + buildAndThrowException(execution, + "Could not resume request with request Id: " + requestId + ". No flowsToExecute was found"); + } } else { if (aLaCarte) { if (orchFlows == null || orchFlows.isEmpty()) { @@ -387,7 +395,7 @@ public class WorkflowAction { flowNames.add(ebb.getBuildingBlock().getBpmnFlowName()); } - if (!aLaCarte) { + if (!isResume) { bbInputSetupUtils.persistFlowExecutionPath(requestId, flowsToExecute); } execution.setVariable("flowNames", flowNames); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index eea885288e..be6fc94890 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -45,11 +45,9 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.UUID; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; @@ -66,7 +64,6 @@ import org.mockito.Spy; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.GenericVnfs; import org.onap.aai.domain.yang.L3Network; -import org.onap.aai.domain.yang.L3Networks; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipList; import org.onap.aai.domain.yang.ServiceInstance; @@ -80,7 +77,6 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.entities.AAIResultWrapper; @@ -103,8 +99,6 @@ import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; -import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.db.request.beans.RequestProcessingData; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.RequestDetails; import org.onap.so.serviceinstancebeans.RequestParameters; @@ -1475,10 +1469,20 @@ public class WorkflowActionTest extends BaseTaskTest { workflowAction.extractResourceIdAndTypeFromUri("something that doesn't match anything"); } + @Test + public void extractResourceIdAndTypeFromUriResumeTest() { + Resource resource = workflowAction.extractResourceIdAndTypeFromUri( + "http://localhost:9100/onap/so/infra/serviceInstantiation/v7/serviceInstances/4ff87c63-461b-4d83-8121-d351e6db216c/vnfs/eea9b93b-b5b9-4fad-9c35-12d52e4b683f/vfModules/33cb74cd-9cb3-4090-a3c0-1b8c8e235847/resume"); + assertEquals(resource.getResourceId(), "33cb74cd-9cb3-4090-a3c0-1b8c8e235847"); + } + @Test public void isUriResumeTest() { assertTrue(workflowAction.isUriResume( "http://localhost:9100/onap/so/infra/orchestrationRequests/v7/requests/2f8ab587-ef6a-4456-b7b2-d73f9363dabd/resume")); + assertTrue(workflowAction.isUriResume( + " http://localhost:9100/onap/so/infra/serviceInstantiation/v7/serviceInstances/4ff87c63-461b-4d83-8121-d351e6db216c/vnfs/eea9b93b-b5b9-4fad-9c35-12d52e4b683f/vfModules/33cb74cd-9cb3-4090-a3c0-1b8c8e235847/resume")); + assertFalse(workflowAction.isUriResume("/v6/serviceInstances/123/vnfs/1234/vfmodules/5678/replace")); } -- cgit 1.2.3-korg