Skip to content

Commit

Permalink
Normalize exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-yves-monnet committed Dec 10, 2024
1 parent fbffc24 commit b5b65c0
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 67 deletions.
2 changes: 1 addition & 1 deletion doc/loadtestscenario/test_1/test-1-c8CrawlUrlMultiple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
-Dautomator.servers.camunda8.taskListUrl=
-Dautomator.servers.camunda8.workerExecutionThreads=1
-Dautomator.startup.scenarioResourceAtStartup=file:/C8CrawlUrlScn.json
-Dautomator.startup.policyExecution=WARMINGUP|CREATION
-Dautomator.startup.policyExecution=WARMINGUP|CREATION|OBJECTIVE
-Dautomator.startup.logLevel=DASHBOARD
resources:
limits:
Expand Down
4 changes: 3 additions & 1 deletion doc/unittestscenario/resources/ScoreAcceptance.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
<bpmn:sequenceFlow id="Flow_1pxztl2" sourceRef="ActSendRejection" targetRef="EndRejected" />
<bpmn:sequenceFlow id="Flow_0wya675" sourceRef="CallApplicant" targetRef="ActSendRejection" />
<bpmn:userTask id="CallApplicant" name="Call Applicant">
<bpmn:extensionElements />
<bpmn:extensionElements>
<zeebe:userTask />
</bpmn:extensionElements>
<bpmn:incoming>Flow_0a4sjzy</bpmn:incoming>
<bpmn:outgoing>Flow_0wya675</bpmn:outgoing>
</bpmn:userTask>
Expand Down
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
<groupId>org.camunda.community.automator</groupId>
<artifactId>process-execution-automator</artifactId>

<version>1.8.0</version>
Norm <version>1.8.1</version>
<!-- Change the banner.txt version -->
<!-- 1.5 Change OperateClient / TaskList Library -->
<!-- 1.6 Increase option multithreading-->
<!-- 1.7 add logs -->
<!-- 1.7.1 Add logs on authentication to describe it -->

