Search in sources :

Example 1 with Acknowledgement

use of org.eclipse.ditto.base.model.signals.acks.Acknowledgement in project ditto by eclipse.

the class DittoProtocolAdapterTest method acknowledgementToAdaptable.

@Test
public void acknowledgementToAdaptable() {
    final Acknowledgement acknowledgement = Acknowledgement.of(AcknowledgementLabel.of("my-twin-persisted"), ThingId.of("thing:id"), HttpStatus.CONTINUE, DittoHeaders.empty());
    final Adaptable adaptable = underTest.toAdaptable((Signal<?>) acknowledgement);
    assertThat(adaptable.getTopicPath()).isEqualTo(ProtocolFactory.newTopicPath("thing/id/things/twin/acks/my-twin-persisted"));
    assertThat((Iterable<?>) adaptable.getPayload().getPath()).isEmpty();
    assertThat(adaptable.getPayload().getHttpStatus()).contains(HttpStatus.CONTINUE);
}
Also used : Acknowledgement(org.eclipse.ditto.base.model.signals.acks.Acknowledgement) Adaptable(org.eclipse.ditto.protocol.Adaptable) Test(org.junit.Test)

Example 2 with Acknowledgement

use of org.eclipse.ditto.base.model.signals.acks.Acknowledgement in project ditto by eclipse.

the class DittoProtocolAdapterTest method acknowledgementsToAdaptable.

@Test
public void acknowledgementsToAdaptable() {
    final Acknowledgement ack1 = Acknowledgement.of(TWIN_PERSISTED, ThingId.of("thing:id"), HttpStatus.CONTINUE, DittoHeaders.empty());
    final Acknowledgement ack2 = Acknowledgement.of(AcknowledgementLabel.of("the-ack-label"), ThingId.of("thing:id"), HttpStatus.LOOP_DETECTED, DittoHeaders.empty());
    final Acknowledgements acks = Acknowledgements.of(Arrays.asList(ack1, ack2), DittoHeaders.empty());
    final Adaptable adaptable = underTest.toAdaptable((Signal<?>) acks);
    final JsonObject expectedPayloadJson = JsonObject.of("{\n" + "  \"twin-persisted\":{\"status\":100,\"headers\":{\"response-required\":false}},\n" + "  \"the-ack-label\":{\"status\":508,\"headers\":{\"response-required\":false}}\n" + "}");
    assertThat(adaptable.getTopicPath()).isEqualTo(ProtocolFactory.newTopicPath("thing/id/things/twin/acks"));
    assertThat((Iterable<?>) adaptable.getPayload().getPath()).isEmpty();
    assertThat(adaptable.getPayload().getHttpStatus()).contains(HttpStatus.FAILED_DEPENDENCY);
    assertThat(adaptable.getPayload().getValue()).contains(expectedPayloadJson);
}
Also used : Acknowledgement(org.eclipse.ditto.base.model.signals.acks.Acknowledgement) JsonObject(org.eclipse.ditto.json.JsonObject) Acknowledgements(org.eclipse.ditto.base.model.signals.acks.Acknowledgements) Adaptable(org.eclipse.ditto.protocol.Adaptable) Test(org.junit.Test)

Example 3 with Acknowledgement

use of org.eclipse.ditto.base.model.signals.acks.Acknowledgement in project ditto by eclipse.

the class AcknowledgementAdapterTest method acknowledgementFromAdaptable.

@Test
public void acknowledgementFromAdaptable() {
    final DittoHeaders dittoHeaders = DittoHeaders.newBuilder().randomCorrelationId().build();
    final JsonValue customAckPayload = JsonValue.of("Custom Ack payload");
    final HttpStatus status = HttpStatus.CREATED;
    final Adaptable adaptable = Adaptable.newBuilder(topicPathMyCustomAck).withHeaders(dittoHeaders).withPayload(Payload.newBuilder(JsonPointer.empty()).withValue(customAckPayload).withStatus(status).build()).build();
    final Acknowledgement expected = ThingAcknowledgementFactory.newAcknowledgement(KNOWN_CUSTOM_LABEL, TestConstants.THING_ID, status, dittoHeaders, customAckPayload);
    final Acknowledgement actual = underTest.fromAdaptable(adaptable);
    assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
Also used : Acknowledgement(org.eclipse.ditto.base.model.signals.acks.Acknowledgement) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) HttpStatus(org.eclipse.ditto.base.model.common.HttpStatus) JsonValue(org.eclipse.ditto.json.JsonValue) Adaptable(org.eclipse.ditto.protocol.Adaptable) ProtocolAdapterTest(org.eclipse.ditto.protocol.adapter.ProtocolAdapterTest) Test(org.junit.Test)

Example 4 with Acknowledgement

use of org.eclipse.ditto.base.model.signals.acks.Acknowledgement in project ditto by eclipse.

the class RabbitMQPublisherActor method buildResponse.

