Java Code Examples for org.apache.karaf.shell.support.table.ShellTable#print()

The following examples show how to use org.apache.karaf.shell.support.table.ShellTable#print() . 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: Query.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
private void executeTupleQuery(Repository repository, String queryString) {
    try (RepositoryConnection conn = repository.getConnection()) {
        TupleQuery query = conn.prepareTupleQuery(queryString);
        TupleQueryResult result = query.evaluate();

        List<String> bindingNames = result.getBindingNames();

        ShellTable table = new ShellTable();
        bindingNames.forEach(table::column);
        table.emptyTableText("\n");

        String[] content = new String[bindingNames.size()];

        result.forEach(bindings -> {
            IntStream.range(0, bindingNames.size()).forEach(index -> {
                Optional<Value> valueOpt = bindings.getValue(bindingNames.get(index));
                String value = valueOpt.isPresent() ? valueOpt.get().stringValue() : "";
                content[index] = value;
            });

            table.addRow().addContent(content);
        });

        table.print(System.out);
    }
}
 
Example 2
Source File: RepositoryList.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Object execute() throws Exception {

    ShellTable table = new ShellTable();
    table.column("ID");
    table.column("Title");
    table.emptyTableText("No Repositories");

    if (repositoryManager != null) {
        repositoryManager.getAllRepositories().forEach((repoID, repo) -> {
            RepositoryConfig config = repo.getConfig();
            table.addRow().addContent(config.id(), config.title());
        });
    }

    table.print(System.out);
    return null;
}
 
Example 3
Source File: ApplicationList.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute() throws Exception {
    System.out.println();
    ShellTable table = new ShellTable();
    table.column("id");
    table.column("name");
    table.column("up");
    table.column("state");
    table.column("expected state");

    managementContext.getApplications().forEach((application -> table.addRow().addContent(
            application.getApplicationId(),
            application.getDisplayName(),
            application.sensors().get(Attributes.SERVICE_UP).toString(),
            application.sensors().get(Attributes.SERVICE_STATE_ACTUAL).toString(),
            application.sensors().get(Attributes.SERVICE_STATE_EXPECTED).toString()
    )));
    table.print(System.out, true);
    System.out.println();
    return null;
}
 
Example 4
Source File: NeighborStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
static void displayNeighborOperationalState(@NonNull final String neighborId,
        @NonNull final Neighbor neighbor, @NonNull final PrintStream stream) {
    final State neighborState = neighbor.getState();
    if (neighborState == null) {
        stream.println(String.format("No BgpSessionState found for [%s]", neighborId));
        return;
    }

    final ShellTable table = new ShellTable();
    table.column("Attribute").alignLeft();
    table.column("Value").alignLeft();
    table.addRow().addContent("Neighbor Address", neighborId);

    final NeighborStateAugmentation stateAug = neighborState.augmentation(NeighborStateAugmentation.class);
    if (stateAug != null) {
        table.addRow().addContent("Session State", stateAug.getSessionState());
        printCapabilitiesState(stateAug.getSupportedCapabilities(), table);
    }

    printTimerState(neighbor.getTimers(), table);
    printTransportState(neighbor.getTransport(), table);
    printMessagesState(neighborState, table);
    printAfiSafisState(neighbor.getAfiSafis().nonnullAfiSafi().values(), table);

    table.print(stream);
}
 
Example 5
Source File: GlobalStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
static void displayRibOperationalState(@NonNull final String ribId, @NonNull final Global global,
        @NonNull final PrintStream stream) {
    final State globalState = global.getState();

    final ShellTable table = new ShellTable();
    table.column("Attribute").alignLeft();
    table.column("Value").alignLeft();

    addHeader(table, "RIB state");
    table.addRow().addContent("Router Id", ribId);
    table.addRow().addContent("As", globalState.getAs());
    table.addRow().addContent("Total Paths", globalState.getTotalPaths());
    table.addRow().addContent("Total Prefixes", globalState.getTotalPrefixes());
    global.getAfiSafis().nonnullAfiSafi().values().forEach(afiSafi -> displayAfiSafi(afiSafi, table));
    table.print(stream);
}
 
Example 6
Source File: ListBussesCommand.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute() throws Exception {
    List<Bus> busses = getBusses();

    ShellTable table = new ShellTable();
    if (terminal != null && terminal.getWidth() > 0) {
        table.size(terminal.getWidth());
    }
    table.column("Name");
    table.column("State");

    for (Bus bus : busses) {
        String name = bus.getId();
        String state = bus.getState().toString();
        table.addRow().addContent(name, state);
    }
    table.print(System.out, !noFormat);
    return null;
}
 
Example 7
Source File: PcepStateUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static void displayNodeState(
        final String topologyId,
        final String nodeId,
        final PcepSessionState pcepSessionState,
        final PrintStream stream) {
    final ShellTable table = new ShellTable();
    table.column("Attribute").alignLeft();
    table.column("Value").alignLeft();

    showNodeState(table, topologyId, nodeId, pcepSessionState);

    addHeader(table, "Local preferences");
    final LocalPref localPref = pcepSessionState.getLocalPref();
    showPreferences(table, localPref);
    final PcepEntityIdStatsAug entAug = localPref.augmentation(PcepEntityIdStatsAug.class);
    if (entAug != null) {
        table.addRow().addContent("Speaker Entity Identifier",
                Arrays.toString(entAug.getSpeakerEntityIdValue()));
    }

    addHeader(table, "Peer preferences");
    final PeerPref peerPref = pcepSessionState.getPeerPref();
    showPreferences(table, peerPref);

    showCapabilities(table, pcepSessionState.getPeerCapabilities());

    final Messages messages = pcepSessionState.getMessages();
    showMessages(table, messages);

    final ErrorMessages error = messages.getErrorMessages();
    showErrorMessages(table, error);

    final ReplyTime reply = messages.getReplyTime();
    showReplyMessages(table, reply);

    table.print(stream);
}
 
