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.db.request.beans.InfraActiveRequests;
35 import org.onap.so.db.request.client.RequestsDbClient;
36 import org.onap.so.logger.MsoLogger;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.core.env.Environment;
39 import org.springframework.stereotype.Component;
42 public class ExecuteBuildingBlockRainyDay {
44 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,
45 ExecuteBuildingBlockRainyDay.class);
46 public static final String HANDLING_CODE = "handlingCode";
49 private CatalogDbClient catalogDbClient;
51 private RequestsDbClient requestDbclient;
52 private static final String ASTERISK = "*";
55 private Environment environment;
56 protected String retryDurationPath = "mso.rainyDay.retryDurationMultiplier";
57 protected String defaultCode = "mso.rainyDay.defaultCode";
59 public void setRetryTimer(DelegateExecution execution) {
61 int retryDurationMult = Integer.parseInt(this.environment.getProperty(retryDurationPath));
62 int retryCount = (int) execution.getVariable("retryCount");
63 int retryTimeToWait = (int) Math.pow(retryDurationMult, retryCount) * 10;
64 String RetryDuration = "PT" + retryTimeToWait + "S";
65 execution.setVariable("RetryDuration", RetryDuration);
66 } catch (Exception e) {
68 throw new BpmnError("Unknown error incrementing retry counter");
72 public void queryRainyDayTable(DelegateExecution execution, boolean primaryPolicy) {
74 ExecuteBuildingBlock ebb = (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
75 String bbName = ebb.getBuildingBlock().getBpmnFlowName();
76 GeneralBuildingBlock gBBInput = (GeneralBuildingBlock) execution.getVariable("gBBInput");
77 String requestId = (String) execution.getVariable("mso-request-id");
78 Map<ResourceKey, String> lookupKeyMap = (Map<ResourceKey, String>) execution.getVariable("lookupKeyMap");
79 String serviceType = ASTERISK;
80 boolean aLaCarte = (boolean) execution.getVariable("aLaCarte");
81 boolean suppressRollback = (boolean) execution.getVariable("suppressRollback");
82 String handlingCode = "";
83 if (suppressRollback) {
84 handlingCode = "Abort";
87 serviceType = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0)
88 .getModelInfoServiceInstance().getServiceType();
89 } catch (Exception ex) {
90 // keep default serviceType value
92 String vnfType = ASTERISK;
94 for (GenericVnf vnf : gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0)
96 if (vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
97 vnfType = vnf.getVnfType();
100 } catch (Exception ex) {
101 // keep default vnfType value
103 WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
104 String errorCode = ASTERISK;
106 errorCode = "" + workflowException.getErrorCode();
107 } catch (Exception ex) {
108 // keep default errorCode value
111 errorCode = "" + (String) execution.getVariable("WorkflowExceptionCode");
112 } catch (Exception ex) {
113 // keep default errorCode value
116 String workStep = ASTERISK;
118 workStep = workflowException.getWorkStep();
119 } catch (Exception ex) {
120 // keep default workStep value
124 // Extract error data to be returned to WorkflowAction
125 execution.setVariable("WorkflowExceptionErrorMessage", workflowException.getErrorMessage());
126 } catch (Exception e) {
127 msoLogger.error("No WorkflowException Found",e);
129 RainyDayHandlerStatus rainyDayHandlerStatus;
130 rainyDayHandlerStatus = catalogDbClient
131 .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName,
132 serviceType, vnfType, errorCode, workStep);
133 if (rainyDayHandlerStatus == null) {
134 rainyDayHandlerStatus = catalogDbClient
135 .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName,
136 ASTERISK, ASTERISK, errorCode, ASTERISK);
139 if (rainyDayHandlerStatus == null) {
140 rainyDayHandlerStatus = catalogDbClient
141 .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(bbName,
142 ASTERISK, ASTERISK, ASTERISK, ASTERISK);
143 if (rainyDayHandlerStatus == null) {
144 handlingCode = "Abort";
147 handlingCode = rainyDayHandlerStatus.getPolicy();
149 handlingCode = rainyDayHandlerStatus.getSecondaryPolicy();
154 handlingCode = rainyDayHandlerStatus.getPolicy();
156 handlingCode = rainyDayHandlerStatus.getSecondaryPolicy();
159 if (!primaryPolicy) {
161 InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
162 request.setRetryStatusMessage("Retries have been exhausted.");
163 requestDbclient.updateInfraActiveRequests(request);
164 } catch (Exception ex) {
165 msoLogger.error("Failed to update Request Db Infra Active Requests with Retry Status",ex);
168 if (handlingCode.equals("RollbackToAssigned") && !aLaCarte) {
169 handlingCode = "Rollback";
172 msoLogger.debug("RainyDayHandler Status Code is: " + handlingCode);
173 execution.setVariable(HANDLING_CODE, handlingCode);
174 } catch (Exception e) {
175 msoLogger.error("Failed to determine RainyDayHandler Status. Seting handlingCode = Abort", e);
176 String code = this.environment.getProperty(defaultCode);
177 execution.setVariable(HANDLING_CODE, code);
181 public void setHandlingStatusSuccess(DelegateExecution execution) {
182 execution.setVariable(HANDLING_CODE, "Success");