Integrate mdsal-netconf-monitoring
[netconf.git] / apps / netconf-nb / src / main / java / org / opendaylight / netconf / northbound / 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.netconf.northbound.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.server.api.monitoring.CapabilityListener;
15 import org.opendaylight.netconf.server.api.monitoring.NetconfMonitoringService;
16 import org.opendaylight.netconf.server.api.operations.NetconfOperation;
17 import org.opendaylight.netconf.server.api.operations.NetconfOperationService;
18 import org.opendaylight.netconf.server.api.operations.NetconfOperationServiceFactory;
19 import org.opendaylight.netconf.server.api.operations.NetconfOperationServiceFactoryListener;
20 import org.opendaylight.netconf.server.mdsal.monitoring.GetSchema;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
22 import org.opendaylight.yangtools.concepts.Registration;
23 import org.osgi.service.component.annotations.Activate;
24 import org.osgi.service.component.annotations.Component;
25 import org.osgi.service.component.annotations.Deactivate;
26 import org.osgi.service.component.annotations.Reference;
27
28 @Component(service = { })
29 public final class MdsalMonitoringMapperFactory implements NetconfOperationServiceFactory, AutoCloseable {
30     private final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener;
31     private final NetconfMonitoringService netconfMonitoringService;
32
33     @Activate
34     public MdsalMonitoringMapperFactory(
35             @Reference(target = "(type=mapper-aggregator-registry)")
36             final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener,
37             @Reference(target = "(type=netconf-server-monitoring)")
38             final NetconfMonitoringService netconfMonitoringService) {
39         this.netconfOperationServiceFactoryListener = requireNonNull(netconfOperationServiceFactoryListener);
40         this.netconfMonitoringService = requireNonNull(netconfMonitoringService);
41         this.netconfOperationServiceFactoryListener.onAddNetconfOperationServiceFactory(this);
42     }
43
44     @Deactivate
45     @Override
46     public void close() {
47         netconfOperationServiceFactoryListener.onRemoveNetconfOperationServiceFactory(this);
48     }
49
50     @Override
51     public NetconfOperationService createService(final SessionIdType sessionId) {
52         return new NetconfOperationService() {
53             @Override
54             public Set<NetconfOperation> getNetconfOperations() {
55                 return Set.of(new GetSchema(sessionId, netconfMonitoringService));
56             }
57
58             @Override
59             public void close() {
60                 // NOOP
61             }
62         };
63     }
64
65     @Override
66     public Set<Capability> getCapabilities() {
67         // TODO No capabilities exposed to prevent clashes with schemas from mdsal-netconf-connector (it exposes all the
68         // schemas). If the schemas exposed by mdsal-netconf-connector are filtered, this class would expose monitoring
69         // related models.
70         return Set.of();
71     }
72
73     @Override
74     public Registration registerCapabilityListener(final CapabilityListener listener) {
75         return () -> { };
76     }
77 }