Search in sources :

Example 11 with Route

use of akka.http.javadsl.server.Route in project ditto by eclipse.

the class RequestResultLoggingDirective method logRequestResult.

/**
 * Logs the StatusCode and duration of the route.
 *
 * @param correlationId the correlationId which will be added to the log
 * @param inner the inner Route to be logged
 * @return the new Route wrapping {@code inner} with logging
 */
public static Route logRequestResult(final CharSequence correlationId, final Supplier<Route> inner) {
    // add akka standard logging to the route
    final Supplier<Route> innerWithAkkaLoggingRoute = () -> logRequest("http-request", () -> logResult("http-response", inner));
    // code is inspired by DebuggingDirectives#logRequestResult
    return extractRequest(request -> {
        final String requestMethod = request.method().name();
        final String filteredRelativeRequestUri = filterUri(request.getUri().toRelative()).toString();
        return mapRouteResult(routeResult -> {
            final ThreadSafeDittoLogger logger = LOGGER.withCorrelationId(correlationId);
            if (routeResult instanceof Complete) {
                final Complete complete = (Complete) routeResult;
                final int statusCode = complete.getResponse().status().intValue();
                logger.info("StatusCode of request {} '{}' was: {}", requestMethod, filteredRelativeRequestUri, statusCode);
                if (logger.isDebugEnabled()) {
                    final String filteredRawRequestUri = filterRawUri(HttpUtils.getRawRequestUri(request));
                    logger.debug("Raw request URI was: {}", filteredRawRequestUri);
                }
                request.getHeader(DITTO_TRACE_HEADERS).filter(unused -> TRACE_LOGGER.isDebugEnabled()).ifPresent(unused -> TRACE_LOGGER.withCorrelationId(correlationId).debug("Request headers: {}", filterHeaders(request.getHeaders())));
            } else {
                /* routeResult could be Rejected, if no route is able to handle the request -> but this should
                            not happen when rejections are handled before this directive is called. */
                logger.warn("Unexpected routeResult for request {} '{}': {}, routeResult will be handled by " + "akka default RejectionHandler.", requestMethod, filteredRelativeRequestUri, routeResult);
            }
            return routeResult;
        }, innerWithAkkaLoggingRoute);
    });
}
Also used : Directives.logRequest(akka.http.javadsl.server.Directives.logRequest) RequestLoggingFilter.filterHeaders(org.eclipse.ditto.gateway.service.endpoints.directives.RequestLoggingFilter.filterHeaders) Route(akka.http.javadsl.server.Route) RequestLoggingFilter.filterRawUri(org.eclipse.ditto.gateway.service.endpoints.directives.RequestLoggingFilter.filterRawUri) DittoLoggerFactory(org.eclipse.ditto.internal.utils.akka.logging.DittoLoggerFactory) Supplier(java.util.function.Supplier) HttpUtils(org.eclipse.ditto.gateway.service.endpoints.utils.HttpUtils) ThreadSafeDittoLogger(org.eclipse.ditto.internal.utils.akka.logging.ThreadSafeDittoLogger) Directives.extractRequest(akka.http.javadsl.server.Directives.extractRequest) Complete(akka.http.javadsl.server.Complete) RequestLoggingFilter.filterUri(org.eclipse.ditto.gateway.service.endpoints.directives.RequestLoggingFilter.filterUri) Directives.logResult(akka.http.javadsl.server.Directives.logResult) Directives.mapRouteResult(akka.http.javadsl.server.Directives.mapRouteResult) ThreadSafeDittoLogger(org.eclipse.ditto.internal.utils.akka.logging.ThreadSafeDittoLogger) Complete(akka.http.javadsl.server.Complete) Route(akka.http.javadsl.server.Route)

Example 12 with Route

use of akka.http.javadsl.server.Route in project mantis by Netflix.

the class JobClusterRoute method getJobClusterRoutes.

