summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortangpeng <tang.peng5@zte.com.cn>2019-03-30 07:56:48 +0000
committertangpeng <tang.peng5@zte.com.cn>2019-03-30 07:56:48 +0000
commitcc31e5503fbc9c17ada9e3b324457c3a2d67ec54 (patch)
tree998325547d20eaf8aacb86c3f5b1443a63b9dc7e
parentdd6a7fa137605db8e2eec437167c438af0ea2447 (diff)
HTTP/S Modifications
Change-Id: I731a37f868a8145f3018314db7c0248a75c8d62d Issue-ID: HOLMES-203 Signed-off-by: tangpeng <tang.peng5@zte.com.cn>
-rw-r--r--pom.xml2
-rw-r--r--rulemgt-standalone/pom.xml2
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java25
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java20
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java15
-rw-r--r--rulemgt/src/main/java/org/onap/holmes/rulemgt/msb/EngineInsQueryTool.java4
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java5
-rw-r--r--rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java12
8 files changed, 39 insertions, 46 deletions
diff --git a/pom.xml b/pom.xml
index 979ad48..0136e0a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -85,7 +85,7 @@
<dependency>
<groupId>org.onap.holmes.common</groupId>
<artifactId>holmes-actions</artifactId>
- <version>1.2.7</version>
+ <version>1.2.8</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
diff --git a/rulemgt-standalone/pom.xml b/rulemgt-standalone/pom.xml
index 2adb938..bb3b0ec 100644
--- a/rulemgt-standalone/pom.xml
+++ b/rulemgt-standalone/pom.xml
@@ -130,7 +130,7 @@
<directory>src/main/assembly/</directory>
<filtering>false</filtering>
<includes>
- <include>nginx.conf</include>
+ <include>nginx-*.conf</include>
<include>**/holmes-frontend*.*</include>
<include>**/*.pem</include>
</includes>
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
index 5c38170..058aea7 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
@@ -17,19 +17,11 @@
package org.onap.holmes.rulemgt;
import io.dropwizard.setup.Environment;
-
-import java.util.EnumSet;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import javax.servlet.DispatcherType;
-
import lombok.extern.slf4j.Slf4j;
import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.dropwizard.ioc.bundle.IOCApplication;
import org.onap.holmes.common.exception.CorrelationException;
+import org.onap.holmes.common.utils.HttpsUtils;
import org.onap.holmes.common.utils.MSBRegisterUtil;
import org.onap.holmes.common.utils.transactionid.TransactionIdFilter;
import org.onap.holmes.rulemgt.dcae.DcaeConfigurationPolling;
@@ -38,6 +30,14 @@ import org.onap.holmes.rulemgt.resources.RuleMgtResources;
import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
import org.onap.msb.sdk.discovery.entity.Node;
+import javax.servlet.DispatcherType;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
@Slf4j
public class RuleActiveApp extends IOCApplication<RuleAppConfig> {
@@ -75,6 +75,8 @@ public class RuleActiveApp extends IOCApplication<RuleAppConfig> {
}
private MicroServiceInfo createMicroServiceInfo() {
+ String msbAddrTemplate = (HttpsUtils.isHttpsEnabled() ? "https" : "http")
+ + "://%s:%s/api/holmes-rule-mgmt/v1/healthcheck";
String[] serviceAddrInfo = MicroServiceConfig.getMicroServiceIpAndPort();
MicroServiceInfo msinfo = new MicroServiceInfo();
msinfo.setServiceName("holmes-rule-mgmt");
@@ -82,13 +84,13 @@ public class RuleActiveApp extends IOCApplication<RuleAppConfig> {
msinfo.setUrl("/api/holmes-rule-mgmt/v1");
msinfo.setProtocol("REST");
msinfo.setVisualRange("0|1");
- msinfo.setEnable_ssl(true);
+ msinfo.setEnable_ssl(HttpsUtils.isHttpsEnabled());
Set<Node> nodes = new HashSet<>();
Node node = new Node();
node.setIp(serviceAddrInfo[0]);
node.setPort("9101");
node.setCheckType("HTTP");
- node.setCheckUrl(String.format("https://%s:%s/api/holmes-rule-mgmt/v1/healthcheck", serviceAddrInfo[0], "9101"));
+ node.setCheckUrl(String.format(msbAddrTemplate, serviceAddrInfo[0], "9101"));
node.setCheckTimeOut("60s");
node.setCheckInterval("60s");
nodes.add(node);
@@ -96,3 +98,4 @@ public class RuleActiveApp extends IOCApplication<RuleAppConfig> {
return msinfo;
}
}
+
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
index 15af38d..cc20cab 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
@@ -31,22 +31,22 @@ import org.onap.holmes.common.utils.HttpsUtils;
import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
-import org.onap.holmes.common.config.MicroServiceConfig;
@Slf4j
@Service
public class EngineService {
- private static final String PREFIX = "https://";
+ private static final String HTTPS = "https://";
+ private static final String HTTP = "http://";
private static final String PORT = ":9102";
protected HttpResponse delete(String packageName, String ip) throws Exception {
HashMap headers = createHeaders();
- String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName;
+ String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName;
CloseableHttpClient httpClient = null;
HttpDelete httpDelete = new HttpDelete(url);
try {
- httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
+ httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
return HttpsUtils.delete(httpDelete, headers, httpClient);
} finally {
httpDelete.releaseConnection();
@@ -58,11 +58,11 @@ public class EngineService {
throws Exception {
String content = GsonUtil.beanToJson(correlationCheckRule4Engine);
HashMap headers = createHeaders();
- String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;
+ String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH;
CloseableHttpClient httpClient = null;
HttpPost httpPost = new HttpPost(url);
try {
- httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
+ httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
return HttpsUtils.post(httpPost, headers, new HashMap<>(), new StringEntity(content), httpClient);
} finally {
httpPost.releaseConnection();
@@ -73,11 +73,11 @@ public class EngineService {
protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) throws Exception {
String content = GsonUtil.beanToJson(correlationDeployRule4Engine);
HashMap headers = createHeaders();
- String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;
+ String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH;
CloseableHttpClient httpClient = null;
HttpPut httpPut = new HttpPut(url);
try {
- httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
+ httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
return HttpsUtils.put(httpPut, headers, new HashMap<>(), new StringEntity(content),httpClient);
} finally {
closeHttpClient(httpClient);
@@ -100,4 +100,8 @@ public class EngineService {
headers.put("Accept", MediaType.APPLICATION_JSON);
return headers;
}
+
+ private String getRequestPref(){
+ return HttpsUtils.isHttpsEnabled() ? HTTPS : HTTP;
+ }
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
index 68314e1..dcd530c 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
@@ -13,19 +13,10 @@
*/
package org.onap.holmes.rulemgt.dcae;
-import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParseException;
-import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import javax.ws.rs.core.MediaType;
@@ -112,7 +103,7 @@ public class DcaeConfigurationPolling implements Runnable {
CloseableHttpClient httpClient = null;
HttpGet httpGet = new HttpGet(url);
try {
- httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
+ httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
HttpResponse httpResponse = HttpsUtils.get(httpGet, headers, httpClient);
String response = HttpsUtils.extractResponseEntity(httpResponse);
return JSONObject.parseObject(response, RuleQueryListResponse.class);
@@ -139,7 +130,7 @@ public class DcaeConfigurationPolling implements Runnable {
CloseableHttpClient httpClient = null;
HttpPut httpPut = new HttpPut(url);
try {
- httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
+ httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
httpResponse = HttpsUtils
.put(httpPut, headers, new HashMap<>(), new StringEntity(content), httpClient);
} catch (UnsupportedEncodingException e) {
@@ -167,7 +158,7 @@ public class DcaeConfigurationPolling implements Runnable {
CloseableHttpClient httpClient = null;
HttpDelete httpDelete = new HttpDelete(url + "/" + correlationRule.getRuleId());
try {
- httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
+ httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
HttpsUtils.delete(httpDelete, headers, httpClient);
} catch (Exception e) {
log.warn("Failed to delete rule, the rule id is : " + correlationRule.getRuleId()
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/msb/EngineInsQueryTool.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/msb/EngineInsQueryTool.java
index 00947bf..a0eee1f 100644
--- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/msb/EngineInsQueryTool.java
+++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/msb/EngineInsQueryTool.java
@@ -16,8 +16,6 @@
package org.onap.holmes.rulemgt.msb;
-import java.io.IOException;
-
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
@@ -50,7 +48,7 @@ public class EngineInsQueryTool {
public List<String> getInstanceList() throws Exception {
String response;
HttpGet httpGet = new HttpGet(url);
- try (CloseableHttpClient httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT)) {
+ try (CloseableHttpClient httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT)) {
HttpResponse httpResponse = HttpsUtils.get(httpGet, new HashMap<>(), httpClient);
response = HttpsUtils.extractResponseEntity(httpResponse);
} catch (Exception e) {
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java
index 836b210..82e51a5 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java
@@ -19,7 +19,6 @@ package org.onap.holmes.rulemgt.bolt.enginebolt;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.any;
import static org.hamcrest.Matchers.equalTo;
import java.util.HashMap;
@@ -27,8 +26,6 @@ import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
-import org.easymock.EasyMock;
-import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -78,7 +75,7 @@ public class EngineServiceTest {
public void testEngineService_closeHttpClient_ok() throws Exception {
PowerMock.resetAll();
CloseableHttpClient closeableHttpClient = HttpsUtils
- .getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);
+ .getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);
Whitebox.invokeMethod(engineService, "closeHttpClient", closeableHttpClient);
}
diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
index 4ad213c..53e60c8 100644
--- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
+++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java
@@ -79,20 +79,20 @@ public class DcaeConfigurationPollingTest {
CloseableHttpClient clientMock = createMock(CloseableHttpClient.class);
HttpResponse httpResponseMock = createMock(HttpResponse.class);
- expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
expect(HttpsUtils.get(anyObject(HttpGet.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
.andReturn(httpResponseMock);
expect(HttpsUtils.extractResponseEntity(httpResponseMock)).andReturn(JSONObject.toJSONString(ruleQueryListResponse));
clientMock.close();
expectLastCall();
- expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
expect(HttpsUtils.delete(anyObject(HttpDelete.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
.andReturn(httpResponseMock);
clientMock.close();
expectLastCall();
- expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
expect(HttpsUtils.put(anyObject(HttpPut.class), anyObject(HashMap.class), anyObject(HashMap.class),
anyObject(StringEntity.class), anyObject(CloseableHttpClient.class)))
.andReturn(httpResponseMock);
@@ -132,13 +132,13 @@ public class DcaeConfigurationPollingTest {
CloseableHttpClient clientMock = createMock(CloseableHttpClient.class);
HttpResponse httpResponseMock = createMock(HttpResponse.class);
- expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
expect(HttpsUtils.delete(anyObject(HttpDelete.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
.andReturn(httpResponseMock);
clientMock.close();
expectLastCall();
- expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
expect(HttpsUtils.put(anyObject(HttpPut.class), anyObject(HashMap.class), anyObject(HashMap.class),
anyObject(StringEntity.class), anyObject(CloseableHttpClient.class)))
.andReturn(httpResponseMock);
@@ -164,7 +164,7 @@ public class DcaeConfigurationPollingTest {
CloseableHttpClient clientMock = createMock(CloseableHttpClient.class);
HttpResponse httpResponseMock = createMock(HttpResponse.class);
- expect(HttpsUtils.getHttpClient(30000)).andReturn(clientMock);
+ expect(HttpsUtils.getConditionalHttpsClient(30000)).andReturn(clientMock);
expect(HttpsUtils.get(anyObject(HttpGet.class), anyObject(HashMap.class), anyObject(CloseableHttpClient.class)))
.andReturn(httpResponseMock);
expect(HttpsUtils.extractResponseEntity(httpResponseMock)).andReturn("{\"correlationRules\": [], \"totalCount\": 0}");