Skip to content

Commit

Permalink
Implemented RoutingKey functionality for REMREM Semantics (#65)
Browse files Browse the repository at this point in the history
* Implemented RoutingKey functionality for REMREM Semantics

* Added json files and modified testcases

* Handled null condition of RoutingKey
  • Loading branch information
Umadevi-Kapu authored Mar 1, 2017
1 parent 7f8e1b9 commit 81ec0c4
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.3.3
- Implemented RoutingKey functionality for REMREM Semantics.

## 0.3.2
- Added comments and removed unnecessary dependencies in build.gradle.

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ subprojects {
apply plugin: 'java'

//Latest version for publish
version = "0.3.2"
version = "0.3.3"

//Declare where to find the dependencies of project here
repositories {
Expand Down Expand Up @@ -100,7 +100,7 @@ subprojects {
compile 'com.github.Ericsson:eiffel-remrem-shared:0.3.0'
compile 'com.github.Ericsson:eiffel-remrem-protocol-interface:0.0.1'
//For publishing eiffel2.0 events
compile 'com.github.Ericsson:eiffel-remrem-semantics:0.2.0'
compile 'com.github.Ericsson:eiffel-remrem-semantics:0.2.3'

//Declare the dependency for your favourite test framework you want to use in your tests.
//TestNG is also supported by the Gradle Test task. Just change the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public class PropertiesConfig {
public static final String SERVER_DOWN = "Internal Server Error";
public static final String SERVER_DOWN_MESSAGE = "Possible to try again later when server is up";
public static final String UNSUCCESSFUL_EVENT_CONTENT = "Please check previous event and try again later";
public static final String PROTOCOL = "eiffel";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.slf4j.LoggerFactory;

import com.ericsson.eiffel.remrem.protocol.MsgService;
import com.ericsson.eiffel.remrem.publish.config.PropertiesConfig;
import com.ericsson.eiffel.remrem.semantics.SemanticsService;
import com.google.gson.JsonObject;

import ch.qos.logback.classic.Logger;
Expand Down Expand Up @@ -42,19 +44,23 @@ public static MsgService getMessageService(String mp, MsgService msgServices[])
* @param msgService the Messaging service.
* @param json the eiffel event
* @param userDomainSuffix is optional parameter, If user provide this it will add to the domainId.
* @return routing key or returns domain id if family and type not available.
* @return routing key or returns null if family and type not available.
*/
public static String prepareRoutingKey(MsgService msgService, JsonObject json, RMQHelper rmqHelper,
String userDomainSuffix) {
String domainId = rmqHelper.getDomainId();
String family = msgService.getFamily(json);
String type = msgService.getType(json);
if (StringUtils.isNotEmpty(userDomainSuffix)) {
domainId = domainId + DOT + userDomainSuffix;
}
if (msgService != null && StringUtils.isNotEmpty(msgService.getFamily(json))
&& StringUtils.isNotEmpty(msgService.getType(json))) {
return msgService.getFamily(json) + DOT + msgService.getType(json) + DOT + "notag" + DOT + domainId;
if (msgService != null && StringUtils.isNotEmpty(family) && StringUtils.isNotEmpty(type)) {
if (msgService instanceof SemanticsService)
return PropertiesConfig.PROTOCOL + DOT + family + DOT + type + DOT + "notag" + DOT + domainId;
else
return family + DOT + type + DOT + "notag" + DOT + domainId;
}
return domainId;
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
Expand Down Expand Up @@ -79,10 +78,11 @@ public SendResult send(String jsonContent, MsgService msgService, String userDom
Map<String, String> map = new HashMap<>();
Map<String, String> routingKeyMap = new HashMap<>();
String eventId = msgService.getEventId(json.getAsJsonObject());
if (eventId != null) {
String routingKey = (eventId != null) ? (PublishUtils.prepareRoutingKey(msgService,
json.getAsJsonObject(), rmqHelper, userDomainSuffix)) : null;
if (eventId != null && routingKey != null) {
map.put(eventId, json.toString());
routingKeyMap.put(eventId, PublishUtils.prepareRoutingKey(msgService, json.getAsJsonObject(),
rmqHelper, userDomainSuffix));
routingKeyMap.put(eventId, routingKey);
} else {
List<PublishResultItem> events = new ArrayList<>();
createFailureResult(events);
Expand Down Expand Up @@ -195,8 +195,11 @@ private void instantiateRmqHelper() {
private void getAndCheckEvent(MsgService msgService, Map<String, String> map, List<PublishResultItem> events,
JsonElement obj, Map<String, String> routingKeyMap, String userDomainSuffix) {
String eventId = msgService.getEventId(obj.getAsJsonObject());
if (eventId != null) {
routingKeyMap.put(eventId, PublishUtils.prepareRoutingKey(msgService, obj.getAsJsonObject(), rmqHelper, userDomainSuffix)) ;
String routingKey = (eventId != null)
? (PublishUtils.prepareRoutingKey(msgService, obj.getAsJsonObject(), rmqHelper, userDomainSuffix))
: null;
if (eventId != null && routingKey != null) {
routingKeyMap.put(eventId, routingKey);
map.put(eventId, obj.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import static com.jayway.restassured.RestAssured.given;
import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.FileReader;
import java.util.Base64;

import org.apache.commons.io.FileUtils;
import org.apache.http.HttpStatus;
import org.hamcrest.Matchers;
import org.junit.Before;
Expand Down Expand Up @@ -49,9 +52,9 @@ public void setUp() {
public void testGetFamily() throws Exception {
MsgService messageService = PublishUtils.getMessageService("eiffel3", msgServices);
if (messageService != null) {
String jsonString = "{'eiffelMessageVersions': { '3.21.37.0.4': { 'domainId': 'testdomain', 'eventId': '4ce1e9e1-21c4-458f-b8d1-ef26b82a5634', 'eventTime': \"2011-11-02T02:50:12.208Z\", 'eventType': 'EiffelJobFinishedEvent', 'inputEventIds': [], 'eventData': { 'jobInstance': 'MySuperGreatJob', 'jobExecutionId': '81e06fbc-1247-4446-9426-3381f9a1bda2', 'jobExecutionNumber': 731, 'resultCode': 'SUCCESS', 'resultDetails': { 'key': 0, 'description': 'The Result was Successful' }, 'logReferences': {}, 'flowContext': '', 'optionalParameters': {} } }, '2.3.37.0.4': { 'domainId': 'testdomain', 'eventId': '4ce1e9e1-21c4-458f-b8d1-ef26b82a5634', 'eventTime': '2016-09-01T08:23:57.894Z', 'eventType': 'EiffelJobFinishedEvent', 'inputEventIds': [], 'eventData': { 'jobInstance': 'MySuperGreatJob', 'jobExecutionId': '81e06fbc-1247-4446-9426-3381f9a1bda2', 'jobExecutionNumber': 731, 'resultCode': 'SUCCESS', 'logReferences': {}, 'optionalParameters': {} } } } }";
File file = new File("src/integration-test/resources/EiffelJobFinishedEvent.json");
JsonParser parser = new JsonParser();
JsonElement json = parser.parse(jsonString);
JsonElement json = parser.parse(new FileReader(file)).getAsJsonObject();
String family = messageService.getFamily(json.getAsJsonObject());
assertEquals("job", family);
}
Expand All @@ -62,19 +65,19 @@ public void testJsonOutput() throws Exception {
MsgService msgService = PublishUtils.getMessageService("eiffel3", msgServices);
if (msgService != null) {
JsonArray jarray = new JsonArray();
String jsonString = "{'eiffelMessageVersions': { '3.21.37.0.4': { 'domainId': 'testdomain', 'eventId': '4ce1e9e1-21c4-458f-b8d1-ef26b82a5634', 'eventTime': '2016-09-01T08:23:57.894Z', 'eventType': 'EiffelJobFinishedEvent', 'inputEventIds': [], 'eventData': { 'jobInstance': 'MySuperGreatJob', 'jobExecutionId': '81e06fbc-1247-4446-9426-3381f9a1bda2', 'jobExecutionNumber': 731, 'resultCode': 'SUCCESS', 'resultDetails': { 'key': 0, 'description': 'The Result was Successful' }, 'logReferences': {}, 'flowContext': '', 'optionalParameters': {} } }, '2.3.37.0.4': { 'domainId': 'testdomain', 'eventId': '4ce1e9e1-21c4-458f-b8d1-ef26b82a5634', 'eventTime': '2016-09-01T08:23:57.894Z', 'eventType': 'EiffelJobFinishedEvent', 'inputEventIds': [], 'eventData': { 'jobInstance': 'MySuperGreatJob', 'jobExecutionId': '81e06fbc-1247-4446-9426-3381f9a1bda2', 'jobExecutionNumber': 731, 'resultCode': 'SUCCESS', 'logReferences': {}, 'optionalParameters': {} } } } }";
String jsonString = FileUtils.readFileToString(new File("src/integration-test/resources/EiffelJobFinishedEvent.json"));
SendResult results = messageService.send(jsonString, msgService, "fem001");
for (PublishResultItem result : results.getEvents()) {
jarray.add(result.toJsonObject());
}
String jsonArray = "[{\"id\":\"4ce1e9e1-21c4-458f-b8d1-ef26b82a5634\",\"status_code\":200,\"result\":\"SUCCESS\",\"message\":\"Event sent successfully\"}]";
String jsonArray = "[{\"id\":\"2930b40e-79dc-453c-b178-bc2bbde593ba\",\"status_code\":200,\"result\":\"SUCCESS\",\"message\":\"Event sent successfully\"}]";
assertEquals(jsonArray, jarray.toString());
}
}

@Test
public void testFailSingleEvent() throws Exception {
String body = "{'data':{'outcome':{'conclusion':'TIMED_OUT','description':'Compilation timed out.'},'persistentLogs':[{'name':'firstLog','uri':'http://myHost.com/firstLog'},{'name':'otherLog','uri':'isbn:0-486-27557-4'}]},'links':{'activityExecution':'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1','flowContext':'flowContext','causes':['cause1','cause2']},'meta':{'domainId':'example.domain','type':'eiffelactivityfinished','version':'0.1.7','time':1478780245184,'tags':['tag1','tag2'],'source':{'host':'host','name':'name','uri':'http://java.sun.com/j2se/1.3/','serializer':{'groupId':'G','artifactId':'A','version':'V'}}}}";
String body = FileUtils.readFileToString(new File("src/integration-test/resources/Invalid_EiffelActivityFinishedEvent.json"));

given().header("Authorization", credentials)
.contentType("application/json").body(body).when().post("/producer/msg").then()
Expand All @@ -83,5 +86,28 @@ public void testFailSingleEvent() throws Exception {
.body("events[0].result", Matchers.equalTo(PropertiesConfig.INVALID_MESSAGE)).body("events[0].message", Matchers
.equalTo("Invalid event content, client need to fix problem in event before submitting again"));
}


@Test
public void testGetFamilyRoutingKey() throws Exception {
MsgService messageService = PublishUtils.getMessageService("", msgServices);
if (messageService != null) {
File file = new File("src/integration-test/resources/EiffelActivityFinishedEvent.json");
JsonParser parser = new JsonParser();
JsonElement json = parser.parse(new FileReader(file)).getAsJsonObject();
String family = messageService.getFamily(json.getAsJsonObject());
assertEquals("activity", family);
}
}

@Test
public void testGetTypeRoutingKey() throws Exception {
MsgService messageService = PublishUtils.getMessageService("", msgServices);
if (messageService != null) {
File file = new File("src/integration-test/resources/EiffelActivityFinishedEvent.json");
JsonParser parser = new JsonParser();
JsonElement json = parser.parse(new FileReader(file)).getAsJsonObject();
String type = messageService.getType(json.getAsJsonObject());
assertEquals("finished", type);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"data": {
"outcome": {
"conclusion": "TIMED_OUT",
"description": "Compilation timed out."
},
"persistentLogs": [{
"name": "firstLog",
"uri": "http://myHost.com/firstLog"
}, {
"name": "otherLog",
"uri": "isbn:0-486-27557-4"
}]
},
"links": {
"activityExecution": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1",
"flowContext": "flowContext",
"causes": ["cause1", "cause2"]
},
"meta": {
"domainId": "TCS",
"id": "1afffd13-04ae-4638-97f1-aaeed78a28c7",
"type": "eiffelactivityfinished",
"version": "0.1.8",
"time": 1481628758807,
"tags": ["tag1", "tag2"],
"source": {
"host": "host",
"name": "name",
"uri": "http://java.sun.com/j2se/1.3/",
"serializer": {
"groupId": "G",
"artifactId": "A",
"version": "V"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"eiffelMessageVersions": {
"3.21.42.0.4": {
"domainId": "eiffel010.generator",
"eventId": "2930b40e-79dc-453c-b178-bc2bbde593ba",
"eventTime": "2016-12-09T05:05:27.797Z",
"eventType": "EiffelJobFinishedEvent",
"inputEventIds": [
"5034777a-6f25-409e-abd2-39e592158c7f"
],
"eventData": {
"jobInstance": "MessageGenerator",
"jobExecutionId": "114ad8ae-3f18-48bf-a672-2b068236845e",
"jobExecutionNumber": 24999,
"resultCode": "SUCCESS",
"logReferences": {

},
"flowContext": "",
"optionalParameters": {
"COUNT": "99995"
}
}
},
"2.3.42.0.4": {
"domainId": "eiffel010.generator",
"eventId": "2930b40e-79dc-453c-b178-bc2bbde593ba",
"eventTime": "2016-12-09T05:05:27.797Z",
"eventType": "EiffelJobFinishedEvent",
"inputEventIds": [
"5034777a-6f25-409e-abd2-39e592158c7f"
],
"eventData": {
"jobInstance": "MessageGenerator",
"jobExecutionId": "114ad8ae-3f18-48bf-a672-2b068236845e",
"jobExecutionNumber": 24999,
"resultCode": "SUCCESS",
"logReferences": {

},
"optionalParameters": {
"COUNT": "99995"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"data": {
"outcome": {
"conclusion": "TIMED_OUT",
"description": "Compilation timed out."
},
"persistentLogs": [{
"name": "firstLog",
"uri": "http://myHost.com/firstLog"
}, {
"name": "otherLog",
"uri": "isbn:0-486-27557-4"
}]
},
"links": {
"activityExecution": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeee1",
"flowContext": "flowContext",
"causes": ["cause1", "cause2"]
},
"meta": {
"domainId": "example.domain",
"type": "eiffelactivityfinished",
"version": "0.1.7",
"time": 1478780245184,
"tags": ["tag1", "tag2"],
"source": {
"host": "host",
"name": "name",
"uri": "http://java.sun.com/j2se/1.3/",
"serializer": {
"groupId": "G",
"artifactId": "A",
"version": "V"
}
}
}
}
Loading

0 comments on commit 81ec0c4

Please sign in to comment.