Search in sources :

Example 11 with Session

use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.

the class SshContainerProvider method destroy.

@Override
public void destroy(Container container) {
    CreateContainerMetadata metadata = container.getMetadata();
    if (!(metadata instanceof CreateSshContainerMetadata)) {
        throw new IllegalStateException("Container doesn't have valid create container metadata type");
    } else {
        CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
        CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
        Session session = null;
        String prevProvisionResult = container.getProvisionResult();
        try {
            String script = buildUninstallScript(container.getId(), options);
            session = createSession(options);
            container.setProvisionResult(Container.PROVISION_DELETING);
            runScriptOnHost(session, script);
        } catch (Throwable t) {
            LOGGER.error("Failed to stop container: " + container.getId(), t);
            throw new FabricException(t);
        } finally {
            if (session != null) {
                session.disconnect();
            }
        }
    }
}
Also used : CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) FabricException(io.fabric8.api.FabricException) Session(com.jcraft.jsch.Session)

Example 12 with Session

use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.

the class SshContainerProvider method create.

/**
 * Creates an {@link io.fabric8.api.Container} with the given name pointing to the specified zooKeeperUrl.
 */
public CreateSshContainerMetadata create(CreateSshContainerOptions options, CreationStateListener listener) {
    try {
        String path = options.getPath();
        String host = options.getHost();
        String ip = InetAddress.getByName(host).getHostAddress();
        if (host == null) {
            throw new IllegalArgumentException("Host name not specified.");
        }
        int port = options.getPort();
        if (port == -1) {
            port = 22;
        }
        String containerName = options.getName();
        CreateSshContainerMetadata metadata = new CreateSshContainerMetadata();
        metadata.setCreateOptions(options);
        metadata.setContainerName(containerName);
        String script = buildInstallAndStartScript(containerName, options);
        LOGGER.debug("Running script on host {}:\n{}", host, script);
        Session session = null;
        try {
            session = createSession(options);
            if (options.doUploadDistribution()) {
                uploadTo(session, options.getProxyUri().resolve("io/fabric8/fabric8-karaf/" + FabricConstants.FABRIC_VERSION + "/fabric8-karaf-" + FabricConstants.FABRIC_VERSION + ".zip").toURL(), "/tmp/fabric8-karaf-" + FabricConstants.FABRIC_VERSION + ".zip");
            }
            runScriptOnHost(session, script);
        } catch (Throwable ex) {
            metadata.setFailure(ex);
            throw new FabricException(ex);
        } finally {
            if (session != null) {
                session.disconnect();
            }
        }
        return metadata;
    } catch (Exception e) {
        throw FabricException.launderThrowable(e);
    }
}
Also used : FabricException(io.fabric8.api.FabricException) FabricException(io.fabric8.api.FabricException) IOException(java.io.IOException) Session(com.jcraft.jsch.Session)

Example 13 with Session

use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.

the class SshContainerProvider method stop.

@Override
public void stop(Container container) {
    CreateContainerMetadata metadata = container.getMetadata();
    if (!(metadata instanceof CreateSshContainerMetadata)) {
        throw new IllegalStateException("Container doesn't have valid create container metadata type");
    } else {
        CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
        CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
        Session session = null;
        try {
            String script = buildStopScript(container.getId(), options);
            session = createSession(options);
            container.setProvisionResult(Container.PROVISION_STOPPING);
            runScriptOnHost(session, script);
            container.setProvisionResult(Container.PROVISION_STOPPED);
        } catch (Throwable t) {
            LOGGER.error("Failed to stop container: " + container.getId(), t);
            throw new FabricException(t);
        } finally {
            if (session != null) {
                session.disconnect();
            }
        }
    }
}
Also used : CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) FabricException(io.fabric8.api.FabricException) Session(com.jcraft.jsch.Session)

Example 14 with Session

use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.

the class ContainerCreateCloud method doExecute.

