summaryrefslogtreecommitdiffstats
path: root/holmes-actions
diff options
context:
space:
mode:
authorGuangrong Fu <fu.guangrong@zte.com.cn>2017-11-03 14:17:20 +0800
committerGuangrong Fu <fu.guangrong@zte.com.cn>2017-11-03 14:17:20 +0800
commit1be6bdd6b55219294a9ce6f708433fef3737cc13 (patch)
tree2c1b7a2bf341ad31b329b8e0787ce5e7dc9574fa /holmes-actions
parentc8e4878d4f519e63a81bd30b30fcba0a0b398eb5 (diff)
Modify the Service Addr Query Logic
Change-Id: I9e97a301bc5ba85e366bddbfda2f0ad721470c5f Issue-ID: HOLMES-81 Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'holmes-actions')
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java6
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java57
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java3
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java6
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java22
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java127
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java7
7 files changed, 84 insertions, 144 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
index cee6236..b80c40e 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
@@ -95,17 +95,17 @@ public class AaiQuery {
private String getBaseUrl(String suffixUrl) {
String url = "";
try {
- String[] msbUrl = MicroServiceConfig.getMsbServerAddr().split(":");
+ String[] msbUrl = MicroServiceConfig.getMsbServerAddrWithHttpPrefix().split(":");
url = msbUrl[0] + ":" + msbUrl[1] + suffixUrl;
} catch (Exception e) {
log.info("Failed to get msb address");
}
if ("".equals(url)) {
try {
- url = "https://" + MicroServiceConfig.getServiceAddrInfoFromCBS("aai_config")
+ url = "https://" + MicroServiceConfig.getServiceConfigInfoFromCBS("aai_config").replace("http://", "")
+ suffixUrl;
} catch (Exception e) {
- log.info("Failed to get aai address");
+ log.info("Failed to get the address of A&AI.", e);
}
}
return url;
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 d86f56c..2be8824 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
@@ -43,22 +43,22 @@ public class MicroServiceConfig {
}
public static String getConsulAddrInfo() {
- return getEnv(CONSUL_HOST) + CONSUL_ADDR_SUF;
+ return "http://" + getEnv(CONSUL_HOST) + CONSUL_ADDR_SUF;
}
- public static String getConfigBindingServiceAddrInfo() {
+ public static String getServiceAddrInfoFromDcaeConsulByHostName(String hostname) {
String ret = null;
- String queryString = getConsulAddrInfo() + CONFIG_BINDING_SERVICE;
- log.info("Query the CBS address using the URL: " + queryString);
+ String queryString = getConsulAddrInfo() + hostname;
+ log.info("Query the " + hostname + " address using the URL: " + queryString);
try {
JSONObject addrJson = (JSONObject) JSONArray.fromObject(execQuery(queryString)).get(0);
if (addrJson.has("ServiceAddress") && addrJson.has("ServicePort")) {
- ret = addrJson.getString("ServiceAddress") + ":" + addrJson.getString("ServicePort");
+ ret = "http://" + addrJson.getString("ServiceAddress") + ":" + addrJson.getString("ServicePort");
}
} catch (Exception e) {
log.warn(e.getMessage(), e);
}
- log.info("The CBS address is " + ret);
+ log.info("The " + hostname + " address is " + ret);
return ret;
}
@@ -68,23 +68,20 @@ public class MicroServiceConfig {
return response.readEntity(String.class);
}
- public static String getServiceAddrInfoFromCBS(String serviceName) {
+ public static String getServiceConfigInfoFromCBS(String hostname) {
String ret = null;
- String url = getConfigBindingServiceAddrInfo() + "/service_component/" +serviceName;
+ String url = getServiceAddrInfoFromDcaeConsulByHostName(getEnv(CONFIG_BINDING_SERVICE)) + "/service_component/" + hostname;
try {
- JSONObject jsonObject = JSONObject.fromObject(execQuery(url));
- log.info("The origin configurations (" + url + ") returned by DCAE is: " + jsonObject.toString());
- if (jsonObject.has(serviceName)) {
- ret = (String) jsonObject.getJSONArray(serviceName).get(0);
- }
+ ret = execQuery(url);
} catch (Exception e) {
log.warn(e.getMessage(), e);
}
+ log.info("The query url is: " + url + ". The corresponding configurations are " + ret);
return ret;
}
- public static String getMsbServerAddr() {
- String[] addrInfo = getMsbAddrInfo();
+ public static String getMsbServerAddrWithHttpPrefix() {
+ String[] addrInfo = getMsbIpAndPort();
String ret = addrInfo[0] + ":" + addrInfo[1];
if (!ret.startsWith(AlarmConst.HTTP) || !ret.startsWith(AlarmConst.HTTPS)){
ret = AlarmConst.HTTP + ret;
@@ -92,33 +89,15 @@ public class MicroServiceConfig {
return ret;
}
- public static String[] getMsbAddrInfo() {
- String[] msbServerInfo = null;
-
- //String info = getServiceAddrInfoFromCBS(MSB_ADDR);
- String info = getServiceAddrInfoFromCBS(getEnv(HOSTNAME));
- log.info("Got the service information of \"" + getEnv(HOSTNAME) + "\" from CBS. The response is " + info + ".");
-
- if (info != null){
- JSONObject infoObj = JSONObject.fromObject(info);
- String msbInfoTmp = infoObj.has("msb.hostname") ? infoObj.getString("msb.hostname") : null;
- if (msbInfoTmp != null) {
- msbServerInfo = split(msbInfoTmp);
- } else {
- msbServerInfo = split(getEnv(MSB_ADDR));
- }
- } else {
- msbServerInfo = split(getEnv(MSB_ADDR));
- }
-
- return msbServerInfo;
+ public static String[] getMsbIpAndPort() {
+ return split(getEnv(MSB_ADDR));
}
- public static String[] getServiceAddrInfo() {
+ public static String[] getMicroServiceIpAndPort() {
String[] serviceAddrInfo = null;
- String info = getServiceAddrInfoFromCBS(getEnv(HOSTNAME));
- log.info("Got the service information of \"" + getEnv(HOSTNAME) + "\" from CBS. The response is " + info + ".");
- if (info != 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()){
serviceAddrInfo = split(info);
} else {
serviceAddrInfo = split(getEnv(HOSTNAME));
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java
index 897f689..a0bb943 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java
@@ -19,7 +19,6 @@ import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import org.glassfish.jersey.client.ClientConfig;
-import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
import org.onap.holmes.common.dcae.utils.DcaeConfigurationParser;
@@ -29,7 +28,7 @@ public class DcaeConfigurationQuery {
public static DcaeConfigurations getDcaeConfigurations(String hostname)
throws CorrelationException {
- String serviceAddrInfo = MicroServiceConfig.getServiceAddrInfoFromCBS(hostname);
+ String serviceAddrInfo = MicroServiceConfig.getServiceConfigInfoFromCBS(hostname);
String response;
try {
response = getDcaeResponse(serviceAddrInfo);
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java
index 1cd481e..877a824 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MSBRegisterUtil.java
@@ -18,14 +18,10 @@ package org.onap.holmes.common.utils;
import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;
-import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
-import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.api.entity.ServiceRegisterEntity;
import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.msb.MicroserviceBusRest;
import org.onap.msb.sdk.discovery.common.RouteException;
import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo;
import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
@@ -36,7 +32,7 @@ import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
public class MSBRegisterUtil {
public void register2Msb(MicroServiceInfo msinfo) throws CorrelationException {
- String[] msbAddrInfo = MicroServiceConfig.getMsbAddrInfo();
+ String[] msbAddrInfo = MicroServiceConfig.getMsbIpAndPort();
MSBServiceClient msbClient = new MSBServiceClient(msbAddrInfo[0],
Integer.parseInt(msbAddrInfo[1]));
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
index 7872f2b..b3f1eb6 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
@@ -97,7 +97,7 @@ public class AaiQueryTest {
when(HttpsUtils.get(url, headers)).thenReturn("{}");
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
+ when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80");
PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
.andReturn("/aai/v11/cloud-infrastructure");
@@ -131,7 +131,7 @@ public class AaiQueryTest {
when(HttpsUtils.get(url, headers)).thenReturn("");
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
+ when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80");
PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
.andReturn("/aai/v11/cloud-infrastructure");
@@ -162,7 +162,7 @@ public class AaiQueryTest {
when(HttpsUtils.get(url, headers)).thenThrow(new CorrelationException(""));
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
+ when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80");
PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
.andReturn("/aai/v11/cloud-infrastructure");
@@ -216,7 +216,7 @@ public class AaiQueryTest {
Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil);
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenReturn("host_url");
+ when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("host_url");
PowerMock.expectPrivate(aaiQuery, "getResponse", anyObject(String.class)).andReturn("").anyTimes();
PowerMock.replayAll();
@@ -235,7 +235,7 @@ public class AaiQueryTest {
Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil);
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenReturn("host_url");
+ when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("host_url");
PowerMock.expectPrivate(aaiQuery, "getResponse", anyObject(String.class)).andReturn("").anyTimes();
PowerMock.replayAll();
@@ -307,8 +307,8 @@ public class AaiQueryTest {
aaiQuery = new AaiQuery();
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenReturn("http://10.96.33.33:80");
- when(MicroServiceConfig.getServiceAddrInfoFromCBS("nihao")).thenReturn("");
+ when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80");
+ when(MicroServiceConfig.getServiceConfigInfoFromCBS("nihao")).thenReturn("");
PowerMock.replayAll();
String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "/url");
@@ -322,8 +322,8 @@ public class AaiQueryTest {
aaiQuery = new AaiQuery();
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenThrow(new NullPointerException());
- when(MicroServiceConfig.getServiceAddrInfoFromCBS("aai_config")).thenReturn("aai");
+ when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenThrow(new NullPointerException());
+ when(MicroServiceConfig.getServiceConfigInfoFromCBS("aai_config")).thenReturn("aai");
PowerMock.replayAll();
String actual = Whitebox.invokeMethod(aaiQuery,"getBaseUrl", "url");
@@ -338,8 +338,8 @@ public class AaiQueryTest {
aaiQuery = new AaiQuery();
PowerMockito.mockStatic(MicroServiceConfig.class);
- when(MicroServiceConfig.getMsbServerAddr()).thenThrow(new NullPointerException());
- when(MicroServiceConfig.getServiceAddrInfoFromCBS("aai_config"))
+ when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenThrow(new NullPointerException());
+ when(MicroServiceConfig.getServiceConfigInfoFromCBS("aai_config"))
.thenThrow(new NullPointerException());
PowerMock.replayAll();
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 23dd075..59af9d3 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
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
import static org.onap.holmes.common.config.MicroServiceConfig.*;
import org.easymock.EasyMock;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.powermock.api.easymock.PowerMock;
@@ -41,14 +42,7 @@ public class MicroServiceConfigTest {
@Test
public void getMsbServerAddrTest() {
System.setProperty(MSB_ADDR, "test:80");
- System.setProperty(HOSTNAME, "rule-mgmt");
- PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);
- EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))
- .andReturn("{\"msb.hostname\": \"test:80\"}");
- PowerMock.replayAll();
- assertThat("http://test:80", equalTo(getMsbServerAddr()));
- PowerMock.verifyAll();
- System.clearProperty(MicroServiceConfig.HOSTNAME);
+ assertThat("http://test:80", equalTo(getMsbServerAddrWithHttpPrefix()));
System.clearProperty(MicroServiceConfig.MSB_ADDR);
}
@@ -56,12 +50,12 @@ public class MicroServiceConfigTest {
public void getMsbServerIpTest() {
System.setProperty(MSB_ADDR, "10.54.23.79:80");
System.setProperty(HOSTNAME, "rule-mgmt");
- PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);
- EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))
+ PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class);
+ EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME)))
.andReturn("{\"msb.hostname\": \"10.54.23.79:80\"}").times(2);
PowerMock.replayAll();
- assertThat("10.54.23.79", equalTo(getMsbAddrInfo()[0]));
- assertThat("80", equalTo(getMsbAddrInfo()[1]));
+ assertThat("10.54.23.79", equalTo(getMsbIpAndPort()[0]));
+ assertThat("80", equalTo(getMsbIpAndPort()[1]));
System.clearProperty(MicroServiceConfig.HOSTNAME);
System.clearProperty(MSB_ADDR);
}
@@ -69,33 +63,37 @@ public class MicroServiceConfigTest {
@Test
public void getServiceIpTest() {
System.setProperty(HOSTNAME, "127.0.0.1");
- assertThat("127.0.0.1", equalTo(getServiceAddrInfo()[0]));
- assertThat("80", equalTo(getServiceAddrInfo()[1]));
+ assertThat("127.0.0.1", equalTo(getMicroServiceIpAndPort()[0]));
+ assertThat("80", equalTo(getMicroServiceIpAndPort()[1]));
System.clearProperty(HOSTNAME);
}
@Test
public void getConsulAddrInfoTest() {
System.setProperty(CONSUL_HOST, "127.0.0.1");
- assertThat("127.0.0.1:8500/v1/catalog/service/", equalTo(getConsulAddrInfo()));
+ assertThat("http://127.0.0.1:8500/v1/catalog/service/", equalTo(getConsulAddrInfo()));
System.clearProperty(CONSUL_HOST);
}
@Test
public void getConfigBindingServiceAddrInfoTest_consul_not_exist() throws Exception {
+ System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
.andThrow(new RuntimeException("Invalid URL."));
PowerMock.replayAll();
- assertThat(getConfigBindingServiceAddrInfo(), is(nullValue()));
+ assertThat(getServiceAddrInfoFromDcaeConsulByHostName(System.getProperty(CONFIG_BINDING_SERVICE))
+ , is(nullValue()));
PowerMock.verifyAll();
+ System.clearProperty(CONFIG_BINDING_SERVICE);
}
@Test
- public void getConfigBindingServiceAddrInfoTest_consul_exists() throws Exception {
+ public void getServiceAddrInfoFromDcaeConsulByHostName_consul_exists() throws Exception {
+ System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
.andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
@@ -103,15 +101,18 @@ public class MicroServiceConfigTest {
PowerMock.replayAll();
- assertThat(getConfigBindingServiceAddrInfo(), equalTo("127.0.0.2:8080"));
+ assertThat(getServiceAddrInfoFromDcaeConsulByHostName(System.getProperty(CONFIG_BINDING_SERVICE)),
+ equalTo("http://127.0.0.2:8080"));
PowerMock.verifyAll();
System.clearProperty(CONSUL_HOST);
+ System.clearProperty(CONFIG_BINDING_SERVICE);
}
@Test
public void getConfigBindingServiceAddrInfoTest_consul_exists_propertie_not_exist() throws Exception {
+ System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
.andReturn("[{\"ServiceAddress\": \"127.0.0.2\"}]");
@@ -119,11 +120,13 @@ public class MicroServiceConfigTest {
PowerMock.replayAll();
- assertThat(getConfigBindingServiceAddrInfo(), is(nullValue()));
+ assertThat(getServiceAddrInfoFromDcaeConsulByHostName(System.getProperty(CONFIG_BINDING_SERVICE)),
+ is(nullValue()));
PowerMock.verifyAll();
System.clearProperty(CONSUL_HOST);
+ System.clearProperty(CONFIG_BINDING_SERVICE);
}
@Test
@@ -134,52 +137,32 @@ public class MicroServiceConfigTest {
PowerMock.replayAll();
- assertThat(getServiceAddrInfoFromCBS(HOSTNAME), is(nullValue()));
+ assertThat(getServiceConfigInfoFromCBS(HOSTNAME), is(nullValue()));
PowerMock.verifyAll();
}
@Test
- public void getServiceAddrInfoFromCBS_consul_exists_service_not_exist() throws Exception {
+ public void getServiceAddrInfoFromDcaeConsulByHostName_consul_exists_service_not_exist() throws Exception {
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("{}");
+ .andReturn("[]");
PowerMock.replayAll();
- assertThat(getServiceAddrInfoFromCBS(HOSTNAME), is(nullValue()));
- PowerMock.verifyAll();
- }
-
- @Test
- public void getServiceAddrInfoFromCBS_normal() throws Exception {
- System.setProperty(HOSTNAME, "rule-mgmt");
- PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("{\"rule-mgmt\": \"[\\\"127.0.0.3:5432\\\"]\"}");
-
- PowerMock.replayAll();
-
- assertThat(getServiceAddrInfoFromCBS("rule-mgmt"), equalTo("127.0.0.3:5432"));
-
+ assertThat(getServiceAddrInfoFromDcaeConsulByHostName(HOSTNAME), is(nullValue()));
PowerMock.verifyAll();
-
- System.clearProperty(HOSTNAME);
}
- @Test
+ @Ignore
public void getMsbAddrInfo_msb_registered() throws Exception {
System.setProperty(MSB_ADDR, "10.74.5.8:1545");
System.setProperty(HOSTNAME, "rule-mgmt");
- PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);
- EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))
+ PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class);
+ EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME)))
.andReturn("{\"msb.hostname\": \"127.0.0.3:5432\"}");
PowerMock.replayAll();
- String[] msbInfo = getMsbAddrInfo();
+ String[] msbInfo = getMsbIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("127.0.0.3"));
@@ -189,16 +172,16 @@ public class MicroServiceConfigTest {
System.clearProperty(MSB_ADDR);
}
- @Test
+ @Ignore
public void getMsbAddrInfo_msb_not_registered() throws Exception {
System.setProperty(MSB_ADDR, "10.74.5.8:1545");
System.setProperty(HOSTNAME, "rule-mgmt");
- PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);
- EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))
+ PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceConfigInfoFromCBS", String.class);
+ EasyMock.expect(MicroServiceConfig.getServiceConfigInfoFromCBS(System.getProperty(HOSTNAME)))
.andReturn("{}");
PowerMock.replayAll();
- String[] msbInfo = getMsbAddrInfo();
+ String[] msbInfo = getMsbIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
@@ -209,16 +192,14 @@ public class MicroServiceConfigTest {
}
@Test
- public void getServiceAddrInfo_msb_registered() throws Exception {
+ public void getMicroServiceIpAndPort_service_registered_to_consul() throws Exception {
System.setProperty(HOSTNAME, "rule-mgmt");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("{\"rule-mgmt\": \"[\\\"127.0.0.3:5432\\\"]\"}");
+ .andReturn("[{\"ServiceAddress\": \"127.0.0.3\", \"ServicePort\": \"5432\"}]");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("127.0.0.3"));
@@ -228,16 +209,14 @@ public class MicroServiceConfigTest {
}
@Test
- public void getServiceAddrInfo_msb_not_registered() throws Exception {
+ public void getMicroServiceIpAndPort_service_not_registered_to_consul() throws Exception {
System.setProperty(HOSTNAME, "10.74.5.8:1545");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("{}");
+ .andReturn("[]");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
@@ -247,16 +226,14 @@ public class MicroServiceConfigTest {
}
@Test
- public void getServiceAddrInfo_msb_not_registered_full_addr() throws Exception {
+ public void getMicroServiceIpAndPort_service_not_registered_full_addr() throws Exception {
System.setProperty(HOSTNAME, "http://10.74.5.8:1545");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
.andReturn("{}");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
@@ -266,16 +243,14 @@ public class MicroServiceConfigTest {
}
@Test
- public void getServiceAddrInfo_msb_not_registered_no_port() throws Exception {
+ public void getMicroServiceIpAndPort_service_not_registered_no_port() throws Exception {
System.setProperty(HOSTNAME, "http://10.74.5.8");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
.andReturn("{}");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
@@ -285,16 +260,14 @@ public class MicroServiceConfigTest {
}
@Test
- public void getServiceAddrInfo_msb_not_registered_only_ip() throws Exception {
+ public void getMicroServiceIpAndPort_service_not_registered_only_ip() throws Exception {
System.setProperty(HOSTNAME, "10.74.5.8");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
.andReturn("{}");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
@@ -304,16 +277,14 @@ public class MicroServiceConfigTest {
}
@Test
- public void getServiceAddrInfo_msb_not_registered_full_addr_https() throws Exception {
+ public void getMicroServiceIpAndPort_service_not_registered_full_addr_https() throws Exception {
System.setProperty(HOSTNAME, "https://10.74.5.8:5432");
PowerMock.mockStaticPartial(MicroServiceConfig.class, "execQuery", String.class);
PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
- PowerMock.expectPrivate(MicroServiceConfig.class, "execQuery", EasyMock.anyObject())
- .andReturn("{}");
+ .andReturn("[]");
PowerMock.replayAll();
- String[] msbInfo = getServiceAddrInfo();
+ String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
assertThat(msbInfo[0], equalTo("10.74.5.8"));
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java
index ab2554f..e1b79bf 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java
@@ -16,17 +16,12 @@
package org.onap.holmes.common.utils;
-import static org.onap.holmes.common.config.MicroServiceConfig.HOSTNAME;
-
import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
import javax.ws.rs.QueryParam;
-import org.easymock.EasyMock;
import org.junit.Rule;
-import org.junit.Test;
import org.onap.holmes.common.msb.MicroserviceBusRest;
import org.onap.holmes.common.api.entity.ServiceRegisterEntity;
import org.onap.holmes.common.config.MicroServiceConfig;
-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;
@@ -41,7 +36,7 @@ public class MSBRegisterUtilTest {
private MicroserviceBusRest microserviceBusRest = new MicroserviceBusRestProxy();
private ServiceRegisterEntity initServiceEntity() {
- String[] serviceAddrInfo = MicroServiceConfig.getServiceAddrInfo();
+ String[] serviceAddrInfo = MicroServiceConfig.getMicroServiceIpAndPort();
ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity();
serviceRegisterEntity.setServiceName("holmes-rule-mgmt");
serviceRegisterEntity.setProtocol("REST");