Skip to content

Commit

Permalink
issues #1 fix: chnages for reading env
Browse files Browse the repository at this point in the history
  • Loading branch information
manzarul.haque committed Jul 11, 2017
1 parent 9d34cec commit c5a67ae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
3 changes: 2 additions & 1 deletion setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 17 additions & 19 deletions src/main/java/org/sunbird/learner/Application.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/sunbird/learner/util/Util.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit c5a67ae

Please sign in to comment.