Search in sources :

Example 1 with EvictionException

use of com.netflix.titus.api.eviction.service.EvictionException in project titus-control-plane by Netflix.

the class GatewayGrpcEvictionService method terminateTask.

@Override
public void terminateTask(TaskTerminateRequest request, StreamObserver<TaskTerminateResponse> responseObserver) {
    Disposable disposable = evictionServiceClient.terminateTask(request.getTaskId(), request.getReason()).subscribe(next -> {
    }, e -> {
        if (e instanceof EvictionException) {
            // TODO Improve error reporting
            responseObserver.onNext(TaskTerminateResponse.newBuilder().setAllowed(true).setReasonCode("failure").setReasonMessage(e.getMessage()).build());
        } else {
            safeOnError(logger, e, responseObserver);
        }
    }, () -> {
        responseObserver.onNext(TaskTerminateResponse.newBuilder().setAllowed(true).build());
        responseObserver.onCompleted();
    });
    attachCancellingCallback(responseObserver, disposable);
}
Also used : Disposable(reactor.core.Disposable) EvictionException(com.netflix.titus.api.eviction.service.EvictionException)

Example 2 with EvictionException

use of com.netflix.titus.api.eviction.service.EvictionException in project titus-control-plane by Netflix.

the class GrpcEvictionModelConverters method toGrpcEvent.

public static Optional<EvictionServiceEvent> toGrpcEvent(EvictionEvent coreEvent) {
    if (coreEvent instanceof EvictionSnapshotEndEvent) {
        EvictionServiceEvent grpcEvent = EvictionServiceEvent.newBuilder().setSnapshotEnd(EvictionServiceEvent.SnapshotEnd.getDefaultInstance()).build();
        return Optional.of(grpcEvent);
    }
    if (coreEvent instanceof EvictionQuotaEvent) {
        EvictionQuotaEvent actualEvent = (EvictionQuotaEvent) coreEvent;
        EvictionServiceEvent grpcEvent = EvictionServiceEvent.newBuilder().setEvictionQuotaEvent(EvictionServiceEvent.EvictionQuotaEvent.newBuilder().setQuota(toGrpcEvictionQuota(actualEvent.getQuota())).build()).build();
        return Optional.of(grpcEvent);
    }
    if (coreEvent instanceof TaskTerminationEvent) {
        TaskTerminationEvent actualEvent = (TaskTerminationEvent) coreEvent;
        EvictionServiceEvent.TaskTerminationEvent.Builder eventBuilder = EvictionServiceEvent.TaskTerminationEvent.newBuilder().setTaskId(actualEvent.getTaskId()).setApproved(actualEvent.isApproved());
        if (!actualEvent.isApproved()) {
            Throwable error = actualEvent.getError().get();
            if (error instanceof EvictionException) {
                EvictionException evictionException = (EvictionException) error;
                eventBuilder.setRestrictionCode("" + evictionException.getErrorCode());
            } else {
                eventBuilder.setRestrictionCode("" + EvictionException.ErrorCode.Unknown);
            }
            eventBuilder.setRestrictionMessage(error.getMessage());
        }
        EvictionServiceEvent grpcEvent = EvictionServiceEvent.newBuilder().setTaskTerminationEvent(eventBuilder.build()).build();
        return Optional.of(grpcEvent);
    }
    return Optional.empty();
}
Also used : EvictionServiceEvent(com.netflix.titus.grpc.protogen.EvictionServiceEvent) EvictionSnapshotEndEvent(com.netflix.titus.api.eviction.model.event.EvictionSnapshotEndEvent) EvictionQuotaEvent(com.netflix.titus.api.eviction.model.event.EvictionQuotaEvent) TaskTerminationEvent(com.netflix.titus.api.eviction.model.event.TaskTerminationEvent) EvictionException(com.netflix.titus.api.eviction.service.EvictionException)

Aggregations

EvictionException (com.netflix.titus.api.eviction.service.EvictionException)2 EvictionQuotaEvent (com.netflix.titus.api.eviction.model.event.EvictionQuotaEvent)1 EvictionSnapshotEndEvent (com.netflix.titus.api.eviction.model.event.EvictionSnapshotEndEvent)1 TaskTerminationEvent (com.netflix.titus.api.eviction.model.event.TaskTerminationEvent)1 EvictionServiceEvent (com.netflix.titus.grpc.protogen.EvictionServiceEvent)1 Disposable (reactor.core.Disposable)1