Search in sources :

Example 1 with CleanInstructionsInput

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

Example 2 with CleanInstructionsInput

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

ArrayList (java.util.ArrayList)1 Test (org.junit.Test)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 CleanInstructionsOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CleanInstructionsOutputBuilder)1 DuplicateInstructionId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.DuplicateInstructionId)1 InstructionId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionId)1 SubmitInstructionInput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.SubmitInstructionInput)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1