Skip to content

Commit

Permalink
chore: upgrade to EDC 0.4.1 (#877)
Browse files Browse the repository at this point in the history
* chore: upgrade to EDC 0.4.0

* DEPENDENCIES

* fix tests

* fix sql migration, fix tests

* fix dataplane tests

* DEPENDENCIES
  • Loading branch information
paullatzelsperger authored Nov 21, 2023
1 parent 4264ca4 commit c8e9675
Show file tree
Hide file tree
Showing 70 changed files with 602 additions and 498 deletions.
389 changes: 197 additions & 192 deletions DEPENDENCIES

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void verify_serializeDeserialize() throws JsonProcessingException {
.endpoint("http://test.com")
.id(randomUUID().toString())
.authCode("11111")
.contractId("test-contract-id")
.authKey("authentication").build();

var edrEntry = EndpointDataReferenceEntry.Builder.newInstance()
Expand Down
1 change: 0 additions & 1 deletion core/edr-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ dependencies {
implementation(libs.edc.spi.core)
implementation(libs.edc.config.filesystem)
implementation(libs.edc.util)
implementation(libs.edc.spi.aggregateservices)
implementation(libs.edc.spi.contract)
implementation(libs.edc.spi.controlplane)
implementation(libs.edc.statemachine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.eclipse.edc.spi.system.ExecutorInstrumentation;
import org.eclipse.edc.spi.telemetry.Telemetry;
import org.eclipse.edc.spi.types.domain.callback.CallbackAddress;
import org.eclipse.edc.statemachine.ProcessorImpl;
import org.eclipse.edc.statemachine.StateMachineManager;
import org.eclipse.edc.statemachine.StateProcessorImpl;
import org.eclipse.edc.statemachine.retry.EntityRetryProcessConfiguration;
import org.eclipse.edc.statemachine.retry.EntityRetryProcessFactory;
import org.eclipse.tractusx.edc.edr.spi.EdrManager;
Expand All @@ -44,9 +44,11 @@
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.Collection;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -148,19 +150,25 @@ private void update(EndpointDataReferenceEntry edrEntry) {
}


private StateProcessorImpl<EndpointDataReferenceEntry> processEdrInState(EndpointDataReferenceEntryStates state, Function<EndpointDataReferenceEntry, Boolean> function) {
private ProcessorImpl<EndpointDataReferenceEntry> processEdrInState(EndpointDataReferenceEntryStates state, Function<EndpointDataReferenceEntry, Boolean> function) {
var filter = new Criterion[] {hasState(state.code())};
return new StateProcessorImpl<>(() -> edrCache.nextNotLeased(batchSize, filter), telemetry.contextPropagationMiddleware(function));
return processor(() -> edrCache.nextNotLeased(batchSize, filter), telemetry.contextPropagationMiddleware(function));
}

private ProcessorImpl<EndpointDataReferenceEntry> processor(Supplier<Collection<EndpointDataReferenceEntry>> o, Function<EndpointDataReferenceEntry, Boolean> telemetryPropagationFunction) {
return ProcessorImpl.Builder.newInstance(o)
.process(telemetryPropagationFunction)
.build();
}

private StateProcessorImpl<EndpointDataReferenceEntry> processDeletingEdr(Function<EndpointDataReferenceEntry, Boolean> function) {

private ProcessorImpl<EndpointDataReferenceEntry> processDeletingEdr(Function<EndpointDataReferenceEntry, Boolean> function) {
var query = QuerySpec.Builder.newInstance()
.filter(hasState(DELETING.code()))
.limit(batchSize)
.build();

return new StateProcessorImpl<>(() -> edrCache.queryForEntries(query).collect(Collectors.toList()), telemetry.contextPropagationMiddleware(function));
return processor(() -> edrCache.queryForEntries(query).collect(Collectors.toList()), telemetry.contextPropagationMiddleware(function));
}

private ContractRequest createContractRequest(NegotiateEdrRequest request) {
Expand Down Expand Up @@ -190,7 +198,7 @@ private boolean processNegotiated(EndpointDataReferenceEntry edrEntry) {
}

private boolean processExpired(EndpointDataReferenceEntry edrEntry) {
return entityRetryProcessFactory.doSimpleProcess(edrEntry, () -> checkExpiration(edrEntry))
return entityRetryProcessFactory.doSyncProcess(edrEntry, () -> checkExpiration(edrEntry))
.onDelay(this::breakLease)
.execute("Start EDR token deletion check");

Expand All @@ -208,13 +216,13 @@ private boolean processDeleting(EndpointDataReferenceEntry edrEntry) {
.execute("Start EDR token deletion");
}

private boolean checkExpiration(EndpointDataReferenceEntry entry) {
private StatusResult<Void> checkExpiration(EndpointDataReferenceEntry entry) {
if (shouldBeRemoved(entry)) {
transitionToDeleting(entry);
return true;
return StatusResult.success();
} else {
breakLease(entry);
return false;
return StatusResult.failure(ResponseStatus.ERROR_RETRY, "Not yet expired.");
}
}

Expand Down Expand Up @@ -242,7 +250,7 @@ private StatusResult<Void> fireTransferProcess(EndpointDataReferenceEntry entry)
.connectorId(dataRequest.getConnectorId())
.contractId(dataRequest.getContractId())
.protocol(dataRequest.getProtocol())
.connectorAddress(dataRequest.getConnectorAddress())
.counterPartyAddress(dataRequest.getConnectorAddress())
.dataDestination(dataRequest.getDataDestination())
.callbackAddresses(transferProcess.getCallbackAddresses())
.build();
Expand Down Expand Up @@ -294,10 +302,6 @@ private Builder() {
edrManager = new EdrManagerImpl();
}

public static Builder newInstance() {
return new Builder();
}

public Builder contractNegotiationService(ContractNegotiationService negotiationService) {
edrManager.contractNegotiationService = negotiationService;
return this;
Expand Down Expand Up @@ -369,5 +373,9 @@ public EdrManagerImpl build() {

return edrManager;
}

public static Builder newInstance() {
return new Builder();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package org.eclipse.tractusx.edc.edr.core.service;

import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation;
import org.eclipse.edc.service.spi.result.ServiceResult;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.spi.result.ServiceResult;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.tractusx.edc.edr.spi.EdrManager;
import org.eclipse.tractusx.edc.edr.spi.service.EdrService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package org.eclipse.tractusx.edc.edr.core.fixtures;

import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation;
import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.types.domain.callback.CallbackAddress;
import org.eclipse.edc.spi.types.domain.offer.ContractOffer;
import org.eclipse.tractusx.edc.edr.spi.types.NegotiateEdrRequest;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import org.eclipse.edc.connector.transfer.spi.types.ProvisionedResourceSet;
import org.eclipse.edc.connector.transfer.spi.types.TransferProcess;
import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates;
import org.eclipse.edc.service.spi.result.ServiceResult;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.query.Criterion;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.spi.result.ServiceResult;
import org.eclipse.edc.spi.result.StoreResult;
import org.eclipse.tractusx.edc.edr.spi.store.EndpointDataReferenceCache;
import org.eclipse.tractusx.edc.edr.spi.types.EndpointDataReferenceEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
package org.eclipse.tractusx.edc.edr.core.service;

import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation;
import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.service.spi.result.ServiceFailure;
import org.eclipse.edc.service.spi.result.ServiceResult;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.spi.response.StatusResult;
import org.eclipse.edc.spi.result.ServiceFailure;
import org.eclipse.edc.spi.result.ServiceResult;
import org.eclipse.edc.spi.result.StoreResult;
import org.eclipse.edc.spi.types.domain.callback.CallbackAddress;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.edc.spi.types.domain.offer.ContractOffer;
import org.eclipse.tractusx.edc.edr.spi.EdrManager;
import org.eclipse.tractusx.edc.edr.spi.store.EndpointDataReferenceCache;
import org.eclipse.tractusx.edc.edr.spi.types.NegotiateEdrRequest;
Expand All @@ -36,6 +36,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -71,7 +72,12 @@ void findByTransferProcessId_shouldReturnTheEdr_whenFoundInCache() {

var transferProcessId = "tpId";

when(endpointDataReferenceCache.resolveReference(transferProcessId)).thenReturn(EndpointDataReference.Builder.newInstance().endpoint("test").build());
when(endpointDataReferenceCache.resolveReference(eq(transferProcessId)))
.thenReturn(EndpointDataReference.Builder.newInstance()
.id("test-id")
.contractId("test-contract")
.endpoint("test")
.build());

var result = transferService.findByTransferProcessId(transferProcessId);

Expand Down Expand Up @@ -115,7 +121,7 @@ void deleteByTransferProcessId() {
void deleteByTransferProcessId_shouldNotFound_whenNotPresentInCache() {
var transferProcessId = "tpId";

when(endpointDataReferenceCache.deleteByTransferProcessId(transferProcessId)).thenReturn(StoreResult.notFound(""));
when(endpointDataReferenceCache.deleteByTransferProcessId(eq(transferProcessId))).thenReturn(StoreResult.notFound(""));

var result = transferService.deleteByTransferProcessId(transferProcessId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class JsonLdExtension implements ServiceExtension {
public void initialize(ServiceExtensionContext context) {
jsonLdService.registerNamespace(TX_PREFIX, TX_NAMESPACE);
FILES.entrySet().stream().map(this::mapToFile)
.forEach(result -> result.onSuccess(entry -> jsonLdService.registerCachedDocument(entry.getKey(), entry.getValue()))
.forEach(result -> result.onSuccess(entry -> jsonLdService.registerCachedDocument(entry.getKey(), entry.getValue().toURI()))
.onFailure(failure -> monitor.warning("Failed to register cached json-ld document: " + failure.getFailureDetail())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dependencies {
implementation(project(":edc-extensions:bpn-validation:bpn-validation-spi"))
implementation(project(":spi:core-spi"))
implementation(libs.edc.api.management)
implementation(libs.edc.spi.aggregateservices)
implementation(libs.jakarta.rsApi)

testImplementation(testFixtures(libs.edc.core.jersey))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

package org.eclipse.tractusx.edc.validation.businesspartner.functions.legacy;

import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement;
import org.eclipse.edc.policy.engine.spi.PolicyContext;
import org.eclipse.edc.policy.model.Operator;
import org.eclipse.edc.spi.agent.ParticipantAgent;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.types.domain.agreement.ContractAgreement;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
Expand Down Expand Up @@ -65,21 +65,6 @@ protected AbstractBusinessPartnerValidation(Monitor monitor, boolean logAgreemen
this.logAgreementEvaluation = logAgreementEvaluation;
}

/**
* At the time of writing (11. April 2022) the business partner number is part of the
* 'referringConnector' claim, which contains a connector URL. As the CX projects are not further
* aligned about the URL formatting, the enforcement can only be done by checking whether the URL
* _contains_ the number. As this introduces some insecurities when validation business partner
* numbers, this should be addresses in the long term.
*
* @param referringConnectorClaim describing URL with business partner number
* @param businessPartnerNumber of the constraint
* @return true if claim contains the business partner number
*/
private static boolean isCorrectBusinessPartner(String referringConnectorClaim, String businessPartnerNumber) {
return referringConnectorClaim.contains(businessPartnerNumber);
}

public boolean isLogAgreementEvaluation() {
return logAgreementEvaluation;
}
Expand Down Expand Up @@ -128,6 +113,21 @@ public boolean evaluate(Operator operator, Object rightValue, PolicyContext poli
}
}

/**
* At the time of writing (11. April 2022) the business partner number is part of the
* 'referringConnector' claim, which contains a connector URL. As the CX projects are not further
* aligned about the URL formatting, the enforcement can only be done by checking whether the URL
* _contains_ the number. As this introduces some insecurities when validation business partner
* numbers, this should be addresses in the long term.
*
* @param referringConnectorClaim describing URL with business partner number
* @param businessPartnerNumber of the constraint
* @return true if claim contains the business partner number
*/
private static boolean isCorrectBusinessPartner(String referringConnectorClaim, String businessPartnerNumber) {
return referringConnectorClaim.contains(businessPartnerNumber);
}

@Nullable
private String getReferringConnectorClaim(ParticipantAgent participantAgent) {
String referringConnectorClaim = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

package org.eclipse.tractusx.edc.validation.businesspartner.functions;

import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement;
import org.eclipse.edc.policy.engine.spi.PolicyContext;
import org.eclipse.edc.policy.model.Operator;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.agent.ParticipantAgent;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.types.domain.agreement.ContractAgreement;
import org.eclipse.tractusx.edc.validation.businesspartner.functions.legacy.AbstractBusinessPartnerValidation;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ plugins {
dependencies {
implementation(project(":spi:core-spi"))
api(libs.edc.spi.core)
api(libs.edc.spi.aggregateservices)
implementation(libs.edc.spi.policy)
implementation(libs.edc.spi.contract)
implementation(libs.edc.spi.policyengine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.edc.policy.engine.spi.PolicyContext;
import org.eclipse.edc.policy.model.Operator;
import org.eclipse.edc.policy.model.Permission;
import org.eclipse.edc.spi.agent.ParticipantAgent;
import org.eclipse.tractusx.edc.policy.cx.common.AbstractVpConstraintFunction;

import java.util.Objects;
Expand Down Expand Up @@ -70,7 +71,7 @@ public boolean evaluate(Operator operator, Object rightValue, Permission permiss
return false;
}

var vp = (JsonObject) context.getParticipantAgent().getClaims().get(VP_PROPERTY);
var vp = (JsonObject) context.getContextData(ParticipantAgent.class).getClaims().get(VP_PROPERTY);
if (!validatePresentation(vp, context)) {
return false;
}
Expand Down Expand Up @@ -139,16 +140,6 @@ private Builder(String credentialType) {
constraint = new FrameworkAgreementConstraintFunction(credentialType);
}

/**
* Ctor.
*
* @param credentialType the framework credential type required by the constraint instance.
* @return the builder
*/
public static Builder newInstance(String credentialType) {
return new Builder(credentialType);
}

/**
* Sets the framework agreement type.
*/
Expand All @@ -169,6 +160,16 @@ public FrameworkAgreementConstraintFunction build() {
requireNonNull(constraint.agreementType, "agreementType");
return constraint;
}

/**
* Ctor.
*
* @param credentialType the framework credential type required by the constraint instance.
* @return the builder
*/
public static Builder newInstance(String credentialType) {
return new Builder(credentialType);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.edc.policy.engine.spi.PolicyContext;
import org.eclipse.edc.policy.model.Operator;
import org.eclipse.edc.policy.model.Permission;
import org.eclipse.edc.spi.agent.ParticipantAgent;
import org.eclipse.tractusx.edc.iam.ssi.spi.jsonld.CredentialsNamespaces;
import org.eclipse.tractusx.edc.policy.cx.common.AbstractVpConstraintFunction;

Expand Down Expand Up @@ -65,7 +66,7 @@ public boolean evaluate(Operator operator, Object rightValue, Permission rule, P
return false;
}

var vp = (JsonObject) context.getParticipantAgent().getClaims().get(VP_PROPERTY);
var vp = (JsonObject) context.getContextData(ParticipantAgent.class).getClaims().get(VP_PROPERTY);
if (!validatePresentation(vp, context)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void verify_no_credential_fail() {
.agreementType("PcfAgreement")
.build();

when(context.getParticipantAgent()).thenReturn(new ParticipantAgent(Map.of(), Map.of()));
when(context.getContextData(ParticipantAgent.class)).thenReturn(new ParticipantAgent(Map.of(), Map.of()));

var result = function.evaluate(EQ, "active", permission, context);

Expand All @@ -135,7 +135,7 @@ void setUp() {

private void setVpInContextVp() throws JsonProcessingException {
var vp = expand(createObjectMapper().readValue(PCF_VP, JsonObject.class), CONTEXT_CACHE);
when(context.getParticipantAgent()).thenReturn(new ParticipantAgent(Map.of(VP_PROPERTY, vp), Map.of()));
when(context.getContextData(ParticipantAgent.class)).thenReturn(new ParticipantAgent(Map.of(VP_PROPERTY, vp), Map.of()));
}


Expand Down
Loading

0 comments on commit c8e9675

Please sign in to comment.