org.springframework.shell.table.TableBuilder Java Examples

The following examples show how to use org.springframework.shell.table.TableBuilder. 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 Project: spring-cloud-skipper   Author: spring-cloud   File: ReleaseCommands.java    License: Apache License 2.0 6 votes vote down vote up
@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 Project: spring-cloud-skipper   Author: spring-cloud   File: ReleaseCommands.java    License: Apache License 2.0 6 votes vote down vote up
@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 #3
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: TaskCommands.java    License: Apache License 2.0 6 votes vote down vote up
@CliCommand(value = EXECUTION_LIST, help = "List created task executions filtered by taskName")
public Table executionListByName(
		@CliOption(key = "name", help = "the task name to be used as a filter", optionContext = "existing-task disable-string-converter") String name) {

	final PagedModel<TaskExecutionResource> tasks;
	if (name == null) {
		tasks = taskOperations().executionList();
	}
	else {
		tasks = taskOperations().executionListByTaskName(name);
	}
	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("taskName", "Task Name");
	headers.put("executionId", "ID");
	headers.put("startTime", "Start Time");
	headers.put("endTime", "End Time");
	headers.put("exitCode", "Exit Code");
	final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(tasks, headers));
	return DataFlowTables.applyStyle(builder).build();
}
 
Example #4
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: StreamCommands.java    License: Apache License 2.0 6 votes vote down vote up
@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 #5
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: StreamCommands.java    License: Apache License 2.0 6 votes vote down vote up
@CliCommand(value = INFO_STREAM, help = "Show information about a specific stream")
public List<Object> streamInfo(@CliOption(key = { "",
		"name" }, help = "the name of the stream to show", mandatory = true, optionContext = "existing-stream disable-string-converter") String name) {
	List<Object> result = new ArrayList<>();
	final StreamDeploymentResource stream = streamOperations().info(name);
	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();
	modelBuilder.addRow().addValue("Stream Name").addValue("Stream Definition").addValue("Description").addValue("Status");
	modelBuilder.addRow().addValue(stream.getStreamName())
			.addValue(stream.getDslText())
			.addValue(stream.getDescription())
			.addValue(stream.getStatus());
	TableBuilder builder = DataFlowTables.applyStyle(new TableBuilder(modelBuilder.build()));
	result.add(builder.build());
	if (StringUtils.hasText(stream.getDeploymentProperties())) {
		//TODO: rename Deployment properties for Skipper as it includes apps' info (app:version) as well
		result.add(String.format("Stream Deployment properties: %s", ShellUtils.prettyPrintIfJson(stream.getDeploymentProperties())));
	}
	return result;
}
 
Example #6
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: JobCommands.java    License: Apache License 2.0 6 votes vote down vote up
@CliCommand(value = INSTANCE_DISPLAY, help = "Display the job executions for a specific job instance.")
public Table instanceDisplay(@CliOption(key = { "id" }, help = "the job instance id", mandatory = true) long id) {

	JobInstanceResource jobInstanceResource = jobOperations().jobInstance(id);

	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();
	modelBuilder.addRow().addValue("Name ").addValue("Execution ID ").addValue("Step Execution Count ")
			.addValue("Status ").addValue("Job Parameters ");
	for (JobExecutionResource job : jobInstanceResource.getJobExecutions()) {
		modelBuilder.addRow().addValue(jobInstanceResource.getJobName()).addValue(job.getExecutionId())
				.addValue(job.getStepExecutionCount()).addValue(job.getJobExecution().getStatus().name())
				.addValue(job.getJobParametersString());
	}
	TableBuilder builder = new TableBuilder(modelBuilder.build());
	DataFlowTables.applyStyle(builder);

	return builder.build();
}
 
