Search in sources :

Example 1 with Query

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

the class OpenshiftBuildService method waitForOpenShiftBuildToComplete.

private void waitForOpenShiftBuildToComplete(OpenShiftClient client, Build build) throws MojoExecutionException, InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final CountDownLatch logTerminateLatch = new CountDownLatch(1);
    final String buildName = KubernetesHelper.getName(build);
    final AtomicReference<Build> buildHolder = new AtomicReference<>();
    // Don't query for logs directly, Watch over the build pod:
    waitUntilPodIsReady(buildName + "-build", 20, log);
    log.info("Waiting for build " + buildName + " to complete...");
    try (LogWatch logWatch = client.pods().withName(buildName + "-build").watchLog()) {
        KubernetesClientUtil.printLogsAsync(logWatch, "Failed to tail build log", logTerminateLatch, log);
        Watcher<Build> buildWatcher = getBuildWatcher(latch, buildName, buildHolder);
        try (Watch watcher = client.builds().withName(buildName).watch(buildWatcher)) {
            // Check if the build is already finished to avoid waiting indefinitely
            Build lastBuild = client.builds().withName(buildName).get();
            String lastStatus = KubernetesResourceUtil.getBuildStatusPhase(lastBuild);
            if (Builds.isFinished(lastStatus)) {
                log.debug("Build %s is already finished", buildName);
                buildHolder.set(lastBuild);
                latch.countDown();
            }
            waitUntilBuildFinished(latch);
            logTerminateLatch.countDown();
            build = buildHolder.get();
            String status = KubernetesResourceUtil.getBuildStatusPhase(build);
            if (Builds.isFailed(status) || Builds.isCancelled(status)) {
                throw new MojoExecutionException("OpenShift Build " + buildName + ": " + KubernetesResourceUtil.getBuildStatusReason(build));
            }
            log.info("Build " + buildName + " " + status);
        }
    }
}
Also used : LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Build(io.fabric8.openshift.api.model.Build) Watch(io.fabric8.kubernetes.client.Watch) LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with Query

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

the class MetricsTest method testDefault.

@Test
public void testDefault() throws Exception {
    Query query = new Query("test", new HashSet<Request>(Arrays.asList(new MBeanAttrs("memory", "java.lang:type=Memory", Arrays.asList("HeapMemoryUsage", "NonHeapMemoryUsage")), new MBeanOpers("deadlocks", "java.lang:type=Threading", "dumpAllThreads", Arrays.<Object>asList(true, true), Arrays.<String>asList(boolean.class.getName(), boolean.class.getName())))), null, null, null, 0, 0);
    System.gc();
    QueryResult qrs = JmxUtils.execute(new Server("local"), query, ManagementFactory.getPlatformMBeanServer());
    String output = new Renderer().render(qrs);
    Map map = new ObjectMapper().readValue(output, Map.class);
    assertEquals("local", map.get("host"));
    assertNotNull(map.get("@timestamp"));
}
Also used : QueryResult(io.fabric8.insight.metrics.model.QueryResult) Query(io.fabric8.insight.metrics.model.Query) Server(io.fabric8.insight.metrics.model.Server) Request(io.fabric8.insight.metrics.model.Request) Renderer(io.fabric8.insight.metrics.mvel.Renderer) MBeanOpers(io.fabric8.insight.metrics.model.MBeanOpers) MBeanAttrs(io.fabric8.insight.metrics.model.MBeanAttrs) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with Query

use of io.fabric8.insight.metrics.model.Query in project fabric8 by fabric8io.

the class OpenShiftPipelineTest method testPipelinesFromConfigMapWithCaching.

@Test
public void testPipelinesFromConfigMapWithCaching() throws Exception {
    String namespace = "myproject";
    final ConfigMap configMap = loadTestConfigMap();
    server.expect().withPath("/api/v1/namespaces/" + namespace + "/configmaps/" + FABRIC8_PIPELINES).andReturn(200, configMap).once();
    Map<String, String> environment = new HashMap<>();
    environment.put(Pipelines.JOB_NAME, "foo");
    environment.put("BRANCH_NAME", "master");
    Pipeline pipeline = Pipelines.getPipeline(getKubernetesClient(), namespace, environment);
    assertEquals("Pipeline kind", pipeline.getKind(), PipelineKind.CD);
    assertEquals("$" + Pipelines.PIPELINE_KIND, "CD", environment.get(Pipelines.PIPELINE_KIND));
    // we should not query the ConfigMap again!
    pipeline = Pipelines.getPipeline(getKubernetesClient(), namespace, environment);
    assertEquals("Pipeline kind", pipeline.getKind(), PipelineKind.CD);
}
Also used : PipelineConfigurationParseTest.loadTestConfigMap(io.fabric8.kubernetes.api.pipelines.PipelineConfigurationParseTest.loadTestConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MBeanAttrs (io.fabric8.insight.metrics.model.MBeanAttrs)1 MBeanOpers (io.fabric8.insight.metrics.model.MBeanOpers)1 Query (io.fabric8.insight.metrics.model.Query)1 QueryResult (io.fabric8.insight.metrics.model.QueryResult)1 Request (io.fabric8.insight.metrics.model.Request)1 Server (io.fabric8.insight.metrics.model.Server)1 Renderer (io.fabric8.insight.metrics.mvel.Renderer)1 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 PipelineConfigurationParseTest.loadTestConfigMap (io.fabric8.kubernetes.api.pipelines.PipelineConfigurationParseTest.loadTestConfigMap)1 Watch (io.fabric8.kubernetes.client.Watch)1 LogWatch (io.fabric8.kubernetes.client.dsl.LogWatch)1 Build (io.fabric8.openshift.api.model.Build)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1