org.springframework.boot.actuate.logging.LoggersEndpoint#org.springframework.shell.standard.ShellMethod源码实例Demo

下面列出了org.springframework.boot.actuate.logging.LoggersEndpoint#org.springframework.shell.standard.ShellMethod 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sqlhelper   文件: ShowDatabaseCommands.java
@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);
    }
}
 
源代码2 项目: sqlhelper   文件: ShowDatabaseCommands.java
@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);
    }
}
 
源代码3 项目: sqlhelper   文件: ShowDatabaseCommands.java
@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);
    }
}
 
源代码4 项目: sqlhelper   文件: ShowDatabaseCommands.java
@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);
    }
}
 
源代码5 项目: spring-rsocket-demo   文件: RSocketShellClient.java
@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));
    }
}
 
@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());
}
 
源代码7 项目: ssh-shell-spring-boot   文件: ActuatorCommand.java
/**
 * 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();
}
 
源代码8 项目: spring-cloud-skipper   文件: ManifestCommands.java
@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;
}
 
源代码9 项目: ssh-shell-spring-boot   文件: DemoCommand.java
/**
 * 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());
}
 
源代码10 项目: ssh-shell-spring-boot   文件: DemoCommand.java
/**
 * 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());
}
 
源代码11 项目: ssh-shell-spring-boot   文件: DemoCommand.java
/**
 * 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());
}
 
源代码12 项目: spring-cloud-skipper   文件: ReleaseCommands.java
@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();
}
 
@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();
}
 
源代码14 项目: spring-cloud-skipper   文件: PackageCommands.java
@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() + ".";
}
 
源代码15 项目: spring-cloud-skipper   文件: ReleaseCommands.java
@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();
}
 
源代码16 项目: spring-cloud-skipper   文件: ReleaseCommands.java
@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();
}
 
源代码17 项目: sqlhelper   文件: ShowDatabaseCommands.java
@ShellMethod(key = "show table", value = "Show table detail")
public Table getTable(@ShellOption(help = "the connection configuration name") String connectionName,
                      @ShellOption(help = "the table name") String table) {
    Connection connection = getConnectionByConnectionConfigurationId(connectionName);
    try {
        DatabaseMetaData dbMetaData = connection.getMetaData();
        return new DatabaseLoader().loadTable(new DatabaseDescription(dbMetaData), Connections.getCatalog(connection), Connections.getSchema(connection), table);
    } catch (Throwable ex) {
        throw Throwables.wrapAsRuntimeException(ex);
    } finally {
        IOs.close(connection);
    }
}
 
源代码18 项目: spring-rsocket-demo   文件: RSocketShellClient.java
@PreDestroy
@ShellMethod("Logout and close your connection")
public void logout() {
    if (userIsLoggedIn()) {
        this.s();
        this.rsocketRequester.rsocket().dispose();
        log.info("Logged out.");
    }
}
 
源代码19 项目: spring-rsocket-demo   文件: RSocketShellClient.java
@ShellMethod("Send one request. One response will be printed.")
public void requestResponse() throws InterruptedException {
    if (userIsLoggedIn()) {
        log.info("\nSending one request. Waiting for one response...");
        Message message = this.rsocketRequester
                .route("request-response")
                .data(new Message(CLIENT, REQUEST))
                .retrieveMono(Message.class)
                .block();
        log.info("\nResponse was: {}", message);
    }
}
 
源代码20 项目: spring-rsocket-demo   文件: RSocketShellClient.java
@ShellMethod("Send one request. No response will be returned.")
public void fireAndForget() throws InterruptedException {
    if (userIsLoggedIn()) {
        log.info("\nFire-And-Forget. Sending one request. Expect no response (check server console log)...");
        this.rsocketRequester
                .route("fire-and-forget")
                .data(new Message(CLIENT, FIRE_AND_FORGET))
                .send()
                .block();
    }
}
 
源代码21 项目: spring-rsocket-demo   文件: RSocketShellClient.java
@ShellMethod("Send one request. Many responses (stream) will be printed.")
public void stream() {
    if (userIsLoggedIn()) {
        log.info("\n\n**** Request-Stream\n**** Send one request.\n**** Log responses.\n**** Type 's' to stop.");
        disposable = this.rsocketRequester
                .route("stream")
                .data(new Message(CLIENT, STREAM))
                .retrieveFlux(Message.class)
                .subscribe(message -> log.info("Response: {} \n(Type 's' to stop.)", message));
    }
}
 
源代码22 项目: spring-rsocket-demo   文件: RSocketShellClient.java
@ShellMethod("Stops Streams or Channels.")
public void s() {
    if (userIsLoggedIn() && null != disposable) {
        log.info("Stopping the current stream.");
        disposable.dispose();
        log.info("Stream stopped.");
    }
}
 
源代码23 项目: ICS-TestBed-Framework   文件: Main.java
@ShellMethod(value = "Start RTU.", group = "RTU")
public void rtu() {
    if (hmi != null) {
        System.out.println("Error: Currently configured as a HMI.");
    } else if (hist != null) {
        System.out.println("Error: Currently configured as a Historian.");
    }else if (rtu == null) {
        rtu = new RTU();
        mode = "RTU";
    }
}
 
源代码24 项目: ICS-TestBed-Framework   文件: Main.java
@ShellMethod(value = "Start HMI.", group = "HMI")
public void hmi() {
    if (rtu != null) {
        System.out.println("Error: Currently configured as a RTU.");
    } else if (hmi == null) {
        hmi = new HMI();
        if(mode.equals("HIST")) {
            mode += "HMI";
        }
        else{
            mode = "HMI";
        }
    }
}
 
源代码25 项目: ICS-TestBed-Framework   文件: Main.java
@ShellMethod(value = "Start data historian.", group = "Historian")
public void hist() {
    if (rtu != null) {
        System.out.println("Error: Currently configured as a RTU.");
    } else if (hist == null) {
        hist = new Historian();
        if(mode.equals("HMI")) {
            mode += "HIST";
        }else{
            mode = "HIST";
        }
    }
}
 
源代码26 项目: ICS-TestBed-Framework   文件: Main.java
@ShellMethod(value = "Set listen interface.", group = "RTU", prefix="")
public void rtuListen(
        @ShellOption(defaultValue = "127.0.0.1") String listen
) {
    try {
        if(!listen.equals(DEFAULT_LISTEN))
            this.listen = listen;

    }catch (NumberFormatException ex) {
        System.out.println("Error: Expecting an integer.");
        LOGGER.log(Level.WARNING, ex.toString(), ex);
    }
}
 
源代码27 项目: ICS-TestBed-Framework   文件: Main.java
@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);
    }
}
 
源代码28 项目: ICS-TestBed-Framework   文件: Main.java
@ShellMethod(value = "Run Configuration.", prefix="")
public void run(){
    if(mode.equals("N/A")) System.out.println("Error mode not set. Configure node as either: RTU, HMI or Historian.");
    if(rtu != null) rtu.start();
    if(hmi != null) hmi.start();
    if(hist != null) {
        try {
            hist.main("opc.tcp://127.0.0.1:8666");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
源代码29 项目: ICS-TestBed-Framework   文件: Main.java
@ShellMethod(value = "Show Current configuration.")
public void show() {
    if(rtu != null){
        System.out.println("IEC104 Enabled: True");
        if(hist != null) System.out.println("OPC-UA Enabled: True");
    }
    if(hmi!= null) hmi.show();
    if(hist != null) hist.show();
}
 
@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()));
}