diff --git a/bocloud.cos.service/src/main/java/com/bocloud/cos/service/ResourceScreenServiceImpl.java b/bocloud.cos.service/src/main/java/com/bocloud/cos/service/ResourceScreenServiceImpl.java index 67897b2..106e64f 100644 --- a/bocloud.cos.service/src/main/java/com/bocloud/cos/service/ResourceScreenServiceImpl.java +++ b/bocloud.cos.service/src/main/java/com/bocloud/cos/service/ResourceScreenServiceImpl.java @@ -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 vendors = cloudVendors.stream().filter(cloudVendor -> !cloudVendor.getIsPublic()) .map(CloudVendor::getType).collect(Collectors.toSet()); + Set vendorIds = + cloudVendors.stream().filter(cloudVendor -> !cloudVendor.getIsPublic()) + .map(CloudVendor::getId).collect(Collectors.toSet()); List 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 hostAll = imsInternalService.listHosts(); - List hosts = hostAll.stream().filter( - server -> null != server.getVendorType() && vendors.contains(server.getVendorType())) - .collect(Collectors.toList()); + List hosts = imsRpcService.getServerAll(vendorIds); hosts.removeIf(server -> null == server.getVendorId()); - Map> hostMap = hosts.stream().filter(server -> null != server.getVendorId()) - .collect(Collectors.groupingBy(Server::getVendorId)); + Map> hostMap = hosts.stream().filter(server -> null != server.getVendorId()) + .collect(Collectors.groupingBy(com.bocloud.ims.entity.resource.Server::getVendorId)); List vmVendors = imsInternalService.listCloudVendor(VendorType.VMWARE.name()); for (CloudVendor vendor : vmVendors) { - List servers = Optional.ofNullable(hostMap.get(vendor.getId())).orElse(new ArrayList<>()); - for (Server server : servers) { - ServerConfig config = server.getConfig(); + List 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 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 opServers = + List 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();