org.apache.karaf.shell.support.table.ShellTable Java Examples

The following examples show how to use org.apache.karaf.shell.support.table.ShellTable. 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: 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 #2
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 #3
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 #4
Source File: NeighborStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
private static void printTransportState(final Transport transport, final ShellTable table) {
    if (transport == null) {
        return;
    }
    final NeighborTransportStateAugmentation state = transport.getState()
            .augmentation(NeighborTransportStateAugmentation.class);
    if (state == null) {
        return;
    }
    addHeader(table, "Transport state");

    final IpAddress remoteAddress = state.getRemoteAddress();
    final String stringRemoteAddress;
    if (remoteAddress.getIpv4Address() == null) {
        stringRemoteAddress = remoteAddress.getIpv6Address().getValue();
    } else {
        stringRemoteAddress = remoteAddress.getIpv4Address().getValue();
    }
    table.addRow().addContent("Remote Address", stringRemoteAddress);
    table.addRow().addContent("Remote Port", state.getRemotePort().getValue());
    table.addRow().addContent("Local Port", state.getLocalPort().getValue());
}
 
Example #5
Source File: NeighborStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
private static void printMessagesState(final State neighborState, final ShellTable table) {
    final BgpNeighborStateAugmentation state = neighborState.augmentation(BgpNeighborStateAugmentation.class);
    if (state == null) {
        return;
    }
    addHeader(table, "Messages state");
    final Messages messages = state.getMessages();
    table.addRow().addContent("Messages Received", "");

    final Received received = messages.getReceived();
    table.addRow().addContent("NOTIFICATION", received.getNOTIFICATION());
    table.addRow().addContent("UPDATE", received.getUPDATE());

    final Sent sent = messages.getSent();
    table.addRow().addContent("Messages Sent", "");
    table.addRow().addContent("NOTIFICATION", sent.getNOTIFICATION());
    table.addRow().addContent("UPDATE", sent.getUPDATE());
}
 
Example #6
Source File: NeighborStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
private static void printAfiSafiState(final AfiSafi afiSafi, final ShellTable table) {
    final NeighborAfiSafiStateAugmentation state = afiSafi.getState()
            .augmentation(NeighborAfiSafiStateAugmentation.class);
    addHeader(table, "AFI state");
    table.addRow().addContent("Family", afiSafi.getAfiSafiName().getSimpleName());
    table.addRow().addContent("Active", state.isActive());
    final Prefixes prefixes = state.getPrefixes();
    if (prefixes == null) {
        return;
    }
    table.addRow().addContent("Prefixes", "");
    table.addRow().addContent("Installed", prefixes.getInstalled());
    table.addRow().addContent("Sent", prefixes.getSent());
    table.addRow().addContent("Received", prefixes.getReceived());

}
 
Example #7
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 #8
Source File: PcepStateUtils.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
private static void showMessages(final ShellTable table, final Messages messages) {
    if (messages == null) {
        return;
    }
    addHeader(table, "Messages");
    table.addRow().addContent("Last Sent Msg Timestamp", messages.getLastSentMsgTimestamp());
    table.addRow().addContent("Received Msg Count", messages.getReceivedMsgCount());
    table.addRow().addContent("Sent Msg Count", messages.getSentMsgCount());
    table.addRow().addContent("Unknown Msg Received", messages.getUnknownMsgReceived());

    final StatefulMessagesStatsAug statefulMessages = messages.augmentation(StatefulMessagesStatsAug.class);
    if (statefulMessages == null) {
        return;
    }
    addHeader(table, " Stateful Messages");
    table.addRow().addContent("Last Received RptMsg Timestamp", statefulMessages
            .getLastReceivedRptMsgTimestamp());
    table.addRow().addContent("Received RptMsg", statefulMessages.getReceivedRptMsgCount());
    table.addRow().addContent("Sent Init Msg", statefulMessages.getSentInitMsgCount());
    table.addRow().addContent("Sent Upd Msg", statefulMessages.getSentUpdMsgCount());
}
 
Example #9
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 #10
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 #11
Source File: PcepStateUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static void showReplyMessages(final ShellTable table, final ReplyTime reply) {
    if (reply == null) {
        return;
    }
    addHeader(table, "Reply Messages");
    table.addRow().addContent("Average Time", reply.getAverageTime());
    table.addRow().addContent("Max Timet", reply.getMaxTime());
    table.addRow().addContent("Min Time", reply.getMinTime());
}
 
Example #12
Source File: GlobalStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static void displayAfiSafi(final AfiSafi afiSafi, final ShellTable table) {
    final GlobalAfiSafiStateAugmentation state = afiSafi.getState()
            .augmentation(GlobalAfiSafiStateAugmentation.class);
    addHeader(table, "AFI/SAFI state");
    table.addRow().addContent("Family", afiSafi.getAfiSafiName().getSimpleName());
    if (state == null) {
        return;
    }
    table.addRow().addContent("Total Paths", state.getTotalPaths());
    table.addRow().addContent("Total Prefixes", state.getTotalPrefixes());
}
 
