2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.pnf.delegate;
23 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
24 import com.google.common.base.Strings;
25 import org.camunda.bpm.engine.RuntimeService;
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.camunda.bpm.engine.delegate.JavaDelegate;
28 import org.onap.so.bpmn.common.BuildingBlockExecution;
29 import org.onap.so.bpmn.infrastructure.pnf.dmaap.DmaapClient;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
31 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
32 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
33 import org.onap.so.client.exception.BBObjectNotFoundException;
34 import org.onap.so.client.exception.ExceptionBuilder;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.beans.factory.annotation.Value;
39 import org.springframework.stereotype.Component;
42 * This class is designed to be used within WaitForPnfReadyBB
45 public class RegisterForPnfReadyEvent implements JavaDelegate {
47 private static final String ERROR_MESSAGE_PNF_NOT_FOUND =
48 "pnf resource not found in buildingBlockExecution while registering to dmaap listener";
49 private static final Logger LOGGER = LoggerFactory.getLogger(RegisterForPnfReadyEvent.class);
51 private DmaapClient dmaapClient;
52 private ExtractPojosForBB extractPojosForBB;
53 private ExceptionBuilder exceptionBuilder;
54 private String pnfEntryNotificationTimeout;
57 public RegisterForPnfReadyEvent(DmaapClient dmaapClient, ExtractPojosForBB extractPojosForBB,
58 ExceptionBuilder exceptionBuilder,
59 @Value("${aai.pnfEntryNotificationTimeout}") String pnfEntryNotificationTimeout) {
60 this.dmaapClient = dmaapClient;
61 this.extractPojosForBB = extractPojosForBB;
62 this.exceptionBuilder = exceptionBuilder;
63 this.pnfEntryNotificationTimeout = pnfEntryNotificationTimeout;
67 public void execute(DelegateExecution execution) {
69 String pnfName = getPnfName(execution);
70 fillExecution(execution, pnfName);
71 RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
72 dmaapClient.registerForUpdate(pnfName, () -> runtimeService.createMessageCorrelation("WorkflowMessage")
73 .processInstanceId(execution.getProcessInstanceId()).correlateWithResult());
74 } catch (BBObjectNotFoundException e) {
75 LOGGER.error(ERROR_MESSAGE_PNF_NOT_FOUND);
76 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ERROR_MESSAGE_PNF_NOT_FOUND);
80 private void fillExecution(DelegateExecution execution, String pnfName) {
81 execution.setVariable(ExecutionVariableNames.PNF_CORRELATION_ID, pnfName);
82 if (Strings.isNullOrEmpty(pnfEntryNotificationTimeout)) {
83 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000,
84 "pnfEntryNotificationTimeout value not defined");
86 execution.setVariable(TIMEOUT_FOR_NOTIFICATION, pnfEntryNotificationTimeout);
89 private String getPnfName(DelegateExecution execution) throws BBObjectNotFoundException {
90 BuildingBlockExecution buildingBlockExecution =
91 (BuildingBlockExecution) execution.getVariable("gBuildingBlockExecution");
92 Pnf pnf = extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.PNF);
93 String pnfName = pnf.getPnfName();
94 if (Strings.isNullOrEmpty(pnfName)) {
95 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "pnf name is not set");