Bump MRI upstreams
[bgpcep.git] / programming / impl / src / main / java / org / opendaylight / bgpcep / programming / impl / ProgrammingServiceImpl.java
index b5c3f00a29d9cdb71e45d0f8fe451addbc58eece..68aa257c3b2f16177fa9a5cb193b19e2f7dc754f 100644 (file)
@@ -7,38 +7,38 @@
  */
 package org.opendaylight.bgpcep.programming.impl;
 
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import io.netty.util.Timeout;
 import io.netty.util.Timer;
 import java.math.BigInteger;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
+import org.checkerframework.checker.lock.qual.GuardedBy;
 import org.opendaylight.bgpcep.programming.NanotimeUtil;
-import org.opendaylight.bgpcep.programming.impl.InstructionDeployerImpl.WriteConfiguration;
 import org.opendaylight.bgpcep.programming.spi.ExecutionResult;
 import org.opendaylight.bgpcep.programming.spi.Instruction;
 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
 import org.opendaylight.bgpcep.programming.spi.SchedulerException;
 import org.opendaylight.bgpcep.programming.spi.SuccessfulRpcResult;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
@@ -66,6 +66,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programm
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.queue.InstructionKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.status.changed.Details;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.submit.instruction.output.result.failure._case.FailureBuilder;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -73,8 +74,8 @@ import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingletonService, InstructionScheduler,
-    ProgrammingService {
+public final class ProgrammingServiceImpl implements ClusterSingletonService, InstructionScheduler,
+        ProgrammingService {
     private static final Logger LOG = LoggerFactory.getLogger(ProgrammingServiceImpl.class);
 
     private final Map<InstructionId, InstructionImpl> insns = new HashMap<>();
@@ -86,9 +87,10 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
     private final String instructionId;
     private final ServiceGroupIdentifier sgi;
     private final ClusterSingletonServiceRegistration csspReg;
-    private final RpcProviderRegistry rpcProviderRegistry;
-    private final WriteConfiguration writeConfiguration;
-    private RpcRegistration<ProgrammingService> reg;
+    private final RpcProviderService rpcProviderRegistry;
+    @GuardedBy("this")
+    private ObjectRegistration<ProgrammingService> reg;
+    @GuardedBy("this")
     private ServiceRegistration<?> serviceRegistration;
 
     private final class InstructionPusher implements QueueInstruction {
@@ -97,7 +99,7 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
         InstructionPusher(final InstructionId id, final Nanotime deadline) {
             this.builder.setDeadline(deadline);
             this.builder.setId(id);
-            this.builder.setKey(new InstructionKey(id));
+            this.builder.withKey(new InstructionKey(id));
             this.builder.setStatus(InstructionStatus.Queued);
         }
 
@@ -106,27 +108,28 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
             if (!status.equals(this.builder.getStatus())) {
                 this.builder.setStatus(status);
 
-                final WriteTransaction t = ProgrammingServiceImpl.this.dataProvider.newWriteOnlyTransaction();
-                t.put(LogicalDatastoreType.OPERATIONAL,
+                final WriteTransaction wt = ProgrammingServiceImpl.this.dataProvider.newWriteOnlyTransaction();
+                wt.put(LogicalDatastoreType.OPERATIONAL,
                         ProgrammingServiceImpl.this.qid.child(
-                                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.queue.Instruction.class,
+                                org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming
+                                        .rev150720.instruction.queue.Instruction.class,
                                 new InstructionKey(this.builder.getId())), this.builder.build());
-                Futures.addCallback(t.submit(), new FutureCallback<Void>() {
+                wt.commit().addCallback(new FutureCallback<CommitInfo>() {
                     @Override
-                    public void onSuccess(final Void result) {
+                    public void onSuccess(final CommitInfo result) {
                         LOG.debug("Instruction Queue {} updated", ProgrammingServiceImpl.this.qid);
                     }
 
                     @Override
-                    public void onFailure(final Throwable t) {
-                        LOG.error("Failed to update Instruction Queue {}", ProgrammingServiceImpl.this.qid, t);
+                    public void onFailure(final Throwable trw) {
+                        LOG.error("Failed to update Instruction Queue {}", ProgrammingServiceImpl.this.qid, trw);
                     }
                 }, MoreExecutors.directExecutor());
             }
 
             try {
                 ProgrammingServiceImpl.this.notifs.putNotification(new InstructionStatusChangedBuilder()
-                    .setId(this.builder.getId()).setStatus(status).setDetails(details).build());
+                        .setId(this.builder.getId()).setStatus(status).setDetails(details).build());
             } catch (final InterruptedException e) {
                 LOG.debug("Failed to publish notification", e);
             }
@@ -134,61 +137,58 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
 
         @Override
         public void instructionRemoved() {
-            final WriteTransaction t = ProgrammingServiceImpl.this.dataProvider.newWriteOnlyTransaction();
-            t.delete(LogicalDatastoreType.OPERATIONAL, ProgrammingServiceImpl.this.qid.child(
-                    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.queue.Instruction.class,
+            final WriteTransaction wt = ProgrammingServiceImpl.this.dataProvider.newWriteOnlyTransaction();
+            wt.delete(LogicalDatastoreType.OPERATIONAL, ProgrammingServiceImpl.this.qid.child(
+                    org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction
+                            .queue.Instruction.class,
                     new InstructionKey(this.builder.getId())));
-            Futures.addCallback(t.submit(), new FutureCallback<Void>() {
+            wt.commit().addCallback(new FutureCallback<CommitInfo>() {
                 @Override
-                public void onSuccess(final Void result) {
+                public void onSuccess(final CommitInfo result) {
                     LOG.debug("Instruction Queue {} removed", ProgrammingServiceImpl.this.qid);
                 }
 
                 @Override
-                public void onFailure(final Throwable t) {
-                    LOG.error("Failed to remove Instruction Queue {}", ProgrammingServiceImpl.this.qid, t);
+                public void onFailure(final Throwable trw) {
+                    LOG.error("Failed to remove Instruction Queue {}", ProgrammingServiceImpl.this.qid, trw);
                 }
             }, MoreExecutors.directExecutor());
         }
     }
 
     ProgrammingServiceImpl(final DataBroker dataProvider, final NotificationPublishService notifs,
-        final ListeningExecutorService executor, final RpcProviderRegistry rpcProviderRegistry,
-        final ClusterSingletonServiceProvider cssp, final Timer timer, final String instructionId,
-        final WriteConfiguration writeConfiguration) {
-        this.dataProvider = Preconditions.checkNotNull(dataProvider);
-        this.instructionId = Preconditions.checkNotNull(instructionId);
-        this.notifs = Preconditions.checkNotNull(notifs);
-        this.executor = Preconditions.checkNotNull(executor);
-        this.rpcProviderRegistry = Preconditions.checkNotNull(rpcProviderRegistry);
-        this.timer = Preconditions.checkNotNull(timer);
-        this.qid = KeyedInstanceIdentifier.builder(InstructionsQueue.class,  new InstructionsQueueKey(this.instructionId)).build();
-        this.writeConfiguration = writeConfiguration;
-        this.sgi = ServiceGroupIdentifier.create("programming-"+ this.instructionId + "-service-group");
+            final ListeningExecutorService executor, final RpcProviderService rpcProviderRegistry,
+            final ClusterSingletonServiceProvider cssp, final Timer timer, final String instructionId) {
+        this.dataProvider = requireNonNull(dataProvider);
+        this.instructionId = requireNonNull(instructionId);
+        this.notifs = requireNonNull(notifs);
+        this.executor = requireNonNull(executor);
+        this.rpcProviderRegistry = requireNonNull(rpcProviderRegistry);
+        this.timer = requireNonNull(timer);
+        this.qid = KeyedInstanceIdentifier.builder(InstructionsQueue.class,
+                new InstructionsQueueKey(this.instructionId)).build();
+        this.sgi = ServiceGroupIdentifier.create(this.instructionId + "-service-group");
+        LOG.info("Creating Programming Service {}.", this.sgi.getName());
         this.csspReg = cssp.registerClusterSingletonService(this);
     }
 
     @Override
-    public void instantiateServiceInstance() {
-        LOG.info("Instruction Queue service {} instantiated", this.sgi.getValue());
-
-        if (this.writeConfiguration != null) {
-            this.writeConfiguration.create();
-        }
-        this.reg = this.rpcProviderRegistry.addRpcImplementation(ProgrammingService.class, this);
-
-        final WriteTransaction t = this.dataProvider.newWriteOnlyTransaction();
-        t.put(LogicalDatastoreType.OPERATIONAL, this.qid, new InstructionsQueueBuilder()
-            .setKey(new InstructionsQueueKey(this.instructionId)).setInstruction(Collections.emptyList()).build());
-        Futures.addCallback(t.submit(), new FutureCallback<Void>() {
+    public synchronized void instantiateServiceInstance() {
+        LOG.info("Instruction Queue service {} instantiated", this.sgi.getName());
+        this.reg = this.rpcProviderRegistry.registerRpcImplementation(ProgrammingService.class, this);
+
+        final WriteTransaction wt = this.dataProvider.newWriteOnlyTransaction();
+        wt.put(LogicalDatastoreType.OPERATIONAL, this.qid, new InstructionsQueueBuilder()
+                .withKey(new InstructionsQueueKey(this.instructionId)).setInstruction(Map.of()).build());
+        wt.commit().addCallback(new FutureCallback<CommitInfo>() {
             @Override
-            public void onSuccess(final Void result) {
+            public void onSuccess(final CommitInfo result) {
                 LOG.debug("Instruction Queue {} added", ProgrammingServiceImpl.this.qid);
             }
 
             @Override
-            public void onFailure(final Throwable t) {
-                LOG.error("Failed to add Instruction Queue {}", ProgrammingServiceImpl.this.qid, t);
+            public void onFailure(final Throwable trw) {
+                LOG.error("Failed to add Instruction Queue {}", ProgrammingServiceImpl.this.qid, trw);
             }
         }, MoreExecutors.directExecutor());
     }
@@ -209,15 +209,17 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
     }
 
     private synchronized RpcResult<CancelInstructionOutput> realCancelInstruction(final CancelInstructionInput input) {
-        final InstructionImpl i = this.insns.get(input.getId());
-        if (i == null) {
+        final InstructionImpl instruction = this.insns.get(input.getId());
+        if (instruction == null) {
             LOG.debug("Instruction {} not present in the graph", input.getId());
 
-            final CancelInstructionOutput out = new CancelInstructionOutputBuilder().setFailure(UnknownInstruction.class).build();
+            final CancelInstructionOutput out = new CancelInstructionOutputBuilder()
+                    .setFailure(UnknownInstruction.class).build();
             return SuccessfulRpcResult.create(out);
         }
 
-        return SuccessfulRpcResult.create(new CancelInstructionOutputBuilder().setFailure(i.tryCancel(null)).build());
+        return SuccessfulRpcResult.create(new CancelInstructionOutputBuilder()
+                .setFailure(instruction.tryCancel(null)).build());
     }
 
     private synchronized RpcResult<CleanInstructionsOutput> realCleanInstructions(final CleanInstructionsInput input) {
@@ -225,33 +227,34 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
 
         for (final InstructionId id : input.getId()) {
             // Find the instruction
-            final InstructionImpl i = this.insns.get(id);
-            if (i == null) {
+            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 (i.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, i.getStatus());
-                failed.add(id);
-                continue;
-            default:
-                break;
+            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
-            i.clean();
+            instruction.clean();
 
             this.insns.remove(id);
             LOG.debug("Instruction {} cleaned successfully", id);
@@ -272,8 +275,8 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
          *  and fail the operation.
          */
         if (!unmet.isEmpty()) {
-            throw new SchedulerException("Instruction's dependencies are already unsuccessful", new FailureBuilder().setType(
-                    DeadOnArrival.class).setFailedPreconditions(unmet).build());
+            throw new SchedulerException("Instruction's dependencies are already unsuccessful", new FailureBuilder()
+                    .setType(DeadOnArrival.class).setFailedPreconditions(unmet).build());
         }
         return dependencies;
     }
@@ -281,52 +284,56 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
     private List<InstructionImpl> collectDependencies(final SubmitInstructionInput input) throws SchedulerException {
         final List<InstructionImpl> dependencies = new ArrayList<>();
         for (final InstructionId pid : input.getPreconditions()) {
-            final InstructionImpl i = this.insns.get(pid);
-            if (i == null) {
+            final InstructionImpl instruction = this.insns.get(pid);
+            if (instruction == null) {
                 LOG.info("Instruction {} depends on {}, which is not a known instruction", input.getId(), pid);
-                throw new SchedulerException("Unknown dependency ID specified", new FailureBuilder().setType(UnknownPreconditionId.class).build());
+                throw new SchedulerException("Unknown dependency ID specified",
+                        new FailureBuilder().setType(UnknownPreconditionId.class).build());
             }
-            dependencies.add(i);
+            dependencies.add(instruction);
         }
         return dependencies;
     }
 
-    private List<InstructionId> checkIfUnfailed(final List<InstructionImpl> dependencies) {
+    private static List<InstructionId> checkIfUnfailed(final List<InstructionImpl> dependencies) {
         final List<InstructionId> unmet = new ArrayList<>();
         for (final InstructionImpl d : dependencies) {
             switch (d.getStatus()) {
-            case Cancelled:
-            case Failed:
-            case Unknown:
-                unmet.add(d.getId());
-                break;
-            case Executing:
-            case Queued:
-            case Scheduled:
-            case Successful:
-                break;
-            default:
-                break;
+                case Cancelled:
+                case Failed:
+                case Unknown:
+                    unmet.add(d.getId());
+                    break;
+                case Executing:
+                case Queued:
+                case Scheduled:
+                case Successful:
+                    break;
+                default:
+                    break;
             }
         }
         return unmet;
     }
 
     @Override
-    public synchronized ListenableFuture<Instruction> scheduleInstruction(final SubmitInstructionInput input) throws SchedulerException {
+    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());
+            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());
+        final BigInteger left = input.getDeadline().getValue().toJava().subtract(now.getValue().toJava());
 
         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());
+            throw new SchedulerException("Instruction arrived after specified deadline",
+                    new FailureBuilder().setType(DeadOnArrival.class).build());
         }
 
         // Resolve dependencies
@@ -339,16 +346,18 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
          */
 
         // Schedule a timeout for the instruction
-        final Timeout t = this.timer.newTimeout(timeout -> timeoutInstruction(input.getId()), left.longValue(), TimeUnit.NANOSECONDS);
+        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 i = new InstructionImpl(new InstructionPusher(id, input.getDeadline()), ret, id, dependencies, t);
-        this.insns.put(id, i);
+        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(i);
+            d.addDependant(instruction);
         }
 
         /*
@@ -357,45 +366,48 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
          * This task should be ingress-weighed, so we reinsert it into the
          * same execution service.
          */
-        this.executor.submit(() -> tryScheduleInstruction(i));
+        this.executor.submit(() -> tryScheduleInstruction(instruction));
 
         return ret;
     }
 
+    @Override
     public String getInstructionID() {
         return this.instructionId;
     }
 
     private synchronized void timeoutInstruction(final InstructionId id) {
-        final InstructionImpl i = this.insns.get(id);
-        if (i == null) {
+        final InstructionImpl instruction = this.insns.get(id);
+        if (instruction == null) {
             LOG.warn("Instruction {} timed out, but not found in the queue", id);
             return;
         }
 
-        i.timeout();
+        instruction.timeout();
     }
 
-    private synchronized void tryScheduleDependants(final InstructionImpl i) {
+    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "https://github.com/spotbugs/spotbugs/issues/811")
+    private synchronized void tryScheduleDependants(final InstructionImpl instruction) {
         // Walk all dependants and try to schedule them
-        final Iterator<InstructionImpl> it = i.getDependants();
+        final Iterator<InstructionImpl> it = instruction.getDependants();
         while (it.hasNext()) {
             tryScheduleInstruction(it.next());
         }
     }
 
-    private synchronized void tryScheduleInstruction(final InstructionImpl i) {
-        final ListenableFuture<ExecutionResult<Details>> f = i.ready();
+    private synchronized void tryScheduleInstruction(final InstructionImpl instruction) {
+        final ListenableFuture<ExecutionResult<Details>> f = instruction.ready();
         if (f != null) {
             Futures.addCallback(f, new FutureCallback<ExecutionResult<Details>>() {
                 @Override
                 public void onSuccess(final ExecutionResult<Details> result) {
-                    tryScheduleDependants(i);
+                    tryScheduleDependants(instruction);
                 }
 
                 @Override
-                public void onFailure(final Throwable t) {
-                    LOG.error("Instruction {} failed to execute", i.getId(), t);
+                public void onFailure(final Throwable trw) {
+                    LOG.error("Instruction {} failed to execute", instruction.getId(), trw);
                 }
             }, MoreExecutors.directExecutor());
         }
@@ -403,41 +415,44 @@ public final class ProgrammingServiceImpl implements AutoCloseable, ClusterSingl
     }
 
     @Override
-    public ListenableFuture<Void> closeServiceInstance() {
-        LOG.info("Closing Instruction Queue service {}", this.sgi.getValue());
+    public synchronized FluentFuture<? extends CommitInfo> closeServiceInstance() {
+        LOG.info("Closing Instruction Queue service {}", this.sgi.getName());
 
-        if (this.writeConfiguration != null) {
-            this.writeConfiguration.remove();
+        if (this.reg != null) {
+            this.reg.close();
+            this.reg = null;
         }
-        this.reg.close();
-        for (final InstructionImpl i : this.insns.values()) {
-            i.tryCancel(null);
+        for (final InstructionImpl instruction : this.insns.values()) {
+            instruction.tryCancel(null);
         }
         // Workaround for BUG-2283
-        final WriteTransaction t = this.dataProvider.newWriteOnlyTransaction();
-        t.delete(LogicalDatastoreType.OPERATIONAL, this.qid);
-        final CheckedFuture<Void, TransactionCommitFailedException> future = t.submit();
-        Futures.addCallback(future, new FutureCallback<Void>() {
+        final WriteTransaction wt = this.dataProvider.newWriteOnlyTransaction();
+        wt.delete(LogicalDatastoreType.OPERATIONAL, this.qid);
+
+        final FluentFuture<? extends CommitInfo> future = wt.commit();
+        future.addCallback(new FutureCallback<CommitInfo>() {
             @Override
-            public void onSuccess(final Void result) {
+            public void onSuccess(final CommitInfo result) {
                 LOG.debug("Instruction Queue {} removed", ProgrammingServiceImpl.this.qid);
             }
 
             @Override
-            public void onFailure(final Throwable t) {
-                LOG.error("Failed to shutdown Instruction Queue {}", ProgrammingServiceImpl.this.qid, t);
+            public void onFailure(final Throwable trw) {
+                LOG.error("Failed to shutdown Instruction Queue {}", ProgrammingServiceImpl.this.qid, trw);
             }
         }, MoreExecutors.directExecutor());
+
         return future;
     }
 
     @Override
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public synchronized void close() {
         if (this.csspReg != null) {
             try {
                 this.csspReg.close();
             } catch (final Exception e) {
-                LOG.debug("Failed to close Instruction Scheduler service", e);
+                LOG.error("Failed to close Instruction Scheduler service", e);
             }
         }
         if (this.serviceRegistration != null) {