Example #13
Source File: NeighborStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static void printTimerState(final Timers timers, final ShellTable table) {
    if (timers == null) {
        return;
    }

    final NeighborTimersStateAugmentation state = timers.getState()
            .augmentation(NeighborTimersStateAugmentation.class);
    if (state == null) {
        return;
    }
    addHeader(table, "Timer state");
    table.addRow().addContent("Negotiated Hold Time", state.getNegotiatedHoldTime());
    table.addRow().addContent("Uptime", state.getUptime().getValue());
}
 
Example #14
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 #15
Source File: PcepStateUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static void showNodeState(final ShellTable table, final String topologyId, final String nodeId,
        final PcepSessionState pcepSessionState) {
    addHeader(table, "Node state");
    table.addRow().addContent("Topology Id", topologyId);
    table.addRow().addContent("Node Id", nodeId);
    table.addRow().addContent("Session duration", pcepSessionState.getSessionDuration());
    table.addRow().addContent("Synchronized", pcepSessionState.isSynchronized());
    table.addRow().addContent("Delegated Lsp Count", pcepSessionState.getDelegatedLspsCount());
}
 
Example #16
Source File: NeighborStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static void printCapabilitiesState(final List<Class<? extends BgpCapability>> supportedCapabilities,
        final ShellTable table) {
    if (supportedCapabilities == null) {
        return;
    }
    addHeader(table, "Supported Capabilities");
    supportedCapabilities.forEach(capa -> table.addRow().addContent("", capa.getSimpleName()));
}
 
Example #17
Source File: PcepStateUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static void showCapabilities(final ShellTable table, final PeerCapabilities capa) {
    if (capa == null) {
        return;
    }
    final StatefulCapabilitiesStatsAug stateFulCapa = capa.augmentation(StatefulCapabilitiesStatsAug.class);
    if (stateFulCapa != null) {
        addHeader(table, "Stateful Capabilities");
        table.addRow().addContent("Stateful", stateFulCapa.isStateful());
        table.addRow().addContent("Active", stateFulCapa.isActive());
        table.addRow().addContent("Instantiation", stateFulCapa.isInstantiation());
    }

}
 
Example #18
Source File: PeerGroupStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static void displayState(final PeerGroup group, final ShellTable table) {
    addHeader(table, "Peer Group state");
    table.addRow().addContent("Peer Group Name", group.getPeerGroupName());
    final State state = group.getState();
    if (state == null) {
        return;
    }
    final PeerGroupStateAugmentation aug = state.augmentation(PeerGroupStateAugmentation.class);
    table.addRow().addContent("Total Prefixes", aug.getTotalPrefixes());
}
 
Example #19
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 #20
Source File: PcepStateUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static void showError(final ShellTable table, final Error error, final String errorMsgHeader) {
    if (error == null) {
        return;
    }
    addHeader(table, errorMsgHeader);
    table.addRow().addContent("Type", error.getErrorType());
    table.addRow().addContent("Value", error.getErrorValue());

}
 
Example #21
Source File: PcepStateUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static void showErrorMessages(final ShellTable table, final ErrorMessages error) {
    if (error == null) {
        return;
    }
    addHeader(table, "Error Messages");
    table.addRow().addContent("Sent Error Msg Count", error.getSentErrorMsgCount());
    table.addRow().addContent("Received Error Msg Count", error.getReceivedErrorMsgCount());

    showError(table, error.getLastSentError(), "Last Sent Error");
    showError(table, error.getLastReceivedError(), "Last Received Error");
}
 
Example #22
Source File: NeighborStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
static void addHeader(final ShellTable table, final String header) {
    table.addRow().addContent("                      ", "");
    table.addRow().addContent(header, "");
    table.addRow().addContent("======================", "");
}
 
Example #23
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 #24
Source File: PcepStateUtils.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
private static void addHeader(final ShellTable table, final String header) {
    table.addRow().addContent("                      ", "");
    table.addRow().addContent(header, "");
    table.addRow().addContent("======================", "");
}
 
Example #25
Source File: PcepStateUtils.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
private static void showPreferences(final ShellTable table, final Preferences preferences) {
    table.addRow().addContent("Session id", preferences.getSessionId());
    table.addRow().addContent("Ip Address", preferences.getIpAddress());
    table.addRow().addContent("Dead Timer", preferences.getDeadtimer());
    table.addRow().addContent("Keep Alive", preferences.getKeepalive());
}
 
Example #26
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;
}
 
Example #27
Source File: NeighborStateCliUtils.java    From bgpcep with Eclipse Public License 1.0 2 votes vote down vote up
private static void printAfiSafisState(final Collection<AfiSafi> afiSafis, final ShellTable table) {
    afiSafis.forEach(afiSafi -> printAfiSafiState(afiSafi, table));

}