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);
44 private CatalogDbClient catalogDbClient;
45 private static final String ASTERISK = "ASTERISK";
47 public void setRetryTimer(DelegateExecution execution) {
49 int retryCount = (int) execution.getVariable("retryCount");
50 int retryTimeToWait = (int) Math.pow(5, retryCount);
51 String RetryDuration = "PT" + retryTimeToWait + "M";
52 execution.setVariable("RetryDuration", RetryDuration);
53 } catch (Exception e) {
55 throw new BpmnError("Unknown error incrementing retry counter");
59 public void queryRainyDayTable(DelegateExecution execution) {
61 ExecuteBuildingBlock ebb = (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
62 String bbName = ebb.getBuildingBlock().getBpmnFlowName();
63 GeneralBuildingBlock gBBInput = (GeneralBuildingBlock) execution.getVariable("gBBInput");
64 Map<ResourceKey, String> lookupKeyMap = (Map<ResourceKey, String>) execution.getVariable("lookupKeyMap");
65 String serviceType = ASTERISK;
67 serviceType = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getModelInfoServiceInstance().getServiceType();
68 } catch (Exception ex) {
69 // keep default serviceType value
71 String vnfType = ASTERISK;
73 for(GenericVnf vnf : gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getVnfs()) {
74 if(vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
75 vnfType = vnf.getVnfType();
78 } catch (Exception ex) {
79 // keep default vnfType value
81 WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
82 String errorCode = ASTERISK;
84 errorCode = "" + workflowException.getErrorCode();
85 } catch (Exception ex) {
86 // keep default errorCode value
88 String workStep = ASTERISK;
90 workStep = workflowException.getWorkStep();
91 } catch (Exception ex) {
92 // keep default workStep value
94 //Extract error data to be returned to WorkflowAction
95 execution.setVariable("WorkflowExceptionErrorMessage", workflowException.getErrorMessage());
96 RainyDayHandlerStatus rainyDayHandlerStatus;
97 String handlingCode = "";
98 rainyDayHandlerStatus = catalogDbClient.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName,serviceType,vnfType,errorCode,workStep);
99 if(rainyDayHandlerStatus==null){
100 rainyDayHandlerStatus = catalogDbClient.getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName,ASTERISK,ASTERISK,ASTERISK,ASTERISK);
101 if(rainyDayHandlerStatus==null){
102 handlingCode = "Abort";
104 handlingCode = rainyDayHandlerStatus.getPolicy();
107 handlingCode = rainyDayHandlerStatus.getPolicy();
109 msoLogger.debug("RainyDayHandler Status Code is: " + handlingCode);
110 execution.setVariable("handlingCode", handlingCode);
111 } catch (Exception e) {
112 msoLogger.debug("RainyDayHandler Status Code is: Abort");
113 execution.setVariable("handlingCode", "Abort");