Example #7
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: JobCommands.java    License: Apache License 2.0 6 votes vote down vote up
@CliCommand(value = STEP_EXECUTION_LIST, help = "List step executions filtered by jobExecutionId")
public Table stepExecutionList(@CliOption(key = {
		"id" }, help = "the job execution id to be used as a filter", mandatory = true) long id) {

	final PagedModel<StepExecutionResource> steps = jobOperations().stepExecutionList(id);

	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();

	modelBuilder.addRow().addValue("ID ").addValue("Step Name ").addValue("Job Exec Id ").addValue("Start Time ")
			.addValue("End Time ").addValue("Status ");
	for (StepExecutionResource step : steps) {
		modelBuilder.addRow().addValue(step.getStepExecution().getId())
				.addValue(step.getStepExecution().getStepName()).addValue(id)
				.addValue(step.getStepExecution().getStartTime()).addValue(step.getStepExecution().getEndTime())
				.addValue(step.getStepExecution().getStatus().name());
	}
	TableBuilder builder = new TableBuilder(modelBuilder.build());

	DataFlowTables.applyStyle(builder);

	return builder.build();
}
 
Example #8
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: JobCommands.java    License: Apache License 2.0 6 votes vote down vote up
@CliCommand(value = STEP_EXECUTION_PROGRESS, help = "Display the details of a specific step progress")
public Table stepProgressDisplay(
		@CliOption(key = { "id" }, help = "the step execution id", mandatory = true) long id, @CliOption(key = {
				"jobExecutionId" }, help = "the job execution id", mandatory = true) long jobExecutionId) {

	StepExecutionProgressInfoResource progressInfoResource = jobOperations().stepExecutionProgress(jobExecutionId,
			id);

	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();
	modelBuilder.addRow().addValue("ID ").addValue("Step Name ").addValue("Complete ").addValue("Duration ");

	modelBuilder.addRow().addValue(progressInfoResource.getStepExecution().getId())
			.addValue(progressInfoResource.getStepExecution().getStepName())
			.addValue(progressInfoResource.getPercentageComplete() * 100 + "%")
			.addValue(progressInfoResource.getDuration() + " ms");

	TableBuilder builder = new TableBuilder(modelBuilder.build());
	DataFlowTables.applyStyle(builder);

	return builder.build();
}
 
Example #9
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: TaskSchedulerCommands.java    License: Apache License 2.0 6 votes vote down vote up
@CliCommand(value = SCHEDULER_LIST, help = "List task schedules by task definition name")
public Table listByDefinition(
		@CliOption(key = { "platform" }, help = "the name platform from which to retrieve a list of schedules") String platform,
		@CliOption(key = { "definitionName" }, help = "the task definition name") String definitionName) {
	PagedModel<ScheduleInfoResource> schedules;
	if (Strings.isEmpty(definitionName)) {
		schedules = scheduleOperations().listByPlatform(platform);
	}
	else {
		schedules = scheduleOperations().list(definitionName, platform);
	}

	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("scheduleName", "Schedule Name");
	headers.put("taskDefinitionName", "Task Definition Name");
	headers.put("scheduleProperties", "Properties");
	final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(schedules, headers));
	return DataFlowTables.applyStyle(builder).build();
}
 
