/** * Builds the {@code /health} route. * * @return the {@code /health} route. */ public Route buildHealthRoute() { return path(PATH_HEALTH, () -> // /health get(() -> // GET completeWithFuture(createOverallHealthResponse()) ) ); }
private Route thingsEntryPolicyId(final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId) { return path(PATH_POLICY_ID, () -> // /things/<thingId>/policyId route( get(() -> // GET /things/<thingId>/policyId handlePerRequest(ctx, RetrievePolicyId.of(thingId, dittoHeaders)) ), put(() -> // GET /things/<thingId>/policyId extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, policyIdJson -> ModifyPolicyId.of(thingId, Optional.of(JsonFactory.readFrom(policyIdJson)) .filter(JsonValue::isString) .map(JsonValue::asString) .orElse(policyIdJson), dittoHeaders) ) ) ) ) ); }
public Route buildStatsRoute(final String correlationId) { return Directives.rawPathPrefix(CustomPathMatchers.mergeDoubleSlashes().concat(STATISTICS_PATH_PREFIX), () -> // /stats/* extractRequestContext(ctx -> get(() -> // GET buildSubRoutes(ctx, correlationId) ) ) ); }
/** * Describes {@code /things} SSE route. * * @return {@code /things} SSE route. */ @SuppressWarnings("squid:S1172") // allow unused ctx-Param in order to have a consistent route-"interface" public Route buildThingsSseRoute(final RequestContext ctx, final Supplier<DittoHeaders> dittoHeadersSupplier) { return rawPathPrefix(mergeDoubleSlashes().concat(PATH_THINGS), () -> pathEndOrSingleSlash(() -> get(() -> headerValuePF(AcceptHeaderExtractor.INSTANCE, accept -> doBuildThingsSseRoute(dittoHeadersSupplier.get()) ) ) ) ); }
/** * Builds a Route for a HTTP Prometheus endpoint where Prometheus can scrape metrics from. * * @param prometheusReporter the PrometheusReporter to retrieve the {@code scrapeData} from * @return the Prometheus Route */ public static Route buildPrometheusReporterRoute(final PrometheusReporter prometheusReporter) { return get(() -> complete(HttpResponse.create() .withStatus(StatusCodes.OK) .withEntity(CONTENT_TYPE, ByteString.fromString(buildMetricsString(prometheusReporter))) ) ); }
/** * Builds a Route for a HTTP Prometheus endpoint where Prometheus can scrape metrics from. * * @param prometheusReporter the PrometheusReporter to retrieve the {@code scrapeData} from * @return the Prometheus Route */ public static Route buildPrometheusReporterRoute(final PrometheusReporter prometheusReporter) { return get(() -> complete(HttpResponse.create() .withStatus(StatusCodes.OK) .withEntity(CONTENT_TYPE, ByteString.fromString(prometheusReporter.scrapeData())) ) ); } }
private Route countThings(final RequestContext ctx, final DittoHeaders dittoHeaders) { return get(() -> // GET things/count?filter=<filterString>&namespaces=<namespacesString> parameterOptional(ThingSearchParameter.FILTER.toString(), filterString -> parameterOptional(ThingSearchParameter.NAMESPACES.toString(), namespacesString -> handlePerRequest(ctx, CountThings.of(calculateFilter(filterString), calculateNamespaces(namespacesString), dittoHeaders)) ) ) ); }
/** * Builds the {@code /status} route. * * @return the {@code /status} route. */ public Route buildStatusRoute() { return pathPrefix(PATH_STATUS, () -> // /status/* get(() -> // GET route( pathEndOrSingleSlash(() -> // /status complete( HttpResponse.create().withStatus(StatusCodes.OK) .withEntity(ContentTypes.APPLICATION_JSON, Status.provideStaticStatus().toString()) ) ), path(PATH_HEALTH, healthRouteSupplier), // /status/health path(PATH_CLUSTER, () -> complete( // /status/cluster HttpResponse.create().withStatus(StatusCodes.OK) .withEntity(ContentTypes.APPLICATION_JSON, clusterStateSupplier.get().toJson().toString())) ) ) ).orElse(complete(StatusCodes.METHOD_NOT_ALLOWED))); }
/** * Builds the {@code /status} route. * * @return the {@code /status} route. */ public Route buildStatusRoute() { return pathPrefix(PATH_STATUS, () -> // /status/* get(() -> // GET route( pathEndOrSingleSlash(() -> // /status complete( HttpResponse.create().withStatus(StatusCodes.OK) .withEntity(ContentTypes.APPLICATION_JSON, Status.provideStaticStatus().toString()) ) ), path(PATH_HEALTH, healthRouteSupplier), // /status/health path(PATH_CLUSTER, () -> complete( // /status/cluster HttpResponse.create().withStatus(StatusCodes.OK) .withEntity(ContentTypes.APPLICATION_JSON, clusterStateSupplier.get().toJson().toString())) ) ) ).orElse(complete(StatusCodes.METHOD_NOT_ALLOWED))); }
private Route things(final RequestContext ctx, final DittoHeaders dittoHeaders) { return pathEndOrSingleSlash(() -> route( // get(() -> // GET /things?ids=<idsString>&fields=<fieldsString> buildRetrieveThingsRoute(ctx, dittoHeaders) ), post(() -> // POST /things extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, thingJson -> CreateThing.of(createThingForPost(thingJson), createInlinePolicyJson(thingJson), getCopyPolicyFrom(thingJson), dittoHeaders) ) ) ) ) ); }
private Route thingsEntryPolicyEntries(final RequestContext ctx, final DittoHeaders dittoHeaders, final String policyId) { return pathEndOrSingleSlash(() -> Directives.route( get(() -> // GET /entries handlePerRequest(ctx, RetrievePolicyEntries.of(policyId, dittoHeaders)) ), put(() -> // PUT /entries extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, policyEntriesJson -> ModifyPolicyEntries.of(policyId, PoliciesModelFactory.newPolicyEntries( policyEntriesJson), dittoHeaders)) ) ) ) ); }
private Route routeLogging(final RequestContext ctx, final String serviceName, final Integer instance, final DittoHeaders dittoHeaders) { return route( get(() -> handlePerRequest(ctx, RetrieveLoggerConfig.ofAllKnownLoggers(serviceName, instance, dittoHeaders), transformResponse(serviceName, instance) ) ), put(() -> extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, loggerConfigJson -> ChangeLogLevel.of(serviceName, instance, ImmutableLoggerConfig.fromJson(loggerConfigJson), dittoHeaders), transformResponse(serviceName, instance) ) ) ) ); }
private Route searchThings(final RequestContext ctx, final DittoHeaders dittoHeaders) { return get( () -> // GET things?filter=<filterString>&options=<optionsString>&fields=<fieldsString>&namespaces=<namespacesString> parameterOptional(ThingSearchParameter.FILTER.toString(), filterString -> parameterOptional(ThingSearchParameter.NAMESPACES.toString(), namespacesString -> parameterOptional(ThingSearchParameter.OPTION.toString(), optionsString -> parameterOptional(ThingSearchParameter.FIELDS.toString(), fieldsString -> handlePerRequest(ctx, QueryThings.of(calculateFilter(filterString), calculateOptions(optionsString), AbstractRoute.calculateSelectedFields( fieldsString) .orElse(null), calculateNamespaces(namespacesString), dittoHeaders)) ) ) ) ) ); }
private Route features(final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId) { return pathEndOrSingleSlash(() -> Directives.route( get(() -> // GET /features?fields=<fieldsString> parameterOptional(ThingsParameter.FIELDS.toString(), fieldsString -> handlePerRequest(ctx, RetrieveFeatures .of(thingId, calculateSelectedFields(fieldsString).orElse( null), dittoHeaders)) ) ), put(() -> // PUT /features extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, featuresJson -> ModifyFeatures .of(thingId, ThingsModelFactory.newFeatures( featuresJson), dittoHeaders)) ) ), delete(() -> // DELETE /features handlePerRequest(ctx, DeleteFeatures.of(thingId, dittoHeaders)) ) ) ); }
/** * Builds the {@code /status} route. * * @return the {@code /status} route. */ public Route buildOverallStatusRoute() { return rawPathPrefix(mergeDoubleSlashes().concat(PATH_OVERALL), () -> // /overall/* authenticateDevopsBasic(REALM_DEVOPS, get(() -> // GET // /overall/status // /overall/status/health // /overall/status/cluster rawPathPrefix(mergeDoubleSlashes().concat(PATH_STATUS), () -> route( // /status pathEndOrSingleSlash( () -> completeWithFuture(createOverallStatusResponse())), // /status/health path(PATH_HEALTH, () -> completeWithFuture(createOverallHealthResponse())), path(PATH_CLUSTER, () -> complete( // /status/cluster HttpResponse.create().withStatus(StatusCodes.OK) .withEntity(ContentTypes.APPLICATION_JSON, clusterStateSupplier.get().toJson().toString())) ) )) ))); }
private Route thingsEntryAcl(final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId) { return rawPathPrefix(mergeDoubleSlashes().concat(PATH_ACL), () -> // /things/<thingId>/acl pathEndOrSingleSlash(() -> route( get(() -> // GET /things/<thingId>/acl handlePerRequest(ctx, RetrieveAcl.of(thingId, dittoHeaders)) ), put(() -> // PUT /things/<thingId>/acl extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, aclJson -> ModifyAcl.of(thingId, ThingsModelFactory.newAcl(aclJson), dittoHeaders)) ) ) ) ) ); }
private Route policyEntry(final RequestContext ctx, final DittoHeaders dittoHeaders, final String policyId) { return pathEndOrSingleSlash(() -> Directives.route( get(() -> // GET /policies/<policyId> handlePerRequest(ctx, RetrievePolicy.of(policyId, dittoHeaders)) ), put(() -> // PUT /policies/<policyId> extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, policyJson -> ModifyPolicy .of(policyId, PoliciesModelFactory.newPolicy( createPolicyJsonObjectForPut(policyJson, policyId)), dittoHeaders) ) ) ), delete(() -> // DELETE /policies/<policyId> handlePerRequest(ctx, DeletePolicy.of(policyId, dittoHeaders)) ) ) ); }
private Route thingsEntryPolicyEntry(final RequestContext ctx, final DittoHeaders dittoHeaders, final String policyId) { return rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment()), label -> pathEndOrSingleSlash(() -> route( get(() -> // GET /entries/<label> handlePerRequest(ctx, RetrievePolicyEntry.of(policyId, Label.of(label), dittoHeaders)) ), put(() -> // PUT /entries/<label> extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, policyEntryJson -> ModifyPolicyEntry .of(policyId, createPolicyEntryForPut(policyEntryJson, label), dittoHeaders)) ) ), delete(() -> // DELETE /entries/<label> handlePerRequest(ctx, DeletePolicyEntry.of(policyId, Label.of(label), dittoHeaders))) ) ) ); }
private Route thingsEntryPolicyEntrySubjects(final RequestContext ctx, final DittoHeaders dittoHeaders, final String policyId) { return rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment()), label -> rawPathPrefix(mergeDoubleSlashes().concat(PATH_SUFFIX_SUBJECTS), () -> pathEndOrSingleSlash(() -> route( get(() -> // GET /entries/<label>/subjects handlePerRequest(ctx, RetrieveSubjects.of(policyId, Label.of(label), dittoHeaders)) ), put(() -> // PUT /entries/<label>/subjects extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, subjectsJson -> ModifySubjects.of(policyId, Label.of(label), PoliciesModelFactory.newSubjects( JsonFactory.newObject( subjectsJson)), dittoHeaders))) ) ) ) ) ); }
private Route featuresEntryDefinition(final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId) { return rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment()), featureId -> rawPathPrefix(mergeDoubleSlashes().concat(PATH_DEFINITION), () -> pathEndOrSingleSlash(() -> route( get(() -> // GET /features/{featureId}/definition handlePerRequest(ctx, RetrieveFeatureDefinition.of(thingId, featureId, dittoHeaders)) ), put(() -> // PUT /features/{featureId}/definition extractDataBytes(payloadSource -> handlePerRequest(ctx, dittoHeaders, payloadSource, definitionJson -> ModifyFeatureDefinition.of(thingId, featureId, ThingsModelFactory. newFeatureDefinition( definitionJson), dittoHeaders)) ) ), delete(() -> // DELETE /features/{featureId}/definition handlePerRequest(ctx, DeleteFeatureDefinition.of(thingId, featureId, dittoHeaders)) ) ) ) ) ); }