Repository: incubator-atlas Updated Branches: refs/heads/master 864cc5bc3 -> b178df2ea
ATLAS-36 listener port properties Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/b178df2e Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/b178df2e Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/b178df2e Branch: refs/heads/master Commit: b178df2ea87ff83997e6eb002b3e4d1ecbe8e8c7 Parents: 864cc5b Author: Jon Maron <[email protected]> Authored: Tue Jul 14 13:03:55 2015 -0400 Committer: Jon Maron <[email protected]> Committed: Tue Jul 14 13:03:55 2015 -0400 ---------------------------------------------------------------------- src/conf/application.properties | 3 ++ webapp/src/main/java/org/apache/atlas/Main.java | 24 +++++++-- .../src/test/java/org/apache/atlas/MainIT.java | 55 ++++++++++++++++++++ 3 files changed, 78 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b178df2e/src/conf/application.properties ---------------------------------------------------------------------- diff --git a/src/conf/application.properties b/src/conf/application.properties index 6c4c7d2..c6b16cc 100755 --- a/src/conf/application.properties +++ b/src/conf/application.properties @@ -39,6 +39,9 @@ atlas.graph.index.search.elasticsearch.create.sleep=2000 atlas.lineage.hive.table.schema.query.hive_table=hive_table where name='%s'\, columns atlas.lineage.hive.table.schema.query.Table=Table where name='%s'\, columns +## Server port configuration +#atlas.server.http.port=21000 +#atlas.server.https.port=21443 ######### Security Properties ######### http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b178df2e/webapp/src/main/java/org/apache/atlas/Main.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/Main.java b/webapp/src/main/java/org/apache/atlas/Main.java index 1dd17b4..6cdeca8 100755 --- a/webapp/src/main/java/org/apache/atlas/Main.java +++ b/webapp/src/main/java/org/apache/atlas/Main.java @@ -40,6 +40,10 @@ public final class Main { private static final String APP_PORT = "port"; private static final String ATLAS_HOME = "atlas.home"; private static final String ATLAS_LOG_DIR = "atlas.log.dir"; + public static final String ATLAS_SERVER_HTTPS_PORT = + "atlas.server.https.port"; + public static final String ATLAS_SERVER_HTTP_PORT = + "atlas.server.http.port"; /** * Prevent users from constructing this. @@ -47,7 +51,7 @@ public final class Main { private Main() { } - private static CommandLine parseArgs(String[] args) throws ParseException { + protected static CommandLine parseArgs(String[] args) throws ParseException { Options options = new Options(); Option opt; @@ -74,7 +78,7 @@ public final class Main { setApplicationHome(); PropertiesConfiguration configuration = PropertiesUtil.getApplicationProperties(); final String enableTLSFlag = configuration.getString("atlas.enableTLS"); - final int appPort = getApplicationPort(cmd, enableTLSFlag); + final int appPort = getApplicationPort(cmd, enableTLSFlag, configuration); final boolean enableTLS = isTLSEnabled(enableTLSFlag, appPort); configuration.setProperty("atlas.enableTLS", String.valueOf(enableTLS)); @@ -96,18 +100,30 @@ public final class Main { return buildConfiguration.getString("project.version"); } - private static int getApplicationPort(CommandLine cmd, String enableTLSFlag) { + static int getApplicationPort(CommandLine cmd, + String enableTLSFlag, + PropertiesConfiguration configuration) { final int appPort; if (cmd.hasOption(APP_PORT)) { appPort = Integer.valueOf(cmd.getOptionValue(APP_PORT)); } else { // default : atlas.enableTLS is true - appPort = StringUtils.isEmpty(enableTLSFlag) || enableTLSFlag.equals("true") ? 21443 : 21000; + appPort = getPortValue(configuration, enableTLSFlag); } return appPort; } + private static int getPortValue(PropertiesConfiguration configuration, String enableTLSFlag) { + int appPort; + + assert configuration != null; + appPort = StringUtils.isEmpty(enableTLSFlag) || enableTLSFlag.equals("true") ? + configuration.getInt(ATLAS_SERVER_HTTPS_PORT, 21443) : + configuration.getInt(ATLAS_SERVER_HTTP_PORT, 21000); + return appPort; + } + private static boolean isTLSEnabled(String enableTLSFlag, int appPort) { return Boolean.valueOf(StringUtils.isEmpty(enableTLSFlag) ? System.getProperty("atlas.enableTLS", (appPort % 1000) == 443 ? "true" : "false") : enableTLSFlag); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/b178df2e/webapp/src/test/java/org/apache/atlas/MainIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/MainIT.java b/webapp/src/test/java/org/apache/atlas/MainIT.java new file mode 100644 index 0000000..19cc4b7 --- /dev/null +++ b/webapp/src/test/java/org/apache/atlas/MainIT.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.atlas; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * + */ +public class MainIT { + + @Test + public void testPortSelection () throws Exception { + PropertiesConfiguration config = new PropertiesConfiguration(); + // test ports via config + config.setProperty(Main.ATLAS_SERVER_HTTP_PORT, 21001); + config.setProperty(Main.ATLAS_SERVER_HTTPS_PORT, 22443); + int port = Main.getApplicationPort(Main.parseArgs(new String[] {}), "false", + config ); + Assert.assertEquals(21001, port, "wrong http port"); + port = Main.getApplicationPort(Main.parseArgs(new String[] {}), "true", + config ); + Assert.assertEquals(22443, port, "wrong https port"); + // test defaults + port = Main.getApplicationPort(Main.parseArgs(new String[] {}), "false", + new PropertiesConfiguration() ); + Assert.assertEquals(21000, port, "wrong http port"); + port = Main.getApplicationPort(Main.parseArgs(new String[] {}), "true", + new PropertiesConfiguration() ); + Assert.assertEquals(21443, port, "wrong https port"); + // test command line override + CommandLine commandLine = Main.parseArgs(new String[] {"--port", "22000"}); + port = Main.getApplicationPort(commandLine, "true", config); + Assert.assertEquals(22000, port, "wrong https port"); + port = Main.getApplicationPort(commandLine, "false", config); + Assert.assertEquals(22000, port, "wrong https port"); + } +}