Example #10
Source Project: spring-cloud-skipper   Author: spring-cloud   File: RepositoryCommands.java    License: Apache License 2.0 5 votes vote down vote up
@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 #11
Source Project: spring-cloud-skipper   Author: spring-cloud   File: ReleaseCommands.java    License: Apache License 2.0 5 votes vote down vote up
@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 #12
Source Project: spring-cloud-skipper   Author: spring-cloud   File: TableUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Customize the given TableBuilder with almost same way than
 * {@link #applyStyle(TableBuilder)} but do not use any header styling.
 *
 * @param builder the table builder to use
 * @return the configured table builder
 */
public static TableBuilder applyStyleNoHeader(TableBuilder builder) {
	builder.addOutlineBorder(BorderStyle.fancy_double)
			.paintBorder(BorderStyle.air, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight()
			.paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER_VERTICAL).fromTopLeft()
			.toBottomRight();
	return Tables.configureKeyValueRendering(builder, " = ");
}
 
Example #13
Source Project: spring-cloud-skipper   Author: spring-cloud   File: PlatformCommands.java    License: Apache License 2.0 5 votes vote down vote up
@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 #14
Source Project: spring-cloud-dashboard   Author: spring-cloud   File: ConfigCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = {"dataflow config info"}, help = "Show the Dataflow server being used")
public String info() {

	final Map<String, String> statusValues = new TreeMap<String, String>();

	final Target target = targetHolder.getTarget();

	statusValues.put("Target", target.getTargetUriAsString());

	if (target.isSkipSslValidation()) {
		statusValues.put("SSL Validation", "skipped");
	}

	if (target.getTargetCredentials() != null) {
		statusValues.put("Credentials", target.getTargetCredentials().getDisplayableContents());
	}
	statusValues.put("Result", target.getTargetResultMessage() != null ? target.getTargetResultMessage() : "");

	final TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();

	for (Map.Entry<String, String> row : statusValues.entrySet()) {
		modelBuilder.addRow().addValue(row.getKey()).addValue(row.getValue());
	}

	final TableBuilder builder = new TableBuilder(modelBuilder.build());
	DataFlowTables.applyStyle(builder);

	final StringBuilder sb = new StringBuilder(builder.build().render(66));

	if (Target.TargetStatus.ERROR.equals(target.getStatus())) {
		sb.append(HORIZONTAL_LINE);
		sb.append("An exception occurred during targeting:\n");

		final StringWriter stringWriter = new StringWriter();
		target.getTargetException().printStackTrace(new PrintWriter(stringWriter));

		sb.append(stringWriter.toString());
	}
	return sb.toString();
}
 
Example #15
Source Project: spring-cloud-dashboard   Author: spring-cloud   File: ApplicationCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = LIST_APPLICATION, help = "List created applications")
public Table listApplications() {
	final PagedResources<ApplicationDefinitionResource> applications = applicationOperations().list();
	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("name", "Application Name");
	headers.put("dslText", "Application Definition");
	headers.put("status", "Status");
	BeanListTableModel<ApplicationDefinitionResource> model = new BeanListTableModel<>(applications, headers);
	return DataFlowTables.applyStyle(new TableBuilder(model))
			.build();
}
 
Example #16
Source Project: spring-cloud-dashboard   Author: spring-cloud   File: DataFlowTables.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Customize the given TableBuilder with the following common features
 * (these choices can always be overridden by applying later customizations) :<ul>
 *     <li>double border around the whole table and first row</li>
 *     <li>vertical space (air) borders, single line separators between rows</li>
 *     <li>first row is assumed to be a header and is centered horizontally and vertically</li>
 *     <li>cells containing Map values are rendered as {@literal key = value} lines, trying to align on equal signs</li>
 * </ul>
 */
public static TableBuilder applyStyle(TableBuilder builder) {
	builder.addOutlineBorder(BorderStyle.fancy_double)
			.paintBorder(BorderStyle.air, BorderSpecification.INNER_VERTICAL)
			.fromTopLeft().toBottomRight()
			.paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER_VERTICAL)
			.fromTopLeft().toBottomRight()
			.addHeaderBorder(BorderStyle.fancy_double)
			.on(CellMatchers.row(0))
			.addAligner(SimpleVerticalAligner.middle)
			.addAligner(SimpleHorizontalAligner.center)
	;
	return Tables.configureKeyValueRendering(builder, " = ");
}
 
Example #17
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: TaskCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = LIST, help = "List created tasks")
public Table list() {
	final PagedModel<TaskDefinitionResource> tasks = taskOperations().list();
	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("name", "Task Name");
	headers.put("dslText", "Task Definition");
	headers.put("description", "description");
	headers.put("status", "Task Status");
	final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(tasks, headers));
	return DataFlowTables.applyStyle(builder).build();
}
 
