From 15aa240232dda21509770f6b196bf1bd43493482 Mon Sep 17 00:00:00 2001 From: Pawel Sosnowski Date: Tue, 9 Jan 2024 11:22:16 +0100 Subject: [PATCH 1/3] feat(irs):[#256] added documentation --- .../arc42/cross-cutting/under-the-hood.adoc | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/src/docs/arc42/cross-cutting/under-the-hood.adoc b/docs/src/docs/arc42/cross-cutting/under-the-hood.adoc index 6dc27f9daf..fba7669989 100644 --- a/docs/src/docs/arc42/cross-cutting/under-the-hood.adoc +++ b/docs/src/docs/arc42/cross-cutting/under-the-hood.adoc @@ -108,3 +108,46 @@ When the EDC Discovery is requested to return the EDC connector endpoint URLs fo The time to live for both caches can be configured separately as described in the Administration Guide. Further information on Discovery Service can be found in the chapter "System scope and context". + +=== EDC + +EndpointDataReferenceStorage is in-memory local storage that holds records (EndpointDataReferences) by either assetId or contractAgreementId. + +When EDC gets EndpointDataReference describing endpoint serving data it uses EndpointDataReferenceStorage and query it by assetId. +This allows reuse of already existing EndpointDataReference if it is present, valid, and it's token is not expired, +rather than starting whole new contract negotiation process. + +In case token is expired the process is also shortened. We don't have to start new contract negotiation process, +since we can obtain required contractAgreementId from present authKey. This improves request processing time. + +[source, mermaid] +.... +sequenceDiagram + autonumber + participant EdcSubmodelClient + participant ContractNegotiationService + participant EndpointDataReferenceStorage + participant EdcCallbackController + participant EdcDataPlaneClient + EdcSubmodelClient ->> EndpointDataReferenceStorage: Get EDR Token for EDC asset id + EndpointDataReferenceStorage ->> EdcSubmodelClient: Return Optional + alt Token is present and not expired + EdcSubmodelClient ->> EdcSubmodelClient: Optional.get + else + alt Token is expired + EdcSubmodelClient ->> ContractNegotiationService: Renew EDR Token based on existing Token + else Token is not present + EdcSubmodelClient ->> ContractNegotiationService: Negotiate new EDR Token + end + ContractNegotiationService -->> EdcCallbackController: EDC flow + EdcCallbackController ->> EndpointDataReferenceStorage: Store EDR token by EDC asset id after EDC callback + loop While EDR Token is not present + EdcSubmodelClient ->> EndpointDataReferenceStorage: Poll for EDR Token + end + EndpointDataReferenceStorage ->> EdcSubmodelClient: Return EDR Token + end + EdcSubmodelClient ->> EdcDataPlaneClient: Get data(EDR Token, Dataplane URL) + EdcDataPlaneClient ->> EdcSubmodelClient: Return data +.... + + From bcda2e2d2077f767b4bb0a489ba17bb8346ee603 Mon Sep 17 00:00:00 2001 From: Pawel Sosnowski Date: Wed, 10 Jan 2024 12:41:09 +0100 Subject: [PATCH 2/3] feat(irs):[#256] fixed problem with parsing authCode --- .../irs/edc/client/ContractNegotiationService.java | 7 ++++--- .../tractusx/irs/edc/client/EdcSubmodelClientImpl.java | 8 ++++---- .../irs/edc/client/ContractNegotiationServiceTest.java | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java index 344cd039a8..231c7792bf 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationService.java @@ -94,11 +94,12 @@ public NegotiationResponse negotiate(final String providerConnectorUrl, final Ca contractAgreementId = negotiationResponse.getContractAgreementId(); } case EXPIRED -> { - final String authKey = resultEndpointDataReferenceStatus.endpointDataReference().getAuthKey(); - if (authKey == null) { + final String authCode = resultEndpointDataReferenceStatus.endpointDataReference().getAuthCode(); + if (authCode == null) { throw new IllegalStateException("Missing information about AuthKey."); } - contractAgreementId = EDRAuthCode.fromAuthCodeToken(authKey).getCid(); + log.error("AuthCode to be parsed: " + authCode); + contractAgreementId = EDRAuthCode.fromAuthCodeToken(authCode).getCid(); log.info( "Cached endpoint data reference has expired token. Refreshing token without new contract negotiation for contractAgreementId: {}", Masker.mask(contractAgreementId)); diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java index eabf6315cd..703a2b1a50 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcSubmodelClientImpl.java @@ -234,11 +234,11 @@ private static String getStorageId(final EndpointDataReferenceStatus endpointDat if (response != null) { storageId = response.getContractAgreementId(); } else { - final String authKey = endpointDataReferenceStatus.endpointDataReference().getAuthKey(); - if (authKey == null) { - throw new IllegalStateException("Missing information about AuthKey."); + final String authCode = endpointDataReferenceStatus.endpointDataReference().getAuthCode(); + if (authCode == null) { + throw new IllegalStateException("Missing information about AuthCode."); } - storageId = EDRAuthCode.fromAuthCodeToken(authKey).getCid(); + storageId = EDRAuthCode.fromAuthCodeToken(authCode).getCid(); } return storageId; } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationServiceTest.java index 2748e84e0c..7c352dc529 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/ContractNegotiationServiceTest.java @@ -226,11 +226,11 @@ void shouldNotStartNewNegotiationWhenTokenIsExpired() Response.builder().responseId("transferProcessId").build()); when(edcControlPlaneClient.getTransferProcess(any())).thenReturn( CompletableFuture.completedFuture(TransferProcessResponse.builder().build())); - final String encodedAuthKey = "eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjE3MDA3NDc0NjMsImRhZCI6IkFXanRhclZySVdtaVE4V1R4VGV2YVhUS1p5SERUZ3pkWG1oMWpkdTR3QUxkTTZVaEgyVHVCOXhhS2Z6TmJQQTZVQVhnVDc2NytPMTgwUXltMGNFdks0NGxzakZQbkROTFQwO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ndpointDataReference.Builder.newInstance().authKey(encodedAuthKey).endpoint("").authCode("").build(), + EndpointDataReference.Builder.newInstance().authKey("").authCode(encodedAuthCode).endpoint("").build(), EndpointDataReferenceStatus.TokenStatus.EXPIRED)); // then From 5b47b1a9897fb7bb1f838c28cdc45198925fd54f Mon Sep 17 00:00:00 2001 From: Pawel Sosnowski Date: Wed, 10 Jan 2024 12:59:39 +0100 Subject: [PATCH 3/3] feat(irs):[#256] fixed documentation typo --- docs/src/docs/arc42/cross-cutting/under-the-hood.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/docs/arc42/cross-cutting/under-the-hood.adoc b/docs/src/docs/arc42/cross-cutting/under-the-hood.adoc index fba7669989..aaa8440e10 100644 --- a/docs/src/docs/arc42/cross-cutting/under-the-hood.adoc +++ b/docs/src/docs/arc42/cross-cutting/under-the-hood.adoc @@ -118,7 +118,7 @@ This allows reuse of already existing EndpointDataReference if it is present, va rather than starting whole new contract negotiation process. In case token is expired the process is also shortened. We don't have to start new contract negotiation process, -since we can obtain required contractAgreementId from present authKey. This improves request processing time. +since we can obtain required contractAgreementId from present authCode. This improves request processing time. [source, mermaid] ....