9baab3f7efcdfa2f868770cd9161f987d735ea6d
[transportpce.git] / tests / honeynode / 2.2.1 / honeynode-plugin-impl / src / main / java / io / fd / honeycomb / transportpce / device / configuration / PmConfiguration.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.http.org.openroadm.pm.rev181019.CurrentPmList;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import io.fd.honeycomb.transportpce.device.tools.DefaultPmListFactory;
26 import io.fd.honeycomb.transportpce.test.common.DataStoreContext;
27 import io.fd.honeycomb.transportpce.test.common.DataStoreContextImpl;
28 import net.jmob.guice.conf.core.BindConfig;
29 import net.jmob.guice.conf.core.InjectConfig;
30 import net.jmob.guice.conf.core.Syntax;
31
32 /**
33  * Class containing static configuration for honeynode-plugin module<br>
34  * <p/>
35  * Further documentation for the configuration injection can be found at:
36  * https://github.com/yyvess/gconf
37  */
38 @BindConfig(value = "honeycomb", syntax = Syntax.JSON)
39 public final class PmConfiguration {
40     private static final Logger LOG = LoggerFactory.getLogger(PmConfiguration.class);
41
42     private DataStoreContext dataStoreContextUtil;
43     private DefaultPmListFactory defaultPmListFactory;
44     private ClassLoader classLoader;
45
46     @InjectConfig("netconf-initial-config-xml")
47     public String PM_DATA_SAMPLE_OPER_XML;
48
49     public PmConfiguration() {
50         classLoader = Thread.currentThread().getContextClassLoader();
51         dataStoreContextUtil = new DataStoreContextImpl();
52         defaultPmListFactory = new DefaultPmListFactory();
53     }
54
55     public String getNetconfInitialPmXml() {
56         return PM_DATA_SAMPLE_OPER_XML;
57     }
58
59     public CurrentPmList getDataPm() {
60         CurrentPmList result = null;
61         File pm_list_data = new File(classLoader.getResource(PM_DATA_SAMPLE_OPER_XML).getFile());
62         result = defaultPmListFactory.createDefaultPmList(dataStoreContextUtil, pm_list_data);
63         if (result != null) {
64             LOG.info("result pm list size : {}", result.getCurrentPmEntry().size());
65         } else {
66             LOG.warn("Failed to get PM info !");
67         }
68         return result;
69     }
70 }