Example #18
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: TaskCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = PLATFORM_LIST, help = "List platform accounts for tasks")
public Table listPlatforms() {
	final PagedModel<LauncherResource> platforms = taskOperations().listPlatforms();
	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("name", "Platform Name");
	headers.put("type", "Platform Type");
	headers.put("description", "Description");
	final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(platforms, headers));
	return DataFlowTables.applyStyle(builder).build();
}
 
Example #19
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: TaskCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = VALIDATE, help = "Validate apps contained in task definitions")
public List<Object> validate(
		@CliOption(key = { "", "name" }, help = "the task definition name", mandatory = true) String name)
		throws OperationNotSupportedException {
	final TaskAppStatusResource task = taskOperations().validateTaskDefinition(name);
	List<Object> result = new ArrayList<>();
	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();
	modelBuilder.addRow().addValue("Task Name").addValue("Task Definition");
	modelBuilder.addRow().addValue(task.getAppName())
			.addValue(task.getDsl());
	TableBuilder builder = DataFlowTables.applyStyle(new TableBuilder(modelBuilder.build()));
	result.add(builder.build());

	modelBuilder = new TableModelBuilder<>();
	modelBuilder.addRow().addValue("App Name").addValue("Validation Status");
	boolean isValidStream = true;
	for (Map.Entry<String, String> entry : task.getAppStatuses().entrySet()) {
		modelBuilder.addRow().addValue(entry.getKey())
				.addValue(entry.getValue());
		if (entry.getValue().equals("invalid")) {
			isValidStream = false;
		}
	}
	builder = DataFlowTables.applyStyle(new TableBuilder(modelBuilder.build()));

	if (isValidStream) {
		result.add(String.format("\n%s is a valid task.", task.getAppName()));
	}
	else {
		result.add(String.format("\n%s is an invalid task.", task.getAppName()));
	}
	result.add(builder.build());
	return result;
}
 
Example #20
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: TaskCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = TASK_EXECUTION_STATUS, help = "Display the details of a specific task execution")
public Table display(@CliOption(key = { "", "id" }, help = "the task execution id", mandatory = true) long id) {

	TaskExecutionResource taskExecutionResource = taskOperations().taskExecutionStatus(id);

	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();

	modelBuilder.addRow().addValue("Key ").addValue("Value ");
	modelBuilder.addRow().addValue("Id ").addValue(taskExecutionResource.getExecutionId());
	modelBuilder.addRow().addValue("Resource URL ").addValue(taskExecutionResource.getResourceUrl());
	modelBuilder.addRow().addValue("Name ").addValue(taskExecutionResource.getTaskName());
	modelBuilder.addRow().addValue("CLI Arguments ").addValue(taskExecutionResource.getArguments());
	modelBuilder.addRow().addValue("App Arguments ").addValue(taskExecutionResource.getAppProperties());
	modelBuilder.addRow().addValue("Deployment Properties ")
			.addValue(taskExecutionResource.getDeploymentProperties());
	modelBuilder.addRow().addValue("Job Execution Ids ").addValue(taskExecutionResource.getJobExecutionIds());
	modelBuilder.addRow().addValue("Start Time ").addValue(taskExecutionResource.getStartTime());
	modelBuilder.addRow().addValue("End Time ").addValue(taskExecutionResource.getEndTime());
	modelBuilder.addRow().addValue("Exit Code ").addValue(taskExecutionResource.getExitCode());
	modelBuilder.addRow().addValue("Exit Message ").addValue(taskExecutionResource.getExitMessage());
	modelBuilder.addRow().addValue("Error Message ").addValue(taskExecutionResource.getErrorMessage());
	modelBuilder.addRow().addValue("External Execution Id ")
			.addValue(taskExecutionResource.getExternalExecutionId());

	TableBuilder builder = new TableBuilder(modelBuilder.build());

	DataFlowTables.applyStyle(builder);

	return builder.build();
}
 
