Search in sources :

Example 96 with Check

use of io.fabric8.karaf.checks.Check in project strimzi by strimzi.

the class KafkaClusterTest method testZookeeperScaleUpScaleDown.

@Test
@KafkaCluster(name = "my-cluster", kafkaNodes = 1, zkNodes = 1)
public void testZookeeperScaleUpScaleDown() {
    // kafka cluster already deployed via annotation
    String clusterName = "my-cluster";
    LOGGER.info("Running zookeeperScaleUpScaleDown with cluster {}", clusterName);
    // kubeClient.waitForStatefulSet(zookeeperStatefulSetName(clusterName), 1);
    KubernetesClient client = new DefaultKubernetesClient();
    final int initialReplicas = client.apps().statefulSets().inNamespace(NAMESPACE).withName(zookeeperStatefulSetName(clusterName)).get().getStatus().getReplicas();
    assertEquals(1, initialReplicas);
    // scale up
    final int scaleTo = initialReplicas + 2;
    final int[] newPodIds = { initialReplicas, initialReplicas + 1 };
    final String[] newPodName = { zookeeperPodName(clusterName, newPodIds[0]), zookeeperPodName(clusterName, newPodIds[1]) };
    final String firstPodName = zookeeperPodName(clusterName, 0);
    LOGGER.info("Scaling zookeeper up to {}", scaleTo);
    replaceCm(clusterName, "zookeeper-nodes", String.valueOf(scaleTo));
    kubeClient.waitForPod(newPodName[0]);
    kubeClient.waitForPod(newPodName[1]);
    // check the new node is either in leader or follower state
    waitForZkMntr(firstPodName, Pattern.compile("zk_server_state\\s+(leader|follower)"));
    waitForZkMntr(newPodName[0], Pattern.compile("zk_server_state\\s+(leader|follower)"));
    waitForZkMntr(newPodName[1], Pattern.compile("zk_server_state\\s+(leader|follower)"));
    // TODO Check for k8s events, logs for errors
    // scale down
    LOGGER.info("Scaling down");
    replaceCm(clusterName, "zookeeper-nodes", String.valueOf(1));
    kubeClient.waitForResourceDeletion("po", zookeeperPodName(clusterName, 1));
    // Wait for the one remaining node to enter standalone mode
    waitForZkMntr(firstPodName, Pattern.compile("zk_server_state\\s+standalone"));
// TODO Check for k8s events, logs for errors
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KafkaCluster(io.strimzi.test.KafkaCluster) Test(org.junit.Test)

Example 97 with Check

use of io.fabric8.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildServiceTest method testSuccessfulBuild.

@Test
public void testSuccessfulBuild() throws Exception {
    int nTries = 0;
    boolean bTestComplete = false;
    do {
        try {
            nTries++;
            BuildService.BuildServiceConfig config = defaultConfig.build();
            WebServerEventCollector<OpenShiftMockServer> collector = createMockServer(config, true, 50, false, false);
            OpenShiftMockServer mockServer = collector.getMockServer();
            DefaultOpenShiftClient client = (DefaultOpenShiftClient) mockServer.createOpenShiftClient();
            LOG.info("Current write timeout is : {}", client.getHttpClient().writeTimeoutMillis());
            LOG.info("Current read timeout is : {}", client.getHttpClient().readTimeoutMillis());
            LOG.info("Retry on failure : {}", client.getHttpClient().retryOnConnectionFailure());
            OpenshiftBuildService service = new OpenshiftBuildService(client, logger, dockerServiceHub, config);
            service.build(image);
            // we should Foadd a better way to assert that a certain call has been made
            assertTrue(mockServer.getRequestCount() > 8);
            collector.assertEventsRecordedInOrder("build-config-check", "new-build-config", "pushed");
            collector.assertEventsNotRecorded("patch-build-config");
            bTestComplete = true;
        } catch (Fabric8ServiceException exception) {
            Throwable rootCause = getRootCause(exception);
            logger.warn("A problem encountered while running test {}, retrying..", exception.getMessage());
            // Let's wait for a while, and then retry again
            if (rootCause != null && rootCause instanceof IOException) {
                continue;
            }
        }
    } while (nTries < MAX_TIMEOUT_RETRIES && !bTestComplete);
}
Also used : OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) BuildService(io.fabric8.maven.core.service.BuildService) IOException(java.io.IOException) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) Test(org.junit.Test)

