diff options
author | 2017-10-30 15:01:53 +0800 | |
---|---|---|
committer | 2017-10-30 15:01:53 +0800 | |
commit | 3dfe506a8ea1bec7096da63541e426958d04a1a0 (patch) | |
tree | 9b644cf858c5b41a44781e4820c0d8bf7ca8da27 /holmes-actions | |
parent | 2e3aee44bf7a25aa665c3e6bd1130209ace50193 (diff) |
Update the logic for MSB addr retrieving
Change-Id: Id4258d763489f622f68c8152bb89e093993d1982
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/config/MicroServiceConfig.java | 10 | ||||
-rw-r--r-- | holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java | 31 |
2 files changed, 31 insertions, 10 deletions
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 01a5f2e..212bc66 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 @@ -49,6 +49,7 @@ public class MicroServiceConfig { public static String getConfigBindingServiceAddrInfo() {
String ret = null;
String queryString = getConsulAddrInfo() + CONFIG_BINDING_SERVICE;
+ log.info("Query the CBS address using the URL: " + queryString);
try {
JSONObject addrJson = (JSONObject) JSONArray.fromObject(execQuery(queryString)).get(0);
if (addrJson.has("ServiceAddress") && addrJson.has("ServicePort")) {
@@ -57,6 +58,7 @@ public class MicroServiceConfig { } catch (Exception e) {
log.warn(e.getMessage(), e);
}
+ log.info("The CBS address is " + ret);
return ret;
}
@@ -71,6 +73,7 @@ public class MicroServiceConfig { String url = getConfigBindingServiceAddrInfo() + "/service_component/" +serviceName;
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);
}
@@ -92,7 +95,11 @@ public class MicroServiceConfig { public static String[] getMsbAddrInfo() {
String[] msbServerInfo = null;
- String info = getServiceAddrInfoFromCBS(MSB_ADDR);
+ //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 + ".");
+ JSONObject infoObj = JSONObject.fromObject(info);
+ info = infoObj.has("msb.hostname") ? infoObj.getString("msb.hostname") : null;
if (info != null){
msbServerInfo = split(info);
} else {
@@ -105,6 +112,7 @@ public class MicroServiceConfig { public static String[] getServiceAddrInfo() {
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){
serviceAddrInfo = split(info);
} else {
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 13064c5..23dd075 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 @@ -41,15 +41,28 @@ 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);
System.clearProperty(MicroServiceConfig.MSB_ADDR);
}
@Test
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)))
+ .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]));
+ System.clearProperty(MicroServiceConfig.HOSTNAME);
System.clearProperty(MSB_ADDR);
}
@@ -160,11 +173,10 @@ public class MicroServiceConfigTest { @Test
public void getMsbAddrInfo_msb_registered() throws Exception {
System.setProperty(MSB_ADDR, "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("{\"" + MSB_ADDR + "\": \"[\\\"127.0.0.3:5432\\\"]\"}");
+ System.setProperty(HOSTNAME, "rule-mgmt");
+ PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);
+ EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))
+ .andReturn("{\"msb.hostname\": \"127.0.0.3:5432\"}");
PowerMock.replayAll();
String[] msbInfo = getMsbAddrInfo();
@@ -173,16 +185,16 @@ public class MicroServiceConfigTest { assertThat(msbInfo[0], equalTo("127.0.0.3"));
assertThat(msbInfo[1], equalTo("5432"));
+ System.clearProperty(HOSTNAME);
System.clearProperty(MSB_ADDR);
}
@Test
public void getMsbAddrInfo_msb_not_registered() throws Exception {
System.setProperty(MSB_ADDR, "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())
+ System.setProperty(HOSTNAME, "rule-mgmt");
+ PowerMock.mockStaticPartial(MicroServiceConfig.class, "getServiceAddrInfoFromCBS", String.class);
+ EasyMock.expect(MicroServiceConfig.getServiceAddrInfoFromCBS(System.getProperty(HOSTNAME)))
.andReturn("{}");
PowerMock.replayAll();
@@ -192,6 +204,7 @@ public class MicroServiceConfigTest { assertThat(msbInfo[0], equalTo("10.74.5.8"));
assertThat(msbInfo[1], equalTo("1545"));
+ System.clearProperty(HOSTNAME);
System.clearProperty(MSB_ADDR);
}
|