Commit b178df2e by Jon Maron

ATLAS-36 listener port properties

parent 864cc5bc
...@@ -39,6 +39,9 @@ atlas.graph.index.search.elasticsearch.create.sleep=2000 ...@@ -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.hive_table=hive_table where name='%s'\, columns
atlas.lineage.hive.table.schema.query.Table=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 ######### ######### Security Properties #########
......
...@@ -40,6 +40,10 @@ public final class Main { ...@@ -40,6 +40,10 @@ public final class Main {
private static final String APP_PORT = "port"; private static final String APP_PORT = "port";
private static final String ATLAS_HOME = "atlas.home"; private static final String ATLAS_HOME = "atlas.home";
private static final String ATLAS_LOG_DIR = "atlas.log.dir"; 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. * Prevent users from constructing this.
...@@ -47,7 +51,7 @@ public final class Main { ...@@ -47,7 +51,7 @@ public final class Main {
private Main() { private Main() {
} }
private static CommandLine parseArgs(String[] args) throws ParseException { protected static CommandLine parseArgs(String[] args) throws ParseException {
Options options = new Options(); Options options = new Options();
Option opt; Option opt;
...@@ -74,7 +78,7 @@ public final class Main { ...@@ -74,7 +78,7 @@ public final class Main {
setApplicationHome(); setApplicationHome();
PropertiesConfiguration configuration = PropertiesUtil.getApplicationProperties(); PropertiesConfiguration configuration = PropertiesUtil.getApplicationProperties();
final String enableTLSFlag = configuration.getString("atlas.enableTLS"); 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); final boolean enableTLS = isTLSEnabled(enableTLSFlag, appPort);
configuration.setProperty("atlas.enableTLS", String.valueOf(enableTLS)); configuration.setProperty("atlas.enableTLS", String.valueOf(enableTLS));
...@@ -96,18 +100,30 @@ public final class Main { ...@@ -96,18 +100,30 @@ public final class Main {
return buildConfiguration.getString("project.version"); 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; final int appPort;
if (cmd.hasOption(APP_PORT)) { if (cmd.hasOption(APP_PORT)) {
appPort = Integer.valueOf(cmd.getOptionValue(APP_PORT)); appPort = Integer.valueOf(cmd.getOptionValue(APP_PORT));
} else { } else {
// default : atlas.enableTLS is true // default : atlas.enableTLS is true
appPort = StringUtils.isEmpty(enableTLSFlag) || enableTLSFlag.equals("true") ? 21443 : 21000; appPort = getPortValue(configuration, enableTLSFlag);
} }
return appPort; 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) { private static boolean isTLSEnabled(String enableTLSFlag, int appPort) {
return Boolean.valueOf(StringUtils.isEmpty(enableTLSFlag) ? return Boolean.valueOf(StringUtils.isEmpty(enableTLSFlag) ?
System.getProperty("atlas.enableTLS", (appPort % 1000) == 443 ? "true" : "false") : enableTLSFlag); System.getProperty("atlas.enableTLS", (appPort % 1000) == 443 ? "true" : "false") : enableTLSFlag);
......
/*
* 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");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment