Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(api): expose dataplanes api v4alpha #4704

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -26,14 +26,12 @@

import java.util.Optional;

import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_DEST_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_SOURCE_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_TRANSFER_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE_TIMESTAMP;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.LAST_ACTIVE;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.PROPERTIES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.TURN_COUNT;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.URL;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
Expand All @@ -54,10 +52,8 @@ public JsonObjectFromDataPlaneInstanceTransformer(JsonBuilderFactory jsonFactory
.add(ID, dataPlaneInstance.getId())
.add(TYPE, DataPlaneInstance.DATAPLANE_INSTANCE_TYPE)
.add(URL, dataPlaneInstance.getUrl().toString())
.add(LAST_ACTIVE, dataPlaneInstance.getLastActive())
.add(TURN_COUNT, dataPlaneInstance.getTurnCount());
.add(LAST_ACTIVE, dataPlaneInstance.getLastActive());

//properties
if (dataPlaneInstance.getProperties() != null && !dataPlaneInstance.getProperties().isEmpty()) {
var propBuilder = jsonFactory.createObjectBuilder();
transformProperties(dataPlaneInstance.getProperties(), propBuilder, mapper, context);
Expand All @@ -67,9 +63,6 @@ public JsonObjectFromDataPlaneInstanceTransformer(JsonBuilderFactory jsonFactory
var srcBldr = jsonFactory.createArrayBuilder(dataPlaneInstance.getAllowedSourceTypes());
builder.add(ALLOWED_SOURCE_TYPES, srcBldr);

var dstBldr = jsonFactory.createArrayBuilder(dataPlaneInstance.getAllowedDestTypes());
builder.add(ALLOWED_DEST_TYPES, dstBldr);

var transferTypesBldr = jsonFactory.createArrayBuilder(dataPlaneInstance.getAllowedTransferTypes());
builder.add(ALLOWED_TRANSFER_TYPES, transferTypesBldr);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2025 Cofinity-X
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Cofinity-X - initial API and implementation
*
*/

package org.eclipse.edc.transform.transformer.edc.from;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.json.JsonBuilderFactory;
import jakarta.json.JsonObject;
import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance;
import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstanceStates;
import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer;
import org.eclipse.edc.transform.spi.TransformerContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_DEST_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_SOURCE_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_TRANSFER_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE_TIMESTAMP;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.LAST_ACTIVE;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.PROPERTIES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.TURN_COUNT;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.URL;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;

public class JsonObjectFromDataPlaneInstanceV3Transformer extends AbstractJsonLdTransformer<DataPlaneInstance, JsonObject> {
private final JsonBuilderFactory jsonFactory;
private final ObjectMapper mapper;

public JsonObjectFromDataPlaneInstanceV3Transformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) {
super(DataPlaneInstance.class, JsonObject.class);
this.jsonFactory = jsonFactory;
this.mapper = mapper;
}

@Override
public @Nullable JsonObject transform(@NotNull DataPlaneInstance dataPlaneInstance, @NotNull TransformerContext context) {
var builder = jsonFactory.createObjectBuilder()
.add(ID, dataPlaneInstance.getId())
.add(TYPE, DataPlaneInstance.DATAPLANE_INSTANCE_TYPE)
.add(URL, dataPlaneInstance.getUrl().toString())
.add(LAST_ACTIVE, dataPlaneInstance.getLastActive())
.add(TURN_COUNT, dataPlaneInstance.getTurnCount());

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
DataPlaneInstance.getTurnCount
should be avoided because it has been deprecated.

if (dataPlaneInstance.getProperties() != null && !dataPlaneInstance.getProperties().isEmpty()) {
var propBuilder = jsonFactory.createObjectBuilder();
transformProperties(dataPlaneInstance.getProperties(), propBuilder, mapper, context);
builder.add(PROPERTIES, propBuilder);
}

var srcBldr = jsonFactory.createArrayBuilder(dataPlaneInstance.getAllowedSourceTypes());
builder.add(ALLOWED_SOURCE_TYPES, srcBldr);

var dstBldr = jsonFactory.createArrayBuilder(dataPlaneInstance.getAllowedDestTypes());

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
DataPlaneInstance.getAllowedDestTypes
should be avoided because it has been deprecated.
builder.add(ALLOWED_DEST_TYPES, dstBldr);

var transferTypesBldr = jsonFactory.createArrayBuilder(dataPlaneInstance.getAllowedTransferTypes());
builder.add(ALLOWED_TRANSFER_TYPES, transferTypesBldr);

var state = Optional.ofNullable(DataPlaneInstanceStates.from(dataPlaneInstance.getState()))
.map(Enum::name)
.orElse(null);

addIfNotNull(state, DATAPLANE_INSTANCE_STATE, builder);

builder.add(DATAPLANE_INSTANCE_STATE_TIMESTAMP, dataPlaneInstance.getStateTimestamp());

return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_DEST_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_SOURCE_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_TRANSFER_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE_TIMESTAMP;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.LAST_ACTIVE;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.PROPERTIES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.TURN_COUNT;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.URL;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstanceStates.AVAILABLE;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
Expand All @@ -54,10 +52,8 @@ void transform() {
.id("test-id")
.url("http://foo.bar")
.allowedSourceType("test-source-type")
.allowedDestType("test-dest-type")
.allowedTransferType("test-transfer-type")
.lastActive(15)
.turnCount(42)
.property("foo", "bar")
.build();

Expand All @@ -67,10 +63,8 @@ void transform() {
assertThat(jsonObject.getString(ID)).isEqualTo("test-id");
assertThat(jsonObject.getString(URL)).isEqualTo("http://foo.bar");
assertThat(jsonObject.getJsonArray(ALLOWED_SOURCE_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-source-type"));
assertThat(jsonObject.getJsonArray(ALLOWED_DEST_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-dest-type"));
assertThat(jsonObject.getJsonArray(ALLOWED_TRANSFER_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-transfer-type"));
assertThat(jsonObject.getJsonNumber(LAST_ACTIVE).intValue()).isEqualTo(15);
assertThat(jsonObject.getJsonNumber(TURN_COUNT).intValue()).isEqualTo(42);
assertThat(jsonObject.getJsonObject(PROPERTIES).getJsonString("foo").getString()).isEqualTo("bar");

}
Expand All @@ -81,10 +75,8 @@ void transform_withState() {
.id("test-id")
.url("http://foo.bar")
.allowedSourceType("test-source-type")
.allowedDestType("test-dest-type")
.allowedTransferType("test-transfer-type")
.lastActive(15)
.turnCount(42)
.state(AVAILABLE.code())
.property("foo", "bar")
.build();
Expand All @@ -95,10 +87,8 @@ void transform_withState() {
assertThat(jsonObject.getString(ID)).isEqualTo("test-id");
assertThat(jsonObject.getString(URL)).isEqualTo("http://foo.bar");
assertThat(jsonObject.getJsonArray(ALLOWED_SOURCE_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-source-type"));
assertThat(jsonObject.getJsonArray(ALLOWED_DEST_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-dest-type"));
assertThat(jsonObject.getJsonArray(ALLOWED_TRANSFER_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-transfer-type"));
assertThat(jsonObject.getJsonNumber(LAST_ACTIVE).intValue()).isEqualTo(15);
assertThat(jsonObject.getJsonNumber(TURN_COUNT).intValue()).isEqualTo(42);
assertThat(jsonObject.getString(DATAPLANE_INSTANCE_STATE)).isEqualTo(AVAILABLE.name());
assertThat(jsonObject.getJsonNumber(DATAPLANE_INSTANCE_STATE_TIMESTAMP).longValue()).isEqualTo(dpi.getStateTimestamp());
assertThat(jsonObject.getJsonObject(PROPERTIES).getJsonString("foo").getString()).isEqualTo("bar");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2025 Cofinity-X
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Cofinity-X - initial API and implementation
*
*/

package org.eclipse.edc.transform.transformer.edc.from;

import jakarta.json.Json;
import jakarta.json.JsonString;
import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance;
import org.eclipse.edc.transform.spi.TransformerContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_DEST_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_SOURCE_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_TRANSFER_TYPES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE_TIMESTAMP;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.LAST_ACTIVE;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.PROPERTIES;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.TURN_COUNT;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.URL;
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstanceStates.AVAILABLE;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper;
import static org.mockito.Mockito.mock;

class JsonObjectFromDataPlaneInstanceV3TransformerTest {

private final TransformerContext context = mock();
private JsonObjectFromDataPlaneInstanceV3Transformer transformer;

@BeforeEach
void setUp() {
transformer = new JsonObjectFromDataPlaneInstanceV3Transformer(Json.createBuilderFactory(Map.of()), createObjectMapper());
}

@Test
void transform() {
var dpi = DataPlaneInstance.Builder.newInstance()
.id("test-id")
.url("http://foo.bar")
.allowedSourceType("test-source-type")
.allowedDestType("test-dest-type")
.allowedTransferType("test-transfer-type")
.lastActive(15)
.turnCount(42)
.property("foo", "bar")
.build();

var jsonObject = transformer.transform(dpi, context);

assertThat(jsonObject).isNotNull();
assertThat(jsonObject.getString(ID)).isEqualTo("test-id");
assertThat(jsonObject.getString(URL)).isEqualTo("http://foo.bar");
assertThat(jsonObject.getJsonArray(ALLOWED_SOURCE_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-source-type"));
assertThat(jsonObject.getJsonArray(ALLOWED_DEST_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-dest-type"));
assertThat(jsonObject.getJsonArray(ALLOWED_TRANSFER_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-transfer-type"));
assertThat(jsonObject.getJsonNumber(LAST_ACTIVE).intValue()).isEqualTo(15);
assertThat(jsonObject.getJsonNumber(TURN_COUNT).intValue()).isEqualTo(42);
assertThat(jsonObject.getJsonObject(PROPERTIES).getJsonString("foo").getString()).isEqualTo("bar");

}

@Test
void transform_withState() {
var dpi = DataPlaneInstance.Builder.newInstance()
.id("test-id")
.url("http://foo.bar")
.allowedSourceType("test-source-type")
.allowedDestType("test-dest-type")
.allowedTransferType("test-transfer-type")
.lastActive(15)
.turnCount(42)
.state(AVAILABLE.code())
.property("foo", "bar")
.build();

var jsonObject = transformer.transform(dpi, context);

assertThat(jsonObject).isNotNull();
assertThat(jsonObject.getString(ID)).isEqualTo("test-id");
assertThat(jsonObject.getString(URL)).isEqualTo("http://foo.bar");
assertThat(jsonObject.getJsonArray(ALLOWED_SOURCE_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-source-type"));
assertThat(jsonObject.getJsonArray(ALLOWED_DEST_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-dest-type"));
assertThat(jsonObject.getJsonArray(ALLOWED_TRANSFER_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-transfer-type"));
assertThat(jsonObject.getJsonNumber(LAST_ACTIVE).intValue()).isEqualTo(15);
assertThat(jsonObject.getJsonNumber(TURN_COUNT).intValue()).isEqualTo(42);
assertThat(jsonObject.getString(DATAPLANE_INSTANCE_STATE)).isEqualTo(AVAILABLE.name());
assertThat(jsonObject.getJsonNumber(DATAPLANE_INSTANCE_STATE_TIMESTAMP).longValue()).isEqualTo(dpi.getStateTimestamp());
assertThat(jsonObject.getJsonObject(PROPERTIES).getJsonString("foo").getString()).isEqualTo("bar");

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[
{
"version": "3.0.4",
"version": "3.0.5",
"urlPath": "/v3",
"lastUpdated": "2024-12-19T10:14:00Z",
"lastUpdated": "2025-01-08T14:26:00Z",
"maturity": "stable"
},
{
Expand All @@ -14,7 +14,7 @@
{
"version": "4.0.0-alpha",
"urlPath": "/v4alpha",
"lastUpdated": "2024-12-04T14:24:00Z",
"lastUpdated": "2025-01-08T14:26:00Z",
"maturity": "alpha"
}
]
2 changes: 1 addition & 1 deletion extensions/common/iam/oauth2/oauth2-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This BOM provides a ready-to-use version of the [Oauth2 IdentityService](../oaut
provided by the EDC.

> **_NOTE:_** Unless you are sure of what you are doing, you do not want to implement your own Oauth2 Client in most cases.
> This BOM should thus be considered as the standard and recommended approach of embedding the Oauth2 Identity Service into your runtime.
> This BOM should thus be considered as the standard and recommended approach of embedding the Oauth2 Identity Service into your runtime.
Loading
Loading