Elffuss BraidHub

kikocis/EDC public

feat: add state field on DataPlaneInstance response (#4350)

Changeset013e37aefd54de154fdccc05e60d3caef235fd86a854b820dc7d92aeab721345
AuthorEnrico Risa <enrico.risa@gmail.com> · 2024-07-10 12:02 +02:00
CommitterGitHub <noreply@github.com> · 2024-07-10 12:02 +02:00
Parentsf67c47f35fe4

Browse the files at this changeset

8 files changed

modified DEPENDENCIES +3 −1
@@ -136,7 +136,7 @@
136136 maven/mavencentral/io.prometheus/simpleclient_tracer_otel_agent/0.16.0, Apache-2.0, approved, clearlydefined
137137 maven/mavencentral/io.rest-assured/json-path/5.5.0, Apache-2.0, approved, clearlydefined
138138 maven/mavencentral/io.rest-assured/rest-assured-common/5.5.0, Apache-2.0, approved, clearlydefined
139-maven/mavencentral/io.rest-assured/rest-assured/5.5.0, Apache-2.0, restricted, clearlydefined
139+maven/mavencentral/io.rest-assured/rest-assured/5.5.0, Apache-2.0, approved, #15676
140140 maven/mavencentral/io.rest-assured/xml-path/5.5.0, Apache-2.0, approved, clearlydefined
141141 maven/mavencentral/io.setl/rdf-urdna/1.1, Apache-2.0, approved, clearlydefined
142142 maven/mavencentral/io.swagger.core.v3/swagger-annotations-jakarta/2.2.22, Apache-2.0, approved, #5947
@@ -188,6 +188,7 @@
188188 maven/mavencentral/net.bytebuddy/byte-buddy/1.14.1, Apache-2.0 AND BSD-3-Clause, approved, #7163
189189 maven/mavencentral/net.bytebuddy/byte-buddy/1.14.15, Apache-2.0 AND BSD-3-Clause, approved, #7163
190190 maven/mavencentral/net.bytebuddy/byte-buddy/1.14.16, Apache-2.0 AND BSD-3-Clause, approved, #7163
191+maven/mavencentral/net.bytebuddy/byte-buddy/1.14.18, Apache-2.0 AND BSD-3-Clause, approved, #7163
191192 maven/mavencentral/net.java.dev.jna/jna/5.13.0, Apache-2.0 AND LGPL-2.1-or-later, approved, #15196
192193 maven/mavencentral/net.javacrumbs.json-unit/json-unit-core/2.36.0, Apache-2.0, approved, clearlydefined
193194 maven/mavencentral/net.minidev/accessors-smart/2.4.7, Apache-2.0, approved, #7515
@@ -228,6 +229,7 @@
228229 maven/mavencentral/org.apache.xbean/xbean-reflect/3.7, Apache-2.0, approved, clearlydefined
229230 maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved, clearlydefined
230231 maven/mavencentral/org.assertj/assertj-core/3.26.0, Apache-2.0, approved, #14886
232+maven/mavencentral/org.assertj/assertj-core/3.26.3, Apache-2.0, approved, #14886
231233 maven/mavencentral/org.awaitility/awaitility/4.2.1, Apache-2.0, approved, #14178
232234 maven/mavencentral/org.bouncycastle/bcpkix-jdk18on/1.72, MIT, approved, #3789
233235 maven/mavencentral/org.bouncycastle/bcpkix-jdk18on/1.78.1, MIT, approved, #14434
modified core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceTransformer.java +12 −0
@@ -18,14 +18,19 @@
1818 import jakarta.json.JsonBuilderFactory;
1919 import jakarta.json.JsonObject;
2020 import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance;
21+import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstanceStates;
2122 import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer;
2223 import org.eclipse.edc.transform.spi.TransformerContext;
2324 import org.jetbrains.annotations.NotNull;
2425 import org.jetbrains.annotations.Nullable;
2526
27+import java.util.Optional;
28+
2629 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_DEST_TYPES;
2730 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_SOURCE_TYPES;
2831 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_TRANSFER_TYPES;
32+import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE;
33+import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE_TIMESTAMP;
2934 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.LAST_ACTIVE;
3035 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.PROPERTIES;
3136 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.TURN_COUNT;
@@ -68,6 +73,13 @@
6873 var transferTypesBldr = jsonFactory.createArrayBuilder(dataPlaneInstance.getAllowedTransferTypes());
6974 builder.add(ALLOWED_TRANSFER_TYPES, transferTypesBldr);
7075
76+ var state = Optional.ofNullable(DataPlaneInstanceStates.from(dataPlaneInstance.getState()))
77+ .map(Enum::name)
78+ .orElse(null);
79+
80+ addIfNotNull(state, DATAPLANE_INSTANCE_STATE, builder);
81+
82+ builder.add(DATAPLANE_INSTANCE_STATE_TIMESTAMP, dataPlaneInstance.getStateTimestamp());
7183
7284 return builder.build();
7385 }
modified core/common/lib/transform-lib/src/main/java/org/eclipse/edc/transform/transformer/edc/to/JsonObjectToDataPlaneInstanceTransformer.java +2 −0
@@ -34,6 +34,7 @@
3434 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_SOURCE_TYPES;
3535 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_TRANSFER_TYPES;
3636 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.Builder;
37+import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE_TIMESTAMP;
3738 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.LAST_ACTIVE;
3839 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.PROPERTIES;
3940 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.TURN_COUNT;
@@ -76,6 +77,7 @@
7677 var set = jsonValue.asJsonArray().stream().map(jv -> transformString(jv, context)).collect(Collectors.toSet());
7778 builder.allowedTransferType(set);
7879 }
80+ case DATAPLANE_INSTANCE_STATE_TIMESTAMP -> transformLong(context, jsonValue, builder::stateTimestamp);
7981 case PROPERTIES -> {
8082 var props = jsonValue.asJsonArray().getJsonObject(0);
8183 visitProperties(props, (k, val) -> transformProperties(k, val, builder, context));
modified core/common/lib/transform-lib/src/test/java/org/eclipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceTransformerTest.java +33 −0
@@ -27,10 +27,13 @@
2727 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_DEST_TYPES;
2828 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_SOURCE_TYPES;
2929 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_TRANSFER_TYPES;
30+import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE;
31+import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE_TIMESTAMP;
3032 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.LAST_ACTIVE;
3133 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.PROPERTIES;
3234 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.TURN_COUNT;
3335 import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.URL;
36+import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstanceStates.AVAILABLE;
3437 import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
3538 import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper;
3639 import static org.mockito.Mockito.mock;
@@ -71,4 +74,34 @@
7174 assertThat(jsonObject.getJsonObject(PROPERTIES).getJsonString("foo").getString()).isEqualTo("bar");
7275
7376 }
77+
78+ @Test
79+ void transform_withState() {
80+ var dpi = DataPlaneInstance.Builder.newInstance()
81+ .id("test-id")
82+ .url("http://foo.bar")
83+ .allowedSourceType("test-source-type")
84+ .allowedDestType("test-dest-type")
85+ .allowedTransferType("test-transfer-type")
86+ .lastActive(15)
87+ .turnCount(42)
88+ .state(AVAILABLE.code())
89+ .property("foo", "bar")
90+ .build();
91+
92+ var jsonObject = transformer.transform(dpi, context);
93+
94+ assertThat(jsonObject).isNotNull();
95+ assertThat(jsonObject.getString(ID)).isEqualTo("test-id");
96+ assertThat(jsonObject.getString(URL)).isEqualTo("http://foo.bar");
97+ assertThat(jsonObject.getJsonArray(ALLOWED_SOURCE_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-source-type"));
98+ assertThat(jsonObject.getJsonArray(ALLOWED_DEST_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-dest-type"));
99+ assertThat(jsonObject.getJsonArray(ALLOWED_TRANSFER_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-transfer-type"));
100+ assertThat(jsonObject.getJsonNumber(LAST_ACTIVE).intValue()).isEqualTo(15);
101+ assertThat(jsonObject.getJsonNumber(TURN_COUNT).intValue()).isEqualTo(42);
102+ assertThat(jsonObject.getString(DATAPLANE_INSTANCE_STATE)).isEqualTo(AVAILABLE.name());
103+ assertThat(jsonObject.getJsonNumber(DATAPLANE_INSTANCE_STATE_TIMESTAMP).longValue()).isEqualTo(dpi.getStateTimestamp());
104+ assertThat(jsonObject.getJsonObject(PROPERTIES).getJsonString("foo").getString()).isEqualTo("bar");
105+
106+ }
74107 }
modified extensions/common/api/management-api-configuration/src/main/resources/management-api-version.json +2 −2
@@ -1,8 +1,8 @@
11 [
22 {
3- "version": "3.0.1",
3+ "version": "3.0.2",
44 "urlPath": "/v3",
5- "lastUpdated": "2024-06-13T14:28:00Z",
5+ "lastUpdated": "2024-07-10T09:17:00Z",
66 "maturity": "stable"
77 },
88 {
modified extensions/data-plane-selector/data-plane-selector-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/api/schemas/DataPlaneInstanceSchema.java +6 −2
@@ -40,7 +40,9 @@
4040 @Schema(requiredMode = REQUIRED)
4141 Set<String> allowedDestTypes,
4242 Integer turnCount,
43- Long lastActive) {
43+ Long lastActive,
44+ String state,
45+ Long stateTimestamp) {
4446 public static final String DATAPLANE_INSTANCE_EXAMPLE = """
4547 {
4648 "@context": {
@@ -53,7 +55,9 @@
5355 "source-type2"
5456 ],
5557 "allowedDestTypes": ["your-dest-type"],
56- "allowedTransferTypes": ["transfer-type"]
58+ "allowedTransferTypes": ["transfer-type"],
59+ "state": "AVAILABLE",
60+ "stateTimestamp": 1688465655
5761 }
5862 """;
5963 }
modified spi/data-plane-selector/data-plane-selector-spi/src/main/java/org/eclipse/edc/connector/dataplane/selector/spi/instance/DataPlaneInstance.java +5 −1
@@ -54,6 +54,10 @@
5454 @Deprecated(since = "0.7.0")
5555 public static final String ALLOWED_DEST_TYPES = EDC_NAMESPACE + "allowedDestTypes";
5656
57+ public static final String DATAPLANE_INSTANCE_STATE = EDC_NAMESPACE + "state";
58+ public static final String DATAPLANE_INSTANCE_STATE_TIMESTAMP = EDC_NAMESPACE + "stateTimestamp";
59+
60+
5761 private Map<String, Object> properties = new HashMap<>();
5862 private Set<String> allowedTransferTypes = new HashSet<>();
5963 private Set<String> allowedSourceTypes = new HashSet<>();
@@ -91,7 +95,7 @@
9195 * transferType against an internal list of allowed source and transfer types.
9296 *
9397 * @param sourceAddress the sourceAddress
94- * @param transferType the transferType
98+ * @param transferType the transferType
9599 * @return true if it can handle, false otherwise.
96100 */
97101 public boolean canHandle(DataAddress sourceAddress, @Nullable String transferType) {
modified system-tests/version-api/version-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/versionapi/VersionApiEndToEndTest.java +1 −1
@@ -55,7 +55,7 @@
5555
5656 assertThat(result).containsKeys("management", "version", "control", "observability", "sts");
5757 assertThat(result.get("management")).hasSize(2)
58- .anyMatch(vr -> vr.version().equals("3.0.1") && vr.maturity().equals("stable"))
58+ .anyMatch(vr -> vr.version().equals("3.0.2") && vr.maturity().equals("stable"))
5959 .anyMatch(vr -> vr.version().equals("3.1.0-alpha") && vr.maturity().equals("alpha"));
6060 assertThat(result.get("version")).hasSize(1).anyMatch(vr -> vr.version().equals("1.0.0"));
6161 assertThat(result.get("observability")).hasSize(1).anyMatch(vr -> vr.version().equals("1.0.0"));