in cli/src/main/java/org/apache/uniffle/cli/UniffleCLI.java [131:238]
public int run(String[] args) throws UniffleCliArgsException, JsonProcessingException {
final CommandLine cmd = parseCommandLineOptions(args, true);
if (args.length < 1) {
printUsage();
return EXIT_ERROR;
}
if (cmd.hasOption(help.getOpt())) {
printUsage();
return 0;
}
if (cmd.hasOption(uniffleClientCli.getOpt())) {
String cliArgs = cmd.getOptionValue(uniffleClientCli.getOpt());
System.out.println("uniffle-client-cli : " + cliArgs);
return EXIT_SUCCESS;
}
if (cmd.hasOption(uniffleAdminCli.getOpt())) {
String cliArgs = cmd.getOptionValue(uniffleAdminCli.getOpt());
System.out.println("uniffle-admin-cli : " + cliArgs);
return EXIT_SUCCESS;
}
if (cmd.hasOption(coordinatorHost.getOpt()) && cmd.hasOption(coordinatorPort.getOpt())) {
getUniffleRestClient(cmd);
// If we use application-cli
if (cmd.hasOption(uniffleApplicationCli.getLongOpt())) {
LOG.info("uniffle-client-cli : get applications");
// If we want to output json file
if (cmd.hasOption(uniffleOutFormat.getOpt())) {
// Get the OutFormat.
String outPutFormat = cmd.getOptionValue(uniffleOutFormat.getOpt()).trim();
if (StringUtils.isBlank(outPutFormat)) {
System.out.println("output format is not null.");
return EXIT_ERROR;
}
// We allow users to enter json\Json\JSON etc.
// If the user enters another format, we will prompt the user that we only support JSON.
if (!StringUtils.equalsAnyIgnoreCase(outPutFormat, "json")) {
System.out.println("The output currently supports only JSON format.");
return EXIT_ERROR;
}
String json = getApplicationsJson(cmd);
if (StringUtils.isBlank(json)) {
System.out.println("no output result.");
return EXIT_ERROR;
}
System.out.println("application: " + json);
if (cmd.hasOption(uniffleOutPutFile.getOpt())) {
// Get output file location.
String uniffleOutPutFile = cmd.getOptionValue(uniffleOutFormat.getOpt()).trim();
if (StringUtils.isBlank(uniffleOutPutFile)) {
System.out.println("The output file cannot be empty.");
return EXIT_ERROR;
}
try (FileOutputStream fos = new FileOutputStream(uniffleOutPutFile);
OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {
osw.write(json);
System.out.println(
"applications json data has been written to the file("
+ uniffleOutPutFile
+ ").");
} catch (IOException e) {
System.out.println(
"An error occurred while writing the applications json data to the file("
+ uniffleOutPutFile
+ ").");
return EXIT_ERROR;
}
}
return EXIT_SUCCESS;
}
try (PrintWriter writer =
new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8))) {
CLIContentUtils formattingCLIUtils =
new CLIContentUtils("Uniffle Applications").addHeaders(APPLICATIONS_HEADER);
List<Application> applications = getApplications(cmd);
if (applications != null) {
applications.forEach(
app ->
formattingCLIUtils.addLine(
app.getApplicationId(),
app.getUser(),
app.getRegistrationTime(),
app.getLastHeartBeatTime(),
app.getRemoteStoragePath()));
}
writer.print(formattingCLIUtils.render());
writer.flush();
return EXIT_SUCCESS;
}
}
}
return EXIT_ERROR;
}