fix: fetch actual agent/environment counts from server for tenant dashboard
The dashboard was showing hardcoded zeroes for agent and environment usage. Now fetches real counts via M2M API from the tenant's server. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -124,6 +124,38 @@ public class ServerApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
/** Fetch agent count from a tenant's server. */
|
||||
public int getAgentCount(String serverEndpoint) {
|
||||
try {
|
||||
var resp = RestClient.create().get()
|
||||
.uri(serverEndpoint + "/api/v1/agents")
|
||||
.header("Authorization", "Bearer " + getAccessToken())
|
||||
.header("X-Cameleer-Protocol-Version", "1")
|
||||
.retrieve()
|
||||
.body(java.util.List.class);
|
||||
return resp != null ? resp.size() : 0;
|
||||
} catch (Exception e) {
|
||||
log.warn("Agent count fetch failed for {}: {}", serverEndpoint, e.getMessage());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** Fetch environment count from a tenant's server. */
|
||||
public int getEnvironmentCount(String serverEndpoint) {
|
||||
try {
|
||||
var resp = RestClient.create().get()
|
||||
.uri(serverEndpoint + "/api/v1/admin/environments")
|
||||
.header("Authorization", "Bearer " + getAccessToken())
|
||||
.header("X-Cameleer-Protocol-Version", "1")
|
||||
.retrieve()
|
||||
.body(java.util.List.class);
|
||||
return resp != null ? resp.size() : 0;
|
||||
} catch (Exception e) {
|
||||
log.warn("Environment count fetch failed for {}: {}", serverEndpoint, e.getMessage());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public record ServerHealthResponse(boolean healthy, String status) {}
|
||||
|
||||
private synchronized String getAccessToken() {
|
||||
|
||||
@@ -47,7 +47,8 @@ public class TenantPortalService {
|
||||
String name, String slug, String tier, String status,
|
||||
boolean serverHealthy, String serverStatus, String serverEndpoint,
|
||||
String licenseTier, long licenseDaysRemaining,
|
||||
Map<String, Object> limits, Map<String, Object> features
|
||||
Map<String, Object> limits, Map<String, Object> features,
|
||||
int agentCount, int environmentCount
|
||||
) {}
|
||||
|
||||
public record LicenseData(
|
||||
@@ -82,10 +83,16 @@ public class TenantPortalService {
|
||||
|
||||
boolean serverHealthy = false;
|
||||
String serverStatus = "NO_ENDPOINT";
|
||||
int agentCount = 0;
|
||||
int environmentCount = 0;
|
||||
if (endpoint != null && !endpoint.isBlank()) {
|
||||
var health = serverApiClient.getHealth(endpoint);
|
||||
serverHealthy = health.healthy();
|
||||
serverStatus = health.status();
|
||||
if (serverHealthy) {
|
||||
agentCount = serverApiClient.getAgentCount(endpoint);
|
||||
environmentCount = serverApiClient.getEnvironmentCount(endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
String licenseTier = null;
|
||||
@@ -107,7 +114,7 @@ public class TenantPortalService {
|
||||
tenant.getTier().name(), tenant.getStatus().name(),
|
||||
serverHealthy, serverStatus, endpoint,
|
||||
licenseTier, licenseDaysRemaining,
|
||||
limits, features
|
||||
limits, features, agentCount, environmentCount
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user