2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.infra.distro.netconf;
19 import com.google.inject.Inject;
20 import com.google.inject.name.Named;
21 import io.fd.honeycomb.infra.distro.ProviderTrait;
22 import java.lang.reflect.Constructor;
23 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
24 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
25 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
26 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
27 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
28 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 public final class NetconfMonitoringMapperProvider extends ProviderTrait<NetconfOperationServiceFactory> {
35 private static final Logger LOG = LoggerFactory.getLogger(NetconfMonitoringMapperProvider.class);
38 @Named(NetconfModule.HONEYCOMB_NETCONF)
39 private BindingAwareBroker bindingAwareBroker;
41 private NetconfOperationServiceFactoryListener aggregator;
43 private NetconfMonitoringService monitoringService;
46 protected NetconfOperationServiceFactory create() {
48 final Class<?> monitoringWriterCls = Class.forName(
49 "org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.MonitoringToMdsalWriter");
50 Constructor<?> declaredConstructor =
51 monitoringWriterCls.getDeclaredConstructor(NetconfMonitoringService.class);
52 declaredConstructor.setAccessible(true);
53 final BindingAwareProvider o = (BindingAwareProvider) declaredConstructor.newInstance(monitoringService);
54 bindingAwareBroker.registerProvider(o);
56 final Class<?> monitoringMapperCls = Class.forName(
57 "org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.NetconfMdsalMonitoringMapperModule$MdsalMonitoringMapper");
59 monitoringMapperCls.getDeclaredConstructor(NetconfMonitoringService.class);
60 declaredConstructor.setAccessible(true);
61 final NetconfOperationService mdSalMonitoringMapper =
62 (NetconfOperationService) declaredConstructor.newInstance(monitoringService);
64 final Class<?> monitoringMpperFactory = Class.forName(
65 "org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.NetconfMdsalMonitoringMapperModule$MdSalMonitoringMapperFactory");
67 monitoringMpperFactory.getDeclaredConstructor(NetconfOperationService.class);
68 declaredConstructor.setAccessible(true);
69 final NetconfOperationServiceFactory mdSalMonitoringMapperFactory =
70 (NetconfOperationServiceFactory) declaredConstructor.newInstance(mdSalMonitoringMapper);
71 aggregator.onAddNetconfOperationServiceFactory(mdSalMonitoringMapperFactory);
72 return mdSalMonitoringMapperFactory;
73 } catch (final ReflectiveOperationException e) {
74 final String msg = "Unable to instantiate operation service factory using reflection";
76 throw new IllegalStateException(msg, e);