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);
}
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();
}
Aggregations