Search in sources :

Example 1 with FitInjection

use of com.netflix.titus.common.framework.fit.FitInjection in project titus-control-plane by Netflix.

the class GrpcFitInterceptor method interceptCall.

@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
    if (!fitRequestHandler.isPresent()) {
        return next.startCall(call, headers);
    }
    FitInjection fitInjection = fitRequestHandler.get();
    String injectionPoint = call.getMethodDescriptor().getFullMethodName();
    // Request failure
    try {
        fitInjection.beforeImmediate(injectionPoint);
    } catch (Exception e) {
        call.close(Status.UNAVAILABLE.withDescription("FIT server failure"), new Metadata());
        return new ServerCall.Listener<ReqT>() {
        };
    }
    // Increased latency.
    return fitInjection.findAction(FitLatencyAction.ACTION_ID).map(action -> {
        int latencyMs = ExceptionExt.doTry(() -> Integer.parseInt(action.getProperties().get("latency"))).orElse(100);
        return new LatencyHandler<>(call, headers, next, latencyMs).getLatencyListener();
    }).orElse(next.startCall(call, headers));
}
Also used : FitInjection(com.netflix.titus.common.framework.fit.FitInjection) ServerCallHandler(io.grpc.ServerCallHandler) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) BlockingQueue(java.util.concurrent.BlockingQueue) Scheduler(reactor.core.scheduler.Scheduler) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) AtomicReference(java.util.concurrent.atomic.AtomicReference) FitLatencyAction(com.netflix.titus.common.framework.fit.internal.action.FitLatencyAction) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerInterceptor(io.grpc.ServerInterceptor) Optional(java.util.Optional) ExceptionExt(com.netflix.titus.common.util.ExceptionExt) ServerCall(io.grpc.ServerCall) Schedulers(reactor.core.scheduler.Schedulers) Metadata(io.grpc.Metadata) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Status(io.grpc.Status) FitFramework(com.netflix.titus.common.framework.fit.FitFramework) FitInjection(com.netflix.titus.common.framework.fit.FitInjection) ServerCall(io.grpc.ServerCall) Metadata(io.grpc.Metadata)

Example 2 with FitInjection

use of com.netflix.titus.common.framework.fit.FitInjection in project titus-control-plane by Netflix.

the class FitSpringResource method deleteAction.

@RequestMapping(method = RequestMethod.DELETE, path = "/actions/{actionId}")
public Response deleteAction(@PathVariable("actionId") String actionId, @RequestParam("componentId") String componentId, @RequestParam("injectionId") String injectionId) {
    FitInjection fitInjection = FitUtil.getFitInjectionOrFail(injectionId, FitUtil.getFitComponentOrFail(fitFramework, componentId));
    fitInjection.removeAction(FitUtil.getFitActionOrFail(actionId, fitInjection).getId());
    return Response.noContent().build();
}
Also used : FitInjection(com.netflix.titus.common.framework.fit.FitInjection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with FitInjection

use of com.netflix.titus.common.framework.fit.FitInjection in project titus-control-plane by Netflix.

the class FitSpringResource method addAction.

@RequestMapping(method = RequestMethod.POST, path = "/actions", consumes = "application/json")
public Response addAction(@RequestBody Fit.AddAction request) {
    FitComponent fitComponent = FitUtil.getFitComponentOrFail(fitFramework, request.getComponentId());
    FitInjection fitInjection = FitUtil.getFitInjectionOrFail(request.getInjectionId(), fitComponent);
    Function<FitInjection, FitAction> fitActionFactory = fitFramework.getFitRegistry().newFitActionFactory(request.getActionKind(), request.getActionId(), request.getPropertiesMap());
    fitInjection.addAction(fitActionFactory.apply(fitInjection));
    return Response.noContent().build();
}
Also used : FitInjection(com.netflix.titus.common.framework.fit.FitInjection) FitComponent(com.netflix.titus.common.framework.fit.FitComponent) FitAction(com.netflix.titus.common.framework.fit.FitAction) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with FitInjection

use of com.netflix.titus.common.framework.fit.FitInjection in project titus-control-plane by Netflix.

the class FitResource method deleteAction.

@DELETE
@Path("/actions/{actionId}")
public Response deleteAction(@PathParam("actionId") String actionId, @QueryParam("componentId") String componentId, @QueryParam("injectionId") String injectionId) {
    FitInjection fitInjection = FitUtil.getFitInjectionOrFail(injectionId, FitUtil.getFitComponentOrFail(fitFramework, componentId));
    fitInjection.removeAction(FitUtil.getFitActionOrFail(actionId, fitInjection).getId());
    return Response.noContent().build();
}
Also used : FitInjection(com.netflix.titus.common.framework.fit.FitInjection) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 5 with FitInjection

use of com.netflix.titus.common.framework.fit.FitInjection in project titus-control-plane by Netflix.

the class FitResource method addAction.

@POST
@Path("/actions")
public Response addAction(Fit.AddAction request) {
    FitComponent fitComponent = FitUtil.getFitComponentOrFail(fitFramework, request.getComponentId());
    FitInjection fitInjection = FitUtil.getFitInjectionOrFail(request.getInjectionId(), fitComponent);
    Function<FitInjection, FitAction> fitActionFactory = fitFramework.getFitRegistry().newFitActionFactory(request.getActionKind(), request.getActionId(), request.getPropertiesMap());
    fitInjection.addAction(fitActionFactory.apply(fitInjection));
    return Response.noContent().build();
}
Also used : FitInjection(com.netflix.titus.common.framework.fit.FitInjection) FitComponent(com.netflix.titus.common.framework.fit.FitComponent) FitAction(com.netflix.titus.common.framework.fit.FitAction) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

FitInjection (com.netflix.titus.common.framework.fit.FitInjection)6 FitAction (com.netflix.titus.common.framework.fit.FitAction)2 FitComponent (com.netflix.titus.common.framework.fit.FitComponent)2 List (java.util.List)2 Path (javax.ws.rs.Path)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Preconditions (com.google.common.base.Preconditions)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 FitFramework (com.netflix.titus.common.framework.fit.FitFramework)1 FitLatencyAction (com.netflix.titus.common.framework.fit.internal.action.FitLatencyAction)1 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)1 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)1 ExceptionExt (com.netflix.titus.common.util.ExceptionExt)1 ReflectionExt (com.netflix.titus.common.util.ReflectionExt)1 Metadata (io.grpc.Metadata)1 ServerCall (io.grpc.ServerCall)1 ServerCallHandler (io.grpc.ServerCallHandler)1 ServerInterceptor (io.grpc.ServerInterceptor)1 Status (io.grpc.Status)1 InvocationHandler (java.lang.reflect.InvocationHandler)1