private Route getJobClusterRoutes() {
    return route(path(segment("api").slash("submit"), () -> decodeRequest(() -> entity(Unmarshaller.entityToString(), request -> {
        logger.debug("/api/submit called {}", request);
        try {
            MantisJobDefinition mjd = Jackson.fromJSON(request, MantisJobDefinition.class);
            logger.debug("job submit request {}", mjd);
            mjd.validate(true);
            Pair<Boolean, String> validationResult = validateSubmitJobRequest(mjd);
            if (!validationResult.first()) {
                jobClusterSubmitError.increment();
                return complete(StatusCodes.BAD_REQUEST, "{\"error\": \"" + validationResult.second() + "\"}");
            }
            jobClusterSubmit.increment();
            return completeWithFuture(jobClusterRouteHandler.submit(JobClusterProtoAdapter.toSubmitJobClusterRequest(mjd)).thenApply(this::toHttpResponse));
        } catch (Exception e) {
            logger.warn("exception in submit job request {}", request, e);
            jobClusterSubmitError.increment();
            return complete(StatusCodes.INTERNAL_SERVER_ERROR, "{\"error\": \"" + e.getMessage() + "\"}");
        }
    }))), pathPrefix(API_V0_JOBCLUSTER, () -> route(post(() -> route(path("create", () -> decodeRequest(() -> entity(Unmarshaller.entityToString(), jobClusterDefn -> {
        logger.debug("/api/namedjob/create called {}", jobClusterDefn);
        try {
            final NamedJobDefinition namedJobDefinition = Jackson.fromJSON(jobClusterDefn, NamedJobDefinition.class);
            if (namedJobDefinition == null || namedJobDefinition.getJobDefinition() == null || namedJobDefinition.getJobDefinition().getJobJarFileLocation() == null || namedJobDefinition.getJobDefinition().getName() == null || namedJobDefinition.getJobDefinition().getName().isEmpty()) {
                logger.warn("JobCluster create request must include name and URL {}", jobClusterDefn);
                return complete(StatusCodes.BAD_REQUEST, "{\"error\": \"Job definition must include name and URL\"}");
            }
            final CompletionStage<CreateJobClusterResponse> response = jobClusterRouteHandler.create(JobClusterProtoAdapter.toCreateJobClusterRequest(namedJobDefinition));
            jobClusterCreate.increment();
            return completeWithFuture(response.thenApply(r -> {
                if ((r.responseCode == CLIENT_ERROR || r.responseCode == CLIENT_ERROR_CONFLICT) && r.message.contains("already exists")) {
                    return new CreateJobClusterResponse(r.requestId, SERVER_ERROR, r.message, r.getJobClusterName());
                }
                return r;
            }).thenApply(this::toHttpResponse));
        } catch (IOException e) {
            logger.warn("Error creating JobCluster {}", jobClusterDefn, e);
            jobClusterCreateError.increment();
            return complete(StatusCodes.BAD_REQUEST, "Can't read valid json in request: " + e.getMessage());
        } catch (Exception e) {
            logger.warn("Error creating JobCluster {}", jobClusterDefn, e);
            jobClusterCreateError.increment();
            return complete(StatusCodes.INTERNAL_SERVER_ERROR, "{\"error\": " + e.getMessage() + "}");
        }
    }))), path("update", () -> decodeRequest(() -> entity(Unmarshaller.entityToString(), jobClusterDefn -> {
        logger.debug("/api/namedjob/update called {}", jobClusterDefn);
        try {
            final NamedJobDefinition namedJobDefinition = Jackson.fromJSON(jobClusterDefn, NamedJobDefinition.class);
            if (namedJobDefinition == null || namedJobDefinition.getJobDefinition() == null || namedJobDefinition.getJobDefinition().getJobJarFileLocation() == null || namedJobDefinition.getJobDefinition().getName() == null || namedJobDefinition.getJobDefinition().getName().isEmpty()) {
                logger.warn("JobCluster update request must include name and URL {}", jobClusterDefn);
                jobClusterCreateUpdateError.increment();
                return complete(StatusCodes.BAD_REQUEST, "{\"error\": \"Job definition must include name and URL\"}");
            }
            final CompletionStage<UpdateJobClusterResponse> response = jobClusterRouteHandler.update(JobClusterProtoAdapter.toUpdateJobClusterRequest(namedJobDefinition));
            jobClusterCreateUpdate.increment();
            return completeWithFuture(response.thenApply(this::toHttpResponse));
        } catch (IOException e) {
            logger.warn("Error updating JobCluster {}", jobClusterDefn, e);
            jobClusterCreateUpdateError.increment();
            return complete(StatusCodes.BAD_REQUEST, "Can't read valid json in request: " + e.getMessage());
        } catch (Exception e) {
            logger.warn("Error updating JobCluster {}", jobClusterDefn, e);
            jobClusterCreateUpdateError.increment();
            return complete(StatusCodes.INTERNAL_SERVER_ERROR, "{\"error\": " + e.getMessage() + "}");
        }
    }))), path("delete", () -> decodeRequest(() -> entity(Unmarshaller.entityToString(), deleteReq -> {
        logger.debug("/api/namedjob/delete called {}", deleteReq);
        try {
            final DeleteJobClusterRequest deleteJobClusterRequest = Jackson.fromJSON(deleteReq, DeleteJobClusterRequest.class);
            final CompletionStage<DeleteJobClusterResponse> response = jobClusterRouteHandler.delete(deleteJobClusterRequest);
            jobClusterDelete.increment();
            return completeWithFuture(response.thenApply(this::toHttpResponse));
        } catch (IOException e) {
            logger.warn("Error deleting JobCluster {}", deleteReq, e);
            jobClusterDeleteError.increment();
            return complete(StatusCodes.BAD_REQUEST, "Can't find valid json in request: " + e.getMessage());
        }
    }))), path("disable", () -> decodeRequest(() -> entity(Unmarshaller.entityToString(), request -> {
        logger.debug("/api/namedjob/disable called {}", request);
        try {
            final DisableJobClusterRequest disableJobClusterRequest = Jackson.fromJSON(request, DisableJobClusterRequest.class);
            final CompletionStage<DisableJobClusterResponse> response = jobClusterRouteHandler.disable(disableJobClusterRequest);
            jobClusterDisable.increment();
            return completeWithFuture(response.thenApply(this::toHttpResponse));
        } catch (IOException e) {
            logger.warn("Error disabling JobCluster {}", request, e);
            jobClusterDisableError.increment();
            return complete(StatusCodes.BAD_REQUEST, "Can't find valid json in request: " + e.getMessage());
        }
    }))), path("enable", () -> decodeRequest(() -> entity(Unmarshaller.entityToString(), request -> {
        logger.debug("/api/namedjob/enable called {}", request);
        try {
            final EnableJobClusterRequest enableJobClusterRequest = Jackson.fromJSON(request, EnableJobClusterRequest.class);
            final CompletionStage<EnableJobClusterResponse> response = jobClusterRouteHandler.enable(enableJobClusterRequest);
            jobClusterEnable.increment();
            return completeWithFuture(response.thenApply(this::toHttpResponse));
        } catch (IOException e) {
            logger.warn("Error enabling JobCluster {}", request, e);
            jobClusterEnableError.increment();
            return complete(StatusCodes.BAD_REQUEST, "Can't find valid json in request: " + e.getMessage());
        }
    }))), path("quickupdate", () -> decodeRequest(() -> entity(Unmarshaller.entityToString(), request -> {
        logger.debug("/api/namedjob/quickupdate called {}", request);
        try {
            final UpdateJobClusterArtifactRequest updateJobClusterArtifactRequest = Jackson.fromJSON(request, UpdateJobClusterArtifactRequest.class);
            final CompletionStage<UpdateJobClusterArtifactResponse> response = jobClusterRouteHandler.updateArtifact(updateJobClusterArtifactRequest);
            jobClusterQuickupdate.increment();
            return completeWithFuture(response.thenApply(this::toHttpResponse));
        } catch (IOException e) {
            logger.warn("Error on quickupdate for JobCluster {}", request, e);
            jobClusterQuickupdateError.increment();
            return complete(StatusCodes.BAD_REQUEST, "Can't find valid json in request: " + e.getMessage());
        }
    }))), path("updatelabels", () -> decodeRequest(() -> entity(Unmarshaller.entityToString(), request -> {
        logger.debug("/api/namedjob/updatelabels called {}", request);
        try {
            final UpdateJobClusterLabelsRequest updateJobClusterLabelsRequest = Jackson.fromJSON(request, UpdateJobClusterLabelsRequest.class);
            jobClusterUpdateLabel.increment();
            return completeWithFuture(jobClusterRouteHandler.updateLabels(updateJobClusterLabelsRequest).thenApply(this::toHttpResponse));
        } catch (IOException e) {
            logger.warn("Error updating labels for JobCluster {}", request, e);
            jobClusterUpdateLabelError.increment();
            return complete(StatusCodes.BAD_REQUEST, "Can't find valid json in request: " + e.getMessage());
        }
    }))), path("updatesla", () -> decodeRequest(() -> entity(Unmarshaller.entityToString(), request -> {
        logger.debug("/api/namedjob/updatesla called {}", request);
        jobClusterUpdateSla.increment();
        try {
            final UpdateJobClusterSLARequest updateJobClusterSLARequest = Jackson.fromJSON(request, UpdateJobClusterSLARequest.class);
            return completeWithFuture(jobClusterRouteHandler.updateSLA(updateJobClusterSLARequest).thenApply(this::toHttpResponse));
        } catch (IOException e) {
            logger.warn("Error updating SLA for JobCluster {}", request, e);
            jobClusterUpdateSlaError.increment();
            return complete(StatusCodes.BAD_REQUEST, "Can't find valid json in request: " + e.getMessage());
        }
    }))), path("migratestrategy", () -> decodeRequest(() -> entity(Unmarshaller.entityToString(), request -> {
        logger.debug("/api/namedjob/migratestrategy called {}", request);
        try {
            final UpdateJobClusterWorkerMigrationStrategyRequest updateMigrateStrategyReq = Jackson.fromJSON(request, UpdateJobClusterWorkerMigrationStrategyRequest.class);
            return completeWithFuture(jobClusterRouteHandler.updateWorkerMigrateStrategy(updateMigrateStrategyReq).thenApply(this::toHttpResponse));
        } catch (IOException e) {
            logger.warn("Error updating migrate strategy for JobCluster {}", request, e);
            return complete(StatusCodes.BAD_REQUEST, "Can't find valid json in request: " + e.getMessage());
        }
    }))), path("quicksubmit", () -> decodeRequest(() -> entity(Unmarshaller.entityToString(), request -> {
        logger.debug("/api/namedjob/quicksubmit called {}", request);
        try {
            final JobClusterManagerProto.SubmitJobRequest submitJobRequest = Jackson.fromJSON(request, JobClusterManagerProto.SubmitJobRequest.class);
            return completeWithFuture(jobClusterRouteHandler.submit(submitJobRequest).thenApply(this::toHttpResponse));
        } catch (IOException e) {
            logger.warn("Error on quick submit for JobCluster {}", request, e);
            return complete(StatusCodes.BAD_REQUEST, "Can't find valid json in request: " + e.getMessage());
        }
    }))))), get(() -> route(pathPrefix("list", () -> route(pathEndOrSingleSlash(() -> {
        logger.debug("/api/namedjob/list called");
        jobClusterListGET.increment();
        return alwaysCache(cache, requestUriKeyer, () -> extractUri(uri -> completeAsync(jobClusterRouteHandler.getAllJobClusters(new ListJobClustersRequest()), resp -> completeOK(resp.getJobClusters().stream().map(jobClusterMetadataView -> JobClusterProtoAdapter.toJobClusterInfo(jobClusterMetadataView)).collect(Collectors.toList()), Jackson.marshaller()), resp -> completeOK(Collections.emptyList(), Jackson.marshaller()))));
    }), path(PathMatchers.segment(), (jobCluster) -> {
        if (logger.isDebugEnabled()) {
            logger.debug("/api/namedjob/list/{} called", jobCluster);
        }
        jobClusterListClusterGET.increment();
        return completeAsync(jobClusterRouteHandler.getJobClusterDetails(new JobClusterManagerProto.GetJobClusterRequest(jobCluster)), resp -> completeOK(resp.getJobCluster().map(jc -> Arrays.asList(jc)).orElse(Collections.emptyList()), Jackson.marshaller()), resp -> completeOK(Collections.emptyList(), Jackson.marshaller()));
    }))), path(segment("listJobIds").slash(PathMatchers.segment()), (jobCluster) -> {
        logger.debug("/api/namedjob/listJobIds/{} called", jobCluster);
        jobClusterListJobIdGET.increment();
        return jobClusterListRoute(jobCluster);
    }), path("listJobIds", () -> {
        logger.debug("/api/namedjob/listJobIds called");
        return complete(StatusCodes.BAD_REQUEST, "Specify the Job cluster name '/api/namedjob/listJobIds/<JobClusterName>' to list the job Ids");
    }))))));
}
Also used : Strings(io.mantisrx.shaded.com.google.common.base.Strings) EnableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterResponse) Uri(akka.http.javadsl.model.Uri) MasterConfiguration(io.mantisrx.server.master.config.MasterConfiguration) Arrays(java.util.Arrays) JavaPartialFunction(akka.japi.JavaPartialFunction) Cache(akka.http.caching.javadsl.Cache) JobRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobRouteHandler) LoggerFactory(org.slf4j.LoggerFactory) LfuCache(akka.http.caching.LfuCache) RequestContext(akka.http.javadsl.server.RequestContext) StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) PathMatchers.segment(akka.http.javadsl.server.PathMatchers.segment) MantisJobDefinition(io.mantisrx.runtime.MantisJobDefinition) CLIENT_ERROR(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.CLIENT_ERROR) StringUnmarshallers(akka.http.javadsl.unmarshalling.StringUnmarshallers) PathMatcher0(akka.http.javadsl.server.PathMatcher0) LfuCacheSettings(akka.http.caching.javadsl.LfuCacheSettings) UpdateJobClusterArtifactResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactResponse) DeleteJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DeleteJobClusterRequest) Map(java.util.Map) JobClusterProtoAdapter(io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter) Unmarshaller(akka.http.javadsl.unmarshalling.Unmarshaller) Metrics(io.mantisrx.common.metrics.Metrics) DisableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest) DisableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterResponse) Jackson(io.mantisrx.master.api.akka.route.Jackson) UpdateJobClusterLabelsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsRequest) HttpMethods(akka.http.javadsl.model.HttpMethods) Collectors(java.util.stream.Collectors) ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) JobClusterRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobClusterRouteHandler) Duration(scala.concurrent.duration.Duration) CompletionStage(java.util.concurrent.CompletionStage) UpdateJobClusterWorkerMigrationStrategyRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterWorkerMigrationStrategyRequest) JobRouteUtils.createListJobIdsRequest(io.mantisrx.master.api.akka.route.utils.JobRouteUtils.createListJobIdsRequest) CachingDirectives.alwaysCache(akka.http.javadsl.server.directives.CachingDirectives.alwaysCache) ActorSystem(akka.actor.ActorSystem) ConfigurationProvider(io.mantisrx.server.master.config.ConfigurationProvider) StageScalingPolicy(io.mantisrx.runtime.descriptor.StageScalingPolicy) Optional(java.util.Optional) CLIENT_ERROR_CONFLICT(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.CLIENT_ERROR_CONFLICT) UpdateJobClusterSLARequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLARequest) SERVER_ERROR(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SERVER_ERROR) UpdateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterResponse) ListJobClustersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobClustersRequest) Route(akka.http.javadsl.server.Route) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) StatusCodes(akka.http.javadsl.model.StatusCodes) Function(java.util.function.Function) PathMatchers(akka.http.javadsl.server.PathMatchers) DeleteJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DeleteJobClusterResponse) SchedulingInfo(io.mantisrx.runtime.descriptor.SchedulingInfo) Counter(io.mantisrx.common.metrics.Counter) Logger(org.slf4j.Logger) RouteResult(akka.http.javadsl.server.RouteResult) HttpHeader(akka.http.javadsl.model.HttpHeader) HttpRequest(akka.http.javadsl.model.HttpRequest) NamedJobDefinition(io.mantisrx.runtime.NamedJobDefinition) EnableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterRequest) IOException(java.io.IOException) CreateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.CreateJobClusterResponse) Pair(akka.japi.Pair) TimeUnit(java.util.concurrent.TimeUnit) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) UpdateJobClusterArtifactRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactRequest) CachingSettings(akka.http.caching.javadsl.CachingSettings) Collections(java.util.Collections) UpdateJobClusterLabelsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsRequest) UpdateJobClusterSLARequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLARequest) MantisJobDefinition(io.mantisrx.runtime.MantisJobDefinition) ListJobClustersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobClustersRequest) IOException(java.io.IOException) IOException(java.io.IOException) DisableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest) UpdateJobClusterArtifactRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactRequest) EnableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterRequest) UpdateJobClusterWorkerMigrationStrategyRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterWorkerMigrationStrategyRequest) DeleteJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DeleteJobClusterRequest) NamedJobDefinition(io.mantisrx.runtime.NamedJobDefinition) CreateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.CreateJobClusterResponse) CompletionStage(java.util.concurrent.CompletionStage) Pair(akka.japi.Pair) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto)

