From dabc6577da6f6e425015af724b45bdf09ce51faa Mon Sep 17 00:00:00 2001 From: Pierre-Yves Date: Fri, 2 Aug 2024 17:26:50 -0700 Subject: [PATCH] Move to java-client-operate 8.5.8-rc1 --- pom.xml | 24 +-- .../bpmnengine/BpmnEngineFactory.java | 17 +- .../camunda8/BpmnEngineCamunda8.java | 164 ++++++++++++------ .../configuration/BpmnEngineList.java | 105 ++++++----- src/main/resources/application.yaml | 3 + 5 files changed, 208 insertions(+), 105 deletions(-) diff --git a/pom.xml b/pom.xml index c208535..a09791e 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,8 @@ ${java.version} ${java.version} - 8.3.0 - 8.3.0 + 8.5.7 + 8.5.5 7.19.0 @@ -52,12 +52,12 @@ io.camunda.spring spring-boot-starter-camunda - ${zeebe.version} + ${version.zeebe} io.camunda zeebe-client-java - ${zeebe-client.version} + ${version.zeebe-client} @@ -97,29 +97,31 @@ camunda-operate-client-java 8.1.8.1 ---> - - - + + io.camunda.spring java-client-operate 8.5.8-rc1 + io.camunda camunda-tasklist-client-java 1.6.1 + + + javax.xml.bind diff --git a/src/main/java/org/camunda/automator/bpmnengine/BpmnEngineFactory.java b/src/main/java/org/camunda/automator/bpmnengine/BpmnEngineFactory.java index 06a959f..f2be74d 100644 --- a/src/main/java/org/camunda/automator/bpmnengine/BpmnEngineFactory.java +++ b/src/main/java/org/camunda/automator/bpmnengine/BpmnEngineFactory.java @@ -7,6 +7,7 @@ package org.camunda.automator.bpmnengine; import org.camunda.automator.bpmnengine.camunda7.BpmnEngineCamunda7; +import org.camunda.automator.bpmnengine.camunda8.BenchmarkStartPiExceptionHandlingStrategy; import org.camunda.automator.bpmnengine.camunda8.BpmnEngineCamunda8; import org.camunda.automator.bpmnengine.dummy.BpmnEngineDummy; import org.camunda.automator.configuration.BpmnEngineList; @@ -15,18 +16,28 @@ import java.util.EnumMap; import java.util.Map; -/** + +/* * This can't be a Component, to be used in AutomatorAPI */ public class BpmnEngineFactory { private static final BpmnEngineFactory bpmnEngineFactory = new BpmnEngineFactory(); Map cacheEngine = new EnumMap<>(BpmnEngineList.CamundaEngine.class); + BenchmarkStartPiExceptionHandlingStrategy benchmarkStartPiExceptionHandlingStrategy=null; + private BpmnEngineFactory() { + // use the getInstance() method + } public static BpmnEngineFactory getInstance() { return bpmnEngineFactory; } + public static BpmnEngineFactory getInstance(BenchmarkStartPiExceptionHandlingStrategy benchmarkStartPiExceptionHandlingStrategy) { + bpmnEngineFactory.benchmarkStartPiExceptionHandlingStrategy = benchmarkStartPiExceptionHandlingStrategy; + return bpmnEngineFactory; + } + public BpmnEngine getEngineFromConfiguration(BpmnEngineList.BpmnServerDefinition serverDefinition, boolean logDebug) throws AutomatorException { BpmnEngine engine = cacheEngine.get(serverDefinition.serverType); @@ -42,9 +53,9 @@ public BpmnEngine getEngineFromConfiguration(BpmnEngineList.BpmnServerDefinition engine = switch (serverDefinition.serverType) { case CAMUNDA_7 -> new BpmnEngineCamunda7(serverDefinition, logDebug); - case CAMUNDA_8 -> BpmnEngineCamunda8.getFromServerDefinition(serverDefinition, logDebug); + case CAMUNDA_8 -> BpmnEngineCamunda8.getFromServerDefinition(serverDefinition, benchmarkStartPiExceptionHandlingStrategy, logDebug); - case CAMUNDA_8_SAAS -> BpmnEngineCamunda8.getFromServerDefinition(serverDefinition, logDebug); + case CAMUNDA_8_SAAS -> BpmnEngineCamunda8.getFromServerDefinition(serverDefinition, benchmarkStartPiExceptionHandlingStrategy, logDebug); case DUMMY -> new BpmnEngineDummy(serverDefinition); diff --git a/src/main/java/org/camunda/automator/bpmnengine/camunda8/BpmnEngineCamunda8.java b/src/main/java/org/camunda/automator/bpmnengine/camunda8/BpmnEngineCamunda8.java index 38c31a8..d315bb5 100644 --- a/src/main/java/org/camunda/automator/bpmnengine/camunda8/BpmnEngineCamunda8.java +++ b/src/main/java/org/camunda/automator/bpmnengine/camunda8/BpmnEngineCamunda8.java @@ -1,15 +1,21 @@ package org.camunda.automator.bpmnengine.camunda8; +import com.fasterxml.jackson.databind.ObjectMapper; import io.camunda.operate.CamundaOperateClient; -import io.camunda.operate.auth.AuthInterface; -import io.camunda.operate.dto.FlownodeInstance; -import io.camunda.operate.dto.FlownodeInstanceState; -import io.camunda.operate.dto.ProcessInstance; -import io.camunda.operate.dto.ProcessInstanceState; -import io.camunda.operate.dto.SearchResult; +import io.camunda.operate.CamundaOperateClientConfiguration; +import io.camunda.operate.auth.JwtAuthentication; +import io.camunda.operate.auth.JwtCredential; +import io.camunda.operate.auth.SimpleAuthentication; +import io.camunda.operate.auth.SimpleCredential; +import io.camunda.operate.auth.TokenResponseMapper; import io.camunda.operate.exception.OperateException; +import io.camunda.operate.model.FlowNodeInstance; +import io.camunda.operate.model.FlowNodeInstanceState; +import io.camunda.operate.model.ProcessInstance; +import io.camunda.operate.model.ProcessInstanceState; +import io.camunda.operate.model.SearchResult; import io.camunda.operate.search.DateFilter; -import io.camunda.operate.search.FlownodeInstanceFilter; +import io.camunda.operate.search.FlowNodeInstanceFilter; import io.camunda.operate.search.ProcessInstanceFilter; import io.camunda.operate.search.SearchQuery; import io.camunda.operate.search.Sort; @@ -35,6 +41,7 @@ import io.camunda.zeebe.client.api.worker.JobWorkerBuilderStep1; import io.camunda.zeebe.client.impl.oauth.OAuthCredentialsProvider; import io.camunda.zeebe.client.impl.oauth.OAuthCredentialsProviderBuilder; +import org.apache.hc.client5.http.impl.classic.HttpClients; import org.camunda.automator.bpmnengine.BpmnEngine; import org.camunda.automator.bpmnengine.camunda8.refactoring.RefactoredCommandWrapper; import org.camunda.automator.configuration.BpmnEngineList; @@ -44,9 +51,10 @@ import org.camunda.automator.engine.flow.FixedBackoffSupplier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import java.io.File; +import java.net.URI; +import java.net.URL; import java.time.Duration; import java.util.ArrayList; import java.util.HashMap; @@ -73,13 +81,14 @@ public class BpmnEngineCamunda8 implements BpmnEngine { Random random = new Random(System.currentTimeMillis()); private ZeebeClient zeebeClient; private CamundaOperateClient operateClient; - private CamundaTaskListClient taskClient; - @Autowired - private BenchmarkStartPiExceptionHandlingStrategy exceptionHandlingStrategy; + private CamundaTaskListClient taskClient; + + private final BenchmarkStartPiExceptionHandlingStrategy exceptionHandlingStrategy; // Default private BpmnEngineList.CamundaEngine typeCamundaEngine = BpmnEngineList.CamundaEngine.CAMUNDA_8; - private BpmnEngineCamunda8() { + private BpmnEngineCamunda8(BenchmarkStartPiExceptionHandlingStrategy exceptionHandlingStrategy ) { + this.exceptionHandlingStrategy = exceptionHandlingStrategy; } /** @@ -89,8 +98,9 @@ private BpmnEngineCamunda8() { * @param logDebug if true, operation will be log as debug level */ public static BpmnEngineCamunda8 getFromServerDefinition(BpmnEngineList.BpmnServerDefinition serverDefinition, + BenchmarkStartPiExceptionHandlingStrategy benchmarkStartPiExceptionHandlingStrategy, boolean logDebug) { - BpmnEngineCamunda8 bpmnEngineCamunda8 = new BpmnEngineCamunda8(); + BpmnEngineCamunda8 bpmnEngineCamunda8 = new BpmnEngineCamunda8(benchmarkStartPiExceptionHandlingStrategy); bpmnEngineCamunda8.serverDefinition = serverDefinition; return bpmnEngineCamunda8; @@ -111,8 +121,9 @@ public static BpmnEngineCamunda8 getFromCamunda8(String zeebeSelfGatewayAddress, String operateUrl, String operateUserName, String operateUserPassword, - String tasklistUrl) { - BpmnEngineCamunda8 bpmnEngineCamunda8 = new BpmnEngineCamunda8(); + String tasklistUrl, + BenchmarkStartPiExceptionHandlingStrategy benchmarkStartPiExceptionHandlingStrategy) { + BpmnEngineCamunda8 bpmnEngineCamunda8 = new BpmnEngineCamunda8(benchmarkStartPiExceptionHandlingStrategy); bpmnEngineCamunda8.serverDefinition = new BpmnEngineList.BpmnServerDefinition(); bpmnEngineCamunda8.serverDefinition.serverType = BpmnEngineList.CamundaEngine.CAMUNDA_8; bpmnEngineCamunda8.serverDefinition = new BpmnEngineList.BpmnServerDefinition(); @@ -145,7 +156,6 @@ public static BpmnEngineCamunda8 getFromCamunda8(String zeebeSelfGatewayAddress, * @param tasklistUrl Url to access TaskList */ public static BpmnEngineCamunda8 getFromCamunda8SaaS( - String zeebeSaasCloudRegister, String zeebeSaasCloudRegion, String zeebeSaasCloudClusterId, @@ -156,8 +166,9 @@ public static BpmnEngineCamunda8 getFromCamunda8SaaS( String operateUrl, String operateUserName, String operateUserPassword, - String tasklistUrl) { - BpmnEngineCamunda8 bpmnEngineCamunda8 = new BpmnEngineCamunda8(); + String tasklistUrl, + BenchmarkStartPiExceptionHandlingStrategy benchmarkStartPiExceptionHandlingStrategy) { + BpmnEngineCamunda8 bpmnEngineCamunda8 = new BpmnEngineCamunda8(benchmarkStartPiExceptionHandlingStrategy); bpmnEngineCamunda8.serverDefinition = new BpmnEngineList.BpmnServerDefinition(); bpmnEngineCamunda8.serverDefinition.serverType = BpmnEngineList.CamundaEngine.CAMUNDA_8; @@ -200,7 +211,7 @@ public void connection() throws AutomatorException { this.typeCamundaEngine = this.serverDefinition.serverType; final ZeebeClientBuilder clientBuilder; - AuthInterface saOperate; + CamundaOperateClientConfiguration configurationOperate; io.camunda.tasklist.auth.AuthInterface saTaskList; // ---------------------------- Camunda Saas @@ -235,12 +246,34 @@ public void connection() throws AutomatorException { throw new AutomatorException( "Bad credential [" + serverDefinition.name + "] Analysis:" + analysis + " fail : " + e.getMessage()); } + try { + URL authUrl = URI.create("https://login.cloud.camunda.io/oauth/token").toURL(); + URL operateUrl = URI.create("https://" + serverDefinition.zeebeSaasRegion + ".operate.camunda.io/" + + serverDefinition.zeebeSaasClusterId).toURL(); + + JwtCredential credentials = new JwtCredential(serverDefinition.zeebeSaasClientId, + serverDefinition.zeebeSaasClientSecret, "operate.camunda.io", authUrl); + ObjectMapper objectMapper = new ObjectMapper(); + + JwtAuthentication authentication = new io.camunda.operate.auth.JwtAuthentication(credentials, + (TokenResponseMapper) objectMapper); + CamundaOperateClientConfiguration configuration = new CamundaOperateClientConfiguration(authentication, + operateUrl, objectMapper, + (org.apache.hc.client5.http.impl.classic.CloseableHttpClient) HttpClients.createDefault()); - saOperate = new io.camunda.operate.auth.SaasAuthentication(serverDefinition.zeebeSaasClientId, - serverDefinition.zeebeSaasClientSecret); - saTaskList = new io.camunda.tasklist.auth.SaasAuthentication(serverDefinition.zeebeSaasClientId, - serverDefinition.zeebeSaasClientSecret); + configurationOperate = new CamundaOperateClientConfiguration(authentication, operateUrl, objectMapper, + HttpClients.createDefault()); + + saTaskList = new io.camunda.tasklist.auth.SaasAuthentication(serverDefinition.zeebeSaasClientId, + serverDefinition.zeebeSaasClientSecret); + } catch (Exception e) { + zeebeClient = null; + logger.error("Can't connect to SaaS environemnt[{}] Analysis:{} : {}", serverDefinition.name, analysis, e); + throw new AutomatorException( + "Can't connect to SaaS environment[" + serverDefinition.name + "] Analysis:" + analysis + " fail : " + + e.getMessage()); + } typeCamundaEngine = BpmnEngineList.CamundaEngine.CAMUNDA_8_SAAS; //---------------------------- Camunda 8 Self Manage @@ -252,8 +285,35 @@ public void connection() throws AutomatorException { clientBuilder = ZeebeClient.newClientBuilder() .gatewayAddress(serverDefinition.zeebeGatewayAddress) .usePlaintext(); - saOperate = new io.camunda.operate.auth.SimpleAuthentication(serverDefinition.operateUserName, - serverDefinition.operateUserPassword, serverDefinition.operateUrl); + try { + if (serverDefinition.operateAuthenticationUrl != null) { + URL operateUrl = URI.create(serverDefinition.operateUrl).toURL(); + // "http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token" + URL authUrl = URI.create(serverDefinition.operateAuthenticationUrl).toURL(); + + JwtCredential credentials = new JwtCredential(serverDefinition.operateClientId, + serverDefinition.operateClientSecret, serverDefinition.operateAudience, authUrl); + ObjectMapper objectMapper = new ObjectMapper(); + JwtAuthentication authentication = new JwtAuthentication(credentials, (TokenResponseMapper) objectMapper); + configurationOperate = new CamundaOperateClientConfiguration(authentication, operateUrl, objectMapper, + HttpClients.createDefault()); + } else { + URL operateUrl = URI.create(serverDefinition.operateUrl).toURL(); + SimpleCredential credentials = new SimpleCredential(serverDefinition.operateUserName, + serverDefinition.operateUserPassword, operateUrl, Duration.ofMinutes(10)); + SimpleAuthentication authentication = new SimpleAuthentication(credentials); + ObjectMapper objectMapper = new ObjectMapper(); + configurationOperate = new CamundaOperateClientConfiguration(authentication, operateUrl, objectMapper, + HttpClients.createDefault()); + } + } catch (Exception e) { + zeebeClient = null; + logger.error("Can't connect to SaaS environment[{}] Analysis:{} : {}", serverDefinition.name, analysis, e); + throw new AutomatorException( + "Can't connect to SaaS environemnt[" + serverDefinition.name + "] Analysis:" + analysis + " fail : " + + e.getMessage()); + } + saTaskList = new io.camunda.tasklist.auth.SimpleAuthentication(serverDefinition.operateUserName, serverDefinition.operateUserPassword); typeCamundaEngine = BpmnEngineList.CamundaEngine.CAMUNDA_8; @@ -298,9 +358,8 @@ public void connection() throws AutomatorException { if (serverDefinition.operateUrl != null && !serverDefinition.operateUrl.isEmpty()) { isOk = stillOk(serverDefinition.operateUrl, "operateUrl", analysis, false, isOk); analysis.append("Operate connection..."); - operateClient = new CamundaOperateClient.Builder().operateUrl(serverDefinition.operateUrl) - .authentication(saOperate) - .build(); + operateClient = new CamundaOperateClient(configurationOperate); + analysis.append("successfully, "); } else analysis.append("No operate connection required, "); @@ -323,6 +382,7 @@ public void connection() throws AutomatorException { } catch (Exception e) { zeebeClient = null; + logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e); throw new AutomatorException( "Can't connect to Server[" + serverDefinition.name + "] Analysis:" + analysis + " Fail : " + e.getMessage()); } @@ -505,11 +565,11 @@ public List searchUserTasks(String userTaskId, int maxResult) throws Aut /* ******************************************************************** */ @Override public RegisteredTask registerServiceTask(String workerId, - String topic, - boolean streamEnabled, - Duration lockTime, - Object jobHandler, - FixedBackoffSupplier backoffSupplier) { + String topic, + boolean streamEnabled, + Duration lockTime, + Object jobHandler, + FixedBackoffSupplier backoffSupplier) { if (!(jobHandler instanceof JobHandler)) { logger.error("handler is not a JobHandler implementation, can't register the worker [{}], topic [{}]", workerId, topic); @@ -551,12 +611,12 @@ public void executeUserTask(String userTaskId, String userId, Map searchServiceTasks(String processInstanceId, String serviceTaskId, String topic, int maxResult) throws AutomatorException { try { - if (operateClient==null) { + if (operateClient == null) { throw new AutomatorException("No Operate connection was provided"); } long processInstanceIdLong = Long.parseLong(processInstanceId); - ProcessInstanceFilter processInstanceFilter = new ProcessInstanceFilter.Builder().parentKey(processInstanceIdLong) + ProcessInstanceFilter processInstanceFilter = ProcessInstanceFilter.builder().parentKey(processInstanceIdLong) .build(); SearchQuery processInstanceQuery = new SearchQuery.Builder().filter(processInstanceFilter).size(100).build(); @@ -629,21 +689,21 @@ public void throwBpmnServiceTask(String serviceTaskId, public List searchTasksByProcessInstanceId(String processInstanceId, String taskId, int maxResult) throws AutomatorException { try { - if (operateClient==null) { + if (operateClient == null) { throw new AutomatorException("No Operate connection was provided"); } // impossible to filter by the task name/ task tyoe, so be ready to get a lot of flowNode and search the correct onee - FlownodeInstanceFilter flownodeFilter = new FlownodeInstanceFilter.Builder().processInstanceKey( + FlowNodeInstanceFilter flownodeFilter = FlowNodeInstanceFilter.builder().processInstanceKey( Long.valueOf(processInstanceId)).build(); SearchQuery flownodeQuery = new SearchQuery.Builder().filter(flownodeFilter).size(maxResult).build(); - List flownodes = operateClient.searchFlownodeInstances(flownodeQuery); + List flownodes = operateClient.searchFlowNodeInstances(flownodeQuery); return flownodes.stream().filter(t -> taskId.equals(t.getFlowNodeId())).map(t -> { TaskDescription taskDescription = new TaskDescription(); taskDescription.taskId = t.getFlowNodeId(); taskDescription.type = getTaskType(t.getType()); // to implement - taskDescription.isCompleted = FlownodeInstanceState.COMPLETED.equals(t.getState()); // to implement + taskDescription.isCompleted = FlowNodeInstanceState.COMPLETED.equals(t.getState()); // to implement return taskDescription; }).toList(); @@ -656,12 +716,12 @@ public List searchProcessInstanceByVariable(String processId Map filterVariables, int maxResult) throws AutomatorException { try { - if (operateClient==null) { + if (operateClient == null) { throw new AutomatorException("No Operate connection was provided"); } // impossible to filter by the task name/ task tyoe, so be ready to get a lot of flowNode and search the correct onee - ProcessInstanceFilter processInstanceFilter = new ProcessInstanceFilter.Builder().bpmnProcessId(processId) + ProcessInstanceFilter processInstanceFilter = ProcessInstanceFilter.builder().bpmnProcessId(processId) .build(); SearchQuery processInstanceQuery = new SearchQuery.Builder().filter(processInstanceFilter) @@ -714,16 +774,16 @@ else if (taskTypeC8.equals("PARALLEL_GATEWAY")) @Override public Map getVariables(String processInstanceId) throws AutomatorException { try { - if (operateClient==null) { + if (operateClient == null) { throw new AutomatorException("No Operate connection was provided"); } // impossible to filter by the task name/ task tyoe, so be ready to get a lot of flowNode and search the correct onee - VariableFilter variableFilter = new VariableFilter.Builder().processInstanceKey(Long.valueOf(processInstanceId)) + VariableFilter variableFilter = VariableFilter.builder().processInstanceKey(Long.valueOf(processInstanceId)) .build(); SearchQuery variableQuery = new SearchQuery.Builder().filter(variableFilter).build(); - List listVariables = operateClient.searchVariables(variableQuery); + List listVariables = operateClient.searchVariables(variableQuery); Map variables = new HashMap<>(); listVariables.forEach(t -> variables.put(t.getName(), t.getValue())); @@ -741,7 +801,7 @@ public Map getVariables(String processInstanceId) throws Automat /* ******************************************************************** */ public long countNumberOfProcessInstancesCreated(String processId, DateFilter startDate, DateFilter endDate) throws AutomatorException { - if (operateClient==null) { + if (operateClient == null) { throw new AutomatorException("No Operate connection was provided"); } @@ -749,7 +809,7 @@ public long countNumberOfProcessInstancesCreated(String processId, DateFilter st try { int cumul = 0; SearchResult searchResult = null; - queryBuilder = queryBuilder.filter(new ProcessInstanceFilter.Builder().bpmnProcessId(processId).build()); + queryBuilder = queryBuilder.filter(ProcessInstanceFilter.builder().bpmnProcessId(processId).build()); queryBuilder.sort(new Sort("key", SortOrder.ASC)); int maxLoop = 0; do { @@ -772,7 +832,7 @@ public long countNumberOfProcessInstancesCreated(String processId, DateFilter st public long countNumberOfProcessInstancesEnded(String processId, DateFilter startDate, DateFilter endDate) throws AutomatorException { - if (operateClient==null) { + if (operateClient == null) { throw new AutomatorException("No Operate connection was provided"); } @@ -781,7 +841,7 @@ public long countNumberOfProcessInstancesEnded(String processId, DateFilter star int cumul = 0; SearchResult searchResult = null; - queryBuilder = queryBuilder.filter(new ProcessInstanceFilter.Builder().bpmnProcessId(processId) + queryBuilder = queryBuilder.filter(ProcessInstanceFilter.builder().bpmnProcessId(processId) // .startDate(startDate) // .endDate(endDate) .state(ProcessInstanceState.COMPLETED).build()); @@ -812,27 +872,27 @@ public long countNumberOfProcessInstancesEnded(String processId, DateFilter star /* ******************************************************************** */ public long countNumberOfTasks(String processId, String taskId) throws AutomatorException { - if (operateClient==null) { + if (operateClient == null) { throw new AutomatorException("No Operate connection was provided"); } try { int cumul = 0; - SearchResult searchResult = null; + SearchResult searchResult = null; int maxLoop = 0; do { maxLoop++; SearchQuery.Builder queryBuilder = new SearchQuery.Builder(); - queryBuilder = queryBuilder.filter(new FlownodeInstanceFilter.Builder().flowNodeId(taskId).build()); + queryBuilder = queryBuilder.filter(FlowNodeInstanceFilter.builder().flowNodeId(taskId).build()); queryBuilder.sort(new Sort("key", SortOrder.ASC)); if (searchResult != null && !searchResult.getItems().isEmpty()) { queryBuilder.searchAfter(searchResult.getSortValues()); } SearchQuery searchQuery = queryBuilder.build(); searchQuery.setSize(SEARCH_MAX_SIZE); - searchResult = operateClient.searchFlownodeInstanceResults(searchQuery); + searchResult = operateClient.searchFlowNodeInstanceResults(searchQuery); cumul += (long) searchResult.getItems().size(); } while (searchResult.getItems().size() >= SEARCH_MAX_SIZE && maxLoop < 1000); return cumul; diff --git a/src/main/java/org/camunda/automator/configuration/BpmnEngineList.java b/src/main/java/org/camunda/automator/configuration/BpmnEngineList.java index fc835d5..d3981f5 100644 --- a/src/main/java/org/camunda/automator/configuration/BpmnEngineList.java +++ b/src/main/java/org/camunda/automator/configuration/BpmnEngineList.java @@ -30,6 +30,11 @@ public class BpmnEngineList { public static final String CONF_OPERATE_URL = "operateUrl"; public static final String CONF_OPERATE_USER_PASSWORD = "operateUserPassword"; public static final String CONF_OPERATE_USER_NAME = "operateUserName"; + public static final String CONF_OPERATE_AUTHENTICATIONURL = "operateAuthenticationUrl"; + public static final String CONF_OPERATE_CLIENTID = "operateClientId"; + public static final String CONF_OPERATE_CLIENTSECRET = "operateClientSecret"; + public static final String CONF_OPERATE_AUDIENCE = "operateAudientce"; + public static final String CONF_ZEEBE_GATEWAY_ADDRESS = "zeebeGatewayAddress"; public static final String CONF_URL = "url"; public static final String CONF_TYPE = "type"; @@ -70,21 +75,22 @@ public void init() { for (BpmnServerDefinition server : allServers) { String serverDetails = "Configuration Server Type[" + server.serverType + "] "; if (server.serverType == null) { - logger.error("ServerType not declared for server [" + server.name + "]"); + logger.error("ServerType not declared for server [{}]",server.name); return; } serverDetails += switch (server.serverType) { case CAMUNDA_8 -> "ZeebeadressGateway [" + server.zeebeGatewayAddress + "]"; - case CAMUNDA_8_SAAS -> "ZeebeClientId [" + server.zeebeSaasClientId + "] ClusterId[" - + server.zeebeSaasClusterId + "] RegionId[" + server.zeebeSaasRegion + "]"; + case CAMUNDA_8_SAAS -> + "ZeebeClientId [" + server.zeebeSaasClientId + "] ClusterId[" + server.zeebeSaasClusterId + "] RegionId[" + + server.zeebeSaasRegion + "]"; case CAMUNDA_7 -> "Camunda7URL [" + server.camunda7ServerUrl + "]"; case DUMMY -> "Dummy"; }; logger.info(serverDetails); } } catch (Exception e) { - logger.error("Error during initialization : " + e.getMessage()); + logger.error("Error during initialization : {}", e.getMessage()); } } @@ -181,43 +187,54 @@ private List getFromServersList() throws AutomatorExceptio bpmnServerDefinition.workerMaxJobsActive = getInteger(CONF_WORKER_MAX_JOBS_ACTIVE, serverMap, DEFAULT_VALUE_MAX_JOBS_ACTIVE, contextLog); - if (CONF_TYPE_V_CAMUNDA_7.equalsIgnoreCase(getString(CONF_TYPE, serverMap, null, contextLog,true))) { + if (CONF_TYPE_V_CAMUNDA_7.equalsIgnoreCase(getString(CONF_TYPE, serverMap, null, contextLog, true))) { bpmnServerDefinition.serverType = CamundaEngine.CAMUNDA_7; - bpmnServerDefinition.camunda7ServerUrl = getString(CONF_URL, serverMap, null, contextLog,true); + bpmnServerDefinition.camunda7ServerUrl = getString(CONF_URL, serverMap, null, contextLog, true); if (bpmnServerDefinition.camunda7ServerUrl == null) throw new AutomatorException( "Incorrect Definition - [url] expected for [" + CONF_TYPE_V_CAMUNDA_7 + "] type " + contextLog); } - if (CONF_TYPE_V_CAMUNDA_8.equalsIgnoreCase(getString(CONF_TYPE, serverMap, null, contextLog,true))) { + if (CONF_TYPE_V_CAMUNDA_8.equalsIgnoreCase(getString(CONF_TYPE, serverMap, null, contextLog, true))) { bpmnServerDefinition.serverType = CamundaEngine.CAMUNDA_8; - bpmnServerDefinition.zeebeGatewayAddress = getString(CONF_ZEEBE_GATEWAY_ADDRESS, serverMap, null, contextLog,true); - bpmnServerDefinition.operateUserName = getString(CONF_OPERATE_USER_NAME, serverMap, "Demo", contextLog,false); - bpmnServerDefinition.operateUserPassword = getString(CONF_OPERATE_USER_PASSWORD, serverMap, "Demo", - contextLog,false); - bpmnServerDefinition.operateUrl = getString(CONF_OPERATE_URL, serverMap, null, contextLog,false); - bpmnServerDefinition.taskListUrl = getString(CONF_TASK_LIST_URL, serverMap, null, contextLog,false); + bpmnServerDefinition.zeebeGatewayAddress = getString(CONF_ZEEBE_GATEWAY_ADDRESS, serverMap, null, contextLog, + true); + bpmnServerDefinition.operateUserName = getString(CONF_OPERATE_USER_NAME, serverMap, "Demo", contextLog, false); + bpmnServerDefinition.operateUserPassword = getString(CONF_OPERATE_USER_PASSWORD, serverMap, "Demo", contextLog, + false); + bpmnServerDefinition.operateUrl = getString(CONF_OPERATE_URL, serverMap, null, contextLog, false); + bpmnServerDefinition.operateAuthenticationUrl = getString(CONF_OPERATE_AUTHENTICATIONURL, serverMap, null, + contextLog, false); + bpmnServerDefinition.operateClientId = getString(CONF_OPERATE_CLIENTID, serverMap, null, contextLog, false); + bpmnServerDefinition.operateClientSecret = getString(CONF_OPERATE_CLIENTSECRET, serverMap, null, contextLog, + false); + bpmnServerDefinition.operateAudience = getString(CONF_OPERATE_AUDIENCE, serverMap, null, contextLog, false); + + bpmnServerDefinition.taskListUrl = getString(CONF_TASK_LIST_URL, serverMap, null, contextLog, false); bpmnServerDefinition.workerExecutionThreads = getInteger(CONF_WORKER_EXECUTION_THREADS, serverMap, DEFAULT_VALUE_EXECUTION_THREADS, contextLog); if (bpmnServerDefinition.zeebeGatewayAddress == null) throw new AutomatorException( "Incorrect Definition - [zeebeGatewayAddress] expected for [" + CONF_TYPE_V_CAMUNDA_8 + "] type"); } - if (CONF_TYPE_V_CAMUNDA_8_SAAS.equalsIgnoreCase(getString(CONF_TYPE, serverMap, null, contextLog,true))) { + if (CONF_TYPE_V_CAMUNDA_8_SAAS.equalsIgnoreCase(getString(CONF_TYPE, serverMap, null, contextLog, true))) { bpmnServerDefinition.serverType = CamundaEngine.CAMUNDA_8_SAAS; - bpmnServerDefinition.zeebeSaasRegion = getString(CONF_ZEEBE_SAAS_REGION, serverMap, null, contextLog,true); - bpmnServerDefinition.zeebeSaasClientSecret = getString(CONF_ZEEBE_SAAS_SECRET, serverMap, null, contextLog,true); - bpmnServerDefinition.zeebeSaasClusterId = getString(CONF_ZEEBE_SAAS_CLUSTER_ID, serverMap, null, contextLog,true); - bpmnServerDefinition.zeebeSaasClientId = getString(CONF_ZEEBE_SAAS_CLIENT_ID, serverMap, null, contextLog,true); - bpmnServerDefinition.zeebeSaasOAuthUrl = getString(CONF_ZEEBE_SAAS_OAUTHURL, serverMap, null, contextLog,true); - bpmnServerDefinition.zeebeSaasAudience = getString(CONF_ZEEBE_SAAS_AUDIENCE, serverMap, null, contextLog,true); + bpmnServerDefinition.zeebeSaasRegion = getString(CONF_ZEEBE_SAAS_REGION, serverMap, null, contextLog, true); + bpmnServerDefinition.zeebeSaasClientSecret = getString(CONF_ZEEBE_SAAS_SECRET, serverMap, null, contextLog, + true); + bpmnServerDefinition.zeebeSaasClusterId = getString(CONF_ZEEBE_SAAS_CLUSTER_ID, serverMap, null, contextLog, + true); + bpmnServerDefinition.zeebeSaasClientId = getString(CONF_ZEEBE_SAAS_CLIENT_ID, serverMap, null, contextLog, + true); + bpmnServerDefinition.zeebeSaasOAuthUrl = getString(CONF_ZEEBE_SAAS_OAUTHURL, serverMap, null, contextLog, true); + bpmnServerDefinition.zeebeSaasAudience = getString(CONF_ZEEBE_SAAS_AUDIENCE, serverMap, null, contextLog, true); bpmnServerDefinition.workerExecutionThreads = getInteger(CONF_WORKER_EXECUTION_THREADS, serverMap, DEFAULT_VALUE_EXECUTION_THREADS, contextLog); - bpmnServerDefinition.operateUserName = getString(CONF_OPERATE_USER_NAME, serverMap, null, contextLog,false); + bpmnServerDefinition.operateUserName = getString(CONF_OPERATE_USER_NAME, serverMap, null, contextLog, false); bpmnServerDefinition.operateUserPassword = getString(CONF_OPERATE_USER_PASSWORD, serverMap, null, contextLog, false); - bpmnServerDefinition.operateUrl = getString(CONF_OPERATE_URL, serverMap, null, contextLog,false); - bpmnServerDefinition.taskListUrl = getString(CONF_TASK_LIST_URL, serverMap, null, contextLog,false); + bpmnServerDefinition.operateUrl = getString(CONF_OPERATE_URL, serverMap, null, contextLog, false); + bpmnServerDefinition.taskListUrl = getString(CONF_TASK_LIST_URL, serverMap, null, contextLog, false); if (bpmnServerDefinition.zeebeSaasRegion == null || bpmnServerDefinition.zeebeSaasClientSecret == null || bpmnServerDefinition.zeebeSaasClusterId == null || bpmnServerDefinition.zeebeSaasClientId == null) throw new AutomatorException( @@ -359,35 +376,38 @@ private List getFromServerConfiguration() { /* */ /* ******************************************************************** */ - private String getString(String name, Map record, String defaultValue, String contextLog, + private String getString(String name, + Map recordData, + String defaultValue, + String contextLog, boolean isMandatory) { try { - if (!record.containsKey(name)) { + if (!recordData.containsKey(name)) { if (isMandatory) { if (defaultValue == null) - logger.error(contextLog + "Variable [{}] not defined in {}", name, contextLog); + logger.error("{}Variable [{}] not defined in {}", contextLog, name, contextLog); else - logger.info(contextLog + "Variable [{}] not defined in {}", name, contextLog); + logger.info("{} Variable [{}] not defined in {}", contextLog, name, contextLog); } return defaultValue; } - return (String) record.get(name); + return (String) recordData.get(name); } catch (Exception e) { - logger.error(contextLog + "Variable [{}] {} bad definition {}", name, contextLog, e.getMessage()); + logger.error("{} Variable [{}] {} bad definition {}", contextLog, name, contextLog, e.getMessage()); return defaultValue; } } - private Integer getInteger(String name, Map record, Integer defaultValue, String contextLog) { + private Integer getInteger(String name, Map recordData, Integer defaultValue, String contextLog) { try { - if (!record.containsKey(name)) { + if (!recordData.containsKey(name)) { if (defaultValue == null) logger.error("Variable [{}] not defined in {}", name, contextLog); else logger.info("Variable [{}] not defined in {}", name, contextLog); return defaultValue; } - return (Integer) record.get(name); + return (Integer) recordData.get(name); } catch (Exception e) { logger.error("Variable [{}] {} bad definition {}", name, contextLog, e.getMessage()); return defaultValue; @@ -457,6 +477,12 @@ public static class BpmnServerDefinition { public String operateUserName; public String operateUserPassword; public String operateUrl; + + // something like "http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token" + public String operateAuthenticationUrl; + public String operateClientId; + public String operateClientSecret; + public String operateAudience; public String taskListUrl; /** @@ -472,17 +498,18 @@ public static class BpmnServerDefinition { public Integer workerExecutionThreads = Integer.valueOf(DEFAULT_VALUE_EXECUTION_THREADS); public Integer workerMaxJobsActive = Integer.valueOf(DEFAULT_VALUE_MAX_JOBS_ACTIVE); - public String getSynthesis() { - String synthesis= serverType.name(); + String synthesis = serverType.name(); if (serverType.equals(CamundaEngine.CAMUNDA_7)) { - synthesis+=" url["+camunda7ServerUrl+"] userName["+camunda7UserName+"]"; + synthesis += " url[" + camunda7ServerUrl + "] userName[" + camunda7UserName + "]"; } - if (serverType.equals(CamundaEngine.CAMUNDA_8) ) { - synthesis+=" address["+zeebeGatewayAddress+"] workerThread["+workerExecutionThreads+"] MaxJobActive["+workerMaxJobsActive+"]"; + if (serverType.equals(CamundaEngine.CAMUNDA_8)) { + synthesis += " address[" + zeebeGatewayAddress + "] workerThread[" + workerExecutionThreads + "] MaxJobActive[" + + workerMaxJobsActive + "]"; } - if (serverType.equals(CamundaEngine.CAMUNDA_8_SAAS) ) { - synthesis+=" clientId["+zeebeSaasClientId+"] workerThread["+workerExecutionThreads+"] MaxJobActive["+workerMaxJobsActive+"]"; + if (serverType.equals(CamundaEngine.CAMUNDA_8_SAAS)) { + synthesis += " clientId[" + zeebeSaasClientId + "] workerThread[" + workerExecutionThreads + "] MaxJobActive[" + + workerMaxJobsActive + "]"; } return synthesis; } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index ce82dd4..dbb6428 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -56,6 +56,9 @@ automator: zeebeGatewayAddress: "127.0.0.1:26500" workerExecutionThreads: 10 workerMaxJobsActive: 10 + operateUserName: "demo" + operateUserPassword: "demo" + operateUrl: "http://localhost:8081" - type: "camunda8saas" name: "Camunda8Grena"