use of com.netflix.titus.api.eviction.model.event.TaskTerminationEvent in project titus-control-plane by Netflix.
the class TaskTerminationExecutorTest method expectTaskTerminationEvent.
private void expectTaskTerminationEvent(Task task, boolean approved) {
EvictionEvent event = eventSubscriber.takeNext();
assertThat(event).isInstanceOf(TaskTerminationEvent.class);
TaskTerminationEvent terminationEvent = (TaskTerminationEvent) event;
assertThat(terminationEvent.getTaskId()).isEqualTo(task.getId());
assertThat(terminationEvent.isApproved()).isEqualTo(approved);
if (!approved) {
assertThat(terminationEvent.getError().get().getMessage()).contains("no quota");
}
}
use of com.netflix.titus.api.eviction.model.event.TaskTerminationEvent 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