|
|
|
@ -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;
|
|
|
|
@ -83,9 +87,16 @@ public class ResourceScreenServiceImpl implements ResourceScreenService {
|
|
|
|
|
List<CloudServer> cloudServers = imsInternalService.listVmsByVendor(null, false, requestContext);
|
|
|
|
|
//私有云平台
|
|
|
|
|
List<CloudVendor> cloudVendors = imsInternalService.listCloudVendor(null);
|
|
|
|
|
Set<String> vendors =
|
|
|
|
|
cloudVendors.stream().filter(cloudVendor -> !cloudVendor.getIsPublic())
|
|
|
|
|
.map(CloudVendor::getType).collect(Collectors.toSet());
|
|
|
|
|
Set<String> vendors = new HashSet<>();
|
|
|
|
|
Set<Long> vendorIds = new HashSet<>();
|
|
|
|
|
List<CloudVendor> noPublicVendors = new ArrayList<>();
|
|
|
|
|
for (CloudVendor cloudVendor : cloudVendors) {
|
|
|
|
|
if (!cloudVendor.getIsPublic()) {
|
|
|
|
|
noPublicVendors.add(cloudVendor);
|
|
|
|
|
vendors.add(cloudVendor.getType());
|
|
|
|
|
vendorIds.add(cloudVendor.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<CloudServer> priServers = cloudServers.stream().filter(
|
|
|
|
|
cloudServer -> null != cloudServer.getVendorType() && vendors.contains(cloudServer.getVendorType()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
@ -105,15 +116,15 @@ public class ResourceScreenServiceImpl implements ResourceScreenService {
|
|
|
|
|
long cpuTotal = 0L;
|
|
|
|
|
Long memTotal = 0L;
|
|
|
|
|
int diskTotal = 0;
|
|
|
|
|
List<Server> hosts = imsInternalService.listHosts();
|
|
|
|
|
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));
|
|
|
|
|
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();
|
|
|
|
|
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 : noPublicVendors) {
|
|
|
|
|
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, "云平台不存在");
|
|
|
|
@ -124,23 +135,23 @@ public class ResourceScreenServiceImpl implements ResourceScreenService {
|
|
|
|
|
excessRatio = Long.valueOf(String.valueOf(authentication.get("excessRatio")));
|
|
|
|
|
}
|
|
|
|
|
if (null != excessRatio && 0L != excessRatio) {
|
|
|
|
|
cpuTotal += config.getCpuCore() * config.getCpuAmount() * excessRatio;
|
|
|
|
|
memTotal += config.getMemoryCapacity().longValue() * excessRatio;
|
|
|
|
|
cpuTotal += (long) Optional.ofNullable(config.getCpuCore()).orElse(0) * Optional.ofNullable(config.getCpuAmount()).orElse(0) * excessRatio;
|
|
|
|
|
memTotal += Optional.ofNullable(config.getMemoryCapacity()).orElse(0.0).longValue() * excessRatio;
|
|
|
|
|
} else {
|
|
|
|
|
cpuTotal += (long) config.getCpuCore() * config.getCpuAmount();
|
|
|
|
|
memTotal += config.getMemoryCapacity().longValue();
|
|
|
|
|
cpuTotal += (long) Optional.ofNullable(config.getCpuCore()).orElse(0) * Optional.ofNullable(config.getCpuAmount()).orElse(0);
|
|
|
|
|
memTotal += Optional.ofNullable(config.getMemoryCapacity()).orElse(0.0).longValue();
|
|
|
|
|
}
|
|
|
|
|
diskTotal += config.getDiskCapacity().intValue();
|
|
|
|
|
diskTotal += Optional.ofNullable(config.getDiskCapacity()).orElse(0.0).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();
|
|
|
|
|
cpuTotal += (long) config.getCpuCore() * config.getCpuAmount();
|
|
|
|
|
diskTotal += config.getDiskCapacity().intValue();
|
|
|
|
|
memTotal += config.getMemoryCapacity().longValue();
|
|
|
|
|
for (com.bocloud.ims.entity.resource.Server opServer : opServers) {
|
|
|
|
|
com.bocloud.ims.entity.resource.ServerConfig config = opServer.getConfig();
|
|
|
|
|
cpuTotal += (long) Optional.ofNullable(config.getCpuCore()).orElse(0) * Optional.ofNullable(config.getCpuAmount()).orElse(0);
|
|
|
|
|
diskTotal += Optional.ofNullable(config.getDiskCapacity()).orElse(0.0).intValue();
|
|
|
|
|
memTotal += Optional.ofNullable(config.getMemoryCapacity()).orElse(0.0).longValue();
|
|
|
|
|
}
|
|
|
|
|
result.put("cpuTotal", cpuTotal);
|
|
|
|
|
result.put("memTotal", memTotal);
|
|
|
|
|