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.onap.so.objects.audit.AAIObjectAuditList;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.core.env.Environment;
35 import org.springframework.stereotype.Component;
38 public class AuditDeleteStackService extends AbstractAuditService {
40 private static final Logger logger = LoggerFactory.getLogger(AuditDeleteStackService.class);
43 protected HeatStackAudit heatStackAudit;
46 protected AuditVServer auditVservers;
49 protected AuditDataService auditDataService;
52 protected Environment env;
54 protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
55 AuditInventory auditInventory = externalTask.getVariable("auditInventory");
56 Map<String, Object> variables = new HashMap<>();
57 setupMDC(externalTask);
58 boolean success = false;
60 logger.info("Executing External Task Delete Audit Inventory. Retry Number: {}", externalTask.getRetries());
61 Optional<AAIObjectAuditList> auditListOpt = auditDataService.getStackDataFromRequestDb(auditInventory);
62 if (auditListOpt.isPresent()) {
63 auditVservers.auditVservers(auditListOpt.get());
65 logger.debug("Auditing Vservers based on vf module relationships");
66 auditListOpt = auditVservers.auditVserversThroughRelationships(auditInventory.getGenericVnfId(),
67 auditInventory.getHeatStackName());
69 auditListOpt.get().setHeatStackName(auditInventory.getHeatStackName());
70 auditListOpt.get().setAuditType("delete");
71 GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
72 variables.put("auditInventoryResult", objectMapper.getMapper().writeValueAsString(auditListOpt.get()));
73 success = !didDeleteAuditFail(auditListOpt.get());
75 } catch (Exception e) {
76 logger.error("Error during audit of stack", e);
78 variables.put("auditIsSuccessful", success);
80 externalTaskService.complete(externalTask, variables);
81 logger.debug("The External Task Id: {} Successful", externalTask.getId());
83 if (externalTask.getRetries() == null) {
84 logger.debug("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}",
85 externalTask.getId(), getRetrySequence().length);
86 externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI,
87 UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, getRetrySequence().length, 10000);
88 } else if (externalTask.getRetries() != null && externalTask.getRetries() - 1 == 0) {
89 logger.debug("The External Task Id: {} Failed, All Retries Exhausted", externalTask.getId());
90 externalTaskService.complete(externalTask, variables);
92 logger.debug("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ",
93 externalTask.getId(), externalTask.getRetries() - 1,
94 calculateRetryDelay(externalTask.getRetries()));
95 externalTaskService.handleFailure(externalTask, UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI,
96 UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI, externalTask.getRetries() - 1,
97 calculateRetryDelay(externalTask.getRetries()));
99 logger.debug("The External Task Id: {} Failed", externalTask.getId());