Example 13 with Route

use of akka.http.javadsl.server.Route in project mantis by Netflix.

the class JobClusterRoute method createRoute.

public Route createRoute(Function<Route, Route> routeFilter) {
    logger.info("creating routes");
    final ExceptionHandler genericExceptionHandler = ExceptionHandler.newBuilder().match(Exception.class, e -> {
        logger.error("got exception", e);
        return complete(StatusCodes.INTERNAL_SERVER_ERROR, "{\"error\": \"" + e.getMessage() + "\"}");
    }).build();
    return respondWithHeaders(DEFAULT_RESPONSE_HEADERS, () -> handleExceptions(genericExceptionHandler, () -> routeFilter.apply(getJobClusterRoutes())));
}
Also used : ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) Strings(io.mantisrx.shaded.com.google.common.base.Strings) EnableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterResponse) Uri(akka.http.javadsl.model.Uri) MasterConfiguration(io.mantisrx.server.master.config.MasterConfiguration) Arrays(java.util.Arrays) JavaPartialFunction(akka.japi.JavaPartialFunction) Cache(akka.http.caching.javadsl.Cache) JobRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobRouteHandler) LoggerFactory(org.slf4j.LoggerFactory) LfuCache(akka.http.caching.LfuCache) RequestContext(akka.http.javadsl.server.RequestContext) StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) PathMatchers.segment(akka.http.javadsl.server.PathMatchers.segment) MantisJobDefinition(io.mantisrx.runtime.MantisJobDefinition) CLIENT_ERROR(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.CLIENT_ERROR) StringUnmarshallers(akka.http.javadsl.unmarshalling.StringUnmarshallers) PathMatcher0(akka.http.javadsl.server.PathMatcher0) LfuCacheSettings(akka.http.caching.javadsl.LfuCacheSettings) UpdateJobClusterArtifactResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactResponse) DeleteJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DeleteJobClusterRequest) Map(java.util.Map) JobClusterProtoAdapter(io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter) Unmarshaller(akka.http.javadsl.unmarshalling.Unmarshaller) Metrics(io.mantisrx.common.metrics.Metrics) DisableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest) DisableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterResponse) Jackson(io.mantisrx.master.api.akka.route.Jackson) UpdateJobClusterLabelsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsRequest) HttpMethods(akka.http.javadsl.model.HttpMethods) Collectors(java.util.stream.Collectors) ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) JobClusterRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobClusterRouteHandler) Duration(scala.concurrent.duration.Duration) CompletionStage(java.util.concurrent.CompletionStage) UpdateJobClusterWorkerMigrationStrategyRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterWorkerMigrationStrategyRequest) JobRouteUtils.createListJobIdsRequest(io.mantisrx.master.api.akka.route.utils.JobRouteUtils.createListJobIdsRequest) CachingDirectives.alwaysCache(akka.http.javadsl.server.directives.CachingDirectives.alwaysCache) ActorSystem(akka.actor.ActorSystem) ConfigurationProvider(io.mantisrx.server.master.config.ConfigurationProvider) StageScalingPolicy(io.mantisrx.runtime.descriptor.StageScalingPolicy) Optional(java.util.Optional) CLIENT_ERROR_CONFLICT(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.CLIENT_ERROR_CONFLICT) UpdateJobClusterSLARequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLARequest) SERVER_ERROR(io.mantisrx.master.jobcluster.proto.BaseResponse.ResponseCode.SERVER_ERROR) UpdateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterResponse) ListJobClustersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobClustersRequest) Route(akka.http.javadsl.server.Route) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) StatusCodes(akka.http.javadsl.model.StatusCodes) Function(java.util.function.Function) PathMatchers(akka.http.javadsl.server.PathMatchers) DeleteJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DeleteJobClusterResponse) SchedulingInfo(io.mantisrx.runtime.descriptor.SchedulingInfo) Counter(io.mantisrx.common.metrics.Counter) Logger(org.slf4j.Logger) RouteResult(akka.http.javadsl.server.RouteResult) HttpHeader(akka.http.javadsl.model.HttpHeader) HttpRequest(akka.http.javadsl.model.HttpRequest) NamedJobDefinition(io.mantisrx.runtime.NamedJobDefinition) EnableJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterRequest) IOException(java.io.IOException) CreateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.CreateJobClusterResponse) Pair(akka.japi.Pair) TimeUnit(java.util.concurrent.TimeUnit) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) UpdateJobClusterArtifactRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterArtifactRequest) CachingSettings(akka.http.caching.javadsl.CachingSettings) Collections(java.util.Collections) IOException(java.io.IOException)

