Skip to content

Commit

Permalink
Merge pull request #27 from camunda-community-hub/feature/25_camunda_…
Browse files Browse the repository at this point in the history
…8-3-x

Support for Camunda 8.3
  • Loading branch information
stephanpelikan authored Dec 22, 2023
2 parents a1c66d7 + 3a58fa0 commit f0c4da2
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 100 deletions.
4 changes: 2 additions & 2 deletions spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.zeebe.version>8.1.15</spring.zeebe.version>
<spring.zeebe.version>8.3.4.2</spring.zeebe.version>
</properties>

<build>
Expand All @@ -35,7 +35,7 @@
<dependency>
<groupId>io.vanillabp</groupId>
<artifactId>spring-boot-support</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>io.camunda</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package io.vanillabp.camunda8;

import io.camunda.zeebe.spring.client.EnableZeebeClient;
import io.camunda.zeebe.spring.client.config.ZeebeClientStarterAutoConfiguration;
import io.camunda.zeebe.spring.client.CamundaAutoConfiguration;
import io.camunda.zeebe.spring.client.jobhandling.DefaultCommandExceptionHandlingStrategy;
import io.camunda.zeebe.spring.client.lifecycle.ZeebeClientLifecycle;
import io.vanillabp.camunda8.deployment.Camunda8DeploymentAdapter;
import io.vanillabp.camunda8.deployment.DeploymentRepository;
import io.vanillabp.camunda8.deployment.DeploymentResourceRepository;
Expand All @@ -17,6 +15,7 @@
import io.vanillabp.springboot.adapter.SpringDataUtil;
import io.vanillabp.springboot.adapter.VanillaBpProperties;
import io.vanillabp.springboot.parameters.MethodParameter;
import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.framework.AopProxyUtils;
Expand All @@ -34,29 +33,26 @@
import java.lang.reflect.Method;
import java.util.List;

import jakarta.annotation.PostConstruct;

