This is an automated email from the ASF dual-hosted git repository. marat pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
The following commit(s) were added to refs/heads/main by this push: new e2c5ead Do not collect camel statuses for non deployed projects e2c5ead is described below commit e2c5eadc40fdee55c3829e5cd4f95c8812446d2e Author: Marat Gubaidullin <marat.gubaidul...@gmail.com> AuthorDate: Mon Dec 19 18:57:28 2022 -0500 Do not collect camel statuses for non deployed projects --- .../org/apache/camel/karavan/api/StatusResource.java | 4 +++- .../apache/camel/karavan/service/StatusService.java | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/api/StatusResource.java b/karavan-app/src/main/java/org/apache/camel/karavan/api/StatusResource.java index aa097d2..c8fa5f0 100644 --- a/karavan-app/src/main/java/org/apache/camel/karavan/api/StatusResource.java +++ b/karavan-app/src/main/java/org/apache/camel/karavan/api/StatusResource.java @@ -17,6 +17,7 @@ package org.apache.camel.karavan.api; import io.vertx.core.eventbus.EventBus; +import io.vertx.core.json.JsonObject; import org.apache.camel.karavan.model.CamelStatus; import org.apache.camel.karavan.model.DeploymentStatus; import org.apache.camel.karavan.model.Environment; @@ -33,6 +34,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; +import java.util.Map; import java.util.Optional; @Path("/api/status") @@ -76,7 +78,7 @@ public class StatusResource { @Produces(MediaType.APPLICATION_JSON) @Path("/camel/{projectId}/{env}") public Response getCamelStatusByProjectAndEnv(@PathParam("projectId") String projectId, @PathParam("env") String env) { - bus.publish(StatusService.CMD_COLLECT_PROJECT_STATUS, projectId); + bus.publish(StatusService.CMD_COLLECT_PROJECT_STATUS, new JsonObject(Map.of("projectId", projectId, "env", env))); CamelStatus status = infinispanService.getCamelStatus(projectId, env); if (status != null) { return Response.ok(status).build(); diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/service/StatusService.java b/karavan-app/src/main/java/org/apache/camel/karavan/service/StatusService.java index 78b9393..b901fd3 100644 --- a/karavan-app/src/main/java/org/apache/camel/karavan/service/StatusService.java +++ b/karavan-app/src/main/java/org/apache/camel/karavan/service/StatusService.java @@ -26,12 +26,15 @@ import io.vertx.mutiny.core.eventbus.EventBus; import io.vertx.mutiny.ext.web.client.HttpResponse; import io.vertx.mutiny.ext.web.client.WebClient; import org.apache.camel.karavan.model.CamelStatus; +import org.apache.camel.karavan.model.DeploymentStatus; +import org.apache.camel.karavan.model.Environment; import org.apache.camel.karavan.model.Project; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.jboss.logging.Logger; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; +import javax.ws.rs.core.Response; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -77,10 +80,18 @@ public class StatusService { } @ConsumeEvent(value = CMD_COLLECT_PROJECT_STATUS, blocking = true, ordered = true) - public void collectProjectStatus(String projectId) { - if ((System.currentTimeMillis() - lastCollect.getOrDefault(projectId, 0L)) > threshold) { - collectStatusesForProject(projectId); - lastCollect.put(projectId, System.currentTimeMillis()); + public void collectProjectStatus(JsonObject data) { + String projectId = data.getString("projectId"); + String env = data.getString("env"); + Optional<Environment> environment = infinispanService.getEnvironments().stream().filter(e -> e.getName().equals(env)).findFirst(); + if (environment.isPresent()){ + DeploymentStatus status = infinispanService.getDeploymentStatus(projectId, environment.get().getNamespace(), environment.get().getCluster()); + if (status != null && status.getReadyReplicas() > 0) { + if ((System.currentTimeMillis() - lastCollect.getOrDefault(projectId, 0L)) > threshold) { + collectStatusesForProject(projectId); + lastCollect.put(projectId, System.currentTimeMillis()); + } + } } }