2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
7 * Copyright (C) 2019 IBM
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.adapters.tasks.inventory;
25 import org.camunda.bpm.client.task.ExternalTask;
26 import org.camunda.bpm.client.task.ExternalTaskService;
27 import org.onap.logging.ref.slf4j.ONAPLogConstants;
28 import org.onap.so.cloud.resource.beans.CloudInformation;
29 import org.onap.so.logging.tasks.AuditMDCSetup;
30 import org.onap.so.utils.ExternalTaskUtils;
31 import org.onap.so.utils.RetrySequenceLevel;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Component;
39 public class CreateInventoryTask extends ExternalTaskUtils {
41 private static final String UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI = "Unable to write all inventory to A&AI";
43 private static final Logger logger = LoggerFactory.getLogger(CreateInventoryTask.class);
45 private static final String AAI_INVENTORY_FAILURE = "AAIInventoryFailure";
48 CreateAAIInventory createInventory;
51 public AuditMDCSetup mdcSetup;
53 public CreateInventoryTask() {
54 super(RetrySequenceLevel.SHORT);
58 public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
59 mdcSetup.setupMDC(externalTask);
60 boolean inventoryException = false;
61 String externalTaskId = externalTask.getId();
62 CloudInformation cloudInformation = externalTask.getVariable("cloudInformation");
63 boolean success = true;
64 if (cloudInformation != null) {
65 Integer retryCount = externalTask.getRetries();
67 logger.info("Executing External Task Create Inventory, Retry Number: {} \n {}", retryCount,
68 cloudInformation.toString());
69 createInventory.heatbridge(cloudInformation);
70 } catch (Exception e) {
71 logger.error("Error during inventory of stack", e);
74 mdcSetup.setElapsedTime();
76 externalTaskService.complete(externalTask);
77 mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.COMPLETE.toString());
78 logger.debug("The External Task Id: {} Successful", externalTaskId);
79 logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
80 mdcSetup.clearClientMDCs();
82 if (retryCount == null) {
83 logger.error("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
84 externalTaskId, getRetrySequence().length);
85 externalTaskService.handleFailure(externalTask, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI,
86 UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, getRetrySequence().length, 10000);
87 } else if (retryCount != null && retryCount - 1 == 0) {
88 externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);
89 mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.ERROR.toString());
90 logger.error("The External Task Id: {} Failed, All Retries Exhausted", externalTaskId);
91 logger.info(ONAPLogConstants.Markers.EXIT, "Exiting");
93 logger.error("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
94 externalTaskId, retryCount - 1, calculateRetryDelay(retryCount));
95 externalTaskService.handleFailure(externalTask, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI,
96 UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, retryCount - 1, calculateRetryDelay(retryCount));
98 logger.error("The External Task Id: {} Failed", externalTaskId);
101 logger.error("The External Task Id: {} Failed, No Cloud Information Provided", externalTaskId);
102 externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE);