X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fdom%2Fbroker%2FBackwardsCompatibleMountPoint.java;h=fb72b5a99a130efbcfcd0ea04056ef61978f2e06;hp=c2329ef4b0583a930b9576dad49c16ecd524602a;hb=971b179000ef1cc56699de35061cf6f97d4cf36f;hpb=a6a97a57081df63432dde5a6b1613eb779b74d79 diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BackwardsCompatibleMountPoint.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BackwardsCompatibleMountPoint.java index c2329ef4b0..fb72b5a99a 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BackwardsCompatibleMountPoint.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BackwardsCompatibleMountPoint.java @@ -15,16 +15,13 @@ import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.JdkFutureAdapters; import com.google.common.util.concurrent.ListenableFuture; -import java.util.List; -import java.util.Map; -import java.util.Set; -import javax.annotation.Nullable; 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.DataCommitHandler; import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandlerRegistration; import org.opendaylight.controller.md.sal.common.api.data.DataReader; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; @@ -67,27 +64,33 @@ import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener; +import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; + +import javax.annotation.Nullable; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutionException; public class BackwardsCompatibleMountPoint implements MountProvisionInstance, SchemaContextProvider, SchemaService { private final DataProviderService dataReader; - private final DataReader readWrapper; + private final DataReader readWrapper; - private final InstanceIdentifier mountPath; + private final YangInstanceIdentifier mountPath; private final NotificationPublishService notificationPublishService; private final RpcProvisionRegistry rpcs; - private final ListenerRegistry schemaListenerRegistry = new ListenerRegistry<>(); + private final ListenerRegistry schemaListenerRegistry = new ListenerRegistry<>(); private SchemaContext schemaContext; - public BackwardsCompatibleMountPoint(final InstanceIdentifier path, final DOMMountPointService.DOMMountPointBuilder mountPointBuilder) { + public BackwardsCompatibleMountPoint(final YangInstanceIdentifier path, final DOMMountPointService.DOMMountPointBuilder mountPointBuilder) { this.mountPath = Preconditions.checkNotNull(path); Preconditions.checkNotNull(mountPointBuilder); @@ -105,7 +108,7 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc mountPointBuilder.register(); } - public BackwardsCompatibleMountPoint(final InstanceIdentifier path, final DOMMountPoint mount) { + public BackwardsCompatibleMountPoint(final YangInstanceIdentifier path, final DOMMountPoint mount) { this.mountPath = Preconditions.checkNotNull(path); Preconditions.checkNotNull(mount); @@ -154,7 +157,7 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc } @Override - public ListenerRegistration registerSchemaServiceListener(final SchemaServiceListener listener) { + public ListenerRegistration registerSchemaContextListener(final SchemaContextListener listener) { return schemaListenerRegistry.register(listener); } @@ -169,29 +172,29 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc } // TODO Read wrapper is never used ... same in org.opendaylight.controller.sal.dom.broker.MountPointImpl - public DataReader getReadWrapper() { + public DataReader getReadWrapper() { return readWrapper; } @Override - public CompositeNode readConfigurationData(final InstanceIdentifier path) { + public CompositeNode readConfigurationData(final YangInstanceIdentifier path) { return dataReader.readConfigurationData(path); } @Override - public CompositeNode readOperationalData(final InstanceIdentifier path) { + public CompositeNode readOperationalData(final YangInstanceIdentifier path) { return dataReader.readOperationalData(path); } @Override public Registration registerOperationalReader( - final InstanceIdentifier path, final DataReader reader) { + final YangInstanceIdentifier path, final DataReader reader) { return dataReader.registerOperationalReader(path, reader); } @Override public Registration registerConfigurationReader( - final InstanceIdentifier path, final DataReader reader) { + final YangInstanceIdentifier path, final DataReader reader) { return dataReader.registerConfigurationReader(path, reader); } @@ -237,14 +240,14 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc } @Override - public ListenerRegistration registerDataChangeListener(final InstanceIdentifier path, + public ListenerRegistration registerDataChangeListener(final YangInstanceIdentifier path, final DataChangeListener listener) { return dataReader.registerDataChangeListener(path, listener); } @Override public Registration registerCommitHandler( - final InstanceIdentifier path, final DataCommitHandler commitHandler) { + final YangInstanceIdentifier path, final DataCommitHandler commitHandler) { return dataReader.registerCommitHandler(path, commitHandler); } @@ -275,24 +278,24 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc @Override public void setSchemaContext(final SchemaContext schemaContext) { this.schemaContext = schemaContext; - for (ListenerRegistration schemaServiceListenerListenerRegistration : schemaListenerRegistry.getListeners()) { + for (ListenerRegistration schemaServiceListenerListenerRegistration : schemaListenerRegistry.getListeners()) { schemaServiceListenerListenerRegistration.getInstance().onGlobalContextUpdated(schemaContext); } } - class ReadWrapper implements DataReader { - private InstanceIdentifier shortenPath(final InstanceIdentifier path) { - InstanceIdentifier ret = null; + class ReadWrapper implements DataReader { + private YangInstanceIdentifier shortenPath(final YangInstanceIdentifier path) { + YangInstanceIdentifier ret = null; if(mountPath.contains(path)) { final List newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size()); - ret = InstanceIdentifier.create(newArgs); + ret = YangInstanceIdentifier.create(newArgs); } return ret; } @Override - public CompositeNode readConfigurationData(final InstanceIdentifier path) { - final InstanceIdentifier newPath = shortenPath(path); + public CompositeNode readConfigurationData(final YangInstanceIdentifier path) { + final YangInstanceIdentifier newPath = shortenPath(path); if(newPath == null) { return null; } @@ -300,8 +303,8 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc } @Override - public CompositeNode readOperationalData(final InstanceIdentifier path) { - final InstanceIdentifier newPath = shortenPath(path); + public CompositeNode readOperationalData(final YangInstanceIdentifier path) { + final YangInstanceIdentifier newPath = shortenPath(path); if(newPath == null) { return null; } @@ -310,13 +313,13 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc } @Override - public ListenerRegistration>> registerCommitHandlerListener( - final RegistrationListener> commitHandlerListener) { + public ListenerRegistration>> registerCommitHandlerListener( + final RegistrationListener> commitHandlerListener) { return dataReader.registerCommitHandlerListener(commitHandlerListener); } @Override - public > ListenerRegistration registerRouteChangeListener( + public > ListenerRegistration registerRouteChangeListener( final L listener) { return rpcs.registerRouteChangeListener(listener); } @@ -344,7 +347,7 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc } @Override - public ListenerRegistration registerDataChangeListener(final LogicalDatastoreType store, final InstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) { + public ListenerRegistration registerDataChangeListener(final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) { throw new UnsupportedOperationException("Register data listener not supported for mount point"); } @@ -380,7 +383,8 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc } @Override - public ListenableFuture>> read(final LogicalDatastoreType store, final InstanceIdentifier path) { + public CheckedFuture>, ReadFailedException> read( + final LogicalDatastoreType store, final YangInstanceIdentifier path) { CompositeNode rawData = null; @@ -396,9 +400,19 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc } Preconditions.checkNotNull(rawData, "Unable to read %s data on path %s", store, path); - final Map.Entry> normalized = normalizer.toNormalized(path, rawData); + final Map.Entry> normalized = normalizer.toNormalized(path, rawData); final Optional> normalizedNodeOptional = Optional.>fromNullable(normalized.getValue()); - return com.google.common.util.concurrent.Futures.immediateFuture(normalizedNodeOptional); + return Futures.immediateCheckedFuture(normalizedNodeOptional); + } + + @Override public CheckedFuture exists(LogicalDatastoreType store, + YangInstanceIdentifier path) { + + try { + return Futures.immediateCheckedFuture(read(store, path).get().isPresent()); + } catch (InterruptedException | ExecutionException e) { + return Futures.immediateFailedCheckedFuture(new ReadFailedException("Exists failed",e)); + } } } @@ -424,10 +438,10 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc } @Override - public void put(final LogicalDatastoreType store, final InstanceIdentifier path, final NormalizedNode data) { + public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) { final CompositeNode legacyData = dataNormalizer.toLegacy(path, data); try { - final InstanceIdentifier legacyPath = dataNormalizer.toLegacy(path); + final YangInstanceIdentifier legacyPath = dataNormalizer.toLegacy(path); switch (store) { case CONFIGURATION: { @@ -443,15 +457,15 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc } @Override - public void merge(final LogicalDatastoreType store, final InstanceIdentifier path, final NormalizedNode data) { + public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) { // TODO not supported throw new UnsupportedOperationException("Merge not supported for mount point"); } @Override - public void delete(final LogicalDatastoreType store, final InstanceIdentifier path) { + public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) { try { - final InstanceIdentifier legacyPath = dataNormalizer.toLegacy(path); + final YangInstanceIdentifier legacyPath = dataNormalizer.toLegacy(path); switch (store) { case CONFIGURATION: { @@ -508,27 +522,38 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc } @Override - public ListenableFuture>> read(final LogicalDatastoreType store, final InstanceIdentifier path) { + public CheckedFuture>, ReadFailedException> read( + final LogicalDatastoreType store, final YangInstanceIdentifier path) { return new BackwardsCompatibleReadTransaction(dataReader, dataNormalizer).read(store, path); } + @Override public CheckedFuture exists(LogicalDatastoreType store, + YangInstanceIdentifier path) { + + try { + return Futures.immediateCheckedFuture(read(store, path).get().isPresent()); + } catch (InterruptedException | ExecutionException e) { + return Futures.immediateFailedCheckedFuture(new ReadFailedException("Exists failed",e)); + } + } + @Override public boolean cancel() { return delegateWriteTx.cancel(); } @Override - public void put(final LogicalDatastoreType store, final InstanceIdentifier path, final NormalizedNode data) { + public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) { delegateWriteTx.put(store, path, data); } @Override - public void merge(final LogicalDatastoreType store, final InstanceIdentifier path, final NormalizedNode data) { + public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) { delegateWriteTx.merge(store, path, data); } @Override - public void delete(final LogicalDatastoreType store, final InstanceIdentifier path) { + public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) { delegateWriteTx.delete(store, path); }