aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main/java
diff options
context:
space:
mode:
authorBoslet, Cory <cory.boslet@att.com>2019-09-08 11:31:56 -0400
committerBenjamin, Max (mb388a) <mb388a@att.com>2019-09-08 11:31:56 -0400
commitff4b57e3632507a7a8e4b740722663f02caacc2a (patch)
tree1a6389d1e04d27ac8705510c29f834e5f1a1178e /common/src/main/java
parentf5f7d0763673dd0af81624eaa93b6951e1d299eb (diff)
Created external task utils in a common location
Created external task utils in a common location then refactored external task to use these common utils Updated junit errors and failures in openstack Removed env param and updated unit test with class Remove env file from parm in unit test class Match argu to match class abstract to con. removed implementation within anonymous class Issue-ID: SO-2291 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: I47c2850d750cbfe7ef67e2396fcb46db43e3cb97
Diffstat (limited to 'common/src/main/java')
-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());
+ }
+
+}