Example #21
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: TaskCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = TASK_EXECUTION_CURRENT, help = "Display count of currently executin tasks and related information")
public Table currentExecutions() {
	Collection<CurrentTaskExecutionsResource> taskExecutionsResources = taskOperations().currentTaskExecutions();
	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("name", "Platform Name");
	headers.put("type", "Platform Type");
	headers.put("runningExecutionCount", "Execution Count");
	headers.put("maximumTaskExecutions", "Maximum Executions");

	TableBuilder builder = new TableBuilder(new BeanListTableModel<>(taskExecutionsResources, headers));
	DataFlowTables.applyStyle(builder);
	return builder.build();
}
 
Example #22
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: StreamCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = STREAM_PLATFORM_LIST, help = "List Skipper platforms")
public Table listPlatforms() {
	Collection<Deployer> platforms = streamOperations().listPlatforms();
	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("name", "Name");
	headers.put("type", "Type");
	headers.put("description", "Description");
	BeanListTableModel<Deployer> model = new BeanListTableModel<>(platforms, headers);
	return DataFlowTables.applyStyle(new TableBuilder(model)).build();
}
 
Example #23
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: StreamCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = LIST_STREAM, help = "List created streams")
public Table listStreams() {
	final PagedModel<StreamDefinitionResource> streams = streamOperations().list();
	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("name", "Stream Name");
	headers.put("description", "Description");
	headers.put("originalDslText", "Stream Definition");
	headers.put("statusDescription", "Status");
	BeanListTableModel<StreamDefinitionResource> model = new BeanListTableModel<>(streams, headers);
	return DataFlowTables.applyStyle(new TableBuilder(model)).build();
}
 
Example #24
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: StreamCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = VALIDATE_STREAM, help = "Verify that apps contained in the stream are valid.")
public List<Object> validateStream(@CliOption(key = { "",
		"name" }, help = "the name of the stream to validate", mandatory = true, optionContext = "existing-stream disable-string-converter") String name) throws OperationNotSupportedException {
	List<Object> result = new ArrayList<>();
	final StreamAppStatusResource stream = streamOperations().validateStreamDefinition(name);
	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();
	modelBuilder.addRow().addValue("Stream Name").addValue("Stream Definition");
	modelBuilder.addRow().addValue(stream.getAppName())
			.addValue(stream.getDsl());
	TableBuilder builder = DataFlowTables.applyStyle(new TableBuilder(modelBuilder.build()));
	result.add(builder.build());

	modelBuilder = new TableModelBuilder<>();
	modelBuilder.addRow().addValue("App Name").addValue("Validation Status");
	boolean isValidStream = true;
	for(Map.Entry<String,String> entry : stream.getAppStatuses().entrySet()) {
		modelBuilder.addRow().addValue(entry.getKey())
				.addValue(entry.getValue());
		if (entry.getValue().equals("invalid")) {
			isValidStream = false;
		}
	}
	builder = DataFlowTables.applyStyle(new TableBuilder(modelBuilder.build()));

	if (isValidStream) {
		result.add(String.format("\n%s is a valid stream.", stream.getAppName()));
	}
	else {
		result.add(String.format("\n%s is an invalid stream.", stream.getAppName()));
	}
	result.add(builder.build());
	return result;
}
 