private static SendResult buildResponse(final Signal<?> signal, @Nullable final Target autoAckTarget, final HttpStatus httpStatus, @Nullable final String message, final ExpressionResolver connectionIdResolver) {
    final var autoAckLabel = Optional.ofNullable(autoAckTarget).flatMap(Target::getIssuedAcknowledgementLabel).flatMap(ackLabel -> resolveConnectionIdPlaceholder(connectionIdResolver, ackLabel));
    final Optional<EntityId> entityIdOptional = WithEntityId.getEntityIdOfType(EntityId.class, signal);
    final Acknowledgement issuedAck;
    if (autoAckLabel.isPresent() && entityIdOptional.isPresent()) {
        issuedAck = Acknowledgement.of(autoAckLabel.get(), entityIdOptional.get(), httpStatus, signal.getDittoHeaders(), message == null ? null : JsonValue.of(message));
    } else {
        issuedAck = null;
    }
    return new SendResult(issuedAck, signal.getDittoHeaders());
}
Also used : WithEntityId(org.eclipse.ditto.base.model.entity.id.WithEntityId) EntityId(org.eclipse.ditto.base.model.entity.id.EntityId) Acknowledgement(org.eclipse.ditto.base.model.signals.acks.Acknowledgement) SendResult(org.eclipse.ditto.connectivity.service.messaging.SendResult)

Example 5 with Acknowledgement

use of org.eclipse.ditto.base.model.signals.acks.Acknowledgement in project ditto by eclipse.

the class StreamingSessionActor method declareAcknowledgementLabels.

/**
 * Attempt to declare the acknowledgement labels (they must be unique cluster wide).
 * Only need to be done once per actor.
 *
 * @param acknowledgementLabels the acknowledgement labels to declare.
 */
