Search in sources :

Example 11 with ShellTable

use of org.apache.karaf.shell.support.table.ShellTable in project karaf by apache.

the class GetCommand method execute.

@Override
public Object execute() throws Exception {
    ShellTable table = new ShellTable();
    table.column("ID");
    table.column("Flight");
    table.column("Customer");
    Booking booking = bookingService.get(id);
    table.addRow().addContent(booking.getId(), booking.getFlight(), booking.getCustomer());
    table.print(System.out);
    return null;
}
Also used : ShellTable(org.apache.karaf.shell.support.table.ShellTable) Booking(org.apache.karaf.examples.jdbc.api.Booking)

Example 12 with ShellTable

use of org.apache.karaf.shell.support.table.ShellTable in project karaf by apache.

the class ListUsersCommand method doExecute.

@Override
protected Object doExecute(BackingEngine engine) throws Exception {
    List<UserPrincipal> users = engine.listUsers();
    ShellTable table = new ShellTable();
    table.column("User Name");
    table.column("Group");
    table.column("Role");
    for (UserPrincipal user : users) {
        List<String> reportedRoles = new ArrayList<>();
        String userName = user.getName();
        for (GroupPrincipal group : engine.listGroups(user)) {
            reportedRoles.addAll(displayGroupRoles(engine, userName, group, table));
        }
        for (RolePrincipal role : engine.listRoles(user)) {
            String roleName = role.getName();
            if (reportedRoles.contains(roleName)) {
                continue;
            }
            reportedRoles.add(roleName);
            table.addRow().addContent(userName, "", roleName);
        }
        if (reportedRoles.size() == 0) {
            table.addRow().addContent(userName, "", "");
        }
    }
    table.print(System.out, !noFormat);
    return null;
}
Also used : ShellTable(org.apache.karaf.shell.support.table.ShellTable) GroupPrincipal(org.apache.karaf.jaas.boot.principal.GroupPrincipal) ArrayList(java.util.ArrayList) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) UserPrincipal(org.apache.karaf.jaas.boot.principal.UserPrincipal)

Example 13 with ShellTable

use of org.apache.karaf.shell.support.table.ShellTable in project karaf by apache.

the class ListRealmsCommand method execute.

@Override
public Object execute() throws Exception {
    ShellTable table = new ShellTable();
    table.column("Index");
    table.column("Realm Name");
    table.column("Login Module Class Name");
    List<JaasRealm> realms = getRealms(hidden);
    if (realms != null && realms.size() > 0) {
        int index = 1;
        for (JaasRealm realm : realms) {
            String realmName = realm.getName();
            AppConfigurationEntry[] entries = realm.getEntries();
            if (entries != null && entries.length > 0) {
                for (AppConfigurationEntry entry : entries) {
                    String moduleClass = (String) entry.getOptions().get(ProxyLoginModule.PROPERTY_MODULE);
                    table.addRow().addContent(index++, realmName, moduleClass);
                }
            }
        }
    }
    table.print(System.out, !noFormat);
    return null;
}
Also used : JaasRealm(org.apache.karaf.jaas.config.JaasRealm) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) ShellTable(org.apache.karaf.shell.support.table.ShellTable)

Example 14 with ShellTable

use of org.apache.karaf.shell.support.table.ShellTable in project karaf by apache.

the class ThreadsAction method execute.

