Search in sources :

Example 6 with TablePrinter

use of io.fabric8.utils.TablePrinter in project fabric8 by jboss-fuse.

the class EnsembleListAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    TablePrinter printer = new TablePrinter();
    printer.column("id");
    List<String> containers = clusterService.getEnsembleContainers();
    if (containers != null) {
        for (String container : containers) {
            printer.row(container);
        }
    }
    printer.print();
    return null;
}
Also used : TablePrinter(io.fabric8.utils.TablePrinter)

Example 7 with TablePrinter

use of io.fabric8.utils.TablePrinter in project fabric8 by jboss-fuse.

the class VersionListAction method printVersions.

protected void printVersions(Container[] containers, List<String> versions, String defaultVersionId, PrintStream out) {
    TablePrinter table = new TablePrinter();
    table.columns("version", "default", "# containers", "description");
    List<String> invalidVersion = new ArrayList<String>();
    // they are sorted in the correct order by default
    for (String versionId : versions) {
        if (versionId != null && !versionId.isEmpty() && ALLOWED_PROFILE_NAMES_PATTERN.matcher(versionId).matches()) {
            boolean isDefault = versionId.equals(defaultVersionId);
            Version version = profileService.getRequiredVersion(versionId);
            int active = countContainersByVersion(containers, version);
            String description = version.getAttributes().get(Version.DESCRIPTION);
            table.row(version.getId(), (isDefault ? "true" : ""), activeContainerCountText(active), description);
        } else {
            invalidVersion.add(versionId);
        }
    }
    table.print();
    if (!invalidVersion.isEmpty()) {
        System.out.println("The following profile versions have been skipped since their names are not correct: " + invalidVersion.toString());
    }
}
Also used : CommandUtils.countContainersByVersion(io.fabric8.commands.support.CommandUtils.countContainersByVersion) Version(io.fabric8.api.Version) TablePrinter(io.fabric8.utils.TablePrinter) ArrayList(java.util.ArrayList)

Example 8 with TablePrinter

use of io.fabric8.utils.TablePrinter in project fabric8 by jboss-fuse.

the class WatchAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (start && stop) {
        System.err.println("Please use only one of --start and --stop options!");
        return null;
    }
    if (interval > 0) {
        System.out.println("Setting watch interval to " + interval + " ms");
        watcher.setInterval(interval);
    }
    if (stop) {
        System.out.println("Stopping watch");
        watcher.stop();
    }
    watcher.setUpload(upload);
    if (urls != null) {
        if (remove) {
            for (String url : urls) {
                watcher.remove(url);
            }
        } else {
            for (String url : urls) {
                watcher.add(url);
            }
        }
    }
    if (start) {
        System.out.println("Starting watch");
        watcher.start();
    }
    if (list) {
        // list the watched bundles.
        TablePrinter printer = new TablePrinter();
        printer.columns("url", "profile", "version", "bundle");
        for (String url : watcher.getWatchURLs()) {
            Map<ProfileVersionKey, Map<String, Parser>> profileArtifacts = watcher.getProfileArtifacts();
            if (profileArtifacts.size() > 0) {
                Set<Map.Entry<ProfileVersionKey, Map<String, Parser>>> entries = profileArtifacts.entrySet();
                for (Map.Entry<ProfileVersionKey, Map<String, Parser>> entry : entries) {
                    ProfileVersionKey key = entry.getKey();
                    Map<String, Parser> artifactMap = entry.getValue();
                    Set<Map.Entry<String, Parser>> artifactMapEntries = artifactMap.entrySet();
                    for (Map.Entry<String, Parser> artifactMapEntry : artifactMapEntries) {
                        String location = artifactMapEntry.getKey();
                        Parser parser = artifactMapEntry.getValue();
                        if (isSnapshot(parser) || watcher.wildCardMatch(location, url)) {
                            printer.row(url, key.getProfileId(), key.getVersion(), location);
                        }
                    }
                }
            } else {
                printer.row(url, "", "", "");
            }
        }
        printer.print();
    } else {
        List<String> urls = watcher.getWatchURLs();
        if (urls != null && urls.size() > 0) {
            System.out.println("Watched URLs: ");
            for (String url : watcher.getWatchURLs()) {
                System.out.println(url);
            }
        } else {
            System.out.println("No watched URLs");
        }
    }
    return null;
}
Also used : ProfileVersionKey(io.fabric8.agent.commands.support.ProfileVersionKey) Parser(io.fabric8.maven.util.Parser) TablePrinter(io.fabric8.utils.TablePrinter) Map(java.util.Map)

Example 9 with TablePrinter

use of io.fabric8.utils.TablePrinter in project fabric8 by jboss-fuse.

the class ArchetypeListAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    TablePrinter table = new TablePrinter();
    if (verbose) {
        table.columns("groupId", "artifactId", "version", "description");
    } else {
        table.columns("artifactId", "description");
    }
    for (Archetype archetype : archetypeService.listArchetypes()) {
        if (verbose) {
            table.row(archetype.groupId, archetype.artifactId, archetype.version, archetype.description);
        } else {
            // only list artifact id in short format
            table.row(archetype.artifactId, archetype.description);
        }
    }
    table.print();
    return null;
}
Also used : Archetype(io.fabric8.tooling.archetype.catalog.Archetype) TablePrinter(io.fabric8.utils.TablePrinter)

Example 10 with TablePrinter

use of io.fabric8.utils.TablePrinter in project fabric8 by jboss-fuse.

the class ContainerListAction method printContainersVerbose.

private void printContainersVerbose(Container[] containers, Version version, PrintStream out) {
    TablePrinter table = new TablePrinter();
    table.columns("id", "version", "type", "connected", "profiles", "blueprint", "spring", "provision status");
    for (Container container : containers) {
        if (CommandUtils.matchVersion(container, version)) {
            String indent = "";
            for (Container c = container; !c.isRoot(); c = c.getParent()) {
                indent += "  ";
            }
            // Mark local container with a star symbol
            String marker = "";
            if (container.getId().equals(fabricService.getCurrentContainer().getId())) {
                marker = "*";
            }
            String blueprintStatus = dataStore.getContainerAttribute(container.getId(), DataStore.ContainerAttribute.BlueprintStatus, "", false, false);
            String springStatus = dataStore.getContainerAttribute(container.getId(), DataStore.ContainerAttribute.SpringStatus, "", false, false);
            blueprintStatus = blueprintStatus.toLowerCase(Locale.ENGLISH);
            springStatus = springStatus.toLowerCase(Locale.ENGLISH);
            List<String> assignedProfiles = dataStore.getContainerProfiles(container.getId());
            table.row(indent + container.getId() + marker, container.getVersion().getId(), container.getType(), aliveText(container), assignedProfiles.get(0), blueprintStatus, springStatus, CommandUtils.status(container));
            // we want multiple profiles to be displayed on next lines
            for (int i = 1; i < assignedProfiles.size(); i++) {
                table.row("", "", "", "", assignedProfiles.get(i), "", "", "");
            }
        }
    }
    table.print();
}
Also used : Container(io.fabric8.api.Container) TablePrinter(io.fabric8.utils.TablePrinter)

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