Skip to content

Commit 5e1d1f2

Browse files
rebase from master (#6)
* Implement Subscription Handler (#8) * [DURACI-6697]-Implement Subscription Handler * fix use of embeded mongo db * fix mongodbhandler for test * Implemented Review comments * Fixed PathVariable annotations for input parameters in RestApi. * Fixed PathVariable annotations for input parameters in RestApi. (#9) * Added a fix for Block Origin in webbrowsers while accessing EI RestApi. * Implement Historical ER Query Service (#6) *Implement historical Event Repository query Service * add posibility to query downstream and upstreamfrom ER and test for ER query method * modify unit test * Fix updateSubscription RestApi issue that prevented subscription to b… (#11) * Fix updateSubscription RestApi issue that prevented subscription to be updated. * Changed name on isDuplicateSubscriptions functions to doSubscriptionExist. Fixed impacted unit test due to this change. * Messagebus ack (#12) * Fixed issue with multiprocessing and added acknowledgement * Simplified updateSubscription RestApi, so SubscritionName is only spe… …cified in json file/object. (#14) * Fix updateSubscription RestApi issue that prevented subscription to be updated. * Changed name on isDuplicateSubscriptions functions to doSubscriptionExist. Fixed impacted unit test due to this change. * Simplified updateSubscription RestApi, so SubscritionName is only specified in json file/object. * Test for measure performance EI is added (TrafficGeneratedTest). (#15) * Test for measure performance EI is added (TrafficGeneratedTest). Number of packages of events (7 events in package) you can add in variable EVENT_PACKAGES. ALL, DEBUG, ERROR, FATAL, INFO, TRACE, WARN parametres are added to a jar file at the time of execution for start EI with logs. No parameters start EI without logs. /// Ex. with logs: java -jar /path/file.jar INFO Ex. without logs: java -jar /path/file.jar /// File ArtifactRules_new.json is modified - added posibility to send SourceChangeCreatedEvent and SourceChangeSubmittedEvent without error. * problem with rules.path fixed
1 parent 2c081d0 commit 5e1d1f2

20 files changed

+871
-78
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ before_install:
1313
- chmod +x pom.xml
1414

1515
script:
16-
- mvn -DsomeModule.test.excludes="**/FlowTest.java, **/FlowTest2.java" test
16+
- mvn -DsomeModule.test.excludes="**/FlowTest.java, **/FlowTest2.java, **/TrafficGeneratedTest.java" test
1717
- mvn -DsomeModule.test.includes="**/FlowTest.java" test
1818
- mvn -DsomeModule.test.includes="**/FlowTest2.java" test
19+
- mvn -DsomeModule.test.includes="**/TrafficGeneratedTest.java" test

src/main/java/com/ericsson/ei/App.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,30 @@
55
import org.springframework.scheduling.annotation.EnableAsync;
66
import org.springframework.scheduling.annotation.EnableScheduling;
77

8+
import java.util.ArrayList;
9+
import java.util.Collections;
10+
import java.util.List;
11+
812
@SpringBootApplication
913
@EnableAsync
1014
@EnableScheduling
1115
public class App {
1216

1317
public static void main(String[] args) {
18+
19+
List<String> logLevels = new ArrayList<>();
20+
Collections.addAll(logLevels, "ALL", "DEBUG", "ERROR", "FATAL", "INFO", "TRACE", "WARN");
21+
22+
if(logLevels.contains(args[0])) {
23+
System.setProperty("logging.level.root", args[0]);
24+
System.setProperty("logging.level.org.springframework.web", args[0]);
25+
System.setProperty("logging.level.com.ericsson.ei", args[0]);
26+
} else {
27+
System.setProperty("logging.level.root", "OFF");
28+
System.setProperty("logging.level.org.springframework.web", "OFF");
29+
System.setProperty("logging.level.com.ericsson.ei", "OFF");
30+
}
31+
1432
SpringApplication.run(App.class, args);
1533
}
1634

src/main/java/com/ericsson/ei/controller/SubscriptionController.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,23 @@ public ResponseEntity<?> createSubscription(
3737
com.ericsson.ei.controller.model.Subscription subscription);
3838

3939
/**
40-
* Returns the subscription rules for given subscription name.
40+
* Modify an existing Subscription.
4141
*
4242
*/
43-
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.GET)
44-
public ResponseEntity<com.ericsson.ei.controller.model.Subscription> getSubscriptionById(
45-
@PathVariable
46-
String subscriptionName);
43+
@RequestMapping(value = "", method = RequestMethod.PUT)
44+
public ResponseEntity<com.ericsson.ei.controller.model.SubscriptionResponse> updateSubscriptions(
45+
@javax.validation.Valid
46+
@org.springframework.web.bind.annotation.RequestBody
47+
com.ericsson.ei.controller.model.Subscription subscription);
4748

4849
/**
49-
* Modify an existing Subscription.
50+
* Returns the subscription rules for given subscription name.
5051
*
5152
*/
52-
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.PUT)
53-
public ResponseEntity<com.ericsson.ei.controller.model.SubscriptionResponse> updateSubscriptionById(
53+
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.GET)
54+
public ResponseEntity<com.ericsson.ei.controller.model.Subscription> getSubscriptionById(
5455
@PathVariable
55-
String subscriptionName,
56-
@javax.validation.Valid
57-
@org.springframework.web.bind.annotation.RequestBody
58-
com.ericsson.ei.controller.model.Subscription subscription);
56+
String subscriptionName);
5957

