summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--holmes-actions/pom.xml2
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java13
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java35
-rw-r--r--pom.xml2
-rw-r--r--version.properties2
5 files changed, 47 insertions, 7 deletions
diff --git a/holmes-actions/pom.xml b/holmes-actions/pom.xml
index e611163..f5c884d 100644
--- a/holmes-actions/pom.xml
+++ b/holmes-actions/pom.xml
@@ -12,7 +12,7 @@
<parent>
<groupId>org.onap.holmes.common</groupId>
<artifactId>holmes-common-parent</artifactId>
- <version>1.4.1-SNAPSHOT</version>
+ <version>1.4.2-SNAPSHOT</version>
</parent>
<name>holmes-common-service</name>
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java
index b8f6b86..33b53c7 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java
@@ -60,9 +60,9 @@ public class MsbRegister {
MicroServiceFullInfo microServiceFullInfo = null;
int retry = 0;
while (null == microServiceFullInfo && retry < totalRetryTimes) {
+ int time = interval * ++retry;
try {
- log.info("Holmes Service Registration. Times: " + ++retry);
- int time = interval * retry;
+ log.info("Holmes Service Registration. Times: " + retry);
microServiceFullInfo = client
.header("Accept", MediaType.APPLICATION_JSON)
.queryParam("createOrUpdate", true)
@@ -72,14 +72,14 @@ public class MsbRegister {
MicroServiceFullInfo.class);
if (null == microServiceFullInfo) {
- log.warn(String.format("Failed to register the service to MSB. Sleep %ds and try again.", time));
- threadSleep(TimeUnit.SECONDS.toSeconds(time));
+ retry(time);
} else {
log.info("Registration succeeded!");
break;
}
} catch (Exception e) {
log.warn("Unexpected exception: " + e.getMessage(), e);
+ retry(time);
}
}
@@ -90,6 +90,11 @@ public class MsbRegister {
log.info("Service registration completed.");
}
+ private void retry(int intervalInSecond) {
+ log.warn(String.format("Failed to register the service to MSB. Sleep %ds and try again.", intervalInSecond));
+ threadSleep(TimeUnit.SECONDS.toSeconds(intervalInSecond));
+ }
+
private void threadSleep(long second) {
log.info("Start sleeping...");
try {
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java
index 0201935..828fe0c 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java
@@ -118,4 +118,39 @@ public class MsbRegisterTest {
PowerMock.verifyAll();
}
+
+ @Test
+ public void test_register2Msb_fail_n_times_due_to_exception() {
+ int requestTimes = 3;
+ expect(mockedJerseyClient.header("Accept", MediaType.APPLICATION_JSON)).andReturn(mockedJerseyClient).times(requestTimes);
+ expect(mockedJerseyClient.queryParam("createOrUpdate", true)).andReturn(mockedJerseyClient).times(requestTimes);
+ expect(mockedJerseyClient.post(anyObject(String.class),
+ anyObject(Entity.class),
+ anyObject(Class.class)))
+ .andThrow(new RuntimeException("Failure!")).times(requestTimes - 1);
+
+ expect(mockedJerseyClient.post(anyObject(String.class),
+ anyObject(Entity.class),
+ anyObject(Class.class)))
+ .andReturn(GsonUtil.jsonToBean("{\"serviceName\":\"holmes-engine-mgmt\"," +
+ "\"version\":\"v1\",\"url\":\"/api/holmes-engine-mgmt/v1\",\"protocol\":\"REST\"," +
+ "\"visualRange\":\"0|1\",\"lb_policy\":\"\",\"publish_port\":\"\",\"namespace\":\"\"," +
+ "\"network_plane_type\":\"\",\"host\":\"\",\"path\":\"/api/holmes-engine-mgmt/v1\"," +
+ "\"enable_ssl\":true,\"nodes\":[{\"ip\":\"127.0.0.1\",\"port\":\"9102\",\"checkType\":\"\"," +
+ "\"checkUrl\":\"\",\"tls_skip_verify\":true,\"ha_role\":\"\",\"nodeId\":\"_v1_holmes-engine-mgmt_127.0.0.1_9102\"," +
+ "\"status\":\"passing\"}],\"metadata\":[],\"labels\":[],\"status\":\"1\",\"is_manual\":false}",
+ MicroServiceFullInfo.class));
+
+ PowerMock.replayAll();
+
+ MsbRegister msbRegister = new MsbRegister();
+ msbRegister.setInterval(1);
+ try {
+ msbRegister.register2Msb(msi);
+ } catch (CorrelationException e) {
+ // Do nothing
+ }
+
+ PowerMock.verifyAll();
+ }
} \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 333c071..083f22b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
<artifactId>holmes-common-parent</artifactId>
<packaging>pom</packaging>
- <version>1.4.1-SNAPSHOT</version>
+ <version>1.4.2-SNAPSHOT</version>
<name>holmes-common</name>
<modules>
<module>holmes-actions</module>
diff --git a/version.properties b/version.properties
index afe1c97..f588a8c 100644
--- a/version.properties
+++ b/version.properties
@@ -4,7 +4,7 @@
major=1
minor=4
-patch=1
+patch=2
base_version=${major}.${minor}.${patch}