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);
}
}
}
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"));
}
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);
}
Aggregations