82359499568db4ce2a5fce6c8d3cbea16f2ee492
[netconf.git] / netconf / mdsal-netconf-monitoring / src / main / java / org / opendaylight / controller / config / yang / netconf / mdsal / monitoring / MdsalMonitoringMapperFactory.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.config.yang.netconf.mdsal.monitoring;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Set;
13 import org.opendaylight.netconf.api.capability.Capability;
14 import org.opendaylight.netconf.api.monitoring.CapabilityListener;
15 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
16 import org.opendaylight.netconf.mapping.api.NetconfOperation;
17 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
18 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
19 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener;
20 import org.opendaylight.yangtools.concepts.Registration;
21 import org.osgi.service.component.annotations.Activate;
22 import org.osgi.service.component.annotations.Component;
23 import org.osgi.service.component.annotations.Deactivate;
24 import org.osgi.service.component.annotations.Reference;
25
26 @Component(service = { })
27 public final class MdsalMonitoringMapperFactory implements NetconfOperationServiceFactory, AutoCloseable {
28     private final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener;
29     private final NetconfMonitoringService netconfMonitoringService;
30
31     @Activate
32     public MdsalMonitoringMapperFactory(
33             @Reference(target = "(type=mapper-aggregator-registry)")
34             final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener,
35             @Reference(target = "(type=netconf-server-monitoring)")
36             final NetconfMonitoringService netconfMonitoringService) {
37         this.netconfOperationServiceFactoryListener = requireNonNull(netconfOperationServiceFactoryListener);
38         this.netconfMonitoringService = requireNonNull(netconfMonitoringService);
39         this.netconfOperationServiceFactoryListener.onAddNetconfOperationServiceFactory(this);
40     }
41
42     @Deactivate
43     @Override
44     public void close() {
45         netconfOperationServiceFactoryListener.onRemoveNetconfOperationServiceFactory(this);
46     }
47
48     @Override
49     public NetconfOperationService createService(final String netconfSessionIdForReporting) {
50         return new NetconfOperationService() {
51             @Override
52             public Set<NetconfOperation> getNetconfOperations() {
53                 return Set.of(new GetSchema(netconfSessionIdForReporting, netconfMonitoringService));
54             }
55
56             @Override
57             public void close() {
58                 // NOOP
59             }
60         };
61     }
62
63     @Override
64     public Set<Capability> getCapabilities() {
65         // TODO No capabilities exposed to prevent clashes with schemas from mdsal-netconf-connector (it exposes all the
66         // schemas). If the schemas exposed by mdsal-netconf-connector are filtered, this class would expose monitoring
67         // related models.
68         return Set.of();
69     }
70
71     @Override
72     public Registration registerCapabilityListener(final CapabilityListener listener) {
73         return () -> { };
74     }
75 }