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()); } }
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; }
@Override public String call(HostVO arg) { return arg.getUuid(); } });
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()); } }
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; }
/** * @return hostUuid list * * Just check it : * The current cluster is mounted only local storage * Specified local storage * * Negative impact * In the case of local + non-local and no ps specified (non-local is Disconnected/Disabled, or non-local capacity not enough), the allocated host may not have enough disks */ private List<String> getNeedCheckHostLocalStorageList(List<HostVO> candidates, HostAllocatorSpec spec){ String requiredPrimaryStorageUuid = spec.getRequiredPrimaryStorageUuid(); boolean isRequireNonLocalStorage = false; if(StringUtils.isNotEmpty(requiredPrimaryStorageUuid)){ isRequireNonLocalStorage = !LocalStorageUtils.isLocalStorage(requiredPrimaryStorageUuid); } List<String> result = new ArrayList<>(); for(HostVO hostVO : candidates){ boolean isOnlyAttachedLocalStorage = LocalStorageUtils.isOnlyAttachedLocalStorage(hostVO.getClusterUuid()); if(!isOnlyAttachedLocalStorage && isRequireNonLocalStorage){ continue; } if(!isOnlyAttachedLocalStorage && spec.isDryRun()){ continue; } result.add(hostVO.getUuid()); } return result; }
private boolean checkMigrateNetworkCidrOfHost(String cidr) { if (NetworkUtils.isIpv4InCidr(self.getManagementIp(), cidr)) { return true; } final String extraIps = HostSystemTags.EXTRA_IPS.getTokenByResourceUuid( self.getUuid(), HostSystemTags.EXTRA_IPS_TOKEN); if (extraIps == null) { logger.error(String.format("Host[uuid:%s] has no IPs in migrate network", self.getUuid())); return false; } final String[] ips = extraIps.split(","); for (String ip: ips) { if (NetworkUtils.isIpv4InCidr(ip, cidr)) { return true; } } return false; }
@Override public void run(FlowTrigger trigger, Map data) { String distro = HostSystemTags.OS_DISTRIBUTION.getTokenByResourceUuid(vo.getUuid(), HostSystemTags.OS_DISTRIBUTION_TOKEN); String release = HostSystemTags.OS_RELEASE.getTokenByResourceUuid(vo.getUuid(), HostSystemTags.OS_RELEASE_TOKEN); String version = HostSystemTags.OS_VERSION.getTokenByResourceUuid(vo.getUuid(), HostSystemTags.OS_VERSION_TOKEN); trigger.fail(operr("after connecting, host[name:%s, ip:%s] returns a null os version", vo.getName(), vo.getManagementIp())); return; q.add(HostVO_.clusterUuid, Op.EQ, vo.getClusterUuid()); q.add(HostVO_.uuid, Op.NOT_EQ, vo.getUuid()); q.add(HostVO_.status, Op.NOT_EQ, HostStatus.Connecting); q.setLimit(1); vo.getClusterUuid(), currentVersion, vo.getName(), vo.getManagementIp(), mineVersion)); return;
try { ConnectCmd cmd = new ConnectCmd(); cmd.setHostUuid(self.getUuid()); cmd.setSendCommandUrl(restf.getSendCommandUrl()); cmd.setIptablesRules(KVMGlobalProperty.IPTABLES_RULES); cmd.setIgnoreMsrs(KVMGlobalConfig.KVM_IGNORE_MSRS.value(Boolean.class)); cmd.setPageTableExtensionDisabled(HostSystemTags.PAGE_TABLE_EXTENSION_DISABLED.hasTag(self.getUuid(), HostVO.class)); ConnectResponse rsp = restf.syncJsonPost(connectPath, cmd, ConnectResponse.class); if (!rsp.isSuccess() || !rsp.isIptablesSucc()) { errCode = operr("unable to connect to kvm host[uuid:%s, ip:%s, url:%s], because %s", self.getUuid(), self.getManagementIp(), connectPath, rsp.getError()); } else { VersionComparator libvirtVersion = new VersionComparator(rsp.getLibvirtVersion()); && qemuVersion.compare(KVMConstant.MIN_QEMU_LIVESNAPSHOT_VERSION) >= 0; String hostOS = HostSystemTags.OS_DISTRIBUTION.getTokenByResourceUuid(self.getUuid(), HostSystemTags.OS_DISTRIBUTION_TOKEN); hostOS, self.getUuid(), self.getName(), self.getManagementIp(), rsp.getLibvirtVersion(), rsp.getQemuVersion())); HostSystemTags.LIVE_SNAPSHOT.deleteInherentTag(self.getUuid()); errCode = operr("unable to connect to kvm host[uuid:%s, ip:%s, url:%s], because %s", self.getUuid(), self.getManagementIp(), connectPath, e.getMessage()); } catch (Throwable t) {
protected boolean changeConnectionState(final HostStatusEvent event, Runnable runnable) { String hostUuid = self.getUuid(); self = dbf.reload(self); if(self == null){ HostStatus before = self.getStatus(); HostStatus next = before.nextStatus(event); if (before == next) { self.setStatus(next); Optional.ofNullable(runnable).ifPresent(Runnable::run); self = dbf.updateAndRefresh(self); logger.debug(String.format("Host %s [uuid:%s] changed connection state from %s to %s", self.getName(), self.getUuid(), before, next)); data.setHostUuid(self.getUuid()); data.setNewStatus(next.toString()); data.setOldStatus(before.toString());
protected void checkStatus() { if (HostStatus.Connected != self.getStatus()) { ErrorCode cause = err(HostErrors.HOST_IS_DISCONNECTED, "host[uuid:%s, name:%s] is in status[%s], cannot perform required operation", self.getUuid(), self.getName(), self.getStatus()); throw new OperationFailureException(err(HostErrors.OPERATION_FAILURE_GC_ELIGIBLE, cause, "unable to do the operation because the host is in status of Disconnected")); } }
@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 List<HostVO> allocate(List<HostVO> vos, long cpu, long memory) { List<HostVO> ret = vos.stream() .filter(hvo -> (cpu == 0 || hvo.getCapacity().getAvailableCpu() >= cpu) && (memory == 0 || ratioMgr.calculateHostAvailableMemoryByRatio(hvo.getUuid(), hvo.getCapacity().getAvailableMemory()) >= memory)) .collect(Collectors.toList()); return ret; }
protected HostState changeState(HostStateEvent event) { HostState currentState = self.getState(); HostState next = currentState.nextState(event); changeStateHook(currentState, event, next); extpEmitter.beforeChange(self, event); self.setState(next); self = dbf.updateAndRefresh(self); extpEmitter.afterChange(self, event, currentState); logger.debug(String.format("Host[%s]'s state changed from %s to %s", self.getUuid(), currentState, self.getState())); return self.getState(); }
@Override public void beforeChangeClusterState(ClusterInventory inventory, ClusterStateEvent event, ClusterState nextState) { /* * given changing cluster state is working simultaneously, we change host state one by one * in order to avoid thread pool exhausted */ if (!event.toString().equals(ClusterStateEvent.disable.toString()) && !event.toString().equals(ClusterStateEvent.enable.toString())) { logger.debug("Unsupport ClusterStateEvent: " + event + ", won't propgate to extensions of host"); return; } HostStateEvent hostEvent = HostStateEvent.valueOf(event.toString()); List<HostVO> vos = findHostUnderClusterByUuid(inventory.getUuid()); if (!vos.isEmpty()) { for (HostVO h : vos) { if (h.getState() == HostState.Maintenance || h.getState() == HostState.PreMaintenance) { continue; } ChangeHostStateMsg msg = new ChangeHostStateMsg(h.getUuid(), hostEvent.toString()); bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, h.getUuid()); ChangeHostStateReply r = (ChangeHostStateReply) bus.call(msg); if (!r.isSuccess()) { logger.warn(String.format("Failed to change host[uuid: %s] state(%s) by event(%s), %s", h.getUuid(), h.getState(), hostEvent, r.getError())); } else { logger.debug(String.format("Successfully changed host[uuid: %s] state(%s) by event(%s), new state is %s", h.getUuid(), h.getState(), hostEvent, r.getInventory().getState())); } } } }
private void handle(final CheckVmStateOnHypervisorMsg msg) { final CheckVmStateOnHypervisorReply reply = new CheckVmStateOnHypervisorReply(); if (self.getStatus() != HostStatus.Connected) { reply.setError(operr("the host[uuid:%s, status:%s] is not Connected", self.getUuid(), self.getStatus())); bus.reply(msg, reply); return; cmd.hostUuid = self.getUuid(); new Http<>(checkVmStatePath, cmd, CheckVmStateRsp.class).call(new ReturnValueCompletion<CheckVmStateRsp>(msg) { @Override
@Override public String call(HostVO arg) { return arg.getClusterUuid(); } });
@Override public void deleteHook() { logger.debug(String.format("Host: %s is being deleted", self.getName())); }
cmd.setCpuSpeed(spec.getVmInventory().getCpuSpeed()); cmd.setMemory(spec.getVmInventory().getMemorySize()); cmd.setMaxMemory(self.getCapacity().getTotalPhysicalMemory()); cmd.setClock(ImagePlatform.isType(platform, ImagePlatform.Windows, ImagePlatform.WindowsVirtio) ? "localtime" : "utc"); cmd.setVideoType(VmGlobalConfig.VM_VIDEO_TYPE.value(String.class)); cmd.setBootMode(bootMode == null ? ImageBootMode.Legacy.toString() : bootMode); cmd.setBootDev(toKvmBootDev(spec.getBootOrders())); cmd.setHostManagementIp(self.getManagementIp()); cmd.setConsolePassword(spec.getConsolePassword()); cmd.setUsbRedirect(spec.getUsbRedirect());