<!-- 1.8.0 Unit Test / Rest API -->
<!-- 1.8.1 Add the reconnect mechanism on TaskList -->
<properties>
<java.version>17</java.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/camunda/automator/AutomatorAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public BpmnEngine getBpmnEngineFromScenario(Scenario scenario, BpmnEngineList bp
return null;
} catch (AutomatorException e) {
logger.error("Can't connect the engine for the scenario [{}] serverName[{}]: {}", scenario.getName(),
scenario.getServerName(), e.getMessage());
scenario.getServerName(), e.getMessage(),e);
throw e;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/camunda/automator/AutomatorCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static List<Path> detectRecursiveScenario(Path folderRecursive) {
}
});
} catch (IOException e) {
logger.error("During detection scenario file: {}", e.getMessage());
logger.error("During detection scenario file: {}", e.getMessage(),e);
}
return listFiles;
}
Expand Down Expand Up @@ -254,7 +254,7 @@ public void run(String[] args) {
logger.info("That's all folks! " + (System.currentTimeMillis() - beginTime) + " ms.");

} catch (Exception e) {
logger.error("Error during execution " + e);
logger.error("Error during execution {} ", e.getMessage(),e);
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/camunda/automator/AutomatorRest.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void startTest(String scenarioName, String serverName, String unitTestId
scenario = automatorAPI.loadFromFile(scenarioFile);
} catch (Exception e) {
logger.error("Error during accessing InputStream from File [{}]: {}", scenarioFile.toAbsolutePath(),
e.getMessage());
e.getMessage(),e);
}
if (scenario == null) {
resultMap.put(JSON_STATUS, "NOTEXIST");
Expand Down Expand Up @@ -154,7 +154,7 @@ private void startTest(String scenarioName, String serverName, String unitTestId
resultMap.putAll(resultToJson(scenarioExecutionResult));

} catch (Exception e) {
logger.error("During execute unit Test", e.getMessage());
logger.error("During execute unit Test : {}", e.getMessage(),e);
resultMap.put("error", e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void connection() throws AutomatorException {
engineApi.getProcessEngineNames();
logger.info("Connection successfully to Camunda7 [{}] ", apiClient.getBasePath());
} catch (ApiException e) {
logger.error("Can't connect Camunda7 server[{}] User[{}]: {}", apiClient.getBasePath(), userName, e.toString());
logger.error("Can't connect Camunda7 server[{}] User[{}]: {}", apiClient.getBasePath(), userName, e.getMessage(),e.getMessage(),e);
throw new AutomatorException("Can't connect to Camunda7 [" + apiClient.getBasePath() + "] : " + e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void executeServiceTask(String serviceTaskId, String workerId, Map<String
try {
zeebeClient.newCompleteCommand(Long.valueOf(serviceTaskId)).variables(variables).send().join();
} catch (Exception e) {
logger.error("executeServiceTask:Can't execute service task[{}] WorkerId[{}] : {}", serviceTaskId, workerId, e.getMessage());
logger.error("executeServiceTask:Can't execute service task[{}] WorkerId[{}] : {}", serviceTaskId, workerId, e.getMessage(),e);
throw new AutomatorException("Can't execute service task " + e.getMessage());
}
}
Expand Down Expand Up @@ -374,7 +374,7 @@ public void throwBpmnServiceTask(String serviceTaskId,
.send()
.join();
} catch (Exception e) {
logger.error("throwBpmnServiceTask: Can't execute service task[{}] WorkerId[{}] errorCode[{}] errorMessage[{}]: {}", serviceTaskId, workerId, errorCode, errorMessage, e.getMessage());
logger.error("throwBpmnServiceTask: Can't execute service task[{}] WorkerId[{}] errorCode[{}] errorMessage[{}]: {}", serviceTaskId, workerId, errorCode, errorMessage, e.getMessage(),e);
throw new AutomatorException("Can't execute service task " + e.getMessage());
}
}
Expand Down Expand Up @@ -445,7 +445,7 @@ public String deployBpmn(File processFile, ScenarioDeployment.Policy policy) thr

return String.valueOf(event.getKey());
} catch (Exception e) {
logger.error("deployBpmn: Can't deploy File[{}] Policy[{}] : {}", processFile.getAbsolutePath(), policy, e.getMessage());
logger.error("deployBpmn: Can't deploy File[{}] Policy[{}] : {}", processFile.getAbsolutePath(), policy, e.getMessage(),e);
throw new AutomatorException("Can't deploy " + e.getMessage());
}
}
Expand Down Expand Up @@ -575,7 +575,7 @@ else if (BpmnEngineList.CamundaEngine.CAMUNDA_8.equals(serverDefinition.serverTy

} catch (Exception e) {
zeebeClient = null;
logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e);
logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage(),e);
throw new AutomatorException(
"BadCredential[" + serverDefinition.name + "] Analysis:" + analysis + " : " + e.getMessage());
}
Expand All @@ -594,7 +594,7 @@ else if (BpmnEngineList.CamundaEngine.CAMUNDA_8.equals(serverDefinition.serverTy
clientBuilder = clientBuilder.usePlaintext();
} catch (Exception e) {
zeebeClient = null;
logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e);
logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage(),e);
throw new AutomatorException(
"badURL[" + serverDefinition.name + "] Analysis:" + analysis + " : " + e.getMessage());
}
Expand Down Expand Up @@ -641,7 +641,7 @@ else if (BpmnEngineList.CamundaEngine.CAMUNDA_8.equals(serverDefinition.serverTy

} catch (Exception e) {
zeebeClient = null;
logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e);
logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage(),e);
throw new AutomatorException(
"Can't connect to Server[" + serverDefinition.name + "] Analysis:" + analysis + " Fail : " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected void connectOperate(StringBuilder analysis) throws AutomatorException


} catch (Exception e) {
logger.error("Can't connect to SaaS environemnt[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage());
logger.error("Can't connect to SaaS environemnt[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage(),e);
throw new AutomatorException(
"Can't connect to SaaS environment[" + serverDefinition.name + "] Analysis:" + analysis + " fail : "
+ e.getMessage());
Expand Down Expand Up @@ -125,7 +125,7 @@ protected void connectOperate(StringBuilder analysis) throws AutomatorException
configuration = new CamundaOperateClientConfiguration(authentication, operateUrl, objectMapper, HttpClients.createDefault());
}
} catch (Exception e) {
logger.error("Can't connect to SaaS environment[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage());
logger.error("Can't connect to SaaS environment[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage(),e);
throw new AutomatorException(
"Can't connect to SaaS environment[" + serverDefinition.name + "] Analysis:" + analysis + " fail : "
+ e.getMessage());
Expand All @@ -145,7 +145,7 @@ protected void connectOperate(StringBuilder analysis) throws AutomatorException
analysis.append("successfully, ");

} catch (Exception e) {
logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage());
logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage(),e);
throw new AutomatorException(
"Can't connect to Server[" + serverDefinition.name + "] Analysis:" + analysis + " Fail : " + e.getMessage());
}
Expand Down Expand Up @@ -228,12 +228,12 @@ public List<BpmnEngine.TaskDescription> searchTasksByProcessInstanceId(String pr
}).toList();

} catch (OperateException e) {
logger.error("Can't search FlowNode: " + e.getMessage());
logger.error("Can't search FlowNode: {}", e.getMessage(),e);
throw new AutomatorException("Can't search FlowNode: " + e.getMessage());
}
// We must not be here
catch (Exception e) {
logger.error("Can't search FlowNode EXCEPTION NOT EXPECTED: " + e.getMessage());
logger.error("Can't search FlowNode EXCEPTION NOT EXPECTED: {} ", e.getMessage(),e);
throw new AutomatorException("Can't search FlowNode: " + e.getMessage());
}
}
Expand Down Expand Up @@ -275,12 +275,12 @@ public List<BpmnEngine.ProcessDescription> searchProcessInstanceByVariable(Strin
}
return listProcessInstanceFind;
} catch (OperateException e) {
logger.error("Can't search flowNodeByVariable: " + e.getMessage());
logger.error("Can't search flowNodeByVariable: {} ", e.getMessage(),e);
throw new AutomatorException("Can't search flowNodeByVariable " + e.getMessage());
}
// We must not be here
catch (Exception e) {
logger.error("Can't search flowNodeByVariable EXCEPTION NOT EXPECTED: " + e.getMessage());
logger.error("Can't search flowNodeByVariable EXCEPTION NOT EXPECTED: {} ",e.getMessage(),e);
throw new AutomatorException("Can't search FlowNode: " + e.getMessage());
}
}
Expand All @@ -305,12 +305,12 @@ public Map<String, Object> getVariables(String processInstanceId) throws Automat

