处理大屏展示资源使用情况问题
parent
62b373324d
commit
07329a2e0c
|
@ -16,8 +16,10 @@ import com.bocloud.cos.model.ChargeResultTrend;
|
|||
import com.bocloud.cos.model.ChargeTrendData;
|
||||
import com.bocloud.cos.internal.ImsInternalService;
|
||||
import com.bocloud.cos.utils.DateUtil;
|
||||
import com.bocloud.rpc.interfaces.ims.ImsRpcService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
@ -35,6 +37,8 @@ import java.util.stream.Collectors;
|
|||
public class ResourceScreenServiceImpl implements ResourceScreenService {
|
||||
private final Logger logger = LoggerFactory.getLogger(ResourceScreenServiceImpl.class);
|
||||
private final ImsInternalService imsInternalService;
|
||||
@Autowired
|
||||
private ImsRpcService imsRpcService;
|
||||
|
||||
public ResourceScreenServiceImpl(ImsInternalService imsInternalService) {
|
||||
this.imsInternalService = imsInternalService;
|
||||
|
@ -86,6 +90,9 @@ public class ResourceScreenServiceImpl implements ResourceScreenService {
|
|||
Set<String> vendors =
|
||||
cloudVendors.stream().filter(cloudVendor -> !cloudVendor.getIsPublic())
|
||||
.map(CloudVendor::getType).collect(Collectors.toSet());
|
||||
Set<Long> vendorIds =
|
||||
cloudVendors.stream().filter(cloudVendor -> !cloudVendor.getIsPublic())
|
||||
.map(CloudVendor::getId).collect(Collectors.toSet());
|
||||
List<CloudServer> priServers = cloudServers.stream().filter(
|
||||
cloudServer -> null != cloudServer.getVendorType() && vendors.contains(cloudServer.getVendorType()))
|
||||
.collect(Collectors.toList());
|
||||
|
@ -105,18 +112,15 @@ public class ResourceScreenServiceImpl implements ResourceScreenService {
|
|||
long cpuTotal = 0L;
|
||||
Long memTotal = 0L;
|
||||
int diskTotal = 0;
|
||||
List<Server> hostAll = imsInternalService.listHosts();
|
||||
List<Server> hosts = hostAll.stream().filter(
|
||||
server -> null != server.getVendorType() && vendors.contains(server.getVendorType()))
|
||||
.collect(Collectors.toList());
|
||||
List<com.bocloud.ims.entity.resource.Server> hosts = imsRpcService.getServerAll(vendorIds);
|
||||
hosts.removeIf(server -> null == server.getVendorId());
|
||||
Map<Long, List<Server>> hostMap = hosts.stream().filter(server -> null != server.getVendorId())
|
||||
.collect(Collectors.groupingBy(Server::getVendorId));
|
||||
Map<Long, List<com.bocloud.ims.entity.resource.Server>> hostMap = hosts.stream().filter(server -> null != server.getVendorId())
|
||||
.collect(Collectors.groupingBy(com.bocloud.ims.entity.resource.Server::getVendorId));
|
||||
List<CloudVendor> vmVendors = imsInternalService.listCloudVendor(VendorType.VMWARE.name());
|
||||
for (CloudVendor vendor : vmVendors) {
|
||||
List<Server> servers = Optional.ofNullable(hostMap.get(vendor.getId())).orElse(new ArrayList<>());
|
||||
for (Server server : servers) {
|
||||
ServerConfig config = server.getConfig();
|
||||
List<com.bocloud.ims.entity.resource.Server> servers = Optional.ofNullable(hostMap.get(vendor.getId())).orElse(new ArrayList<>());
|
||||
for (com.bocloud.ims.entity.resource.Server server : servers) {
|
||||
com.bocloud.ims.entity.resource.ServerConfig config = server.getConfig();
|
||||
//从平台获取超分比
|
||||
List<CloudVendor> collect = cloudVendors.stream().filter(vendor1 -> vendor1.getId().equals(server.getVendorId())).collect(Collectors.toList());
|
||||
Assert.notNull(collect, "云平台不存在");
|
||||
|
@ -136,11 +140,11 @@ public class ResourceScreenServiceImpl implements ResourceScreenService {
|
|||
diskTotal += config.getDiskCapacity().intValue();
|
||||
}
|
||||
}
|
||||
List<Server> opServers =
|
||||
List<com.bocloud.ims.entity.resource.Server> opServers =
|
||||
hosts.stream().filter(server -> server.getVendorType().equals(VendorType.OPENSTACK.name()))
|
||||
.collect(Collectors.toList());
|
||||
for (Server opServer : opServers) {
|
||||
ServerConfig config = opServer.getConfig();
|
||||
for (com.bocloud.ims.entity.resource.Server opServer : opServers) {
|
||||
com.bocloud.ims.entity.resource.ServerConfig config = opServer.getConfig();
|
||||
cpuTotal += (long) config.getCpuCore() * config.getCpuAmount();
|
||||
diskTotal += config.getDiskCapacity().intValue();
|
||||
memTotal += config.getMemoryCapacity().longValue();
|
||||
|
|
Loading…
Reference in New Issue