Search in sources :

Example 1 with SubmitInstructionInput

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

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

the class ProgrammingServiceImplTest method testCancelDependantInstruction.

@Test
public void testCancelDependantInstruction() throws Exception {
    final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
    this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
    final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
    this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
    final SubmitInstructionInput mockedSubmit3 = getMockedSubmitInstructionInput("mockedSubmit3", "mockedSubmit1", "mockedSubmit2");
    this.testedProgrammingService.scheduleInstruction(mockedSubmit3);
    this.testedProgrammingService.cancelInstruction(getCancelInstruction("mockedSubmit1"));
    this.mockedNotificationServiceWrapper.assertNotificationsCount(1 + /*First Scheduled*/
    3);
    this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit1.getId(), InstructionStatus.Scheduled);
    this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Cancelled);
    this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit2.getId(), InstructionStatus.Cancelled);
    this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit3.getId(), InstructionStatus.Cancelled);
    checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit1.getId()));
    checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit2.getId()));
    checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit3.getId()));
}
Also used : SubmitInstructionInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.SubmitInstructionInput) Test(org.junit.Test)

Example 3 with SubmitInstructionInput

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

the class ProgrammingServiceImplTest method testTimeoutWhileSuccessfulTransaction.

@Test(timeout = 30 * 1000)
public void testTimeoutWhileSuccessfulTransaction() throws Exception {
    final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS);
    final Nanotime current = NanotimeUtil.currentTime();
    final Nanotime deadlineNano = new Nanotime(current.getValue().add(deadlineOffset));
    final Optional<Nanotime> deadline = Optional.of(deadlineNano);
    final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1", deadline);
    final ListenableFuture<Instruction> future = this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
    this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
    final Instruction i = future.get();
    i.checkedExecutionStart();
    i.executionCompleted(InstructionStatus.Successful, getDetails());
    this.mockedNotificationServiceWrapper.assertNotificationsCount(3);
    this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Executing);
    this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(), InstructionStatus.Successful);
// Timeout in success should not do anything
}
Also used : BigInteger(java.math.BigInteger) Instruction(org.opendaylight.bgpcep.programming.spi.Instruction) SubmitInstructionInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.SubmitInstructionInput) Nanotime(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.Nanotime) Test(org.junit.Test)

Example 4 with SubmitInstructionInput

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

the class ProgrammingServiceImplTest method testScheduleDependingInstruction.

@Test
public void testScheduleDependingInstruction() throws Exception {
    this.testedProgrammingService.scheduleInstruction(getMockedSubmitInstructionInput("mockedSubmit1"));
    final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
    this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
    this.mockedExecutorWrapper.assertSubmittedTasksSize(2);
    // First is in state scheduled, so second could not be scheduled yet
    this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
}
Also used : SubmitInstructionInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.SubmitInstructionInput) Test(org.junit.Test)

Example 5 with SubmitInstructionInput

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

the class ProgrammingServiceImplTest method testCleanInstructions.

@Test
public void testCleanInstructions() throws Exception {
    final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
    this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
    final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
    this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
    final CleanInstructionsInputBuilder cleanInstructionsInputBuilder = new CleanInstructionsInputBuilder();
    final CleanInstructionsInput cleanInstructionsInput = cleanInstructionsInputBuilder.setId(Lists.newArrayList(mockedSubmit1.getId(), mockedSubmit2.getId())).build();
    ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanedInstructionOutput = this.testedProgrammingService.cleanInstructions(cleanInstructionsInput);
    assertCleanInstructionOutput(cleanedInstructionOutput, 2);
    this.testedProgrammingService.cancelInstruction(getCancelInstruction("mockedSubmit1"));
    cleanedInstructionOutput = this.testedProgrammingService.cleanInstructions(cleanInstructionsInput);
    assertCleanInstructionOutput(cleanedInstructionOutput, 0);
    checkNotPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit1.getId()));
    checkNotPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit2.getId()));
}
Also used : CleanInstructionsInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CleanInstructionsInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) CleanInstructionsInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CleanInstructionsInput) SubmitInstructionInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.SubmitInstructionInput) Test(org.junit.Test)

Aggregations

SubmitInstructionInput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.SubmitInstructionInput)11 Test (org.junit.Test)10 Instruction (org.opendaylight.bgpcep.programming.spi.Instruction)5 Nanotime (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.Nanotime)5 BigInteger (java.math.BigInteger)4 InstructionId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId)3 SchedulerException (org.opendaylight.bgpcep.programming.spi.SchedulerException)2 DuplicateInstructionId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.DuplicateInstructionId)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 ArrayList (java.util.ArrayList)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 CancelInstructionInput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CancelInstructionInput)1 CleanInstructionsInput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CleanInstructionsInput)1 CleanInstructionsInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CleanInstructionsInputBuilder)1 UnknownInstruction (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.UnknownInstruction)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1