Merge "Bug 7172 - Correct error-info for missing-attribute errors"
[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 org.opendaylight.controller.config.util.capability.Capability;
11 import org.opendaylight.controller.sal.common.util.NoopAutoCloseable;
12 import org.opendaylight.netconf.api.monitoring.CapabilityListener;
13 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
14 import org.opendaylight.netconf.mapping.api.NetconfOperation;
15 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
16 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
17 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener;
18 import org.opendaylight.netconf.monitoring.GetSchema;
19
20 import java.util.Collections;
21 import java.util.Set;
22
23 public class MdsalMonitoringMapperFactory implements NetconfOperationServiceFactory, AutoCloseable {
24
25     private final NetconfOperationService operationService;
26     private final MonitoringToMdsalWriter monitoringToMdsalWriter;
27     private final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener;
28
29     private static final Set<Capability> CAPABILITIES = Collections.emptySet();
30
31     public MdsalMonitoringMapperFactory(final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener,
32                                         final NetconfMonitoringService netconfMonitoringService,
33                                         final MonitoringToMdsalWriter monitoringToMdsalWriter) {
34
35         this.netconfOperationServiceFactoryListener = netconfOperationServiceFactoryListener;
36         this.monitoringToMdsalWriter = monitoringToMdsalWriter;
37
38         this.operationService = new NetconfOperationService() {
39             @Override
40             public Set<NetconfOperation> getNetconfOperations() {
41                 return Collections.singleton(new GetSchema(netconfMonitoringService));
42             }
43
44             @Override
45             public void close() {
46                 // NOOP
47             }
48         };
49
50         this.netconfOperationServiceFactoryListener.onAddNetconfOperationServiceFactory(this);
51     }
52
53     @Override
54     public NetconfOperationService createService(final String netconfSessionIdForReporting) {
55         return operationService;
56     }
57
58     @Override
59     public Set<Capability> getCapabilities() {
60         // TODO
61         // No capabilities exposed to prevent clashes with schemas from mdsal-netconf-connector (it exposes all the schemas)
62         // If the schemas exposed by mdsal-netconf-connector are filtered, this class would expose monitoring related models
63         return CAPABILITIES;
64     }
65
66     @Override
67     public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
68         return NoopAutoCloseable.INSTANCE;
69     }
70
71     /**
72      * Invoke using blueprint
73      */
74     @Override
75     public void close() {
76         monitoringToMdsalWriter.close();
77         netconfOperationServiceFactoryListener.onRemoveNetconfOperationServiceFactory(this);
78     }
79
80 }