Search in sources :

Example 1 with SchedulingStatus

use of com.netflix.titus.common.framework.scheduler.model.SchedulingStatus in project titus-control-plane by Netflix.

the class LocalSchedulerTransactionLogger method logScheduleUpdateEvent.

private static String logScheduleUpdateEvent(ScheduleUpdateEvent event) {
    SchedulingStatus status = event.getSchedule().getCurrentAction().getStatus();
    SchedulingState schedulingState = status.getState();
    String summary;
    switch(schedulingState) {
        case Waiting:
            summary = "Waiting...";
            break;
        case Running:
            summary = "Running...";
            break;
        case Cancelling:
            summary = "Schedule cancelled by a user";
            break;
        case Succeeded:
            summary = "Scheduled action completed";
            break;
        case Failed:
            summary = "Scheduled action failed: error=" + status.getError().map(Throwable::getMessage).orElse("<error_not_available>");
            break;
        default:
            summary = "Unknown scheduling state: schedulingState=" + schedulingState;
    }
    return doFormat(event.getSchedule(), "ExecutionUpdate", summary);
}
Also used : SchedulingStatus(com.netflix.titus.common.framework.scheduler.model.SchedulingStatus) SchedulingState(com.netflix.titus.common.framework.scheduler.model.SchedulingStatus.SchedulingState)

Example 2 with SchedulingStatus

use of com.netflix.titus.common.framework.scheduler.model.SchedulingStatus in project titus-control-plane by Netflix.

the class ScheduledActionExecutor method handleWaitingState.

