Skip to content

Commit

Permalink
Merge branch 'lb4/datahub_rest_emitter_init' of https://github.com/im…
Browse files Browse the repository at this point in the history
…ec-int/edc into lb4/datahub_rest_emitter_init
  • Loading branch information
xdxxxdx committed Aug 30, 2023
2 parents b0d0eb1 + f58dbd2 commit c56050d
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 177 deletions.
20 changes: 10 additions & 10 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ maven/mavencentral/com.fasterxml.jackson/jackson-bom/2.14.2, Apache-2.0, approve
maven/mavencentral/com.fasterxml.jackson/jackson-bom/2.15.2, Apache-2.0, approved, #7929
maven/mavencentral/com.fasterxml.uuid/java-uuid-generator/4.1.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.github.cliftonlabs/json-simple/3.0.2, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.github.docker-java/docker-java-api/3.3.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.github.docker-java/docker-java-transport-zerodep/3.3.0, Apache-2.0 AND (Apache-2.0 AND BSD-3-Clause), approved, #7946
maven/mavencentral/com.github.docker-java/docker-java-transport/3.3.0, Apache-2.0, approved, #7942
maven/mavencentral/com.github.docker-java/docker-java-api/3.3.3, , restricted, clearlydefined
maven/mavencentral/com.github.docker-java/docker-java-transport-zerodep/3.3.3, Apache-2.0 AND (Apache-2.0 AND BSD-3-Clause), approved, #7946
maven/mavencentral/com.github.docker-java/docker-java-transport/3.3.3, Apache-2.0, approved, #7942
maven/mavencentral/com.github.java-json-tools/btf/1.3, Apache-2.0 OR LGPL-3.0-or-later, approved, #2721
maven/mavencentral/com.github.java-json-tools/jackson-coreutils-equivalence/1.0, LGPL-3.0 OR Apache-2.0, approved, clearlydefined
maven/mavencentral/com.github.java-json-tools/jackson-coreutils/2.0, , approved, #2719
Expand Down Expand Up @@ -201,7 +201,7 @@ maven/mavencentral/org.apache.commons/commons-pool2/2.11.1, Apache-2.0, approved
maven/mavencentral/org.apache.commons/commons-text/1.10.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.apache.groovy/groovy-bom/4.0.11, Apache-2.0, approved, #9266
maven/mavencentral/org.apache.groovy/groovy-json/4.0.11, Apache-2.0, approved, #7411
maven/mavencentral/org.apache.groovy/groovy-xml/4.0.11, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.apache.groovy/groovy-xml/4.0.11, Apache-2.0, approved, #10179
maven/mavencentral/org.apache.groovy/groovy/4.0.11, Apache-2.0 AND BSD-3-Clause AND MIT, approved, #1742
maven/mavencentral/org.apache.httpcomponents/httpclient/4.5.13, Apache-2.0 AND LicenseRef-Public-Domain, approved, CQ23527
maven/mavencentral/org.apache.httpcomponents/httpcore/4.4.13, Apache-2.0, approved, CQ23528
Expand Down Expand Up @@ -322,12 +322,12 @@ maven/mavencentral/org.slf4j/slf4j-api/1.7.36, MIT, approved, CQ13368
maven/mavencentral/org.slf4j/slf4j-api/2.0.5, MIT, approved, #5915
maven/mavencentral/org.slf4j/slf4j-api/2.0.6, MIT, approved, #5915
maven/mavencentral/org.slf4j/slf4j-api/2.0.7, MIT, approved, #5915
maven/mavencentral/org.testcontainers/database-commons/1.18.3, MIT, approved, clearlydefined
maven/mavencentral/org.testcontainers/jdbc/1.18.3, MIT, approved, clearlydefined
maven/mavencentral/org.testcontainers/junit-jupiter/1.18.3, MIT, approved, #7941
maven/mavencentral/org.testcontainers/postgresql/1.18.3, MIT, approved, #9332
maven/mavencentral/org.testcontainers/testcontainers/1.18.3, MIT, approved, #7938
maven/mavencentral/org.testcontainers/vault/1.18.3, MIT, approved, #7927
maven/mavencentral/org.testcontainers/database-commons/1.19.0, , restricted, clearlydefined
maven/mavencentral/org.testcontainers/jdbc/1.19.0, , restricted, clearlydefined
maven/mavencentral/org.testcontainers/junit-jupiter/1.19.0, , restricted, clearlydefined
maven/mavencentral/org.testcontainers/postgresql/1.19.0, , restricted, clearlydefined
maven/mavencentral/org.testcontainers/testcontainers/1.19.0, , restricted, clearlydefined
maven/mavencentral/org.testcontainers/vault/1.19.0, , restricted, clearlydefined
maven/mavencentral/org.xerial.snappy/snappy-java/1.1.10.1, Apache-2.0 AND (Apache-2.0 AND BSD-3-Clause), approved, #9098
maven/mavencentral/org.xmlunit/xmlunit-core/2.9.1, Apache-2.0, approved, #6272
maven/mavencentral/org.xmlunit/xmlunit-placeholders/2.9.1, Apache-2.0, approved, clearlydefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import static java.lang.String.format;
import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.Type.PROVIDER;
import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.ACCEPTED;
import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.AGREEING;
import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.FINALIZING;
import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.OFFERING;
Expand All @@ -51,6 +52,7 @@ public void start() {
stateMachineManager = StateMachineManager.Builder.newInstance("provider-contract-negotiation", monitor, executorInstrumentation, waitStrategy)
.processor(processNegotiationsInState(OFFERING, this::processOffering))
.processor(processNegotiationsInState(REQUESTED, this::processRequested))
.processor(processNegotiationsInState(ACCEPTED, this::processAccepted))
.processor(processNegotiationsInState(AGREEING, this::processAgreeing))
.processor(processNegotiationsInState(VERIFIED, this::processVerified))
.processor(processNegotiationsInState(FINALIZING, this::processFinalizing))
Expand Down Expand Up @@ -137,6 +139,17 @@ private boolean processRequested(ContractNegotiation negotiation) {
return true;
}

/**
* Processes {@link ContractNegotiation} in state ACCEPTED. It transitions to AGREEING.
*
* @return true if processed, false otherwise
*/
@WithSpan
private boolean processAccepted(ContractNegotiation negotiation) {
transitionToAgreeing(negotiation);
return true;
}

/**
* Processes {@link ContractNegotiation} in state CONFIRMING. Tries to send a contract agreement to the respective
* consumer. If this succeeds, the ContractNegotiation is transitioned to state CONFIRMED. Else, it is transitioned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import static java.util.concurrent.CompletableFuture.failedFuture;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.ACCEPTED;
import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.AGREED;
import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.AGREEING;
import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.FINALIZED;
Expand Down Expand Up @@ -140,6 +141,20 @@ void requested_shouldTransitionToAgreeing() {
});
}

@Test
void accepted_shouldTransitionToAgreeing() {
var negotiation = contractNegotiationBuilder().state(ACCEPTED.code()).build();
when(store.nextNotLeased(anyInt(), stateIs(ACCEPTED.code()))).thenReturn(List.of(negotiation)).thenReturn(emptyList());
when(store.findById(negotiation.getId())).thenReturn(negotiation);

manager.start();

await().untilAsserted(() -> {
verify(store).save(argThat(p -> p.getState() == AGREEING.code()));
verifyNoInteractions(dispatcherRegistry);
});
}

@Test
void verified_shouldTransitionToFinalizing() {
var negotiation = contractNegotiationBuilder().state(VERIFIED.code()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreementVerificationMessage;
import org.eclipse.edc.connector.contract.spi.types.agreement.ContractNegotiationEventMessage;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationTerminationMessage;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractOfferMessage;
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestMessage;
Expand All @@ -40,7 +39,6 @@
import java.util.Optional;
import java.util.UUID;

import static java.lang.String.format;
import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.Type.PROVIDER;

public class ContractNegotiationProtocolServiceImpl implements ContractNegotiationProtocolService {
Expand Down Expand Up @@ -71,7 +69,6 @@ public ServiceResult<ContractNegotiation> notifyRequested(ContractRequestMessage
return transactionContext.execute(() -> validateOffer(message, claimToken)
.compose(validatedOffer -> createNegotiation(message, validatedOffer))
.onSuccess(negotiation -> {
monitor.debug(() -> "[Provider] Contract offer received.");
negotiation.transitionRequested();
update(negotiation);
observable.invokeForEach(l -> l.requested(negotiation));
Expand All @@ -85,7 +82,6 @@ public ServiceResult<ContractNegotiation> notifyOffered(ContractOfferMessage mes
return transactionContext.execute(() -> getNegotiation(message)
.compose(negotiation -> validateRequest(claimToken, negotiation))
.onSuccess(negotiation -> {
monitor.debug(() -> "[Consumer] Contract offer received.");
negotiation.addContractOffer(message.getContractOffer());
negotiation.transitionOffered();
update(negotiation);
Expand All @@ -97,7 +93,13 @@ public ServiceResult<ContractNegotiation> notifyOffered(ContractOfferMessage mes
@WithSpan
@NotNull
public ServiceResult<ContractNegotiation> notifyAccepted(ContractNegotiationEventMessage message, ClaimToken claimToken) {
throw new UnsupportedOperationException("not implemented");
return transactionContext.execute(() -> getNegotiation(message)
.compose(negotiation -> validateRequest(claimToken, negotiation))
.onSuccess(negotiation -> {
negotiation.transitionAccepted();
update(negotiation);
observable.invokeForEach(l -> l.accepted(negotiation));
}));
}

@Override
Expand All @@ -107,7 +109,6 @@ public ServiceResult<ContractNegotiation> notifyAgreed(ContractAgreementMessage
return transactionContext.execute(() -> getNegotiation(message)
.compose(negotiation -> validateAgreed(message, claimToken, negotiation))
.onSuccess(negotiation -> {
monitor.debug("[Consumer] Contract agreement received. Validation successful.");
negotiation.setContractAgreement(message.getContractAgreement());
negotiation.transitionAgreed();
update(negotiation);
Expand Down Expand Up @@ -160,7 +161,7 @@ public ServiceResult<ContractNegotiation> notifyTerminated(ContractNegotiationTe
public ServiceResult<ContractNegotiation> findById(String id, ClaimToken claimToken) {
return transactionContext.execute(() -> Optional.ofNullable(store.findById(id))
.map(negotiation -> validateRequest(claimToken, negotiation))
.orElse(ServiceResult.notFound(format("No negotiation with id %s found", id))));
.orElse(ServiceResult.notFound("No negotiation with id %s found".formatted(id))));
}

@NotNull
Expand Down Expand Up @@ -221,8 +222,8 @@ private ServiceResult<ContractNegotiation> getNegotiation(ContractRemoteMessage

private void update(ContractNegotiation negotiation) {
store.save(negotiation);
monitor.debug(String.format("[%s] ContractNegotiation %s is now in state %s.",
negotiation.getType(), negotiation.getId(), ContractNegotiationStates.from(negotiation.getState())));
monitor.debug(() -> "[%s] ContractNegotiation %s is now in state %s."
.formatted(negotiation.getType(), negotiation.getId(), negotiation.stateAsString()));
}

}
Loading

0 comments on commit c56050d

Please sign in to comment.