Skip to content

Commit

Permalink
Merge pull request #60 from carlos-schmidt/edc-v0.4.1
Browse files Browse the repository at this point in the history
EDC v0.4.1
  • Loading branch information
carlos-schmidt authored Nov 27, 2023
2 parents 69acebd + 243d09a commit cb2d28f
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 40 deletions.
3 changes: 3 additions & 0 deletions edc-extension4aas/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ dependencies {
implementation("$group:dsp-catalog-http-dispatcher:$edcVersion")
implementation("$group:management-api:$edcVersion")
implementation("$group:runtime-metamodel:$edcVersion")
implementation("$group:data-plane-http-spi:$edcVersion") // HttpDataAddress


implementation("com.squareup.okhttp3:okhttp:${okHttpVersion}")
implementation("de.fraunhofer.iosb.ilt.faaast.service:starter:${faaastVersion}")
implementation("io.admin-shell.aas:dataformat-json:1.2.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,41 @@
*/
package de.fraunhofer.iosb.app.client;

import static java.lang.String.format;
import static org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP;

import java.net.URL;
import java.util.Objects;
import java.util.concurrent.ExecutionException;

import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest;
import org.eclipse.edc.connector.dataplane.http.spi.HttpDataAddress;
import org.eclipse.edc.connector.policy.spi.PolicyDefinition;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.types.domain.agreement.ContractAgreement;
import org.eclipse.edc.spi.types.domain.offer.ContractOffer;

import de.fraunhofer.iosb.app.Logger;
import de.fraunhofer.iosb.app.client.contract.PolicyService;
import de.fraunhofer.iosb.app.client.dataTransfer.TransferInitiator;
import de.fraunhofer.iosb.app.client.negotiation.Negotiator;
import de.fraunhofer.iosb.app.util.Pair;
import jakarta.ws.rs.*;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest;
import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer;
import org.eclipse.edc.connector.policy.spi.PolicyDefinition;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.types.domain.HttpDataAddress;

import java.net.URL;
import java.util.Objects;
import java.util.concurrent.ExecutionException;

import static java.lang.String.format;
import static org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP;

/**
* Automated contract negotiation
*/
@Consumes({MediaType.APPLICATION_JSON, MediaType.WILDCARD})
@Produces({MediaType.APPLICATION_JSON})
@Consumes({ MediaType.APPLICATION_JSON, MediaType.WILDCARD })
@Produces({ MediaType.APPLICATION_JSON })
@Path(ClientEndpoint.AUTOMATED_PATH)
public class ClientEndpoint {

Expand All @@ -65,22 +73,25 @@ public class ClientEndpoint {
/**
* Initialize a client endpoint.
*
* @param policyService Finds out policy for a given asset id and provider EDC url.
* @param policyService Finds out policy for a given asset id and provider
* EDC url.
* @param negotiator Send contract offer, negotiation status watch.
* @param transferInitiator Initiate transfer requests.
*/
public ClientEndpoint(PolicyService policyService,
Negotiator negotiator,
TransferInitiator transferInitiator) {
Negotiator negotiator,
TransferInitiator transferInitiator) {
this.policyService = policyService;
this.negotiator = negotiator;
this.transferInitiator = transferInitiator;
}

/**
* Negotiate a contract with a provider edc.
* WARNING: By initiating this request, any policy provided by the provider for the specified asset will be sent
* as a contract offer unmodified if edc.aas.client.acceptAllProviderOffers is set to true.
* WARNING: By initiating this request, any policy provided by the provider for
* the specified asset will be sent
* as a contract offer unmodified if edc.aas.client.acceptAllProviderOffers is
* set to true.
*
* @param providerUrl Provider EDCs URL (IDS endpoint)
* @param assetId ID of the asset to be retrieved
Expand All @@ -89,9 +100,9 @@ public ClientEndpoint(PolicyService policyService,
@POST
@Path(NEGOTIATE_PATH)
public Response negotiateContract(@QueryParam("providerUrl") URL providerUrl,
@QueryParam("providerId") String providerId,
@QueryParam("assetId") String assetId,
@QueryParam("dataDestinationUrl") URL dataDestinationUrl) {
@QueryParam("providerId") String providerId,
@QueryParam("assetId") String assetId,
@QueryParam("dataDestinationUrl") URL dataDestinationUrl) {
LOGGER.debug(format("Received a %s POST request", NEGOTIATE_PATH));
Objects.requireNonNull(providerUrl, "Provider URL must not be null");
Objects.requireNonNull(assetId, "Asset ID must not be null");
Expand Down Expand Up @@ -142,7 +153,7 @@ public Response negotiateContract(@QueryParam("providerUrl") URL providerUrl,
@GET
@Path(DATASET_PATH)
public Response getDataset(@QueryParam("providerUrl") URL providerUrl,
@QueryParam("assetId") String assetId) {
@QueryParam("assetId") String assetId) {
if (Objects.isNull(providerUrl)) {
return Response.status(Response.Status.BAD_REQUEST).entity("Provider URL must not be null").build();
}
Expand Down Expand Up @@ -173,8 +184,10 @@ public Response negotiateContract(ContractRequest contractRequest) {
var agreement = negotiator.negotiate(contractRequest);
return Response.ok(agreement).build();
} catch (InterruptedException | ExecutionException negotiationException) {
LOGGER.error(format("Negotiation failed for provider %s and contractRequest %s", contractRequest.getProviderId(),
contractRequest.getContractOffer().getId()), negotiationException);
LOGGER.error(
format("Negotiation failed for provider %s and contractRequest %s", contractRequest.getProviderId(),
contractRequest.getContractOffer().getId()),
negotiationException);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(negotiationException.getMessage())
.build();
}
Expand All @@ -187,13 +200,13 @@ public Response negotiateContract(ContractRequest contractRequest) {
* @param agreementId The basis of the data transfer.
* @param assetId The asset of which the data should be transferred
* @return On success, the data of the desired asset. Else, returns an error
* message.
* message.
*/
@GET
@Path(TRANSFER_PATH)
public Response getData(@QueryParam("providerUrl") URL providerUrl,
@QueryParam("agreementId") String agreementId, @QueryParam("assetId") String assetId,
@QueryParam("dataDestinationUrl") URL dataDestinationUrl) {
@QueryParam("agreementId") String agreementId, @QueryParam("assetId") String assetId,
@QueryParam("dataDestinationUrl") URL dataDestinationUrl) {
Objects.requireNonNull(providerUrl, "providerUrl must not be null");
Objects.requireNonNull(agreementId, "agreementId must not be null");
Objects.requireNonNull(assetId, "assetId must not be null");
Expand Down Expand Up @@ -221,12 +234,14 @@ public Response getData(@QueryParam("providerUrl") URL providerUrl,
}

/**
* Add policyDefinitions to the 'accepted list'. These policies or any other stored
* Add policyDefinitions to the 'accepted list'. These policies or any other
* stored
* policy must be matched on automated contract negotiation.
* This means, any policyDefinition by a provider must have the same rules
* as any of the stored policyDefinitions.
*
* @param policyDefinitions The policyDefinitions to add (Only their rules are relevant)
* @param policyDefinitions The policyDefinitions to add (Only their rules are
* relevant)
* @return OK as response.
*/
@POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public CompletableFuture<String> initiateTransferProcess(URL providerUrl, String

var transferRequest = TransferRequest.Builder.newInstance()
.id(UUID.randomUUID().toString()) // this is not relevant, thus can be random
.connectorAddress(providerUrl.toString()) // the address of the provider connector
.connectorId(providerUrl.toString()) // the address of the provider connector
.protocol(DATASPACE_PROTOCOL_HTTP)
.connectorId("consumer")
.assetId(assetId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import org.eclipse.edc.connector.contract.spi.negotiation.ConsumerContractNegotiationManager;
import org.eclipse.edc.connector.contract.spi.negotiation.observe.ContractNegotiationObservable;
import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore;
import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.spi.types.domain.agreement.ContractAgreement;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package de.fraunhofer.iosb.app.edc;

import org.eclipse.edc.spi.asset.AssetIndex;
import org.eclipse.edc.spi.types.domain.HttpDataAddress;
import org.eclipse.edc.connector.dataplane.http.spi.HttpDataAddress;
import org.eclipse.edc.spi.types.domain.asset.Asset;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest;
import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer;
import org.eclipse.edc.connector.policy.spi.PolicyDefinition;
import org.eclipse.edc.connector.spi.catalog.CatalogService;
import org.eclipse.edc.connector.transfer.spi.TransferProcessManager;
Expand All @@ -41,6 +40,7 @@
import org.eclipse.edc.spi.response.ResponseStatus;
import org.eclipse.edc.spi.response.StatusResult;
import org.eclipse.edc.spi.types.domain.asset.Asset;
import org.eclipse.edc.spi.types.domain.offer.ContractOffer;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.junit.jupiter.api.*;
import org.mockserver.integration.ClientAndServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.eclipse.edc.connector.transfer.spi.types.TransferProcess;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.response.StatusResult;
import org.eclipse.edc.spi.types.domain.HttpDataAddress;
import org.eclipse.edc.connector.dataplane.http.spi.HttpDataAddress;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import org.eclipse.edc.connector.contract.spi.negotiation.ConsumerContractNegotiationManager;
import org.eclipse.edc.connector.contract.spi.negotiation.observe.ContractNegotiationObservable;
import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore;
import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequest;
import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer;
import org.eclipse.edc.policy.model.Action;
import org.eclipse.edc.policy.model.Permission;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.spi.response.StatusResult;
import org.eclipse.edc.spi.types.domain.agreement.ContractAgreement;
import org.eclipse.edc.spi.types.domain.offer.ContractOffer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
javaVersion=17
group=org.eclipse.edc
edcVersion=0.3.0
edcVersion=0.4.1
faaastVersion=0.5.0
rsApi=3.1.0
okHttpVersion=4.10.0
Expand Down

0 comments on commit cb2d28f

Please sign in to comment.