Example 14 with Route

use of akka.http.javadsl.server.Route in project mantis by Netflix.

the class JobRoute method createRoute.

public Route createRoute(Function<Route, Route> routeFilter) {
    logger.info("creating routes");
    final ExceptionHandler genericExceptionHandler = ExceptionHandler.newBuilder().match(Exception.class, x -> {
        logger.error("got exception", x);
        return complete(StatusCodes.INTERNAL_SERVER_ERROR, "{\"error\": \"" + x.getMessage() + "\"}");
    }).build();
    return respondWithHeaders(DEFAULT_RESPONSE_HEADERS, () -> handleExceptions(genericExceptionHandler, () -> routeFilter.apply(getJobRoutes())));
}
Also used : ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) JobId(io.mantisrx.server.master.domain.JobId) Uri(akka.http.javadsl.model.Uri) MasterConfiguration(io.mantisrx.server.master.config.MasterConfiguration) Arrays(java.util.Arrays) JavaPartialFunction(akka.japi.JavaPartialFunction) Cache(akka.http.caching.javadsl.Cache) JobRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobRouteHandler) LoggerFactory(org.slf4j.LoggerFactory) RequestContext(akka.http.javadsl.server.RequestContext) PathMatchers.segment(akka.http.javadsl.server.PathMatchers.segment) StringUnmarshallers(akka.http.javadsl.unmarshalling.StringUnmarshallers) PathMatcher0(akka.http.javadsl.server.PathMatcher0) ListArchivedWorkersRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListArchivedWorkersRequest) JobClusterProtoAdapter(io.mantisrx.master.api.akka.route.proto.JobClusterProtoAdapter) Unmarshaller(akka.http.javadsl.unmarshalling.Unmarshaller) Metrics(io.mantisrx.common.metrics.Metrics) ResubmitWorkerRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ResubmitWorkerRequest) PostJobStatusRequest(io.mantisrx.server.core.PostJobStatusRequest) Jackson(io.mantisrx.master.api.akka.route.Jackson) BaseResponse(io.mantisrx.master.jobcluster.proto.BaseResponse) ScaleStageRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ScaleStageRequest) HttpMethods(akka.http.javadsl.model.HttpMethods) Collectors(java.util.stream.Collectors) ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) List(java.util.List) JobRouteUtils.createListJobIdsRequest(io.mantisrx.master.api.akka.route.utils.JobRouteUtils.createListJobIdsRequest) CachingDirectives.alwaysCache(akka.http.javadsl.server.directives.CachingDirectives.alwaysCache) ActorSystem(akka.actor.ActorSystem) ConfigurationProvider(io.mantisrx.server.master.config.ConfigurationProvider) Optional(java.util.Optional) DataFormatAdapter(io.mantisrx.server.master.domain.DataFormatAdapter) MantisJobMetadataView(io.mantisrx.master.jobcluster.job.MantisJobMetadataView) MantisWorkerMetadataWritable(io.mantisrx.server.master.store.MantisWorkerMetadataWritable) JobRouteUtils.createListJobsRequest(io.mantisrx.master.api.akka.route.utils.JobRouteUtils.createListJobsRequest) Route(akka.http.javadsl.server.Route) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) StatusCodes(akka.http.javadsl.model.StatusCodes) Function(java.util.function.Function) PathMatchers(akka.http.javadsl.server.PathMatchers) WorkerEvent(io.mantisrx.server.master.scheduler.WorkerEvent) KillJobRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.KillJobRequest) Counter(io.mantisrx.common.metrics.Counter) Logger(org.slf4j.Logger) RouteResult(akka.http.javadsl.server.RouteResult) HttpHeader(akka.http.javadsl.model.HttpHeader) HttpRequest(akka.http.javadsl.model.HttpRequest) IOException(java.io.IOException) DEFAULT_LIST_ARCHIVED_WORKERS_LIMIT(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListArchivedWorkersRequest.DEFAULT_LIST_ARCHIVED_WORKERS_LIMIT) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) JobRouteUtils.createWorkerStatusRequest(io.mantisrx.master.api.akka.route.utils.JobRouteUtils.createWorkerStatusRequest) Collections(java.util.Collections) WorkerHeartbeat(io.mantisrx.master.jobcluster.job.worker.WorkerHeartbeat) IOException(java.io.IOException)

