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