X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-restconf-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fbroker%2Fimpl%2FDataBrokerServiceImpl.java;fp=opendaylight%2Fmd-sal%2Fsal-restconf-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fbroker%2Fimpl%2FDataBrokerServiceImpl.java;h=e6659c226520f2cd7cf7c9de03716d333d9de7f5;hp=0000000000000000000000000000000000000000;hb=d17dcf6c084be6f33515ea2d957884918fbe7a1c;hpb=1c67e75387f441591ab3d0ec8bbe53fabf962a23 diff --git a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/DataBrokerServiceImpl.java b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/DataBrokerServiceImpl.java new file mode 100644 index 0000000000..e6659c2265 --- /dev/null +++ b/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/DataBrokerServiceImpl.java @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.sal.restconf.broker.impl; + +import com.google.common.base.Optional; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import org.opendaylight.controller.sal.binding.api.data.DataBrokerService; +import org.opendaylight.controller.sal.binding.api.data.DataChangeListener; +import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction; +import org.opendaylight.controller.sal.common.DataStoreIdentifier; +import org.opendaylight.controller.sal.restconf.broker.listeners.RemoteDataChangeNotificationListener; +import org.opendaylight.controller.sal.restconf.broker.tools.RemoteStreamTools; +import org.opendaylight.controller.sal.restconf.broker.transactions.RemoteDataModificationTransaction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.BeginTransactionOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateDataChangeEventSubscriptionInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.CreateDataChangeEventSubscriptionOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.SalRemoteService; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext; +import org.opendaylight.yangtools.restconf.client.api.event.EventStreamInfo; +import org.opendaylight.yangtools.restconf.client.api.event.ListenableEventStreamContext; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.DataRoot; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DataBrokerServiceImpl implements DataBrokerService { + + private static final Logger logger = LoggerFactory.getLogger(DataBrokerServiceImpl.class.toString()); + private RestconfClientContext restconfClientContext; + private SalRemoteService salRemoteService; + + public DataBrokerServiceImpl(RestconfClientContext restconfClientContext) { + this.restconfClientContext = restconfClientContext; + this.salRemoteService = this.restconfClientContext.getRpcServiceContext(SalRemoteService.class).getRpcService(); + } + @Override + public T getData(DataStoreIdentifier store, Class rootType) { + throw new UnsupportedOperationException("Deprecated"); + } + + @Override + public T getData(DataStoreIdentifier store, T filter) { + throw new UnsupportedOperationException("Deprecated"); + } + + @Override + public T getCandidateData(DataStoreIdentifier store, Class rootType) { + throw new UnsupportedOperationException("Deprecated"); + } + + @Override + public T getCandidateData(DataStoreIdentifier store, T filter) { + throw new UnsupportedOperationException("Deprecated"); + } + + @Override + public RpcResult editCandidateData(DataStoreIdentifier store, DataRoot changeSet) { + throw new UnsupportedOperationException("Deprecated"); + } + + @Override + public Future> commit(DataStoreIdentifier store) { + throw new UnsupportedOperationException("Deprecated"); + } + + @Override + public DataObject getData(InstanceIdentifier data) { + throw new UnsupportedOperationException("Deprecated"); + } + + @Override + public DataObject getConfigurationData(InstanceIdentifier data) { + throw new UnsupportedOperationException("Deprecated"); + } + + @Override + public DataModificationTransaction beginTransaction() { + Future> rpcResultFuture = this.salRemoteService.beginTransaction(); + //TODO finish yang model for proper remoteDataModificationTransaction setup + RemoteDataModificationTransaction remoteDataModificationTransaction = new RemoteDataModificationTransaction(); + return remoteDataModificationTransaction; + } + + @Override + public void registerChangeListener(InstanceIdentifier path, DataChangeListener changeListener) { + throw new UnsupportedOperationException("Deprecated"); + } + + @Override + public void unregisterChangeListener(InstanceIdentifier path, DataChangeListener changeListener) { + throw new UnsupportedOperationException("Deprecated"); + } + + @Override + public DataObject readConfigurationData(InstanceIdentifier path) { + try { + Optional optDataObject = (Optional) this.restconfClientContext.getConfigurationDatastore().readData(path).get(); + if (optDataObject.isPresent()){ + return optDataObject.get(); + } + } catch (InterruptedException e) { + logger.trace("Reading configuration data interrupted {}",e); + } catch (ExecutionException e) { + logger.trace("Reading configuration execution exception {}",e); + } + throw new IllegalStateException("No data to return."); + } + + @Override + public DataObject readOperationalData(InstanceIdentifier path) { + try { + Optional optDataObject = (Optional) this.restconfClientContext.getOperationalDatastore().readData(path).get(); + if (optDataObject.isPresent()){ + return optDataObject.get(); + } + } catch (InterruptedException e) { + logger.trace("Reading configuration data interrupted {}",e); + } catch (ExecutionException e) { + logger.trace("Reading configuration execution exception {}",e); + } + throw new IllegalStateException("No data to return."); + } + @Override + public ListenerRegistration registerDataChangeListener(InstanceIdentifier path, DataChangeListener listener) { + CreateDataChangeEventSubscriptionInputBuilder inputBuilder = new CreateDataChangeEventSubscriptionInputBuilder(); + Future> rpcResultFuture = salRemoteService.createDataChangeEventSubscription(inputBuilder.setPath(path).build()); + String streamName = ""; + try { + if (rpcResultFuture.get().isSuccessful()){ + streamName = rpcResultFuture.get().getResult().getStreamName(); + } + } catch (InterruptedException e) { + logger.trace("Interupted while getting rpc result due to {}",e); + } catch (ExecutionException e) { + logger.trace("Execution exception while getting rpc result due to {}",e); + } + final Map desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext,streamName); + ListenableEventStreamContext restConfListenableEventStreamContext = restconfClientContext.getEventStreamContext(desiredEventStream.get(streamName)); + RemoteDataChangeNotificationListener remoteDataChangeNotificationListener = new RemoteDataChangeNotificationListener(listener); + restConfListenableEventStreamContext.registerNotificationListener(remoteDataChangeNotificationListener); + return new SalRemoteDataListenerRegistration(listener); + } + + private class SalRemoteDataListenerRegistration implements ListenerRegistration { + private DataChangeListener dataChangeListener; + public SalRemoteDataListenerRegistration(DataChangeListener dataChangeListener){ + this.dataChangeListener = dataChangeListener; + } + @Override + public DataChangeListener getInstance() { + return this.dataChangeListener; + } + @Override + public void close() throws Exception { + //noop + } + } +}