YANG Model update for A1 Adapter
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / impl / conf / odlAkka / AkkaConfig.java
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.conf.odlAkka;
19
20 import java.io.File;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import com.typesafe.config.Config;
26 import com.typesafe.config.ConfigFactory;
27
28 public class AkkaConfig {
29
30     @SuppressWarnings("unused")
31     private static final Logger LOG = LoggerFactory.getLogger(AkkaConfig.class);
32
33     private static final String DEFAULT_FILENAME = "configuration/initial/akka.conf";
34     private final String filename;
35     private ClusterConfig cluserConfig;
36
37     public ClusterConfig getClusterConfig() {
38         return this.cluserConfig;
39     }
40
41     private AkkaConfig(String filename) {
42         this.filename = filename;
43     }
44
45     public AkkaConfig() {
46         this(null);
47     }
48
49     @Override
50     public String toString() {
51         return "AkkaConfig [filename=" + filename + ", cluserConfig=" + cluserConfig + "]";
52     }
53
54     private void loadFromFile() throws Exception {
55         Config cfg = ConfigFactory.parseFile(new File(this.filename));
56         this.cluserConfig = new ClusterConfig(cfg.getConfig("odl-cluster-data").getConfig("akka").getConfig("cluster"));
57     }
58
59     public boolean isCluster() {
60         return this.cluserConfig != null ? this.cluserConfig.isCluster() : false;
61     }
62
63     public boolean isClusterAndFirstNode() {
64         return isSingleNode() || isCluster() && getClusterConfig().getRoleMemberIndex() == 1;
65     }
66
67     public static AkkaConfig load() throws Exception {
68         return load(DEFAULT_FILENAME);
69     }
70
71     public static AkkaConfig load(String filename) throws Exception {
72         AkkaConfig cfg = new AkkaConfig(filename);
73         cfg.loadFromFile();
74         return cfg;
75     }
76
77     public boolean isSingleNode() {
78         return !this.isCluster();
79     }
80      public static AkkaConfig parse(String content) throws Exception {
81         Config cfg = ConfigFactory.parseString(content);
82         AkkaConfig c = new AkkaConfig();
83         c.cluserConfig=new ClusterConfig(cfg.getConfig("odl-cluster-data").getConfig("akka").getConfig("cluster"));
84         return c;
85     }
86 }