Search in sources :

Example 1 with TablePrinter

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();
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) JsonParseException(com.fasterxml.jackson.core.JsonParseException) TablePrinter(io.fabric8.utils.TablePrinter) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with TablePrinter

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();
}
Also used : TablePrinter(io.fabric8.utils.TablePrinter) AutoScaleProfileStatus(io.fabric8.api.AutoScaleProfileStatus)

Example 3 with TablePrinter

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;
}
Also used : IDomain(com.openshift.client.IDomain) IApplication(com.openshift.client.IApplication) IOpenShiftConnection(com.openshift.client.IOpenShiftConnection) TablePrinter(io.fabric8.utils.TablePrinter)

Example 4 with TablePrinter

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();
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements) TablePrinter(io.fabric8.utils.TablePrinter)

Example 5 with TablePrinter

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();
}
Also used : TablePrinter(io.fabric8.utils.TablePrinter) Profile(io.fabric8.api.Profile)

Aggregations

TablePrinter (io.fabric8.utils.TablePrinter)14 Container (io.fabric8.api.Container)3 IDomain (com.openshift.client.IDomain)2 IOpenShiftConnection (com.openshift.client.IOpenShiftConnection)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IApplication (com.openshift.client.IApplication)1 ProfileVersionKey (io.fabric8.agent.commands.support.ProfileVersionKey)1 AutoScaleProfileStatus (io.fabric8.api.AutoScaleProfileStatus)1 Profile (io.fabric8.api.Profile)1 ProfileRequirements (io.fabric8.api.ProfileRequirements)1 Version (io.fabric8.api.Version)1 GitVersion (io.fabric8.api.commands.GitVersion)1 CommandUtils.countContainersByVersion (io.fabric8.commands.support.CommandUtils.countContainersByVersion)1 Parser (io.fabric8.maven.util.Parser)1 Archetype (io.fabric8.tooling.archetype.catalog.Archetype)1 HashMap (java.util.HashMap)1 List (java.util.List)1