Skip to content

Commit

Permalink
chore: Add support for Kamelet data types
Browse files Browse the repository at this point in the history
- Update Kamelet and KameletBinding model to support data types
  • Loading branch information
christophd committed Mar 9, 2023
1 parent eff2d8c commit 746d11c
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,14 @@ public void setNamespace(String namespace) {
runner.run(createVariable(VariableNames.KAMELET_NAMESPACE.value(), namespace));
}

@Given("^Kamelet type (in|out|error)(?:=| is )\"(.+)\"$")
public void addType(String slot, String mediaType) {
kamelet.addType(slot, mediaType);
@Given("^Kamelet dataType (in|out|error)(?:=| is )\"(.+)\"$")
public void addType(String slot, String format) {
if (format.contains(":")) {
String[] schemeAndFormat = format.split(":");
kamelet.addDataType(slot, schemeAndFormat[0], schemeAndFormat[1]);
} else {
kamelet.addDataType(slot, "camel", format);
}
}

@Given("^Kamelet title \"(.+)\"$")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class CreateKameletAction extends AbstractKameletAction {
private final KameletSpec.Source source;
private final KameletSpec.Definition definition;
private final List<String> dependencies;
private final Map<String, KameletSpec.TypeSpec> types;
private final Map<String, KameletSpec.DataTypesSpec> dataTypes;
private final Resource resource;
private final boolean supportVariables;

Expand All @@ -63,7 +63,7 @@ public CreateKameletAction(Builder builder) {
this.source = builder.source;
this.definition = builder.definition;
this.dependencies = builder.dependencies;
this.types = builder.types;
this.dataTypes = builder.dataTypes;
this.resource = builder.resource;
this.supportVariables = builder.supportVariables;
}
Expand Down Expand Up @@ -117,8 +117,8 @@ private void createKamelet(TestContext context) {
builder.dependencies(context.resolveDynamicValuesInList(dependencies));
}

if (types != null && !types.isEmpty()) {
builder.types(context.resolveDynamicValuesInMap(types));
if (dataTypes != null && !dataTypes.isEmpty()) {
builder.dataTypes(context.resolveDynamicValuesInMap(dataTypes));
}

kamelet = builder.build();
Expand Down Expand Up @@ -150,8 +150,10 @@ public static final class Builder extends AbstractKameletAction.Builder<CreateKa
private KameletSpec.Source source;
private final List<String> dependencies = new ArrayList<>();
private KameletSpec.Definition definition = new KameletSpec.Definition();
private final Map<String, KameletSpec.TypeSpec> types = new HashMap<>();
private final Map<String, KameletSpec.DataTypesSpec> dataTypes = new HashMap<>();

private Resource resource;

private boolean supportVariables = true;

public Builder supportVariables(boolean supportVariables) {
Expand Down Expand Up @@ -216,20 +218,25 @@ public Builder addProperty(String name, KameletSpec.Definition.PropertyConfig pr
return this;
}

public Builder inType(String mediaType) {
return addType("in", mediaType);
public Builder inType(String scheme, String format) {
return addDataType("in", scheme, format);
}

public Builder outType(String mediaType) {
return addType("out", mediaType);
public Builder outType(String scheme, String format) {
return addDataType("out", scheme, format);
}

public Builder errorType(String mediaType) {
return addType("error", mediaType);
public Builder errorType(String scheme, String format) {
return addDataType("error", scheme, format);
}

public Builder addType(String slot, String mediaType) {
this.types.put(slot, new KameletSpec.TypeSpec(mediaType));
public Builder addDataType(String slot, String scheme, String format) {
if (dataTypes.containsKey(slot)) {
this.dataTypes.get(slot).getTypes().add(new KameletSpec.DataTypeSpec(scheme, format));
} else {
this.dataTypes.put(slot, new KameletSpec.DataTypesSpec(format, new KameletSpec.DataTypeSpec(scheme, format)));
}

return this;
}

Expand All @@ -239,7 +246,7 @@ public Builder fromBuilder(Kamelet.Builder builder) {
name = kamelet.getMetadata().getName();
definition = kamelet.getSpec().getDefinition();
dependencies.addAll(kamelet.getSpec().getDependencies());
types.putAll(kamelet.getSpec().getTypes());
dataTypes.putAll(kamelet.getSpec().getDataTypes());

if (kamelet.getSpec().getSources() != null && !kamelet.getSpec().getSources().isEmpty()) {
source = kamelet.getSpec().getSources().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static class Builder {
private String name;
private String template;
private KameletSpec.Definition definition = new KameletSpec.Definition();
private final Map<String, KameletSpec.TypeSpec> types = new HashMap<>();
private final Map<String, KameletSpec.DataTypesSpec> dataTypes = new HashMap<>();
private List<String> dependencies = new ArrayList<>();
private KameletSpec.Source source;

Expand Down Expand Up @@ -100,13 +100,18 @@ public Builder dependencies(List<String> dependencies) {
return this;
}

public Builder types(Map<String, KameletSpec.TypeSpec> types) {
this.types.putAll(types);
public Builder dataTypes(Map<String, KameletSpec.DataTypesSpec> types) {
this.dataTypes.putAll(types);
return this;
}

public Builder addType(String slot, String mediaType) {
this.types.put(slot, new KameletSpec.TypeSpec(mediaType));
public Builder addDataType(String slot, String scheme, String format) {
if (dataTypes.containsKey(slot)) {
this.dataTypes.get(slot).getTypes().add(new KameletSpec.DataTypeSpec(scheme, format));
} else {
this.dataTypes.put(slot, new KameletSpec.DataTypesSpec(format, new KameletSpec.DataTypeSpec(scheme, format)));
}

return this;
}

Expand All @@ -124,7 +129,7 @@ public Kamelet build() {
}

kamelet.getSpec().setDependencies(dependencies);
kamelet.getSpec().setTypes(types);
kamelet.getSpec().setDataTypes(dataTypes);
return kamelet;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Integration getIntegration() {

@JsonDeserialize(using = JsonDeserializer.None.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({"ref", "uri", "properties"})
@JsonPropertyOrder({"ref", "uri", "properties", "dataTypes"})
public static class Endpoint implements KubernetesResource {
@JsonProperty("ref")
private ObjectReference ref;
Expand All @@ -101,6 +101,10 @@ public static class Endpoint implements KubernetesResource {
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, Object> properties = new HashMap<>();

@JsonProperty("dataTypes")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, DataTypeRef> dataTypes = new HashMap<>();

public Endpoint() {
}

Expand Down Expand Up @@ -141,6 +145,50 @@ public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}

public Map<String, DataTypeRef> getDataTypes() {
return dataTypes;
}

public void setDataTypes(Map<String, DataTypeRef> dataTypes) {
this.dataTypes = dataTypes;
}

@JsonDeserialize(using = JsonDeserializer.None.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({"scheme", "format"})
public static class DataTypeRef implements KubernetesResource {
@JsonProperty("scheme")
private String scheme;

@JsonProperty("format")
private String format;

public DataTypeRef() {
super();
}

public DataTypeRef(String scheme, String format) {
this.scheme = scheme;
this.format = format;
}

public String getScheme() {
return scheme;
}

public void setScheme(String scheme) {
this.scheme = scheme;
}

public String getFormat() {
return format;
}

public void setFormat(String format) {
this.format = format;
}
}

@JsonDeserialize(using = JsonDeserializer.None.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({"name", "kind", "namespace", "uid", "apiVersion", "resourceVersion", "fieldPath"})
Expand Down
Loading

0 comments on commit 746d11c

Please sign in to comment.