@Override
public Object execute() throws Exception {
    Map<Long, ThreadInfo> threadInfos = new TreeMap<>();
    ThreadMXBean threadsBean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] infos;
    if (threadsBean.isObjectMonitorUsageSupported() && threadsBean.isSynchronizerUsageSupported()) {
        infos = threadsBean.dumpAllThreads(true, true);
    } else {
        infos = threadsBean.getThreadInfo(threadsBean.getAllThreadIds(), Integer.MAX_VALUE);
    }
    for (ThreadInfo info : infos) {
        threadInfos.put(info.getThreadId(), info);
    }
    if (id != null) {
        ThreadInfo ti = threadInfos.get(id);
        if (ti != null) {
            System.out.println("Thread " + ti.getThreadId() + " " + ti.getThreadName() + " " + ti.getThreadState());
            System.out.println("Stacktrace:");
            StackTraceElement[] st = ti.getStackTrace();
            for (StackTraceElement ste : st) {
                System.out.println(ste.getClassName() + "." + ste.getMethodName() + " line: " + ste.getLineNumber());
            }
        }
    } else if (list) {
        ShellTable table = new ShellTable();
        table.column("Id");
        table.column("Name");
        table.column("State");
        table.column("CPU time");
        table.column("Usr time");
        for (ThreadInfo thread : threadInfos.values()) {
            long id = thread.getThreadId();
            table.addRow().addContent(id, thread.getThreadName(), thread.getThreadState(), threadsBean.getThreadCpuTime(id) / 1000000, threadsBean.getThreadUserTime(id) / 1000000);
        }
        table.print(System.out, !noFormat);
    } else {
        ThreadGroup group = Thread.currentThread().getThreadGroup();
        while (group.getParent() != null) {
            group = group.getParent();
        }
        ThreadGroupData data = new ThreadGroupData(group, threadInfos);
        data.print();
    }
    return null;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) ShellTable(org.apache.karaf.shell.support.table.ShellTable) TreeMap(java.util.TreeMap)

Example 15 with ShellTable

use of org.apache.karaf.shell.support.table.ShellTable in project karaf by apache.

the class ListFeaturesCommand method doExecute.

protected void doExecute(FeaturesService featuresService) throws Exception {
    boolean needsLegend = false;
    ShellTable table = new ShellTable();
    table.column("Name");
    table.column("Version");
    table.column("Required");
    table.column("State");
    table.column("Repository");
    table.column("Description").maxSize(50);
    if (showBlacklisted) {
        table.column("Blacklisted");
    }
    table.emptyTableText(onlyInstalled ? "No features installed" : "No features available");
    List<Repository> repos = Arrays.asList(featuresService.listRepositories());
    for (Repository r : repos) {
        List<Feature> features = Arrays.asList(r.getFeatures());
        if (ordered) {
            features.sort(new FeatureComparator());
        }
        for (Feature f : features) {
            if (onlyInstalled && !featuresService.isInstalled(f)) {
                // Filter out not installed features if we only want to see the installed ones
                continue;
            }
            if (onlyRequired && !featuresService.isRequired(f)) {
                // Filter out not installed features if we only want to see the installed ones
                continue;
            }
            if (!showBlacklisted && f.isBlacklisted()) {
                // Filter out blacklisted
                continue;
            }
            if (!showHidden && f.isHidden()) {
                // Filter out hidden feature if not asked to display those
                continue;
            }
            Row row = table.addRow();
            row.addContent(f.getName(), f.getVersion(), featuresService.isRequired(f) ? "x" : "", featuresService.getState(f.getId()), r.getName(), f.getDescription());
            if (showBlacklisted) {
                row.addContent(f.isBlacklisted() ? "yes" : "no");
            }
            if (isInstalledViaDeployDir(r.getName())) {
                needsLegend = true;
            }
        }
    }
    table.print(System.out, !noFormat);
    if (needsLegend) {
        System.out.println("* Installed via deploy directory");
    }
}
Also used : Repository(org.apache.karaf.features.Repository) ShellTable(org.apache.karaf.shell.support.table.ShellTable) Row(org.apache.karaf.shell.support.table.Row) Feature(org.apache.karaf.features.Feature)

Aggregations

ShellTable (org.apache.karaf.shell.support.table.ShellTable)59 Row (org.apache.karaf.shell.support.table.Row)10 Col (org.apache.karaf.shell.support.table.Col)7 ArrayList (java.util.ArrayList)4 Bundle (org.osgi.framework.Bundle)4 Map (java.util.Map)3 Feature (org.apache.karaf.features.Feature)3 Repository (org.apache.karaf.features.Repository)3 List (java.util.List)2 TreeMap (java.util.TreeMap)2 Bus (org.apache.cxf.Bus)2 Booking (org.apache.karaf.examples.jdbc.api.Booking)2 Booking (org.apache.karaf.examples.jpa.Booking)2 MavenRepositoryURL (org.apache.karaf.maven.core.MavenRepositoryURL)2 Attribute (ddf.catalog.data.Attribute)1 Result (ddf.catalog.data.Result)1 SortByImpl (ddf.catalog.filter.impl.SortByImpl)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1