Skip to content

Commit 5ebb883

Browse files
Release 2.2.4
1 parent 68f1710 commit 5ebb883

File tree

92 files changed

+3111
-9781
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+3111
-9781
lines changed

COPYRIGHT.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

LAUNCHTEST_README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Table of Contents
2+
3+
- Introduction
4+
- Launching Test
5+
- Launching Smoke Tests for Production and external github branches
6+
7+
## Introduction
8+
All the existing tests have been categorized into Sanity Tests via annotation @Category(SanityTest.class).
9+
Further there are more categories for new tests or existing test that could be categorized further into correct bucket. Available categories are as follows
10+
- SmokeTest - @Category(SmokeTest.class)
11+
- IntegrationTest - @Category(IntegrationTest.class)
12+
- RegressionTest - @Category(RegressionTest.class)
13+
- DefectTest - @Category(DefectTest.class)
14+
15+
Once could either categorize a single test via these annoations by adding the annoation on the test or can categorize all the tests within a class by annotating at class level. e.g. AllSmokeTests.java . A single test can also be part of different category's by defining the categoery it belongs to e.g. @Category({SmokeTest.class,SanityTest.class})
16+
17+
18+
## Launching Tests
19+
To run tests you need to associate a profile. e.g. "mvn test -P $PROFILENAME". This profilename is lets you pick which category of tests you want to launch. The profiles are below
20+
- -P Smoke tied to SmokeTest
21+
- -P Sanity tied to SanityTest
22+
- -P Integration tied to IntegrationTest
23+
- -P Regression tied to RegressionTest
24+
- -P Defect tied to DefectTest
25+
26+
However there is a default profile that is tied to that, which is SmokeTest. This will be picked up when you launch "mvn clean install".
27+
If you want to run a different category of Tests you can launch via mvn $TARGET -P Sanity ($TARGET could be clean,compile,test,install)
28+
29+
You can also launch multiple profile tests together. e.g. mvn test -P Smoke,Sanity
30+
31+
To Run all Tests "mvn test -P Sanity"
32+
33+
## Launching Smoke Tests for Production and external github branches
34+
To simply launching tests on these environments and be able to leverage same tests across different environment targets without making use of exporting environment variables we have provision this via use of properties file. The properties file takes only few variables that should be enough to launch the tests against different environments.
35+
There are two properites file aiding to help you launch the tests against different environments from a single point without having to edit the same property file while flipping between target enviornments.
36+
37+
1.) event-hub.properties tied to env variable environemnt=production .
38+
39+
2.) event-hub-test.properties file tied to env variable environment=test .
40+
41+
If the env variable is not set; it will default to environement=test and read the corresponding file to gather the key value pairs.
42+
43+
Contents of the properties file, but not limited to the following. You are free to add more property values and add a test that consumes that.
44+
- EVENTHUB_URI= - Mandatory, however Either this needs to be present or EVENT_HOST needs to be present
45+
- EVENTHUB_HOST= - Same as above
46+
- AUTH_URL= - Mandatory
47+
- CLIENT_ID= - Mandatory
48+
- CLIENT_SECRET= - Mandatory
49+
- ZONE_ID= - Mandatory
50+
- EVENTHUB_PORT= - Mandatory
51+
- NUMBER_OF_MESSAGES= - If not specified, defaults to 1.
52+
53+
### e.g of Launching Smoke Tests to make use of event-hub.properties
54+
55+
1.) Step 1 : export environment=production
56+
57+
2.) Step 2 : mvn test -P Smoke
58+
59+
You should see the following log messages
60+
61+
2018-12-13 17:48:29 INFO AllSmokeTest:71 - Environment used for testing : PRODUCTION
62+
63+
2018-12-13 17:48:29 INFO PropertiesConfiguration:84 - Looking for file event-hub.properties at path
64+
65+
66+
### e.g. Launching Smoke Tess to make use of event-hub-test.properties
67+
68+
1.) Step 1 (Optional): export environment=test
69+
70+
2.) Step 2 : mvn test -P Smoke
71+
72+
You should see the following log messages
73+
74+
2018-12-14 10:19:58 INFO AllSmokeTest:71 - Environment used for testing : TEST
75+
76+
2018-12-14 10:19:58 INFO PropertiesConfiguration:84 - Looking for file event-hub-test.properties at path .
77+

LICENSE.md

