2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.connect.netconf.sal;
10 import java.util.Collection;
11 import java.util.Collections;
13 import java.util.concurrent.ExecutorService;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
16 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
17 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
18 import org.opendaylight.controller.sal.core.api.Broker;
19 import org.opendaylight.controller.sal.core.api.Provider;
20 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
21 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
22 import org.opendaylight.yangtools.yang.binding.RpcService;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.Preconditions;
28 final class NetconfDeviceSalProvider implements AutoCloseable, Provider, BindingAwareProvider {
30 private static final Logger logger = LoggerFactory.getLogger(NetconfDeviceSalProvider.class);
32 private final RemoteDeviceId id;
33 private final ExecutorService executor;
34 private volatile MountProvisionInstance mountInstance;
35 private volatile NetconfDeviceDatastoreAdapter datastoreAdapter;
37 public NetconfDeviceSalProvider(final RemoteDeviceId deviceId, final ExecutorService executor) {
39 this.executor = executor;
42 public MountProvisionInstance getMountInstance() {
43 Preconditions.checkState(mountInstance != null,
44 "%s: Sal provider was not initialized by sal. Cannot publish notification", id);
48 public NetconfDeviceDatastoreAdapter getDatastoreAdapter() {
49 Preconditions.checkState(datastoreAdapter != null,
50 "%s: Sal provider %s was not initialized by sal. Cannot publish notification", id);
51 return datastoreAdapter;
55 public void onSessionInitiated(final Broker.ProviderSession session) {
56 final MountProvisionService mountService = session.getService(MountProvisionService.class);
57 if (mountService != null) {
58 mountInstance = mountService.createOrGetMountPoint(id.getPath());
61 logger.debug("{}: (BI)Session with sal established {}", id, session);
65 public Collection<Provider.ProviderFunctionality> getProviderFunctionality() {
66 return Collections.emptySet();
70 public Collection<? extends RpcService> getImplementations() {
71 return Collections.emptySet();
75 public Collection<? extends BindingAwareProvider.ProviderFunctionality> getFunctionality() {
76 return Collections.emptySet();
80 public void onSessionInitiated(final BindingAwareBroker.ProviderContext session) {
81 final DataProviderService dataBroker = session.getSALService(DataProviderService.class);
82 datastoreAdapter = new NetconfDeviceDatastoreAdapter(id, dataBroker, executor);
84 logger.debug("{}: Session with sal established {}", id, session);
88 public void onSessionInitialized(final BindingAwareBroker.ConsumerContext session) {
91 public void close() throws Exception {
93 datastoreAdapter.close();
94 datastoreAdapter = null;