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 com.google.common.base.Preconditions;
11 import java.util.Collection;
12 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 final class NetconfDeviceSalProvider implements AutoCloseable, Provider, BindingAwareProvider {
28 private static final Logger logger = LoggerFactory.getLogger(NetconfDeviceSalProvider.class);
30 private final RemoteDeviceId id;
31 private final ExecutorService executor;
32 private volatile MountProvisionInstance mountInstance;
33 private volatile NetconfDeviceDatastoreAdapter datastoreAdapter;
35 public NetconfDeviceSalProvider(final RemoteDeviceId deviceId, final ExecutorService executor) {
37 this.executor = executor;
40 public MountProvisionInstance getMountInstance() {
41 Preconditions.checkState(mountInstance != null,
42 "%s: Sal provider was not initialized by sal. Cannot get mount instance", id);
46 public NetconfDeviceDatastoreAdapter getDatastoreAdapter() {
47 Preconditions.checkState(datastoreAdapter != null,
48 "%s: Sal provider %s was not initialized by sal. Cannot get datastore adapter", id);
49 return datastoreAdapter;
53 public void onSessionInitiated(final Broker.ProviderSession session) {
54 final MountProvisionService mountService = session.getService(MountProvisionService.class);
55 if (mountService != null) {
56 mountInstance = mountService.createOrGetMountPoint(id.getPath());
59 logger.debug("{}: (BI)Session with sal established {}", id, session);
63 public Collection<Provider.ProviderFunctionality> getProviderFunctionality() {
64 return Collections.emptySet();
68 public Collection<? extends RpcService> getImplementations() {
69 return Collections.emptySet();
73 public Collection<? extends BindingAwareProvider.ProviderFunctionality> getFunctionality() {
74 return Collections.emptySet();
78 public void onSessionInitiated(final BindingAwareBroker.ProviderContext session) {
79 final DataProviderService dataBroker = session.getSALService(DataProviderService.class);
80 datastoreAdapter = new NetconfDeviceDatastoreAdapter(id, dataBroker, executor);
82 logger.debug("{}: Session with sal established {}", id, session);
86 public void onSessionInitialized(final BindingAwareBroker.ConsumerContext session) {
89 public void close() throws Exception {
91 datastoreAdapter.close();
92 datastoreAdapter = null;