Example 15 with Route

use of akka.http.javadsl.server.Route in project mantis by Netflix.

the class MasterDescriptionRoute method createRoute.

public Route createRoute(Function<Route, Route> routeFilter) {
    logger.info("creating routes");
    final ExceptionHandler jsonExceptionHandler = ExceptionHandler.newBuilder().match(IOException.class, x -> {
        logger.error("got exception", x);
        return complete(StatusCodes.BAD_REQUEST, "caught exception " + x.getMessage());
    }).build();
    return respondWithHeaders(DEFAULT_RESPONSE_HEADERS, () -> handleExceptions(jsonExceptionHandler, () -> routeFilter.apply(getMasterDescRoute())));
}
Also used : ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) MasterConfiguration(io.mantisrx.server.master.config.MasterConfiguration) Arrays(java.util.Arrays) ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper) Route(akka.http.javadsl.server.Route) WorkerMigrationConfig(io.mantisrx.runtime.WorkerMigrationConfig) MasterDescription(io.mantisrx.server.core.master.MasterDescription) JobConstraints(io.mantisrx.runtime.JobConstraints) LoggerFactory(org.slf4j.LoggerFactory) StatusCodes(akka.http.javadsl.model.StatusCodes) PathMatchers.segment(akka.http.javadsl.server.PathMatchers.segment) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Logger(org.slf4j.Logger) JsonProcessingException(io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException) HttpHeader(akka.http.javadsl.model.HttpHeader) Jackson(io.mantisrx.master.api.akka.route.Jackson) JsonIgnoreProperties(io.mantisrx.shaded.com.fasterxml.jackson.annotation.JsonIgnoreProperties) JsonProperty(io.mantisrx.shaded.com.fasterxml.jackson.annotation.JsonProperty) IOException(java.io.IOException) ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) Objects(java.util.Objects) DeserializationFeature(io.mantisrx.shaded.com.fasterxml.jackson.databind.DeserializationFeature) List(java.util.List) ConfigurationProvider(io.mantisrx.server.master.config.ConfigurationProvider) JsonCreator(io.mantisrx.shaded.com.fasterxml.jackson.annotation.JsonCreator) StageScalingPolicy(io.mantisrx.runtime.descriptor.StageScalingPolicy) IOException(java.io.IOException)

Aggregations

Route (akka.http.javadsl.server.Route)26 HttpHeader (akka.http.javadsl.model.HttpHeader)12 StatusCodes (akka.http.javadsl.model.StatusCodes)11 Function (java.util.function.Function)11 ExceptionHandler (akka.http.javadsl.server.ExceptionHandler)10 PathMatchers (akka.http.javadsl.server.PathMatchers)10 RequestContext (akka.http.javadsl.server.RequestContext)10 Arrays (java.util.Arrays)10 Optional (java.util.Optional)9 HttpRequest (akka.http.javadsl.model.HttpRequest)8 ActorSystem (akka.actor.ActorSystem)7 PathMatchers.segment (akka.http.javadsl.server.PathMatchers.segment)7 Map (java.util.Map)7 CompletionStage (java.util.concurrent.CompletionStage)7 DittoHeaders (org.eclipse.ditto.base.model.headers.DittoHeaders)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 IOException (java.io.IOException)6 Collections (java.util.Collections)6 List (java.util.List)6