@Override public String call(HostInventory arg) { return arg.getUuid(); } });
@Override public void sort() { subCandidates.clear(); subCandidates.addAll(candidates); List<String> softAvoidHosts = spec.getSoftAvoidHostUuids(); if (softAvoidHosts == null || softAvoidHosts.isEmpty()) { return; } subCandidates.removeIf(inv -> softAvoidHosts.contains(inv.getUuid())); }
@Override public String getHostUuid() { return vmSpec.getDestHost().getUuid(); }
@Override public String getHostUuid() { return vmSpec.getDestHost().getUuid(); }
@Override public void sort() { Map<String, HostInventory> hosts = candidates.stream().collect(Collectors.toMap(HostInventory::getUuid, (candidate) -> candidate)); List<String> sortedHostUuids = findLeastVmHost(candidates.stream().map(HostInventory::getUuid).collect(Collectors.toList())); candidates.clear(); sortedHostUuids.forEach(huuid -> candidates.add(hosts.get(huuid))); logger.debug(String.format("Sorted by StoppedVmAwareLeastVmPreferred the hosts %s", candidates.stream().map(c -> c.getUuid()).collect(Collectors.toList()))); }
@Override public void sort() { Map<String, HostInventory> hosts = candidates.stream().collect(Collectors.toMap(HostInventory::getUuid, (candidate) -> candidate)); List<String> sortedHostUuids = findLeastVmHost(candidates.stream().map(HostInventory::getUuid).collect(Collectors.toList())); candidates.clear(); sortedHostUuids.forEach(huuid -> candidates.add(hosts.get(huuid))); logger.debug(String.format("Sorted by LeastVmPreferred the hosts %s", candidates.stream().map(c -> c.getUuid()).collect(Collectors.toList()))); }
@Override public void run(VmInstanceMigrateExtensionPoint ext) { ext.beforeMigrateVm(spec.getVmInventory(), destHost.getUuid()); } });
public Do() { hostUuids = new ArrayList<>(); List<HostInventory> hinvs = primaryStorageFactory.getConnectedHostForOperation(getSelfInventory(),0,50); hinvs.forEach(it -> hostUuids.add(it.getUuid())); if (hostUuids.isEmpty()) { throw new OperationFailureException(operr("cannot find any connected host to perform the operation, it seems all KVM hosts" + " in the clusters attached with the shared mount point storage[uuid:%s] are disconnected", self.getUuid())); } }
@Override public void applyDhcpService(List<DhcpStruct> dhcpStructList, VmInstanceSpec spec, final Completion completion) { if (dhcpStructList.isEmpty()) { completion.success(); return; } applyDhcpToHosts(toDhcpInfo(dhcpStructList), spec.getDestHost().getUuid(), false, completion); }
public Result audit(APIMessage msg, APIEvent rsp) { String uuid = ""; if (rsp.isSuccess()) { APIAddHostEvent evt = (APIAddHostEvent) rsp; uuid = evt.getInventory().getUuid(); } return new Result(uuid, HostVO.class); } }
private void reserveCapacity(final HostInventory host) { new HostAllocatorChain().reserveCapacity(host.getUuid(), allocationSpec.getCpuCapacity(), allocationSpec.getMemoryCapacity()); logger.debug(String.format("[Host Allocation]: successfully reserved cpu[%s], memory[%s bytes] on host[uuid:%s] for vm[uuid:%s]", allocationSpec.getCpuCapacity(), allocationSpec.getMemoryCapacity(), host.getUuid(), allocationSpec.getVmInstance().getUuid())); }
private void rollbackCapacity(final HostInventory host) { new HostAllocatorChain().reserveCapacity(host.getUuid(), 0L - allocationSpec.getCpuCapacity(),0L - allocationSpec.getMemoryCapacity()); logger.debug(String.format("[Host Allocation]: successfully rollback cpu[%s], memory[%s bytes] on host[uuid:%s] for vm[uuid:%s]", allocationSpec.getCpuCapacity(), allocationSpec.getMemoryCapacity(), host.getUuid(), allocationSpec.getVmInstance().getUuid())); } }
public void setParametersFromVmSpec(VmInstanceSpec vmSpec) { vmUuid = vmSpec.getVmInventory().getUuid(); vmNics = vmSpec.getDestNics(); hostUuid = vmSpec.getDestHost().getUuid(); }
@Override void handle(InstantiateVolumeOnPrimaryStorageMsg msg, ReturnValueCompletion<InstantiateVolumeOnPrimaryStorageReply> completion) { if (msg instanceof InstantiateRootVolumeFromTemplateOnPrimaryStorageMsg) { createRootVolume((InstantiateRootVolumeFromTemplateOnPrimaryStorageMsg) msg, completion); } else { createEmptyVolume(msg.getVolume(), msg.getDestHost().getUuid(), completion); } }
@Override public void after(APIEvent evt) { if (evt.isSuccess()) { ntfy("Added").resource(((APIAddHostEvent)evt).getInventory().getUuid(), HostVO.class.getSimpleName()) .messageAndEvent(that, evt).done(); } } };
@Override public void releaseDhcpService(List<DhcpStruct> dhcpStructsList, final VmInstanceSpec spec, final NoErrorCompletion completion) { if (dhcpStructsList.isEmpty()) { completion.done(); return; } releaseDhcpService(toDhcpInfo(dhcpStructsList), spec.getVmInventory().getUuid(), spec.getDestHost().getUuid(), completion); }
@Override public void run(MessageReply reply) { if (!reply.isSuccess()) { logger.warn(String.format("failed to stop vm[uuid:%s] on host[uuid:%s], %s", spec.getVmInventory().getUuid(), spec.getDestHost().getUuid(), reply.getError())); } chain.rollback(); } });
@Override public void afterDeleteHost(HostInventory inventory) { String clusterUuid = inventory.getClusterUuid(); List<String> psUuids = getNfsPrimaryStorageInCluster(clusterUuid); if(psUuids == null || psUuids.isEmpty()) { return; } if (Q.New(HostVO.class).eq(HostVO_.clusterUuid, clusterUuid).notEq(HostVO_.uuid, inventory.getUuid()).isExists()) { return; } for(String psUuid : psUuids) { releasePrimaryStorageCapacity(psUuid); } }
private void handle(MigrateVmOnHypervisorMsg msg) { MigrateVmOnHypervisorReply reply = new MigrateVmOnHypervisorReply(); if (!config.migrateSuccess) { reply.setError(operr("on purpose")); } else { logger.debug(String.format("Successfully migrate vm[uuid:%s] on simulator host[uuid:%s] to host[uuid:%s]", msg.getVmInventory().getUuid(), self.getUuid(), msg.getDestHostInventory().getUuid())); config.removeVm(msg.getSrcHostUuid(), msg.getVmInventory().getUuid()); config.putVm(msg.getDestHostInventory().getUuid(), msg.getVmInventory().getUuid(), VmInstanceState.Running); } bus.reply(msg, reply); }
@Override public void run(MessageReply reply) { if (!reply.isSuccess()) { logger.warn(String.format("failed to roll back vm[uuid:%s, name:%s] on host[uuid:%s, ip:%s], %s", spec.getVmInventory().getUuid(), spec.getVmInventory().getName(), spec.getDestHost().getUuid(), spec.getDestHost().getName(), reply.getError())); } trigger.rollback(); } });