org.springframework.shell.standard.ShellMethod Java Examples
The following examples show how to use
org.springframework.shell.standard.ShellMethod.
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: StateMachineCommands.java From spring-statemachine-learning with Apache License 2.0 | 6 votes |
@ShellMethod(value = "sm variables", key = "sm variables") public String variables() { if (stateMachine == null) { return "please select sm"; } StringBuilder buf = new StringBuilder(); Set<Map.Entry<Object, Object>> entrySet = stateMachine.getExtendedState().getVariables().entrySet(); Iterator<Map.Entry<Object, Object>> iterator = entrySet.iterator(); if (entrySet.size() > 0) { while (iterator.hasNext()) { Map.Entry<Object, Object> e = iterator.next(); buf.append(e.getKey() + "=" + e.getValue()); if (iterator.hasNext()) { buf.append("\n"); } } } else { buf.append("No variables"); } return buf.toString(); }
Example #2
Source File: ShowDatabaseCommands.java From sqlhelper with GNU Lesser General Public License v3.0 | 6 votes |
@ShellMethod(key = "show indexes", value = "Show table index") public List<String> getIndexNames( @ShellOption(help = "the connection configuration name") String connectionName, @ShellOption(help = "the table name") String table) { Connection connection = getConnectionByConnectionConfigurationId(connectionName); try { DatabaseMetaData dbMetaData = connection.getMetaData(); DatabaseDescription databaseDescription = new DatabaseDescription(dbMetaData); List<Index> indexes = new DatabaseLoader().findTableIndexes(databaseDescription, Connections.getCatalog(connection), Connections.getSchema(connection), table); return Pipeline.of(indexes).map(new Function<Index, String>() { @Override public String apply(Index index) { return index.getName() + "\t" + SQLs.getTableFQN(index.getCatalog(), index.getSchema(), index.getTableName()); } }).asList(); } catch (Throwable ex) { throw Throwables.wrapAsRuntimeException(ex); } finally { IOs.close(connection); } }
Example #3
Source File: ShowDatabaseCommands.java From sqlhelper with GNU Lesser General Public License v3.0 | 6 votes |
@ShellMethod(key = "show index", value = "Show index detail") public Index getIndex(@ShellOption(help = "the connection configuration name") String connectionName, @ShellOption(help = "the table name") String table, @ShellOption(help = "the index name") String index) { Connection connection = getConnectionByConnectionConfigurationId(connectionName); try { DatabaseMetaData dbMetaData = connection.getMetaData(); Table t = new DatabaseLoader().loadTable(new DatabaseDescription(dbMetaData), Connections.getCatalog(connection), Connections.getSchema(connection), table); return t.getIndex(index); } catch (Throwable ex) { throw Throwables.wrapAsRuntimeException(ex); } finally { IOs.close(connection); } }
Example #4
Source File: ShowDatabaseCommands.java From sqlhelper with GNU Lesser General Public License v3.0 | 6 votes |
@ShellMethod(key = "show tables", value = "Show table names") public List<String> getTableNames( @ShellOption(help = "the connection configuration name") String connectionName ) { Connection connection = getConnectionByConnectionConfigurationId(connectionName); try { DatabaseMetaData dbMetaData = connection.getMetaData(); final DatabaseDescription databaseDescription = new DatabaseDescription(dbMetaData); List<Table> tables = new DatabaseLoader().loadTables(databaseDescription, Connections.getCatalog(connection), Connections.getSchema(connection), null); return Pipeline.of(tables).map(new Function<Table, String>() { @Override public String apply(Table table) { return SQLs.getTableFQN(databaseDescription, table.getCatalog(), table.getSchema(), table.getName()); } }).asList(); } catch (Throwable ex) { throw Throwables.wrapAsRuntimeException(ex); } finally { IOs.close(connection); } }
Example #5
Source File: ShowDatabaseCommands.java From sqlhelper with GNU Lesser General Public License v3.0 | 6 votes |
@ShellMethod(key = "show ddl", value = "Show table DDL") public String getTableDDL(@ShellOption(help = "the connection configuration name") String connectionName, @ShellOption(help = "the table name") String table) { Connection connection = getConnectionByConnectionConfigurationId(connectionName); try { DatabaseMetaData dbMetaData = connection.getMetaData(); DatabaseDescription databaseDescription = new DatabaseDescription(dbMetaData); Table t = new DatabaseLoader().loadTable(databaseDescription, Connections.getCatalog(connection), Connections.getSchema(connection), table); Preconditions.checkNotNull(t, StringTemplates.formatWithPlaceholder("table {} is not exists", table)); CommonTableGenerator generator = new CommonTableGenerator(databaseDescription); return generator.generate(t); } catch (Throwable ex) { throw Throwables.wrapAsRuntimeException(ex); } finally { IOs.close(connection); } }
Example #6
Source File: ActuatorCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 6 votes |
/** * Metrics method * * @param name metrics name to display * @param tags tags to filter with * @return metrics */ @ShellMethod(key = "metrics", value = "Display metrics endpoint.") @ShellMethodAvailability("metricsAvailability") public Object metrics( @ShellOption(value = {"-n", "--name"}, help = "Metric name to get", defaultValue = ShellOption.NULL) String name, @ShellOption(value = {"-t", "--tags"}, help = "Tags (key=value, separated by coma)", defaultValue = ShellOption.NULL) String tags ) { if (name != null) { MetricsEndpoint.MetricResponse result = metrics.metric(name, tags != null ? Arrays.asList(tags.split(",") ) : null); if (result == null) { String tagsStr = tags != null ? " and tags: " + tags : ""; throw new IllegalArgumentException("No result for metrics name: " + name + tagsStr); } return result; } return metrics.listNames(); }
Example #7
Source File: ManifestCommands.java From spring-cloud-skipper with Apache License 2.0 | 6 votes |
@ShellMethod(key = "manifest get", value = "Get the manifest for a release") public Object getManifest( @ShellOption(help = "release name") @NotNull String releaseName, @ShellOption(help = "specific release version.", defaultValue = ShellOption.NULL) Integer releaseVersion) { String manifest; try { if (releaseVersion == null) { manifest = this.skipperClient.manifest(releaseName); } else { manifest = this.skipperClient.manifest(releaseName, releaseVersion); } } catch (HttpStatusCodeException e) { if (e.getStatusCode() == HttpStatus.NOT_FOUND) { return "Release with name '" + releaseName + "' not found"; } // if something else, rethrow throw e; } return manifest; }
Example #8
Source File: DemoCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 6 votes |
/** * Displays ssh session information */ @ShellMethod("Displays ssh session information") public String displaySshSession() { ServerSession session = helper.getSshSession(); if (session == null) { return helper.getWarning("Not in a ssh session"); } return helper.renderTable(SimpleTable.builder() .column("Property").column("Value") .line(Arrays.asList("Session id", session.getIoSession().getId())) .line(Arrays.asList("Local address", session.getIoSession().getLocalAddress())) .line(Arrays.asList("Remote address", session.getIoSession().getRemoteAddress())) .line(Arrays.asList("Acceptance address", session.getIoSession().getAcceptanceAddress())) .line(Arrays.asList("Server version", session.getServerVersion())) .line(Arrays.asList("Client version", session.getClientVersion())) .build()); }
Example #9
Source File: DemoCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 6 votes |
/** * Simple table example command * * @return principal */ @ShellMethod("Simple table command") public String tableSimple() { return helper.renderTable(SimpleTable.builder() .column("col1") .column("col2") .column("col3") .column("col4") .line(Arrays.asList("line1 col1", "line1 col2", "line1 col3", "line1 col4")) .line(Arrays.asList("line2 col1", "line2 col2", "line2 col3", "line2 col4")) .line(Arrays.asList("line3 col1", "line3 col2", "line3 col3", "line3 col4")) .line(Arrays.asList("line4 col1", "line4 col2", "line4 col3", "line4 col4")) .line(Arrays.asList("line5 col1", "line5 col2", "line5 col3", "line5 col4")) .line(Arrays.asList("line6 col1", "line6 col2", "line6 col3", "line6 col4")) .build()); }
Example #10
Source File: RSocketShellClient.java From spring-rsocket-demo with GNU General Public License v3.0 | 6 votes |
@ShellMethod("Stream some settings to the server. Stream of responses will be printed.") public void channel() { if (userIsLoggedIn()) { log.info("\n\n***** Channel (bi-directional streams)\n***** Asking for a stream of messages.\n***** Type 's' to stop.\n\n"); Mono<Duration> setting1 = Mono.just(Duration.ofSeconds(1)); Mono<Duration> setting2 = Mono.just(Duration.ofSeconds(3)).delayElement(Duration.ofSeconds(5)); Mono<Duration> setting3 = Mono.just(Duration.ofSeconds(5)).delayElement(Duration.ofSeconds(15)); Flux<Duration> settings = Flux.concat(setting1, setting2, setting3) .doOnNext(d -> log.info("\nSending setting for a {}-second interval.\n", d.getSeconds())); disposable = this.rsocketRequester .route("channel") .data(settings) .retrieveFlux(Message.class) .subscribe(message -> log.info("Received: {} \n(Type 's' to stop.)", message)); } }
Example #11
Source File: ReleaseCommands.java From spring-cloud-skipper with Apache License 2.0 | 6 votes |
@ShellMethod(key = "release rollback", value = "Rollback the release to a previous or a specific release.") public String rollback( @ShellOption(help = "the name of the release to rollback") String releaseName, @ShellOption(help = "the specific release version to rollback to. " + "Not specifying the value rolls back to the previous release.", defaultValue = "0") int releaseVersion, @ShellOption(help = "the expression for rollback timeout", defaultValue = ShellOption.NULL) String timeoutExpression) { RollbackRequest rollbackRequest = new RollbackRequest(releaseName, releaseVersion); Duration duration = DurationUtils.convert(timeoutExpression); if (duration != null) { rollbackRequest.setTimeout(duration.toMillis()); } Release release = skipperClient.rollback(rollbackRequest); StringBuilder sb = new StringBuilder(); sb.append(release.getName() + " has been rolled back. Now at version v" + release.getVersion() + "."); return sb.toString(); }
Example #12
Source File: ReleaseCommands.java From spring-cloud-skipper with Apache License 2.0 | 6 votes |
@ShellMethod(key = "release upgrade", value = "Upgrade a release.") public Object upgrade( @ShellOption(help = "the name of the release to upgrade") String releaseName, @ShellOption(help = "the name of the package to use for the upgrade") String packageName, @ShellOption(help = "the version of the package to use for the upgrade, if not specified latest version will be used", defaultValue = ShellOption.NULL) String packageVersion, @ShellOption(help = "specify values in a YAML file", defaultValue = ShellOption.NULL) File file, @ShellOption(help = "the expression for upgrade timeout", defaultValue = ShellOption.NULL) String timeoutExpression, @ShellOption(help = "the comma separated set of properties to override during upgrade", defaultValue = ShellOption.NULL) String properties, @ShellOption(help = "force upgrade") boolean force, @ShellOption(help = "application names to force upgrade. If no specific list is provided, all the apps in the packages are force upgraded", defaultValue = ShellOption.NULL) String appNames) throws IOException { // Commented out until https://github.com/spring-cloud/spring-cloud-skipper/issues/263 is // addressed // assertMutuallyExclusiveFileAndProperties(file, properties); if (StringUtils.hasText(appNames)) { Assert.isTrue(force, "App names can be used only when the stream update is forced."); } Release release = skipperClient .upgrade(getUpgradeRequest(releaseName, packageName, packageVersion, file, properties, timeoutExpression, force, appNames)); StringBuilder sb = new StringBuilder(); sb.append(release.getName() + " has been upgraded. Now at version v" + release.getVersion() + "."); return sb.toString(); }
Example #13
Source File: PackageCommands.java From spring-cloud-skipper with Apache License 2.0 | 6 votes |
@ShellMethod(key = "package install", value = "Install a package.") public String install( @ShellOption(help = "name of the package to install") String packageName, @ShellOption(help = "version of the package to install, if not specified latest version will be used", defaultValue = ShellOption.NULL) String packageVersion, @ShellOption(help = "specify values in a YAML file", defaultValue = ShellOption.NULL) File file, @ShellOption(help = "the comma separated set of properties to override during install", defaultValue = ShellOption.NULL) String properties, @ShellOption(help = "the release name to use") String releaseName, @ShellOption(help = "the platform name to use", defaultValue = "default") String platformName) throws IOException { // Commented out until https://github.com/spring-cloud/spring-cloud-skipper/issues/263 is // addressed // assertMutuallyExclusiveFileAndProperties(file, properties); Release release = skipperClient .install(getInstallRequest(packageName, packageVersion, file, properties, releaseName, platformName)); return "Released " + release.getName() + ". Now at version v" + release.getVersion() + "."; }
Example #14
Source File: ManageSessionsCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 6 votes |
@ShellMethod("Displays active sessions") public String manageSessionsList() { Map<Long, ChannelSession> sessions = sessionManager.listSessions(); SimpleTable.SimpleTableBuilder builder = SimpleTable.builder() .column("Session Id").column("Local address").column("Remote address").column("Authenticated User"); for (ChannelSession value : sessions.values()) { builder.line(Arrays.asList( value.getServerSession().getIoSession().getId(), value.getServerSession().getIoSession().getLocalAddress(), value.getServerSession().getIoSession().getRemoteAddress(), sessionUserName(value) )); } return helper.renderTable(builder.build()); }
Example #15
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 #16
Source File: DemoCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 6 votes |
/** * Complex table example command * * @return principal */ @ShellMethod("Complex table command") public String tableComplex() { return helper.renderTable(SimpleTable.builder() .column("col1") .column("col2") .column("col3") .column("col4") .line(Arrays.asList("line1 col1", "line1 col2", "line1 col3", "line1 col4")) .line(Arrays.asList("line2 col1", "line2 col2", "line2 col3", "line2 col4")) .line(Arrays.asList("line3 col1", "line3 col2", "line3 col3", "line3 col4")) .line(Arrays.asList("line4 col1", "line4 col2", "line4 col3", "line4 col4")) .line(Arrays.asList("line5 col1", "line5 col2", "line5 col3", "line5 col4")) .line(Arrays.asList("line6 col1", "line6 col2", "line6 col3", "line6 col4")) .headerAligner(SimpleHorizontalAligner.right) .lineAligner(SimpleHorizontalAligner.left) .lineAligner(SimpleVerticalAligner.bottom) .useFullBorder(false) .borderStyle(BorderStyle.fancy_heavy_double_dash) .tableBuilderListener(tableBuilder -> { tableBuilder.addInnerBorder(BorderStyle.fancy_light_double_dash); tableBuilder.addOutlineBorder(BorderStyle.fancy_double); }).build()); }
Example #17
Source File: StacktraceCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
@ShellMethod(key = {"stacktrace"}, value = "Display the full stacktrace of the last error.") public void stacktrace() { Throwable lastError = TypePostProcessorResultHandler.THREAD_CONTEXT.get(); if (lastError != null) { lastError.printStackTrace(this.terminal.writer()); } }
Example #18
Source File: Postprocessors.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
@ShellMethod(value = "Display the available post processors") public CharSequence postprocessors() { AttributedStringBuilder result = new AttributedStringBuilder(); result.append("Available Post-Processors\n\n", AttributedStyle.BOLD); for (PostProcessor postProcessor : postProcessors) { result.append("\t" + postProcessor.getName() + ": ", AttributedStyle.BOLD); Class<?> cls = ((Class) ((ParameterizedType) (postProcessor.getClass().getGenericInterfaces())[0]).getActualTypeArguments()[0]); result.append(cls.getName() + "\n", AttributedStyle.DEFAULT); } return result; }
Example #19
Source File: SystemCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
@ShellMethod(key = "jvm-env", value = "List system environment.") public Object jvmEnv(boolean simpleView) { if (simpleView) { return buildSimple(System.getenv()); } return buildTable(System.getenv()).render(helper.terminalSize().getRows()); }
Example #20
Source File: ActuatorCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
/** * Loggers method * * @param action action to make * @param loggerName logger name for get or configure * @param loggerLevel logger level for configure * @return loggers */ @ShellMethod(key = "loggers", value = "Display or configure loggers.") @ShellMethodAvailability("loggersAvailability") public Object loggers( @ShellOption(value = {"-a", "--action"}, help = "Action to perform", defaultValue = "list") LoggerAction action, @ShellOption(value = {"-n", "--name"}, help = "Logger name for configuration or display", defaultValue = ShellOption.NULL) String loggerName, @ShellOption(value = {"-l", "--level"}, help = "Logger level for configuration", defaultValue = ShellOption.NULL) LogLevel loggerLevel) { if ((action == LoggerAction.get || action == LoggerAction.conf) && loggerName == null) { throw new IllegalArgumentException("Logger name is mandatory for '" + action + "' action"); } switch (action) { case get: LoggersEndpoint.LoggerLevels levels = loggers.loggerLevels(loggerName); return "Logger named [" + loggerName + "] : [configured: " + levels.getConfiguredLevel() + "]"; case conf: if (loggerLevel == null) { throw new IllegalArgumentException("Logger level is mandatory for '" + action + "' action"); } loggers.configureLogLevel(loggerName, loggerLevel); return "Logger named [" + loggerName + "] now configured to level [" + loggerLevel + "]"; default: // list return loggers.loggers(); } }
Example #21
Source File: Main.java From ICS-TestBed-Framework with GNU General Public License v3.0 | 5 votes |
@ShellMethod(value = "Set IEC104 Port.", group = "RTU", prefix="") public void rtuIEC104Port( @ShellOption(defaultValue = "2404") String port ){ try { if(Integer.parseInt(port) != DEFAULT_IEC104_PORT) this.portIEC104 = Integer.parseInt(port); }catch (NumberFormatException ex) { System.out.println("Error: Expecting an integer."); LOGGER.log(Level.WARNING, ex.toString(), ex); } }
Example #22
Source File: DemoCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
/** * Echo command * * @param message message to print * @param color color for the message * @return message */ @ShellMethod("Echo command") public String echo(String message, @ShellOption(defaultValue = ShellOption.NULL) PromptColor color) { if (color != null) { return new AttributedStringBuilder().append(message, AttributedStyle.DEFAULT.foreground(color.toJlineAttributedStyle())).toAnsi(); } return message; }
Example #23
Source File: ActuatorCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
/** * Environment method * * @param pattern pattern to filter with * @return env */ @ShellMethod(key = "env", value = "Display env endpoint.") @ShellMethodAvailability("envAvailability") public EnvironmentEndpoint.EnvironmentDescriptor env( @ShellOption(value = {"-p", "--pattern"}, defaultValue = ShellOption.NULL, help = "Pattern " + "to filter on") String pattern) { return env.environment(pattern); }
Example #24
Source File: ActuatorCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
/** * Audit method * * @param principal principal to filter with * @param type to filter with * @return audit */ @ShellMethod(key = "audit", value = "Display audit endpoint.") @ShellMethodAvailability("auditAvailability") public AuditEventsEndpoint.AuditEventsDescriptor audit( @ShellOption(value = {"-p", "--principal"}, defaultValue = ShellOption.NULL, help = "Principal to filter " + "on") String principal, @ShellOption(value = {"-t", "--type"}, defaultValue = ShellOption.NULL, help = "Type to filter on") String type) { return audit.events(principal, null, type); }
Example #25
Source File: DemoCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
/** * Interaction example command * * @return welcome message */ @ShellMethod("Welcome command") public String welcome() { helper.printInfo("You are now in the welcome command"); String name = helper.read("What's your name ?"); return "Hello, '" + name + "' !"; }
Example #26
Source File: StateMachineCommands.java From spring-statemachine-learning with Apache License 2.0 | 5 votes |
@ShellMethod(value = "Sends an event to a state machine", key = "sm select") public String select(final String name) { if (stateMachine != null) { return "have selected sm " ; } stateMachine = context.getBean(name, ObjectStateMachine.class); return "select sm :" + name; }
Example #27
Source File: DatastoreBookshelfExample.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@ShellMethod("Loads all books") public String findAllBooks() { Iterable<Book> books = this.bookRepository.findAll(); List<Book> bookList = new ArrayList<>(); books.forEach(bookList::add); return books.toString(); }
Example #28
Source File: ManageSessionsCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
@ShellMethod("Displays session") public String manageSessionsInfo(@ShellOption(value = {"-i", "--session-id"}) long sessionId) { ChannelSession session = sessionManager.getSession(sessionId); if (session == null) { return helper.getError("Session [" + sessionId + "] not found"); } return helper.getSuccess(sessionTable(session.getServerSession())); }
Example #29
Source File: ScannerCommand.java From java-examples with MIT License | 5 votes |
@ShellMethod(value = "Scan open ports for a specific IP address") public String scan( @ShellOption(help = "IP address") String ip, @ShellOption(help = "Specific port or port range, e.g. 1-1024") String port, @ShellOption(help = "Weather only open ports should be displayed") boolean displayOnlyOpen ) throws ExecutionException, InterruptedException { //Add all required ports into port scanner List<Future<ScannerService.ScanResult>> futureList; if (port.contains(PORT_SEPARATOR)) { String[] rangeLimits = port.split(PORT_SEPARATOR); futureList = addToScan(ip, range(Integer.parseInt(rangeLimits[0]), Integer.parseInt(rangeLimits[1]))); } else { futureList = addToScan(ip, Integer.parseInt(port)); } //Read and write results for (final Future<ScannerService.ScanResult> scanResultFuture : futureList) { ScannerService.ScanResult scanResult = scanResultFuture.get(); if (displayOnlyOpen) { if (scanResult.isOpen()) { System.out.println(scanResult); } } else { System.out.println(scanResult); } } return "DONE"; }
Example #30
Source File: SystemCommand.java From ssh-shell-spring-boot with Apache License 2.0 | 5 votes |
@ShellMethod(key = "jvm-properties", value = "List system properties.") public Object jvmProperties(boolean simpleView) { Map<String, String> map = System.getProperties().entrySet().stream().filter(e -> e.getKey() != null).collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue() != null ? e.getValue().toString() : "")); if (simpleView) { return buildSimple(map); } return buildTable(map).render(helper.terminalSize().getRows()); }