@AutoConfigurationPackage(basePackageClasses = Camunda8AdapterConfiguration.class)
@AutoConfigureBefore(ZeebeClientStarterAutoConfiguration.class)
@EnableZeebeClient
@AutoConfigureBefore(CamundaAutoConfiguration.class)
public class Camunda8AdapterConfiguration extends AdapterConfigurationBase<Camunda8ProcessService<?>> {

private static final Logger logger = LoggerFactory.getLogger(Camunda8AdapterConfiguration.class);

public static final String ADAPTER_ID = "camunda8";

@Value("${workerId}")
private String workerId;

@Value("${spring.application.name:@null}")
private String applicationName;

@Autowired
private SpringDataUtil springDataUtil; // ensure persistence is up and running

@Autowired
private ApplicationContext applicationContext;

@Autowired
private ZeebeClientLifecycle clientLifecycle;

@Autowired
private DefaultCommandExceptionHandlingStrategy commandExceptionHandlingStrategy;

Expand Down Expand Up @@ -88,9 +84,9 @@ public Camunda8DeploymentAdapter camunda8Adapter(
final Camunda8TaskWiring camunda8TaskWiring) {

return new Camunda8DeploymentAdapter(
applicationName,
properties,
deploymentService,
clientLifecycle,
camunda8TaskWiring);

}
Expand All @@ -104,6 +100,7 @@ public Camunda8TaskWiring camunda8TaskWiring(
return new Camunda8TaskWiring(
springDataUtil,
applicationContext,
applicationName,
workerId,
userTaskHandler,
taskHandlers,
Expand Down Expand Up @@ -158,6 +155,7 @@ public <DE> Camunda8ProcessService<?> newProcessServiceImplementation(
final CrudRepository<DE, Object> workflowAggregateRepository) {

final var result = new Camunda8ProcessService<DE>(
applicationName,
workflowAggregateRepository,
workflowAggregate -> springDataUtil.getId(workflowAggregate),
workflowAggregateClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
import io.camunda.zeebe.model.bpmn.instance.SignalEventDefinition;
import io.camunda.zeebe.model.bpmn.instance.StartEvent;
import io.camunda.zeebe.model.bpmn.instance.UserTask;
import io.camunda.zeebe.spring.client.event.ClientStartedEvent;
import io.camunda.zeebe.spring.client.lifecycle.ZeebeClientLifecycle;
import io.camunda.zeebe.spring.client.event.ZeebeClientCreatedEvent;
import io.vanillabp.camunda8.Camunda8AdapterConfiguration;
import io.vanillabp.camunda8.service.Camunda8ProcessService;
import io.vanillabp.camunda8.utils.HashCodeInputStream;
Expand Down Expand Up @@ -47,21 +46,21 @@ public class Camunda8DeploymentAdapter extends ModuleAwareBpmnDeployment {
private final Camunda8TaskWiring taskWiring;

private final DeploymentService deploymentService;

private final String applicationName;

private final ZeebeClientLifecycle clientLifecycle;

private ZeebeClient client;

public Camunda8DeploymentAdapter(
final String applicationName,
final VanillaBpProperties properties,
final DeploymentService deploymentService,
final ZeebeClientLifecycle clientLifecycle,
final Camunda8TaskWiring taskWiring) {

super(properties);
this.taskWiring = taskWiring;
this.deploymentService = deploymentService;
this.clientLifecycle = clientLifecycle;
this.applicationName = applicationName;

}

Expand All @@ -78,11 +77,12 @@ protected String getAdapterId() {
return Camunda8AdapterConfiguration.ADAPTER_ID;

}

@EventListener
public void zeebeClientStarted(final ClientStartedEvent event) {
public void zeebeClientCreated(
final ZeebeClientCreatedEvent event) {

this.client = clientLifecycle.get();
this.client = event.getClient();

deployAllWorkflowModules();

Expand All @@ -93,7 +93,6 @@ public void zeebeClientStarted(final ClientStartedEvent event) {
@Override
protected void doDeployment(
final String workflowModuleId,
final String workflowModuleName,
final Resource[] bpmns,
final Resource[] dmns,
final Resource[] cmms) throws Exception {
Expand Down Expand Up @@ -124,7 +123,7 @@ protected void doDeployment(

final var deployedProcesses = new HashMap<String, DeployedBpmn>();

final boolean hasDeployables[] = { false };
final boolean[] hasDeployables = { false };

// Add all BPMNs to deploy-command: on one hand to deploy them and on the
// other hand to wire them to the using project beans according to the SPI
Expand All @@ -136,7 +135,8 @@ protected void doDeployment(
deploymentHashCode[0])) {

logger.info("About to deploy '{}' of workflow-module '{}'",
resource.getFilename(), workflowModuleName);
resource.getFilename(),
workflowModuleId == null ? "default" : workflowModuleId);
final var model = bpmnParser.parseModelFromStream(inputStream);

final var bpmn = deploymentService.addBpmn(
Expand All @@ -159,34 +159,36 @@ protected void doDeployment(
.reduce((first, second) -> second);

if (hasDeployables[0]) {


final var tenantId = workflowModuleId == null ? applicationName : workflowModuleId;
final var deployedResources = deploymentCommand
.map(command -> command.send().join())
.map(command -> tenantId == null ? command : command.tenantId(tenantId))
.map(command -> command
.send()
.join())
.orElseThrow();

// BPMNs which are part of the current package will stored
deployedResources
.getProcesses()
.stream()
.map(process -> deploymentService.addProcess(
.forEach(process -> deploymentService.addProcess(
deploymentHashCode[0],
process,
deployedProcesses.get(process.getBpmnProcessId())).getDefinitionKey())
.collect(Collectors.toList());
deployedProcesses.get(process.getBpmnProcessId())));

}

// BPMNs which were deployed in the past need to be forced to be parsed for wiring
deploymentService
.getBpmnNotOfPackage(deploymentHashCode[0])
.stream()
.forEach(bpmn -> {

try (var inputStream = new ByteArrayInputStream(
bpmn.getResource())) {

logger.info("About to verify old BPMN '{}' of workflow-module '{}'",
bpmn.getResourceName(), workflowModuleName);
bpmn.getResourceName(),
workflowModuleId == null ? "default" : workflowModuleId);
final var model = bpmnParser.parseModelFromStream(inputStream);

processBpmnModel(workflowModuleId, deployedProcesses, bpmn, model, true);
Expand Down Expand Up @@ -250,7 +252,7 @@ private void processBpmnModel(
)
.flatMap(i -> i) // map stream of streams to one stream
)
.forEach(connectable -> taskWiring.wireTask(processService[0], connectable));
.forEach(connectable -> taskWiring.wireTask(workflowModuleId, processService[0], connectable));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class DeployedProcess extends Deployment {
public static final String TYPE = "PROCESS";

/** the BPMN process id of the process */
@Column(name = "BPMN_PROCESS_ID")
@Column(name = "C8D_BPMN_PROCESS_ID")
private String bpmnProcessId;

public String getBpmnProcessId() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.vanillabp.camunda8.deployment;

import java.time.OffsetDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.Entity;
Expand All @@ -14,38 +12,40 @@
import jakarta.persistence.Table;
import jakarta.persistence.Version;

import java.time.OffsetDateTime;

@Entity
@Table(name = "CAMUNDA8_DEPLOYMENTS")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE")
@DiscriminatorColumn(name = "C8D_TYPE")
@IdClass(DeploymentId.class)
public abstract class Deployment {

/** the key of the deployed process */
@Id
@Column(name = "DEFINITION_KEY")
@Column(name = "C8D_DEFINITION_KEY")
private long definitionKey;

/** the version of the deployed process */
@Id
@Column(name = "VERSION")
@Column(name = "C8D_VERSION")
private int version;

@Version
@Column(name = "RECORD_VERSION")
@Column(name = "C8D_RECORD_VERSION")
private int recordVersion;

@Column(name = "PACKAGE_ID")
@Column(name = "C8D_PACKAGE_ID")
private int packageId;

@ManyToOne(optional = false)
@JoinColumn(name = "RESOURCE", nullable = false, updatable = false)
@JoinColumn(name = "C8D_RESOURCE", nullable = false, updatable = false)
private DeploymentResource deployedResource;

@Column(name = "PUBLISHED_AT", nullable = false, columnDefinition = "TIMESTAMP WITH TIME ZONE")
@Column(name = "C8D_PUBLISHED_AT", nullable = false, columnDefinition = "TIMESTAMP WITH TIME ZONE")
private OffsetDateTime publishedAt;

@Column(name = "TYPE", updatable = false, insertable = false)
@Column(name = "C8D_TYPE", updatable = false, insertable = false)
private String type;

public long getDefinitionKey() {
Expand Down Expand Up @@ -103,5 +103,18 @@ public int getRecordVersion() {
public void setRecordVersion(int recordVersion) {
this.recordVersion = recordVersion;
}


@Override
public int hashCode() {
return (int) definitionKey % Integer.MAX_VALUE;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Deployment other)) {
return false;
}
return other.getDefinitionKey() == getDefinitionKey();
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.vanillabp.camunda8.deployment;

import java.util.List;

import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.Entity;
Expand All @@ -14,31 +12,33 @@
import jakarta.persistence.Table;
import jakarta.persistence.Version;

import java.util.List;

@Entity
@Table(name = "CAMUNDA8_RESOURCES")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE")
@DiscriminatorColumn(name = "C8R_TYPE")
public abstract class DeploymentResource {

@Id
@Column(name = "ID")
@Column(name = "C8R_ID")
private int fileId;

@Version
@Column(name = "RECORD_VERSION")
@Column(name = "C8R_RECORD_VERSION")
private int recordVersion;

@Column(name = "RESOURCE_NAME")
@Column(name = "C8R_RESOURCE_NAME")
private String resourceName;

@OneToMany(mappedBy = "deployedResource", fetch = FetchType.LAZY)
private List<Deployment> deployments;

@Lob
@Column(name = "RESOURCE")
@Column(name = "C8R_RESOURCE")
private byte[] resource;

@Column(name = "TYPE", updatable = false, insertable = false)
@Column(name = "C8R_TYPE", updatable = false, insertable = false)
private String type;

public int getFileId() {
Expand Down Expand Up @@ -88,5 +88,18 @@ public int getRecordVersion() {
public void setRecordVersion(int recordVersion) {
this.recordVersion = recordVersion;
}


@Override
public int hashCode() {
return getFileId();
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof DeploymentResource other)) {
return false;
}
return getFileId() == other.getFileId();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
@Repository
public interface DeploymentResourceRepository extends CrudRepository<DeploymentResource, Integer> {

List<DeployedBpmn> findDistinctByTypeAndDeployments_packageIdNot(String type, int packageId);
List<DeployedBpmn> findByTypeAndDeployments_packageIdNot(String type, int packageId);

}
Loading

0 comments on commit f0c4da2

Please sign in to comment.