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