Skip to content

Commit 8da9bed

Browse files
Release 1.0.3
1 parent 48fe161 commit 8da9bed

10 files changed

Lines changed: 115 additions & 37 deletions

File tree

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<a href="../../../../pages/adoption/audit-sdk/javadocs/index.html" target="_blank" >
1+
<a href="../../../../pages/adoption/audit-sdk/javadocs/index.html" target="\_blank" >
22
<img height="50px" width="100px" src="images/javadoc.png" alt="view javadoc"></a>
3-
&nbsp;
4-
<a href="../../../../pages/adoption/audit-sdk" target="_blank">
3+
4+
<a href="../../../../pages/adoption/audit-sdk" target="\_blank">
55
<img height="50px" width="100px" src="images/pages.jpg" alt="view github pages">
66
</a>
77

@@ -19,7 +19,7 @@ Use the SDK to publish audit messages using the Audit client.
1919
<dependency>
2020
<groupId>com.ge.predix</groupId>
2121
<artifactId>audit-sdk</artifactId>
22-
<version>1.0.0</version>
22+
<version>1.0.1</version>
2323
</dependency>
2424
```
2525

@@ -175,7 +175,7 @@ Here is an example:
175175
#### Additional API
176176

177177
##### Reconnect option
178-
Occasionally, audit client can be disconnected. In such a case, you receive an ```onFailure``` callback with ```FailReport.STREAM_IS_CLOSE```
178+
Occasionally, audit client can be disconnected. In such a case, you receive an ```onFailure``` callback with ```FailReport.STREAM_IS_CLOSE```
179179
**This notification is currently available only for ASYNC mode**.
180180

181181
There are two ways to handle reconnection:
@@ -192,10 +192,10 @@ AuditConfiguration.builder()
192192
The sdk supports two modes of authentication:
193193
- Using a UAA user and pass. Use the `AuditConfiguration.builder()` to obtain a regular, UAA based configuration.
194194
- Using an authentication token. Use the `AuditConfiguration.builderWithAuthToken()` to obtain an auth token based configuration.
195-
195+
196196
Once a client was created, its authentication mode cannot be changed.
197197
When working with authentication token, you might need to refresh the token. This can be achieved by running the `auditClient.setAuthToken(token)` API.
198-
198+
199199
Please note that this API throws IllegalStateException if executed on a client configured with UAA authentication mode.
200200

201201
----
@@ -221,12 +221,11 @@ AuditConfiguration.builder()
221221
If APPLICATION_NAME variable was set in the environment, it will be added to each message and there is no need to explicitly provide it when building the message.
222222

223223
#### For more information about the api: https://docs.predix.io/en-US/content/service/security/audit/using-predix-audit-service
224-
224+
225225
----
226-
# Example Projects:
226+
# Example Projects:
227227
- https://github.com/PredixDev/samplePublisherApp
228228
- https://github.com/PredixDev/samplePub-POJO
229229

230230

231231
[![Analytics](https://ga-beacon.appspot.com/UA-82773213-1/audit-sdk/readme?pixel)](https://github.com/PredixDev)
232-

pom.xml

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
12
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<groupId>com.ge.predix.audit</groupId>
67
<artifactId>audit-sdk</artifactId>
7-
<version>1.0.0</version>
8+
<version>1.0.3</version>
89
<packaging>jar</packaging>
910

1011
<name>audit-sdk</name>
@@ -15,8 +16,21 @@
1516
<maven.compiler.source>1.8</maven.compiler.source>
1617
<maven.compiler.target>1.8</maven.compiler.target>
1718
<powermock.version>1.7.1</powermock.version>
19+
<jackson.version>2.9.4</jackson.version>
20+
<eventhub.sdk.version>1.2.11</eventhub.sdk.version>
1821
</properties>
1922
<dependencies>
23+
<dependency>
24+
<groupId>org.projectlombok</groupId>
25+
<artifactId>lombok</artifactId>
26+
<version>1.18.0</version>
27+
<scope>provided</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>commons-logging</groupId>
31+
<artifactId>commons-logging</artifactId>
32+
<version>1.2</version>
33+
</dependency>
2034
<dependency>
2135
<groupId>javax.validation</groupId>
2236
<artifactId>validation-api</artifactId>
@@ -30,19 +44,40 @@
3044
<dependency>
3145
<groupId>com.ge.predix.eventhub</groupId>
3246
<artifactId>predix-event-hub-sdk</artifactId>
33-
<version>1.2.11</version>
47+
<version>${eventhub.sdk.version}</version>
3448
<exclusions>
3549
<exclusion>
3650
<groupId>org.apache.httpcomponents</groupId>
3751
<artifactId>httpclient</artifactId>
3852
</exclusion>
53+
<exclusion>
54+
<groupId>com.fasterxml.jackson.core</groupId>
55+
<artifactId>jackson-core</artifactId>
56+
</exclusion>
57+
<exclusion>
58+
<groupId>com.fasterxml.jackson.core</groupId>
59+
<artifactId>jackson-databind</artifactId>
60+
</exclusion>
61+
<exclusion>
62+
<groupId>com.fasterxml.jackson.core</groupId>
63+
<artifactId>jackson-annotations</artifactId>
64+
</exclusion>
3965
</exclusions>
4066
</dependency>
4167
<dependency>
42-
<groupId>org.projectlombok</groupId>
43-
<artifactId>lombok</artifactId>
44-
<version>1.16.10</version>
45-
<scope>provided</scope>
68+
<groupId>com.fasterxml.jackson.core</groupId>
69+
<artifactId>jackson-core</artifactId>
70+
<version>${jackson.version}</version>
71+
</dependency>
72+
<dependency>
73+
<groupId>com.fasterxml.jackson.core</groupId>
74+
<artifactId>jackson-databind</artifactId>
75+
<version>${jackson.version}</version>
76+
</dependency>
77+
<dependency>
78+
<groupId>com.fasterxml.jackson.core</groupId>
79+
<artifactId>jackson-annotations</artifactId>
80+
<version>${jackson.version}</version>
4681
</dependency>
4782
<dependency>
4883
<groupId>org.mockito</groupId>
@@ -55,12 +90,6 @@
5590
</exclusion>
5691
</exclusions>
5792
</dependency>
58-
<dependency>
59-
<groupId>junit</groupId>
60-
<artifactId>junit</artifactId>
61-
<version>4.12</version>
62-
<scope>test</scope>
63-
</dependency>
6493
<dependency>
6594
<groupId>org.mortbay.jetty.alpn</groupId>
6695
<artifactId>alpn-boot</artifactId>
@@ -103,9 +132,8 @@
103132
<version>${powermock.version}</version>
104133
<scope>test</scope>
105134
</dependency>
106-
107-
108135
</dependencies>
136+
109137
<build>
110138
<resources>
111139
<resource>
@@ -117,6 +145,15 @@
117145
</resource>
118146
</resources>
119147
<plugins>
148+
<plugin>
149+
<groupId>org.apache.maven.plugins</groupId>
150+
<artifactId>maven-surefire-plugin</artifactId>
151+
<configuration>
152+
<systemPropertyVariables>
153+
<java.util.logging.config.file>logging.properties</java.util.logging.config.file>
154+
</systemPropertyVariables>
155+
</configuration>
156+
</plugin>
120157
<plugin>
121158
<groupId>org.codehaus.mojo</groupId>
122159
<artifactId>build-helper-maven-plugin</artifactId>

src/main/java/com/ge/predix/audit/sdk/AbstractAuditClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public AbstractAuditClientImpl(AuditConfiguration configuration, TracingHandler
8383

8484
/**
8585
* Reconnect audit client manually
86-
* @throws EventHubClientException
86+
* @throws EventHubClientException in case of EventHub failure
8787
*/
8888
@Override
8989
public synchronized void reconnect() throws EventHubClientException {

src/main/java/com/ge/predix/audit/sdk/AuditClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public void shutdown() throws EventHubClientException {
103103

104104
/**
105105
* Returns the state of this client.
106+
*
107+
* @return state of Audit Client
106108
*/
107109
public AuditClientState getState(){
108110
return auditClientAsyncImpl.getAuditClientState();

src/main/java/com/ge/predix/audit/sdk/AuditClientAsyncImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected void addToEventhubCache(Collection<AuditEvent> events) {
147147
});
148148
}
149149

150-
private void innerReconnect(){
150+
private synchronized void innerReconnect(){
151151
try {
152152
reconnect();
153153
} catch (EventHubClientException e) {

src/main/java/com/ge/predix/audit/sdk/AuditClientSync.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public void shutdown() throws EventHubClientException {
9797

9898
/**
9999
* Returns the state of this client.
100+
*
101+
* @return state of Audit Client
100102
*/
101103
public AuditClientState getState(){
102104
return auditClientSyncImpl.getAuditClientState();

src/main/java/com/ge/predix/audit/sdk/ExponentialReconnectStrategy.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class ExponentialReconnectStrategy implements ReconnectStrategy {
2525
private volatile AtomicInteger curIndex;
2626
private volatile AtomicBoolean isBetweenIntervals;
2727
private volatile AtomicBoolean shouldReconnectNextInterval;
28+
private volatile AuditCommonClientState auditCommonClientState;
2829

2930
public ExponentialReconnectStrategy(Runnable actionToPerform) {
3031
threadExecutor = Executors.newSingleThreadScheduledExecutor();
@@ -36,6 +37,7 @@ public ExponentialReconnectStrategy(Runnable actionToPerform) {
3637

3738
@Override
3839
public synchronized void notifyStateChanged(AuditCommonClientState auditCommonClientState) {
40+
this.auditCommonClientState = auditCommonClientState;
3941
switch (auditCommonClientState){
4042
case DISCONNECTED:{
4143
if (!isBetweenIntervals.get()) {
@@ -53,25 +55,32 @@ public synchronized void notifyStateChanged(AuditCommonClientState auditCommonCl
5355
shouldReconnectNextInterval.set(false);
5456
shutdown();
5557
}
58+
case CONNECTING:{
59+
shouldReconnectNextInterval.set(true);
60+
}
61+
case CONNECTED:{
62+
shouldReconnectNextInterval.set(false);
63+
}
5664
default:
5765
break;
5866
}
5967
}
6068

6169
synchronized void handleInterval() {
6270
log.info("Running reconnect algo: shouldReconnect: "+shouldReconnectNextInterval+" index: "+curIndex);
63-
if (shouldReconnectNextInterval.get()) {
71+
if (shouldReconnectNextInterval.get()) {
6472
try {
6573
if(actionToPerform != null) {
6674
actionToPerform.run();
6775
}
76+
// if (!)
6877
} catch (Exception e) {
6978
log.warn("failed to perform reconnect: "+e.getMessage());
7079
}
7180
if (curIndex.get() < reconnectIntervalsMillis.length) {
7281
curIndex.incrementAndGet();
7382
}
74-
shouldReconnectNextInterval.set(false);
83+
//shouldReconnectNextInterval.set(false);
7584
threadExecutor.schedule(this::handleInterval, reconnectIntervalsMillis[curIndex.get()], TimeUnit.MILLISECONDS);
7685
} else {
7786
curIndex.set(0);

src/main/java/com/ge/predix/audit/sdk/TracingHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public interface TracingHandler {
1515

1616
/**
17-
* @returns AuditTracingEvent optional.
17+
* @return AuditTracingEvent optional.
1818
* it will return the sent message or null if no message was sent
1919
*/
2020
Optional<AuditTracingEvent> sendInitialCheckpoint();
@@ -26,4 +26,4 @@ public interface TracingHandler {
2626
boolean isTracingAck(Ack ack);
2727

2828
boolean isTracingEvent(AuditEvent event);
29-
}
29+
}

src/test/java/com/ge/predix/audit/sdk/ExponentialReconnectStrategyTest.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,44 @@
1111
/**
1212
* Created by 212582776 on 2/15/2018.
1313
*/
14+
1415
public class ExponentialReconnectStrategyTest {
1516

16-
public static class DoNothingRunnable implements Runnable{
17+
18+
public class NotifyConnectedRunnable implements Runnable{
19+
20+
1721

1822
@Override
1923
public void run() {
20-
24+
exponentialReconnectStrategy.notifyStateChanged(AuditCommonClientState.CONNECTED);
2125
}
2226
}
2327

24-
public static class ThrowsRuntimeExceptionRunnable implements Runnable{
28+
public class ThrowsRuntimeExceptionRunnable implements Runnable{
2529

2630
@Override
2731
public void run() {
32+
exponentialReconnectStrategy.notifyStateChanged(AuditCommonClientState.CONNECTING);
2833
throw new RuntimeException("exception");
34+
35+
}
36+
}
37+
38+
public class ReconnectFailureRunnable implements Runnable{
39+
40+
@Override
41+
public void run() {
42+
exponentialReconnectStrategy.notifyStateChanged(AuditCommonClientState.CONNECTING);
43+
exponentialReconnectStrategy.notifyStateChanged(AuditCommonClientState.DISCONNECTED);
2944
}
3045
}
3146

32-
private DoNothingRunnable doNothingRunnable = spy(new DoNothingRunnable());
47+
private NotifyConnectedRunnable doNothingRunnable = spy(new NotifyConnectedRunnable());
48+
private ReconnectFailureRunnable reconnectFailureRunnable = spy(new ReconnectFailureRunnable());
3349
private ThrowsRuntimeExceptionRunnable throwsRuntimeExceptionRunnable = spy(new ThrowsRuntimeExceptionRunnable());
3450

51+
3552
@Spy
3653
ExponentialReconnectStrategy exponentialReconnectStrategy;
3754
private static final int[] backoffIntervals = new int[]{100,200,300,400};
@@ -114,11 +131,22 @@ public void notifyStateChange_clientShutdown_reconnectIsNotAttempted() throws Ex
114131

115132
@Test
116133
public void notifyStateChange_actionThrowsException_reconnectContinues() throws Exception {
117-
exponentialReconnectStrategy = spy(new ExponentialReconnectStrategy(throwsRuntimeExceptionRunnable));
134+
exponentialReconnectStrategy = spy(new ExponentialReconnectStrategy(reconnectFailureRunnable));
118135
setBackoff();
119136
exponentialReconnectStrategy.notifyStateChanged(AuditCommonClientState.DISCONNECTED);
120-
Thread.sleep(500);
137+
Thread.sleep(150);
138+
verify(exponentialReconnectStrategy,times(1)).handleInterval();
139+
verify(reconnectFailureRunnable,times(1)).run();
140+
Thread.sleep(200);
121141
verify(exponentialReconnectStrategy,times(2)).handleInterval();
122-
verify(throwsRuntimeExceptionRunnable,times(1)).run();
142+
verify(reconnectFailureRunnable,times(2)).run();
143+
144+
doAnswer(invocation -> {
145+
exponentialReconnectStrategy.notifyStateChanged(AuditCommonClientState.CONNECTED); return null;}).when(reconnectFailureRunnable).run();
146+
147+
Thread.sleep(1000);
148+
verify(exponentialReconnectStrategy,times(4)).handleInterval();
149+
verify(reconnectFailureRunnable,times(3)).run();
150+
123151
}
124152
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
java.util.logging.ConsoleHandler.level=WARNING

0 commit comments

Comments
 (0)