Displays the status of the job.
| 38 | * Displays the status of the job. |
| 39 | */ |
| 40 | @ThreadSafe |
| 41 | @PublicApi |
| 42 | public final class StatCommand extends AbstractFileSystemCommand { |
| 43 | private static final Logger LOG = LoggerFactory.getLogger(StatCommand.class); |
| 44 | private static final Option VERBOSE_OPTION = |
| 45 | Option.builder("v") |
| 46 | .required(false) |
| 47 | .hasArg(false) |
| 48 | .desc("show the status of every task") |
| 49 | .build(); |
| 50 | |
| 51 | /** |
| 52 | * Creates the job stat command. |
| 53 | * |
| 54 | * @param fsContext the Alluxio filesystem client |
| 55 | */ |
| 56 | public StatCommand(FileSystemContext fsContext) { |
| 57 | super(fsContext); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public String getCommandName() { |
| 62 | return "stat"; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public Options getOptions() { |
| 67 | return new Options().addOption(VERBOSE_OPTION); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public int run(CommandLine cl) throws AlluxioException, IOException { |
| 72 | long id = Long.parseLong(cl.getArgs()[0]); |
| 73 | try (CloseableResource<JobMasterClient> client = |
| 74 | JobContext.create(mFsContext.getClusterConf(), mFsContext.getClientContext().getUserState()) |
| 75 | .acquireMasterClientResource()) { |
| 76 | JobInfo info = client.get().getJobStatusDetailed(id); |
| 77 | System.out.print(formatOutput(cl, info)); |
| 78 | } catch (Exception e) { |
| 79 | LOG.error("Failed to get status of the job", e); |
| 80 | System.out.println("Failed to get status of the job " + id); |
| 81 | return -1; |
| 82 | } |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | private String formatOutput(CommandLine cl, JobInfo info) { |
| 87 | StringBuilder output = new StringBuilder(); |
| 88 | output.append("ID: ").append(info.getId()).append("\n"); |
| 89 | output.append("Name: ").append(info.getName()).append("\n"); |
| 90 | output.append("Description: "); |
| 91 | if (cl.hasOption("v")) { |
| 92 | output.append(info.getDescription()); |
| 93 | } else { |
| 94 | output.append(StringUtils.abbreviate(info.getDescription(), 200)); |
| 95 | } |
| 96 | output.append("\n"); |
| 97 | output.append("Status: ").append(info.getStatus()).append("\n"); |