2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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.adapters.audit;
23 import java.util.HashMap;
25 import java.util.Optional;
26 import org.camunda.bpm.client.task.ExternalTask;
27 import org.camunda.bpm.client.task.ExternalTaskService;
28 import org.onap.so.audit.beans.AuditInventory;
29 import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.core.env.Environment;
34 import org.springframework.stereotype.Component;
37 public class AuditDeleteStackService extends AbstractAuditService {
39 private static final Logger logger = LoggerFactory.getLogger(AuditDeleteStackService.class);
42 public HeatStackAudit heatStackAudit;
45 public Environment environment;
47 protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
48 AuditInventory auditInventory = externalTask.getVariable("auditInventory");
49 Map<String, Object> variables = new HashMap<>();
50 setupMDC(externalTask);
51 boolean success = false;
53 logger.info("Executing External Task Audit Inventory, Retry Number: {} \n {}", auditInventory,
54 externalTask.getRetries());
55 Optional<AAIObjectAuditList> auditListOpt = heatStackAudit.auditHeatStack(auditInventory.getCloudRegion(),
56 auditInventory.getCloudOwner(), auditInventory.getTenantId(), auditInventory.getHeatStackName());
57 if (auditListOpt.isPresent()) {
58 GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
59 variables.put("auditInventoryResult", objectMapper.getMapper().writeValueAsString(auditListOpt.get()));
60 success = didDeleteAuditFail(auditListOpt);
62 } catch (Exception e) {
63 logger.error("Error during audit of stack", e);
65 variables.put("auditIsSuccessful", success);
67 externalTaskService.complete(externalTask, variables);
68 logger.debug("The External Task Id: {} Successful", externalTask.getId());
70 if (externalTask.getRetries() == null) {
71 logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
72 externalTask.getId(), getRetrySequence().length);
73 externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI,
74 UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, getRetrySequence().length, 10000);
75 } else if (externalTask.getRetries() != null && externalTask.getRetries() - 1 == 0) {
76 logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTask.getId());
77 externalTaskService.complete(externalTask);
79 logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
80 externalTask.getId(), externalTask.getRetries() - 1,
81 calculateRetryDelay(externalTask.getRetries()));
82 externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI,
83 UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, externalTask.getRetries() - 1,
84 calculateRetryDelay(externalTask.getRetries()));
86 logger.debug("The External Task Id: {} Failed", externalTask.getId());