From: tangpeng Date: Sat, 30 Mar 2019 07:58:02 +0000 (+0000) Subject: HTTP/S Modifications X-Git-Tag: 1.2.4~7^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=holmes%2Fengine-management.git;a=commitdiff_plain;h=3f438510b3aae2372b33d4d976cd10482a07492a HTTP/S Modifications Change-Id: Icabaf996d23297d0d5f16601645665a128616105 Issue-ID: HOLMES-203 Signed-off-by: tangpeng --- diff --git a/engine-d-standalone/src/main/assembly/bin/run.sh b/engine-d-standalone/src/main/assembly/bin/run.sh index 0da0cf8..d036ceb 100644 --- a/engine-d-standalone/src/main/assembly/bin/run.sh +++ b/engine-d-standalone/src/main/assembly/bin/run.sh @@ -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%:*}" diff --git a/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java b/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java index 160fc38..245647d 100644 --- a/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java +++ b/engine-d/src/main/java/org/onap/holmes/dsa/dmaappolling/Subscriber.java @@ -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); diff --git a/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java b/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java index c045050..9417242 100644 --- a/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java +++ b/engine-d/src/main/java/org/onap/holmes/engine/EngineDActiveApp.java @@ -16,19 +16,11 @@ 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 { @@ -66,6 +66,8 @@ public class EngineDActiveApp extends IOCApplication { } 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 { msinfo.setUrl("/api/holmes-engine-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("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); diff --git a/engine-d/src/test/java/org/onap/holmes/engine/EngineDActiveAppTest.java b/engine-d/src/test/java/org/onap/holmes/engine/EngineDActiveAppTest.java index 1a5795a..7c9b652 100644 --- a/engine-d/src/test/java/org/onap/holmes/engine/EngineDActiveAppTest.java +++ b/engine-d/src/test/java/org/onap/holmes/engine/EngineDActiveAppTest.java @@ -22,16 +22,19 @@ import org.onap.holmes.common.config.MicroServiceConfig; import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; import org.onap.msb.sdk.discovery.entity.Node; import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; +import static org.easymock.EasyMock.anyObject; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @PrepareForTest(MicroServiceConfig.class) @RunWith(PowerMockRunner.class) +@PowerMockIgnore("javax.net.ssl.*") public class EngineDActiveAppTest { public static void main(String[] args) throws Exception { @@ -48,6 +51,7 @@ public class EngineDActiveAppTest { serviceAddrInfo[1] = "80"; EasyMock.expect(MicroServiceConfig.getMicroServiceIpAndPort()).andReturn(serviceAddrInfo); EasyMock.expectLastCall(); + EasyMock.expect(MicroServiceConfig.getEnv(anyObject(String.class))).andReturn("true").times(2); PowerMock.replayAll(); MicroServiceInfo msinfo = Whitebox.invokeMethod(engineDActiveApp,"createMicroServiceInfo"); diff --git a/pom.xml b/pom.xml index 9782ae6..47d2448 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ org.onap.holmes.common holmes-actions - 1.2.7 + 1.2.8 io.dropwizard