Search in sources :

Example 1 with SchedulerException

use of org.opendaylight.bgpcep.programming.spi.SchedulerException in project bgpcep by opendaylight.

the class AbstractInstructionExecutor method schedule.

public static FailureCase schedule(final InstructionScheduler scheduler, final AbstractInstructionExecutor fwd) {
    final ListenableFuture<Instruction> listenableFuture;
    try {
        listenableFuture = scheduler.scheduleInstruction(fwd.getInput());
    } catch (final SchedulerException e) {
        LOG.info("Instuction {} failed to schedule", e.getMessage(), e);
        return new FailureCaseBuilder().setFailure(e.getFailure()).build();
    }
    Futures.addCallback(listenableFuture, fwd, MoreExecutors.directExecutor());
    return null;
}
Also used : FailureCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.submit.instruction.output.result.FailureCaseBuilder) SchedulerException(org.opendaylight.bgpcep.programming.spi.SchedulerException) Instruction(org.opendaylight.bgpcep.programming.spi.Instruction)

Example 2 with SchedulerException

use of org.opendaylight.bgpcep.programming.spi.SchedulerException in project bgpcep by opendaylight.

the class ProgrammingServiceImpl method scheduleInstruction.

@Override
public synchronized ListenableFuture<Instruction> scheduleInstruction(final SubmitInstructionInput input) throws SchedulerException {
    final InstructionId id = input.getId();
    if (this.insns.get(id) != null) {
        LOG.info("Instruction ID {} already present", id);
        throw new SchedulerException("Instruction ID currently in use", new FailureBuilder().setType(DuplicateInstructionId.class).build());
    }
    // First things first: check the deadline
    final Nanotime now = NanotimeUtil.currentTime();
    final BigInteger left = input.getDeadline().getValue().subtract(now.getValue());
    if (left.compareTo(BigInteger.ZERO) <= 0) {
        LOG.debug("Instruction {} deadline has already passed by {}ns", id, left);
        throw new SchedulerException("Instruction arrived after specified deadline", new FailureBuilder().setType(DeadOnArrival.class).build());
    }
    // Resolve dependencies
    final List<InstructionImpl> dependencies = checkDependencies(input);
    /*
         * All pre-flight checks done are at this point, the following
         * steps can only fail in catastrophic scenarios (OOM and the
         * like).
         */
    // Schedule a timeout for the instruction
    final Timeout t = this.timer.newTimeout(timeout -> timeoutInstruction(input.getId()), left.longValue(), TimeUnit.NANOSECONDS);
    // Put it into the instruction list
    final SettableFuture<Instruction> ret = SettableFuture.create();
    final InstructionImpl instruction = new InstructionImpl(new InstructionPusher(id, input.getDeadline()), ret, id, dependencies, t);
    this.insns.put(id, instruction);
    // Attach it into its dependencies
    for (final InstructionImpl d : dependencies) {
        d.addDependant(instruction);
    }
    /*
         * All done. The next part is checking whether the instruction can
         * run, which we can figure out after sending out the acknowledgement.
         * This task should be ingress-weighed, so we reinsert it into the
         * same execution service.
         */
    this.executor.submit(() -> tryScheduleInstruction(instruction));
    return ret;
}
Also used : FailureBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.submit.instruction.output.result.failure._case.FailureBuilder) SchedulerException(org.opendaylight.bgpcep.programming.spi.SchedulerException) InstructionId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId) DuplicateInstructionId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.DuplicateInstructionId) Timeout(io.netty.util.Timeout) BigInteger(java.math.BigInteger) Instruction(org.opendaylight.bgpcep.programming.spi.Instruction) UnknownInstruction(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.UnknownInstruction) Nanotime(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.Nanotime)

Example 3 with SchedulerException

use of org.opendaylight.bgpcep.programming.spi.SchedulerException in project bgpcep by opendaylight.

the class ProgrammingServiceImpl method collectDependencies.

private List<InstructionImpl> collectDependencies(final SubmitInstructionInput input) throws SchedulerException {
    final List<InstructionImpl> dependencies = new ArrayList<>();
    for (final InstructionId pid : input.getPreconditions()) {
        final InstructionImpl instruction = this.insns.get(pid);
        if (instruction == null) {
            LOG.info("Instruction {} depends on {}, which is not a known instruction", input.getId(), pid);
            throw new SchedulerException("Unknown dependency ID specified", new FailureBuilder().setType(UnknownPreconditionId.class).build());
        }
        dependencies.add(instruction);
    }
    return dependencies;
}
Also used : FailureBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.submit.instruction.output.result.failure._case.FailureBuilder) SchedulerException(org.opendaylight.bgpcep.programming.spi.SchedulerException) InstructionId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId) DuplicateInstructionId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.DuplicateInstructionId) ArrayList(java.util.ArrayList)

Aggregations

SchedulerException (org.opendaylight.bgpcep.programming.spi.SchedulerException)3 Instruction (org.opendaylight.bgpcep.programming.spi.Instruction)2 DuplicateInstructionId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.DuplicateInstructionId)2 InstructionId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId)2 FailureBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.submit.instruction.output.result.failure._case.FailureBuilder)2 Timeout (io.netty.util.Timeout)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Nanotime (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.Nanotime)1 UnknownInstruction (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.UnknownInstruction)1 FailureCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.submit.instruction.output.result.FailureCaseBuilder)1