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