Example 8
Source File: PeerGroupStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
static void displayPeerOperationalState(@NonNull final Collection<PeerGroup> peerGroupList,
        @NonNull final PrintStream stream) {
    final ShellTable table = new ShellTable();
    table.column("Attribute").alignLeft();
    table.column("Value").alignLeft();

    peerGroupList.forEach(group -> displayState(group, table));
    table.print(stream);
}
 
Example 9
Source File: EntityInfo.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Override
public Object execute() throws Exception {
    Optional<Entity> entity = Optional.ofNullable(managementContext.getEntityManager().getEntity(id));
    if(!entity.isPresent()){
        System.err.println(String.format("Entity [%s] not found", id));
        return null;
    }
    printHeader("Basic Information");
    final ShellTable infoTable = new ShellTable();
    infoTable.column("").bold();
    infoTable.column("");
    infoTable.noHeaders();
    infoTable.addRow().addContent("Application Id", entity.get().getApplicationId());
    infoTable.addRow().addContent("Application Name", entity.get().getApplication().getDisplayName());
    infoTable.addRow().addContent("Name", entity.get().getDisplayName());
    infoTable.addRow().addContent("Id", id);
    infoTable.addRow().addContent("UP", entity.get().sensors().get(Attributes.SERVICE_UP));
    infoTable.addRow().addContent("State", entity.get().sensors().get(Attributes.SERVICE_STATE_ACTUAL));
    infoTable.addRow().addContent("Expected State", entity.get().sensors().get(Attributes.SERVICE_STATE_EXPECTED));
    infoTable.print(System.out, true);
    if (displayChildren || displayAll) {
        printHeader("Child Information");
        final ShellTable childrenTable = new ShellTable();
        childrenTable.column("id");
        childrenTable.column("name");

        entity.get().getChildren().forEach(child -> childrenTable.addRow().addContent(child.getId(), child.getDisplayName()));

        childrenTable.print(System.out, true);
    }
    if (displaySensors || displayAll) {
        printHeader("Sensor Information");
        final ShellTable sensorTable = new ShellTable();
        sensorTable.column("name");
        sensorTable.column("value");
        sensorTable.column("description");

        entity.get().getEntityType().getSensors().stream()
                .filter(AttributeSensor.class::isInstance).map(AttributeSensor.class::cast)
                .forEach(sensor -> sensorTable.addRow().addContent(sensor.getName(), entity.get().getAttribute(sensor), sensor.getDescription()));

        sensorTable.print(System.out, true);
    }

    if (displayConfig || displayAll) {
        printHeader("Config Information");
        final ShellTable configTable = new ShellTable();
        configTable.column("name");
        configTable.column("value");
        configTable.column("description");

        entity.get().getEntityType().getConfigKeys().stream()
                .forEach(configKey -> configTable.addRow().addContent(configKey.getName(), entity.get().getConfig(configKey), configKey.getDescription()));
        configTable.print(System.out, true);
    }

    if (displayBlueprint || displayAll) {
        final Optional<String> bluePrint = Optional.ofNullable(BrooklynTags.findFirst(BrooklynTags.YAML_SPEC_KIND, entity.get().tags().getTags()))
                .map(BrooklynTags.NamedStringTag::getContents);
        if (bluePrint.isPresent()) {
            printHeader("Blueprint Information");
            System.out.println("---");
            System.out.print(bluePrint.get());
            System.out.println("...");
        }
    }

    System.out.println();
    return null;
}
 
Example 10
Source File: CqlExecuter.java    From Karaf-Cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public Object doExecute() throws Exception {

	Session session = (Session) this.session
			.get(SessionParameter.CASSANDRA_SESSION);

	if (session == null) {
		System.err
				.println("No active session found--run the connect command first");
		return null;
	}

	if (cql == null && fileLocation == null) {
		System.err
				.println("Either cql skript or a filename must be given.");
		return null;
	}

	if (cql == null && fileLocation != null) {
		byte[] encoded;
		InputStream is = fileLocation.toURL().openStream ();
		try (ByteArrayOutputStream os = new ByteArrayOutputStream();) {
	        byte[] buffer = new byte[0xFFFF];

	        for (int len; (len = is.read(buffer)) != -1;)
	            os.write(buffer, 0, len);

	        os.flush();

	        encoded = os.toByteArray();
	    } catch (IOException e) {
	    	System.err.println("Can't read fileinput");
	        return null;
	    }

		cql = new String(encoded, Charset.defaultCharset());
	} else {
		int start = 0;
		int end = 0;
		if (cql.startsWith("\"")) {
			//need to remove quotes first
			start = 1;
			if (cql.endsWith("\"")) {
				end = cql.lastIndexOf("\"");
			}
			cql = cql.substring(start, end);
		}
	}

	ShellTable table = new ShellTable();

	ResultSet execute = session.execute(cql);

	cassandraRowFormater(table, execute);

	table.print(System.out);
	
	return null;
}