Skip to content

Commit

Permalink
build: fix compilation (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt authored Jan 23, 2025
1 parent 1374b14 commit 7cd7b53
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
package com.huawei.cloud.fixtures;

import com.fasterxml.jackson.annotation.JsonCreator;
import org.eclipse.edc.connector.controlplane.test.system.utils.LazySupplier;
import org.eclipse.edc.connector.controlplane.test.system.utils.Participant;
import org.eclipse.edc.spi.system.configuration.Config;
import org.eclipse.edc.spi.system.configuration.ConfigFactory;

import java.net.URI;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -30,30 +32,29 @@ public class HuaweiParticipant extends Participant {

private static final String IAM_OTC_CLOUD_URL = "https://iam.eu-de.otc.t-systems.com";

private static final Duration TIMEOUT = Duration.ofMillis(10000);
private Endpoint controlEndpoint;
private String apiKey;
private final LazySupplier<URI> controlEndpoint = new LazySupplier<>(() -> URI.create("http://localhost:" + getFreePort() + "/control"));

public Endpoint getControlEndpoint() {
return controlEndpoint;
public URI getControlEndpoint() {
return controlEndpoint.get();
}

public Map<String, String> controlPlaneConfiguration() {
return new HashMap<>() {
public Config controlPlaneConfig() {
var settings = (Map<String, String>) new HashMap<String, String>() {
{
put(PARTICIPANT_ID, id);
put("edc.api.auth.key", apiKey);
put("web.http.port", String.valueOf(getFreePort()));
put("web.http.path", "/api");
put("web.http.protocol.port", String.valueOf(protocolEndpoint.getUrl().getPort()));
put("web.http.protocol.path", protocolEndpoint.getUrl().getPath());
put("web.http.management.port", String.valueOf(managementEndpoint.getUrl().getPort()));
put("web.http.management.path", managementEndpoint.getUrl().getPath());
put("web.http.control.port", String.valueOf(controlEndpoint.getUrl().getPort()));
put("web.http.control.path", controlEndpoint.getUrl().getPath());
put("web.http.protocol.port", String.valueOf(controlPlaneProtocol.get().getPort()));
put("web.http.protocol.path", controlPlaneProtocol.get().getPath());
put("web.http.management.port", String.valueOf(controlPlaneManagement.get().getPort()));
put("web.http.management.path", controlPlaneManagement.get().getPath());
put("web.http.control.port", String.valueOf(controlEndpoint.get().getPort()));
put("web.http.control.path", controlEndpoint.get().getPath());
put("web.http.public.path", "/public");
put("web.http.public.port", String.valueOf(getFreePort()));
put("edc.dsp.callback.address", protocolEndpoint.getUrl().toString());
put("edc.dsp.callback.address", controlPlaneProtocol.get().toString());
put("edc.connector.name", name);
put("edc.component.id", "connector-test");
put("edc.dataplane.token.validation.endpoint", "http://token-validation.com");
Expand All @@ -63,6 +64,8 @@ public Map<String, String> controlPlaneConfiguration() {
put("edc.transfer.proxy.token.signer.privatekey.alias", "privatekey");
}
};

return ConfigFactory.fromMap(settings);
}

public static final class Builder extends Participant.Builder<HuaweiParticipant, Builder> {
Expand All @@ -83,11 +86,8 @@ public Builder apiKey(String apiKey) {

@Override
public HuaweiParticipant build() {
super.managementEndpoint(new Endpoint(URI.create("http://localhost:" + getFreePort() + "/api/management"), Map.of("X-Api-Key", participant.apiKey)));
super.protocolEndpoint(new Endpoint(URI.create("http://localhost:" + getFreePort() + "/protocol")));
super.build();
participant.controlEndpoint = new Endpoint(URI.create("http://localhost:" + getFreePort() + "/control"), Map.of());
return participant;
participant.enrichManagementRequest = request -> request.header("X-Api-Key", participant.apiKey);
return super.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,14 @@ public class ObsTransferEndToEndTest {
@RegisterExtension
static RuntimeExtension consumer = new RuntimePerClassExtension(new EmbeddedRuntime(
"consumer",
CONSUMER.controlPlaneConfiguration(),
":launchers:e2e-test"
));
).configurationProvider(CONSUMER::controlPlaneConfig));

@RegisterExtension
static RuntimeExtension provider = new RuntimePerClassExtension(new EmbeddedRuntime(
"provider",
PROVIDER.controlPlaneConfiguration(),
":launchers:e2e-test"
));
).configurationProvider(PROVIDER::controlPlaneConfig));

@Container
private final GenericContainer<?> providerContainer = new GenericContainer<>(MINIO_DOCKER_IMAGE)
Expand Down Expand Up @@ -142,7 +140,7 @@ void transfer_singleFile() throws IOException {
consumerClient.createBucket(destBucket);

var flowRequest = createFlowRequest(destBucket, consumerEndpoint, srcBucket, TESTFILE_NAME, providerEndpoint).build();
var url = PROVIDER.getControlEndpoint().getUrl().toString() + "/v1/dataflows";
var url = PROVIDER.getControlEndpoint() + "/v1/dataflows";

var startMessage = registry.transform(flowRequest, JsonObject.class).orElseThrow(failTest());

Expand Down Expand Up @@ -178,7 +176,7 @@ void transfer_multipleFilesWithPrefix() throws IOException {
consumerClient.createBucket(destBucket);

var flowRequest = createFlowRequest(destBucket, consumerEndpoint, srcBucket, "file", providerEndpoint).build();
var url = PROVIDER.getControlEndpoint().getUrl().toString() + "/v1/dataflows";
var url = PROVIDER.getControlEndpoint() + "/v1/dataflows";


var startMessage = registry.transform(flowRequest, JsonObject.class).orElseThrow(failTest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@
import com.huawei.cloud.obs.ObsClientProviderImpl;
import com.huawei.cloud.obs.OtcTest;
import com.obs.services.ObsClient;
import com.obs.services.model.ObsObject;
import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonValue;
import org.eclipse.edc.connector.controlplane.test.system.utils.Participant;
import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates;
import org.eclipse.edc.connector.dataplane.spi.Endpoint;
import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService;
import org.eclipse.edc.junit.extensions.EdcClassRuntimesExtension;
import org.eclipse.edc.junit.extensions.EdcRuntimeExtension;
import org.eclipse.edc.junit.extensions.EmbeddedRuntime;
import org.eclipse.edc.junit.extensions.RuntimeExtension;
import org.eclipse.edc.junit.extensions.RuntimePerClassExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -68,23 +67,16 @@ public class OtcTransferEndToEndTest {
private static final String OBS_OTC_CLOUD_URL = "https://obs.eu-de.otc.t-systems.com";


static EdcRuntimeExtension providerRuntime = new EdcRuntimeExtension(
":launchers:e2e-test",
"consumer",
CONSUMER.controlPlaneConfiguration()
);
static EmbeddedRuntime providerRuntime = new EmbeddedRuntime("consumer", ":launchers:e2e-test")
.configurationProvider(CONSUMER::controlPlaneConfig);

static EdcRuntimeExtension consumerRuntime = new EdcRuntimeExtension(
":launchers:e2e-test",
"provider",
PROVIDER.controlPlaneConfiguration()
);
static EmbeddedRuntime consumerRuntime = new EmbeddedRuntime("provider", ":launchers:e2e-test")
.configurationProvider(PROVIDER::controlPlaneConfig);

@RegisterExtension
static EdcClassRuntimesExtension runtimes = new EdcClassRuntimesExtension(
providerRuntime,
consumerRuntime
);
static RuntimeExtension provider = new RuntimePerClassExtension(providerRuntime);
@RegisterExtension
static RuntimeExtension consumer = new RuntimePerClassExtension(consumerRuntime);

private String id;
private String sourceBucket;
Expand All @@ -105,8 +97,8 @@ void setup() {
var consumerClientProviderImp = (ObsClientProviderImpl) consumerRuntime.getService(ObsClientProvider.class);
consumerClientProviderImp.getVault().storeSecret("publickey", PUBLIC_KEY);
consumerClientProviderImp.getVault().storeSecret("privatekey", PRIVATE_KEY);
var providerEndpointGeneratorService = (PublicEndpointGeneratorService) providerRuntime.getService(PublicEndpointGeneratorService.class);
var consumerEndpointGeneratorService = (PublicEndpointGeneratorService) consumerRuntime.getService(PublicEndpointGeneratorService.class);
var providerEndpointGeneratorService = providerRuntime.getService(PublicEndpointGeneratorService.class);
var consumerEndpointGeneratorService = consumerRuntime.getService(PublicEndpointGeneratorService.class);
var endpoint = new Endpoint("endpoint", "obs");
providerEndpointGeneratorService.addGeneratorFunction("HttpData", dataAddress1 -> endpoint);
consumerEndpointGeneratorService.addGeneratorFunction("HttpData", dataAddress1 -> endpoint);
Expand All @@ -132,7 +124,7 @@ void obsToObsTransfer() {
assertThat(TransferProcessStates.valueOf(state).code()).isGreaterThanOrEqualTo(COMPLETED.code());
});

List<ObsObject> consumerObsObjectList = consumerClient.listObjects(destBucket).getObjects();
var consumerObsObjectList = consumerClient.listObjects(destBucket).getObjects();
if (!consumerObsObjectList.isEmpty()) {
assertThat(consumerObsObjectList)
.allSatisfy(obsObject -> assertThat(obsObject.getObjectKey()).isEqualTo(TESTFILE_NAME));
Expand All @@ -146,8 +138,8 @@ void cleanup() {
}

private JsonObject getOfferForAsset(Participant provider, String assetId) {
JsonObject dataset = CONSUMER.getDatasetForAsset(provider, assetId);
JsonObject policy = ((JsonValue) dataset.getJsonArray("http://www.w3.org/ns/odrl/2/hasPolicy").get(0)).asJsonObject();
var dataset = CONSUMER.getDatasetForAsset(provider, assetId);
var policy = dataset.getJsonArray("http://www.w3.org/ns/odrl/2/hasPolicy").get(0).asJsonObject();
return Json.createObjectBuilder(policy).add("http://www.w3.org/ns/odrl/2/assigner", Json.createObjectBuilder().add("@id", provider.getId())).add("http://www.w3.org/ns/odrl/2/target", Json.createObjectBuilder().add("@id", (JsonValue) dataset.get("@id"))).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
@Provides(ObsClientProvider.class)
public class ObsCoreExtension implements ServiceExtension {

@Setting(value = "The key of the secret where the AWS Access Key Id is stored")
@Setting(description = "The key of the secret where the AWS Access Key Id is stored")
public static final String HUAWEI_ACCESS_KEY = "edc.huawei.obs.alias.ak";
@Setting(value = "The key of the secret where the AWS Secret Access Key is stored")
@Setting(description = "The key of the secret where the AWS Secret Access Key is stored")
public static final String HUAWEI_SECRET_KEY = "edc.huawei.obs.alias.sk";
@Setting(value = "If valued, the AWS clients will point to the specified endpoint")
@Setting(description = "If valued, the AWS clients will point to the specified endpoint")
public static final String HUAWEI_IAM_ENDPOINT = "edc.huawei.iam.endpoint";
protected static final String NAME = "OBS Core";
private ObsClientProvider clientProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ObsProvisionExtension implements ServiceExtension {

public static final String NAME = "OBS Provision";

@Setting(value = "Duration in seconds of the temporary token", defaultValue = "" + ObsProvisionExtension.PROVISIONER_DEFAULT_TOKEN_DURATION)
@Setting(description = "Duration in seconds of the temporary token", defaultValue = "" + ObsProvisionExtension.PROVISIONER_DEFAULT_TOKEN_DURATION)
private static final String PROVISION_TOKEN_DURATION = "edc.obs.provision.token.duration";

private static final int PROVISIONER_DEFAULT_TOKEN_DURATION = 60 * 30;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,6 @@ void findById_notExist() {
assertThat(getContractNegotiationStore().findById("not-exist")).isNull();
}

@Test
@DisplayName("Find entity by its correlation ID")
void findForCorrelationId() {
var negotiation = createNegotiation("test-cn1");
getContractNegotiationStore().save(negotiation);

assertThat(getContractNegotiationStore().findForCorrelationId(negotiation.getCorrelationId()))
.usingRecursiveComparison()
.isEqualTo(negotiation);
}

@Test
@DisplayName("Find ContractAgreement by contract ID")
void findContractAgreement() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.edc.connector.dataplane.selector.store.sql.SqlDataPlaneInstanceStore;
import org.eclipse.edc.connector.dataplane.selector.store.sql.schema.DataPlaneInstanceStatements;
import org.eclipse.edc.connector.dataplane.selector.store.sql.schema.postgres.PostgresDataPlaneInstanceStatements;
import org.eclipse.edc.spi.types.domain.DataAddress;
import org.eclipse.edc.sql.QueryExecutor;
import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry;
import org.eclipse.edc.transaction.spi.TransactionContext;
Expand All @@ -39,7 +38,6 @@

import static com.huawei.cloud.gaussdb.testfixtures.GaussDbTestExtension.DEFAULT_DATASOURCE_NAME;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.spi.result.StoreFailure.Reason.ALREADY_EXISTS;

@GaussDbTest
@ExtendWith(GaussDbTestExtension.class)
Expand All @@ -59,7 +57,7 @@ static void deleteTable(GaussDbTestExtension.SqlHelper runner) {

@BeforeEach
void setup(GaussDbTestExtension.SqlHelper runner, TransactionContext transactionContext, QueryExecutor queryExecutor, DataSourceRegistry reg, Clock clock) {
String lease = "lease";
var lease = "lease";
dataPlaneInstanceStore = new SqlDataPlaneInstanceStore(reg, DEFAULT_DATASOURCE_NAME, transactionContext, SQL_STATEMENTS, new ObjectMapper(), queryExecutor, clock, lease);

runner.truncateTable("edc_data_plane_instance");
Expand All @@ -68,42 +66,22 @@ void setup(GaussDbTestExtension.SqlHelper runner, TransactionContext transaction
@Test
void save() {
var inst = TestFunctions.createInstance("test-id");
getStore().create(inst);
getStore().save(inst);
assertThat(getStore().getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly(inst);
}

@Test
void save_whenExists_shouldNotUpsert() {
var inst = TestFunctions.createInstance("test-id");
getStore().create(inst);

var inst2 = DataPlaneInstance.Builder.newInstance()
.id("test-id")
.url("http://somewhere.other:9876/api/v2") //different URL
.build();

var result = getStore().create(inst2);

assertThat(result.failed()).isTrue();
assertThat(result.getFailure().getReason()).isEqualTo(ALREADY_EXISTS);

assertThat(getStore().getAll()).hasSize(1).usingRecursiveFieldByFieldElementComparator().containsExactly(inst);
}

@Test
void update_whenExists_shouldUpdate() {
var inst = TestFunctions.createInstance("test-id");
getStore().create(inst);
getStore().save(inst);


var inst2 = DataPlaneInstance.Builder.newInstance()
.id("test-id")
.url("http://somewhere.other:9876/api/v2") //different URL
.build();

var result = getStore().update(inst2);

assertThat(result.succeeded()).isTrue();
getStore().save(inst2);

assertThat(getStore().getAll()).hasSize(1).usingRecursiveFieldByFieldElementComparator().containsExactly(inst2);
}
Expand All @@ -112,7 +90,7 @@ void update_whenExists_shouldUpdate() {
void save_shouldReturnCustomInstance() {
var custom = TestFunctions.createCustomInstance("test-id", "name");

getStore().create(custom);
getStore().save(custom);

var customInstance = getStore().findById(custom.getId());

Expand All @@ -126,7 +104,7 @@ void save_shouldReturnCustomInstance() {
@Test
void findById() {
var inst = TestFunctions.createInstance("test-id");
getStore().create(inst);
getStore().save(inst);

assertThat(getStore().findById("test-id")).usingRecursiveComparison().isEqualTo(inst);
}
Expand All @@ -143,8 +121,8 @@ void getAll() {

var store = getStore();

store.create(doc1);
store.create(doc2);
store.save(doc1);
store.save(doc2);

var foundItems = store.getAll();

Expand All @@ -159,10 +137,6 @@ public class TestFunctions {
TestFunctions() {
}

public static DataAddress createAddress(String type) {
return DataAddress.Builder.newInstance().type("test-type").keyName(type).property("someprop", "someval").build();
}

public static DataPlaneInstance createInstance(String id) {
return org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.Builder.newInstance().id(id).url("http://somewhere.com:1234/api/v1").build();
}
Expand All @@ -172,4 +146,4 @@ public static DataPlaneInstance createCustomInstance(String id, String name) {
}
}

}
}

0 comments on commit 7cd7b53

Please sign in to comment.