@Override
protected Object doExecute() throws Exception {
    // validate input before creating containers
    preCreateContainer(name);
    FabricValidations.validateProfileNames(profiles);
    if (isEnsembleServer && newUserPassword == null) {
        newUserPassword = zookeeperPassword != null ? zookeeperPassword : fabricService.getZookeeperPassword();
    }
    CreateJCloudsContainerOptions.Builder builder = CreateJCloudsContainerOptions.builder().name(name).bindAddress(bindAddress).resolver(resolver).manualIp(manualIp).ensembleServer(isEnsembleServer).credential(credential).group(group).hardwareId(hardwareId).identity(identity).osFamily(osFamily).osVersion(osVersion).imageId(imageId).instanceType(instanceType).locationId(locationId).number(number).nodeOptions(CloudUtils.parseProviderOptions(options)).owner(owner).adminAccess(!disableAdminAccess).publicKeyFile(publicKeyFile).contextName(contextName).providerName(providerName).apiName(apiName).user(user).password(password).proxyUri(proxyUri != null ? proxyUri : fabricService.getMavenRepoURI()).zookeeperUrl(fabricService.getZookeeperUrl()).zookeeperPassword(isEnsembleServer && zookeeperPassword != null ? zookeeperPassword : fabricService.getZookeeperPassword()).jvmOpts(jvmOpts).environmentalVariable(environmentalVariables).version(version).withUser(newUser, newUserPassword, newUserRole).profiles(getProfileNames()).dataStoreProperties(getDataStoreProperties()).uploadDistribution(!distributionUploadDisable);
    if (path != null && !path.isEmpty()) {
        builder.path(path);
    }
    CreateContainerMetadata[] metadatas = fabricService.createContainers(builder.build(), new PrintStreamCreationStateListener(System.out));
    if (isEnsembleServer && metadatas != null && metadatas.length > 0 && metadatas[0].isSuccess()) {
        ShellUtils.storeZookeeperPassword(session, metadatas[0].getCreateOptions().getZookeeperPassword());
    }
    // display containers
    displayContainers(metadatas);
    return null;
}
Also used : PrintStreamCreationStateListener(io.fabric8.internal.PrintStreamCreationStateListener) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) CreateJCloudsContainerOptions(io.fabric8.service.jclouds.CreateJCloudsContainerOptions)

Example 15 with Session

use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by jboss-fuse.

the class ExtendedBurnIn method lotsOfClientLoad.

@Test
public void lotsOfClientLoad() throws Exception {
    startRestEndpoint();
    startHttpGateway();
    DetectingGateway gateway = startDetectingGateway();
    final ShutdownTracker tracker = new ShutdownTracker();
    // Run some concurrent load against the broker via the gateway...
    final StompJmsConnectionFactory factory = new StompJmsConnectionFactory();
    factory.setBrokerURI("tcp://localhost:" + gateway.getBoundPort());
    for (int client = 0; client < 10; client++) {
        new Thread("JMS Client: " + client) {

            @Override
            public void run() {
                while (tracker.attemptRetain()) {
                    try {
                        Connection connection = factory.createConnection();
                        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                        MessageConsumer consumer = session.createConsumer(session.createTopic("FOO"));
                        MessageProducer producer = session.createProducer(session.createTopic("FOO"));
                        producer.send(session.createTextMessage("Hello"));
                        consumer.receive(1000);
                        connection.close();
                    } catch (JMSException e) {
                        e.printStackTrace();
                    } finally {
                        tracker.release();
                    }
                }
            }
        }.start();
    }
    int httpPort = gateway.getBoundPort();
    final URL httpUrl = new URL("http://localhost:" + httpPort + "/hello/world");
    for (int client = 0; client < 10; client++) {
        new Thread("HTTP Client: " + client) {

            @Override
            public void run() {
                while (tracker.attemptRetain()) {
                    try {
                        InputStream is = httpUrl.openConnection().getInputStream();
                        try {
                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            int c = 0;
                            while ((c = is.read()) >= 0) {
                                baos.write(c);
                            }
                            assertEquals("Hello World!", new String(baos.toByteArray()));
                        } finally {
                            is.close();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        tracker.release();
                    }
                }
            }
        }.start();
    }
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // Lets monitor memory usage for 5 min..
    for (int i = 0; i < 60 * 5; i++) {
        Thread.sleep(900);
        Runtime.getRuntime().gc();
        Thread.sleep(100);
        long usedMB = ((Long) ((CompositeData) mBeanServer.getAttribute(new ObjectName("java.lang:type=Memory"), "HeapMemoryUsage")).get("used")).longValue() / (1024 * 1024);
        System.out.println("Using " + usedMB + " MB of heap.");
    }
    tracker.stop();
}
Also used : DetectingGateway(io.fabric8.gateway.handlers.detecting.DetectingGateway) InputStream(java.io.InputStream) CompositeData(javax.management.openmbean.CompositeData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) ObjectName(javax.management.ObjectName) ShutdownTracker(io.fabric8.common.util.ShutdownTracker) StompJmsConnectionFactory(org.fusesource.stomp.jms.StompJmsConnectionFactory) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)14 Session (io.fabric8.arquillian.kubernetes.Session)8 FabricException (io.fabric8.api.FabricException)7 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)7 Test (org.junit.Test)6 Session (com.jcraft.jsch.Session)5 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)5 File (java.io.File)5 Logger (io.fabric8.arquillian.kubernetes.log.Logger)4 Pod (io.fabric8.kubernetes.api.model.Pod)4 Service (io.fabric8.kubernetes.api.model.Service)4 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)4 ArrayList (java.util.ArrayList)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 FabricAuthenticationException (io.fabric8.api.FabricAuthenticationException)3 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)3 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)3 GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)3 MultiException (io.fabric8.utils.MultiException)3 HashMap (java.util.HashMap)3