Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

feature: Bean EIP as in https://camel.apache.org/components/latest/eips/bean-eip.html #788

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.kaoto.backend.camel.model.deployment.kamelet.expression.Script;
import io.kaoto.backend.camel.model.deployment.kamelet.expression.ScriptExpression;
import io.kaoto.backend.camel.model.deployment.kamelet.step.AggregateFlowStep;
import io.kaoto.backend.camel.model.deployment.kamelet.step.BeanFlowStep;
import io.kaoto.backend.camel.model.deployment.kamelet.step.ChoiceFlowStep;
import io.kaoto.backend.camel.model.deployment.kamelet.step.CircuitBreakerFlowStep;
import io.kaoto.backend.camel.model.deployment.kamelet.step.ClaimCheckFlowStep;
Expand Down Expand Up @@ -519,6 +520,9 @@ private FlowStep processStep(final Step step, final boolean to) {
case "aggregate":
flowStep = new AggregateFlowStep(step);
break;
case "bean":
flowStep = new BeanFlowStep(step);
break;
case "claim-check":
flowStep = new ClaimCheckFlowStep(step);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package io.kaoto.backend.camel.model.deployment.kamelet.step;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.kaoto.backend.api.metadata.catalog.StepCatalog;
import io.kaoto.backend.camel.model.deployment.kamelet.FlowStep;
import io.kaoto.backend.camel.service.step.parser.kamelet.KameletStepParserService;
import io.kaoto.backend.model.step.Step;

import java.io.Serial;
import java.util.HashMap;
import java.util.Map;


@JsonDeserialize(using = JsonDeserializer.None.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public class BeanFlowStep implements FlowStep {
public static final String BEAN_LABEL = "bean";
@Serial
private static final long serialVersionUID = 5848053149715309142L;
@JsonProperty(BEAN_LABEL)
private BeanStep bean;

public BeanFlowStep() {
//Needed for serialization
}

@JsonCreator
public BeanFlowStep(final @JsonProperty(value = BEAN_LABEL, required = true) Object bean) {
super();
if (bean instanceof BeanStep beanStep) {
this.setBean(beanStep);
} else if (bean instanceof Map map) {
this.setBean(new BeanStep(map));
} else if (bean != null) {
this.setBean(new BeanStep());
this.getBean().setBeanType(String.valueOf(bean));
}
}

public BeanFlowStep(Step step) {
setBean(new BeanStep(step));
}

@Override
public Map<String, Object> getRepresenterProperties() {
Map<String, Object> res = new HashMap<>();
final var representerProperties = getBean().getRepresenterProperties();
if (representerProperties.size() == 1
&& (representerProperties.containsKey(BeanStep.REF_LABEL)
|| representerProperties.containsKey(BeanStep.BEAN_TYPE_LABEL)
|| representerProperties.containsKey(BeanStep.BEAN_TYPE_LABEL2))) {
res.put(BEAN_LABEL, representerProperties.entrySet().iterator().next().getValue());
} else {
res.put(BEAN_LABEL, representerProperties);
}
return res;
}

@Override
public Step getStep(final StepCatalog catalog, final KameletStepParserService kameletStepParserService,
final Boolean start, final Boolean end) {
return getBean().getStep(catalog, BEAN_LABEL, kameletStepParserService);
}

public BeanStep getBean() {
return bean;
}

public void setBean(BeanStep bean) {
this.bean = bean;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package io.kaoto.backend.camel.model.deployment.kamelet.step;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.kaoto.backend.model.parameter.Parameter;
import io.kaoto.backend.model.step.Step;

import java.util.Map;


public class BeanStep extends EIPStep {
public static final String REF_LABEL = "ref";
public static final String METHOD_LABEL = "method";
public static final String BEAN_TYPE_LABEL = "beanType";
public static final String BEAN_TYPE_LABEL2 = "bean-type";
public static final String SCOPE_LABEL = "scope";
public static final String DESCRIPTION_LABEL = "description";
public static final String ID_LABEL = "id";

private String ref;

private String method;

private String beanType;
private String scope;
private String description;

public BeanStep() {
}

@JsonCreator
public BeanStep(final @JsonProperty(REF_LABEL) String ref,
final @JsonProperty(METHOD_LABEL) String method,
final @JsonProperty(BEAN_TYPE_LABEL) String beanType,
final @JsonProperty(BEAN_TYPE_LABEL2) String beanType2,
final @JsonProperty(SCOPE_LABEL) String scope,
final @JsonProperty(DESCRIPTION_LABEL) String description,
final @JsonProperty(ID_LABEL) String id) {
setRef(ref);
setMethod(method);
setDescription(description);
setBeanType(beanType != null ? beanType : beanType2);
setScope(scope);
setId(id);
}

public BeanStep(Step step) {
super(step);
}

public BeanStep(Map<String, Object> map) {
super(map);
if (map.containsKey(REF_LABEL)) {
this.setRef(String.valueOf(map.get(REF_LABEL)));
}
if (map.containsKey(METHOD_LABEL)) {
this.setMethod(String.valueOf(map.get(METHOD_LABEL)));
}
if (map.containsKey(SCOPE_LABEL)) {
this.setScope(String.valueOf(map.get(SCOPE_LABEL)));
}
if (map.containsKey(DESCRIPTION_LABEL)) {
this.setDescription(String.valueOf(map.get(DESCRIPTION_LABEL)));
}
if (map.containsKey(ID_LABEL)) {
this.setId(String.valueOf(map.get(ID_LABEL)));
}

if (map.containsKey(BEAN_TYPE_LABEL)) {
this.setBeanType(String.valueOf(map.get(BEAN_TYPE_LABEL)));
} else if (map.containsKey(BEAN_TYPE_LABEL2)) {
this.setBeanType(String.valueOf(map.get(BEAN_TYPE_LABEL2)));
}
}

@Override
public Map<String, Object> getRepresenterProperties() {
Map<String, Object> properties = super.getDefaultRepresenterProperties();
if (this.getRef() != null) {
properties.put(REF_LABEL, this.getRef());
}
if (this.getMethod() != null) {
properties.put(METHOD_LABEL, this.getMethod());
}
if (this.getScope() != null) {
properties.put(SCOPE_LABEL, this.getScope());
}
if (this.getBeanType() != null) {
properties.put(BEAN_TYPE_LABEL, this.getBeanType());
}
if (this.getDescription() != null) {
properties.put(DESCRIPTION_LABEL, this.getDescription());
}
return properties;
}


@Override
protected void assignAttribute(final Parameter parameter) {
switch (parameter.getId()) {
case REF_LABEL:
this.setRef(parameter.getValue().toString());
break;
case METHOD_LABEL:
this.setMethod(parameter.getValue().toString());
break;
case SCOPE_LABEL:
this.setScope(parameter.getValue().toString());
break;
case BEAN_TYPE_LABEL:
case BEAN_TYPE_LABEL2:
this.setBeanType(parameter.getValue().toString());
break;
case DESCRIPTION_LABEL:
this.setDescription(parameter.getValue().toString());
break;
case ID_LABEL:
this.setId(parameter.getValue().toString());
break;
default:
break;
}
}

@Override
protected void assignProperty(final Parameter parameter) {
switch (parameter.getId()) {
case REF_LABEL:
parameter.setValue(this.getRef());
break;
case METHOD_LABEL:
parameter.setValue(this.getMethod());
break;
case SCOPE_LABEL:
parameter.setValue(this.getScope());
break;
case BEAN_TYPE_LABEL:
parameter.setValue(this.getBeanType());
break;
case ID_LABEL:
parameter.setValue(this.getId());
break;
case DESCRIPTION_LABEL:
parameter.setValue(this.getDescription());
break;
default:
break;
}
}

public String getRef() {
return ref;
}

public void setRef(String ref) {
this.ref = ref;
}

public String getMethod() {
return method;
}

public void setMethod(String method) {
this.method = method;
}

public String getBeanType() {
return beanType;
}

public void setBeanType(String beanType) {
this.beanType = beanType;
}

public String getScope() {
return scope;
}

public void setScope(String scope) {
this.scope = scope;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private Map<String, Class> getFlowSteps() {
Map<String, Class> steps = new HashMap<>();

steps.put("aggregate", AggregateFlowStep.class);
steps.put("bean", BeanFlowStep.class);
steps.put("claim-check", ClaimCheckFlowStep.class);
steps.put("claimCheck", ClaimCheckFlowStep.class);
steps.put("circuitBreaker", CircuitBreakerFlowStep.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.kaoto.backend.camel.model.deployment.kamelet.expression.Script;
import io.kaoto.backend.camel.model.deployment.kamelet.expression.ScriptExpression;
import io.kaoto.backend.camel.model.deployment.kamelet.step.AggregateFlowStep;
import io.kaoto.backend.camel.model.deployment.kamelet.step.BeanFlowStep;
import io.kaoto.backend.camel.model.deployment.kamelet.step.ChoiceFlowStep;
import io.kaoto.backend.camel.model.deployment.kamelet.step.CircuitBreakerFlowStep;
import io.kaoto.backend.camel.model.deployment.kamelet.step.ClaimCheckFlowStep;
Expand Down Expand Up @@ -253,6 +254,7 @@ private void addEIP() {
// and making a mess?
var eips = new Class[] {
AggregateFlowStep.class,
BeanFlowStep.class,
ClaimCheckFlowStep.class,
CircuitBreakerFlowStep.class,
ChoiceFlowStep.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void localFolder() throws URISyntaxException {
ParseCatalog<Step> kameletParser = parseCatalog.getLocalFolder(Path.of(url.toURI()));
List<Step> steps = kameletParser.parse().join().stream().filter(Objects::nonNull).toList();

assertEquals(8, steps.size());
assertEquals(9, steps.size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ void appliesToInvalid(String resourcePath) throws IOException {
}

@ParameterizedTest
@ValueSource(strings = {"eip.kamelet.yaml", "jq.kamelet.yaml", "name.kamelet.yaml"})
@ValueSource(strings = {"eip.kamelet.yaml", "jq.kamelet.yaml", "name.kamelet.yaml",
"kafka-manual-commit-action.kamelet.yaml"})
void checkRoundTrip(String resource) throws Exception {
String kamelet = new String(Objects.requireNonNull(this.getClass().getResourceAsStream(resource))
.readAllBytes(), StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
annotations:
camel.apache.org/kamelet.support.level: Stable
camel.apache.org/catalog.version: 3.20.6
camel.apache.org/kamelet.icon: data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sb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SAtMzYsLTQ1LjUgLTU0LC03MC41IDI2LC01MCA0MSwtOTggbCAxODMsLTI4IHEgMTMsLTIgMjEsLTEyLjUgOCwtMTAuNSA4LC0yMy41IHoiCiAgICAgICBpZD0icGF0aDMwMjkiCiAgICAgICBpbmtzY2FwZTpjb25uZWN0b3ItY3VydmF0dXJlPSIwIgogICAgICAgc3R5bGU9ImZpbGw6Y3VycmVudENvbG9yIiAvPgogIDwvZz4KPC9zdmc+Cg==
camel.apache.org/provider: Apache Software Foundation
camel.apache.org/kamelet.group: Actions
camel.apache.org/kamelet.namespace: Kafka
labels:
camel.apache.org/kamelet.type: action
name: kafka-manual-commit-action
spec:
definition:
properties: {}
title: Kafka Manual Commit Action
type: object
dependencies:
- mvn:org.apache.camel.kamelets:camel-kamelets-utils:3.20.6
- camel:kamelet
- camel:core
template:
from:
uri: kamelet:source
steps:
- bean: org.apache.camel.kamelets.utils.transform.kafka.ManualCommit