summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2018-10-18 14:44:52 +0800
committerGuangrongFu <fu.guangrong@zte.com.cn>2018-10-18 14:44:52 +0800
commitf0ae1a9f8d1464782a041c2361400dddbf1e890a (patch)
treeec3a2344a3d6f9c4805038cab1ffadc126ada7d9
parent746543151309d116aac2ba78093574138cf26095 (diff)
Geted Holmes IP from Env Var1.2.2
Change-Id: Idf803dd37a33cf325af71dbf43fca3fe2dacaefe Issue-ID: HOLMES-175 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
-rw-r--r--holmes-actions/pom.xml2
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java12
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java49
-rw-r--r--pom.xml2
-rw-r--r--version.properties2
5 files changed, 64 insertions, 3 deletions
diff --git a/holmes-actions/pom.xml b/holmes-actions/pom.xml
index 5090b74..2b43532 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.2.1</version>
+ <version>1.2.2</version>
</parent>
<name>holmes-common-service</name>
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java b/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java
index c179280..66daebf 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java
@@ -25,15 +25,19 @@ import javax.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import org.onap.holmes.common.constant.AlarmConst;
+import java.util.regex.Pattern;
+
@Slf4j
public class MicroServiceConfig {
final static public String CONSUL_ADDR_SUF = ":8500/v1/catalog/service/";
final static public String CONSUL_HOST = "CONSUL_HOST";
final static public String HOSTNAME = "HOSTNAME";
+ final static public String POD_IP = "POD_IP";
final static public String CONFIG_BINDING_SERVICE = "CONFIG_BINDING_SERVICE";
final static public String DOCKER_HOST = "DOCKER_HOST";
final static public String MSB_ADDR = "MSB_ADDR";
+ final static public Pattern IP_REG = Pattern.compile("(http(s)?://)?(\\d+\\.\\d+\\.\\d+\\.\\d+)(:(\\d+))?");
public static String getEnv(String name) {
String value = System.getenv(name);
@@ -100,7 +104,11 @@ public class MicroServiceConfig {
String[] serviceAddrInfo = null;
String info = getServiceAddrInfoFromDcaeConsulByHostName(getEnv(HOSTNAME));
log.info("Got the service information of \"" + getEnv(HOSTNAME) + "\" from Consul. The response is " + info + ".");
+
if (info != null && !info.isEmpty()) {
+ if (!isIpAddress(info)) {
+ info = getEnv(POD_IP);
+ }
serviceAddrInfo = split(info);
} else {
serviceAddrInfo = split(getEnv(HOSTNAME));
@@ -108,6 +116,10 @@ public class MicroServiceConfig {
return serviceAddrInfo;
}
+ private static boolean isIpAddress(String info) {
+ return IP_REG.matcher(info).matches();
+ }
+
private static String[] split(String addr) {
String ip;
String port = "80";
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java
index 59af9d3..a5d6597 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java
@@ -31,6 +31,7 @@ import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;
+import org.powermock.reflect.internal.WhiteboxImpl;
@PrepareForTest(MicroServiceConfig.class)
@PowerMockIgnore({"javax.ws.*"})
@@ -292,4 +293,52 @@ public class MicroServiceConfigTest {
System.clearProperty(MSB_ADDR);
}
+
+ @Test
+ public void isValidIpAddress_with_port() throws Exception {
+ boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "10.75.13.21:90");
+ assertThat(res, is(true));
+ }
+
+ @Test
+ public void isValidIpAddress_without_port() throws Exception {
+ boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "10.75.13.21");
+ assertThat(res, is(true));
+ }
+
+ @Test
+ public void isValidIpAddress_with_port_with_http_prefix() throws Exception {
+ boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "http://10.75.13.21:90");
+ assertThat(res, is(true));
+ }
+
+ @Test
+ public void isValidIpAddress_without_port_with_https_prefix() throws Exception {
+ boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "https://10.75.13.21");
+ assertThat(res, is(true));
+ }
+
+ @Test
+ public void isValidIpAddress_invalid_ip_without_port() throws Exception {
+ boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "holmes-rule-mgmt");
+ assertThat(res, is(false));
+ }
+
+ @Test
+ public void isValidIpAddress_invalid_ip_with_port() throws Exception {
+ boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "holmes-rule-mgmt:80");
+ assertThat(res, is(false));
+ }
+
+ @Test
+ public void isValidIpAddress_invalid_ip_without_port_with_http_prefix() throws Exception {
+ boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "http://holmes-rule-mgmt");
+ assertThat(res, is(false));
+ }
+
+ @Test
+ public void isValidIpAddress_invalid_ip_with_port_with_https_prefix() throws Exception {
+ boolean res = WhiteboxImpl.invokeMethod(MicroServiceConfig.class, "isIpAddress", "https://holmes-rule-mgmt:80");
+ assertThat(res, is(false));
+ }
} \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 5e450b8..7b5932c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
<artifactId>holmes-common-parent</artifactId>
<packaging>pom</packaging>
- <version>1.2.1</version>
+ <version>1.2.2</version>
<name>holmes-common</name>
<modules>
<module>holmes-actions</module>
diff --git a/version.properties b/version.properties
index 146a672..cfb32e0 100644
--- a/version.properties
+++ b/version.properties
@@ -4,7 +4,7 @@
major=1
minor=2
-patch=1
+patch=2
base_version=${major}.${minor}.${patch}