Skip to content

Commit

Permalink
issue #1 fix: changes project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
manzarul.haque committed Jul 3, 2017
0 parents commit e085012
Show file tree
Hide file tree
Showing 37 changed files with 5,099 additions and 0 deletions.
99 changes: 99 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sunbird</groupId>
<artifactId>learner-state-actor</artifactId>
<name>sunbird_learner_actor</name>
<version>1.0-SNAPSHOT</version>
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<includes>
<include>**/*Spec.java</include>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>4.0.5</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
<excludes>
<exclude>**/*.scala</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.sunbird.learner.Application</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer>
<resource>reference.conf</resource>
</transformer>
<transformer>
<mainClass>org.sunbird.learner.Application</mainClass>
</transformer>
<transformer />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<logback.version>1.0.7</logback.version>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<slf4j.version>1.6.1</slf4j.version>
<version.compiler.plugin>2.3.1</version.compiler.plugin>
<scoverage.plugin.version>1.1.1</scoverage.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>

170 changes: 170 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sunbird</groupId>
<artifactId>learner-state-actor</artifactId>
<version>1.0-SNAPSHOT</version>
<name>sunbird_learner_actor</name>
<properties>
<version.compiler.plugin>2.3.1</version.compiler.plugin>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<scoverage.plugin.version>1.1.1</scoverage.plugin.version>
<slf4j.version>1.6.1</slf4j.version>
<logback.version>1.0.7</logback.version>
</properties>
<dependencies>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-slf4j_2.11</artifactId>
<version>2.5.1</version>
</dependency>
<!-- <dependency>
<groupId>org.sunbird</groupId>
<artifactId>common-util</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> -->
<dependency>
<groupId>org.sunbird</groupId>
<artifactId>cassandra-dac</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.sunbird</groupId>
<artifactId>common.elastic</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-remote_2.11</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.typesafe.akka/akka-testkit_2.11 -->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_2.11</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
</dependencies>

<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
<plugins>
<!-- to create executable jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.sunbird.learner.Application</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<includes>
<include>**/*Spec.java</include>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>4.0.5</version>
<configuration>
<!--<targetPercentage>1%</targetPercentage>-->
<includes>
<include>**/*.java</include>
</includes>
<excludes>
<exclude>**/*.scala</exclude>
</excludes>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- to run application -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.sunbird.learner.Application</mainClass>
</configuration>
</plugin>

</plugins>
</pluginManagement>
</build>
</project>
32 changes: 32 additions & 0 deletions setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Pre-requisites
1. Cassandra
1. Install Cassandra database and start the server
2. Run [cassandra.cql](https://github.com/ekstep/sunbird-mw/blob/alpha2/actors/learner-state-mw/src/main/resources/cassandra.cql) file to create the required keyspaces, tables and indices
2. ElasticSearch
1. Install ElasticSearch database and start the server

## Configuration
1. Environment Variables:
1. sunbird_cassandra_host: host running the cassandra server
2. sunbird_cassandra_port: port on which cassandra server is running
3. sunbird_cassandra_username (optional): username for cassandra database, if authentication is enabled
4. sunbird_cassandra_password (optional): password for cassandra database, if authentication is enabled
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
2. Actor configuration: Actor configuration is provided via [application.conf](https://github.com/ekstep/sunbird-mw/blob/alpha2/actors/learner-state-mw/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
3. router: type of router to be used for switching between actors
4. nr-of-instances: number of instances of actor to run in this host

## Build
1. Run "mvn clean install" from "sunbird-mw/actors" to build the actors.
2. The build file is a executable jar file "learner-state-actor-1.0-SNAPSHOT.jar" generated in "sunbird-mw/actors/learner-state-mw/target" folder

## Run
1. Actors can be started with default configuration by running **java -cp "learner-state-actor-1.0-SNAPSHOT.jar" org.sunbird.learner.Application**
2. To run the actors with custom configuration:
1. Create **application.conf** file with the custom configuration. Sample [application.conf](https://github.com/ekstep/sunbird-mw/blob/alpha2/actors/learner-state-mw/src/main/resources/application.conf)
2. Run the command **java -cp "path_to_folder_containing_custom_application.conf:learner-state-actor-1.0-SNAPSHOT.jar" org.sunbird.learner.Application**. This will override the default configuration (like hostname, port, etc).
25 changes: 25 additions & 0 deletions src/main/java/org/sunbird/bean/ContentResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
*
*/
package org.sunbird.bean;

import java.util.Map;

/**
* @author Manzarul
*
*/
public class ContentResponse {
private Map<String,Object> result;

public Map<String, Object> getResult() {
return result;
}

public void setResult(Map<String, Object> result) {
this.result = result;
}



}
57 changes: 57 additions & 0 deletions src/main/java/org/sunbird/learner/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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;
import org.sunbird.learner.actors.RequestRouterActor;
import org.sunbird.learner.util.SchedulerManager;
import org.sunbird.learner.util.Util;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;

/**
* @author arvind.
* Remote actor Application start point .
*/
public class Application {
private static LogHelper logger = LogHelper.getInstance(Application.class.getName());
private static ActorSystem system;
private static final String ACTOR_CONFIG_NAME = "RemoteMWConfig";
private static final String ACTOR_SYSTEM_NAME = "RemoteMiddlewareSystem";
public static void main(String[] args) {
startRemoteCreationSystem();
}
/**
* 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 checkCassandraConnection() {
Util.checkCassandraDbConnections();
SchedulerManager.schedule();
}
}
Loading

0 comments on commit e085012

Please sign in to comment.