Lines changed: 36 additions & 31 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
<a href="http://predixdev.github.io/predix-event-hub-sdk/javadocs/index.html" target="_blank" >
2-
<img height="50px" width="100px" src="images/javadoc.png" alt="view javadoc"></a>
3-
&nbsp;
4-
<a href="http://predixdev.github.io/predix-event-hub-sdk" target="_blank">
5-
<img height="50px" width="100px" src="images/pages.jpg" alt="view github pages">
6-
</a>
7-
81
# Event Hub SDK for Java
92
Event Hub SDK is a library that helps connect an application to [Event Hub](https://www.predix.io/services/service.html?id=1987)
103

@@ -20,6 +13,7 @@ Event Hub SDK is a library that helps connect an application to [Event Hub](http
2013
- [Debugging](#debugging)
2114
- [Building SDK from repository](#building-sdk-from-repository)
2215
- [Common Issues](#building-sdk-from-repository)
16+
- [Running Tests](#running-tests)
2317

2418
## SDK from Artifactory
2519
The most simple way to use this SDK is to pull from the Predix Snapshot artifactory repository. Add the following to your pom file:
@@ -30,7 +24,7 @@ The most simple way to use this SDK is to pull from the Predix Snapshot artifact
3024
<dependency>
3125
<groupId>com.ge.predix.eventhub</groupId>
3226
<artifactId>predix-event-hub-sdk</artifactId>
33-
<version>2.0.7</version>
27+
<version>2.2.4</version>
3428
</dependency>
3529
...
3630
</dependencies>
@@ -502,13 +496,31 @@ You can resubscribe to rebuild the stream.
502496

503497
#### Multiple Subscribers
504498

505-
Only one subscription per `subscriberName` can be made.
506-
507499
Event Hub will send each unique `subscriberName` or subscription all stored messages. If there are multiple clients
508500
per `subscriberName` (max of five) those clients will collectively receive all the messages. That is, the stored
509501
messages will be divided and load balanced among the clients for that `subscriberName`. Note that this can be used to
510502
increase the speed at which messages are retrieved from EventHub for a subscription.
511503

504+
#### Multiple Topics
505+
506+
Event Hub allows users to subscribe to multiple topics. This allows a single subscription to consume all messages published
507+
across default and custom topics associated with their respective zone ID.
508+
509+
```java
510+
//Provide the names of the topic.
511+
String topicSuffix1 = "NewTopic1";
512+
String topicSuffix2 = "NewTopic2";
513+
514+
List<String> topicSuffixes = new ArrayList<String>();
515+
topicSuffixes.add(topicSuffix1);
516+
topicSuffixes.add(topicSuffix2);
517+
518+
EventHubConfiguration configuration_all_topics_subscribe = new EventHubConfiguration.Builder()
519+
.fromEnvironmentVariables()
520+
.subscribeConfiguration(new SubscribeConfiguration.Builder()
521+
.topics(topicSuffixes) //Note the topics(List) vs topic(String)
522+
```
523+
512524
## Logging
513525
The Event hub sdk offers the ability to configure logging though a
514526
configuration object. The skd can either use the default Simple Logging Facade
@@ -614,7 +626,7 @@ where `string` is all the scopes comma separated. The following are the scopes t
614626
| predix-event-hub.zones.`<zoneID>`.grpc.publish | Required to publish to default topic
615627
| predix-event-hub.zones.`<zoneID>`.grpc.subscribe | Required to subscribe to default topic
616628
| predix-event-hub.zones.`<zoneID>`.`<subTopic>`.grpc.subscribe | Required to subscribe to a subtopic topic
617-
| predix-event-hub.zones.`<zoneID>`.`<subTopic>`.grpc.publish | Required to publish to a subtiouc topic
629+
| predix-event-hub.zones.`<zoneID>`.`<subTopic>`.grpc.publish | Required to publish to a subtopic topic
618630

619631
Note: if you are a user of the Power VPC then you need to replace the scope prefix, predix-event-hub, with event-hub-power
620632

@@ -672,10 +684,11 @@ The following dependency needs to be added *first* of the dependencies
672684
in the pom.xml of the project using the Java SDK.
673685

674686
```xml
687+
675688
<dependency>
676689
<groupId>io.netty</groupId>
677690
<artifactId>netty-tcnative-boringssl-static</artifactId>
678-
<version>2.0.5.Final</version>
691+
<version>2.0.7.Final</version>
679692
</dependency>
680693

681694
<repositories>
@@ -686,7 +699,7 @@ in the pom.xml of the project using the Java SDK.
686699
</repositories>
687700
```
688701
### Best Practices
689-
See [this](https://github.com/PredixDev/predix-event-hub-java-sdk/tree/develop/examples) for sample apps, examples, and step-by-step guides on best practices.
702+
See [this](https://github.com/PredixDev/event-hub-java-sample-app) for sample apps, examples, and step-by-step guides on best practices.
690703
### FAQ
691704
1. What is latest stable version of EventHub SDK?
692705
- v1.2.11 can be used in production now. v2.X.X is also available, but is being reviewed for public release (you can still use it if you're not planning to be in production)
@@ -780,5 +793,9 @@ See [this](https://github.com/PredixDev/predix-event-hub-java-sdk/tree/develop/e
780793
| | 11. Error or unable finding instance
781794
| EventHubClientException.PublishFailureException | 1. Publish failed
782795

796+
## Running Tests
797+
Please refer [Here](./LAUNCHTEST_README.md)
798+
799+
[![Analytics](https://predix-beacon.appspot.com/UA-82773213-1/event-hub-java-sdk/readme?pixel)](https://github.com/PredixDev)
800+
783801

784-
[![Analytics](https://ga-beacon.appspot.com/UA-82773213-1/predix-event-hub-sdk/readme?pixel)](https://github.com/PredixDev)

_config.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
applications:
33
- name: event-hub-java-sample-spark-app
4-
memory: 512M
4+
memory: 1GB
55
instances: 1
66
timeout: 180
77
path: target/event-hub-java-spark-sample-app-1.0-SNAPSHOT.jar
88
buildpack: java-buildpack
99
env:
10-
UAA_INSTANCE_NAME: <uaa>
11-
EVENTHUB_INSTANCE_NAME: <event_hub>
12-
CLIENT_ID: <client_id>
13-
CLIENT_SECRET: <client_password>
10+
UAA_INSTANCE_NAME: <UAA Instance Name>
11+
EVENTHUB_INSTANCE_NAME: <Event Hub Instance Name>
12+
CLIENT_ID: <Client ID>
13+
CLIENT_SECRET: <Client Secret>
1414
EVENTHUB_ENABLE_DEBUG: true
15-
15+
JAVA_OPTS: -Dspark.driver.memory=471859200
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# event-hub-java-spark-sample-app
22

33
## Background:
4-
Built on top of EventHub Java Sample App (https://github.com/PredixDev//predix-event-hub-java-sdk/examples) but this app adds a simple Spark job.
4+
Built on top of EventHub Java Sample App (https://github.com/PredixDev/event-hub-java-sample-app) but this app adds a simple Spark job.
55

66
## Summary:
77
Writes all received messages in the Subscriber Callback to a file.
88

99
A GET request to "/spark" will trigger a simple Spark job that counts how many times unique words appear in the written file of received messages.
1010

1111
The results of the Spark job are then written to "output/part-00000".
12-
13-
14-
[![Analytics](https://ga-beacon.appspot.com/UA-82773213-1/predix-event-hub-sdk/readme?pixel)](https://github.com/PredixDev)
12+
[![Analytics](https://predix-beacon.appspot.com/UA-82773213-1/event-hub-java-sdk/readme?pixel)](https://github.com/PredixDev)

examples/event-hub-java-spark-sample-app/pom.xml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
<groupId>event-hub-java-spark-sample-app</groupId>
66
<artifactId>event-hub-java-spark-sample-app</artifactId>
7-
<version>1.0.0</version>
7+
<version>1.0</version>
88

99
<parent>
1010
<groupId>org.springframework.boot</groupId>
1111
<artifactId>spring-boot-starter-parent</artifactId>
12-
<version>1.4.0.RELEASE</version>
12+
<version>2.0.3.RELEASE</version>
1313
<relativePath /> <!-- lookup parent from repository -->
1414
</parent>
1515

@@ -60,10 +60,6 @@
6060
</plugins>
6161
</build>
6262

63-
<properties>
64-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
65-
<jackson.version>2.6.5</jackson.version>
66-
</properties>
6763

6864
<dependencies>
6965
<dependency>
@@ -88,30 +84,20 @@
8884
<groupId>org.springframework.boot</groupId>
8985
<artifactId>spring-boot-starter-web</artifactId>
9086
</dependency>
91-
<dependency>
92-
<groupId>org.springframework.cloud</groupId>
93-
<artifactId>spring-cloud-core</artifactId>
94-
</dependency>
9587
<dependency>
9688
<groupId>org.springframework.boot</groupId>
9789
<artifactId>spring-boot-starter-websocket</artifactId>
9890
</dependency>
99-
10091
<dependency>
10192
<groupId>org.apache.spark</groupId>
10293
<artifactId>spark-core_2.11</artifactId>
10394
<version>2.1.0</version>
10495
</dependency>
105-
<dependency>
106-
<groupId>com.fasterxml.jackson.core</groupId>
107-
<artifactId>jackson-databind</artifactId>
108-
<version>${jackson.version}</version>
109-
</dependency>
11096
<dependency>
11197
<groupId>junit</groupId>
11298
<artifactId>junit</artifactId>
11399
<version>3.8.1</version>
114100
<scope>test</scope>
115101
</dependency>
116102
</dependencies>
117-
</project>
103+
</project>

examples/event-hub-java-spark-sample-app/src/main/java/com/ge/predix/eventhub/spark/sample/Controller.java

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
import java.io.BufferedWriter;
2222
import java.io.FileWriter;
2323
import java.io.IOException;
24-
import java.util.ArrayList;
25-
import java.util.Arrays;
26-
import java.util.Collections;
27-
import java.util.List;
24+
import java.util.*;
2825
import java.util.concurrent.atomic.AtomicInteger;
2926
import java.util.logging.Logger;
3027

@@ -50,8 +47,13 @@ public void makeClient() throws Exception {
5047
writer = new BufferedWriter(new FileWriter("messages.txt", true));
5148
conf = new SparkConf().setMaster("local").setAppName("Work Count App");
5249
sc = new JavaSparkContext(conf);
53-
System.out.println("******************************* Using environment variables *******************************");
54-
fromExplicit();
50+
if(System.getenv("EVENTHUB_INSTANCE_NAME") != null && System.getenv("UAA_INSTANCE_NAME") != null) {
51+
System.out.println("******************************* Using bound services *******************************");
52+
fromEnv();
53+
} else {
54+
System.out.println("******************************* Using environment variables *******************************");
55+
fromExplicit();
56+
}
5557

5658
class SubCallback implements Client.SubscribeCallback {
5759
@Override
@@ -83,10 +85,45 @@ void spark() {
8385
JavaRDD<String> lines = sc.textFile("messages.txt");
8486
JavaPairRDD<String, Integer> pairs = lines.mapToPair(s -> new Tuple2<>(s,1));
8587
JavaPairRDD<String, Integer> counts = pairs.reduceByKey((a, b) -> a + b);
88+
counts.foreach(data -> {
89+
System.out.println("result" + data);
90+
});
8691
counts.saveAsTextFile("output");
8792
sc.close();
8893
}
8994

95+
/**
96+
* Initialize the EventHubConfiguration Object
97+
* As if it were in cloud foundry (Uses V_cap services)
98+
* @throws EventHubClientException Exception occurred during creation
99+
*/
100+
private void fromEnv() throws EventHubClientException {
101+
try {
102+
EventHubConfiguration configuration = new EventHubConfiguration.Builder()
103+
.fromEnvironmentVariables()
104+
.publishConfiguration(new PublishConfiguration.Builder().publisherType(PublishConfiguration.PublisherType.SYNC).build())
105+
.subscribeConfiguration(new SubscribeConfiguration.Builder().subscriberName(subscriberName).subscriberInstance(subscriberInstance).build())
106+
.build();
107+
108+
eventHub = new Client(configuration);
109+
logger.info("** logging Client details **");
110+
logger.info(configuration.getAuthURL());
111+
logger.info(configuration.getClientID());
112+
logger.info(configuration.getClientSecret());
113+
logger.info(configuration.getHost());
114+
logger.info(configuration.getZoneID());
115+
logger.info(configuration.getPort() + "");
116+
logger.info(configuration.isAutomaticTokenRenew() + "");
117+
logger.info("** logging Client details **");
118+
eventHub.forceRenewToken();
119+
eventHubConfiguration = configuration;
120+
121+
} catch (EventHubClientException.InvalidConfigurationException e){
122+
logger.info(e.getMessage());
123+
System.out.println("Could not create client");
124+
}
125+
}
126+
90127

91128
private void fromExplicit() throws EventHubClientException {
92129
try {

examples/quick-start/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,5 @@ class QuickStart{
141141
}
142142
}
143143

144-
```
144+
[![Analytics](https://predix-beacon.appspot.com/UA-82773213-1/event-hub-java-sdk/readme?pixel)](https://github.com/PredixDev)
145145

146-
[![Analytics](https://ga-beacon.appspot.com/UA-82773213-1/predix-event-hub-sdk/readme?pixel)](https://github.com/PredixDev)

examples/quick-start/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<dependency>
1212
<groupId>com.ge.predix.eventhub</groupId>
1313
<artifactId>predix-event-hub-sdk</artifactId>
14-
<version>2.0.1</version>
14+
<version>2.0.0</version>
1515
</dependency>
1616

1717
<dependency>

examples/spring-rest/MANIFEST.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ applications:
44
memory: 512M
55
instances: 1
66
timeout: 180
7-
path: target/spring-rest-1.0.0.jar
7+
path: target/spring-rest-1.1-SNAPSHOT.jar
88
buildpack: java-buildpack
99
env:
1010
UAA_INSTANCE_NAME: <Bound UAA Instance Name>

0 commit comments

Comments
 (0)