bba6537d8d217edd8139962e8d68a74769535403
[transportpce.git] / tests / honeynode / 1.2.1 / honeynode-plugin-impl / src / main / java / io / fd / honeycomb / transportpce / device / configuration / NetconfConfiguration.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.transportpce.device.configuration;
18
19 import java.io.File;
20
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import io.fd.honeycomb.transportpce.device.tools.DefaultNetconfFactory;
27 import io.fd.honeycomb.transportpce.test.common.DataStoreContext;
28 import io.fd.honeycomb.transportpce.test.common.DataStoreContextImpl;
29 import net.jmob.guice.conf.core.BindConfig;
30 import net.jmob.guice.conf.core.InjectConfig;
31 import net.jmob.guice.conf.core.Syntax;
32
33 /**
34  * Class containing static configuration for honeynode-plugin module<br>
35  * <p/>
36  * Further documentation for the configuration injection can be found at:
37  * https://github.com/yyvess/gconf
38  */
39 @BindConfig(value = "honeycomb", syntax = Syntax.JSON)
40 public final class NetconfConfiguration {
41     private static final Logger LOG = LoggerFactory.getLogger(NetconfConfiguration.class);
42
43     private DataStoreContext dataStoreContextUtil;
44     private DefaultNetconfFactory defaultNetconf;
45     private ClassLoader classLoader;
46
47     @InjectConfig("netconf-initial-config-xml")
48     public String NETCONF_DATA_SAMPLE_OPER_XML;
49
50     public NetconfConfiguration() {
51         classLoader = Thread.currentThread().getContextClassLoader();
52         dataStoreContextUtil = new DataStoreContextImpl();
53         defaultNetconf = new DefaultNetconfFactory();
54     }
55
56     public String getNetconfInitialXml() {
57         return NETCONF_DATA_SAMPLE_OPER_XML;
58     }
59
60     public Streams getNetconfStreamsData() {
61         Streams result = null;
62         File netconf_data = new File(classLoader.getResource(NETCONF_DATA_SAMPLE_OPER_XML).getFile());
63         Netconf netconf = defaultNetconf.createDefaultNetconf(dataStoreContextUtil, netconf_data);
64         if (netconf != null) {
65             try {
66                 result = netconf.getStreams();
67                 LOG.info("netconf streams result : {}", netconf.getStreams());
68             } catch (NullPointerException e) {
69                 LOG.error("failed to get Netconf Streams");
70             }
71         } else {
72             LOG.warn("failed to get Netconf Streams");
73         }
74         return result;
75     }
76 }