private void declareAcknowledgementLabels(final Collection<AcknowledgementLabel> acknowledgementLabels) {
    final ActorRef self = getSelf();
    logger.info("Declaring acknowledgement labels <{}>", acknowledgementLabels);
    dittoProtocolSub.declareAcknowledgementLabels(acknowledgementLabels, self, null).thenAccept(unused -> logger.info("Acknowledgement label declaration successful for labels: <{}>", acknowledgementLabels)).exceptionally(error -> {
        final var dittoRuntimeException = DittoRuntimeException.asDittoRuntimeException(error, cause -> AcknowledgementLabelNotUniqueException.newBuilder().cause(cause).build());
        logger.info("Acknowledgement label declaration failed for labels: <{}> - cause: {} {}", acknowledgementLabels, error.getClass().getSimpleName(), error.getMessage());
        self.tell(dittoRuntimeException, ActorRef.noSender());
        return null;
    });
}
Also used : EntityIdPlaceholder(org.eclipse.ditto.connectivity.api.placeholders.EntityIdPlaceholder) PFBuilder(akka.japi.pf.PFBuilder) StreamingType(org.eclipse.ditto.internal.utils.pubsub.StreamingType) Terminated(akka.actor.Terminated) Acknowledgement(org.eclipse.ditto.base.model.signals.acks.Acknowledgement) Signal(org.eclipse.ditto.base.model.signals.Signal) DittoHeaderDefinition(org.eclipse.ditto.base.model.headers.DittoHeaderDefinition) RqlPredicateParser(org.eclipse.ditto.rql.parser.RqlPredicateParser) MessageCommandAckRequestSetter(org.eclipse.ditto.messages.model.signals.commands.acks.MessageCommandAckRequestSetter) DittoRuntimeException(org.eclipse.ditto.base.model.exceptions.DittoRuntimeException) Criteria(org.eclipse.ditto.rql.query.criteria.Criteria) DittoHeaders(org.eclipse.ditto.base.model.headers.DittoHeaders) InvalidJwt(org.eclipse.ditto.gateway.service.streaming.InvalidJwt) DittoProtocolSub(org.eclipse.ditto.internal.utils.pubsub.DittoProtocolSub) ActorRef(akka.actor.ActorRef) Duration(java.time.Duration) Map(java.util.Map) RefreshSession(org.eclipse.ditto.gateway.service.streaming.RefreshSession) CommandResponse(org.eclipse.ditto.base.model.signals.commands.CommandResponse) PolicyAnnouncement(org.eclipse.ditto.policies.model.signals.announcements.PolicyAnnouncement) EnumSet(java.util.EnumSet) NamespaceReader(org.eclipse.ditto.base.model.namespaces.NamespaceReader) SubscriptionManager(org.eclipse.ditto.internal.utils.search.SubscriptionManager) SourceQueueWithComplete(akka.stream.javadsl.SourceQueueWithComplete) SubscriptionEvent(org.eclipse.ditto.thingsearch.model.signals.events.SubscriptionEvent) PartialFunction(scala.PartialFunction) EnumMap(java.util.EnumMap) SignalInformationPoint(org.eclipse.ditto.internal.models.signal.SignalInformationPoint) QueryFilterCriteriaFactory(org.eclipse.ditto.rql.query.filter.QueryFilterCriteriaFactory) Done(akka.Done) Collection(java.util.Collection) ThingLiveCommandAckRequestSetter(org.eclipse.ditto.things.model.signals.commands.acks.ThingLiveCommandAckRequestSetter) GatewayInternalErrorException(org.eclipse.ditto.base.model.signals.commands.exceptions.GatewayInternalErrorException) Set(java.util.Set) GatewayWebsocketSessionExpiredException(org.eclipse.ditto.base.model.signals.commands.exceptions.GatewayWebsocketSessionExpiredException) Instant(java.time.Instant) FatalPubSubException(org.eclipse.ditto.base.model.acks.FatalPubSubException) DittoLoggerFactory(org.eclipse.ditto.internal.utils.akka.logging.DittoLoggerFactory) HeaderTranslator(org.eclipse.ditto.protocol.HeaderTranslator) List(java.util.List) ResourcePlaceholder(org.eclipse.ditto.protocol.placeholders.ResourcePlaceholder) Optional(java.util.Optional) Props(akka.actor.Props) Connect(org.eclipse.ditto.gateway.service.streaming.Connect) StartStreaming(org.eclipse.ditto.gateway.service.streaming.StartStreaming) ThingSearchCommand(org.eclipse.ditto.thingsearch.model.signals.commands.ThingSearchCommand) Event(org.eclipse.ditto.base.model.signals.events.Event) AcknowledgementConfig(org.eclipse.ditto.internal.models.acks.config.AcknowledgementConfig) AcknowledgementLabel(org.eclipse.ditto.base.model.acks.AcknowledgementLabel) AuthorizationContext(org.eclipse.ditto.base.model.auth.AuthorizationContext) Jwt(org.eclipse.ditto.gateway.service.streaming.Jwt) DittoHeaderInvalidException(org.eclipse.ditto.base.model.exceptions.DittoHeaderInvalidException) ThreadSafeDittoLoggingAdapter(org.eclipse.ditto.internal.utils.akka.logging.ThreadSafeDittoLoggingAdapter) GatewayWebsocketSessionClosedException(org.eclipse.ditto.base.model.signals.commands.exceptions.GatewayWebsocketSessionClosedException) AbstractActorWithTimers(akka.actor.AbstractActorWithTimers) Nullable(javax.annotation.Nullable) JwtAuthenticationResultProvider(org.eclipse.ditto.gateway.service.security.authentication.jwt.JwtAuthenticationResultProvider) TopicPathPlaceholder(org.eclipse.ditto.protocol.placeholders.TopicPathPlaceholder) JsonSchemaVersion(org.eclipse.ditto.base.model.json.JsonSchemaVersion) AcknowledgementLabelNotDeclaredException(org.eclipse.ditto.base.model.acks.AcknowledgementLabelNotDeclaredException) AcknowledgementAggregatorActorStarter(org.eclipse.ditto.internal.models.acks.AcknowledgementAggregatorActorStarter) StopStreaming(org.eclipse.ditto.gateway.service.streaming.StopStreaming) ImmutableJsonWebToken(org.eclipse.ditto.jwt.model.ImmutableJsonWebToken) TimePlaceholder(org.eclipse.ditto.placeholders.TimePlaceholder) ThingModifyCommandAckRequestSetter(org.eclipse.ditto.things.model.signals.commands.acks.ThingModifyCommandAckRequestSetter) JwtValidator(org.eclipse.ditto.gateway.service.security.authentication.jwt.JwtValidator) IncomingSignal(org.eclipse.ditto.gateway.service.streaming.IncomingSignal) AcknowledgementForwarderActor(org.eclipse.ditto.internal.models.acks.AcknowledgementForwarderActor) ReceiveBuilder(akka.japi.pf.ReceiveBuilder) AcknowledgementLabelNotUniqueException(org.eclipse.ditto.base.model.acks.AcknowledgementLabelNotUniqueException) ActorRef(akka.actor.ActorRef)

Aggregations

Acknowledgement (org.eclipse.ditto.base.model.signals.acks.Acknowledgement)61 Test (org.junit.Test)43 Acknowledgements (org.eclipse.ditto.base.model.signals.acks.Acknowledgements)25 TestKit (akka.testkit.javadsl.TestKit)21 AcknowledgementLabel (org.eclipse.ditto.base.model.acks.AcknowledgementLabel)21 DittoHeaders (org.eclipse.ditto.base.model.headers.DittoHeaders)21 TestProbe (akka.testkit.TestProbe)18 ActorRef (akka.actor.ActorRef)14 HttpStatus (org.eclipse.ditto.base.model.common.HttpStatus)11 Signal (org.eclipse.ditto.base.model.signals.Signal)11 ThingId (org.eclipse.ditto.things.model.ThingId)11 OutboundSignal (org.eclipse.ditto.connectivity.api.OutboundSignal)10 Set (java.util.Set)9 AcknowledgementRequest (org.eclipse.ditto.base.model.acks.AcknowledgementRequest)9 JsonObject (org.eclipse.ditto.json.JsonObject)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 EntityId (org.eclipse.ditto.base.model.entity.id.EntityId)8 Target (org.eclipse.ditto.connectivity.model.Target)8 ActorSelection (akka.actor.ActorSelection)7 ArrayList (java.util.ArrayList)7