aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main')
-rw-r--r--common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java46
-rw-r--r--common/src/main/java/org/onap/so/utils/ExternalTaskUtils.java46
2 files changed, 92 insertions, 0 deletions
diff --git a/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java b/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java
new file mode 100644
index 0000000000..e43b431821
--- /dev/null
+++ b/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java
@@ -0,0 +1,46 @@
+package org.onap.so.utils;
+
+import java.security.GeneralSecurityException;
+import org.camunda.bpm.client.ExternalTaskClient;
+import org.camunda.bpm.client.interceptor.ClientRequestInterceptor;
+import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ExternalTaskServiceUtils {
+
+ @Autowired
+ public Environment env;
+
+ private static final Logger logger = LoggerFactory.getLogger(ExternalTaskServiceUtils.class);
+
+ public ExternalTaskClient createExternalTaskClient() throws Exception {
+ String auth = getAuth();
+ ClientRequestInterceptor interceptor = createClientInterceptor(auth);
+ return ExternalTaskClient.create().baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1)
+ .addInterceptor(interceptor).asyncResponseTimeout(120000).build();
+ }
+
+ protected ClientRequestInterceptor createClientInterceptor(String auth) {
+ return new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"), auth);
+ }
+
+ protected String getAuth() throws Exception {
+ try {
+ return CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey"));
+ } catch (IllegalStateException | GeneralSecurityException e) {
+ logger.error("Error Decrypting Password", e);
+ throw new Exception("Cannot load password");
+ }
+ }
+
+ public int getMaxClients() {
+ return Integer.parseInt(env.getProperty("workflow.topics.maxClients", "3"));
+ }
+
+
+}
diff --git a/common/src/main/java/org/onap/so/utils/ExternalTaskUtils.java b/common/src/main/java/org/onap/so/utils/ExternalTaskUtils.java
new file mode 100644
index 0000000000..349767fc5b
--- /dev/null
+++ b/common/src/main/java/org/onap/so/utils/ExternalTaskUtils.java
@@ -0,0 +1,46 @@
+package org.onap.so.utils;
+
+import org.camunda.bpm.client.task.ExternalTask;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+@Component
+public abstract class ExternalTaskUtils {
+
+ @Autowired
+ Environment env;
+
+ private static final Logger logger = LoggerFactory.getLogger(ExternalTaskUtils.class);
+
+ public long calculateRetryDelay(int currentRetries) {
+ int retrySequence = getRetrySequence().length - currentRetries;
+ return Integer.parseInt(getRetrySequence()[retrySequence]) * getRetryMutiplier();
+ }
+
+ protected Long getRetryMutiplier() {
+ return Long.parseLong(env.getProperty("mso.workflow.topics.retryMultiplier", "6000"));
+ }
+
+ protected String[] getRetrySequence() {
+ String[] seq = {"1", "1", "2", "3", "5", "8", "13", "20"};
+ if (env.getProperty("mso.workflow.topics.retrySequence") != null) {
+ seq = env.getProperty("mso.workflow.topics.retrySequence", String[].class);
+ }
+ return seq;
+ }
+
+ protected void setupMDC(ExternalTask externalTask) {
+ logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
+ 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());
+ }
+
+}