Skip to content

Commit

Permalink
hide details about the "namespace hotness" behind secured HTTP resource
Browse files Browse the repository at this point in the history
* added new resource /stats/things/details secured with devops auth
* split up statistics into publicly available ones (a.k.a hotness)
  and secured ones (hotness per namespace)

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch-si.com>
  • Loading branch information
thjaeckle committed Jul 23, 2018
1 parent 7e38117 commit 4ad05d3
Show file tree
Hide file tree
Showing 12 changed files with 505 additions and 146 deletions.
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.ditto.signals.commands.base.CommandResponse;
import org.eclipse.ditto.signals.commands.base.ErrorResponse;
import org.eclipse.ditto.signals.commands.base.WithEntity;
import org.eclipse.ditto.signals.commands.devops.RetrieveStatisticsResponse;
import org.eclipse.ditto.signals.commands.messages.MessageCommand;
import org.eclipse.ditto.signals.commands.messages.MessageCommandResponse;
import org.eclipse.ditto.signals.commands.messages.SendMessageAcceptedResponse;
Expand Down Expand Up @@ -153,15 +152,6 @@ private HttpRequestActor(final ActorRef proxyActor, final HttpRequest request,
completeWithResult(HttpResponse.create().withStatus(HttpStatusCode.INTERNAL_SERVER_ERROR.toInt())
);
})
.match(RetrieveStatisticsResponse.class, statisticsResponse -> {
logger.debug("Got 'RetrieveStatisticsResponse' message");
final JsonObject statisticsJson = statisticsResponse.getStatistics();
completeWithResult(
HttpResponse.create()
.withEntity(CONTENT_TYPE_JSON, ByteString.fromString(statisticsJson.toString()))
.withStatus(HttpStatusCode.OK.toInt())
);
})
.match(Status.Failure.class, f -> f.cause() instanceof AskTimeoutException, failure -> {
logger.warning("Got AskTimeoutException when a command response was expected: '{}'",
failure.cause().getMessage());
Expand Down
Expand Up @@ -16,7 +16,10 @@
import static akka.http.javadsl.server.Directives.get;
import static akka.http.javadsl.server.Directives.path;
import static akka.http.javadsl.server.Directives.pathEndOrSingleSlash;
import static akka.http.javadsl.server.Directives.pathPrefix;
import static akka.http.javadsl.server.Directives.route;
import static org.eclipse.ditto.services.gateway.endpoints.directives.DevopsBasicAuthenticationDirective.REALM_DEVOPS;
import static org.eclipse.ditto.services.gateway.endpoints.directives.DevopsBasicAuthenticationDirective.authenticateDevopsBasic;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
Expand All @@ -31,6 +34,7 @@
import org.eclipse.ditto.services.models.thingsearch.commands.sudo.SudoCountThings;
import org.eclipse.ditto.signals.commands.devops.DevOpsCommand;
import org.eclipse.ditto.signals.commands.devops.RetrieveStatistics;
import org.eclipse.ditto.signals.commands.devops.RetrieveStatisticsDetails;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
Expand All @@ -52,6 +56,7 @@ public final class StatsRoute extends AbstractRoute {
static final String STATISTICS_PATH_PREFIX = "stats";
static final String THINGS_PATH = "things";
static final String SEARCH_PATH = "search";
private static final String DETAILS_PATH = "details";

/**
* Constructs the {@code /stats} route builder.
Expand All @@ -72,29 +77,35 @@ public StatsRoute(final ActorRef proxyActor, final ActorSystem actorSystem) {
public Route buildStatsRoute(final String correlationId) {
return Directives.rawPathPrefix(CustomPathMatchers.mergeDoubleSlashes().concat(STATISTICS_PATH_PREFIX),
() -> // /stats/*
extractRequestContext(ctx ->
get(() -> // GET
buildSubRoutes(ctx, correlationId)
extractRequestContext(ctx ->
get(() -> // GET
buildSubRoutes(ctx, correlationId)
)
)
)
);
}

private Route buildSubRoutes(final RequestContext ctx, final String correlationId) {
return route(
path(THINGS_PATH, () -> // /stats/things
pathEndOrSingleSlash(() ->
handleDevOpsPerRequest(ctx,
RetrieveStatistics.of(
buildDevOpsDittoHeaders(correlationId)))
pathPrefix(THINGS_PATH, () -> // /stats/things
route(
path(DETAILS_PATH, () ->
authenticateDevopsBasic(REALM_DEVOPS,
handleDevOpsPerRequest(ctx,
RetrieveStatisticsDetails.of(
buildDevOpsDittoHeaders(correlationId))))
),
pathEndOrSingleSlash(() ->
handleDevOpsPerRequest(ctx,
RetrieveStatistics.of(
buildDevOpsDittoHeaders(correlationId)))
)
)
),
path(SEARCH_PATH, () -> // /stats/search
pathEndOrSingleSlash(() ->
handleSudoCountThingsPerRequest(ctx,
SudoCountThings.of(
buildDevOpsDittoHeaders(correlationId)))
)
handleSudoCountThingsPerRequest(ctx,
SudoCountThings.of(
buildDevOpsDittoHeaders(correlationId)))
)
);
}
Expand Down
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.ditto.services.utils.akka.LogUtil;
import org.eclipse.ditto.signals.base.Signal;
import org.eclipse.ditto.signals.commands.devops.RetrieveStatistics;
import org.eclipse.ditto.signals.commands.devops.RetrieveStatisticsDetails;

import akka.actor.AbstractActor;
import akka.actor.ActorKilledException;
Expand Down Expand Up @@ -84,6 +85,10 @@ public Receive createReceive() {
.match(RetrieveStatistics.class, retrieveStatistics -> {
log.debug("Got 'RetrieveStatistics' message");
statisticsActor.forward(retrieveStatistics, getContext());
})
.match(RetrieveStatisticsDetails.class, retrieveStatisticsDetails -> {
log.debug("Got 'RetrieveStatisticsDetails' message");
statisticsActor.forward(retrieveStatisticsDetails, getContext());
});

// specific commands
Expand Down

0 comments on commit 4ad05d3

Please sign in to comment.