Search in sources :

Example 1 with ExceptionHandler

use of akka.http.javadsl.server.ExceptionHandler 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 2 with ExceptionHandler

use of akka.http.javadsl.server.ExceptionHandler 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 3 with ExceptionHandler

use of akka.http.javadsl.server.ExceptionHandler 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)

Example 4 with ExceptionHandler

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

the class JobDiscoveryRoute method createRoute.

public Route createRoute(Function<Route, Route> routeFilter) {
    logger.info("creating routes");
    final ExceptionHandler jsonExceptionHandler = 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(jsonExceptionHandler, () -> routeFilter.apply(getJobDiscoveryRoutes())));
}
Also used : ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) JobId(io.mantisrx.server.master.domain.JobId) Arrays(java.util.Arrays) Route(akka.http.javadsl.server.Route) JobClusterInfo(io.mantisrx.master.api.akka.route.proto.JobClusterInfo) Source(akka.stream.javadsl.Source) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) LoggerFactory(org.slf4j.LoggerFactory) StatusCodes(akka.http.javadsl.model.StatusCodes) PathMatchers.segment(akka.http.javadsl.server.PathMatchers.segment) ServerSentEvent(akka.http.javadsl.model.sse.ServerSentEvent) JobDiscoveryRouteProto(io.mantisrx.master.api.akka.route.proto.JobDiscoveryRouteProto) Function(java.util.function.Function) Observable(rx.Observable) PathMatchers(akka.http.javadsl.server.PathMatchers) StringUnmarshallers(akka.http.javadsl.unmarshalling.StringUnmarshallers) Metrics(io.mantisrx.common.metrics.Metrics) Counter(io.mantisrx.common.metrics.Counter) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) Logger(org.slf4j.Logger) HttpHeader(akka.http.javadsl.model.HttpHeader) JobDiscoveryRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobDiscoveryRouteHandler) EventStreamMarshalling(akka.http.javadsl.marshalling.sse.EventStreamMarshalling) ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) CompletionStage(java.util.concurrent.CompletionStage) RxReactiveStreams(rx.RxReactiveStreams) StreamingUtils(io.mantisrx.master.api.akka.route.utils.StreamingUtils) NotUsed(akka.NotUsed) Optional(java.util.Optional)

Example 5 with ExceptionHandler

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

the class JobStatusRoute 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(getJobStatusRoutes())));
}
Also used : ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) JobStatusRouteHandler(io.mantisrx.master.api.akka.route.handlers.JobStatusRouteHandler) HttpHeader(akka.http.javadsl.model.HttpHeader) Route(akka.http.javadsl.server.Route) Flow(akka.stream.javadsl.Flow) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) StatusCodes(akka.http.javadsl.model.StatusCodes) PathMatchers.segment(akka.http.javadsl.server.PathMatchers.segment) Function(java.util.function.Function) ExceptionHandler(akka.http.javadsl.server.ExceptionHandler) PathMatchers(akka.http.javadsl.server.PathMatchers) NotUsed(akka.NotUsed) Message(akka.http.javadsl.model.ws.Message) IOException(java.io.IOException)

Aggregations

HttpHeader (akka.http.javadsl.model.HttpHeader)6 StatusCodes (akka.http.javadsl.model.StatusCodes)6 ExceptionHandler (akka.http.javadsl.server.ExceptionHandler)6 PathMatchers.segment (akka.http.javadsl.server.PathMatchers.segment)6 Route (akka.http.javadsl.server.Route)6 Arrays (java.util.Arrays)6 Function (java.util.function.Function)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 IOException (java.io.IOException)5 PathMatchers (akka.http.javadsl.server.PathMatchers)4 Counter (io.mantisrx.common.metrics.Counter)4 Metrics (io.mantisrx.common.metrics.Metrics)4 Jackson (io.mantisrx.master.api.akka.route.Jackson)4 ConfigurationProvider (io.mantisrx.server.master.config.ConfigurationProvider)4 MasterConfiguration (io.mantisrx.server.master.config.MasterConfiguration)4 ActorSystem (akka.actor.ActorSystem)3 Cache (akka.http.caching.javadsl.Cache)3 HttpMethods (akka.http.javadsl.model.HttpMethods)3 HttpRequest (akka.http.javadsl.model.HttpRequest)3