1 package org.onap.so.adapters.audit;
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;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.core.env.Environment;
11 import org.springframework.stereotype.Component;
14 public abstract class AbstractAuditService {
16 private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class);
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";
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).findFirst()
54 .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;