super("get", "log");
}
@Override
public Object runCommand() throws PlatformLayerClientException {
PlatformLayerClient client = getPlatformLayerClient();
if (jobId.contains("/") && executionId == null) {
String[] tokens = jobId.split("/");
if (tokens.length == 2) {
jobId = tokens[0];
executionId = tokens[1];
}
}
List<JobLog> logs = Lists.newArrayList();
if (Strings.isNullOrEmpty(executionId)) {
JobExecutionList jobExecutions = client.listJobExecutions(jobId);
List<JobExecutionData> runs = jobExecutions.getRuns();
sort(runs);
// TODO: Remove limit (or iterate)
if (runs.size() > 10) {
runs = Lists.newArrayList(runs.subList(runs.size() - 10, runs.size()));
}
// TODO: Fix 1+N slowness...
for (JobExecutionData execution : runs) {
if (execution.getState() == JobState.PRESTART) {
continue;
}
String executionId = execution.getExecutionId();
try {
JobLog jobLog = client.getJobExecutionLog(jobId, executionId);
logs.add(jobLog);
} catch (PlatformLayerClientNotFoundException e) {
// TODO: Warn?
}
}
} else {
JobLog jobLog = client.getJobExecutionLog(jobId, executionId);
logs.add(jobLog);
}
return logs;
}