From d0ec4426cbe4da7dbf94a4faf6e36c032a81c395 Mon Sep 17 00:00:00 2001 From: "Smokowski, Steven" Date: Fri, 7 Feb 2020 17:14:39 -0500 Subject: Initial commit to check client alive Initial commit to check client alive Issue-ID: SO-2653 Signed-off-by: Benjamin, Max (mb388a) Change-Id: Ib9f4cf7f5815bd9b8d0d42417f3e5fd83382547a --- .../onap/so/utils/ExternalTaskServiceUtils.java | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'common/src/main/java/org') 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 e43b431821..4f13cec8f4 100644 --- a/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java +++ b/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java @@ -1,6 +1,8 @@ package org.onap.so.utils; import java.security.GeneralSecurityException; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.camunda.bpm.client.ExternalTaskClient; import org.camunda.bpm.client.interceptor.ClientRequestInterceptor; import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider; @@ -8,21 +10,30 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; + + @Component public class ExternalTaskServiceUtils { @Autowired public Environment env; + protected Set taskClients = ConcurrentHashMap.newKeySet(); + + 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(); + ExternalTaskClient client = + ExternalTaskClient.create().baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1) + .addInterceptor(interceptor).asyncResponseTimeout(120000).build(); + taskClients.add(client); + return client; } protected ClientRequestInterceptor createClientInterceptor(String auth) { @@ -42,5 +53,13 @@ public class ExternalTaskServiceUtils { return Integer.parseInt(env.getProperty("workflow.topics.maxClients", "3")); } + @Scheduled(fixedDelay = 30000) + public void checkAllClientsActive() { + getClients().stream().filter(client -> !client.isActive()).forEach(ExternalTaskClient::start); + } + + protected Set getClients() { + return taskClients; + } } -- cgit 1.2.3-korg