Search in sources :

Example 1 with FabricService

use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.

the class ContainerAddProfileAction method doExecute.

protected Object doExecute() throws Exception {
    FabricValidations.validateContainerName(container);
    FabricValidations.validateProfileNames(profiles);
    Container cont = FabricCommand.getContainer(fabricService, container);
    // we can add existing profiles
    Profile[] profs = FabricCommand.getExistingProfiles(fabricService, cont.getVersion(), this.profiles);
    cont.addProfiles(profs);
    return null;
}
Also used : Container(io.fabric8.api.Container) Profile(io.fabric8.api.Profile)

Example 2 with FabricService

use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.

the class ContainerChangeProfileAction method doExecute.

protected Object doExecute() throws Exception {
    FabricValidations.validateContainerName(container);
    FabricValidations.validateProfileNames(profiles);
    Container cont = FabricCommand.getContainer(fabricService, container);
    // we can only change to existing profiles
    Profile[] profs = FabricCommand.getExistingProfiles(fabricService, cont.getVersion(), profiles);
    cont.setProfiles(profs);
    return null;
}
Also used : Container(io.fabric8.api.Container) Profile(io.fabric8.api.Profile)

Example 3 with FabricService

use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.

the class WelcomeAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    String name = runtimeProperties.getRuntimeIdentity();
    String appName = runtimeProperties.getProperty("karaf.app.name", "JBoss Fuse");
    System.out.println("Welcome to " + appName);
    System.out.println("");
    // are we part of fabric?
    if (fabricService != null) {
        Container container = fabricService.getCurrentContainer();
        if (container != null) {
            boolean ensemble = container.isEnsembleServer();
            if (ensemble) {
                System.out.println("This container \u001B[1m" + container.getId() + "\u001B[0m is a Fabric ensemble server.");
            } else {
                System.out.println("This container \u001B[1m" + container.getId() + "\u001B[0m is joined to an existing Fabric.");
            }
        } else {
            System.out.println("This container \u001B[1m" + name + "\u001B[0m is a standalone container.");
        }
        String url = fabricService.getWebConsoleUrl();
        if (url != null) {
            System.out.println("Web management console available at: \u001B[1m" + url + "\u001B[0m");
        }
        System.out.println("");
    } else {
        // no we are standalone
        System.out.println("This container \u001B[1m" + name + "\u001B[0m is a standalone container.");
        System.out.println("");
        System.out.println("Create a new Fabric via '\u001B[1mfabric:create\u001B[0m'");
        System.out.println("or join an existing Fabric via '\u001B[1mfabric:join [someUrls]\u001B[0m'");
        System.out.println("");
    }
    return null;
}
Also used : Container(io.fabric8.api.Container)

Example 4 with FabricService

use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.

the class AbstractChildContainerCreateAction method preCreateContainer.

/**
 * Pre validates input before creating the container(s)
 *
 * @param name the name of the container to create
 * @throws IllegalArgumentException is thrown if input is invalid
 */
protected void preCreateContainer(String name) throws IllegalArgumentException {
    FabricValidations.validateContainerName(name);
    if (clusterService.getEnsembleContainers().isEmpty()) {
        return;
    }
    if (FabricCommand.doesContainerExist(fabricService, name)) {
        throw new IllegalArgumentException("A container with name " + name + " already exists.");
    }
    // get the profiles for the given version
    Version ver = version != null ? profileService.getRequiredVersion(version) : fabricService.getRequiredDefaultVersion();
    List<Profile> profiles = ver.getProfiles();
    // validate profiles exists before creating a new container
    Set<String> names = getProfileNames();
    for (String profile : names) {
        Profile prof = getProfile(profiles, profile, ver);
        if (prof == null) {
            throw new IllegalArgumentException("Profile " + profile + " with version " + ver.getId() + " does not exist.");
        }
        if (prof.isAbstract()) {
            throw new IllegalArgumentException("Profile " + profile + " with version " + ver.getId() + " is abstract and can not be associated to containers.");
        }
    }
    if (fabricService.getZookeeperUrl() == null) {
        throw new IllegalArgumentException("should start a zookeeper ensemble first.");
    }
}
Also used : Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Example 5 with FabricService

use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.

the class AbstractContainerCreateAction method preCreateContainer.

/**
 * Pre validates input before creating the container(s)
 *
 * @param name the name of the container to create
 * @throws IllegalArgumentException is thrown if input is invalid
 */
protected void preCreateContainer(String name) throws IllegalArgumentException {
    FabricValidations.validateContainerName(name);
    if (!isEnsembleServer) {
        if (clusterService.getEnsembleContainers().isEmpty()) {
            if (!isEnsembleServer) {
                throw new IllegalStateException("The use of the --ensemble-server option is mandatory when creating an initial container");
            }
            return;
        }
        if (FabricCommand.doesContainerExist(fabricService, name)) {
            throw new IllegalArgumentException("A container with name " + name + " already exists.");
        }
        // get the profiles for the given version
        Version ver = version != null ? profileService.getRequiredVersion(version) : fabricService.getRequiredDefaultVersion();
        List<Profile> profiles = ver.getProfiles();
        // validate profiles exists before creating a new container
        Set<String> names = getProfileNames();
        for (String profile : names) {
            Profile prof = getProfile(profiles, profile, ver);
            if (prof == null) {
                throw new IllegalArgumentException("Profile " + profile + " with version " + ver.getId() + " does not exist.");
            }
            if (prof.isAbstract()) {
                throw new IllegalArgumentException("Profile " + profile + " with version " + ver.getId() + " is abstract and can not be associated to containers.");
            }
        }
    }
    if (!isEnsembleServer && fabricService.getZookeeperUrl() == null) {
        throw new IllegalArgumentException("Either start a zookeeper ensemble or use --ensemble-server.");
    }
}
Also used : Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Aggregations

FabricService (io.fabric8.api.FabricService)80 Container (io.fabric8.api.Container)76 Test (org.junit.Test)52 Profile (io.fabric8.api.Profile)50 BundleContext (org.osgi.framework.BundleContext)29 Version (io.fabric8.api.Version)24 ArrayList (java.util.ArrayList)21 ProfileService (io.fabric8.api.ProfileService)19 HashMap (java.util.HashMap)16 CuratorFramework (org.apache.curator.framework.CuratorFramework)16 HashSet (java.util.HashSet)14 Map (java.util.Map)13 FabricException (io.fabric8.api.FabricException)12 IOException (java.io.IOException)12 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)11 Ignore (org.junit.Ignore)10 File (java.io.File)9 LinkedList (java.util.LinkedList)9 Path (javax.ws.rs.Path)8 FabricRequirements (io.fabric8.api.FabricRequirements)7