Example 98 with Check

use of io.fabric8.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.

the class ProfileUtil method lookup.

/**
 * Lookup profiles from a given directory and merge it with a profile of the
 * same name found in the classpath
 *
 * @param name name of the profile to lookup
 * @param directory directory to lookup
 * @return Profile found or null
 * @throws IOException if somethings fails during lookup
 */
public static Profile lookup(String name, File directory) throws IOException {
    // First check from the classpath, these profiles are used as a basis
    List<Profile> profiles = readProfileFromClasspath(name);
    File profileFile = findProfileYaml(directory);
    if (profileFile != null) {
        List<Profile> fileProfiles = fromYaml(new FileInputStream(profileFile));
        for (Profile profile : fileProfiles) {
            if (profile.getName().equals(name)) {
                profiles.add(profile);
                break;
            }
        }
    }
    // "larger" orders are "earlier" in the list
    Collections.sort(profiles, Collections.<Profile>reverseOrder());
    return mergeProfiles(profiles);
}
Also used : Profile(io.fabric8.maven.core.config.Profile)

Example 99 with Check

use of io.fabric8.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.

the class KarafHealthCheckEnricher method discoverKarafProbe.

// 
// Karaf has a readiness/health URL exposed if the fabric8-karaf-check feature is installed.
// 
private Probe discoverKarafProbe(String path, int initialDelay) {
    for (Plugin plugin : this.getProject().getBuildPlugins()) {
        if ("karaf-maven-plugin".equals(plugin.getArtifactId())) {
            Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
            if (configuration == null)
                return null;
            Xpp3Dom startupFeatures = configuration.getChild("startupFeatures");
            if (startupFeatures == null)
                return null;
            for (Xpp3Dom feature : startupFeatures.getChildren("feature")) {
                if ("fabric8-karaf-checks".equals(feature.getValue())) {
                    // TODO: handle the case where the user changes the default port
                    return new ProbeBuilder().withNewHttpGet().withNewPort(DEFAULT_HEALTH_CHECK_PORT).withPath(path).endHttpGet().withInitialDelaySeconds(initialDelay).build();
                }
            }
        }
    }
    return null;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) Plugin(org.apache.maven.model.Plugin)

Example 100 with Check

use of io.fabric8.karaf.checks.Check in project fabric8-maven-plugin by fabric8io.

the class VertxHealthCheckEnricher method discoverVertxHealthCheck.

private Probe discoverVertxHealthCheck(int initialDelay, boolean readiness) {
    if (!isApplicable()) {
        return null;
    }
    int port = getPort();
    String path = null;
    if (readiness) {
        path = getReadinessPath();
        if (path != null && path.isEmpty()) {
            // Disabled.
            return null;
        }
    }
    if (path == null) {
        path = getPath();
    }
    if (port <= 0 || path == null || path.isEmpty()) {
        // Health check disabled
        return null;
    }
    String scheme = getScheme();
    return new ProbeBuilder().withNewHttpGet().withScheme(scheme).withNewPort(port).withPath(path).endHttpGet().withInitialDelaySeconds(initialDelay).build();
}
Also used : ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder)

Aggregations

Test (org.junit.Test)35 IOException (java.io.IOException)23 File (java.io.File)17 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)15 FabricService (io.fabric8.api.FabricService)11 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)11 Map (java.util.Map)10 Container (io.fabric8.api.Container)9 PatchException (io.fabric8.patch.management.PatchException)9 Expectations (mockit.Expectations)9 Profile (io.fabric8.api.Profile)8 TreeMap (java.util.TreeMap)7 Version (io.fabric8.api.Version)6 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)6 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 Check (io.fabric8.karaf.checks.Check)5 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)5 Patch (io.fabric8.patch.management.Patch)5