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=b45450ae3a54554243fe6a3c5097f362fb82779b;hp=ab0dc6e24fb91c96ebf6e40aaa2b6251489a3c2b;hb=8546c990b067c288f913d75b92dcdb652fb4dc86;hpb=f330b481b7f70fb165f423cc566214d1efddade8 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 ab0dc6e24f..b45450ae3a 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 @@ -18,7 +18,6 @@ import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; -import org.opendaylight.controller.md.sal.binding.api.BindingDataChangeListener; import org.opendaylight.controller.md.sal.common.api.RegistrationListener; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; @@ -34,7 +33,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; import org.opendaylight.controller.sal.binding.api.data.DataChangeListener; import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction; import org.opendaylight.controller.sal.binding.api.data.DataProviderService; -import org.opendaylight.controller.sal.common.util.Rpcs; +import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.yangtools.concepts.AbstractObjectRegistration; import org.opendaylight.yangtools.concepts.Delegator; import org.opendaylight.yangtools.concepts.ListenerRegistration; @@ -42,8 +41,8 @@ import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.concepts.util.ListenerRegistry; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,12 +59,11 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat private static final Logger LOG = LoggerFactory.getLogger(ForwardedBackwardsCompatibleDataBroker.class); private final ConcurrentHashMap, CommitHandlerRegistrationImpl> commitHandlers = new ConcurrentHashMap<>(); - private final ListenerRegistry fakeRegistry = ListenerRegistry.create(); private final ListeningExecutorService executorService; public ForwardedBackwardsCompatibleDataBroker(final DOMDataBroker domDataBroker, - final BindingIndependentMappingService mappingService, final ListeningExecutorService executor) { - super(domDataBroker, mappingService); + final BindingIndependentMappingService mappingService, final SchemaService schemaService,final ListeningExecutorService executor) { + super(domDataBroker, mappingService,schemaService); executorService = executor; LOG.info("ForwardedBackwardsCompatibleBroker started."); } @@ -113,11 +111,11 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat final InstanceIdentifier path, final DataChangeListener listener) { - BindingDataChangeListener asyncOperListener = new BackwardsCompatibleOperationalDataChangeInvoker(listener); - BindingDataChangeListener asyncCfgListener = new BackwardsCompatibleConfigurationDataChangeInvoker(listener); + org.opendaylight.controller.md.sal.binding.api.DataChangeListener asyncOperListener = new BackwardsCompatibleOperationalDataChangeInvoker(listener); + org.opendaylight.controller.md.sal.binding.api.DataChangeListener asyncCfgListener = new BackwardsCompatibleConfigurationDataChangeInvoker(listener); - ListenerRegistration cfgReg = registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, path, asyncCfgListener, DataChangeScope.SUBTREE); - ListenerRegistration operReg = registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, path, asyncOperListener, DataChangeScope.SUBTREE); + ListenerRegistration cfgReg = registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, path, asyncCfgListener, DataChangeScope.SUBTREE); + ListenerRegistration operReg = registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, path, asyncOperListener, DataChangeScope.SUBTREE); return new LegacyListenerRegistration(listener,cfgReg,operReg); } @@ -129,12 +127,6 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat throw new UnsupportedOperationException("Data reader contract is not supported."); } - @Override - public void close() throws Exception { - // TODO Auto-generated method stub - - } - public ListenableFuture> commit(final ForwardedBackwardsCompatibleTransacion tx) { final List, DataObject>> subTrans = new ArrayList<>(); @@ -170,7 +162,7 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat if(requestCommitSuccess) { return tx.getDelegate().commit(); } - return Futures.immediateFuture(Rpcs.getRpcResult(false, TransactionStatus.FAILED, Collections.emptySet())); + return Futures.immediateFuture(RpcResultBuilder.failed().withResult(TransactionStatus.FAILED).build()); } }); @@ -193,8 +185,9 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat } private class ForwardedBackwardsCompatibleTransacion extends - AbstractForwardedTransaction implements DataModificationTransaction { + AbstractReadWriteTransaction 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<>(); @@ -218,13 +211,17 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat @Override public void putOperationalData(final InstanceIdentifier path, final DataObject data) { - posponedRemovedOperational.remove(path); - doPutWithEnsureParents(getDelegate(), LogicalDatastoreType.OPERATIONAL, path, data); + boolean previouslyRemoved = posponedRemovedOperational.remove(path); + if(previouslyRemoved) { + doPutWithEnsureParents(LogicalDatastoreType.OPERATIONAL, path, data); + } else { + doMergeWithEnsureParents(LogicalDatastoreType.OPERATIONAL, path, data); + } } @Override public void putConfigurationData(final InstanceIdentifier path, final DataObject data) { - posponedRemovedConfiguration.remove(path); + boolean previouslyRemoved = posponedRemovedConfiguration.remove(path); DataObject originalObj = readConfigurationData(path); if (originalObj != null) { original.put(path, originalObj); @@ -233,7 +230,11 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat created.put(path, data); } updated.put(path, data); - doPutWithEnsureParents(getDelegate(), LogicalDatastoreType.CONFIGURATION, path, data); + if(previouslyRemoved) { + doPutWithEnsureParents(LogicalDatastoreType.CONFIGURATION, path, data); + } else { + doMergeWithEnsureParents(LogicalDatastoreType.CONFIGURATION, path, data); + } } @Override @@ -306,31 +307,34 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat } } - @Override - public Object getIdentifier() { - return getDelegate().getIdentifier(); - } - 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() { for(InstanceIdentifier path : posponedRemovedConfiguration) { - doDelete(getDelegate(), LogicalDatastoreType.CONFIGURATION, path); + doDelete(LogicalDatastoreType.CONFIGURATION, path); } for(InstanceIdentifier path : posponedRemovedOperational) { - doDelete(getDelegate(), LogicalDatastoreType.OPERATIONAL, path); + doDelete(LogicalDatastoreType.OPERATIONAL, path); } - final ListenableFuture> f = ForwardedBackwardsCompatibleDataBroker.this.commit(this); - changeStatus(TransactionStatus.SUBMITED); + final ListenableFuture> f = ForwardedBackwardsCompatibleDataBroker.this.commit(this); + Futures.addCallback(f, new FutureCallback>() { @Override public void onSuccess(final RpcResult result) { @@ -349,7 +353,7 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat @Override public ListenerRegistration registerListener(final DataTransactionListener listener) { - throw new UnsupportedOperationException(); + return listeners.register(listener); } } @@ -376,12 +380,12 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat private static final class LegacyListenerRegistration implements ListenerRegistration { private final DataChangeListener instance; - private final ListenerRegistration cfgReg; - private final ListenerRegistration operReg; + private final ListenerRegistration cfgReg; + private final ListenerRegistration operReg; public LegacyListenerRegistration(final DataChangeListener listener, - final ListenerRegistration cfgReg, - final ListenerRegistration operReg) { + final ListenerRegistration cfgReg, + final ListenerRegistration operReg) { this.instance = listener; this.cfgReg = cfgReg; this.operReg = operReg; @@ -400,7 +404,7 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat } - private static class BackwardsCompatibleOperationalDataChangeInvoker implements BindingDataChangeListener, Delegator { + private static class BackwardsCompatibleOperationalDataChangeInvoker implements org.opendaylight.controller.md.sal.binding.api.DataChangeListener, Delegator { private final org.opendaylight.controller.md.sal.common.api.data.DataChangeListener delegate; @@ -425,10 +429,7 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat } - private static class BackwardsCompatibleConfigurationDataChangeInvoker implements BindingDataChangeListener, Delegator { - - - @SuppressWarnings("rawtypes") + private static class BackwardsCompatibleConfigurationDataChangeInvoker implements org.opendaylight.controller.md.sal.binding.api.DataChangeListener, Delegator { private final org.opendaylight.controller.md.sal.common.api.data.DataChangeListener delegate; public BackwardsCompatibleConfigurationDataChangeInvoker(final DataChangeListener listener) {