Replaced all tabs with spaces in java and pom.xml
[so.git] / adapters / mso-openstack-adapters / src / main / java / org / onap / so / adapters / audit / AbstractAuditService.java
1 package org.onap.so.adapters.audit;
2
3 import java.util.Optional;
4 import org.camunda.bpm.client.task.ExternalTask;
5 import org.onap.logging.ref.slf4j.ONAPLogConstants;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8 import org.slf4j.MDC;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.core.env.Environment;
11 import org.springframework.stereotype.Component;
12
13 @Component
14 public abstract class AbstractAuditService {
15
16     private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class);
17
18
19
20     protected static final String UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI =
21             "Unable to find all VServers and L-Interaces in A&AI";
22
23     @Autowired
24     public Environment env;
25
26     /**
27      * @param auditHeatStackFailed
28      * @param auditList
29      * @return
30      */
31     protected boolean didCreateAuditFail(Optional<AAIObjectAuditList> auditList) {
32         if (auditList.get().getAuditList() != null && !auditList.get().getAuditList().isEmpty()) {
33             if (logger.isInfoEnabled()) {
34                 logger.info("Audit Results: {}", auditList.get().toString());
35             }
36             return auditList.get().getAuditList().stream().filter(auditObject -> !auditObject.isDoesObjectExist())
37                     .findFirst().map(v -> true).orElse(false);
38         } else {
39             return false;
40         }
41     }
42
43     /**
44      * @param auditHeatStackFailed
45      * @param auditList
46      * @return
47      */
48     protected boolean didDeleteAuditFail(Optional<AAIObjectAuditList> auditList) {
49         if (auditList.get().getAuditList() != null && !auditList.get().getAuditList().isEmpty()) {
50             if (logger.isInfoEnabled()) {
51                 logger.info("Audit Results: {}", auditList.get().toString());
52             }
53             return auditList.get().getAuditList().stream().filter(AAIObjectAudit::isDoesObjectExist).findFirst()
54                     .map(v -> true).orElse(false);
55         } else {
56             return false;
57         }
58     }
59
60     protected String[] getRetrySequence() {
61         return env.getProperty("mso.workflow.topics.retrySequence", String[].class);
62     }
63
64     protected void setupMDC(ExternalTask externalTask) {
65         String msoRequestId = externalTask.getVariable("mso-request-id");
66         if (msoRequestId != null && !msoRequestId.isEmpty())
67             MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId);
68     }
69
70     protected long calculateRetryDelay(int currentRetries) {
71         int retrySequence = getRetrySequence().length - currentRetries;
72         long retryMultiplier = Long.parseLong(env.getProperty("mso.workflow.topics.retryMultiplier", "6000"));
73         return Integer.parseInt(getRetrySequence()[retrySequence]) * retryMultiplier;
74     }
75 }