Made the retry interval longer during MSB reg. 27/128927/8
authorGuangrongFu <fu.guangrong@zte.com.cn>
Thu, 28 Apr 2022 03:46:53 +0000 (11:46 +0800)
committerGuangrongFu <fu.guangrong@zte.com.cn>
Thu, 28 Apr 2022 06:50:27 +0000 (14:50 +0800)
Issue-ID: HOLMES-536
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Change-Id: Ib1be1e8b8d193a7a4bb6bdb63f55dcbda8bc029c

holmes-actions/pom.xml
holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java
holmes-actions/src/test/java/org/onap/holmes/common/utils/MsbRegisterTest.java
pom.xml
version.properties

index 1000189..e611163 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
-<!-- Copyright 2017-2020 ZTE Corporation. Licensed under the Apache License, Version\r
+<!-- Copyright 2017-2022 ZTE Corporation. Licensed under the Apache License, Version\r
        2.0 (the "License"); you may not use this file except in compliance with\r
        the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\r
        Unless required by applicable law or agreed to in writing, software distributed\r
@@ -12,7 +12,7 @@
     <parent>\r
         <groupId>org.onap.holmes.common</groupId>\r
         <artifactId>holmes-common-parent</artifactId>\r
-        <version>1.4.0-SNAPSHOT</version>\r
+        <version>1.4.1-SNAPSHOT</version>\r
     </parent>\r
 \r
     <name>holmes-common-service</name>\r
index 018da17..b8f6b86 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright 2017-2020 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 
 package org.onap.holmes.common.utils;
 
+import lombok.Setter;
 import org.apache.commons.lang3.StringUtils;
 import org.jvnet.hk2.annotations.Service;
 import org.onap.holmes.common.config.MicroServiceConfig;
@@ -38,6 +39,12 @@ public class MsbRegister {
 
     private JerseyClient client = JerseyClient.newInstance();
 
+    @Setter
+    private int totalRetryTimes = 20;
+
+    @Setter
+    private int interval = 20;
+
     public MsbRegister() {
     }
 
@@ -52,11 +59,10 @@ public class MsbRegister {
 
         MicroServiceFullInfo microServiceFullInfo = null;
         int retry = 0;
-        int interval = 5;
-        while (null == microServiceFullInfo && retry < 20) {
+        while (null == microServiceFullInfo && retry < totalRetryTimes) {
             try {
-                log.info("Holmes Service Registration. Retry: " + retry++);
-
+                log.info("Holmes Service Registration. Times: " + ++retry);
+                int time  = interval * retry;
                 microServiceFullInfo = client
                         .header("Accept", MediaType.APPLICATION_JSON)
                         .queryParam("createOrUpdate", true)
@@ -66,9 +72,8 @@ public class MsbRegister {
                                 MicroServiceFullInfo.class);
 
                 if (null == microServiceFullInfo) {
-                    log.warn(String.format("Failed to register the service to MSB. Sleep %ds and try again.", interval));
-                    threadSleep(TimeUnit.SECONDS.toSeconds(interval));
-                    interval += 5;
+                    log.warn(String.format("Failed to register the service to MSB. Sleep %ds and try again.", time));
+                    threadSleep(TimeUnit.SECONDS.toSeconds(time));
                 } else {
                     log.info("Registration succeeded!");
                     break;
index cf40c17..0201935 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright 2017-2020 ZTE Corporation.
+ * Copyright 2017-2022 ZTE Corporation.
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -85,13 +85,14 @@ public class MsbRegisterTest {
     }
 
     @Test
-    public void test_register2Msb_fail_once() {
-        expect(mockedJerseyClient.header("Accept", MediaType.APPLICATION_JSON)).andReturn(mockedJerseyClient).times(2);
-        expect(mockedJerseyClient.queryParam("createOrUpdate", true)).andReturn(mockedJerseyClient).times(2);
+    public void test_register2Msb_fail_n_times() {
+        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)))
-                .andReturn(null);
+                .andReturn(null).times(requestTimes - 1);
 
         expect(mockedJerseyClient.post(anyObject(String.class),
                 anyObject(Entity.class),
@@ -108,6 +109,7 @@ public class MsbRegisterTest {
         PowerMock.replayAll();
 
         MsbRegister msbRegister = new MsbRegister();
+        msbRegister.setInterval(1);
         try {
             msbRegister.register2Msb(msi);
         } catch (CorrelationException e) {
diff --git a/pom.xml b/pom.xml
index 39f2e4d..333c071 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
-<!-- Copyright 2017-2020 ZTE Corporation. Licensed under the Apache License, Version\r
+<!-- Copyright 2017-2022 ZTE Corporation. Licensed under the Apache License, Version\r
        2.0 (the "License"); you may not use this file except in compliance with\r
        the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\r
        Unless required by applicable law or agreed to in writing, software distributed\r
@@ -20,7 +20,7 @@
     <artifactId>holmes-common-parent</artifactId>\r
     <packaging>pom</packaging>\r
 \r
-    <version>1.4.0-SNAPSHOT</version>\r
+    <version>1.4.1-SNAPSHOT</version>\r
     <name>holmes-common</name>\r
     <modules>\r
         <module>holmes-actions</module>\r
index 611dff3..afe1c97 100644 (file)
@@ -4,7 +4,7 @@
 \r
 major=1\r
 minor=4\r
-patch=0\r
+patch=1\r
 \r
 base_version=${major}.${minor}.${patch}\r
 \r