Skip to content

Commit

Permalink
ATLAS-4969: checkstyle compliance updates - atlas-webapp module (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
mneethiraj authored Feb 4, 2025
1 parent 70c69b1 commit c5ff86d
Show file tree
Hide file tree
Showing 153 changed files with 9,313 additions and 8,857 deletions.
1 change: 1 addition & 0 deletions dev-support/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<suppress files="[\\/]surefire-reports[\\/]" checks="[a-zA-Z0-9]*"/>
<suppress files="AtlasClient.java" checks="TypeName"/>
<suppress files="AtlasClientV2.java" checks="TypeName"/>
<suppress files="AtlasDebugMetricsSource.java" checks="MemberName"/>
<suppress files="AtlasGraph.java" checks="MethodName"/>
<suppress files="AtlasGraphTraversalSource.java" checks="MethodName"/>
<suppress files="DeleteHandlerV1.java" checks="MethodName"/>
Expand Down
2 changes: 2 additions & 0 deletions webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<description>Apache Atlas Web Application</description>

<properties>
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
<checkstyle.skip>false</checkstyle.skip>
<debug.jetty.daemon>true</debug.jetty.daemon>
<logback.configurationFile>file:///${project.build.directory}/../../distro/src/conf/atlas-logback.xml</logback.configurationFile>
<projectBaseDir>${project.basedir}/..</projectBaseDir>
Expand Down
161 changes: 85 additions & 76 deletions webapp/src/main/java/org/apache/atlas/Atlas.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* 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
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.
Expand Down Expand Up @@ -44,118 +44,92 @@
*/
public final class Atlas {
private static final Logger LOG = LoggerFactory.getLogger(Atlas.class);
private static final String APP_PATH = "app";
private static final String APP_PORT = "port";
private static final String ATLAS_HOME = "atlas.home";
private static final String ATLAS_DATA = "atlas.data";
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";


private static EmbeddedServer server;
public static final String ATLAS_SERVER_HTTPS_PORT = "atlas.server.https.port";
public static final String ATLAS_SERVER_HTTP_PORT = "atlas.server.http.port";

static {
ShutdownHookManager.get().addShutdownHook(new Thread() {
@Override
public void run() {
try {
LOG.info("==> Shutdown of Atlas");

shutdown();
} catch (Exception e) {
LOG.error("Failed to shutdown", e);
} finally {
LOG.info("<== Shutdown of Atlas");
}
}
}, AtlasConstants.ATLAS_SHUTDOWN_HOOK_PRIORITY);
}
private static final String APP_PATH = "app";
private static final String APP_PORT = "port";
private static final String ATLAS_HOME = "atlas.home";
private static final String ATLAS_DATA = "atlas.data";
private static final String ATLAS_LOG_DIR = "atlas.log.dir";

private static void shutdown() {
server.stop();
}
private static EmbeddedServer server;

/**
* Prevent users from constructing this.
*/
private Atlas() {
}

protected static CommandLine parseArgs(String[] args) throws ParseException {
Options options = new Options();
Option opt;

opt = new Option(APP_PATH, true, "Application Path");
opt.setRequired(false);
options.addOption(opt);

opt = new Option(APP_PORT, true, "Application Port");
opt.setRequired(false);
options.addOption(opt);

return new GnuParser().parse(options, args);
}

public static void main(String[] args) throws Exception {
CommandLine cmd = parseArgs(args);
CommandLine cmd = parseArgs(args);
PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
String appPath = "webapp/target/atlas-webapp-" + getProjectVersion(buildConfiguration);
String appPath = "webapp/target/atlas-webapp-" + getProjectVersion(buildConfiguration);

if (cmd.hasOption(APP_PATH)) {
appPath = cmd.getOptionValue(APP_PATH);
}

setApplicationHome();

Configuration configuration = ApplicationProperties.get();
final String enableTLSFlag = configuration.getString(SecurityProperties.TLS_ENABLED);
final String appHost = configuration.getString(SecurityProperties.BIND_ADDRESS, EmbeddedServer.ATLAS_DEFAULT_BIND_ADDRESS);
final String enableTLSFlag = configuration.getString(SecurityProperties.TLS_ENABLED);
final String appHost = configuration.getString(SecurityProperties.BIND_ADDRESS, EmbeddedServer.ATLAS_DEFAULT_BIND_ADDRESS);

if (!isLocalAddress(InetAddress.getByName(appHost))) {
String msg =
"Failed to start Atlas server. Address " + appHost
+ " does not belong to this host. Correct configuration parameter: "
+ SecurityProperties.BIND_ADDRESS;
String msg = "Failed to start Atlas server. Address " + appHost + " does not belong to this host. Correct configuration parameter: " + SecurityProperties.BIND_ADDRESS;

LOG.error(msg);

throw new IOException(msg);
}

final int appPort = getApplicationPort(cmd, enableTLSFlag, configuration);

System.setProperty(AtlasConstants.SYSTEM_PROPERTY_APP_PORT, String.valueOf(appPort));

final boolean enableTLS = isTLSEnabled(enableTLSFlag, appPort);

configuration.setProperty(SecurityProperties.TLS_ENABLED, String.valueOf(enableTLS));

showStartupInfo(buildConfiguration, enableTLS, appPort);

server = EmbeddedServer.newServer(appHost, appPort, appPath, enableTLS);

installLogBridge();

server.start();
}

private static void setApplicationHome() {
if (System.getProperty(ATLAS_HOME) == null) {
System.setProperty(ATLAS_HOME, "target");
}
if (System.getProperty(ATLAS_DATA) == null) {
System.setProperty(ATLAS_DATA, "target/data");
}
if (System.getProperty(ATLAS_LOG_DIR) == null) {
System.setProperty(ATLAS_LOG_DIR, "target/logs");
}
}

public static String getProjectVersion(PropertiesConfiguration buildConfiguration) {
return buildConfiguration.getString("project.version");
}

static CommandLine parseArgs(String[] args) throws ParseException {
Options options = new Options();
Option opt;

opt = new Option(APP_PATH, true, "Application Path");

opt.setRequired(false);
options.addOption(opt);

opt = new Option(APP_PORT, true, "Application Port");

opt.setRequired(false);
options.addOption(opt);

return new GnuParser().parse(options, args);
}

static int getApplicationPort(CommandLine cmd, String enableTLSFlag, Configuration configuration) {
String optionValue = cmd.hasOption(APP_PORT) ? cmd.getOptionValue(APP_PORT) : null;

final int appPort;

if (StringUtils.isNotEmpty(optionValue)) {
appPort = Integer.valueOf(optionValue);
appPort = Integer.parseInt(optionValue);
} else {
// default : atlas.enableTLS is true
appPort = getPortValue(configuration, enableTLSFlag);
Expand All @@ -164,19 +138,34 @@ static int getApplicationPort(CommandLine cmd, String enableTLSFlag, Configurati
return appPort;
}

private static void shutdown() {
server.stop();
}

private static void setApplicationHome() {
if (System.getProperty(ATLAS_HOME) == null) {
System.setProperty(ATLAS_HOME, "target");
}

if (System.getProperty(ATLAS_DATA) == null) {
System.setProperty(ATLAS_DATA, "target/data");
}

if (System.getProperty(ATLAS_LOG_DIR) == null) {
System.setProperty(ATLAS_LOG_DIR, "target/logs");
}
}

private static int getPortValue(Configuration 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);
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(SecurityProperties.TLS_ENABLED, (appPort % 1000) == 443 ? "true" : "false") : enableTLSFlag);
return Boolean.parseBoolean(StringUtils.isEmpty(enableTLSFlag) ? System.getProperty(SecurityProperties.TLS_ENABLED, (appPort % 1000) == 443 ? "true" : "false") : enableTLSFlag);
}

private static boolean isLocalAddress(InetAddress addr) {
Expand All @@ -188,31 +177,38 @@ private static boolean isLocalAddress(InetAddress addr) {
try {
local = NetworkInterface.getByInetAddress(addr) != null;
} catch (SocketException e) {
local = false;
// ignore
}
}

return local;
}

private static void showStartupInfo(PropertiesConfiguration buildConfiguration, boolean enableTLS, int appPort) {
StringBuilder buffer = new StringBuilder();

buffer.append("\n############################################");
buffer.append("############################################");
buffer.append("\n Atlas Server (STARTUP)");
buffer.append("\n");

try {
final Iterator<String> keys = buildConfiguration.getKeys();

while (keys.hasNext()) {
String key = keys.next();
buffer.append('\n').append('\t').append(key).
append(":\t").append(buildConfiguration.getProperty(key));

buffer.append('\n').append('\t').append(key).append(":\t").append(buildConfiguration.getProperty(key));
}
} catch (Throwable e) {
buffer.append("*** Unable to get build info ***");
}

buffer.append("\n############################################");
buffer.append("############################################");

LOG.info(buffer.toString());

LOG.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
LOG.info("Server starting with TLS ? {} on port {}", enableTLS, appPort);
LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
Expand All @@ -227,4 +223,17 @@ private static void installLogBridge() {
SLF4JBridgeHandler.install();
}

static {
ShutdownHookManager.get().addShutdownHook(new Thread(() -> {
try {
LOG.info("==> Shutdown of Atlas");

shutdown();
} catch (Exception e) {
LOG.error("Failed to shutdown", e);
} finally {
LOG.info("<== Shutdown of Atlas");
}
}), AtlasConstants.ATLAS_SHUTDOWN_HOOK_PRIORITY);
}
}
16 changes: 8 additions & 8 deletions webapp/src/main/java/org/apache/atlas/LocalServletRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpUpgradeHandler;
import javax.servlet.http.Part;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
import java.util.Collection;
import java.util.Enumeration;
Expand Down Expand Up @@ -193,22 +193,22 @@ public void login(String username, String password) throws ServletException {
}

@Override
public void logout() throws ServletException {
public void logout() {
throw new IllegalStateException("Not supported");
}

@Override
public Collection<Part> getParts() throws IOException, ServletException {
public Collection<Part> getParts() {
throw new IllegalStateException("Not supported");
}

@Override
public Part getPart(String name) throws IOException, ServletException {
public Part getPart(String name) {
throw new IllegalStateException("Not supported");
}

@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) {
throw new IllegalStateException("Not supported");
}

Expand All @@ -228,7 +228,7 @@ public String getCharacterEncoding() {
}

@Override
public void setCharacterEncoding(String env) throws UnsupportedEncodingException {
public void setCharacterEncoding(String env) {
throw new IllegalStateException("Not supported");
}

Expand All @@ -248,7 +248,7 @@ public String getContentType() {
}

@Override
public ServletInputStream getInputStream() throws IOException {
public ServletInputStream getInputStream() {
throw new IllegalStateException("Not supported");
}

Expand Down Expand Up @@ -293,7 +293,7 @@ public int getServerPort() {
}

@Override
public BufferedReader getReader() throws IOException {
public BufferedReader getReader() {
throw new IllegalStateException("Not supported");
}

Expand Down
Loading

0 comments on commit c5ff86d

Please sign in to comment.