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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl;
20 import com.typesafe.config.Config;
21 import com.typesafe.config.ConfigFactory;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.util.ClusterConfig;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class AkkaConfig {
29 @SuppressWarnings("unused")
30 private static final Logger LOG = LoggerFactory.getLogger(AkkaConfig.class);
32 private static final String DEFAULT_FILENAME = "configuration/initial/akka.conf";
33 private final String filename;
34 private ClusterConfig cluserConfig;
36 public ClusterConfig getClusterConfig() {
37 return this.cluserConfig;
40 private AkkaConfig(String filename) {
41 this.filename = filename;
49 public String toString() {
50 return "AkkaConfig [filename=" + filename + ", cluserConfig=" + cluserConfig + "]";
53 private void loadFromFile() throws Exception {
54 Config cfg = ConfigFactory.parseFile(new File(this.filename));
55 this.cluserConfig = new ClusterConfig(cfg.getConfig("odl-cluster-data").getConfig("akka").getConfig("cluster"));
58 public boolean isCluster() {
59 return this.cluserConfig != null ? this.cluserConfig.isCluster() : false;
62 public boolean isClusterAndFirstNode() {
63 return isSingleNode() || isCluster() && getClusterConfig().getRoleMemberIndex() == 1;
66 public static AkkaConfig load() throws Exception {
67 return load(DEFAULT_FILENAME);
70 public static AkkaConfig load(String filename) throws Exception {
71 AkkaConfig cfg = new AkkaConfig(filename);
76 public boolean isSingleNode() {
77 return !this.isCluster();
79 public static AkkaConfig parse(String content) throws Exception {
80 Config cfg = ConfigFactory.parseString(content);
81 AkkaConfig c = new AkkaConfig();
82 c.cluserConfig=new ClusterConfig(cfg.getConfig("odl-cluster-data").getConfig("akka").getConfig("cluster"));