-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Task Operations and shell commands for task logs #3393
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ public class TaskCommands implements CommandMarker { | |
|
||
private static final String LAUNCH = "task launch"; | ||
private static final String STOP = "task execution stop"; | ||
private static final String LOG = "task execution log"; | ||
|
||
// Destroy Role | ||
|
||
|
@@ -229,6 +230,20 @@ public String stop(@CliOption(key = { "", "ids" }, help = "the task execution id | |
return String.format("Request to stop the task execution with id(s): %s has been submitted", ids); | ||
} | ||
|
||
@CliCommand(value = LOG, help = "Retrieve task execution log") | ||
public String retrieveTaskExecutionLog(@CliOption(key = { "", "id" }, help = "the task execution id", mandatory = true) long id, | ||
@CliOption(key = { "", "platform" }, help = "the platform of the task execution", mandatory = false) String platform) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove key |
||
TaskExecutionResource taskExecutionResource = taskOperations().taskExecutionStatus(id); | ||
String result; | ||
if(platform != null) { | ||
result = taskOperations().taskExecutionLog(taskExecutionResource.getExternalExecutionId(), platform); | ||
} | ||
else { | ||
result = taskOperations().taskExecutionLog(taskExecutionResource.getExternalExecutionId()); | ||
} | ||
return result; | ||
} | ||
|
||
@CliCommand(value = DESTROY, help = "Destroy an existing task") | ||
public String destroy( | ||
@CliOption(key = { "", "name" }, help = "the name of the task to destroy", mandatory = true, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,10 @@ | |
*/ | ||
public class TaskCommandTemplate { | ||
|
||
private final static int WAIT_INTERVAL = 500; | ||
|
||
private final static int MAX_WAIT_TIME = 3000; | ||
|
||
private final JLineShellComponent shell; | ||
|
||
private List<String> tasks = new ArrayList<String>(); | ||
|
@@ -103,6 +107,65 @@ public long launchWithAlternateCTR(String taskName, String ctrAppName) { | |
return value; | ||
} | ||
|
||
/** | ||
* Launch a task and validate the result from shell on default platform. | ||
* | ||
* @param taskName the name of the task | ||
*/ | ||
public String getTaskExecutionLog(String taskName) throws Exception{ | ||
long id = launchTaskExecutionForLog(taskName); | ||
CommandResult cr = shell.executeCommand("task execution log --id " + id); | ||
assertTrue(cr.toString().contains("Starting TimestampTaskApplication")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking |
||
|
||
return cr.toString(); | ||
} | ||
|
||
/** | ||
* Launch a task with invalid platform. | ||
* | ||
* @param taskName the name of the task | ||
*/ | ||
public void getTaskExecutionLogInvalidPlatform(String taskName) throws Exception{ | ||
long id = launchTaskExecutionForLog(taskName); | ||
shell.executeCommand(String.format("task execution log --id %s --platform %s", id, "foo")); | ||
} | ||
|
||
/** | ||
* Launch a task with invalid task execution id | ||
|
||
*/ | ||
public void getTaskExecutionLogInvalidId() throws Exception{ | ||
CommandResult cr = shell.executeCommand(String.format("task execution log --id %s", 88)); | ||
} | ||
|
||
private long launchTaskExecutionForLog(String taskName) throws Exception{ | ||
// add the task name to the tasks list before assertion | ||
tasks.add(taskName); | ||
CommandResult cr = shell.executeCommand(String.format("task launch %s", taskName)); | ||
CommandResult idResult = shell.executeCommand("task execution list --name " + taskName); | ||
Table taskExecutionResult = (Table) idResult.getResult(); | ||
|
||
long id = (long) taskExecutionResult.getModel().getValue(1, 1); | ||
assertTrue(cr.toString().contains("with execution id " + id)); | ||
waitForDBToBePopulated(id); | ||
return id; | ||
} | ||
|
||
private void waitForDBToBePopulated(long id) throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why do we need this method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, I get this now. |
||
for (int waitTime = 0; waitTime <= MAX_WAIT_TIME; waitTime += WAIT_INTERVAL) { | ||
Thread.sleep(WAIT_INTERVAL); | ||
if (isEndTime(id)) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private boolean isEndTime(long id) { | ||
CommandResult cr = taskExecutionStatus(id); | ||
Table table = (Table) cr.getResult(); | ||
return (table.getModel().getValue(6, 1) != null); | ||
|
||
} | ||
/** | ||
* Stop a task execution. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove
to