Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Rename annotations (#239). Removed dedicated reader classes to ease d…
Browse files Browse the repository at this point in the history
…eprecation handling
  • Loading branch information
berndruecker committed Oct 12, 2022
1 parent 5be448c commit 51b4f64
Show file tree
Hide file tree
Showing 30 changed files with 367 additions and 337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.camunda.zeebe.client.api.worker.BackoffSupplier;
import io.camunda.zeebe.client.impl.worker.ExponentialBackoffBuilderImpl;
import io.camunda.zeebe.spring.client.annotation.processor.AnnotationProcessorConfiguration;
import io.camunda.zeebe.spring.client.annotation.value.factory.ReadAnnotationValueConfiguration;
import io.camunda.zeebe.spring.client.jobhandling.DefaultCommandExceptionHandlingStrategy;
import io.camunda.zeebe.spring.client.jobhandling.JobWorkerManager;
import io.camunda.zeebe.spring.client.jobhandling.SpringSecretProvider;
Expand All @@ -23,8 +22,7 @@
* The subclasses add the differences for prod/test
*/
@Import({
AnnotationProcessorConfiguration.class,
ReadAnnotationValueConfiguration.class,
AnnotationProcessorConfiguration.class
})
public abstract class AbstractZeebeBaseClientSpringConfiguration {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.camunda.zeebe.spring.client.annotation;

import java.lang.annotation.*;

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CustomHeaders {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.camunda.zeebe.spring.client.annotation;

import java.lang.annotation.*;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited // has to be inherited to work on spring aop beans
public @interface Deployment {

String[] resources() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.camunda.zeebe.spring.client.annotation;

import java.lang.annotation.*;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface JobWorker {

String type() default ""; // set to empty string which leads to method name being used (if not ${zeebe.client.worker.default-type}" is configured) Implemented in ZeebeWorkerAnnotationProcessor

String name() default ""; // set to empty string which leads to default from ZeebeClientBuilderImpl being used in ZeebeWorkerAnnotationProcessor

long timeout() default -1L;

int maxJobsActive() default -1;

long requestTimeout() default -1L;

long pollInterval() default -1L;

String[] fetchVariables() default {};

/**
* If set to true, all variables are fetched
*/
boolean fetchAllVariables() default false;

/**
* If set to true, the job is automatically completed after the worker code has finished.
* In this case, your worker code is not allowed to complete the job itself.
*
* You can still throw exceptions if you want to raise a problem instead of job completion.
* You could also raise a BPMN problem throwing a {@link io.camunda.zeebe.spring.client.exception.ZeebeBpmnError}
*/
boolean autoComplete() default true;

boolean enabled() default true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.camunda.zeebe.spring.client.annotation;

import java.lang.annotation.*;

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Variable {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.camunda.zeebe.spring.client.annotation;

import java.lang.annotation.*;

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface VariablesAsType {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
/**
* @deprecated
* Use {@link CustomHeaders} instead.
*/
@Deprecated
public @interface ZeebeCustomHeaders {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited // has to be inherited to work on spring aop beans
/**
* @deprecated
* Use {@link Deployment} instead.
*/
@Deprecated
public @interface ZeebeDeployment {

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
/**
* @deprecated
* Use {@link Variable} instead.
*/
@Deprecated
public @interface ZeebeVariable {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
/**
* @deprecated
* Use {@link VariablesAsType} instead.
*/
@Deprecated
public @interface ZeebeVariablesAsType {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
/**
* @deprecated
* Use {@link JobWorker} instead. Note, that the default for auto completion has changed there from "false" to "true"!
*/
@Deprecated
public @interface ZeebeWorker {

String type() default ""; // set to empty string which leads to method name being used (if not ${zeebe.client.worker.default-type}" is configured) Implemented in ZeebeWorkerAnnotationProcessor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package io.camunda.zeebe.spring.client.annotation.processor;

import io.camunda.connector.api.annotation.OutboundConnector;
import io.camunda.zeebe.client.api.worker.BackoffSupplier;
import io.camunda.zeebe.spring.client.annotation.customizer.ZeebeWorkerValueCustomizer;
import io.camunda.zeebe.spring.client.annotation.value.factory.ReadAnnotationValueConfiguration;
import io.camunda.zeebe.spring.client.annotation.value.factory.ReadOutboundConnectorValue;
import io.camunda.zeebe.spring.client.annotation.value.factory.ReadZeebeDeploymentValue;
import io.camunda.zeebe.spring.client.annotation.value.factory.ReadZeebeWorkerValue;
import java.util.List;

import io.camunda.zeebe.spring.client.jobhandling.DefaultCommandExceptionHandlingStrategy;
import io.camunda.zeebe.spring.client.jobhandling.JobWorkerManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;

import java.util.List;

@Import(ReadAnnotationValueConfiguration.class)
public class AnnotationProcessorConfiguration {

@Bean
Expand All @@ -23,20 +15,22 @@ public ZeebeAnnotationProcessorRegistry zeebeAnnotationProcessorRegistry(final L
}

@Bean
public ZeebeDeploymentAnnotationProcessor deploymentPostProcessor(final ReadZeebeDeploymentValue reader) {
return new ZeebeDeploymentAnnotationProcessor(reader);
public ZeebeDeploymentAnnotationProcessor deploymentPostProcessor() {
return new ZeebeDeploymentAnnotationProcessor();
}

@Bean
public OutboundConnectorAnnotationProcessor outboundConnectorAnnotationProcessor(final ReadOutboundConnectorValue reader, final JobWorkerManager jobWorkerManager) {
return new OutboundConnectorAnnotationProcessor(reader, jobWorkerManager);
public OutboundConnectorAnnotationProcessor outboundConnectorAnnotationProcessor(final JobWorkerManager jobWorkerManager) {
return new OutboundConnectorAnnotationProcessor(jobWorkerManager);
}

@Bean
public ZeebeWorkerAnnotationProcessor zeebeWorkerPostProcessor(final ReadZeebeWorkerValue reader,
final JobWorkerManager jobWorkerManager,
final List<ZeebeWorkerValueCustomizer> zeebeWorkerValueCustomizers) {
return new ZeebeWorkerAnnotationProcessor(reader, jobWorkerManager, zeebeWorkerValueCustomizers);
public ZeebeWorkerAnnotationProcessor zeebeWorkerPostProcessor(final JobWorkerManager jobWorkerManager,
final List<ZeebeWorkerValueCustomizer> zeebeWorkerValueCustomizers,
final Environment environment) { // can#t use @Value because it is only evaluated after constructors are executed
String defaultWorkerType = environment.getProperty("zeebe.client.worker.default-type", (String)null);
String defaultJobWorkerName = environment.getProperty("zeebe.client.worker.default-name", (String)null);
return new ZeebeWorkerAnnotationProcessor(jobWorkerManager, zeebeWorkerValueCustomizers, defaultWorkerType, defaultJobWorkerName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@
import io.camunda.connector.api.outbound.OutboundConnectorFunction;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.worker.JobWorker;
import io.camunda.zeebe.spring.client.annotation.ZeebeWorker;
import io.camunda.zeebe.spring.client.annotation.value.OutboundConnectorValue;
import io.camunda.zeebe.spring.client.annotation.value.ZeebeWorkerValue;
import io.camunda.zeebe.spring.client.annotation.value.factory.ReadOutboundConnectorValue;
import io.camunda.zeebe.spring.client.bean.ClassInfo;
import io.camunda.zeebe.spring.client.bean.MethodInfo;
import io.camunda.zeebe.spring.client.jobhandling.JobWorkerManager;
import io.camunda.zeebe.spring.client.jobhandling.copy.OutboundConnectorFunctionInvoker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.util.ReflectionUtils;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,12 +23,11 @@
public class OutboundConnectorAnnotationProcessor extends AbstractZeebeAnnotationProcessor {

private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private ReadOutboundConnectorValue reader;

private final List<OutboundConnectorValue> outboundConnectors = new ArrayList<>();
private final JobWorkerManager jobWorkerManager;

public OutboundConnectorAnnotationProcessor(ReadOutboundConnectorValue reader, final JobWorkerManager jobWorkerManager) {
this.reader = reader;
public OutboundConnectorAnnotationProcessor(final JobWorkerManager jobWorkerManager) {
this.jobWorkerManager = jobWorkerManager;
}

Expand All @@ -46,9 +38,14 @@ public boolean isApplicableFor(ClassInfo beanInfo) {

@Override
public void configureFor(ClassInfo beanInfo) {
Optional<OutboundConnectorValue> connectorValue = reader.apply(beanInfo);
if (connectorValue.isPresent()) {
OutboundConnectorValue connector = connectorValue.get();
Optional<OutboundConnector> annotation = beanInfo.getAnnotation(OutboundConnector.class);
if (annotation.isPresent()) {
OutboundConnectorValue connector = new OutboundConnectorValue()
.setBeanInfo(beanInfo)
.setType(annotation.get().type())
.setName(annotation.get().name())
.setInputVariables(annotation.get().inputVariables());

LOGGER.info("Configuring outbound connector {} of bean '{}'", connector, beanInfo.getBeanName());
outboundConnectors.add(connector);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.command.DeployResourceCommandStep1;
import io.camunda.zeebe.client.api.response.DeploymentEvent;
import io.camunda.zeebe.spring.client.annotation.Deployment;
import io.camunda.zeebe.spring.client.annotation.ZeebeDeployment;
import io.camunda.zeebe.spring.client.bean.BeanInfo;
import io.camunda.zeebe.spring.client.bean.ClassInfo;
import io.camunda.zeebe.spring.client.annotation.value.ZeebeDeploymentValue;
import io.camunda.zeebe.spring.client.annotation.value.factory.ReadZeebeDeploymentValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
Expand All @@ -16,16 +17,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Always created by {@link AnnotationProcessorConfiguration}
*
* Loop throgh @{@link ZeebeDeployment} annotations to deploy resources to Zeebe
* Loop throgh @{@link Deployment} annotations to deploy resources to Zeebe
* once the {@link io.camunda.zeebe.spring.client.lifecycle.ZeebeClientLifecycle} was initialized.
*/
public class ZeebeDeploymentAnnotationProcessor extends AbstractZeebeAnnotationProcessor {
Expand All @@ -34,25 +33,66 @@ public class ZeebeDeploymentAnnotationProcessor extends AbstractZeebeAnnotationP

private static final ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();

private final ReadZeebeDeploymentValue reader;

private List<ZeebeDeploymentValue> deploymentValues = new ArrayList<>();

public ZeebeDeploymentAnnotationProcessor(ReadZeebeDeploymentValue reader) {
this.reader = reader;
public ZeebeDeploymentAnnotationProcessor() {
}

@Override
public boolean isApplicableFor(ClassInfo beanInfo) {
return beanInfo.hasClassAnnotation(ZeebeDeployment.class);
return beanInfo.hasClassAnnotation(Deployment.class) || beanInfo.hasClassAnnotation(ZeebeDeployment.class);
}

@Override
public void configureFor(final ClassInfo beanInfo) {
ZeebeDeploymentValue value = reader.applyOrThrow(beanInfo);
LOGGER.info("Configuring deployment: {}", value);
Optional<ZeebeDeploymentValue> zeebeDeploymentValue = readAnnotation(beanInfo);
if (zeebeDeploymentValue.isPresent()) {
LOGGER.info("Configuring deployment: {}", zeebeDeploymentValue.get());
deploymentValues.add(zeebeDeploymentValue.get());
}
}

public Optional<ZeebeDeploymentValue> readAnnotation(ClassInfo beanInfo) {
Optional<Deployment> annotation = beanInfo.getAnnotation(Deployment.class);
if (!annotation.isPresent()) {
return readDeprecatedAnnotation(beanInfo);
} else {
List<String> resources = Arrays.stream(annotation.get().resources()).collect(Collectors.toList());
return Optional.of(ZeebeDeploymentValue.builder()
.beanInfo(beanInfo)
.resources(resources)
.build());
}
}

private static final String CLASSPATH_ALL_URL_PREFIX = "classpath*:";

/**
* Seperate handling for legacy annotation (had additional classPathResources attribute)
* @param beanInfo
*/
private Optional<ZeebeDeploymentValue> readDeprecatedAnnotation(ClassInfo beanInfo) {
Optional<ZeebeDeployment> annotation = beanInfo.getAnnotation(ZeebeDeployment.class);
if (!annotation.isPresent()) {
return Optional.empty();
}

List<String> resources = Arrays.stream(annotation.get().resources()).collect(Collectors.toList());

String[] classPathResources = annotation.get().classPathResources();
if (classPathResources.length > 0) {
resources.addAll(
Arrays.stream(classPathResources)
.map(resource -> CLASSPATH_ALL_URL_PREFIX + resource)
.collect(Collectors.toList())
);
}

deploymentValues.add(value);
return Optional.of(
ZeebeDeploymentValue.builder()
.beanInfo(beanInfo)
.resources(resources)
.build());
}

@Override
Expand Down
Loading

0 comments on commit 51b4f64

Please sign in to comment.