Search in sources :

Example 1 with EvictionSnapshotEndEvent

use of com.netflix.titus.api.eviction.model.event.EvictionSnapshotEndEvent 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

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 EvictionException (com.netflix.titus.api.eviction.service.EvictionException)1 EvictionServiceEvent (com.netflix.titus.grpc.protogen.EvictionServiceEvent)1