Example #25
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: JobCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = EXECUTION_LIST, help = "List created job executions filtered by jobName")
public Table executionList(
		@CliOption(key = { "name" }, help = "the job name to be used as a filter", mandatory = false) String name) {

	final PagedModel<JobExecutionThinResource> jobs;
	if (name == null) {
		jobs = jobOperations().executionThinList();
	}
	else {
		jobs = jobOperations().executionThinListByJobName(name);
	}

	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();

	modelBuilder.addRow().addValue("ID ").addValue("Task ID").addValue("Job Name ").addValue("Start Time ")
			.addValue("Step Execution Count ").addValue("Definition Status ");
	for (JobExecutionThinResource job : jobs) {
		modelBuilder.addRow().addValue(job.getExecutionId()).addValue(job.getTaskExecutionId())
				.addValue(job.getName())
				.addValue(job.getStartDateTime())
				.addValue(job.getStepExecutionCount())
				.addValue(job.isDefined() ? "Created" : "Destroyed");
	}
	TableBuilder builder = new TableBuilder(modelBuilder.build());

	DataFlowTables.applyStyle(builder);

	return builder.build();
}
 
Example #26
Source Project: ssh-shell-spring-boot   Author: fonimus   File: ThreadCommand.java    License: Apache License 2.0 4 votes vote down vote up
private String table(ThreadColumn orderBy, boolean reverseOrder, boolean fullscreen) {
    List<Thread> ordered = new ArrayList<>(getThreads().values());
    ordered.sort(comparator(orderBy, reverseOrder));

    // handle maximum rows: 1 line for headers, 3 borders, 3 description lines
    int maxWithHeadersAndBorders = helper.terminalSize().getRows() - 8;
    int tableSize = ordered.size() + 1;
    boolean addDotLine = false;
    if (fullscreen && ordered.size() > maxWithHeadersAndBorders) {
        ordered = ordered.subList(0, maxWithHeadersAndBorders);
        tableSize = maxWithHeadersAndBorders + 2;
        addDotLine = true;
    }

    String[][] data = new String[tableSize][ThreadColumn.values().length];
    TableBuilder tableBuilder = new TableBuilder(new ArrayTableModel(data));

    int i = 0;
    for (ThreadColumn column : ThreadColumn.values()) {
        data[0][i] = column.name();
        tableBuilder.on(at(0, i)).addAligner(SimpleHorizontalAligner.center);
        i++;
    }
    int r = 1;
    for (Thread t : ordered) {
        data[r][0] = String.valueOf(t.getId());
        data[r][1] = String.valueOf(t.getPriority());
        data[r][2] = t.getState().name();
        tableBuilder.on(at(r, 2)).addAligner(new ColorAligner(color(t.getState())));
        data[r][3] = String.valueOf(t.isInterrupted());
        data[r][4] = String.valueOf(t.isDaemon());
        data[r][5] = t.getName();
        r++;
    }
    if (addDotLine) {
        String dots = "...";
        data[r][0] = dots;
        data[r][1] = dots;
        data[r][2] = dots;
        data[r][3] = dots;
        data[r][4] = dots;
        data[r][5] = "... not enough rows to display all threads";
    }
    return tableBuilder.addHeaderAndVerticalsBorders(BorderStyle.fancy_double).build().render(helper.terminalSize().getRows());
}
 