6058
/**
6159
* Removes the subscription from the database.

src/main/java/com/ericsson/ei/controller/SubscriptionControllerImpl.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class SubscriptionControllerImpl implements SubscriptionController {
4444
@ApiOperation(value = "Creates the subscription")
4545
public ResponseEntity<SubscriptionResponse> createSubscription(@RequestBody Subscription subscription) {
4646
SubscriptionResponse subscriptionResponse = new SubscriptionResponse();
47-
if (!subscriptionService.isDuplicatedSubscription(subscription.getSubscriptionName())) {
47+
if (!subscriptionService.doSubscriptionExist(subscription.getSubscriptionName())) {
4848
subscriptionService.addSubscription(subscription);
4949
LOG.info("Subscription :" + subscription.getSubscriptionName() + " Inserted Successfully");
5050
subscriptionResponse.setMsg("Inserted Successfully"); subscriptionResponse.setStatusCode(HttpStatus.OK.value());
@@ -75,20 +75,21 @@ public ResponseEntity<Subscription> getSubscriptionById(@PathVariable String sub
7575
}
7676

7777
@Override
78-
@CrossOrigin
78+
//@CrossOrigin
7979
@ApiOperation(value = "Update the existing subscription by the subscription name")
80-
public ResponseEntity<SubscriptionResponse> updateSubscriptionById(@PathVariable String subscriptionName, @RequestBody Subscription subscription) {
80+
public ResponseEntity<SubscriptionResponse> updateSubscriptions(@RequestBody Subscription subscription) {
81+
String subscriptionName = subscription.getSubscriptionName();
8182
LOG.info("Subscription :" + subscriptionName + " update started");
8283
SubscriptionResponse subscriptionResponse = new SubscriptionResponse();
83-
if (!subscriptionService.isDuplicatedSubscription(subscription.getSubscriptionName())) {
84+
if (subscriptionService.doSubscriptionExist(subscriptionName)) {
8485
subscriptionService.modifySubscription(subscription, subscriptionName);
8586
LOG.info("Subscription :" + subscriptionName + " update completed");
8687
subscriptionResponse.setMsg("Updated Successfully"); subscriptionResponse.setStatusCode(HttpStatus.OK.value());
8788
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.OK);
8889

8990
} else {
90-
LOG.error("Subscription :" + subscription.getSubscriptionName() + " identified as duplicate subscription");
91-
subscriptionResponse.setMsg("Duplicate Subscription"); subscriptionResponse.setStatusCode(HttpStatus.BAD_REQUEST.value());
91+
LOG.error("Subscription :" + subscription.getSubscriptionName() + " can't be found.");
92+
subscriptionResponse.setMsg("Subscription can't be found"); subscriptionResponse.setStatusCode(HttpStatus.BAD_REQUEST.value());
9293
return new ResponseEntity<SubscriptionResponse>(subscriptionResponse, HttpStatus.BAD_REQUEST);
9394
}
9495

src/main/java/com/ericsson/ei/handlers/EventHandler.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,37 @@ public void eventReceived(String event) {
3636
idRulesHandler.runIdRules(eventRules, event);
3737
}
3838

39+
@Bean
40+
public Executor asyncExecutor() {
41+
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
42+
executor.setCorePoolSize(corePoolSize);
43+
executor.setQueueCapacity(queueCapacity);
44+
executor.setMaxPoolSize(maxPoolSize);
45+
executor.setThreadNamePrefix("EventHandler-");
46+
executor.initialize();
47+
return executor;
48+
}
49+
3950
public void eventReceived(byte[] message) {
4051
log.info("Thread id " + Thread.currentThread().getId() + " spawned");
4152
String actualMessage = new String(message);
4253
log.info("Event received <" + actualMessage + ">");
4354
eventReceived(actualMessage);
44-
if (System.getProperty("flow.test") == "true") {
45-
String countStr = System.getProperty("eiffel.intelligence.processedEventsCount");
46-
int count = Integer.parseInt(countStr);
47-
count++;
48-
System.setProperty("eiffel.intelligence.processedEventsCount", "" + count);
49-
}
55+
// if (System.getProperty("flow.test") == "true") {
56+
// String countStr = System.getProperty("eiffel.intelligence.processedEventsCount");
57+
// int count = Integer.parseInt(countStr);
58+
// count++;
59+
// System.setProperty("eiffel.intelligence.processedEventsCount", "" + count);
60+
// }
61+
}
62+
63+
@Async
64+
public void onMessage(Message message, Channel channel) throws Exception {
65+
byte[] messageBody = message.getBody();
66+
eventReceived(messageBody);
67+
long deliveryTag = message.getMessageProperties().getDeliveryTag();
68+
channel.basicAck(deliveryTag, false);
69+
int breakHere = 1;
5070
}
5171

5272
@Async

src/main/java/com/ericsson/ei/rmqhandler/EIMessageListenerAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public void onMessage(Message message, Channel channel) throws Exception {
1818
if (delegate != this) {
1919
if (delegate instanceof EventHandler) {
2020
if (channel != null) {
21+
channel.basicQos(150);
2122
((EventHandler) delegate).onMessage(message, channel);
2223
return;
2324
}

src/main/java/com/ericsson/ei/rmqhandler/RmqHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public class RmqHandler {
5252
private String routingKey;
5353
@Value("${rabbitmq.consumerName}")
5454
private String consumerName;
55-
// SimpleMessageListenerContainer container;
5655
private RabbitTemplate rabbitTemplate;
5756
private CachingConnectionFactory factory;
5857
private SimpleMessageListenerContainer container;
@@ -230,6 +229,7 @@ public void confirm(CorrelationData correlationData, boolean ack, String cause)
230229

231230
public void publishObjectToWaitlistQueue(String message) {
232231
log.info("publishing message to message bus...");
232+
//rabbitMqTemplate().convertAndSend(message);
233233
waitListRabbitMqTemplate().convertAndSend(message);
234234
}
235235

src/main/java/com/ericsson/ei/rules/RulesHandler.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.ericsson.ei.rules;
22

3-
import java.io.File;
3+
import java.io.*;
44
import java.util.Iterator;
55

66
import org.apache.commons.io.FileUtils;
7-
87
import org.slf4j.Logger;
98
import org.slf4j.LoggerFactory;
109

@@ -30,7 +29,12 @@ public class RulesHandler {
3029
@PostConstruct public void init() {
3130
if (parsedJason == null) {
3231
try {
33-
jsonFileContent = FileUtils.readFileToString(new File(jsonFilePath));
32+
InputStream in = this.getClass().getResourceAsStream(jsonFilePath);
33+
if(in == null) {
34+
jsonFileContent = FileUtils.readFileToString(new File(jsonFilePath));
35+
} else {
36+
jsonFileContent = getContent(in);
37+
}
3438
ObjectMapper objectmapper = new ObjectMapper();
3539
parsedJason = objectmapper.readTree(jsonFileContent);
3640
} catch (Exception e) {
@@ -48,7 +52,6 @@ public RulesObject getRulesForEvent(String event) {
4852
JsonNode type;
4953
JsonNode result;
5054
Iterator<JsonNode> iter = parsedJason.iterator();
51-
5255
while(iter.hasNext()) {
5356
JsonNode rule = iter.next();
5457
typeRule = rule.get("TypeRule").toString();
@@ -66,4 +69,21 @@ public RulesObject getRulesForEvent(String event) {
6669
return null;
6770
}
6871

69-
}
72+
private String getContent(InputStream inputStream){
73+
try {
74+
75+
76+
ByteArrayOutputStream result = new ByteArrayOutputStream();
77+
byte[] buffer = new byte[1024];
78+
int length;
79+
while ((length = inputStream.read(buffer)) != -1) {
80+
result.write(buffer, 0, length);
81+
}
82+
return result.toString("UTF-8");}
83+
catch (Exception e) {
84+
log.error(e.getMessage(), e);
85+
}
86+
return null;
87+
}
88+
89+
}

src/main/java/com/ericsson/ei/services/ISubscriptionService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public interface ISubscriptionService {
4747
boolean deleteSubscription(String name);
4848

4949
/**
50-
* isDuplicatedSubscription method checks the is there any Subscription By Subscription Name
50+
* doSubscriptionExist method checks the is there any Subscription By Subscription Name
5151
* @param name
5252
* @return true when Subscription available with same name. Otherwise returns false.
5353
*/
54-
boolean isDuplicatedSubscription(String name);
54+
boolean doSubscriptionExist(String name);
5555

5656

5757
}

src/main/java/com/ericsson/ei/services/SubscriptionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Subscription getSubscription(String name) throws SubscriptionNotFoundExce
5656
}
5757

5858
@Override
59-
public boolean isDuplicatedSubscription(String name) {
59+
public boolean doSubscriptionExist(String name) {
6060
String query = String.format(SUBSCRIPTION_NAME, name);
6161
ArrayList<String> list = subscriptionRepository.getSubscription(query);
6262
if (list.isEmpty()) {

0 commit comments

Comments
 (0)