private boolean isNoHypervisor(String hyType) { return !candidates.stream().anyMatch(vo -> hyType.equals(vo.getHypervisorType())); }
private List<HostVO> allocate(List<HostVO> vos, String hypervisorType) { List<HostVO> lst = new ArrayList<HostVO>(vos.size()); for (HostVO vo : vos) { if (hypervisorType != null && !hypervisorType.equals(vo.getHypervisorType())) { continue; } if (vo.getState() == HostState.Enabled && vo.getStatus() == HostStatus.Connected) { lst.add(vo); } } return lst; }
private List<HostVO> allocate(List<HostVO> candidates, String zoneUuid, String clusterUuid, String hostUuid, String hypervisorType) { List<HostVO> ret = new ArrayList<HostVO>(candidates.size()); for (HostVO h : candidates) { if (zoneUuid != null && !h.getZoneUuid().equals(zoneUuid)) { continue; } if (clusterUuid != null && !h.getClusterUuid().equals(clusterUuid)) { continue; } if (hostUuid != null && !h.getUuid().equals(hostUuid)) { continue; } if (hypervisorType != null && !h.getHypervisorType().equals(hypervisorType)) { continue; } ret.add(h); } return ret; }
@Override public void next(List<HostVO> candidates) { DebugUtils.Assert(candidates != null, "cannot pass null to next() method"); DebugUtils.Assert(!candidates.isEmpty(), "cannot pass empty candidates to next() method"); result = candidates; VmInstanceInventory vm = allocationSpec.getVmInstance(); logger.debug(String.format("[Host Allocation]: flow[%s] successfully found %s candidate hosts for vm[uuid:%s, name:%s]", lastFlow.getClass().getName(), result.size(), vm.getUuid(), vm.getName())); if (logger.isTraceEnabled()) { StringBuilder sb = new StringBuilder("[Host Allocation Details]:"); for (HostVO vo : result) { sb.append(String.format("\ncandidate host[name:%s, uuid:%s, zoneUuid:%s, clusterUuid:%s, hypervisorType:%s]", vo.getName(), vo.getUuid(), vo.getZoneUuid(), vo.getClusterUuid(), vo.getHypervisorType())); } logger.trace(sb.toString()); } if (it.hasNext()) { runFlow(it.next()); return; } done(); }
@Override public void handle(Map data) { HostInventory inv = factory.getHostInventory(vo.getUuid()); logger.debug(String.format("successfully added host[name:%s, hypervisor:%s, uuid:%s]", vo.getName(), vo.getHypervisorType(), vo.getUuid())); completion.success(inv); } }).error(new FlowErrorHandler(amsg) {
private void passThrough(HostMessage msg) { HostVO vo = dbf.findByUuid(msg.getHostUuid(), HostVO.class); if (vo == null && allowedMessageAfterSoftDeletion.contains(msg.getClass())) { HostEO eo = dbf.findByUuid(msg.getHostUuid(), HostEO.class); vo = ObjectUtils.newAndCopy(eo, HostVO.class); } if (vo == null) { ErrorCode err = Platform.err(SysErrors.RESOURCE_NOT_FOUND, "cannot find host[uuid:%s], it may have been deleted", msg.getHostUuid()); throw new OperationFailureException(err); } HypervisorFactory factory = this.getHypervisorFactory(HypervisorType.valueOf(vo.getHypervisorType())); Host host = factory.getHost(vo); host.handleMessage((Message) msg); }
@Override public void run(FlowTrigger trigger, Map data) { String hostUuid = getAvailableHostUuidForOperation(); if (hostUuid == null) { trigger.next(); return; } HostVO hvo = dbf.findByUuid(hostUuid, HostVO.class); DeleteVolumeBitsOnPrimaryStorageMsg dmsg = new DeleteVolumeBitsOnPrimaryStorageMsg(); dmsg.setFolder(true); dmsg.setHypervisorType(hvo.getHypervisorType()); dmsg.setInstallPath(new File(msg.getInstallPath()).getParent()); dmsg.setPrimaryStorageUuid(msg.getPrimaryStorageUuid()); bus.makeTargetServiceIdByResourceUuid(dmsg, PrimaryStorageConstant.SERVICE_ID, msg.getPrimaryStorageUuid()); bus.send(dmsg, new CloudBusCallBack(trigger) { @Override public void run(MessageReply reply) { if (reply.isSuccess()) { trigger.next(); } else { trigger.fail(reply.getError()); } } }); } }).done(new FlowDoneHandler(msg) {
protected HostVO(HostVO vo) { this.setClusterUuid(vo.getClusterUuid()); this.setStatus(vo.getStatus()); this.setCreateDate(vo.getCreateDate()); this.setDescription(vo.getDescription()); this.setHypervisorType(vo.getHypervisorType()); this.setLastOpDate(vo.getLastOpDate()); this.setManagementIp(vo.getManagementIp()); this.setName(vo.getName()); this.setState(vo.getState()); this.setUuid(vo.getUuid()); this.setZoneUuid(vo.getZoneUuid()); this.setCapacity(vo.getCapacity()); } }
protected HostInventory(HostVO vo) { this.setStatus(vo.getStatus().toString()); this.setCreateDate(vo.getCreateDate()); this.setDescription(vo.getDescription()); this.setHypervisorType(vo.getHypervisorType()); this.setLastOpDate(vo.getLastOpDate()); this.setManagementIp(vo.getManagementIp()); this.setName(vo.getName()); this.setState(vo.getState().toString()); this.setUuid(vo.getUuid()); this.setZoneUuid(vo.getZoneUuid()); this.setClusterUuid(vo.getClusterUuid()); if (vo.getCapacity() != null) { this.setTotalCpuCapacity(vo.getCapacity().getTotalCpu()); this.setAvailableCpuCapacity(vo.getCapacity().getAvailableCpu()); this.setTotalMemoryCapacity(vo.getCapacity().getTotalMemory()); this.setAvailableMemoryCapacity(vo.getCapacity().getAvailableMemory()); this.setCpuSockets(vo.getCapacity().getCpuSockets()); this.setCpuNum(vo.getCapacity().getCpuNum()); } }