Skip to content

Commit

Permalink
Issue SB-1 feat : code merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
arvindyadav108 committed Oct 30, 2017
2 parents 67ec644 + 42507b8 commit 5756293
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 35 deletions.
2 changes: 1 addition & 1 deletion actors/libs
Submodule libs updated from 37b52b to b90749
3 changes: 2 additions & 1 deletion actors/src/main/java/org/sunbird/learner/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ private static void startRemoteActorSystem() {


public static void checkCassandraConnection() {
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
Util.checkCassandraDbConnections(JsonKey.SUNBIRD_PLUGIN);
SchedulerManager.schedule();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ private String getType(String objectType) {
private Map<String, Object> getOrgDetails(Entry<String, Object> entry) {
ProjectLogger.log("fetching org data started");
Map<String, Object> orgMap = (Map<String, Object>) entry.getValue();
orgMap.remove(JsonKey.ORG_TYPE);
if (orgMap.containsKey(JsonKey.ADDRESS_ID)
&& !ProjectUtil.isStringNullOREmpty((String) orgMap.get(JsonKey.ADDRESS_ID))) {
orgMap.put(JsonKey.ADDRESS, getDetailsById(Util.dbInfoMap.get(JsonKey.ADDRESS_DB),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.sunbird.common.models.response.Response;
import org.sunbird.common.models.util.JsonKey;
import org.sunbird.common.models.util.ProjectLogger;
import org.sunbird.common.models.util.ProjectUtil;
import org.sunbird.helper.ServiceFactory;

/**
Expand All @@ -27,6 +28,7 @@ public class DataCacheHandler implements Runnable {
private static Map<String, Object> roleMap = new ConcurrentHashMap<>();
private static Map<String, String> orgTypeMap = new ConcurrentHashMap<>();
CassandraOperation cassandraOperation = ServiceFactory.getInstance();
private static final String KEY_SPACE_NAME = "sunbird";

@Override
public void run() {
Expand All @@ -39,7 +41,7 @@ public void run() {

private void orgTypeCache(Map<String, String> orgTypeMap) {
Response response =
cassandraOperation.getAllRecords(Util.getProperty("db.keyspace"), JsonKey.ORG_TYPE_DB);
cassandraOperation.getAllRecords(KEY_SPACE_NAME, JsonKey.ORG_TYPE_DB);
List<Map<String, Object>> responseList =
(List<Map<String, Object>>) response.get(JsonKey.RESPONSE);
if (null != responseList && !responseList.isEmpty()) {
Expand All @@ -51,7 +53,7 @@ private void orgTypeCache(Map<String, String> orgTypeMap) {

private void roleCache(Map<String, Object> roleMap) {
Response response =
cassandraOperation.getAllRecords(Util.getProperty("db.keyspace"), JsonKey.ROLE_GROUP);
cassandraOperation.getAllRecords(KEY_SPACE_NAME, JsonKey.ROLE_GROUP);
List<Map<String, Object>> responseList =
(List<Map<String, Object>>) response.get(JsonKey.RESPONSE);
if (null != responseList && !responseList.isEmpty()) {
Expand All @@ -60,7 +62,7 @@ private void roleCache(Map<String, Object> roleMap) {
}
}
Response response2 =
cassandraOperation.getAllRecords(Util.getProperty("db.keyspace"), JsonKey.ROLE);
cassandraOperation.getAllRecords(KEY_SPACE_NAME, JsonKey.ROLE);
List<Map<String, Object>> responseList2 =
(List<Map<String, Object>>) response2.get(JsonKey.RESPONSE);
if (null != responseList2 && !responseList2.isEmpty()) {
Expand All @@ -74,7 +76,7 @@ private void roleCache(Map<String, Object> roleMap) {
private void cache(Map<String, Map<String, Object>> map, String tableName) {
try {
Response response =
cassandraOperation.getAllRecords(Util.getProperty("db.keyspace"), tableName);
cassandraOperation.getAllRecords(KEY_SPACE_NAME, tableName);
List<Map<String, Object>> responseList =
(List<Map<String, Object>>) response.get(JsonKey.RESPONSE);
if (null != responseList && !responseList.isEmpty()) {
Expand All @@ -88,6 +90,8 @@ private void cache(Map<String, Map<String, Object>> map, String tableName) {
}
}
}
ProjectLogger.log("pagemap size" +map.size());
ProjectLogger.log("pagemap keyset "+map.keySet());
} catch (Exception e) {
ProjectLogger.log(e.getMessage(), e);
}
Expand Down
23 changes: 12 additions & 11 deletions actors/src/main/java/org/sunbird/learner/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,30 +181,30 @@ public static boolean checkOrgStatusTransition(Integer currentState , Integer ne
* provided environment variable , if environment variable values
* are not set then connection will be established from property file.
*/
public static void checkCassandraDbConnections() {
public static void checkCassandraDbConnections(String keySpace) {

PropertiesCache propertiesCache = PropertiesCache.getInstance();

String cassandraMode = propertiesCache.getProperty(JsonKey.SUNBIRD_CASSANDRA_MODE);
if (ProjectUtil.isStringNullOREmpty(cassandraMode) || cassandraMode
.equalsIgnoreCase(JsonKey.EMBEDDED_MODE)) {

// configure the Embeddee mode and return true here ....
// configure the Embedded mode and return true here ....
CassandraConnectionManager cassandraConnectionManager = CassandraConnectionMngrFactory
.getObject(cassandraMode);
boolean result = cassandraConnectionManager.createConnection(null , null , null ,null, KEY_SPACE_NAME);
boolean result = cassandraConnectionManager.createConnection(null , null , null ,null, keySpace);
if (result) {
ProjectLogger
.log("CONNECTION CREATED SUCCESSFULLY FOR IP:" + " : KEYSPACE :"
+ KEY_SPACE_NAME,
+ keySpace,
LoggerEnum.INFO.name());
} else {
ProjectLogger
.log("CONNECTION CREATION FAILED FOR IP: " + " : KEYSPACE :" + KEY_SPACE_NAME);
.log("CONNECTION CREATION FAILED FOR IP: " + " : KEYSPACE :" + keySpace);
}

} else if (cassandraMode.equalsIgnoreCase(JsonKey.STANDALONE_MODE)) {
if (readConfigFromEnv()) {
if (readConfigFromEnv(keySpace)) {
ProjectLogger.log("db connection is created from System env variable.");
return;
}
Expand Down Expand Up @@ -249,7 +249,7 @@ public static void checkCassandraDbConnections() {
* This method will read the configuration from System variable.
* @return boolean
*/
public static boolean readConfigFromEnv() {
public static boolean readConfigFromEnv(String keyspace) {
boolean response = false;
String ips = System.getenv(JsonKey.SUNBIRD_CASSANDRA_IP);
String envPort = System.getenv(JsonKey.SUNBIRD_CASSANDRA_PORT);
Expand All @@ -267,11 +267,11 @@ public static boolean readConfigFromEnv() {
String ip = ipList[i];
String port = portList[i];
try {
boolean result = cassandraConnectionManager.createConnection(ip, port, userName, password, KEY_SPACE_NAME);
boolean result = cassandraConnectionManager.createConnection(ip, port, userName, password, keyspace);
if (result) {
ProjectLogger.log("CONNECTION CREATED SUCCESSFULLY FOR IP: " + ip + " : KEYSPACE :" + KEY_SPACE_NAME, LoggerEnum.INFO.name());
ProjectLogger.log("CONNECTION CREATED SUCCESSFULLY FOR IP: " + ip + " : KEYSPACE :" + keyspace, LoggerEnum.INFO.name());
} else {
ProjectLogger.log("CONNECTION CREATION FAILED FOR IP: " + ip + " : KEYSPACE :" + KEY_SPACE_NAME, LoggerEnum.INFO.name());
ProjectLogger.log("CONNECTION CREATION FAILED FOR IP: " + ip + " : KEYSPACE :" + keyspace, LoggerEnum.INFO.name());
}
response = true;
} catch (ProjectCommonException ex) {
Expand Down Expand Up @@ -598,7 +598,8 @@ public static String validateRoles(List<String> roleList){

public static void main(String[] args) {
System.out.println("MAIN STARTED");
checkCassandraDbConnections();
checkCassandraDbConnections(JsonKey.SUNBIRD);
checkCassandraDbConnections(JsonKey.SUNBIRD_PLUGIN);
System.out.println("MAIN END");
}

Expand Down
13 changes: 13 additions & 0 deletions actors/src/main/resources/cassandra.cql
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,16 @@ ALTER TABLE sunbird.user ADD tcupdatedat text;







//Announcement apis -27th Oct
CREATE KEYSPACE IF NOT EXISTS sunbirdplugin WITH replication = {'class':'SimpleStrategy','replication_factor':1};
//CREATE TYPE IF NOT EXISTS sunbirdplugin.attachment (id text,filename text,mimetype text);
CREATE TABLE sunbirdplugin.announcement (id text,userid text,sourceid text,details map<text, text>,links list<text>,attachments list<text>,target text,sentcount int,priority text,expiry text,status text,createddate text,updateddate text, PRIMARY KEY (id));
CREATE TABLE sunbirdplugin.attachment (id text,file text,filename text,mimetype text,createdby text,status text,createddate text, PRIMARY KEY (id));
CREATE TABLE sunbirdplugin.metrics (id text,userid text,announcementid text,activity text,channel text,createddate text, PRIMARY KEY (id));
CREATE TABLE sunbirdplugin.announcementtype (id text,rootorgid text,name text,status text,createddate text, PRIMARY KEY (id));
CREATE TABLE sunbirdplugin.announcementauth (id text,userid text,rootorgid text,permissions map<text, text>,status text,createddate text, PRIMARY KEY (id));

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AssessmentItemActorTest {
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
ref = TestActorRef.create(system, props, "testActor");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class CourseEnrollmentActorTest {
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
userCoursesdbInfo = Util.dbInfoMap.get(JsonKey.LEARNER_COURSE_DB);
//PowerMockito.mockStatic(EkStepRequestUtil.class);
insertBatch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CourseManagementActorTest {
//@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
ref = TestActorRef.create(system, props, "testActor");
courseManagementActor = ref.underlyingActor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CourseSearchActorTest {
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
}

//@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class LearnerStateActorTest {
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
ref = TestActorRef.create(system, props, "testActor");
insertCourse();
insertContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class LearnerStateUpdateActorTest {
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
insertCourse();
insertBatch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class NotesManagementActorTest {
public static void setUp() {
system = ActorSystem.create("system");
ref = TestActorRef.create(system, props, "testActor");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
insertUserDataToES();
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class OrganisationManagementActorTest {
public static void setUp() {
Application.startLocalActorSystem();
system = ActorSystem.create("system");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
userManagementDB = Util.dbInfoMap.get(JsonKey.USER_DB);
addressDB = Util.dbInfoMap.get(JsonKey.ADDRESS_DB);
orgTypeDbInfo = Util.dbInfoMap.get(JsonKey.ORG_TYPE_DB);
Expand Down Expand Up @@ -193,8 +193,8 @@ public void test13CreateOrgWithSourceAndExternalIdSuc(){
orgMap.put(JsonKey.ORGANISATION_NAME , "CBSE");
orgMap.put(JsonKey.DESCRIPTION, "Central Board of Secondary Education");
orgMap.put("orgCode", "CBSE");
orgMap.put(JsonKey.PROVIDER, "pr0001");
orgMap.put(JsonKey.EXTERNAL_ID, "ex0001");
orgMap.put(JsonKey.PROVIDER, "pr00001");
orgMap.put(JsonKey.EXTERNAL_ID, "ex00001");
// orgMap.put("channel", "test1");
innerMap.put(JsonKey.ORGANISATION , orgMap);

Expand Down Expand Up @@ -223,8 +223,8 @@ public void test14CreateOrgWithSameSourceAndExternalIdExc(){
orgMap.put(JsonKey.ORGANISATION_NAME , "CBSE");
orgMap.put(JsonKey.DESCRIPTION, "Central Board of Secondary Education");
orgMap.put("orgCode", "CBSE");
orgMap.put(JsonKey.PROVIDER, "pr0001");
orgMap.put(JsonKey.EXTERNAL_ID, "ex0001");
orgMap.put(JsonKey.PROVIDER, "pr00001");
orgMap.put(JsonKey.EXTERNAL_ID, "ex00001");
orgMap.put("channel", "test");
innerMap.put(JsonKey.ORGANISATION , orgMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class PageManagementActorTest {
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
pageMgmntDbInfo = Util.dbInfoMap.get(JsonKey.PAGE_MGMT_DB);
pageSectionDbInfo = Util.dbInfoMap.get(JsonKey.PAGE_SECTION_DB);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void setUp() {
Application.startLocalActorSystem();
encryption = PropertiesCache.getInstance().getProperty(JsonKey.SUNBIRD_ENCRYPTION);
system = ActorSystem.create("system");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
userManagementDB = Util.dbInfoMap.get(JsonKey.USER_DB);
addressDB = Util.dbInfoMap.get(JsonKey.ADDRESS_DB);
jobDB = Util.dbInfoMap.get(JsonKey.JOB_PROFILE_DB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class RecommendorActorTest {
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
}

@Test()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void setUp(){
system = ActorSystem.create("system");

skillsList.add("Java");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
insertUserDataInCassandraAndEs();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class AuditLogServiceImplTest {
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
Util.checkCassandraDbConnections();
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
}

@SuppressWarnings({"deprecation", "unchecked"})
Expand Down
2 changes: 1 addition & 1 deletion actors/src/test/resources/dbconfig.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ db.ip=127.0.0.1
db.port=9042
db.username=cassandra
db.password=password
db.keyspace=sunbird
db.keyspace=sunbird,sunbirdplugin

0 comments on commit 5756293

Please sign in to comment.