org.springframework.shell.table.TableModel Java Examples
The following examples show how to use
org.springframework.shell.table.TableModel.
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: ReleaseCommands.java From spring-cloud-skipper with Apache License 2.0 | 6 votes |
@ShellMethod(key = "release list", value = "List the latest version of releases with status of deployed or failed.") public Table list( @ShellOption(help = "wildcard expression to search by release name", defaultValue = ShellOption.NULL) String releaseName) { List<Release> releases = this.skipperClient.list(releaseName); LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("name", "Name"); headers.put("version", "Version"); headers.put("info.lastDeployed", "Last updated"); headers.put("info.status.statusCode", "Status"); headers.put("pkg.metadata.name", "Package Name"); headers.put("pkg.metadata.version", "Package Version"); headers.put("platformName", "Platform Name"); headers.put("info.status.platformStatusPrettyPrint", "Platform Status"); TableModel model = new BeanListTableModel<>(releases, headers); TableBuilder tableBuilder = new TableBuilder(model); TableUtils.applyStyle(tableBuilder); return tableBuilder.build(); }
Example #2
Source File: RuntimeCommandsTests.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
@Test public void testStatusWithoutSummary() { Collection<AppStatusResource> data = new ArrayList<>(); data.add(appStatusResource1); data.add(appStatusResource2); PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(data.size(), 1, data.size(), 1); PagedModel<AppStatusResource> result = new PagedModel<>(data, metadata); when(runtimeOperations.status()).thenReturn(result); Object[][] expected = new String[][] { { "1", "deployed", "2" }, { "10", "deployed" }, { "20", "deployed" }, { "2", "undeployed", "0" } }; TableModel model = runtimeCommands.list(false, null).getModel(); for (int row = 0; row < expected.length; row++) { for (int col = 0; col < expected[row].length; col++) { assertThat(String.valueOf(model.getValue(row + 1, col)), Matchers.is(expected[row][col])); } } }
Example #3
Source File: RuntimeCommandsTests.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
@Test public void testStatusWithSummary() { Collection<AppStatusResource> data = new ArrayList<>(); data.add(appStatusResource1); data.add(appStatusResource2); data.add(appStatusResource3); PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(data.size(), 1, data.size(), 1); PagedModel<AppStatusResource> result = new PagedModel<>(data, metadata); when(runtimeOperations.status()).thenReturn(result); Object[][] expected = new String[][] { { "1", "deployed", "2" }, { "2", "undeployed", "0" }, { "3", "failed", "0" } }; TableModel model = runtimeCommands.list(true, null).getModel(); for (int row = 0; row < expected.length; row++) { for (int col = 0; col < expected[row].length; col++) { assertThat(String.valueOf(model.getValue(row + 1, col)), Matchers.is(expected[row][col])); } } }
Example #4
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 #5
Source File: StreamCommands.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
@CliCommand(value = STREAM_HISTORY, help = "Get history for the stream deployed using Skipper") public Table history( @CliOption(key = { "", "name" }, help = "the name of the stream", mandatory = true, optionContext = "existing-stream " + "disable-string-converter") String name) { Collection<Release> releases = streamOperations().history(name); LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("version", "Version"); headers.put("info.lastDeployed", "Last updated"); headers.put("info.status.statusCode", "Status"); headers.put("pkg.metadata.name", "Package Name"); headers.put("pkg.metadata.version", "Package Version"); headers.put("info.description", "Description"); TableModel model = new BeanListTableModel<>(releases, headers); TableBuilder tableBuilder = new TableBuilder(model); DataFlowTables.applyStyle(tableBuilder); return tableBuilder.build(); }
Example #6
Source File: RuntimeCommandsTests.java From spring-cloud-dashboard with Apache License 2.0 | 6 votes |
@Test public void testStatusByModuleId() { when(runtimeOperations.status("1")).thenReturn(appStatusResource1); Object[][] expected = new String[][] { {"1", "deployed", "2"}, {"10", "deployed"}, {"20", "deployed"} }; TableModel model = runtimeCommands.list(false, new String[] {"1"}).getModel(); assertTrue(model.getRowCount() == 4); for (int row = 0; row < expected.length; row++) { for (int col = 0; col < expected[row].length; col++) { assertThat(String.valueOf(model.getValue(row + 1, col)), Matchers.is(expected[row][col])); } } }
Example #7
Source File: RuntimeCommandsTests.java From spring-cloud-dashboard with Apache License 2.0 | 6 votes |
@Test public void testStatusWithoutSummary() { Collection<AppStatusResource> data = new ArrayList<>(); data.add(appStatusResource1); data.add(appStatusResource2); PagedResources.PageMetadata metadata = new PagedResources.PageMetadata(data.size(), 1, data.size(), 1); PagedResources<AppStatusResource> result = new PagedResources<>(data, metadata); when(runtimeOperations.status()).thenReturn(result); Object[][] expected = new String[][] { {"1", "deployed", "2"}, {"10", "deployed"}, {"20", "deployed"}, {"2", "undeployed", "0"} }; TableModel model = runtimeCommands.list(false, null).getModel(); for (int row = 0; row < expected.length; row++) { for (int col = 0; col < expected[row].length; col++) { assertThat(String.valueOf(model.getValue(row + 1, col)), Matchers.is(expected[row][col])); } } }
Example #8
Source File: RuntimeCommandsTests.java From spring-cloud-dashboard with Apache License 2.0 | 6 votes |
@Test public void testStatusWithSummary() { Collection<AppStatusResource> data = new ArrayList<>(); data.add(appStatusResource1); data.add(appStatusResource2); data.add(appStatusResource3); PagedResources.PageMetadata metadata = new PagedResources.PageMetadata(data.size(), 1, data.size(), 1); PagedResources<AppStatusResource> result = new PagedResources<>(data, metadata); when(runtimeOperations.status()).thenReturn(result); Object[][] expected = new String[][] { {"1", "deployed", "2"}, {"2", "undeployed", "0"}, {"3", "failed", "0"} }; TableModel model = runtimeCommands.list(true, null).getModel(); for (int row = 0; row < expected.length; row++) { for (int col = 0; col < expected[row].length; col++) { assertThat(String.valueOf(model.getValue(row + 1, col)), Matchers.is(expected[row][col])); } } }
Example #9
Source File: ReleaseCommands.java From spring-cloud-skipper with Apache License 2.0 | 6 votes |
@ShellMethod(key = "release history", value = "List the history of versions for a given release.") public Table history( @ShellOption(help = "wildcard expression to search by release name") @NotNull String releaseName) { Collection<Release> releases; releases = this.skipperClient.history(releaseName); LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("version", "Version"); headers.put("info.lastDeployed", "Last updated"); headers.put("info.status.statusCode", "Status"); headers.put("pkg.metadata.name", "Package Name"); headers.put("pkg.metadata.version", "Package Version"); headers.put("info.description", "Description"); TableModel model = new BeanListTableModel<>(releases, headers); TableBuilder tableBuilder = new TableBuilder(model); TableUtils.applyStyle(tableBuilder); return tableBuilder.build(); }
Example #10
Source File: AppRegistryCommandsTests.java From spring-cloud-dashboard with Apache License 2.0 | 5 votes |
@Test public void testList() { String[][] apps = new String[][] { {"http", "source"}, {"filter", "processor"}, {"transform", "processor"}, {"file", "source"}, {"log", "sink"}, {"moving-average", "processor"} }; Collection<AppRegistrationResource> data = new ArrayList<>(); for (String[] app : apps) { data.add(new AppRegistrationResource(app[0], app[1], null)); } PagedResources.PageMetadata metadata = new PagedResources.PageMetadata(data.size(), 1, data.size(), 1); PagedResources<AppRegistrationResource> result = new PagedResources<>(data, metadata); when(appRegistryOperations.list()).thenReturn(result); Object[][] expected = new String[][] { { "source", "processor", "sink" }, { "http", "filter", "log" }, { "file", "transform", null }, { null, "moving-average", null } }; TableModel model = ((Table) appRegistryCommands.list()).getModel(); for (int row = 0; row < expected.length; row++) { for (int col = 0; col < expected[row].length; col++) { assertThat(model.getValue(row, col), Matchers.is(expected[row][col])); } } }
Example #11
Source File: PlatformCommands.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
@ShellMethod(key = "platform list", value = "List platforms") public Table list() { Collection<Deployer> repositoryResources = this.skipperClient.listDeployers(); LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("name", "Name"); headers.put("type", "Type"); headers.put("description", "Description"); TableModel model = new BeanListTableModel<>(repositoryResources, headers); TableBuilder tableBuilder = new TableBuilder(model); return TableUtils.applyStyle(tableBuilder).build(); }
Example #12
Source File: TableMatcher.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
public static DiagnosingMatcher<Table> hasRowThat(Matcher<?>... cells) { return new DiagnosingMatcher<Table>() { @Override protected boolean matches(Object item, Description mismatchDescription) { TableModel model = ((Table) item).getModel(); outer: for (int row = 0; row < model.getRowCount(); row++) { mismatchDescription.appendText("\nRow " + row + ": "); for (int col = 0; col < cells.length; col++) { mismatchDescription.appendText("\n Column " + col + ": "); cells[col].describeMismatch(model.getValue(row, col), mismatchDescription); if (!cells[col].matches(model.getValue(row, col))) { continue outer; } } return true; } return false; } @Override public void describeTo(Description description) { description.appendText("a table having at least one row that\n"); for (int col = 0; col < cells.length; col++) { description.appendText("column " + col + ": "); cells[col].describeTo(description); description.appendText("\n"); } } }; }
Example #13
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 #14
Source File: ReleaseCommands.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
@ShellMethod(key = "release status", value = "Status for a last known release version.") public Object status( @ShellOption(help = "release name") @NotNull String releaseName, @ShellOption(help = "the specific release version.", defaultValue = ShellOption.NULL) Integer releaseVersion) { Info info; try { if (releaseVersion == null) { info = this.skipperClient.status(releaseName); } else { info = this.skipperClient.status(releaseName, releaseVersion); } } catch (ReleaseNotFoundException e) { return "Release with name '" + e.getReleaseName() + "' not found"; } Object[][] data = new Object[3][]; data[0] = new Object[] { "Last Deployed", info.getFirstDeployed() }; data[1] = new Object[] { "Status", info.getStatus().getStatusCode().toString() }; DeploymentState aggregateState = aggregateState(info.getStatus().getDeploymentStateList()); StringBuilder sb = new StringBuilder(); sb.append(DeploymentStateDisplay.fromKey(aggregateState.name()).getDescription() + "\n"); sb.append(info.getStatus().getPlatformStatusPrettyPrint()); data[2] = new Object[] { "Platform Status", sb.toString() }; TableModel model = new ArrayTableModel(data); TableBuilder tableBuilder = new TableBuilder(model); TableUtils.applyStyleNoHeader(tableBuilder); return tableBuilder.build(); }
Example #15
Source File: RepositoryCommands.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
@ShellMethod(key = "repo list", value = "List package repositories") public Table list() { Collection<Repository> repositoryResources = this.skipperClient.listRepositories(); LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("name", "Name"); headers.put("url", "URL"); headers.put("local", "Local"); headers.put("repoOrder", "Order"); TableModel model = new BeanListTableModel<>(repositoryResources, headers); TableBuilder tableBuilder = new TableBuilder(model); return TableUtils.applyStyle(tableBuilder).build(); }
Example #16
Source File: RuntimeCommandsTests.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Test public void testStatusByModuleId() { when(runtimeOperations.status("1")).thenReturn(appStatusResource1); Object[][] expected = new String[][] { { "1", "deployed", "2" }, { "10", "deployed" }, { "20", "deployed" } }; TableModel model = runtimeCommands.list(false, new String[] { "1" }).getModel(); assertTrue(model.getRowCount() == 4); for (int row = 0; row < expected.length; row++) { for (int col = 0; col < expected[row].length; col++) { assertThat(String.valueOf(model.getValue(row + 1, col)), Matchers.is(expected[row][col])); } } }
Example #17
Source File: RuntimeCommands.java From spring-cloud-dashboard with Apache License 2.0 | 4 votes |
@CliCommand(value = LIST_APPS, help = "List runtime apps") public Table list( @CliOption(key = "summary", help = "whether to hide app instance details", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean summary, @CliOption(key = {"appId", "appIds"}, help = "app id(s) to display, also supports '<group>.*' pattern") String[] appIds) { Set<String> filter = null; if (appIds != null) { filter = new HashSet<>(Arrays.asList(appIds)); } TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>(); if (!summary) { modelBuilder.addRow() .addValue("App Id / Instance Id") .addValue("Unit Status") .addValue("No. of Instances / Attributes"); } else { modelBuilder.addRow() .addValue("App Id") .addValue("Unit Status") .addValue("No. of Instances"); } // In detailed mode, keep track of app vs instance lines, to use // a different border style later. List<Integer> splits = new ArrayList<>(); int line = 1; // Optimise for the single app case, which is likely less resource intensive on the server // than client side filtering Iterable<AppStatusResource> statuses; if (filter != null && filter.size() == 1 && !filter.iterator().next().endsWith(".*")) { statuses = Collections.singleton(runtimeOperations().status(filter.iterator().next())); } else { statuses = runtimeOperations().status(); } for (AppStatusResource appStatusResource : statuses) { if (filter != null && !shouldRetain(filter, appStatusResource)) { continue; } modelBuilder.addRow() .addValue(appStatusResource.getDeploymentId()) .addValue(appStatusResource.getState()) .addValue(appStatusResource.getInstances().getContent().size()); splits.add(line); line++; if (!summary) { for (AppInstanceStatusResource appInstanceStatusResource : appStatusResource.getInstances()) { modelBuilder.addRow() .addValue(appInstanceStatusResource.getInstanceId()) .addValue(appInstanceStatusResource.getState()) .addValue(appInstanceStatusResource.getAttributes()); line++; } } } TableModel model = modelBuilder.build(); final TableBuilder builder = new TableBuilder(model); DataFlowTables.applyStyle(builder); builder.on(column(0)).addAligner(middle) .on(column(1)).addAligner(middle) .on(column(1)).addAligner(center) // This will match the "number of instances" cells only .on(ofType(Integer.class)).addAligner(center); Tables.configureKeyValueRendering(builder, " = "); for (int i = 2; i < model.getRowCount(); i++) { if (splits.contains(i)) { builder.paintBorder(fancy_light, TOP).fromRowColumn(i, 0).toRowColumn(i + 1, model.getColumnCount()); } else { builder.paintBorder(fancy_light_quadruple_dash, TOP).fromRowColumn(i, 0).toRowColumn(i + 1, model.getColumnCount()); } } return builder.build(); }
Example #18
Source File: RuntimeCommands.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
@CliCommand(value = LIST_APPS, help = "List runtime apps") public Table list( @CliOption(key = "summary", help = "whether to hide app instance details", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean summary, @CliOption(key = { "appId", "appIds" }, help = "app id(s) to display, also supports '<group>.*' pattern") String[] appIds) { Set<String> filter = null; if (appIds != null) { filter = new HashSet<>(Arrays.asList(appIds)); } TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>(); if (!summary) { modelBuilder.addRow().addValue("App Id / Instance Id").addValue("Unit Status") .addValue("No. of Instances / Attributes"); } else { modelBuilder.addRow().addValue("App Id").addValue("Unit Status").addValue("No. of Instances"); } // In detailed mode, keep track of app vs instance lines, to use // a different border style later. List<Integer> splits = new ArrayList<>(); int line = 1; // Optimise for the single app case, which is likely less resource intensive on // the server // than client side filtering Iterable<AppStatusResource> statuses; if (filter != null && filter.size() == 1 && !filter.iterator().next().endsWith(".*")) { statuses = Collections.singleton(runtimeOperations().status(filter.iterator().next())); } else { statuses = runtimeOperations().status(); } for (AppStatusResource appStatusResource : statuses) { if (filter != null && !shouldRetain(filter, appStatusResource)) { continue; } modelBuilder.addRow().addValue(appStatusResource.getDeploymentId()).addValue(appStatusResource.getState()) .addValue(appStatusResource.getInstances().getContent().size()); splits.add(line); line++; if (!summary) { for (AppInstanceStatusResource appInstanceStatusResource : appStatusResource.getInstances()) { modelBuilder.addRow().addValue(appInstanceStatusResource.getInstanceId()) .addValue(appInstanceStatusResource.getState()) .addValue(appInstanceStatusResource.getAttributes()); line++; } } } TableModel model = modelBuilder.build(); final TableBuilder builder = new TableBuilder(model); DataFlowTables.applyStyle(builder); builder.on(CellMatchers.column(0)).addAligner(SimpleVerticalAligner.middle).on(CellMatchers.column(1)).addAligner(SimpleVerticalAligner.middle).on(CellMatchers.column(1)).addAligner(SimpleHorizontalAligner.center) // This will match the "number of instances" cells only .on(CellMatchers.ofType(Integer.class)).addAligner(SimpleHorizontalAligner.center); Tables.configureKeyValueRendering(builder, " = "); for (int i = 2; i < model.getRowCount(); i++) { if (splits.contains(i)) { builder.paintBorder(BorderStyle.fancy_light, BorderSpecification.TOP).fromRowColumn(i, 0).toRowColumn(i + 1, model.getColumnCount()); } else { builder.paintBorder(BorderStyle.fancy_light_quadruple_dash, BorderSpecification.TOP).fromRowColumn(i, 0).toRowColumn(i + 1, model.getColumnCount()); } } return builder.build(); }