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;
}
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;
}
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;
}
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;
}
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");
}
}
Aggregations