diff --git a/src/test/java/org/hyperagents/yggdrasil/BodyNotificationTest.java b/src/test/java/org/hyperagents/yggdrasil/BodyNotificationTest.java index 16734f14..7b3a5f30 100644 --- a/src/test/java/org/hyperagents/yggdrasil/BodyNotificationTest.java +++ b/src/test/java/org/hyperagents/yggdrasil/BodyNotificationTest.java @@ -17,7 +17,6 @@ import java.nio.file.Path; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.hc.core5.http.HttpStatus; @@ -302,60 +301,60 @@ public void testRun(final VertxTestContext ctx) throws URISyntaxException, IOExc ); Assertions.assertNull(r.bodyAsString(), RESPONSE_BODY_EMPTY_MESSAGE); }) - .compose(r -> this.callbackMessages - .get(2) - .future() - .compose(r1 -> this.callbackMessages - .get(3) - .future() - .onSuccess(r2 -> { - Assertions.assertEquals( - this.getUrl( - WORKSPACES_PATH - + MAIN_WORKSPACE_NAME - + BODIES_PATH - + TEST_AGENT_NAME - ), - r1.getKey(), - URIS_EQUAL_MESSAGE - ); - Assertions.assertEquals( - this.getUrl( - WORKSPACES_PATH - + MAIN_WORKSPACE_NAME - + BODIES_PATH - + TEST_AGENT_NAME - ), - r2.getKey(), - URIS_EQUAL_MESSAGE - ); - Assertions.assertEquals( - Set.of( - JsonObject - .of( - "artifactName", - COUNTER_ARTIFACT_NAME, - "actionName", - "inc", - "eventType", - "actionRequested" - ) - .encode(), - JsonObject - .of( - "artifactName", - COUNTER_ARTIFACT_NAME, - "actionName", - "inc", - "eventType", - "actionSucceeded" - ) - .encode() - ), - Set.of(r1.getValue(), r2.getValue()), - REPRESENTATIONS_EQUAL_MESSAGE - ); - }))) + .compose(r -> this.callbackMessages.get(2).future()) + .onSuccess(m -> { + Assertions.assertEquals( + this.getUrl( + WORKSPACES_PATH + + MAIN_WORKSPACE_NAME + + BODIES_PATH + + TEST_AGENT_NAME + ), + m.getKey(), + URIS_EQUAL_MESSAGE + ); + Assertions.assertEquals( + JsonObject + .of( + "artifactName", + COUNTER_ARTIFACT_NAME, + "actionName", + "inc", + "eventType", + "actionRequested" + ) + .encode(), + m.getValue(), + REPRESENTATIONS_EQUAL_MESSAGE + ); + }) + .compose(r -> this.callbackMessages.get(3).future()) + .onSuccess(m -> { + Assertions.assertEquals( + this.getUrl( + WORKSPACES_PATH + + MAIN_WORKSPACE_NAME + + BODIES_PATH + + TEST_AGENT_NAME + ), + m.getKey(), + URIS_EQUAL_MESSAGE + ); + Assertions.assertEquals( + JsonObject + .of( + "artifactName", + COUNTER_ARTIFACT_NAME, + "actionName", + "inc", + "eventType", + "actionSucceeded" + ) + .encode(), + m.getValue(), + REPRESENTATIONS_EQUAL_MESSAGE + ); + }) .onComplete(ctx.succeedingThenComplete()); } diff --git a/yggdrasil-cartago/src/main/java/org/hyperagents/yggdrasil/cartago/CartagoVerticle.java b/yggdrasil-cartago/src/main/java/org/hyperagents/yggdrasil/cartago/CartagoVerticle.java index 75f5a36e..5a6a030b 100644 --- a/yggdrasil-cartago/src/main/java/org/hyperagents/yggdrasil/cartago/CartagoVerticle.java +++ b/yggdrasil-cartago/src/main/java/org/hyperagents/yggdrasil/cartago/CartagoVerticle.java @@ -294,6 +294,12 @@ private Future> doAction( final var promise = Promise.promise(); final var workspace = this.workspaceRegistry.getWorkspace(workspaceName).orElseThrow(); final var agentName = this.getAgentNameFromAgentUri(agentUri); + this.dispatcherMessagebox.sendMessage( + new HttpNotificationDispatcherMessage.ActionRequested( + this.httpConfig.getAgentBodyUri(workspaceName, agentName), + this.getActionNotificationContent(artifactName, action).encode() + ) + ); workspace.execOp(0L, this.getAgentId(this.getAgentCredential(agentUri), workspace.getId()), e -> { @@ -301,7 +307,7 @@ private Future> doAction( this.dispatcherMessagebox.sendMessage( new HttpNotificationDispatcherMessage.ActionSucceeded( this.httpConfig.getAgentBodyUri(workspaceName, agentName), - this.getActionNotificationContent(artifactName, action) + this.getActionNotificationContent(artifactName, action).encode() ) ); promise.complete(); @@ -310,6 +316,8 @@ private Future> doAction( new HttpNotificationDispatcherMessage.ActionFailed( this.httpConfig.getAgentBodyUri(workspaceName, agentName), this.getActionNotificationContent(artifactName, action) + .put("cause", f.getFailureMsg()) + .encode() ) ); promise.fail(f.getFailureMsg()); @@ -319,12 +327,6 @@ private Future> doAction( operation, -1, null); - this.dispatcherMessagebox.sendMessage( - new HttpNotificationDispatcherMessage.ActionRequested( - this.httpConfig.getAgentBodyUri(workspaceName, agentName), - this.getActionNotificationContent(artifactName, action) - ) - ); return promise.future() .map(ignored -> Optional.ofNullable(feedbackParameter.get()) @@ -338,15 +340,13 @@ private Future> doAction( ); } - private String getActionNotificationContent(final String artifactName, final String action) { - return JsonObject - .of( - "artifactName", - artifactName, - "actionName", - action - ) - .encode(); + private JsonObject getActionNotificationContent(final String artifactName, final String action) { + return JsonObject.of( + "artifactName", + artifactName, + "actionName", + action + ); } private String getAgentNameFromAgentUri(final String agentUri) {