Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ public class TaskInterceptor implements ServerInterceptor {
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
return new ForwardingServerCallListener.SimpleForwardingServerCallListener<>(next.startCall(call, headers)) {

private boolean taskRequest = false;

@Override
public void onMessage(ReqT message) {
super.onMessage(message);
taskRequest = isTaskRequest(message);

if (isTaskRequest(message)) {
if (taskRequest) {
try {
Method method = message.getClass().getDeclaredMethod("getTaskId");
Long taskId = (Long) method.invoke(message);
Expand All @@ -69,16 +73,20 @@ public void onHalfClose() {
public void onCancel() {
super.onCancel();

Caches.RUNNING_TASK = null;
MDC.clear();
if (taskRequest) {
Caches.RUNNING_TASK = null;
MDC.clear();
}
}

@Override
public void onComplete() {
super.onComplete();

Caches.RUNNING_TASK = null;
MDC.clear();
if (taskRequest) {
Caches.RUNNING_TASK = null;
MDC.clear();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface ServiceDao extends BaseDao<ServicePO> {

List<ServicePO> findByQuery(@Param("query") ServiceQuery query);

int countByClusterId(@Param("clusterId") Long clusterId);

List<ServicePO> findByClusterId(@Param("clusterId") Long clusterId);

ServicePO findByClusterIdAndName(@Param("clusterId") Long clusterId, @Param("name") String name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@
<property name="alias" value="c"/>
</include>, u.nickname as create_user,
count(h.id) as total_host, sum(h.available_processors) as total_processor,
sum(h.total_memory_size) as total_memory, sum(h.total_disk) as total_disk, count(s.id) as total_service
sum(h.total_memory_size) as total_memory, sum(h.total_disk) as total_disk
from
cluster c left join user u on c.create_by = u.id
left join host h on c.id = h.cluster_id
left join service s on c.id = s.cluster_id
where c.id = #{id}
limit 1
</select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
</where>
</select>

<select id="countByClusterId" parameterType="java.lang.Long" resultType="int">
select
count(*)
from service
where
cluster_id = #{clusterId}
</select>

<select id="findByClusterId" parameterType="java.lang.Long" resultType="org.apache.bigtop.manager.dao.po.ServicePO">
select
<include refid="baseColumns" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@
<property name="alias" value="c"/>
</include>, u.nickname as create_user,
count(h.id) as total_host, sum(h.available_processors) as total_processor,
sum(h.total_memory_size) as total_memory, sum(h.total_disk) as total_disk, count(s.id) as total_service
sum(h.total_memory_size) as total_memory, sum(h.total_disk) as total_disk
from
cluster c left join "user" u on c.create_by = u.id
left join host h on c.id = h.cluster_id
left join service s on c.id = s.cluster_id
where c.id = #{id}
group by c.id, u.nickname
limit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
</where>
</select>

<select id="countByClusterId" parameterType="java.lang.Long" resultType="int">
select
count(*)
from service
where
cluster_id = #{clusterId}
</select>

<select id="findByClusterId" parameterType="java.lang.Long" resultType="org.apache.bigtop.manager.dao.po.ServicePO">
select
<include refid="baseColumns" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ public static List<Stage> createComponentStages(
stages.add(new ComponentConfigureStage(stageContext));
break;
case INIT:
stageContext = createStageContext(componentName, hostnames, commandDTO);
stageContext = createStageContext(componentName, List.of(hostnames.get(0)), commandDTO);
stages.add(new ComponentInitStage(stageContext));
break;
case PREPARE:
// Prepare phase runs after component started, client component shouldn't create this.
if (!StackUtils.isClientComponent(componentName)) {
stageContext = createStageContext(componentName, hostnames, commandDTO);
stageContext = createStageContext(componentName, List.of(hostnames.get(0)), commandDTO);
Comment on lines +102 to +108
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restricting INIT and PREPARE stages to only the first hostname may skip running stages on other hosts; consider passing the full hostnames list or explicitly documenting that change.

Copilot uses AI. Check for mistakes.
stages.add(new ComponentPrepareStage(stageContext));
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.bigtop.manager.server.controller;

import org.apache.bigtop.manager.server.model.vo.ClusterMetricsVO;
import org.apache.bigtop.manager.server.model.vo.HostMetricsVO;
import org.apache.bigtop.manager.server.service.MetricsService;
import org.apache.bigtop.manager.server.utils.ResponseEntity;

Expand All @@ -27,37 +29,30 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import jakarta.annotation.Resource;

@Tag(name = "Metrics Controller")
@RestController
@RequestMapping("metrics")
@RequestMapping("/metrics")
public class MetricsController {

@Resource
private MetricsService metricsService;

@Operation(summary = "hosts healthy", description = "hosts healthy check")
@GetMapping("hostshealthy")
public ResponseEntity<JsonNode> agentHostsHealthyStatus() {
return ResponseEntity.success(metricsService.queryAgentsHealthyStatus());
}

@Operation(summary = "host info", description = "host info query")
@GetMapping("hosts/{id}")
public ResponseEntity<JsonNode> queryAgentInfo(
@RequestParam(value = "interval", defaultValue = "1m") String interval, @PathVariable String id) {
return ResponseEntity.success(metricsService.queryAgentsInfo(Long.valueOf(id), interval));
@GetMapping("/hosts/{id}")
public ResponseEntity<HostMetricsVO> queryAgentInfo(
@RequestParam(value = "interval", defaultValue = "1m") String interval, @PathVariable Long id) {
return ResponseEntity.success(metricsService.queryAgentsInfo(id, interval));
}

@Operation(summary = "cluster info", description = "cluster info query")
@GetMapping("clusters/{id}")
public ResponseEntity<JsonNode> queryCluster(
@RequestParam(value = "interval", defaultValue = "1m") String interval, @PathVariable String id) {
return ResponseEntity.success(metricsService.queryClustersInfo(Long.valueOf(id), interval));
@GetMapping("/clusters/{id}")
public ResponseEntity<ClusterMetricsVO> queryCluster(
@RequestParam(value = "interval", defaultValue = "1m") String interval, @PathVariable Long id) {
return ResponseEntity.success(metricsService.queryClustersInfo(id, interval));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ServiceCommandReq {
@NotNull @Schema(description = "Service name", example = "zookeeper")
private String serviceName;

@NotNull @Schema(description = "Whether the service is already installed", example = "false")
@Schema(description = "Whether the service is already installed", example = "false")
private Boolean installed;

@NotEmpty(groups = {CommandGroupSequenceProvider.ServiceInstallCommandGroup.class})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bigtop.manager.server.model.vo;

import lombok.Data;

import java.util.List;

@Data
public class ClusterMetricsVO {

private String cpuUsageCur;
private String memoryUsageCur;

private List<String> timestamps;
private List<String> cpuUsage;
private List<String> memoryUsage;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bigtop.manager.server.model.vo;

import lombok.Data;

import java.util.List;

@Data
public class HostMetricsVO {

private String cpuUsageCur;
private String memoryUsageCur;
private String diskUsageCur;
private String fileDescriptorUsage;
private String diskReadCur;
private String diskWriteCur;

private List<String> timestamps;
private List<String> cpuUsage;
private List<String> systemLoad1;
private List<String> systemLoad5;
private List<String> systemLoad15;
private List<String> memoryUsage;
private List<String> diskRead;
private List<String> diskWrite;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bigtop.manager.server.prometheus;

import lombok.Data;

import java.util.List;

@Data
public class PrometheusData {

// "matrix" | "vector" | "scalar" | "string",
private String resultType;

private List<PrometheusResult> result;
}
Loading
Loading