Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement][datasophon-service]The rack information displayed in the host management shows the actual name instead of the rack #436

Merged
merged 7 commits into from
Oct 25, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.datasophon.api.master.ActorUtils;
import com.datasophon.api.master.PrometheusActor;
import com.datasophon.api.master.RackActor;
import com.datasophon.api.service.ClusterRackService;
import com.datasophon.api.service.host.ClusterHostService;
import com.datasophon.api.service.ClusterInfoService;
import com.datasophon.api.service.ClusterServiceRoleInstanceService;
Expand All @@ -39,6 +40,7 @@
import com.datasophon.common.utils.Result;
import com.datasophon.dao.entity.ClusterHostDO;
import com.datasophon.dao.entity.ClusterInfoEntity;
import com.datasophon.dao.entity.ClusterRack;
import com.datasophon.dao.entity.ClusterServiceRoleInstanceEntity;
import com.datasophon.domain.host.enums.HostState;
import com.datasophon.dao.enums.RoleType;
Expand Down Expand Up @@ -74,6 +76,9 @@ public class ClusterHostServiceImpl extends ServiceImpl<ClusterHostMapper, Clust
@Autowired
ClusterInfoService clusterInfoService;

@Autowired
ClusterRackService clusterRackService;

private final String IP = "ip";

@Override
Expand All @@ -96,6 +101,10 @@ public Result listByPage(Integer clusterId, String hostname, String ip, String c
.orderByAsc("asc".equals(orderType), orderField)
.orderByDesc("desc".equals(orderType), orderField)
.last("limit " + offset + "," + pageSize));

// 回显rack的名称 而不是ID
Map<String, String> rackMap = clusterRackService.queryClusterRack(clusterId).stream()
.collect(Collectors.toMap(obj->obj.getId()+"", ClusterRack::getRack));
for (ClusterHostDO clusterHostDO : list) {
QueryHostListPageDTO queryHostListPageDTO = new QueryHostListPageDTO();
BeanUtils.copyProperties(clusterHostDO,queryHostListPageDTO);
Expand All @@ -104,6 +113,7 @@ public Result listByPage(Integer clusterId, String hostname, String ip, String c
.eq(Constants.HOSTNAME, clusterHostDO.getHostname()));
queryHostListPageDTO.setServiceRoleNum(serviceRoleNum);
queryHostListPageDTO.setHostState(clusterHostDO.getHostState().getValue());
queryHostListPageDTO.setRack(rackMap.getOrDefault(queryHostListPageDTO.getRack(),"/default-rack"));
hostListPageDTOS.add(queryHostListPageDTO);
}
int count = this.count(new QueryWrapper<ClusterHostDO>().eq(Constants.CLUSTER_ID, clusterId)
Expand Down