private boolean handleWaitingState() {
    long now = clock.wallTime();
    if (action.getStatus().getExpectedStartTime() > now) {
        return false;
    }
    SchedulingStatus oldStatus = action.getStatus();
    this.action = action.toBuilder().withStatus(SchedulingStatus.newBuilder().withState(SchedulingState.Running).withTimestamp(now).build()).withStatusHistory(CollectionsExt.copyAndAdd(action.getStatusHistory(), oldStatus)).build();
    this.schedule = schedule.toBuilder().withCurrentAction(action).build();
    try {
        this.retryer = descriptor.getRetryerSupplier().get();
        this.actionCompleted = false;
        this.error = null;
        this.actionDisposable = actionProducer.apply(ExecutionContext.newBuilder().withId(schedule.getId()).withIteration(action.getExecutionId()).build()).timeout(descriptor.getTimeout()).subscribeOn(scheduler).publishOn(scheduler).doOnCancel(() -> actionCompleted = true).subscribe(next -> {
        // Never
        }, e -> {
            if (logger.isDebugEnabled()) {
                logger.warn("Action execution error: name={}", descriptor.getName(), e);
            }
            Throwable effectiveError = e;
            if (e instanceof TimeoutException) {
                effectiveError = new TimeoutException(String.format("Action did not complete in time: timeout=%sms", descriptor.getTimeout().toMillis()));
            }
            Throwable finalEffectiveError = effectiveError;
            ExceptionExt.silent(() -> descriptor.getOnErrorHandler().accept(action, finalEffectiveError));
            this.error = effectiveError;
            this.actionCompleted = true;
        }, () -> {
            ExceptionExt.silent(() -> descriptor.getOnSuccessHandler().accept(action));
            this.actionCompleted = true;
        });
    } catch (Exception e) {
        logger.warn("Could not produce action: name={}", descriptor.getName(), e);
        this.action = newFailedStatus();
    }
    return true;
}
Also used : SchedulingStatus(com.netflix.titus.common.framework.scheduler.model.SchedulingStatus) ExecutionContext(com.netflix.titus.common.framework.scheduler.ExecutionContext) Logger(org.slf4j.Logger) Disposable(reactor.core.Disposable) Schedule(com.netflix.titus.common.framework.scheduler.model.Schedule) SchedulingState(com.netflix.titus.common.framework.scheduler.model.SchedulingStatus.SchedulingState) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Mono(reactor.core.publisher.Mono) ExecutionId(com.netflix.titus.common.framework.scheduler.model.ExecutionId) Scheduler(reactor.core.scheduler.Scheduler) Function(java.util.function.Function) Consumer(java.util.function.Consumer) List(java.util.List) LocalSchedulerException(com.netflix.titus.common.framework.scheduler.LocalSchedulerException) ScheduleDescriptor(com.netflix.titus.common.framework.scheduler.model.ScheduleDescriptor) ExceptionExt(com.netflix.titus.common.util.ExceptionExt) Preconditions(com.google.common.base.Preconditions) ScheduledAction(com.netflix.titus.common.framework.scheduler.model.ScheduledAction) Retryer(com.netflix.titus.common.util.retry.Retryer) Clock(com.netflix.titus.common.util.time.Clock) SchedulingStatus(com.netflix.titus.common.framework.scheduler.model.SchedulingStatus) TimeoutException(java.util.concurrent.TimeoutException) LocalSchedulerException(com.netflix.titus.common.framework.scheduler.LocalSchedulerException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with SchedulingStatus

use of com.netflix.titus.common.framework.scheduler.model.SchedulingStatus in project titus-control-plane by Netflix.

the class ScheduledActionExecutor method changeState.

private ScheduledAction changeState(Consumer<SchedulingStatus.Builder> updater) {
    SchedulingStatus.Builder statusBuilder = SchedulingStatus.newBuilder().withTimestamp(clock.wallTime());
    updater.accept(statusBuilder);
    SchedulingStatus oldStatus = action.getStatus();
    List<SchedulingStatus> statusHistory = CollectionsExt.copyAndAdd(action.getStatusHistory(), oldStatus);
    return action.toBuilder().withStatus(statusBuilder.build()).withStatusHistory(statusHistory).build();
}
Also used : SchedulingStatus(com.netflix.titus.common.framework.scheduler.model.SchedulingStatus)

Example 4 with SchedulingStatus

use of com.netflix.titus.common.framework.scheduler.model.SchedulingStatus in project titus-control-plane by Netflix.

the class LocalSchedulerTransactionLogger method toElapsedMs.

private static long toElapsedMs(Schedule schedule) {
    SchedulingStatus currentStatus = schedule.getCurrentAction().getStatus();
    if (currentStatus.getState() != SchedulingState.Waiting) {
        List<SchedulingStatus> statusHistory = schedule.getCurrentAction().getStatusHistory();
        return currentStatus.getTimestamp() - last(statusHistory).getTimestamp();
    }
    // Report time between the new action, and the previous one
    if (schedule.getCompletedActions().isEmpty()) {
        return 0;
    }
    ScheduledAction previousAction = last(schedule.getCompletedActions());
    return currentStatus.getTimestamp() - previousAction.getStatus().getTimestamp();
}
Also used : SchedulingStatus(com.netflix.titus.common.framework.scheduler.model.SchedulingStatus) ScheduledAction(com.netflix.titus.common.framework.scheduler.model.ScheduledAction)

Aggregations

SchedulingStatus (com.netflix.titus.common.framework.scheduler.model.SchedulingStatus)4 ScheduledAction (com.netflix.titus.common.framework.scheduler.model.ScheduledAction)2 SchedulingState (com.netflix.titus.common.framework.scheduler.model.SchedulingStatus.SchedulingState)2 Preconditions (com.google.common.base.Preconditions)1 ExecutionContext (com.netflix.titus.common.framework.scheduler.ExecutionContext)1 LocalSchedulerException (com.netflix.titus.common.framework.scheduler.LocalSchedulerException)1 ExecutionId (com.netflix.titus.common.framework.scheduler.model.ExecutionId)1 Schedule (com.netflix.titus.common.framework.scheduler.model.Schedule)1 ScheduleDescriptor (com.netflix.titus.common.framework.scheduler.model.ScheduleDescriptor)1 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)1 ExceptionExt (com.netflix.titus.common.util.ExceptionExt)1 Retryer (com.netflix.titus.common.util.retry.Retryer)1 Clock (com.netflix.titus.common.util.time.Clock)1 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Disposable (reactor.core.Disposable)1