Skip to content

Commit 56feecf

Browse files
authored
ATLAS-4958: checkstyle compliance updates - atlas-client module (#274)
1 parent 6ff6b62 commit 56feecf

File tree

17 files changed

+1274
-1085
lines changed

17 files changed

+1274
-1085
lines changed

client/client-v1/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727

2828
<artifactId>atlas-client-v1</artifactId>
2929

30+
<properties>
31+
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
32+
<checkstyle.skip>false</checkstyle.skip>
33+
</properties>
34+
3035
<dependencies>
3136
<dependency>
3237
<groupId>org.apache.atlas</groupId>

client/client-v1/src/main/java/org/apache/atlas/AtlasAdminClient.java

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* to you under the Apache License, Version 2.0 (the
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,7 +32,6 @@
3232

3333
import java.util.Arrays;
3434

35-
3635
/**
3736
* An application that allows users to run admin commands against an Atlas server.
3837
*
@@ -44,68 +43,68 @@
4443
* <li>-1/255: application error</li>
4544
*/
4645
public class AtlasAdminClient {
47-
4846
private static final Option STATUS = new Option("status", false, "Get the status of an atlas instance");
4947
private static final Option STATS = new Option("stats", false, "Get the metrics of an atlas instance");
5048
private static final Option CREDENTIALS = new Option("u", true, "Authorized atlas user credentials (<user>:<password>)");
5149

5250
private static final Options OPTIONS = new Options();
5351

5452
private static final int INVALID_OPTIONS_STATUS = 1;
55-
private static final int PROGRAM_ERROR_STATUS = -1;
56-
57-
static {
58-
OPTIONS.addOption(STATUS);
59-
OPTIONS.addOption(STATS);
60-
OPTIONS.addOption(CREDENTIALS);
61-
}
53+
private static final int PROGRAM_ERROR_STATUS = -1;
6254

6355
public static void main(String[] args) throws AtlasException, ParseException {
6456
AtlasAdminClient atlasAdminClient = new AtlasAdminClient();
65-
int result = atlasAdminClient.run(args);
57+
int result = atlasAdminClient.run(args);
58+
6659
System.exit(result);
6760
}
6861

6962
private int run(String[] args) throws AtlasException {
70-
CommandLine commandLine = parseCommandLineOptions(args);
71-
Configuration configuration = ApplicationProperties.get();
72-
String[] atlasServerUri = configuration.getStringArray(AtlasConstants.ATLAS_REST_ADDRESS_KEY);
63+
CommandLine commandLine = parseCommandLineOptions(args);
64+
Configuration configuration = ApplicationProperties.get();
65+
String[] atlasServerUri = configuration.getStringArray(AtlasConstants.ATLAS_REST_ADDRESS_KEY);
7366

7467
if (atlasServerUri == null || atlasServerUri.length == 0) {
75-
atlasServerUri = new String[] { AtlasConstants.DEFAULT_ATLAS_REST_ADDRESS };
68+
atlasServerUri = new String[] {AtlasConstants.DEFAULT_ATLAS_REST_ADDRESS};
7669
}
7770

7871
return handleCommand(commandLine, atlasServerUri);
7972
}
8073

8174
private int handleCommand(CommandLine commandLine, String[] atlasServerUri) throws AtlasException {
82-
AtlasClient atlasClient;
83-
8475
String[] providedUserPassword = getUserPassword(commandLine);
76+
int cmdStatus = PROGRAM_ERROR_STATUS;
8577

86-
int cmdStatus = PROGRAM_ERROR_STATUS;
8778
if (commandLine.hasOption(STATUS.getOpt())) {
88-
atlasClient = initAtlasClient(atlasServerUri, providedUserPassword); // Status is open API, no auth needed
79+
AtlasClient atlasClient = initAtlasClient(atlasServerUri, providedUserPassword); // Status is open API, no auth needed
80+
8981
try {
9082
System.out.println(atlasClient.getAdminStatus());
83+
9184
cmdStatus = 0;
9285
} catch (AtlasServiceException e) {
9386
System.err.println("Could not retrieve status of the server at " + Arrays.toString(atlasServerUri));
87+
9488
printStandardHttpErrorDetails(e);
9589
}
9690
} else if (commandLine.hasOption(STATS.getOpt())) {
97-
atlasClient = initAtlasClient(atlasServerUri, providedUserPassword); // Stats/metrics is open API, no auth needed
91+
AtlasClient atlasClient = initAtlasClient(atlasServerUri, providedUserPassword); // Stats/metrics is open API, no auth needed
92+
9893
try {
9994
AtlasMetrics atlasMetrics = atlasClient.getAtlasMetrics();
100-
String json = AtlasType.toJson(atlasMetrics);
95+
String json = AtlasType.toJson(atlasMetrics);
96+
10197
System.out.println(json);
98+
10299
cmdStatus = 0;
103100
} catch (AtlasServiceException e) {
104101
System.err.println("Could not retrieve metrics of the server at " + Arrays.toString(atlasServerUri));
102+
105103
printStandardHttpErrorDetails(e);
106104
}
107105
} else {
108106
System.err.println("Unsupported option. Refer to usage for valid options.");
107+
109108
printUsage();
110109
}
111110

@@ -118,18 +117,21 @@ private String[] getUserPassword(CommandLine commandLine) {
118117
// Parse the provided username password
119118
if (commandLine.hasOption(CREDENTIALS.getOpt())) {
120119
String value = commandLine.getOptionValue(CREDENTIALS.getOpt());
120+
121121
if (value != null) {
122122
basicAuthUsernamePassword = value.split(":");
123123
}
124124
}
125+
125126
if (basicAuthUsernamePassword == null || basicAuthUsernamePassword.length != 2) {
126127
System.err.println("Invalid credentials. Format: <user>:<password>");
127128
}
129+
128130
return basicAuthUsernamePassword;
129131
}
130132

131133
private AtlasClient initAtlasClient(final String[] atlasServerUri, final String[] providedUserNamePassword) throws AtlasException {
132-
AtlasClient atlasClient;
134+
final AtlasClient atlasClient;
133135

134136
if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
135137
if (providedUserNamePassword == null || providedUserNamePassword.length < 2) {
@@ -140,35 +142,46 @@ private AtlasClient initAtlasClient(final String[] atlasServerUri, final String[
140142
} else {
141143
atlasClient = new AtlasClient(atlasServerUri);
142144
}
145+
143146
return atlasClient;
144147
}
145148

146149
private void printStandardHttpErrorDetails(AtlasServiceException e) {
147150
System.err.println("Error details: ");
148-
System.err.println("HTTP Status: " + e.getStatus().getStatusCode() + ","
149-
+ e.getStatus().getReasonPhrase());
151+
System.err.println("HTTP Status: " + e.getStatus().getStatusCode() + "," + e.getStatus().getReasonPhrase());
150152
System.err.println("Exception message: " + e.getMessage());
151153
}
152154

153155
private CommandLine parseCommandLineOptions(String[] args) {
154156
if (args.length == 0) {
155157
printUsage();
156158
}
157-
CommandLineParser parser = new GnuParser();
158-
CommandLine commandLine = null;
159+
160+
CommandLineParser parser = new GnuParser();
161+
CommandLine commandLine = null;
162+
159163
try {
160164
commandLine = parser.parse(OPTIONS, args);
161165
} catch (ParseException e) {
162166
System.err.println("Could not parse command line options. " + e.getMessage());
167+
163168
printUsage();
164169
}
170+
165171
return commandLine;
166172
}
167173

168174
private void printUsage() {
169175
HelpFormatter helpFormatter = new HelpFormatter();
176+
170177
helpFormatter.printHelp("atlas_admin.py", OPTIONS);
178+
171179
System.exit(AtlasAdminClient.INVALID_OPTIONS_STATUS);
172180
}
173181

182+
static {
183+
OPTIONS.addOption(STATUS);
184+
OPTIONS.addOption(STATS);
185+
OPTIONS.addOption(CREDENTIALS);
186+
}
174187
}

0 commit comments

Comments
 (0)