Search in sources :

Example 31 with Container

use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.

the class ContainerStartAction method doExecute.

protected Object doExecute() throws Exception {
    Collection<String> expandedNames = super.expandGlobNames(containers);
    for (String containerName : expandedNames) {
        validateContainerName(containerName);
        Container found = FabricCommand.getContainer(fabricService, containerName);
        applyUpdatedCredentials(found);
        if (force || !found.isAlive()) {
            found.start(force);
        } else {
            System.err.println("Container " + containerName + " is already started");
        }
    }
    return null;
}
Also used : Container(io.fabric8.api.Container)

Example 32 with Container

use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.

the class ContainerStopAction method doExecute.

protected Object doExecute() throws Exception {
    Collection<String> expandedNames = super.expandGlobNames(containers);
    for (String containerName : expandedNames) {
        validateContainerName(containerName);
        if (!force && FabricCommand.isPartOfEnsemble(fabricService, containerName)) {
            System.out.println("Container is part of the ensemble. If you still want to stop it, please use --force option.");
            return null;
        }
        Container found = FabricCommand.getContainer(fabricService, containerName);
        applyUpdatedCredentials(found);
        if (found.isAlive()) {
            found.stop(force);
            found = FabricCommand.getContainer(fabricService, containerName);
            if (!found.isAlive()) {
                System.out.println("Container '" + found.getId() + "' stopped successfully.");
            } else {
                // In case of SSH container we can have timing issue with this command
                // so we will poll the status of container for a fixed number of times
                // if it's not stopped then we will output the message, otherwise we will continue normally
                int count = 0;
                boolean alive = true;
                for (count = 0; count < attemptNumber; count++) {
                    found = FabricCommand.getContainer(fabricService, containerName);
                    if (!found.isAlive()) {
                        alive = false;
                    } else {
                        Thread.sleep(pollingInterval);
                    }
                }
                if (alive) {
                    System.out.println("Container '" + found.getId() + "' was not stopped successfully, something went wrong. Check Logs.");
                }
            }
        } else {
            System.err.println("Container '" + found.getId() + "' already stopped.");
        }
    }
    return null;
}
Also used : Container(io.fabric8.api.Container)

Example 33 with Container

use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.

the class ProfileScaleAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    try {
        FabricValidations.validateProfileName(name);
    } catch (IllegalArgumentException e) {
        // we do not want exception in the server log, so print the error message to the console
        System.out.println(e.getMessage());
        return 1;
    }
    fabricService.scaleProfile(name, count);
    ProfileRequirements profileRequirements = fabricService.getRequirements().getOrCreateProfileRequirement(name);
    Integer minimumInstances = profileRequirements.getMinimumInstances();
    int size = Containers.containersForProfile(fabricService.getContainers(), name).size();
    PrintStream output = System.out;
    output.println("Profile " + name + " " + (minimumInstances != null ? "now requires " + minimumInstances + " container(s)" : "does not require any containers") + " currently has " + size + " container(s) running");
    return null;
}
Also used : PrintStream(java.io.PrintStream) ProfileRequirements(io.fabric8.api.ProfileRequirements)

Example 34 with Container

use of io.fabric8.maven.docker.model.Container 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 35 with Container

use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.

the class ContainerListAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    Container[] containers = fabricService.getContainers();
    // filter unwanted containers, and split list into parent/child,
    // so we can sort the list as we want it
    containers = CommandUtils.filterContainers(containers, filter);
    // we want the list to be sorted
    containers = CommandUtils.sortContainers(containers);
    Version ver = null;
    if (version != null) {
        // limit containers to only with same version
        ver = profileService.getRequiredVersion(version);
    }
    if (verbose) {
        printContainersVerbose(containers, ver, System.out);
    } else {
        printContainers(containers, ver, System.out);
    }
    return null;
}
Also used : Container(io.fabric8.api.Container) Version(io.fabric8.api.Version)

Aggregations

Container (io.fabric8.api.Container)139 Test (org.junit.Test)85 FabricService (io.fabric8.api.FabricService)56 Container (io.fabric8.kubernetes.api.model.Container)56 ArrayList (java.util.ArrayList)42 IOException (java.io.IOException)40 Profile (io.fabric8.api.Profile)37 HashMap (java.util.HashMap)36 Map (java.util.Map)32 FabricException (io.fabric8.api.FabricException)27 File (java.io.File)27 Pod (io.fabric8.kubernetes.api.model.Pod)24 BundleContext (org.osgi.framework.BundleContext)24 Version (io.fabric8.api.Version)23 HashSet (java.util.HashSet)20 List (java.util.List)20 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)19 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)17 LinkedList (java.util.LinkedList)17 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)16