Skip to content

Commit

Permalink
fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Jan 6, 2025
1 parent f4190d0 commit 4f3c88e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public class HostPO extends BasePO implements Serializable {
@Transient
private String clusterName;

@Transient
private String clusterDisplayName;

@Transient
private Integer componentNum;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
select
<include refid="baseColumnsV2">
<property name="alias" value="h"/>
</include>, c.display_name as cluster_name, count(comp.id) as component_num
</include>, c.name as cluster_name, c.display_name as cluster_display_name, count(comp.id) as component_num
from host h
left join cluster c on h.cluster_id = c.id
left join component comp on h.id = comp.host_id
Expand All @@ -67,7 +67,7 @@
select
<include refid="baseColumnsV2">
<property name="alias" value="h"/>
</include>, c.display_name as cluster_name, count(comp.id) as component_num
</include>, c.name as cluster_name, c.display_name as cluster_display_name, count(comp.id) as component_num
from host h
left join cluster c on h.cluster_id = c.id
left join component comp on h.id = comp.host_id
Expand Down Expand Up @@ -95,7 +95,7 @@
<include refid="baseColumnsV2">
<property name="alias" value="h"/>
</include>
,clus.display_name as cluster_name
, clus.name as cluster_name, clus.display_name as cluster_display_name
from host h
left join cluster clus
on h.cluster_id = clus.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
select
<include refid="baseColumnsV2">
<property name="alias" value="h"/>
</include>, c.display_name as cluster_name, count(comp.id) as component_num
</include>, c.name as cluster_name, c.display_name as cluster_display_name, count(comp.id) as component_num
from host h
left join cluster c on h.cluster_id = c.id
left join component comp on h.id = comp.host_id
Expand All @@ -67,7 +67,7 @@
select
<include refid="baseColumnsV2">
<property name="alias" value="h"/>
</include>, c.display_name as cluster_name, count(comp.id) as component_num
</include>, c.name as cluster_name, c.display_name as cluster_display_name, count(comp.id) as component_num
from host h
left join cluster c on h.cluster_id = c.id
left join component comp on h.id = comp.host_id
Expand Down Expand Up @@ -95,7 +95,7 @@
<include refid="baseColumnsV2">
<property name="alias" value="h"/>
</include>
,clus.display_name as cluster_name
, clus.name as cluster_name, clus.display_name as cluster_display_name
from
host h
left join cluster clus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.bigtop.manager.server.model.dto.ComponentDTO;
import org.apache.bigtop.manager.server.model.dto.ServiceDTO;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -86,19 +87,13 @@ protected TaskContext createTaskContext(String hostname) {

private Map<String, List<String>> getClusterHosts() {
Map<String, List<String>> clusterHosts = new HashMap<>();
List<HostPO> hostPOs = hostDao.findAll();
for (HostPO hostPO : hostPOs) {
Long clusterId = hostPO.getClusterId();
if (clusterId == null) {
continue;
}
String host = hostPO.getIpv4();
String clusterName = clusterDao.findById(clusterId).getName();
if (clusterHosts.containsKey(clusterName)) {
clusterHosts.get(clusterName).add(host);
} else {
clusterHosts.put(clusterName, List.of(host));
for (ClusterPO clusterPO : clusterDao.findAll()) {
List<String> hosts = new ArrayList<>();
for (HostPO hostPO : hostDao.findAllByClusterId(clusterPO.getId())) {
String host = hostPO.getHostname();
hosts.add(host);
}
clusterHosts.put(clusterPO.getName(), hosts);
}
return clusterHosts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@ public class HostVO {

private String clusterName;

private String clusterDisplayName;

private Integer componentNum;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,15 @@
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Slf4j
@NoArgsConstructor
public abstract class InfraParams extends BaseParams {

protected Map<String, List<String>> clusterHosts;

protected InfraParams(CommandPayload commandPayload) {
super(commandPayload);
clusterHosts = commandPayload.getClusterHosts();
}

/**
Expand Down Expand Up @@ -82,6 +77,6 @@ public String stackHome() {

public Map<String, List<String>> getClusterHosts() {
// In Component Status stage, clusterHosts is null
return Objects.requireNonNullElseGet(clusterHosts, HashMap::new);
return commandPayload.getClusterHosts();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,20 @@ public void setAgentScrapeJob() {
agentScrapeJob.put("metrics_path", "/actuator/prometheus");

List<Map<String, Object>> agentTargets = new ArrayList<>();
getClusterHosts().forEach((cluster, hosts) -> {
Map<String, Object> agentTarget = new HashMap<>();
List<String> targets = new ArrayList<>();
for (String host : hosts) {
targets.add(MessageFormat.format("{0}:{1}", host, BM_AGENT_PORT));
}
agentTarget.put("targets", targets);
agentTarget.put("labels", Map.of(AGENT_TARGET_LABEL, cluster));
agentTargets.add(agentTarget);
});
Map<String, List<String>> clusterHosts = getClusterHosts();
if (clusterHosts != null) {
clusterHosts.forEach((cluster, hosts) -> {
Map<String, Object> agentTarget = new HashMap<>();
List<String> targets = new ArrayList<>();
for (String host : hosts) {
targets.add(MessageFormat.format("{0}:{1}", host, BM_AGENT_PORT));
}
agentTarget.put("targets", targets);
agentTarget.put("labels", Map.of(AGENT_TARGET_LABEL, cluster));
agentTargets.add(agentTarget);
});
}

agentScrapeJob.put("targets_list", agentTargets);
}
}

0 comments on commit 4f3c88e

Please sign in to comment.