/** * Migrates the passed in {@code connectionJsonObject} into the current {@link Connection} structure. * <br /> * If the {@code connectionJsonObject} is already in the current structure, simply build a {@link Connection} * instance from it. * * @param connectionJsonObject the Connection JSON to parse * @return the (potentially migrated) Connection instance */ static Connection connectionFromJsonWithMigration(@Nonnull final JsonObject connectionJsonObject) { final Function<JsonObject, JsonObject> migrateSourceFilters = new MigrateSourceFilters(); final Function<JsonObject, JsonObject> migrateAuthorizationContexts = new MigrateAuthorizationContexts(); return ConnectivityModelFactory.connectionFromJson( migrateAuthorizationContexts .andThen(migrateSourceFilters) .apply(connectionJsonObject)); }
/** * Returns a mutable builder with a fluent API for immutable {@code Connection}. The builder is initialised with the * entries of this instance. * * @return the new builder. */ default ConnectionBuilder toBuilder() { return ConnectivityModelFactory.newConnectionBuilder(this); }
/** * New instance of {@link Enforcement} options to be used with connections supporting filtering on their * {@link Source} {@code address}. * * @param requiredFilter the required filter * @param additionalFilters additional filters * @return the enforcement instance */ public static Enforcement newSourceAddressEnforcement(final String requiredFilter, final String... additionalFilters) { return newEnforcement(SOURCE_ADDRESS_ENFORCEMENT, requiredFilter, additionalFilters); }
protected BasePublisherActor() { addressMetric = ConnectivityModelFactory.newAddressMetric(ConnectionStatus.OPEN, "Started at " + Instant.now(), 0, null); }
/** * Creates a new {@code SourceMetrics} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the SourceMetrics to be created. * @return a new SourceMetrics which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static SourceMetrics fromJson(final JsonObject jsonObject) { final Map<String, AddressMetric> readAddressMetrics = jsonObject.getValue(JsonFields.ADDRESS_METRICS) .map(obj -> obj.stream() .collect(Collectors.toMap( f -> f.getKey().toString(), f -> ConnectivityModelFactory.addressMetricFromJson(f.getValue().asObject())))) .orElse(Collections.emptyMap()); final long readConsumedMessages = jsonObject.getValueOrThrow(JsonFields.CONSUMED_MESSAGES); return ImmutableSourceMetrics.of(readAddressMetrics, readConsumedMessages); }
private void respondWithEmptyMetrics(final RetrieveConnectionMetrics command, final ActorRef origin) { log.debug("ClientActor not started, responding with empty connection metrics with status closed."); final ConnectionMetrics metrics = ConnectivityModelFactory.newConnectionMetrics(ConnectionStatus.CLOSED, "connection is closed", connectionClosedAt != null ? connectionClosedAt : Instant.ofEpochSecond(0), BaseClientState.DISCONNECTED.name(), Collections.emptyList(), Collections.emptyList()); final RetrieveConnectionMetricsResponse metricsResponse = RetrieveConnectionMetricsResponse.of(connectionId, metrics, command.getDittoHeaders()); final String responseType = metricsResponse.getType(); final AggregatedConnectivityCommandResponse response = AggregatedConnectivityCommandResponse.of(connectionId, Collections.singletonList(metricsResponse), responseType, HttpStatusCode.OK, command.getDittoHeaders()); origin.tell(response, getSelf()); }
/** * Creates a new {@code RetrieveConnectionMetricsResponse} from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the response. * @return the response. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static RetrieveConnectionMetricsResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<RetrieveConnectionMetricsResponse>(TYPE, jsonObject).deserialize( statusCode -> { final String readConnectionId = jsonObject.getValueOrThrow(ConnectivityCommandResponse.JsonFields.JSON_CONNECTION_ID); final ConnectionMetrics readConnectionMetrics = ConnectivityModelFactory.connectionMetricsFromJson( jsonObject.getValueOrThrow(JSON_CONNECTION_METRICS)); return of(readConnectionId, readConnectionMetrics, dittoHeaders); }); }
protected BasePublisherActor() { addressMetric = ConnectivityModelFactory.newAddressMetric(ConnectionStatus.OPEN, "Started at " + Instant.now(), 0, null); }
/** * Creates a new {@code TargetMetrics} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the TargetMetrics to be created. * @return a new TargetMetrics which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static TargetMetrics fromJson(final JsonObject jsonObject) { final Map<String, AddressMetric> readAddressMetrics = jsonObject.getValue(JsonFields.ADDRESS_METRICS) .map(obj -> obj.stream() .collect(Collectors.toMap( f -> f.getKey().toString(), f -> ConnectivityModelFactory.addressMetricFromJson(f.getValue().asObject())))) .orElse(Collections.emptyMap()); final long readPublishedMessages = jsonObject.getValueOrThrow(JsonFields.PUBLISHED_MESSAGES); return ImmutableTargetMetrics.of(readAddressMetrics, readPublishedMessages); }
private void respondWithEmptyMetrics(final RetrieveConnectionMetrics command, final ActorRef origin) { log.debug("ClientActor not started, responding with empty connection metrics with status closed."); final ConnectionMetrics metrics = ConnectivityModelFactory.newConnectionMetrics(ConnectionStatus.CLOSED, "connection is closed", connectionClosedAt != null ? connectionClosedAt : Instant.ofEpochSecond(0), BaseClientState.DISCONNECTED.name(), Collections.emptyList(), Collections.emptyList()); final RetrieveConnectionMetricsResponse metricsResponse = RetrieveConnectionMetricsResponse.of(connectionId, metrics, command.getDittoHeaders()); final String responseType = metricsResponse.getType(); final AggregatedConnectivityCommandResponse response = AggregatedConnectivityCommandResponse.of(connectionId, Collections.singletonList(metricsResponse), responseType, HttpStatusCode.OK, command.getDittoHeaders()); origin.tell(response, getSelf()); }
/** * Creates a new {@code RetrieveConnectionMetricsResponse} from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the response. * @return the response. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static RetrieveConnectionMetricsResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<RetrieveConnectionMetricsResponse>(TYPE, jsonObject).deserialize( statusCode -> { final String readConnectionId = jsonObject.getValueOrThrow(ConnectivityCommandResponse.JsonFields.JSON_CONNECTION_ID); final ConnectionMetrics readConnectionMetrics = ConnectivityModelFactory.connectionMetricsFromJson( jsonObject.getValueOrThrow(JSON_CONNECTION_METRICS)); return of(readConnectionId, readConnectionMetrics, dittoHeaders); }); }
/** * Migrates the passed in {@code connectionJsonObject} into the current {@link Connection} structure. * <br /> * If the {@code connectionJsonObject} is already in the current structure, simply build a {@link Connection} * instance from it. * * @param connectionJsonObject the Connection JSON to parse * @return the (potentially migrated) Connection instance */ static Connection connectionFromJsonWithMigration(@Nonnull final JsonObject connectionJsonObject) { final Function<JsonObject, JsonObject> migrateSourceFilters = new MigrateSourceFilters(); final Function<JsonObject, JsonObject> migrateAuthorizationContexts = new MigrateAuthorizationContexts(); return ConnectivityModelFactory.connectionFromJson( migrateAuthorizationContexts .andThen(migrateSourceFilters) .apply(connectionJsonObject)); }
/** * New instance of {@link Enforcement} options to be used with connections supporting filtering on their * {@link Source} {@code address}. * * @param filters the filters * @return the enforcement instance */ public static Enforcement newSourceAddressEnforcement(final Set<String> filters) { return newEnforcement(SOURCE_ADDRESS_ENFORCEMENT, filters); }
/** * Returns a mutable builder with a fluent API for immutable {@code Connection}. The builder is initialised with the * entries of this instance. * * @return the new builder. */ default ConnectionBuilder toBuilder() { return ConnectivityModelFactory.newConnectionBuilder(this); }
/** * Constructs a new instance and records its association to the passed-in channel. * * @param channel the channel to which this consumer is attached */ private RabbitMQMessageConsumer(final ActorRef consumerActor, final Channel channel) { super(channel); this.consumerActor = consumerActor; consumerActor.tell(ConnectivityModelFactory.newAddressMetric(ConnectionStatus.OPEN, "Consumer initialized at " + Instant.now(), 0, null), null); }
/** * Creates a new {@code SourceMetrics} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the SourceMetrics to be created. * @return a new SourceMetrics which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static SourceMetrics fromJson(final JsonObject jsonObject) { final Map<String, AddressMetric> readAddressMetrics = jsonObject.getValue(JsonFields.ADDRESS_METRICS) .map(obj -> obj.stream() .collect(Collectors.toMap( f -> f.getKey().toString(), f -> ConnectivityModelFactory.addressMetricFromJson(f.getValue().asObject())))) .orElse(Collections.emptyMap()); final long readConsumedMessages = jsonObject.getValueOrThrow(JsonFields.CONSUMED_MESSAGES); return ImmutableSourceMetrics.of(readAddressMetrics, readConsumedMessages); }
private FSM.State<BaseClientState, BaseClientData> retrieveConnectionMetrics( final RetrieveConnectionMetrics command, final BaseClientData data) { final ActorRef sender = getSender(); final ActorRef self = getSelf(); final DittoHeaders dittoHeaders = command.getDittoHeaders().toBuilder() .source(org.eclipse.ditto.services.utils.config.ConfigUtil.instanceIdentifier()) .build(); final CompletionStage<List<SourceMetrics>> sourceMetricsFuture = getCurrentSourcesMetrics(); final CompletionStage<List<TargetMetrics>> targetMetricsFuture = getCurrentTargetsMetrics(); final CompletionStage<ConnectionMetrics> metricsFuture = sourceMetricsFuture.thenCompose(sourceMetrics -> targetMetricsFuture.thenApply(targetMetrics -> ConnectivityModelFactory.newConnectionMetrics( getCurrentConnectionStatus(), getCurrentConnectionStatusDetails().orElse(null), getInConnectionStatusSince(), stateName().name(), sourceMetrics, targetMetrics) ) ); metricsFuture.thenAccept(connectionMetrics -> { final Object response = RetrieveConnectionMetricsResponse.of(connectionId(), connectionMetrics, dittoHeaders); sender.tell(response, self); }); return stay(); }
/** * Creates a new {@code ModifyConnection} from a JSON object. * * @param jsonObject the JSON object of which the command is to be created. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static ModifyConnection fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandJsonDeserializer<ModifyConnection>(TYPE, jsonObject).deserialize(() -> { final JsonObject jsonConnection = jsonObject.getValueOrThrow(JSON_CONNECTION); final Connection readConnection = ConnectivityModelFactory.connectionFromJson(jsonConnection); return of(readConnection, dittoHeaders); }); }
/** * New instance of {@link Enforcement} options to be used with connections supporting filtering on their * {@link Source} {@code address}. * * @param filters the filters * @return the enforcement instance */ public static Enforcement newSourceAddressEnforcement(final Set<String> filters) { return newEnforcement(SOURCE_ADDRESS_ENFORCEMENT, filters); }
@Test public void toStringDoesNotContainPassword() { final String password = "thePassword"; final String uri = "amqps://foo:" + password + "@host.com:5671"; final Connection connection = ConnectivityModelFactory.newConnectionBuilder(ID, TYPE, STATUS, uri) .sources(Collections.singletonList(SOURCE1)) .build(); assertThat(connection.toString()).doesNotContain(password); }