use of io.fabric8.utils.TablePrinter in project fabric8 by jboss-fuse.
the class ClusterListAction method printCluster.
protected void printCluster(String dir, PrintStream out) throws Exception {
// do we have any clusters at all?
if (exists(getCurator(), dir) == null) {
return;
}
List<String> children = getAllChildren(getCurator(), dir);
Map<String, Map<String, ClusterNode>> clusters = new TreeMap<String, Map<String, ClusterNode>>();
for (String child : children) {
byte[] data = getCurator().getData().forPath(child);
if (data != null && data.length > 0) {
String text = new String(data).trim();
if (!text.isEmpty()) {
String clusterName = getClusterName(dir, child);
Map<String, ClusterNode> cluster = clusters.get(clusterName);
if (cluster == null) {
cluster = new TreeMap<String, ClusterNode>();
clusters.put(clusterName, cluster);
}
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> map = null;
try {
map = mapper.readValue(data, HashMap.class);
} catch (JsonParseException e) {
log.error("Error parsing JSON string: {}", text);
throw e;
}
ClusterNode node = null;
Object id = value(map, "id", "container");
if (id != null) {
Object agent = value(map, "container", "agent");
List services = (List) value(map, "services");
node = cluster.get(id);
if (node == null) {
node = new ClusterNode();
cluster.put(id.toString(), node);
}
if (services != null) {
if (!services.isEmpty()) {
for (Object service : services) {
node.services.add(getSubstitutedData(getCurator(), service.toString()));
}
node.masters.add(agent);
} else {
node.slaves.add(agent);
}
} else {
Object started = value(map, "started");
if (started == Boolean.TRUE) {
node.masters.add(agent);
} else {
node.slaves.add(agent);
}
}
}
}
}
}
TablePrinter table = new TablePrinter();
table.columns("cluster", "masters", "slaves", "services");
for (String clusterName : clusters.keySet()) {
Map<String, ClusterNode> nodes = clusters.get(clusterName);
table.row(clusterName, "", "", "", "");
for (String nodeName : nodes.keySet()) {
ClusterNode node = nodes.get(nodeName);
table.row(" " + nodeName, printList(node.masters), printList(node.slaves), printList(node.services));
}
}
table.print();
}
use of io.fabric8.utils.TablePrinter in project fabric8 by jboss-fuse.
the class AutoScaleStatusListAction method printStatus.
protected void printStatus(PrintStream out, AutoScaleStatus status) {
TablePrinter table = new TablePrinter();
table.columns("auto scale profile", "status", "message");
List<AutoScaleProfileStatus> profileStatuses = status.getProfileStatuses();
for (AutoScaleProfileStatus profile : profileStatuses) {
table.row(getStringOrBlank(profile.getProfile()), getStringOrBlank(profile.getStatus()), getStringOrBlank(profile.getMessage()));
}
table.print();
}
use of io.fabric8.utils.TablePrinter in project fabric8 by jboss-fuse.
the class ApplicationListAction method doExecute.
@Override
protected Object doExecute() throws Exception {
IOpenShiftConnection connection = getOrCreateConnection();
TablePrinter printer = new TablePrinter();
printer.columns("domain", "application id");
for (IDomain domain : connection.getDomains()) {
if (domainId == null || domainId.equals(domain.getId())) {
String displayDomain = domain.getId();
domain.refresh();
for (IApplication application : domain.getApplications()) {
printer.row(displayDomain, application.getName());
displayDomain = "";
}
}
}
printer.print();
return null;
}
use of io.fabric8.utils.TablePrinter in project fabric8 by jboss-fuse.
the class RequireProfileListAction method printRequirements.
@Override
protected void printRequirements(PrintStream out, FabricRequirements requirements) {
TablePrinter table = new TablePrinter();
table.columns("profile", "# minimum", "# maximum", "depends on");
List<ProfileRequirements> profileRequirements = requirements.getProfileRequirements();
for (ProfileRequirements profile : profileRequirements) {
table.row(profile.getProfile(), getStringOrBlank(profile.getMinimumInstances()), getStringOrBlank(profile.getMaximumInstances()), getStringOrBlank(profile.getDependentProfiles()));
}
table.print();
}
use of io.fabric8.utils.TablePrinter in project fabric8 by jboss-fuse.
the class ProfileListAction method printProfiles.
protected void printProfiles(ProfileService profileService, List<Profile> profiles, PrintStream out) {
TablePrinter table = new TablePrinter();
table.columns("id", "# containers", "parents");
for (Profile profile : profiles) {
String versionId = profile.getVersion();
String profileId = profile.getId();
// skip profiles that do not exists (they may have been deleted)
if (profileService.hasProfile(versionId, profileId) && (hidden || !profile.isHidden())) {
int active = fabricService.getAssociatedContainers(versionId, profileId).length;
String parents = Strings.join(profile.getParentIds(), " ");
table.row(profileId, activeContainerCountText(active), parents);
}
}
table.print();
}
Aggregations