Skip to content

Commit

Permalink
Added possibility to replace service task types on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
berndruecker committed May 16, 2024
1 parent a326ae1 commit 3b1a383
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ benchmark.bpmnProcessId=benchmark-dmn
benchmark.payloadPath=url:https://gist.githubusercontent.com/berndruecker/ec94642075548d2c84404336d77ea6f1/raw/11cd080fd387c2de64e0e718bedf25f4412f0981/data.json
```

You can adjust the model on the fly, for example because you want to replace specific service task types with the `benchmark` task type mocked by the benchmark project (instead of calling the sendgrid connecter in the example below). Also you can replace the process id with `benchmark` automatically:

```poperties
benchmark.jobTypesToReplace=io.camunda:sendgrid:1
benchmark.bpmnProcessIdToReplace=Process_145kw8o
```

## Typical process

If you do not specify a process model, the [typical process](blob/main/src/main/resources/bpmn/typical_process.bpmn) is used as a process model showing a typical model size we see at customers (around 10 to 30 tasks). It is intentional, that there are not much other elements (like gateways or events), as this did not influence benchmark too much in our experiments, so we preferred to keep it simple.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.command.DeployResourceCommandStep1;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

@Component
public class ProcessDeployer {

Expand All @@ -27,14 +31,41 @@ public void autoDeploy() {
try {
LOG.info("Deploy " + StringUtils.arrayToCommaDelimitedString(config.getBpmnResource()) + " to Zeebe...");
DeployResourceCommandStep1.DeployResourceCommandStep2 deployResourceCommand = zeebeClient.newDeployResourceCommand()
.addResourceStream(config.getBpmnResource()[0].getInputStream(), config.getBpmnResource()[0].getFilename()); // Have to add at least the first resource to have the right class of Step2
.addResourceStream(adjustInputStreamBasedOnConfig(config.getBpmnResource()[0].getInputStream()), config.getBpmnResource()[0].getFilename()); // Have to add at least the first resource to have the right class of Step2
for (int i = 1; i < config.getBpmnResource().length; i++) { // now adding the rest of resources starting from 1
deployResourceCommand = deployResourceCommand.addResourceStream(config.getBpmnResource()[i].getInputStream(), config.getBpmnResource()[i].getFilename());
deployResourceCommand = deployResourceCommand.addResourceStream(adjustInputStreamBasedOnConfig(config.getBpmnResource()[i].getInputStream()), config.getBpmnResource()[i].getFilename());
}
deployResourceCommand.send().join();
} catch (Exception ex) {
throw new RuntimeException("Could not deploy to Zeebe: " + ex.getMessage(), ex);
}
}
}

private InputStream adjustInputStreamBasedOnConfig(InputStream is) throws IOException {
if (config.getJobTypesToReplace()==null && config.getBpmnProcessIdToReplace()==null) {
return is;
}

// Replace job types or BPMN id on-the-fly

byte[] stringBytes = is.readAllBytes();
String fileContent = new String(stringBytes);

if (config.getJobTypesToReplace()!=null) {
// Split by "," if there are multiple task types to be replaced
String[] tasksToReplace = {config.getJobTypesToReplace()};
if (config.getJobTypesToReplace().contains(",")) {
tasksToReplace = config.getJobTypesToReplace().split(",");
}
for (String taskToReplace: tasksToReplace) {
fileContent = fileContent.replaceAll(taskToReplace, config.getJobType());
}
}
if (config.getBpmnProcessIdToReplace()!=null) {
fileContent = fileContent.replaceAll(config.getBpmnProcessIdToReplace(), config.getBpmnProcessId());
}

return new ByteArrayInputStream(fileContent.getBytes());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class BenchmarkConfiguration {
private Resource[] bpmnResource;
private boolean autoDeployProcess = true;

private String jobTypesToReplace;
private String bpmnProcessIdToReplace;

private long warmupPhaseDurationMillis = 0;
private String startRateAdjustmentStrategy="backpressure";

Expand Down Expand Up @@ -216,4 +219,20 @@ public long getMessagesLoadDuration() {
public void setMessagesLoadDuration(long messagesLoadDuration) {
this.messagesLoadDuration = messagesLoadDuration;
}

public String getJobTypesToReplace() {
return jobTypesToReplace;
}

public void setJobTypesToReplace(String jobTypesToReplace) {
this.jobTypesToReplace = jobTypesToReplace;
}

public String getBpmnProcessIdToReplace() {
return bpmnProcessIdToReplace;
}

public void setBpmnProcessIdToReplace(String bpmnProcessIdToReplace) {
this.bpmnProcessIdToReplace = bpmnProcessIdToReplace;
}
}

0 comments on commit 3b1a383

Please sign in to comment.