HTTP/S Modifications 90/83790/1
authortangpeng <tang.peng5@zte.com.cn>
Sat, 30 Mar 2019 07:56:48 +0000 (07:56 +0000)
committertangpeng <tang.peng5@zte.com.cn>
Sat, 30 Mar 2019 07:56:48 +0000 (07:56 +0000)
Change-Id: I731a37f868a8145f3018314db7c0248a75c8d62d
Issue-ID: HOLMES-203
Signed-off-by: tangpeng <tang.peng5@zte.com.cn>
pom.xml
rulemgt-standalone/pom.xml
rulemgt/src/main/java/org/onap/holmes/rulemgt/RuleActiveApp.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineService.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPolling.java
rulemgt/src/main/java/org/onap/holmes/rulemgt/msb/EngineInsQueryTool.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/bolt/enginebolt/EngineServiceTest.java
rulemgt/src/test/java/org/onap/holmes/rulemgt/dcae/DcaeConfigurationPollingTest.java

diff --git a/pom.xml b/pom.xml
index 979ad48..0136e0a 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -85,7 +85,7 @@
             <dependency>\r
                 <groupId>org.onap.holmes.common</groupId>\r
                 <artifactId>holmes-actions</artifactId>\r
-                <version>1.2.7</version>\r
+                <version>1.2.8</version>\r
             </dependency>\r
             <dependency>\r
                 <groupId>io.dropwizard</groupId>\r
index 2adb938..bb3b0ec 100644 (file)
                                     <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>
index 5c38170..058aea7 100644 (file)
 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;
     }
 }
+
index 15af38d..cc20cab 100644 (file)
@@ -31,22 +31,22 @@ import org.onap.holmes.common.utils.HttpsUtils;
 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
 import org.onap.holmes.rulemgt.constant.RuleMgtConstant;\r
-import org.onap.holmes.common.config.MicroServiceConfig;\r
 \r
 @Slf4j\r
 @Service\r
 public class EngineService {\r
 \r
-    private static final String PREFIX = "https://";\r
+    private static final String HTTPS = "https://";\r
+    private static final String HTTP = "http://";\r
     private static final String PORT = ":9102";\r
 \r
     protected HttpResponse delete(String packageName, String ip) throws Exception {\r
         HashMap headers = createHeaders();\r
-        String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName;\r
+        String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName;\r
         CloseableHttpClient httpClient = null;\r
         HttpDelete httpDelete = new HttpDelete(url);\r
         try {\r
-            httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);\r
+            httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);\r
             return HttpsUtils.delete(httpDelete, headers, httpClient);\r
         } finally {\r
             httpDelete.releaseConnection();\r
@@ -58,11 +58,11 @@ public class EngineService {
             throws Exception {\r
         String content = GsonUtil.beanToJson(correlationCheckRule4Engine);\r
         HashMap headers = createHeaders();\r
-        String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
+        String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
         CloseableHttpClient httpClient = null;\r
         HttpPost httpPost = new HttpPost(url);\r
         try {\r
-            httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);\r
+            httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);\r
             return HttpsUtils.post(httpPost, headers, new HashMap<>(), new StringEntity(content), httpClient);\r
         } finally {\r
             httpPost.releaseConnection();\r
@@ -73,11 +73,11 @@ public class EngineService {
     protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) throws Exception {\r
         String content = GsonUtil.beanToJson(correlationDeployRule4Engine);\r
         HashMap headers = createHeaders();\r
-        String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
+        String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
         CloseableHttpClient httpClient = null;\r
         HttpPut httpPut = new HttpPut(url);\r
         try {\r
-            httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);\r
+            httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);\r
             return HttpsUtils.put(httpPut, headers, new HashMap<>(), new StringEntity(content),httpClient);\r
         } finally {\r
             closeHttpClient(httpClient);\r
@@ -100,4 +100,8 @@ public class EngineService {
         headers.put("Accept", MediaType.APPLICATION_JSON);\r
         return headers;\r
     }\r
+\r
+    private String getRequestPref(){\r
+        return HttpsUtils.isHttpsEnabled() ? HTTPS : HTTP;\r
+    }\r
 }\r
index 68314e1..dcd530c 100644 (file)
  */
 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()
index 00947bf..a0eee1f 100644 (file)
@@ -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) {
index 836b210..82e51a5 100644 (file)
@@ -19,7 +19,6 @@ package org.onap.holmes.rulemgt.bolt.enginebolt;
 \r
 \r
 import static org.hamcrest.MatcherAssert.assertThat;\r
-import static org.hamcrest.Matchers.any;\r
 import static org.hamcrest.Matchers.equalTo;\r
 \r
 import java.util.HashMap;\r
@@ -27,8 +26,6 @@ import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.CloseableHttpResponse;\r
 import org.apache.http.impl.client.CloseableHttpClient;\r
 import org.apache.http.impl.client.HttpClients;\r
-import org.easymock.EasyMock;\r
-import org.hamcrest.Matchers;\r
 import org.junit.Before;\r
 import org.junit.Rule;\r
 import org.junit.Test;\r
@@ -78,7 +75,7 @@ public class EngineServiceTest {
     public void testEngineService_closeHttpClient_ok() throws Exception {\r
         PowerMock.resetAll();\r
         CloseableHttpClient closeableHttpClient = HttpsUtils\r
-                .getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);\r
+                .getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);\r
         Whitebox.invokeMethod(engineService, "closeHttpClient", closeableHttpClient);\r
     }\r
 \r
index 4ad213c..53e60c8 100644 (file)
@@ -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}");