Search in sources :

Example 1 with InstructionId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId in project bgpcep by opendaylight.

the class InstructionImpl method cancelInstrunction.

private synchronized void cancelInstrunction() {
    final List<InstructionId> ids = new ArrayList<>();
    for (final InstructionImpl instruction : this.dependencies) {
        if (instruction.getStatus() != InstructionStatus.Successful) {
            ids.add(instruction.getId());
        }
    }
    cancel(new DetailsBuilder().setUnmetDependencies(ids).build());
}
Also used : InstructionId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId) ArrayList(java.util.ArrayList) DetailsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.status.changed.DetailsBuilder)

Example 2 with InstructionId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId in project bgpcep by opendaylight.

the class InstructionImpl method checkDependencies.

private Boolean checkDependencies() {
    boolean ready = true;
    final List<InstructionId> unmet = new ArrayList<>();
    for (final InstructionImpl instruction : this.dependencies) {
        switch(instruction.getStatus()) {
            case Cancelled:
            case Failed:
            case Unknown:
                unmet.add(instruction.getId());
                break;
            case Executing:
            case Queued:
            case Scheduled:
                ready = false;
                break;
            case Successful:
                // No-op
                break;
            default:
                break;
        }
    }
    if (!unmet.isEmpty()) {
        LOG.warn("Instruction {} was Queued, while some dependencies were resolved unsuccessfully, cancelling it", this.id);
        cancel(new DetailsBuilder().setUnmetDependencies(unmet).build());
        return false;
    }
    return ready;
}
Also used : InstructionId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId) ArrayList(java.util.ArrayList) DetailsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.status.changed.DetailsBuilder)

Example 3 with InstructionId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId 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 4 with InstructionId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId in project bgpcep by opendaylight.

the class ProgrammingServiceImplTest method getCancelInstruction.

private static CancelInstructionInput getCancelInstruction(final String instructionId) {
    final CancelInstructionInputBuilder builder = new CancelInstructionInputBuilder();
    builder.setId(new InstructionId(instructionId));
    return builder.build();
}
Also used : InstructionId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId) CancelInstructionInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CancelInstructionInputBuilder)

Example 5 with InstructionId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId in project bgpcep by opendaylight.

the class ProgrammingServiceImpl method realCleanInstructions.

private synchronized RpcResult<CleanInstructionsOutput> realCleanInstructions(final CleanInstructionsInput input) {
    final List<InstructionId> failed = new ArrayList<>();
    for (final InstructionId id : input.getId()) {
        // Find the instruction
        final InstructionImpl instruction = this.insns.get(id);
        if (instruction == null) {
            LOG.debug("Instruction {} not present in the graph", input.getId());
            failed.add(id);
            continue;
        }
        // Check its status
        switch(instruction.getStatus()) {
            case Cancelled:
            case Failed:
            case Successful:
                break;
            case Executing:
            case Queued:
            case Scheduled:
            case Unknown:
                LOG.debug("Instruction {} cannot be cleaned because of it's in state {}", id, instruction.getStatus());
                failed.add(id);
                continue;
            default:
                break;
        }
        // The instruction is in a terminal state, we need to just unlink
        // it from its dependencies and dependents
        instruction.clean();
        this.insns.remove(id);
        LOG.debug("Instruction {} cleaned successfully", id);
    }
    final CleanInstructionsOutputBuilder ob = new CleanInstructionsOutputBuilder();
    ob.setUnflushed(failed);
    return SuccessfulRpcResult.create(ob.build());
}
Also used : CleanInstructionsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CleanInstructionsOutputBuilder) 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

InstructionId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId)7 ArrayList (java.util.ArrayList)4 DuplicateInstructionId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.DuplicateInstructionId)3 SchedulerException (org.opendaylight.bgpcep.programming.spi.SchedulerException)2 Nanotime (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.Nanotime)2 DetailsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.status.changed.DetailsBuilder)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 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Instruction (org.opendaylight.bgpcep.programming.spi.Instruction)1 CancelInstructionInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CancelInstructionInputBuilder)1 CleanInstructionsOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CleanInstructionsOutputBuilder)1 InstructionStatusChanged (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionStatusChanged)1 SubmitInstructionInput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.SubmitInstructionInput)1 UnknownInstruction (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.UnknownInstruction)1