Java Code Examples for org.springframework.shell.core.CommandResult#getResult()
The following examples show how to use
org.springframework.shell.core.CommandResult#getResult() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoRyaShellIT.java From rya with Apache License 2.0 | 6 votes |
@Test public void printConnectionDetails_connectedToMongo_noAuths() throws IOException { final JLineShellComponent shell = getTestShell(); // Connect to the Mongo instance. final String cmd = RyaConnectionCommands.CONNECT_MONGO_CMD + " " + "--hostname " + super.getMongoHostname() + " " + "--port " + super.getMongoPort(); shell.executeCommand(cmd); // Run the print connection details command. final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD ); final String msg = (String) printResult.getResult(); final String expected = "The shell is connected to an instance of MongoDB using the following parameters:\n" + " Hostname: " + super.getMongoHostname() + "\n" + " Port: " + super.getMongoPort() + "\n"; assertEquals(expected, msg); }
Example 2
Source File: StreamCommandTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
/** * Verify the stream is listed in stream list. * * @param streamName the name of the stream * @param definition definition of the stream */ public void verifyExists(String streamName, String definition, boolean deployed) { CommandResult cr = shell.executeCommand("stream list"); assertTrue("Failure. CommandResult = " + cr.toString(), cr.isSuccess()); Table table = (org.springframework.shell.table.Table) cr.getResult(); TableModel model = table.getModel(); Collection<String> statuses = deployed ? Arrays.asList(DeploymentStateResource.DEPLOYED.getDescription(), DeploymentStateResource.DEPLOYING.getDescription()) : Arrays.asList(DeploymentStateResource.UNDEPLOYED.getDescription()); for (int row = 0; row < model.getRowCount(); row++) { if (streamName.equals(model.getValue(row, 0)) && definition.replace("\\\\", "\\").equals(model.getValue(row, 2))) { // TODO (Tzolov) CLASSIC-MODE-REMOVAL To compute an aggregated state the Info returned by the mocked // TODO SkipperClient.info() (in SkipperStreamDeployer#getStreamDeploymentState) must have a // TODO valid PlatformStatus // && statuses.contains(model.getValue(row, 2))) { return; } } fail("Stream named " + streamName + " does not exist"); }
Example 3
Source File: TaskCommandTests.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
@Test public void testTaskExecutionList() { logger.info("Retrieve Task Execution List Test"); CommandResult cr = task().taskExecutionList(); assertTrue("task execution list command must be successful", cr.isSuccess()); Table table = (Table) cr.getResult(); assertEquals("Number of columns returned was not expected", 5, table.getModel().getColumnCount()); verifyTableValue(table, 0, 0, "Task Name"); verifyTableValue(table, 0, 1, "ID"); verifyTableValue(table, 0, 2, "Start Time"); verifyTableValue(table, 0, 3, "End Time"); verifyTableValue(table, 0, 4, "Exit Code"); verifyTableValue(table, 1, 0, TASK_NAME); verifyTableValue(table, 1, 1, TASK_EXECUTION_ID); verifyTableValue(table, 1, 2, startTime); verifyTableValue(table, 1, 3, endTime); verifyTableValue(table, 1, 4, EXIT_CODE); }
Example 4
Source File: TaskCommandTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Test public void testViewExecution() { logger.info("Retrieve Task Execution Status by Id"); CommandResult idResult = task().taskExecutionList(); Table result = (Table) idResult.getResult(); long value = (long) result.getModel().getValue(findRowForExecutionId(result, TASK_EXECUTION_ID), 1); logger.info("Looking up id " + value); CommandResult cr = task().taskExecutionStatus(value); assertTrue("task execution status command must be successful", cr.isSuccess()); Table table = (Table) cr.getResult(); assertEquals("Number of columns returned was not expected", 2, table.getModel().getColumnCount()); verifyTableValue(table, 0, 0, "Key "); verifyTableValue(table, 1, 0, "Id "); verifyTableValue(table, 2, 0, "Resource URL "); verifyTableValue(table, 3, 0, "Name "); verifyTableValue(table, 4, 0, "CLI Arguments "); verifyTableValue(table, 5, 0, "App Arguments "); verifyTableValue(table, 6, 0, "Deployment Properties "); verifyTableValue(table, 7, 0, "Job Execution Ids "); verifyTableValue(table, 8, 0, "Start Time "); verifyTableValue(table, 9, 0, "End Time "); verifyTableValue(table, 10, 0, "Exit Code "); verifyTableValue(table, 11, 0, "Exit Message "); verifyTableValue(table, 12, 0, "Error Message "); verifyTableValue(table, 13, 0, "External Execution Id "); verifyTableValue(table, 1, 1, TASK_EXECUTION_ID); verifyTableValue(table, 3, 1, TASK_NAME); verifyTableValue(table, 8, 1, startTime); verifyTableValue(table, 9, 1, endTime); verifyTableValue(table, 10, 1, EXIT_CODE); verifyTableValue(table, 11, 1, EXIT_MESSAGE); verifyTableValue(table, 12, 1, ERROR_MESSAGE); verifyTableValue(table, 13, 1, EXTERNAL_EXECUTION_ID); }
Example 5
Source File: MongoRyaShellIT.java From rya with Apache License 2.0 | 5 votes |
@Test public void printConnectionDetails_notConnected() { final JLineShellComponent shell = getTestShell(); // Run the print connection details command. final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD ); final String msg = (String) printResult.getResult(); final String expected = "The shell is not connected to anything."; assertEquals(expected, msg); }
Example 6
Source File: AccumuloRyaConnectionCommandsIT.java From rya with Apache License 2.0 | 5 votes |
@Test public void printConnectionDetails_connectedToAccumulo() throws IOException { final MiniAccumuloCluster cluster = getCluster(); final Bootstrap bootstrap = getTestBootstrap(); final JLineShellComponent shell = getTestShell(); // Mock the user entering the correct password. final ApplicationContext context = bootstrap.getApplicationContext(); final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class ); when(mockPrompt.getPassword()).thenReturn("password".toCharArray()); // Connect to the mini accumulo instance. final String cmd = RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " + "--username root " + "--instanceName " + cluster.getInstanceName() + " "+ "--zookeepers " + cluster.getZooKeepers(); shell.executeCommand(cmd); // Run the print connection details command. final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD ); final String msg = (String) printResult.getResult(); final String expected = "The shell is connected to an instance of Accumulo using the following parameters:\n" + " Username: root\n" + " Instance Name: " + cluster.getInstanceName() + "\n" + " Zookeepers: " + cluster.getZooKeepers(); assertEquals(expected, msg); }
Example 7
Source File: MongoRyaShellIT.java From rya with Apache License 2.0 | 5 votes |
@Test public void printConnectionDetails_connectedToMongo_auths() throws IOException { final Bootstrap bootstrap = getTestBootstrap(); final JLineShellComponent shell = getTestShell(); // Mock the user entering the correct password. final ApplicationContext context = bootstrap.getApplicationContext(); final PasswordPrompt mockPrompt = context.getBean( PasswordPrompt.class ); when(mockPrompt.getPassword()).thenReturn("password".toCharArray()); // Connect to the Mongo instance. final String cmd = RyaConnectionCommands.CONNECT_MONGO_CMD + " " + "--hostname " + super.getMongoHostname() + " " + "--port " + super.getMongoPort() + " " + "--username bob"; shell.executeCommand(cmd); // Run the print connection details command. final CommandResult printResult = shell.executeCommand( RyaConnectionCommands.PRINT_CONNECTION_DETAILS_CMD ); final String msg = (String) printResult.getResult(); final String expected = "The shell is connected to an instance of MongoDB using the following parameters:\n" + " Hostname: " + super.getMongoHostname() + "\n" + " Port: " + super.getMongoPort() + "\n" + " Username: bob\n"; assertEquals(expected, msg); }
Example 8
Source File: LensInterpreter.java From zeppelin with Apache License 2.0 | 5 votes |
private String formatResult(String st, CommandResult result) { if (result == null) { return "error in interpret, no result object returned"; } if (!result.isSuccess() || result.getResult() == null) { if (result.getException() != null) { return result.getException().getMessage(); //try describe cube (without cube name)- error is written as a warning, //but not returned to result object } else { return "error in interpret, unable to execute command"; } } StringBuilder sb = new StringBuilder(); for (Map.Entry<String, Pattern> entry : LENS_TABLE_FORMAT_REGEX.entrySet()) { if (entry.getValue().matcher(st.toLowerCase()).find()) { sb.append("%table " + entry.getKey() + " \n"); break; } } if (queryExecutePattern.matcher(st.toLowerCase()).find() && result.getResult().toString().contains(" rows process in (")) { sb.append("%table "); } if (sb.length() > 0) { return sb.append(result.getResult().toString()).toString(); } return result.getResult().toString(); //Lens sends error messages without setting result.isSuccess() = false. }
Example 9
Source File: TaskCommandTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Test public void testPlatformList() { CommandResult cr = task().taskPlatformList(); Table table = (Table) cr.getResult(); assertEquals("Number of columns returned was not expected", 3, table.getModel().getColumnCount()); assertEquals("First Row First Value should be: Platform Name", "Platform Name", table.getModel().getValue(0, 0)); assertEquals("First Row Second Value should be: Platform Type", "Platform Type", table.getModel().getValue(0, 1)); assertEquals("First Row Second Value should be: Description", "Description", table.getModel().getValue(0, 2)); assertEquals("Second Row First Value should be: default", "default", table.getModel().getValue(1, 0)); assertEquals("Second Row Second Value should be: Local", "Local", table.getModel().getValue(1, 1)); }
Example 10
Source File: TaskCommandTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Test public void testCurrentExecutions() { CommandResult cr = task().taskExecutionCurrent(); Table table = (Table) cr.getResult(); assertEquals("Number of columns returned was not expected", 4, table.getModel().getColumnCount()); verifyTableValue(table, 0, 0, "Platform Name"); verifyTableValue(table, 0, 1, "Platform Type"); verifyTableValue(table, 0, 2, "Execution Count"); verifyTableValue(table, 0, 3, "Maximum Executions"); verifyTableValue(table, 1, 0, "default"); verifyTableValue(table, 1, 1, "Local"); verifyTableValue(table, 1, 3, 20); }
Example 11
Source File: TaskCommandTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Test public void testTaskExecutionListByName() { logger.info("Retrieve Task Execution List By Name Test"); task().create("mytask", "timestamp"); CommandResult cr = task().taskExecutionListByName("mytask"); assertTrue("task execution list by name command must be successful", cr.isSuccess()); Table table = (Table) cr.getResult(); assertEquals("Number of columns returned was not expected", 5, table.getModel().getColumnCount()); verifyTableValue(table,0, 0, "Task Name"); verifyTableValue(table,0, 1, "ID"); verifyTableValue(table,0, 2, "Start Time"); verifyTableValue(table,0, 3, "End Time"); verifyTableValue(table,0, 4, "Exit Code"); }
Example 12
Source File: TaskScheduleCommandTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
public void listByTaskDefinition(String definitionName) { ScheduleInfo scheduleInfo = new ScheduleInfo(); scheduleInfo.setScheduleName("schedName"); scheduleInfo.setTaskDefinitionName("testDefinition"); scheduleInfo.setScheduleProperties(Collections.EMPTY_MAP); when(schedule.list(definitionName, null)).thenReturn(Arrays.asList(scheduleInfo)); String wholeCommand = String.format("task schedule list --definitionName %s", definitionName); CommandResult cr = dataFlowShell.executeCommand(wholeCommand); Table table = (Table) cr.getResult(); assertEquals("schedName", table.getModel().getValue(1, 0)); }
Example 13
Source File: TaskScheduleCommandTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
public void list() { ScheduleInfo scheduleInfo = new ScheduleInfo(); scheduleInfo.setScheduleName("schedName"); scheduleInfo.setTaskDefinitionName("testDefinition"); scheduleInfo.setScheduleProperties(Collections.EMPTY_MAP); when(schedule.listForPlatform(null)).thenReturn(Arrays.asList(scheduleInfo)); String wholeCommand = "task schedule list"; CommandResult cr = dataFlowShell.executeCommand(wholeCommand); Table table = (Table) cr.getResult(); assertEquals("schedName", table.getModel().getValue(1, 0)); }
Example 14
Source File: TaskCommandTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Verify the task is listed in task list. * * @param taskName the name of the task * @param definition definition of the task */ public void verifyExists(String taskName, String definition) { CommandResult cr = shell.executeCommand("task list"); assertTrue("Failure. CommandResult = " + cr.toString(), cr.isSuccess()); Table table = (Table) cr.getResult(); TableModel model = table.getModel(); for (int row = 0; row < model.getRowCount(); row++) { if (taskName.equals(model.getValue(row, 0)) && definition.replace("\\\\", "\\").equals(model.getValue(row, 1))) { return; } } fail("Task named " + taskName + " was not created"); }
Example 15
Source File: TaskCommandTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
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; }
Example 16
Source File: TaskCommandTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Launch a task and validate the result from shell. * * @param taskName the name of the task * @param ctrAppName the app to use when launching a ComposedTask if default is not wanted. */ public long launchWithAlternateCTR(String taskName, String ctrAppName) { // add the task name to the tasks list before assertion tasks.add(taskName); CommandResult cr = shell.executeCommand(String.format("task launch %s --composedTaskRunnerName %s", taskName, ctrAppName)); CommandResult idResult = shell.executeCommand("task execution list --name " + taskName); Table result = (Table) idResult.getResult(); long value = (long) result.getModel().getValue(1, 1); assertTrue(cr.toString().contains("with execution id " + value)); return value; }
Example 17
Source File: TaskCommandTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Launch a task and validate the result from shell. * * @param taskName the name of the task */ public long launch(String taskName) { // add the task name to the tasks list before assertion tasks.add(taskName); CommandResult cr = shell.executeCommand("task launch " + taskName); CommandResult idResult = shell.executeCommand("task execution list --name " + taskName); Table result = (Table) idResult.getResult(); long value = (long) result.getModel().getValue(1, 1); assertTrue(cr.toString().contains("with execution id " + value)); return value; }
Example 18
Source File: JobCommandTests.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
private Table getTable(CommandResult cr) { assertTrue("Command must be successful", cr.isSuccess()); return (Table) cr.getResult(); }
Example 19
Source File: LensInterpreter.java From zeppelin with Apache License 2.0 | 4 votes |
@Override public InterpreterResult interpret(String input, InterpreterContext context) { if (input == null || input.length() == 0) { return new InterpreterResult(Code.ERROR, "no command submitted"); } String st = input.replaceAll("\\n", " "); LOGGER.info("LensInterpreter command: " + st); Bootstrap bs = createBootstrap(); JLineShell shell = getJLineShell(bs); CommandResult res; LensClient lensClient = null; String qh = null; if (st.trim().startsWith("help")) { return handleHelp(shell, st); } try { lensClient = createAndSetLensClient(bs); clientMap.put(lensClient, true); String lensCommand = modifyQueryStatement(st); LOGGER.info("executing command : " + lensCommand); res = shell.executeCommand(lensCommand); if (!lensCommand.equals(st) && res != null && res.getResult() != null && res.getResult().toString().trim().matches("[a-z0-9-]+")) { // setup query progress tracking qh = res.getResult().toString(); paraToQH.put(context.getParagraphId(), new ExecutionDetail(qh, lensClient, shell)); String getResultsCmd = "query results --async false " + qh; LOGGER.info("executing query results command : " + context.getParagraphId() + " : " + getResultsCmd); res = shell.executeCommand(getResultsCmd); paraToQH.remove(context.getParagraphId()); } } catch (Exception ex) { LOGGER.error("error in interpret", ex); return new InterpreterResult(Code.ERROR, ex.getMessage()); } finally { if (shell != null) { closeShell(shell); } if (lensClient != null) { closeLensClient(lensClient); clientMap.remove(lensClient); } if (qh != null) { paraToQH.remove(context.getParagraphId()); } } return new InterpreterResult(Code.SUCCESS, formatResult(st, res)); }
Example 20
Source File: TaskCommandTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
private boolean isEndTime(long id) { CommandResult cr = taskExecutionStatus(id); Table table = (Table) cr.getResult(); return (table.getModel().getValue(6, 1) != null); }