X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2FForwardedBackwardsCompatibleDataBroker.java;h=e08e9a4e0580556d038cbe01e6de2dc0ed064735;hp=ee7607306a8aa9f242a50c64b81237fe61132756;hb=ed62b66118000e74ef3ddbf53f265ae02e7c8912;hpb=743b4bf3f8b1b8ff1ffffbd8151cbd4c1842330d diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedBackwardsCompatibleDataBroker.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedBackwardsCompatibleDataBroker.java index ee7607306a..e08e9a4e05 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedBackwardsCompatibleDataBroker.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedBackwardsCompatibleDataBroker.java @@ -195,12 +195,17 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat private class ForwardedBackwardsCompatibleTransacion extends AbstractForwardedTransaction implements DataModificationTransaction { + private final ListenerRegistry listeners = ListenerRegistry.create(); private final Map, DataObject> updated = new HashMap<>(); private final Map, DataObject> created = new HashMap<>(); private final Set> removed = new HashSet<>(); private final Map, DataObject> original = new HashMap<>(); private TransactionStatus status = TransactionStatus.NEW; + private final Set> posponedRemovedOperational = new HashSet<>(); + private final Set> posponedRemovedConfiguration = new HashSet<>(); + + @Override public final TransactionStatus getStatus() { return status; @@ -214,12 +219,17 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat @Override public void putOperationalData(final InstanceIdentifier path, final DataObject data) { - - doPutWithEnsureParents(getDelegate(), LogicalDatastoreType.OPERATIONAL, path, data); + boolean previouslyRemoved = posponedRemovedOperational.remove(path); + if(previouslyRemoved) { + doPutWithEnsureParents(getDelegate(), LogicalDatastoreType.OPERATIONAL, path, data); + } else { + doMergeWithEnsureParents(getDelegate(), LogicalDatastoreType.OPERATIONAL, path, data); + } } @Override public void putConfigurationData(final InstanceIdentifier path, final DataObject data) { + boolean previouslyRemoved = posponedRemovedConfiguration.remove(path); DataObject originalObj = readConfigurationData(path); if (originalObj != null) { original.put(path, originalObj); @@ -228,18 +238,21 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat created.put(path, data); } updated.put(path, data); - doPutWithEnsureParents(getDelegate(), LogicalDatastoreType.CONFIGURATION, path, data); + if(previouslyRemoved) { + doPutWithEnsureParents(getDelegate(), LogicalDatastoreType.CONFIGURATION, path, data); + } else { + doMergeWithEnsureParents(getDelegate(), LogicalDatastoreType.CONFIGURATION, path, data); + } } @Override public void removeOperationalData(final InstanceIdentifier path) { - doDelete(getDelegate(), LogicalDatastoreType.OPERATIONAL, path); - + posponedRemovedOperational.add(path); } @Override public void removeConfigurationData(final InstanceIdentifier path) { - doDelete(getDelegate(), LogicalDatastoreType.CONFIGURATION, path); + posponedRemovedConfiguration.add(path); } @Override @@ -307,25 +320,42 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat return getDelegate().getIdentifier(); } - private void changeStatus(TransactionStatus status) { + private void changeStatus(final TransactionStatus status) { LOG.trace("Transaction {} changed status to {}", getIdentifier(), status); this.status = status; + + for(ListenerRegistration listener : listeners) { + try { + listener.getInstance().onStatusUpdated(this, status); + } catch (Exception e) { + LOG.error("Error during invoking transaction listener {}",listener.getInstance(),e); + } + } } @Override public ListenableFuture> commit() { - final ListenableFuture> f = ForwardedBackwardsCompatibleDataBroker.this.commit(this); + + for(InstanceIdentifier path : posponedRemovedConfiguration) { + doDelete(getDelegate(), LogicalDatastoreType.CONFIGURATION, path); + } + + for(InstanceIdentifier path : posponedRemovedOperational) { + doDelete(getDelegate(), LogicalDatastoreType.OPERATIONAL, path); + } changeStatus(TransactionStatus.SUBMITED); + final ListenableFuture> f = ForwardedBackwardsCompatibleDataBroker.this.commit(this); + Futures.addCallback(f, new FutureCallback>() { @Override - public void onSuccess(RpcResult result) { + public void onSuccess(final RpcResult result) { changeStatus(result.getResult()); } @Override - public void onFailure(Throwable t) { + public void onFailure(final Throwable t) { LOG.error("Transaction {} failed to complete", getIdentifier(), t); changeStatus(TransactionStatus.FAILED); } @@ -336,7 +366,7 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat @Override public ListenerRegistration registerListener(final DataTransactionListener listener) { - throw new UnsupportedOperationException(); + return listeners.register(listener); } } @@ -413,9 +443,6 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat } private static class BackwardsCompatibleConfigurationDataChangeInvoker implements BindingDataChangeListener, Delegator { - - - @SuppressWarnings("rawtypes") private final org.opendaylight.controller.md.sal.common.api.data.DataChangeListener delegate; public BackwardsCompatibleConfigurationDataChangeInvoker(final DataChangeListener listener) {