import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
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 java.util.concurrent.ExecutionException;
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.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;
import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService;
import org.opendaylight.controller.sal.dom.broker.impl.NotificationRouterImpl;
import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker;
-import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProvider;
import org.opendaylight.controller.sal.dom.broker.spi.NotificationRouter;
import org.opendaylight.controller.sal.dom.broker.util.ProxySchemaContext;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
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.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 org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
+@Deprecated
public class BackwardsCompatibleMountPoint implements MountProvisionInstance, SchemaContextProvider, SchemaService {
private final DataProviderService dataReader;
- private final DataReader<InstanceIdentifier,CompositeNode> readWrapper;
+ private final DataReader<YangInstanceIdentifier,CompositeNode> readWrapper;
- private final InstanceIdentifier mountPath;
+ private final YangInstanceIdentifier mountPath;
private final NotificationPublishService notificationPublishService;
private final RpcProvisionRegistry rpcs;
- private final ListenerRegistry<SchemaServiceListener> schemaListenerRegistry = new ListenerRegistry<>();
+ private final ListenerRegistry<SchemaContextListener> 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);
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);
final DOMDataBroker domBroker = getServiceWithCheck(mount, DOMDataBroker.class);
this.schemaContext = mount.getSchemaContext();
+
dataReader = new BackwardsCompatibleDataBroker(domBroker, this);
+
+ // Set schema context to provide it for BackwardsCompatibleDataBroker
+ if(schemaContext != null) {
+ setSchemaContext(schemaContext);
+ }
+
readWrapper = new ReadWrapper();
notificationPublishService = getServiceWithCheck(mount, NotificationPublishService.class);
}
@Override
- public ListenerRegistration<SchemaServiceListener> registerSchemaServiceListener(final SchemaServiceListener listener) {
+ public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(final SchemaContextListener listener) {
return schemaListenerRegistry.register(listener);
}
}
// TODO Read wrapper is never used ... same in org.opendaylight.controller.sal.dom.broker.MountPointImpl
- public DataReader<InstanceIdentifier, CompositeNode> getReadWrapper() {
+ public DataReader<YangInstanceIdentifier, CompositeNode> 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<InstanceIdentifier, CompositeNode> reader) {
+ final YangInstanceIdentifier path, final DataReader<YangInstanceIdentifier, CompositeNode> reader) {
return dataReader.registerOperationalReader(path, reader);
}
@Override
public Registration registerConfigurationReader(
- final InstanceIdentifier path, final DataReader<InstanceIdentifier, CompositeNode> reader) {
+ final YangInstanceIdentifier path, final DataReader<YangInstanceIdentifier, CompositeNode> reader) {
return dataReader.registerConfigurationReader(path, reader);
}
}
@Override
- public ListenerRegistration<DataChangeListener> registerDataChangeListener(final InstanceIdentifier path,
+ public ListenerRegistration<DataChangeListener> registerDataChangeListener(final YangInstanceIdentifier path,
final DataChangeListener listener) {
return dataReader.registerDataChangeListener(path, listener);
}
@Override
public Registration registerCommitHandler(
- final InstanceIdentifier path, final DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
+ final YangInstanceIdentifier path, final DataCommitHandler<YangInstanceIdentifier, CompositeNode> commitHandler) {
return dataReader.registerCommitHandler(path, commitHandler);
}
@Override
public void setSchemaContext(final SchemaContext schemaContext) {
this.schemaContext = schemaContext;
- for (ListenerRegistration<SchemaServiceListener> schemaServiceListenerListenerRegistration : schemaListenerRegistry.getListeners()) {
+ for (ListenerRegistration<SchemaContextListener> schemaServiceListenerListenerRegistration : schemaListenerRegistry.getListeners()) {
schemaServiceListenerListenerRegistration.getInstance().onGlobalContextUpdated(schemaContext);
}
}
- class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
- private InstanceIdentifier shortenPath(final InstanceIdentifier path) {
- InstanceIdentifier ret = null;
- if(mountPath.contains(path)) {
- final List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
- ret = InstanceIdentifier.create(newArgs);
+ class ReadWrapper implements DataReader<YangInstanceIdentifier, CompositeNode> {
+ private YangInstanceIdentifier shortenPath(final YangInstanceIdentifier path) {
+ if (!mountPath.contains(path)) {
+ return null;
}
- return ret;
+ return YangInstanceIdentifier.create(Iterables.skip(path.getPathArguments(), Iterables.size(mountPath.getPathArguments())));
}
@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;
}
}
@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;
}
}
@Override
- public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
- final RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
+ public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<YangInstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
+ final RegistrationListener<DataCommitHandlerRegistration<YangInstanceIdentifier, CompositeNode>> commitHandlerListener) {
return dataReader.registerCommitHandlerListener(commitHandlerListener);
}
@Override
- public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
+ public <L extends RouteChangeListener<RpcRoutingContext, YangInstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(
final L listener) {
return rpcs.registerRouteChangeListener(listener);
}
}
@Override
- public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, final InstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
+ public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
throw new UnsupportedOperationException("Register data listener not supported for mount point");
}
}
@Override
- public ListenableFuture<Optional<NormalizedNode<?, ?>>> read(final LogicalDatastoreType store, final InstanceIdentifier path) {
+ public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
+ final LogicalDatastoreType store, final YangInstanceIdentifier path) {
CompositeNode rawData = null;
}
Preconditions.checkNotNull(rawData, "Unable to read %s data on path %s", store, path);
- final Map.Entry<InstanceIdentifier, NormalizedNode<?, ?>> normalized = normalizer.toNormalized(path, rawData);
+ final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> normalized = normalizer.toNormalized(path, rawData);
final Optional<NormalizedNode<?, ?>> normalizedNodeOptional = Optional.<NormalizedNode<?, ?>>fromNullable(normalized.getValue());
- return com.google.common.util.concurrent.Futures.immediateFuture(normalizedNodeOptional);
+ return Futures.immediateCheckedFuture(normalizedNodeOptional);
+ }
+
+ @Override public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
+ final 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 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: {
}
@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: {
}
@Override
- public ListenableFuture<Optional<NormalizedNode<?, ?>>> read(final LogicalDatastoreType store, final InstanceIdentifier path) {
+ public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
+ final LogicalDatastoreType store, final YangInstanceIdentifier path) {
return new BackwardsCompatibleReadTransaction(dataReader, dataNormalizer).read(store, path);
}
+ @Override public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
+ final 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);
}