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()));
}
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());
}
Aggregations