1 package org.onap.so.adapters.audit;
3 import java.util.Optional;
5 import org.camunda.bpm.client.task.ExternalTask;
6 import org.onap.logging.ref.slf4j.ONAPLogConstants;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.core.env.Environment;
12 import org.springframework.stereotype.Component;
15 public abstract class AbstractAuditService {
17 private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class);
21 protected static final String UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI = "Unable to find all VServers and L-Interaces in A&AI";
24 public Environment env;
27 * @param auditHeatStackFailed
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());
36 return auditList.get().getAuditList().stream().filter(auditObject -> !auditObject.isDoesObjectExist())
37 .findFirst().map(v -> true).orElse(false);
44 * @param auditHeatStackFailed
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());
53 return auditList.get().getAuditList().stream().filter(AAIObjectAudit::isDoesObjectExist)
54 .findFirst().map(v -> true).orElse(false);
60 protected String[] getRetrySequence() {
61 return env.getProperty("mso.workflow.topics.retrySequence",String[].class);
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);
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;