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=0000000000000000000000000000000000000000;hp=003ad9853a32a20d7df06262a6c2490e7f6dfe0d;hb=89b8b59cd26fd4810293ff14386eb29a71da9fac;hpb=9ba2b4eca79bcc0e78099b133296801c8d45a6c4 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 deleted file mode 100644 index 003ad9853a..0000000000 --- a/opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/DataBrokerServiceImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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 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.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.AbstractListenerRegistration; -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.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Optional; - -public class DataBrokerServiceImpl implements DataBrokerService { - - private static final Logger logger = LoggerFactory.getLogger(DataBrokerServiceImpl.class.toString()); - private final RestconfClientContext restconfClientContext; - private final SalRemoteService salRemoteService; - - public DataBrokerServiceImpl(RestconfClientContext restconfClientContext) { - this.restconfClientContext = restconfClientContext; - this.salRemoteService = this.restconfClientContext.getRpcServiceContext(SalRemoteService.class).getRpcService(); - } - - @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 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); - final ListenerRegistration reg = restConfListenableEventStreamContext.registerNotificationListener(remoteDataChangeNotificationListener); - return new AbstractListenerRegistration(listener) { - @Override - protected void removeRegistration() { - reg.close(); - } - }; - } -}