2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
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.servicedecomposition.tasks;
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.onap.so.bpmn.core.WorkflowException;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
29 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
30 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
31 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
32 import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus;
33 import org.onap.so.db.catalog.client.CatalogDbClient;
34 import org.onap.so.logger.MsoLogger;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
39 public class ExecuteBuildingBlockRainyDay {
41 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ExecuteBuildingBlockRainyDay.class);
42 public static final String HANDLING_CODE = "handlingCode";
45 private CatalogDbClient catalogDbClient;
46 private static final String ASTERISK = "*";
48 public void setRetryTimer(DelegateExecution execution) {
50 int retryCount = (int) execution.getVariable("retryCount");
51 int retryTimeToWait = (int) Math.pow(5, retryCount);
52 String RetryDuration = "PT" + retryTimeToWait + "M";
53 execution.setVariable("RetryDuration", RetryDuration);
54 } catch (Exception e) {
56 throw new BpmnError("Unknown error incrementing retry counter");
60 public void queryRainyDayTable(DelegateExecution execution, boolean primaryPolicy) {
62 ExecuteBuildingBlock ebb = (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
63 String bbName = ebb.getBuildingBlock().getBpmnFlowName();
64 GeneralBuildingBlock gBBInput = (GeneralBuildingBlock) execution.getVariable("gBBInput");
65 Map<ResourceKey, String> lookupKeyMap = (Map<ResourceKey, String>) execution.getVariable("lookupKeyMap");
66 String serviceType = ASTERISK;
68 serviceType = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getModelInfoServiceInstance().getServiceType();
69 } catch (Exception ex) {
70 // keep default serviceType value
72 String vnfType = ASTERISK;
74 for(GenericVnf vnf : gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getVnfs()) {
75 if(vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
76 vnfType = vnf.getVnfType();
79 } catch (Exception ex) {
80 // keep default vnfType value
82 WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
83 String errorCode = ASTERISK;
85 errorCode = "" + workflowException.getErrorCode();
86 } catch (Exception ex) {
87 // keep default errorCode value
89 String workStep = ASTERISK;
91 workStep = workflowException.getWorkStep();
92 } catch (Exception ex) {
93 // keep default workStep value
95 //Extract error data to be returned to WorkflowAction
96 execution.setVariable("WorkflowExceptionErrorMessage", workflowException.getErrorMessage());
97 RainyDayHandlerStatus rainyDayHandlerStatus;
98 String handlingCode = "";
99 rainyDayHandlerStatus = catalogDbClient.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName,serviceType,vnfType,errorCode,workStep);
100 if(rainyDayHandlerStatus==null){
101 rainyDayHandlerStatus = catalogDbClient.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName,ASTERISK,ASTERISK,ASTERISK,ASTERISK);
102 if(rainyDayHandlerStatus==null){
103 handlingCode = "Abort";
106 handlingCode = rainyDayHandlerStatus.getPolicy();
108 handlingCode = rainyDayHandlerStatus.getSecondaryPolicy();
113 handlingCode = rainyDayHandlerStatus.getPolicy();
115 handlingCode = rainyDayHandlerStatus.getSecondaryPolicy();
118 msoLogger.debug("RainyDayHandler Status Code is: " + handlingCode);
119 execution.setVariable(HANDLING_CODE, handlingCode);
120 } catch (Exception e) {
121 msoLogger.debug("RainyDayHandler Status Code is: Abort");
122 execution.setVariable(HANDLING_CODE, "Abort");
126 public void setHandlingStatusSuccess(DelegateExecution execution){
127 execution.setVariable(HANDLING_CODE, "Success");