Search in sources :

Example 16 with Stop

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

the class ExtendedCreateChildContainerTest method testContainerWithPasswordChange.

@Test
public // [FABRIC-482] Fabric doesn't allow remote host user/password to be changed once the container is created.
void testContainerWithPasswordChange() throws Exception {
    System.out.println(CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning"));
    // System.out.println(executeCommand("shell:info"));
    // System.out.println(executeCommand("fabric:info"));
    // System.out.println(executeCommand("fabric:profile-list"));
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        Set<Container> containers = ContainerBuilder.child(1).withName("basic_cnt_d").assertProvisioningResult().build(fabricService);
        try {
            Container cntD = containers.iterator().next();
            System.out.println(CommandSupport.executeCommands("jaas:manage --realm karaf --module io.fabric8.jaas.ZookeeperLoginModule", "jaas:userdel admin", "jaas:useradd admin newpassword", "jaas:roleadd admin admin", "jaas:update"));
            System.out.println(CommandSupport.executeCommand("fabric:container-stop --user admin --password newpassword " + cntD.getId()));
            ProvisionSupport.containersAlive(containers, false, ProvisionSupport.PROVISION_TIMEOUT);
            containers.remove(cntD);
        } finally {
            ContainerBuilder.stop(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 17 with Stop

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

the class AbstractManagedContainer method stop.

@Override
public final synchronized void stop() throws LifecycleException {
    assertNotDestroyed();
    try {
        if (state == State.STARTED) {
            doStop(configuration);
            state = State.STOPPED;
        }
    } catch (Exception ex) {
        throw new LifecycleException("Cannot stop container", ex);
    }
}
Also used : LifecycleException(io.fabric8.runtime.container.LifecycleException) LifecycleException(io.fabric8.runtime.container.LifecycleException) IOException(java.io.IOException)

Example 18 with Stop

use of io.fabric8.arquillian.kubernetes.event.Stop in project strimzi by strimzi.

the class ClusterControllerTest method startStop.

/**
 * Does the CC start and then stop a verticle per namespace?
 * @param context
 * @param namespaces
 */
private void startStop(TestContext context, String namespaces) {
    AtomicInteger numWatchers = new AtomicInteger(0);
    KubernetesClient client = mock(KubernetesClient.class);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(client.configMaps()).thenReturn(mockCms);
    List<String> namespaceList = asList(namespaces.split(" *,+ *"));
    for (String namespace : namespaceList) {
        MixedOperation mockNamespacedCms = mock(MixedOperation.class);
        when(mockNamespacedCms.watch(any())).thenAnswer(invo -> {
            numWatchers.incrementAndGet();
            Watch mockWatch = mock(Watch.class);
            doAnswer(invo2 -> {
                ((Watcher) invo.getArgument(0)).onClose(null);
                return null;
            }).when(mockWatch).close();
            return mockWatch;
        });
        when(mockNamespacedCms.withLabels(any())).thenReturn(mockNamespacedCms);
        when(mockCms.inNamespace(namespace)).thenReturn(mockNamespacedCms);
    }
    Async async = context.async();
    Map<String, String> env = new HashMap<>();
    env.put(ClusterControllerConfig.STRIMZI_NAMESPACE, namespaces);
    env.put(ClusterControllerConfig.STRIMZI_CONFIGMAP_LABELS, STRIMZI_IO_KIND_CLUSTER);
    env.put(ClusterControllerConfig.STRIMZI_FULL_RECONCILIATION_INTERVAL_MS, "120000");
    Main.run(vertx, client, true, env).setHandler(ar -> {
        context.assertNull(ar.cause(), "Expected all verticles to start OK");
        async.complete();
    });
    async.await();
    context.assertEquals(namespaceList.size(), vertx.deploymentIDs().size(), "A verticle per namespace");
    List<Async> asyncs = new ArrayList<>();
    for (String deploymentId : vertx.deploymentIDs()) {
        Async async2 = context.async();
        asyncs.add(async2);
        vertx.undeploy(deploymentId, ar -> {
            context.assertNull(ar.cause(), "Didn't expect error when undeploying verticle " + deploymentId);
            async2.complete();
        });
    }
    for (Async async2 : asyncs) {
        async2.await();
    }
    if (numWatchers.get() > namespaceList.size()) {
        context.fail("Looks like there were more watchers than namespaces");
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) Watch(io.fabric8.kubernetes.client.Watch) ArrayList(java.util.ArrayList) Watcher(io.fabric8.kubernetes.client.Watcher) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation)

Example 19 with Stop

use of io.fabric8.arquillian.kubernetes.event.Stop in project fabric8 by fabric8io.

the class SuiteListener method stop.

public void stop(@Observes(precedence = -100) AfterSuite event, Logger logger) {
    controlEvent.fire(new Stop(session));
    session.destroy();
}
Also used : Stop(io.fabric8.arquillian.kubernetes.event.Stop)

Example 20 with Stop

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

the class DeploymentAgent method handleRestartJvmFlag.

/**
 * Adds support for a directive to force a restart upon the first assignment of a specific profile to a container.
 * It creates an entry in zk so that a subsequent modification to the same profile, will not trigger a jvm restart.
 * The behavior is useful for situation when a profile provision .jars in lib/ folder, that are picked up only at
 * jvm boot time.
 *
 * @param profile
 * @param restart
 * @return
 */
protected boolean handleRestartJvmFlag(Profile profile, AtomicBoolean restart) {
    boolean result = false;
    List<String> profilesRequiringRestart = new ArrayList<>();
    ServiceReference<CuratorFramework> curatorServiceReference = systemBundleContext.getServiceReference(CuratorFramework.class);
    ServiceReference<FabricService> fabricServiceReference = systemBundleContext.getServiceReference(FabricService.class);
    if (curatorServiceReference != null && fabricServiceReference != null) {
        CuratorFramework curator = systemBundleContext.getService(curatorServiceReference);
        FabricService fs = systemBundleContext.getService(fabricServiceReference);
        String currentContainerName = fs.getCurrentContainerName();
        List<String> activeProfiles = fs.getCurrentContainer().getProfileIds();
        // check for jvm restart requests
        Map<String, String> agentProperties = profile.getConfiguration("io.fabric8.agent");
        Map<String, String> jvmRestartEntries = new HashMap<>();
        for (String key : agentProperties.keySet()) {
            if (key.startsWith("io.fabric8.agent.forceOneTimeJVMRestart")) {
                jvmRestartEntries.put(key, agentProperties.get(key));
                LOGGER.info("Found a profile carrying a one-time JVM restart request: {}", key);
            }
        }
        // clean old entries
        String basePath = ZkPath.CONTAINER_PROVISION_RESTART.getPath(currentContainerName);
        try {
            if (ZooKeeperUtils.exists(curator, basePath) != null) {
                List<String> zkPaths = ZooKeeperUtils.getAllChildren(curator, ZkPath.CONTAINER_PROVISION_RESTART.getPath(currentContainerName));
                for (String zkPath : zkPaths) {
                    String[] split = zkPath.split("/");
                    String prof = split[split.length - 1];
                    if (!activeProfiles.contains(prof)) {
                        LOGGER.info("Deleting old JVM restart request status: {}", zkPath);
                        ZooKeeperUtils.delete(curator, zkPath);
                    }
                }
            }
        } catch (Exception e) {
            LOGGER.error("Unable to check ZK connection", e);
        }
        for (String key : jvmRestartEntries.keySet()) {
            String[] split = key.split("\\.");
            String profileForcingRestart = split[split.length - 1];
            try {
                String zkPath = ZkPath.CONTAINER_PROVISION_RESTART_PROFILES.getPath(currentContainerName, profileForcingRestart);
                Stat exists = exists(curator, zkPath);
                if (exists == null) {
                    ZooKeeperUtils.create(curator, zkPath);
                    profilesRequiringRestart.add(profileForcingRestart);
                    result = true;
                }
            } catch (Exception e) {
                LOGGER.error("Unable to check ZK connection", e);
            }
        }
    }
    if (result) {
        System.setProperty("karaf.restart.jvm", "true");
        restart.set(true);
        LOGGER.warn("Profiles {} scheduled a JVM restart request. Automated JVM restart support is not universally available. If your jvm doesn't support it you are required to manually restart the container that has just been assigned the profile.", profilesRequiringRestart);
        try {
            bundleContext.getBundle(0).stop();
        } catch (BundleException e) {
            LOGGER.error("Error when forcing a JVM restart", e);
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConfigurationException(org.osgi.service.cm.ConfigurationException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) CuratorFramework(org.apache.curator.framework.CuratorFramework) Stat(org.apache.zookeeper.data.Stat) FabricService(io.fabric8.api.FabricService) BundleException(org.osgi.framework.BundleException)

Aggregations

Container (io.fabric8.api.Container)7 FabricService (io.fabric8.api.FabricService)7 IOException (java.io.IOException)7 File (java.io.File)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 BundleException (org.osgi.framework.BundleException)5 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)4 URISyntaxException (java.net.URISyntaxException)4 Bundle (org.osgi.framework.Bundle)4 FabricException (io.fabric8.api.FabricException)3 HashMap (java.util.HashMap)3 Session (com.jcraft.jsch.Session)2 Downloader (io.fabric8.agent.download.Downloader)2 StreamProvider (io.fabric8.agent.download.StreamProvider)2 Watch (io.fabric8.kubernetes.client.Watch)2 Watcher (io.fabric8.kubernetes.client.Watcher)2 MavenResolver (io.fabric8.maven.MavenResolver)2 Parser (io.fabric8.maven.util.Parser)2 BundleUpdate (io.fabric8.patch.management.BundleUpdate)2