summaryrefslogtreecommitdiffstats
path: root/holmes-actions
diff options
context:
space:
mode:
Diffstat (limited to 'holmes-actions')
-rw-r--r--holmes-actions/pom.xml2
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java17
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dcae/DcaeConfigurationQuery.java1
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/utils/FileUtils.java5
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java6
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/config/MicroServiceConfigTest.java81
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/JerseyClientTest.java30
7 files changed, 28 insertions, 114 deletions
diff --git a/holmes-actions/pom.xml b/holmes-actions/pom.xml
index 6d139f0..bab5cef 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.3.7-SNAPSHOT</version>
+ <version>1.3.8-SNAPSHOT</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 97c7141..191d897 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
@@ -24,7 +24,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.onap.holmes.common.utils.CommonUtils.getEnv;
-import static org.onap.holmes.common.utils.CommonUtils.isIpAddress;
public class MicroServiceConfig {
@@ -97,22 +96,14 @@ public class MicroServiceConfig {
}
public static String[] getMicroServiceIpAndPort() {
- 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);
+ String info = getEnv(POD_IP);
+ if (info != null) {
+ return split(info);
} else {
- serviceAddrInfo = split(getEnv(HOSTNAME));
+ return split(getEnv(HOSTNAME));
}
- return serviceAddrInfo;
}
-
private static String[] split(String addr) {
String ip;
String port = "80";
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 4f8a0a5..2c963d8 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
@@ -20,6 +20,7 @@ import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
import org.onap.holmes.common.dcae.utils.DcaeConfigurationParser;
import org.onap.holmes.common.exception.CorrelationException;
+@Deprecated
public class DcaeConfigurationQuery {
public static DcaeConfigurations getDcaeConfigurations(String hostname)
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/FileUtils.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/FileUtils.java
index cf5de1c..a512c83 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/FileUtils.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/FileUtils.java
@@ -27,6 +27,7 @@ import java.io.IOException;
public class FileUtils {
final static private Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
+ final static private String LINE_SEPARATOR = System.getProperty ("line.separator");
static public String readTextFile(String path) {
try {
@@ -34,9 +35,9 @@ public class FileUtils {
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
- sb.append(line);
+ sb.append(line).append(LINE_SEPARATOR);
}
- return sb.toString();
+ return sb.substring(0, sb.length() - 1);
} catch (FileNotFoundException e) {
LOGGER.warn("No file found: {}", path);
} catch (IOException e) {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java
index 871ffad..cfb601a 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java
@@ -197,12 +197,14 @@ public class JerseyClient {
private boolean isSuccessful(Response response, String url) {
Response.StatusType statusInfo = response.getStatusInfo();
if (statusInfo.getFamily() != Response.Status.Family.SUCCESSFUL) {
- throw new HttpException(statusInfo.getStatusCode(),
- String.format("Failed to get response from the server. " +
+ logger.error(
+ String.format("Failed to get response from the server <%d>. " +
"\nURL: %s\nCause: %s\nResponse body: %s",
+ statusInfo.getStatusCode(),
url,
statusInfo.getReasonPhrase(),
response.readEntity(String.class)));
+ return false;
}
return true;
}
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 dd0c71a..3e28464 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
@@ -74,8 +74,6 @@ public class MicroServiceConfigTest {
@Test
public void getServiceIpTest() {
- mockGet(null);
-
String ip = StringUtils.isEmpty(ACTUAL_HOSTNAME) ? "10.74.5.8" : ACTUAL_HOSTNAME;
String hostname = String.format("http://%s", ip);
System.setProperty(HOSTNAME, hostname);
@@ -98,7 +96,7 @@ public class MicroServiceConfigTest {
}
@Test
- public void getConfigBindingServiceAddrInfoTest_consul_not_exist() throws Exception {
+ public void getConfigBindingServiceAddrInfoTest_consul_not_exist() {
System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service");
mockGet(null);
@@ -113,7 +111,7 @@ public class MicroServiceConfigTest {
}
@Test
- public void getServiceAddrInfoFromDcaeConsulByHostName_consul_exists() throws Exception {
+ public void getServiceAddrInfoFromDcaeConsulByHostName_consul_exists() {
System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service");
mockGet("[{\"ServiceAddress\": \"127.0.0.2\", \"ServicePort\": \"8080\"}]");
System.setProperty(CONSUL_HOST, "127.0.0.1");
@@ -130,7 +128,7 @@ public class MicroServiceConfigTest {
}
@Test
- public void getConfigBindingServiceAddrInfoTest_consul_return_empty_array() throws Exception {
+ public void getConfigBindingServiceAddrInfoTest_consul_return_empty_array() {
System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service");
System.setProperty(CONSUL_HOST, "127.0.0.1");
@@ -148,7 +146,7 @@ public class MicroServiceConfigTest {
}
@Test
- public void getConfigBindingServiceAddrInfoTest_consul_exists_property_not_exist() throws Exception {
+ public void getConfigBindingServiceAddrInfoTest_consul_exists_property_not_exist() {
System.setProperty(CONFIG_BINDING_SERVICE, "config_binding_service");
System.setProperty(CONSUL_HOST, "127.0.0.1");
@@ -178,7 +176,7 @@ public class MicroServiceConfigTest {
}
@Test
- public void getServiceAddrInfoFromDcaeConsulByHostName_consul_exists_service_not_exist() throws Exception {
+ public void getServiceAddrInfoFromDcaeConsulByHostName_consul_exists_service_not_exist() {
mockGet("[]");
PowerMock.replayAll();
@@ -189,7 +187,7 @@ public class MicroServiceConfigTest {
}
@Ignore
- public void getMsbAddrInfo_msb_registered() throws Exception {
+ public void getMsbAddrInfo_msb_registered() {
System.setProperty(MSB_IAG_SERVICE_HOST, "10.74.5.8");
System.setProperty(MSB_IAG_SERVICE_PORT, "1545");
System.setProperty(HOSTNAME, "rule-mgmt");
@@ -210,7 +208,7 @@ public class MicroServiceConfigTest {
}
@Ignore
- public void getMsbAddrInfo_msb_not_registered() throws Exception {
+ public void getMsbAddrInfo_msb_not_registered() {
System.setProperty(MSB_IAG_SERVICE_HOST, "10.74.5.8");
System.setProperty(MSB_IAG_SERVICE_PORT, "1545");
System.setProperty(HOSTNAME, "rule-mgmt");
@@ -231,49 +229,12 @@ public class MicroServiceConfigTest {
}
@Test
- public void getMicroServiceIpAndPort_service_registered_to_consul() throws Exception {
- System.setProperty(HOSTNAME, "rule-mgmt");
-
- mockGet("[{\"ServiceAddress\": \"127.0.0.3\", \"ServicePort\": \"5432\"}]");
-
- PowerMock.replayAll();
- String[] msbInfo = getMicroServiceIpAndPort();
- PowerMock.verifyAll();
-
- assertThat(msbInfo[0], equalTo("127.0.0.3"));
- assertThat(msbInfo[1], equalTo("5432"));
-
- System.clearProperty(HOSTNAME);
- }
-
- @Test
- public void getMicroServiceIpAndPort_service_not_registered_to_consul() throws Exception {
- String ip = StringUtils.isEmpty(ACTUAL_HOSTNAME) ? "10.74.5.8" : ACTUAL_HOSTNAME;
- String port = StringUtils.isEmpty(ACTUAL_HOSTNAME) ? "1545" : "80";
- String hostname = String.format("http://%s:%s", ip, port);
- System.setProperty(HOSTNAME, hostname);
-
- mockGet("[]");
-
- PowerMock.replayAll();
- String[] msbInfo = getMicroServiceIpAndPort();
- PowerMock.verifyAll();
-
- assertThat(msbInfo[0], equalTo(ip));
- assertThat(msbInfo[1], equalTo(port));
-
- System.clearProperty(HOSTNAME);
- }
-
- @Test
- public void getMicroServiceIpAndPort_service_not_registered_full_addr() throws Exception {
+ public void getMicroServiceIpAndPort_full_addr() {
String ip = StringUtils.isEmpty(ACTUAL_HOSTNAME) ? "10.74.5.8" : ACTUAL_HOSTNAME;
String port = StringUtils.isEmpty(ACTUAL_HOSTNAME) ? "1545" : "80";
String hostname = String.format("http://%s:%s", ip, port);
System.setProperty(HOSTNAME, hostname);
- mockGet("{}");
-
PowerMock.replayAll();
String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
@@ -285,13 +246,11 @@ public class MicroServiceConfigTest {
}
@Test
- public void getMicroServiceIpAndPort_service_not_registered_no_port() throws Exception {
+ public void getMicroServiceIpAndPort_no_port() {
String ip = StringUtils.isEmpty(ACTUAL_HOSTNAME) ? "10.74.5.8" : ACTUAL_HOSTNAME;
String hostname = String.format("http://%s", ip);
System.setProperty(HOSTNAME, hostname);
- mockGet("{}");
-
PowerMock.replayAll();
String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
@@ -303,32 +262,12 @@ public class MicroServiceConfigTest {
}
@Test
- public void getMicroServiceIpAndPort_service_not_registered_only_ip() throws Exception {
- String ip = StringUtils.isEmpty(ACTUAL_HOSTNAME) ? "10.74.5.8" : ACTUAL_HOSTNAME;
- String hostname = String.format("http://%s", ip);
- System.setProperty(HOSTNAME, hostname);
-
- mockGet("{}");
-
- PowerMock.replayAll();
- String[] msbInfo = getMicroServiceIpAndPort();
- PowerMock.verifyAll();
-
- assertThat(msbInfo[0], equalTo(ip));
- assertThat(msbInfo[1], equalTo("80"));
-
- System.clearProperty(HOSTNAME);
- }
-
- @Test
- public void getMicroServiceIpAndPort_service_not_registered_full_addr_https() throws Exception {
+ public void getMicroServiceIpAndPort_full_addr_https() {
String ip = StringUtils.isEmpty(ACTUAL_HOSTNAME) ? "10.74.5.8" : ACTUAL_HOSTNAME;
String port = StringUtils.isEmpty(ACTUAL_HOSTNAME) ? "1545" : "80";
String hostname = String.format("http://%s:%s", ip, port);
System.setProperty(HOSTNAME, hostname);
- mockGet("[]");
-
PowerMock.replayAll();
String[] msbInfo = getMicroServiceIpAndPort();
PowerMock.verifyAll();
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/JerseyClientTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JerseyClientTest.java
index b0b5714..ef4b3db 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/utils/JerseyClientTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/JerseyClientTest.java
@@ -37,20 +37,16 @@ import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"javax.net.ssl.*", "javax.security.*"})
public class JerseyClientTest {
- private final String ERROR_MSG = "Failed to get response from the server. \nURL: http://www.onap.org/holmes/test" +
- "\nCause: Not Found\nResponse body: Error";
private JerseyClient jerseyClient = JerseyClient.newInstance();
private String url = "http://www.onap.org/holmes/test";
- @Rule
- private ExpectedException exception = ExpectedException.none();
-
@Test
public void get_normal() {
Client mockedClient = PowerMock.createMock(Client.class);
@@ -134,18 +130,14 @@ public class JerseyClientTest {
EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
EasyMock.expect(mockedBuilder.get()).andReturn(mockedResponse);
- EasyMock.expect(mockedResponse.getStatus()).andReturn(404);
EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.NOT_FOUND);
EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Error");
WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
- exception.expect(HttpException.class);
- exception.expectMessage(ERROR_MSG);
-
PowerMock.replayAll();
- jerseyClient.get(url);
+ assertThat(jerseyClient.get(url), nullValue());
PowerMock.verifyAll();
}
@@ -182,18 +174,14 @@ public class JerseyClientTest {
EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
EasyMock.expect(mockedBuilder.post(null)).andReturn(mockedResponse);
- EasyMock.expect(mockedResponse.getStatus()).andReturn(404);
EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.NOT_FOUND);
EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Error");
WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
- exception.expect(HttpException.class);
- exception.expectMessage(ERROR_MSG);
-
PowerMock.replayAll();
- jerseyClient.post(url);
+ assertThat(jerseyClient.post(url), nullValue());
PowerMock.verifyAll();
}
@@ -300,18 +288,14 @@ public class JerseyClientTest {
EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
EasyMock.expect(mockedBuilder.put(null)).andReturn(mockedResponse);
- EasyMock.expect(mockedResponse.getStatus()).andReturn(404);
EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.NOT_FOUND);
EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Error");
WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
- exception.expect(HttpException.class);
- exception.expectMessage(ERROR_MSG);
-
PowerMock.replayAll();
- jerseyClient.put(url, null, null);
+ assertThat(jerseyClient.put(url, null, null), nullValue());
PowerMock.verifyAll();
}
@@ -394,18 +378,14 @@ public class JerseyClientTest {
EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
EasyMock.expect(mockedBuilder.delete()).andReturn(mockedResponse);
- EasyMock.expect(mockedResponse.getStatus()).andReturn(404);
EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.NOT_FOUND);
EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Error");
WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
- exception.expect(HttpException.class);
- exception.expectMessage(ERROR_MSG);
-
PowerMock.replayAll();
- jerseyClient.delete(url);
+ assertThat(jerseyClient.delete(url), nullValue());
PowerMock.verifyAll();
}