From cd4e5b408603a13dabc58f832e4aae4194e81995 Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Wed, 25 Mar 2020 16:04:41 -0400 Subject: convert openstack to external tasks Use external tasks to communicate with openstack adapter Will be more resilient to failures Refactored all flows to use external tasks not REST calls Rollback is now an external task Ensured backwards compatibility Issue-ID: SO-2767 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I8afdb89c688d756aed0f25f7d9a7fb898142554d --- .../so/externaltasks/logging/AuditMDCSetup.java | 56 --------------------- .../org/onap/so/logging/tasks/AuditMDCSetup.java | 57 ++++++++++++++++++++++ .../onap/so/utils/ExternalTaskServiceUtils.java | 7 ++- .../java/org/onap/so/utils/ExternalTaskUtils.java | 6 +-- 4 files changed, 66 insertions(+), 60 deletions(-) delete mode 100644 common/src/main/java/org/onap/so/externaltasks/logging/AuditMDCSetup.java create mode 100644 common/src/main/java/org/onap/so/logging/tasks/AuditMDCSetup.java (limited to 'common/src/main/java/org/onap') diff --git a/common/src/main/java/org/onap/so/externaltasks/logging/AuditMDCSetup.java b/common/src/main/java/org/onap/so/externaltasks/logging/AuditMDCSetup.java deleted file mode 100644 index 9f71e61e1f..0000000000 --- a/common/src/main/java/org/onap/so/externaltasks/logging/AuditMDCSetup.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.onap.so.externaltasks.logging; - -import java.time.ZoneOffset; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import org.camunda.bpm.client.task.ExternalTask; -import org.onap.logging.filter.base.MDCSetup; -import org.onap.logging.filter.base.ONAPComponents; -import org.onap.logging.ref.slf4j.ONAPLogConstants; -import org.onap.so.logger.MdcConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; -import org.springframework.stereotype.Component; - -@Component -public class AuditMDCSetup { - - private static final Logger logger = LoggerFactory.getLogger(AuditMDCSetup.class); - - private MDCSetup mdcSetup = new MDCSetup(); - - public void setupMDC(ExternalTask externalTask) { - MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, - ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); - String msoRequestId = externalTask.getVariable("mso-request-id"); - if (msoRequestId != null && !msoRequestId.isEmpty()) { - MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId); - } - MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, externalTask.getTopicName()); - MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, ONAPComponents.OPENSTACK_ADAPTER.toString()); - setResponseCode(ONAPLogConstants.ResponseStatus.INPROGRESS.toString()); - setElapsedTime(); - mdcSetup.setServerFQDN(); - logger.info(ONAPLogConstants.Markers.ENTRY, "Entering"); - } - - public void setElapsedTime() { - DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME; - MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, Long.toString(System.currentTimeMillis() - ZonedDateTime - .parse(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP), timeFormatter).toInstant().toEpochMilli())); - } - - public void setResponseCode(String code) { - MDC.put(MdcConstants.OPENSTACK_STATUS_CODE, code); - MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, code); - } - - public void clearClientMDCs() { - MDC.remove(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE); - MDC.remove(MdcConstants.OPENSTACK_STATUS_CODE); - MDC.remove(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP); - MDC.remove(ONAPLogConstants.MDCs.ELAPSED_TIME); - MDC.remove(ONAPLogConstants.MDCs.PARTNER_NAME); - } -} diff --git a/common/src/main/java/org/onap/so/logging/tasks/AuditMDCSetup.java b/common/src/main/java/org/onap/so/logging/tasks/AuditMDCSetup.java new file mode 100644 index 0000000000..8d98307a43 --- /dev/null +++ b/common/src/main/java/org/onap/so/logging/tasks/AuditMDCSetup.java @@ -0,0 +1,57 @@ +package org.onap.so.logging.tasks; + +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import org.camunda.bpm.client.task.ExternalTask; +import org.onap.logging.filter.base.MDCSetup; +import org.onap.logging.filter.base.ONAPComponents; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.so.logger.MdcConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.springframework.stereotype.Component; + +@Component +public class AuditMDCSetup { + + private static final Logger logger = LoggerFactory.getLogger(AuditMDCSetup.class); + + private MDCSetup mdcSetup = new MDCSetup(); + + public void setupMDC(ExternalTask externalTask) { + MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, + ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); + String msoRequestId = externalTask.getVariable("mso-request-id"); + if (msoRequestId != null && !msoRequestId.isEmpty()) { + MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId); + } + MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, externalTask.getTopicName()); + MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, ONAPComponents.OPENSTACK_ADAPTER.toString()); + setResponseCode(ONAPLogConstants.ResponseStatus.INPROGRESS.toString()); + setElapsedTime(); + mdcSetup.setServerFQDN(); + logger.info(ONAPLogConstants.Markers.ENTRY, "Entering"); + } + + public void setElapsedTime() { + DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME; + MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, Long.toString(System.currentTimeMillis() - ZonedDateTime + .parse(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP), timeFormatter).toInstant().toEpochMilli())); + } + + public void setResponseCode(String code) { + MDC.put(MdcConstants.OPENSTACK_STATUS_CODE, code); + MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, code); + } + + public void clearClientMDCs() { + MDC.remove(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE); + MDC.remove(MdcConstants.OPENSTACK_STATUS_CODE); + MDC.remove(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP); + MDC.remove(ONAPLogConstants.MDCs.ELAPSED_TIME); + MDC.remove(ONAPLogConstants.MDCs.PARTNER_NAME); + } + +} diff --git a/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java b/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java index 035ad1dc81..840a978a61 100644 --- a/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java +++ b/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java @@ -51,7 +51,12 @@ public class ExternalTaskServiceUtils { } public int getMaxClients() { - return Integer.parseInt(env.getProperty("workflow.topics.maxClients", "3")); + return Integer.parseInt(env.getProperty("workflow.topics.maxClients", "10")); + } + + public Long getLockDuration() { + Long lockDuration = Long.parseLong(env.getProperty("mso.audit.lock-time", "60000")); + return lockDuration; } @ScheduledLogging diff --git a/common/src/main/java/org/onap/so/utils/ExternalTaskUtils.java b/common/src/main/java/org/onap/so/utils/ExternalTaskUtils.java index 9488187003..d414135570 100644 --- a/common/src/main/java/org/onap/so/utils/ExternalTaskUtils.java +++ b/common/src/main/java/org/onap/so/utils/ExternalTaskUtils.java @@ -9,11 +9,11 @@ import org.springframework.stereotype.Component; @Component public abstract class ExternalTaskUtils { + private static final Logger logger = LoggerFactory.getLogger(ExternalTaskUtils.class); + @Autowired Environment env; - private static final Logger logger = LoggerFactory.getLogger(ExternalTaskUtils.class); - private final RetrySequenceLevel retrySequenceLevel; public ExternalTaskUtils() { @@ -49,7 +49,7 @@ public abstract class ExternalTaskUtils { return seqInter; case LONG: String[] seqLong = {"1", "1", "2", "3", "5", "8", "13", "20"}; - if (env.getProperty("mso.workflow.topics.retrySequence") != null) { + if (env.getProperty("mso.workflow.topics.retrySequence.long") != null) { seqLong = env.getProperty("mso.workflow.topics.retrySequence", String[].class); } return seqLong; -- cgit 1.2.3-korg