From c5a67aea124f3fd49b29241b5cfe967604582ad5 Mon Sep 17 00:00:00 2001 From: "manzarul.haque" Date: Tue, 11 Jul 2017 17:46:10 +0530 Subject: [PATCH] issues #1 fix: chnages for reading env --- setup.md | 3 +- .../java/org/sunbird/learner/Application.java | 36 +++++++++---------- .../java/org/sunbird/learner/util/Util.java | 7 ++-- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/setup.md b/setup.md index fe25c6f48..5b8077cb2 100644 --- a/setup.md +++ b/setup.md @@ -14,7 +14,8 @@ 5. sunbird_es_host: host running the elasticsearch server 6. sunbird_es_port: port on which elasticsearch server is running 7. sunbird_es_cluster (optional): name of the elasticsearch cluster - 8. sunbird_actor_file_path + 8. sunbird_learner_actor_host: host running for learner actor + 9.sunbird_learner_actor_port: port on which learner actor is running. 2. Actor configuration: Actor configuration is provided via [application.conf](https://github.com/ekstep/sunbird-mw/blob/alpha2/actors/learner-actor/src/main/resources/application.conf) file. The project is bundled with default application.conf file which runs 5 instances of each actor with hostname as "127.0.0.1" and on the port "8088". This configuration can be overrided by providing a custom application.conf file: 1. hostname: the hostname on the which the akka actors will be listening 2. port: port on which the akka actors will be listening diff --git a/src/main/java/org/sunbird/learner/Application.java b/src/main/java/org/sunbird/learner/Application.java index dbd2f9b93..c6c9aa761 100644 --- a/src/main/java/org/sunbird/learner/Application.java +++ b/src/main/java/org/sunbird/learner/Application.java @@ -1,7 +1,5 @@ package org.sunbird.learner; -import java.io.File; - import org.sunbird.common.models.util.JsonKey; import org.sunbird.common.models.util.LogHelper; import org.sunbird.common.models.util.ProjectUtil; @@ -31,24 +29,24 @@ public static void main(String[] args) { /** * This method will do the basic setup for actors. */ - private static void startRemoteCreationSystem(){ - String filePath = System.getenv(JsonKey.SUNBIRD_ACTOR_FILE_PATH); - Config con = null; - File file = null; - if(!ProjectUtil.isStringNullOREmpty(filePath)){ - file = new File(System.getenv("sunbird_file_path")); - } - if( file !=null && file.exists()){ - con = ConfigFactory.parseFile(file).getConfig(ACTOR_CONFIG_NAME); - } else { - con = ConfigFactory.load().getConfig(ACTOR_CONFIG_NAME); - } - system = ActorSystem.create(ACTOR_SYSTEM_NAME, con); - ActorRef learnerActorSelectorRef = system.actorOf(Props.create(RequestRouterActor.class), - RequestRouterActor.class.getSimpleName()); - logger.info("ACTORS STARTED " + learnerActorSelectorRef); - checkCassandraConnection(); + private static void startRemoteCreationSystem() { + Config con = null; + String host = System.getenv(JsonKey.SUNBIRD_ACTOR_SERVICE_IP); + String port = System.getenv(JsonKey.SUNBIRD_ACTOR_SERVICE_PORT); + if (!ProjectUtil.isStringNullOREmpty(host) && !ProjectUtil.isStringNullOREmpty(port)) { + con = ConfigFactory + .parseString( + "akka.remote.netty.tcp.hostname=" + host + ",akka.remote.netty.tcp.port=" + port + "") + .withFallback(ConfigFactory.load().getConfig(ACTOR_CONFIG_NAME)); + } else { + con = ConfigFactory.load().getConfig(ACTOR_CONFIG_NAME); } + system = ActorSystem.create(ACTOR_SYSTEM_NAME, con); + ActorRef learnerActorSelectorRef = system.actorOf(Props.create(RequestRouterActor.class), + RequestRouterActor.class.getSimpleName()); + logger.info("ACTORS STARTED " + learnerActorSelectorRef); + checkCassandraConnection(); + } private static void checkCassandraConnection() { Util.checkCassandraDbConnections(); diff --git a/src/main/java/org/sunbird/learner/util/Util.java b/src/main/java/org/sunbird/learner/util/Util.java index f863ad2ea..891f41ce7 100644 --- a/src/main/java/org/sunbird/learner/util/Util.java +++ b/src/main/java/org/sunbird/learner/util/Util.java @@ -1,6 +1,7 @@ package org.sunbird.learner.util; import com.fasterxml.jackson.databind.ObjectMapper; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -120,12 +121,14 @@ public static void checkCassandraDbConnections() { public static boolean readConfigFromEnv() { boolean response = false; String ips = System.getenv(JsonKey.SUNBIRD_CASSANDRA_IP); - if (ProjectUtil.isStringNullOREmpty(ips)) { + String envPort = System.getenv(JsonKey.SUNBIRD_CASSANDRA_PORT); + + if (ProjectUtil.isStringNullOREmpty(ips) || ProjectUtil.isStringNullOREmpty(envPort) ) { logger.info("Configuration value is not coming form System variable."); return response; } String[] ipList = ips.split(","); - String[] portList = System.getenv(JsonKey.SUNBIRD_CASSANDRA_PORT).split(","); + String[] portList = envPort.split(","); String userName = System.getenv(JsonKey.SUNBIRD_CASSANDRA_USER_NAME); String password = System.getenv(JsonKey.SUNBIRD_CASSANDRA_PASSWORD); for (int i = 0; i < ipList.length; i++) {