From cc31e5503fbc9c17ada9e3b324457c3a2d67ec54 Mon Sep 17 00:00:00 2001 From: tangpeng Date: Sat, 30 Mar 2019 07:56:48 +0000 Subject: HTTP/S Modifications Change-Id: I731a37f868a8145f3018314db7c0248a75c8d62d Issue-ID: HOLMES-203 Signed-off-by: tangpeng --- .../org/onap/holmes/rulemgt/RuleActiveApp.java | 25 ++++++++++++---------- .../rulemgt/bolt/enginebolt/EngineService.java | 20 ++++++++++------- .../rulemgt/dcae/DcaeConfigurationPolling.java | 15 +++---------- .../holmes/rulemgt/msb/EngineInsQueryTool.java | 4 +--- 4 files changed, 30 insertions(+), 34 deletions(-) (limited to 'rulemgt/src/main') 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 { @@ -75,6 +75,8 @@ public class RuleActiveApp extends IOCApplication { } 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 { msinfo.setUrl("/api/holmes-rule-mgmt/v1"); msinfo.setProtocol("REST"); msinfo.setVisualRange("0|1"); - msinfo.setEnable_ssl(true); + msinfo.setEnable_ssl(HttpsUtils.isHttpsEnabled()); Set 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 { 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 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) { -- cgit 1.2.3-korg