return variables;
} catch (OperateException e) {
logger.error("Can't getVariables: " + e.getMessage());
logger.error("Can't getVariables: {} ", e.getMessage(),e);
throw new AutomatorException("Can't search variables task " + e.getMessage());
}
// We must not be here
catch (Exception e) {
logger.error("Can't getVariables EXCEPTION NOT EXPECTED: " + e.getMessage());
logger.error("Can't getVariables EXCEPTION NOT EXPECTED: {} ", e.getMessage(),e);
throw new AutomatorException("Can't getVariables: " + e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class TaskListClient {
BpmnEngineCamunda8 engineCamunda8;
private CamundaTaskListClient taskClient;

private long lastCallToTaskList;

protected TaskListClient(BpmnEngineCamunda8 engineCamunda8) {
this.engineCamunda8 = engineCamunda8;
}
Expand Down Expand Up @@ -61,7 +63,7 @@ public void connectTaskList(StringBuilder analysis) throws AutomatorException {
taskListBuilder.taskListUrl(taskListUrl)
.saaSAuthentication(serverDefinition.taskListClientId, serverDefinition.taskListClientSecret);
} catch (Exception e) {
logger.error("Can't connect to SaaS environemnt[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage());
logger.error("Can't connect to SaaS environemnt[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage(),e);
throw new AutomatorException(
"Can't connect to SaaS environment[" + serverDefinition.name + "] Analysis:" + analysis + " fail : "
+ e.getMessage());
Expand Down Expand Up @@ -105,16 +107,27 @@ public void connectTaskList(StringBuilder analysis) throws AutomatorException {
taskClient = taskListBuilder.build();

analysis.append("successfully, ");
lastCallToTaskList= System.currentTimeMillis();

} catch (Exception e) {
logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage());
logger.error("Can't connect to Server[{}] Analysis:{} : {}", serverDefinition.name, analysis, e.getMessage(),e);
throw new AutomatorException(
"Can't connect to Server[" + serverDefinition.name + "] Analysis:" + analysis + " Fail : " + e.getMessage());
}
}

/**
* There is a timeout on the taskList, so reconnection may be necessary
* @param analysis analyse the result
*/
public void reconnect(StringBuilder analysis) throws AutomatorException {
connectTaskList(analysis);
}


public List<String> searchUserTasksByProcessInstance(String processInstanceId, String userTaskId, int maxResult)
throws AutomatorException {
checkConnection();
try {
// impossible to filter by the task name/ task type, so be ready to get a lot of flowNode and search the correct one
Long processInstanceIdLong = Long.valueOf(processInstanceId);
Expand Down Expand Up @@ -153,12 +166,13 @@ public List<String> searchUserTasksByProcessInstance(String processInstanceId, S
return listTasksResult;

} catch (TaskListException e) {
logger.error("TaskListClient: error during search task: {}", e.getMessage());
logger.error("TaskListClient: error during search task: processInstance[{}] : {} ", processInstanceId, e.getMessage(), e);
throw new AutomatorException("Can't search users task " + e.getMessage());
}
}

public List<String> searchUserTasks(String userTaskId, int maxResult) throws AutomatorException {
checkConnection();
try {
// impossible to filter by the task name/ task type, so be ready to get a lot of flowNode and search the correct one

Expand All @@ -181,22 +195,35 @@ public List<String> searchUserTasks(String userTaskId, int maxResult) throws Aut
return listTasksResult;

} catch (TaskListException e) {
logger.error("SearchUserTask: userId[{}] : {}", userTaskId, e.getMessage());
logger.error("SearchUserTask: userId[{}] : {}", userTaskId, e.getMessage(),e);
throw new AutomatorException("Can't search users task " + e.getMessage());
}
}

public void executeUserTask(String userTaskId, String userId, Map<String, Object> variables)
throws AutomatorException {
checkConnection();
try {
taskClient.claim(userTaskId, engineCamunda8.getServerDefinition().operateUserName);
taskClient.completeTask(userTaskId, variables);
} catch (TaskListException e) {
logger.error("ExecuteUserTask: taskId[{}] userId[{}] : {}", userTaskId, userId, e.getMessage());
logger.error("ExecuteUserTask: taskId[{}] userId[{}] : {}", userTaskId, userId, e.getMessage(),e);
throw new AutomatorException("Can't execute task [" + userTaskId + "]");
} catch (Exception e) {
logger.error("ExecuteUserTask: Exception on taskId[{}] userId[{}] : {}", userTaskId, userId, e.getMessage());
logger.error("ExecuteUserTask: Exception on taskId[{}] userId[{}] : {}", userTaskId, userId, e.getMessage(), e);
throw new AutomatorException("Can't execute task [" + userTaskId + "]");
}
}

/**
* There is a timeout with taskList.
* If the last call was more than 4 minutes, then reconnect
*/

private void checkConnection() throws AutomatorException {
StringBuilder analysis = new StringBuilder();
if (lastCallToTaskList<System.currentTimeMillis()-4*60*1000)
reconnect(analysis);
lastCallToTaskList = System.currentTimeMillis();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void init() {
logger.info(serverDetails);
}
} catch (Exception e) {
logger.error("Error during initialization : {}", e.getMessage());
logger.error("Error during initialization : {}", e.getMessage(),e);
}
}

Expand Down Expand Up @@ -432,7 +432,7 @@ private String getString(String name,
}
return (String) recordData.get(name);
} catch (Exception e) {
logger.error("{} Variable [{}] {} bad definition {}", contextLog, name, contextLog, e.getMessage());
logger.error("{} Variable [{}] {} bad definition {}", contextLog, name, contextLog, e.getMessage(),e);
return defaultValue;
}
}
Expand All @@ -456,7 +456,7 @@ private Boolean getBoolean(String name,
return valueBoolean;
return Boolean.valueOf(recordData.get(name).toString());
} catch (Exception e) {
logger.error("{} Variable [{}] {} bad definition {}", contextLog, name, contextLog, e.getMessage());
logger.error("{} Variable [{}] {} bad definition {}", contextLog, name, contextLog, e.getMessage(),e);
return defaultValue;
}
}
Expand All @@ -472,7 +472,7 @@ private Integer getInteger(String name, Map<String, Object> recordData, Integer
}
return (Integer) recordData.get(name);
} catch (Exception e) {
logger.error("Variable [{}] {} bad definition {}", name, contextLog, e.getMessage());
logger.error("Variable [{}] {} bad definition {}", name, contextLog, e.getMessage(),e);
return defaultValue;
}
}
Expand All @@ -483,7 +483,7 @@ private int parseInt(String label, String value, int defaultValue, String contex
return defaultValue;
return Integer.parseInt(value);
} catch (Exception e) {
logger.error("Can't parse value [{}] at [{}] {}", value, label, contextLog);
logger.error("Can't parse value [{}] at [{}] {}", value, label, contextLog,e);
return defaultValue;
}
}
Expand Down
Loading

0 comments on commit b5b65c0

Please sign in to comment.