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