- try {
- //TODO:Remove notifications
- final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier =
- DeviceStateUtil.createNodeInstanceIdentifier(new NodeId(entityName));
- deviceManager.sendNodeRemovedNotification(nodeInstanceIdentifier);
- LOG.info("Try to remove device {} from operational DS", entityName);
- ListenableFuture<?> future = deviceManager.removeDeviceFromOperationalDS(nodeInstanceIdentifier);
- Futures.addCallback(future, new FutureCallback<Object>() {
- @Override
- public void onSuccess(final Object result) {
- LOG.debug("Node removed from Oper DS, Node: {}", dpnId);
- OF_EVENT_LOG.debug("Node removed from Oper DS, Node: {}", dpnId);
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- LOG.error("Could not remove device {} from operational DS", dpnId, throwable);
+ nodeCleanerExecutor.schedule(() -> {
+ try {
+ Optional<EntityOwnershipState> ownershipState = getCurrentOwnershipStatus(entityName);
+ if (!ownershipState.isPresent()
+ || Objects.equals(ownershipState.get(), EntityOwnershipState.NO_OWNER)) {
+ LOG.debug("Entity {} has no owner", entityName);
+ final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier =
+ DeviceStateUtil.createNodeInstanceIdentifier(new NodeId(entityName));
+ deviceManager.sendNodeRemovedNotification(nodeInstanceIdentifier);
+ LOG.info("Try to remove device {} from operational DS", entityName);
+ ListenableFuture<?> future =
+ deviceManager.removeDeviceFromOperationalDS(nodeInstanceIdentifier);
+ Futures.addCallback(future, new FutureCallback<Object>() {
+ @Override
+ public void onSuccess(final Object result) {
+ LOG.debug("Node removed from Oper DS, Node: {}", dpnId);
+ OF_EVENT_LOG.debug("Node removed from Oper DS, Node: {}", dpnId);
+ }
+
+ @Override
+ public void onFailure(final Throwable throwable) {
+ LOG.error("Could not remove device {} from operational DS", dpnId, throwable);
+ }
+ }, MoreExecutors.directExecutor());
+ future.get(REMOVE_DEVICE_FROM_DS_TIMEOUT, TimeUnit.MILLISECONDS);
+ } else {
+ LOG.warn("Seems like device is still owned by other controller instance. Skip deleting {} "
+ + "node from operational datastore.", entityName);