Search in sources :

Example 6 with Server

use of io.fabric8.insight.metrics.model.Server in project docker-maven-plugin by fabric8io.

the class DockerFileBuilderTest method testEntryPointParams.

@Test
public void testEntryPointParams() {
    Arguments a = Arguments.Builder.get().withParam("java").withParam("-jar").withParam("/my-app-1.1.1.jar").withParam("server").build();
    String dockerfileContent = new DockerFileBuilder().entryPoint(a).content();
    assertThat(dockerfileToMap(dockerfileContent), hasEntry("ENTRYPOINT", "[\"java\",\"-jar\",\"/my-app-1.1.1.jar\",\"server\"]"));
}
Also used : Arguments(io.fabric8.maven.docker.config.Arguments) Test(org.junit.Test)

Example 7 with Server

use of io.fabric8.insight.metrics.model.Server in project docker-maven-plugin by fabric8io.

the class DockerFileBuilderTest method testEntryPointShell.

@Test
public void testEntryPointShell() {
    Arguments a = Arguments.Builder.get().withShell("java -jar /my-app-1.1.1.jar server").build();
    String dockerfileContent = new DockerFileBuilder().entryPoint(a).content();
    assertThat(dockerfileToMap(dockerfileContent), hasEntry("ENTRYPOINT", "java -jar /my-app-1.1.1.jar server"));
}
Also used : Arguments(io.fabric8.maven.docker.config.Arguments) Test(org.junit.Test)

Example 8 with Server

use of io.fabric8.insight.metrics.model.Server 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 9 with Server

use of io.fabric8.insight.metrics.model.Server 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)

Example 10 with Server

use of io.fabric8.insight.metrics.model.Server in project fabric8 by jboss-fuse.

the class ContainerEditJvmOptionsAction method doExecute.

protected Object doExecute() throws Exception {
    validateContainerName(container);
    if (!FabricCommand.doesContainerExist(fabricService, container)) {
        System.out.println("Container " + container + " does not exists!");
        return null;
    }
    Container containerInstance = FabricCommand.getContainerIfExists(fabricService, container);
    String type = containerInstance.getType();
    if (!"karaf".equals(type)) {
        System.out.println("Sorry, currently only \"karaf\" type container are supported");
        return null;
    }
    // read current jvm values
    FabricManager fabricManager = new FabricManager(fabricService);
    if (full) {
        String jmxUrl = null;
        JMXConnector connector = null;
        MBeanServerConnection remote = null;
        HashMap<String, String[]> authenticationData = null;
        jmxUrl = containerInstance.getJmxUrl();
        authenticationData = prepareAuthenticationData();
        try {
            connector = connectOrRetry(authenticationData, jmxUrl);
        } catch (Exception e) {
            username = null;
            password = null;
            System.out.println("Operation Failed. Check logs.");
            log.error("Unable to connect to JMX Server", e);
            return null;
        }
        ObjectName objName = new ObjectName(JAVA_LANG_OBJECT_NAME);
        try {
            remote = connector.getMBeanServerConnection();
            String[] arguments = (String[]) remote.getAttribute(objName, "InputArguments");
            String output = Arrays.toString(arguments);
            output = output.replaceAll(",", "");
            output = output.substring(1, output.length() - 1);
            System.out.println(output);
        } catch (Exception e) {
            System.out.println("Operation Failed. Check logs.");
            log.error("Unable to fetch child jvm opts", e);
        }
        try {
            connector.close();
        } catch (IOException e) {
            log.error("Errors closing remote MBean connection", e);
        }
    } else {
        try {
            String output = fabricManager.getJvmOpts(container);
            if ("Inapplicable".equals(output)) {
                String message = container + " jvmOpts cannot be handled within Fabric. You have to set required values directly in startup scripts.";
                System.out.println(message);
                log.error(message);
                return null;
            }
            if (jvmOptions == null) {
                System.out.println(output);
            } else {
                fabricManager.setJvmOpts(container, jvmOptions);
                System.out.println("Operation succeeded. New JVM flags will be loaded at the next start of " + container + " container");
                log.info("Updated JVM flags for container {}", container);
            }
        } catch (Exception e) {
            System.out.println("Operation Failed. Check logs.");
            log.error("Unable to set ssh jvm opts", e);
        }
    }
    return null;
}
Also used : Container(io.fabric8.api.Container) FabricManager(io.fabric8.core.jmx.FabricManager) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection) FabricAuthenticationException(io.fabric8.api.FabricAuthenticationException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName)

Aggregations

HashMap (java.util.HashMap)20 Test (org.junit.Test)19 IOException (java.io.IOException)18 File (java.io.File)9 Map (java.util.Map)9 ClientInvokerImpl (io.fabric8.dosgi.tcp.ClientInvokerImpl)8 ServerInvokerImpl (io.fabric8.dosgi.tcp.ServerInvokerImpl)8 ArrayList (java.util.ArrayList)8 Profile (io.fabric8.api.Profile)7 ServerInvoker (io.fabric8.dosgi.io.ServerInvoker)7 InvocationHandler (java.lang.reflect.InvocationHandler)7 DispatchQueue (org.fusesource.hawtdispatch.DispatchQueue)7 Container (io.fabric8.api.Container)6 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)6 Version (io.fabric8.api.Version)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 FabricException (io.fabric8.api.FabricException)4 RuntimeProperties (io.fabric8.api.RuntimeProperties)4 InputStream (java.io.InputStream)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3