private void handle(L3NetworkUpdateDhcpMsg msg) { L3NetworkUpdateDhcpReply reply = new L3NetworkUpdateDhcpReply(); Map<String, List<DhcpInfo>> l3DhcpMap = new HashMap<String, List<DhcpInfo>>(); List<String> vmUuids = Q.New(VmNicVO.class).eq(VmNicVO_.l3NetworkUuid, msg.getL3NetworkUuid()).select(VmNicVO_.vmInstanceUuid) .groupBy(VmNicVO_.vmInstanceUuid).listValues(); for (String uuid: vmUuids) { VmInstanceInventory vm = VmInstanceInventory.valueOf(dbf.findByUuid(uuid, VmInstanceVO.class)); if (!vm.getState().equals(VmInstanceState.Running.toString()) || vm.getHostUuid() == null) { continue; } String hostUuid = vm.getHostUuid(); List<DhcpInfo> hostInfo = l3DhcpMap.computeIfAbsent(hostUuid, k -> new ArrayList<>()); hostInfo.addAll(getVmDhcpInfo(vm, msg.getL3NetworkUuid())); } applyDhcpToHosts(l3DhcpMap.entrySet().iterator(), new Completion(msg) { @Override public void success() { bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { reply.setError(errorCode); bus.reply(msg, reply); } }); }
@Override public void run(final FlowTrigger chain, Map ctx) { final VolumeInventory volume = (VolumeInventory) ctx.get(VmInstanceConstant.Params.AttachingVolumeInventory.toString()); final VmInstanceSpec spec = (VmInstanceSpec) ctx.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); assert volume != null; assert spec != null; if (spec.getVmInventory().getState().equals(VmInstanceState.Stopped.toString())) { chain.next(); return; } assert VmInstanceState.Running.toString().equals(spec.getVmInventory().getState()); String hostUuid = spec.getVmInventory().getHostUuid(); AttachVolumeToVmOnHypervisorMsg msg = new AttachVolumeToVmOnHypervisorMsg(); msg.setHostUuid(hostUuid); msg.setVmInventory(spec.getVmInventory()); msg.setInventory(volume); bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, hostUuid); bus.send(msg, new CloudBusCallBack(chain) { @Override public void run(MessageReply reply) { if (reply.isSuccess()) { chain.next(); } else { chain.fail(reply.getError()); } } }); }
@Override public void run(final FlowTrigger trigger, final Map data) { final VmInstanceInventory vm = (VmInstanceInventory) data.get(VmInstanceConstant.Params.vmInventory.toString()); final VmNicInventory nic = (VmNicInventory) data.get(VmInstanceConstant.Params.VmNicInventory.toString()); final UsedIpInventory ip = (UsedIpInventory) data.get(VmInstanceConstant.Params.UsedIPInventory.toString()); if (!vm.getState().equals(VmInstanceState.Running.toString())) { trigger.next(); return; } DeleteL3NetworkFromVmNicMsg msg = new DeleteL3NetworkFromVmNicMsg(); msg.setVmInstanceUuid(vm.getUuid()); msg.setVmNicUuid(nic.getUuid()); msg.setNewL3Uuid(ip.getL3NetworkUuid()); bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, vm.getUuid()); bus.send(msg, new CloudBusCallBack(trigger) { @Override public void run(MessageReply reply) { if (reply.isSuccess()) { trigger.next(); } else { trigger.fail(reply.getError()); } } }); }
@Override public void run(final FlowTrigger trigger, final Map data) { final VmInstanceInventory vm = (VmInstanceInventory) data.get(VmInstanceConstant.Params.vmInventory.toString()); final VmNicInventory nic = (VmNicInventory) data.get(VmInstanceConstant.Params.VmNicInventory.toString()); final L3NetworkInventory l3Inv = (L3NetworkInventory)data.get(VmInstanceConstant.Params.L3NetworkInventory.toString()); if (!vm.getState().equals(VmInstanceState.Running.toString())) { trigger.next(); return; } AddL3NetworkToVmNicMsg msg = new AddL3NetworkToVmNicMsg(); msg.setVmInstanceUuid(vm.getUuid()); msg.setVmNicUuid(nic.getUuid()); msg.setNewL3Uuid(l3Inv.getUuid()); bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, vm.getUuid()); bus.send(msg, new CloudBusCallBack(trigger) { @Override public void run(MessageReply reply) { if (reply.isSuccess()) { trigger.next(); } else { trigger.fail(reply.getError()); } } }); }
for (VmDeletionStruct inv : vminvs) { if (!vmStateCanStop.stream().anyMatch( str -> str.trim().equals(inv.getInventory().getState()))) { continue;
if (VmInstanceState.Stopped.toString().equals(spec.getVmInventory().getState())) { chain.next(); return;
DebugUtils.Assert(previousL3 != null || nowL3 != null, "why I get two NULL L3 networks!!!!"); if (!VmInstanceState.Running.toString().equals(vm.getState())) { return;
self.setState(VmInstanceState.valueOf(msg.getState())); update = true; if (!vm.getState().equals(msg.getState())) { extensions.add(new Runnable() { @Override
public VmInstanceInventory(VmInstanceInventory origin) { VmInstanceInventory inv; try { inv = (VmInstanceInventory) origin.clone(); } catch (CloneNotSupportedException e) { throw new CloudRuntimeException(e); } this.setClusterUuid(inv.getClusterUuid()); this.setCreateDate(inv.getCreateDate()); this.setDescription(inv.getDescription()); this.setHostUuid(inv.getHostUuid()); this.setHypervisorType(inv.getHypervisorType()); this.setImageUuid(inv.getImageUuid()); this.setInstanceOfferingUuid(inv.getInstanceOfferingUuid()); this.setLastHostUuid(inv.getLastHostUuid()); this.setLastOpDate(inv.getLastOpDate()); this.setName(inv.getName()); this.setRootVolumeUuid(inv.getRootVolumeUuid()); this.setState(inv.getState()); this.setType(inv.getType()); this.setUuid(inv.getUuid()); this.setZoneUuid(inv.getZoneUuid()); this.setAllVolumes(inv.getAllVolumes()); this.setVmNics(inv.getVmNics()); this.setInternalId(inv.getInternalId()); this.setCpuNum(inv.getCpuNum()); this.setCpuSpeed(inv.getCpuSpeed()); this.setMemorySize(inv.getMemorySize()); this.setAllocatorStrategy(inv.getAllocatorStrategy()); }