HTTP/S Modifications 91/83791/1
authortangpeng <tang.peng5@zte.com.cn>
Sat, 30 Mar 2019 07:58:02 +0000 (07:58 +0000)
committertangpeng <tang.peng5@zte.com.cn>
Sat, 30 Mar 2019 07:58:02 +0000 (07:58 +0000)
Change-Id: Icabaf996d23297d0d5f16601645665a128616105
Issue-ID: HOLMES-203
Signed-off-by: tangpeng <tang.peng5@zte.com.cn>
engine-d-standalone/src/main/assembly/bin/run.sh
engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java
engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java
engine-d/src/test/java/org/onap/holmes/engine/EngineDActiveAppTest.java
pom.xml

index 0da0cf8..d036ceb 100644 (file)
@@ -69,13 +69,31 @@ if [ ! -z ${URL_JDBC} ] && [ `expr index $URL_JDBC :` != 0 ]; then
 fi
 echo DB_PORT=$DB_PORT
 
-KEY_PATH="$main_path/conf/holmes.keystore"
-KEY_PASSWORD="holmes"
+if [ -z ${ENABLE_ENCRYPT} ]; then
+    export ENABLE_ENCRYPT=true
+fi
+echo ENABLE_ENCRYPT=$ENABLE_ENCRYPT
 
+KEY_PATH="/home/holmes/conf/holmes.keystore"
+KEY_PASSWORD="holmes"
 #HTTPS Configurations
 sed -i "s|keyStorePath:.*|keyStorePath: $KEY_PATH|" "$main_path/conf/engine-d.yml"
 sed -i "s|keyStorePassword:.*|keyStorePassword: $KEY_PASSWORD|" "$main_path/conf/engine-d.yml"
 
+if [ ${ENABLE_ENCRYPT} == true ]; then
+    sed -i "s|type:\s*https\?$|type: https|" "$main_path/conf/engine-d.yml"
+    sed -i "s|#\?keyStorePath|keyStorePath|" "$main_path/conf/engine-d.yml"
+    sed -i "s|#\?keyStorePassword|keyStorePassword|" "$main_path/conf/engine-d.yml"
+    sed -i "s|#\?validateCerts|validateCerts|" "$main_path/conf/engine-d.yml"
+    sed -i "s|#\?validatePeers|validatePeers|" "$main_path/conf/engine-d.yml"
+else
+    sed -i 's|type:\s*https\?$|type: http|' "$main_path/conf/engine-d.yml"
+    sed -i "s|#\?keyStorePath|#keyStorePath|" "$main_path/conf/engine-d.yml"
+    sed -i "s|#\?keyStorePassword|#keyStorePassword|" "$main_path/conf/engine-d.yml"
+    sed -i "s|#\?validateCerts|#validateCerts|" "$main_path/conf/engine-d.yml"
+    sed -i "s|#\?validatePeers|#validatePeers|" "$main_path/conf/engine-d.yml"
+fi
+
 cat "$main_path/conf/engine-d.yml"
 
 ./bin/initDB.sh $JDBC_USERNAME $JDBC_PASSWORD $DB_NAME $DB_PORT "${URL_JDBC%:*}"
index 160fc38..245647d 100644 (file)
@@ -87,7 +87,7 @@ public class Subscriber {
         CloseableHttpClient closeableHttpClient = null;
         HttpGet httpGet = new HttpGet(url + "/" + consumerGroup + "/" + consumer + "?timeout=" + period);
         try {
-            closeableHttpClient = HttpsUtils.getHttpClient(timeout);
+            closeableHttpClient = HttpsUtils.getConditionalHttpsClient(timeout);
             HttpResponse httpResponse = HttpsUtils
                     .get(httpGet, new HashMap<>(), closeableHttpClient);
             response = HttpsUtils.extractResponseEntity(httpResponse);
index c045050..9417242 100644 (file)
 package org.onap.holmes.engine;
 
 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.engine.dcae.DcaeConfigurationPolling;
@@ -36,6 +28,14 @@ import org.onap.holmes.engine.resources.EngineResources;
 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 EngineDActiveApp extends IOCApplication<EngineDAppConfig> {
 
@@ -66,6 +66,8 @@ public class EngineDActiveApp extends IOCApplication<EngineDAppConfig> {
     }
 
     private MicroServiceInfo createMicroServiceInfo() {
+        String msbAddrTemplate = (HttpsUtils.isHttpsEnabled() ? "https" : "http")
+                + "://%s:%s/api/holmes-engine-mgmt/v1/healthcheck";
         String[] serviceAddrInfo = MicroServiceConfig.getMicroServiceIpAndPort();
         MicroServiceInfo msinfo = new MicroServiceInfo();
         msinfo.setServiceName("holmes-engine-mgmt");
@@ -73,13 +75,13 @@ public class EngineDActiveApp extends IOCApplication<EngineDAppConfig> {
         msinfo.setUrl("/api/holmes-engine-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("9102");
         node.setCheckType("HTTP");
-        node.setCheckUrl(String.format("https://%s:%s/api/holmes-engine-mgmt/v1/healthcheck", serviceAddrInfo[0], "9102"));
+        node.setCheckUrl(String.format(msbAddrTemplate, serviceAddrInfo[0], "9102"));
         node.setCheckTimeOut("60s");
         node.setCheckInterval("60s");
         nodes.add(node);
index 1a5795a..7c9b652 100644 (file)
@@ -22,16 +22,19 @@ import org.onap.holmes.common.config.MicroServiceConfig;
 import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;\r
 import org.onap.msb.sdk.discovery.entity.Node;\r
 import org.powermock.api.easymock.PowerMock;\r
+import org.powermock.core.classloader.annotations.PowerMockIgnore;\r
 import org.powermock.core.classloader.annotations.PrepareForTest;\r
 import org.powermock.modules.junit4.PowerMockRunner;\r
 import org.powermock.reflect.Whitebox;\r
 \r
+import static org.easymock.EasyMock.anyObject;\r
 import static org.hamcrest.CoreMatchers.equalTo;\r
 import static org.hamcrest.CoreMatchers.is;\r
 import static org.junit.Assert.assertThat;\r
 \r
 @PrepareForTest(MicroServiceConfig.class)\r
 @RunWith(PowerMockRunner.class)\r
+@PowerMockIgnore("javax.net.ssl.*")\r
 public class EngineDActiveAppTest {\r
 \r
     public static void main(String[] args) throws Exception {\r
@@ -48,6 +51,7 @@ public class EngineDActiveAppTest {
         serviceAddrInfo[1] = "80";\r
         EasyMock.expect(MicroServiceConfig.getMicroServiceIpAndPort()).andReturn(serviceAddrInfo);\r
         EasyMock.expectLastCall();\r
+        EasyMock.expect(MicroServiceConfig.getEnv(anyObject(String.class))).andReturn("true").times(2);\r
         PowerMock.replayAll();\r
 \r
         MicroServiceInfo msinfo = Whitebox.invokeMethod(engineDActiveApp,"createMicroServiceInfo");\r
diff --git a/pom.xml b/pom.xml
index 9782ae6..47d2448 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -93,7 +93,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>