Example #27
Source Project: spring-cloud-dashboard   Author: spring-cloud   File: RuntimeCommands.java    License: Apache License 2.0 4 votes vote down vote up
@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 #28
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: RuntimeCommands.java    License: Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #29
Source Project: spring-cloud-dataflow   Author: spring-cloud   File: JobCommands.java    License: Apache License 2.0 4 votes vote down vote up
@CliCommand(value = STEP_EXECUTION_DISPLAY, help = "Display the details of a specific step execution")
public Table stepExecutionDisplay(
		@CliOption(key = { "id" }, help = "the step execution id", mandatory = true) long id, @CliOption(key = {
				"jobExecutionId" }, help = "the job execution id", mandatory = true) long jobExecutionId) {

	StepExecutionProgressInfoResource progressInfoResource = jobOperations().stepExecutionProgress(jobExecutionId,
			id);

	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();
	modelBuilder.addRow().addValue("Key ").addValue("Value ");
	modelBuilder.addRow().addValue("Step Execution Id ").addValue(id);
	modelBuilder.addRow().addValue("Job Execution Id ").addValue(jobExecutionId);
	modelBuilder.addRow().addValue("Step Name ").addValue(progressInfoResource.getStepExecution().getStepName());
	modelBuilder.addRow().addValue("Start Time ").addValue(progressInfoResource.getStepExecution().getStartTime());
	modelBuilder.addRow().addValue("End Time ").addValue(progressInfoResource.getStepExecution().getEndTime());
	modelBuilder.addRow().addValue("Duration ").addValue(progressInfoResource.getDuration() + " ms");
	modelBuilder.addRow().addValue("Status ").addValue(progressInfoResource.getStepExecution().getStatus().name());
	modelBuilder.addRow().addValue("Last Updated ")
			.addValue(progressInfoResource.getStepExecution().getLastUpdated());
	modelBuilder.addRow().addValue("Read Count ")
			.addValue(progressInfoResource.getStepExecutionHistory().getReadCount().getCount());
	modelBuilder.addRow().addValue("Write Count ")
			.addValue(progressInfoResource.getStepExecutionHistory().getWriteCount().getCount());
	modelBuilder.addRow().addValue("Filter Count ")
			.addValue(progressInfoResource.getStepExecutionHistory().getFilterCount().getCount());
	modelBuilder.addRow().addValue("Read Skip Count ")
			.addValue(progressInfoResource.getStepExecutionHistory().getReadSkipCount().getCount());
	modelBuilder.addRow().addValue("Write Skip Count ")
			.addValue(progressInfoResource.getStepExecutionHistory().getWriteSkipCount().getCount());
	modelBuilder.addRow().addValue("Process Skip Count ")
			.addValue(progressInfoResource.getStepExecutionHistory().getProcessSkipCount().getCount());
	modelBuilder.addRow().addValue("Read Skip Count ")
			.addValue(progressInfoResource.getStepExecutionHistory().getReadSkipCount().getCount());
	modelBuilder.addRow().addValue("Commit Count ")
			.addValue(progressInfoResource.getStepExecutionHistory().getCommitCount().getCount());
	modelBuilder.addRow().addValue("Rollback Count ")
			.addValue(progressInfoResource.getStepExecutionHistory().getRollbackCount().getCount());
	modelBuilder.addRow().addValue("Exit Status ")
			.addValue(progressInfoResource.getStepExecution().getExitStatus().getExitCode());
	modelBuilder.addRow().addValue("Exit Description ")
			.addValue(progressInfoResource.getStepExecution().getExitStatus().getExitDescription());

	TableBuilder builder = new TableBuilder(modelBuilder.build());

	DataFlowTables.applyStyle(builder);

	return builder.build();
}
 
Example #30
Source Project: spring-cloud-skipper   Author: spring-cloud   File: TableUtils.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Customize the given TableBuilder with the following common features (these choices can
 * always be overridden by applying later customizations) :
 * <ul>
 * <li>double border around the whole table and first row</li>
 * <li>vertical space (air) borders, single line separators between rows</li>
 * <li>first row is assumed to be a header and is centered horizontally and
 * vertically</li>
 * <li>cells containing Map values are rendered as {@literal key = value} lines, trying to
 * align on equal signs</li>
 * </ul>
 *
 * @param builder the table builder to use
 * @return the configured table builder
 */
public static TableBuilder applyStyle(TableBuilder builder) {
	builder.addOutlineBorder(BorderStyle.fancy_double)
			.paintBorder(BorderStyle.air, BorderSpecification.INNER_VERTICAL).fromTopLeft().toBottomRight()
			.paintBorder(BorderStyle.fancy_light, BorderSpecification.INNER_VERTICAL).fromTopLeft()
			.toBottomRight()
			.addHeaderBorder(BorderStyle.fancy_double).on(CellMatchers.row(0))
			.addAligner(SimpleVerticalAligner.middle).addAligner(SimpleHorizontalAligner.center);
	return Tables.configureKeyValueRendering(builder, " = ");
}