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.impl.conf.odlAkka;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.typesafe.config.Config;
26 import com.typesafe.config.ConfigFactory;
28 public class AkkaConfig {
30 @SuppressWarnings("unused")
31 private static final Logger LOG = LoggerFactory.getLogger(AkkaConfig.class);
33 private static final String DEFAULT_FILENAME = "configuration/initial/akka.conf";
34 private final String filename;
35 private ClusterConfig cluserConfig;
37 public ClusterConfig getClusterConfig() {
38 return this.cluserConfig;
41 private AkkaConfig(String filename) {
42 this.filename = filename;
50 public String toString() {
51 return "AkkaConfig [filename=" + filename + ", cluserConfig=" + cluserConfig + "]";
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"));
59 public boolean isCluster() {
60 return this.cluserConfig != null ? this.cluserConfig.isCluster() : false;
63 public boolean isClusterAndFirstNode() {
64 return isSingleNode() || isCluster() && getClusterConfig().getRoleMemberIndex() == 1;
67 public static AkkaConfig load() throws Exception {
68 return load(DEFAULT_FILENAME);
71 public static AkkaConfig load(String filename) throws Exception {
72 AkkaConfig cfg = new AkkaConfig(filename);
77 public boolean isSingleNode() {
78 return !this.isCluster();
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"));