@Override public List<VmNicVO> call(VmInstanceVO arg) { List<VmNicVO> lst = new ArrayList<VmNicVO>(); lst.addAll(arg.getVmNics()); return lst; } });
if (!self.getVmNics().isEmpty()){ for (String l3uuid: self.getVmNics().stream().flatMap(nic -> VmNicHelper.getL3Uuids(VmNicInventory.valueOf(nic)).stream()) .distinct().collect(Collectors.toList())){ clusterUuids = getCandidateClusterUuidsFromAttachedL3(l3uuid, clusterUuids); if (!self.getVmNics().isEmpty()) { List<String> vmL3Uuids = self.getVmNics().stream().flatMap(nic -> VmNicHelper.getL3Uuids(VmNicInventory.valueOf(nic)).stream()) .distinct().collect(Collectors.toList()); l3s = l3s.stream().filter(l3 -> !vmL3Uuids.contains(l3.getUuid())).collect(Collectors.toList());
private String buildUrl(String path) { String mgmtNicIp = CollectionUtils.find(self.getVmNics(), new Function<String, VmNicVO>() { @Override public String call(VmNicVO arg) { if (arg.getL3NetworkUuid().equals(getSelf().getManagementNetworkUuid())) { return arg.getIp(); } return null; } }); return buildAgentUrl(mgmtNicIp, path, getSelf().getAgentPort()); }
if (self.getVmNics().isEmpty()) { if (l3Uuids == null) {
@Override public void handle(Map data) { CollectionUtils.safeForEach(pluginRgty.getExtensionList(VmAfterExpungeExtensionPoint.class), arg -> arg.vmAfterExpunge(inv)); callVmJustBeforeDeleteFromDbExtensionPoint(); dbf.reload(self); dbf.removeCollection(self.getVmNics(), VmNicVO.class); dbf.removeCollection(self.getVmCdRoms(), VmCdRomVO.class); dbf.remove(self); logger.debug(String.format("successfully expunged the vm[uuid:%s]", self.getUuid())); dbf.eoCleanup(VmInstanceVO.class, Collections.singletonList(self.getUuid())); completion.success(); } }).error(new FlowErrorHandler(completion) {
final VmNicVO candidate = CollectionUtils.find(self.getVmNics(), new Function<VmNicVO, VmNicVO>() { @Override public VmNicVO call(VmNicVO arg) {
amsg.setAllocatorStrategy(HostAllocatorConstant.MIGRATE_VM_ALLOCATOR_TYPE); amsg.setVmOperation(VmOperation.Migrate.toString()); amsg.setL3NetworkUuids(VmNicHelper.getL3Uuids(VmNicInventory.valueOf(self.getVmNics()))); amsg.setDryRun(true); amsg.setAllowNoL3Networks(true);
private void detachNic(final String nicUuid, boolean releaseNic, final Completion completion) { VmNicVO vmNicVO = CollectionUtils.find(self.getVmNics(), new Function<VmNicVO, VmNicVO>() { @Override public VmNicVO call(VmNicVO arg) { CollectionUtils.find(self.getVmNics(), new Function<VmNicVO, VmNicVO>() { @Override public VmNicVO call(VmNicVO arg) {
private void changeVmIp(final String l3Uuid, final String ip, final Completion completion) { final VmNicVO targetNic = CollectionUtils.find(self.getVmNics(), new Function<VmNicVO, VmNicVO>() { @Override public VmNicVO call(VmNicVO arg) {
VmNicVO nic = CollectionUtils.find(self.getVmNics(), new Function<VmNicVO, VmNicVO>() { @Override public VmNicVO call(VmNicVO arg) {
@Override public void run(FlowTrigger chain, Map data) { DesignatedAllocateHostMsg msg = new DesignatedAllocateHostMsg(); msg.setCpuCapacity(cpuNum - oldCpuNum); msg.setMemoryCapacity(struct.alignedMemory - oldMemorySize); msg.setAllocatorStrategy(HostAllocatorConstant.DESIGNATED_HOST_ALLOCATOR_STRATEGY_TYPE); msg.setVmInstance(VmInstanceInventory.valueOf(self)); if (self.getImageUuid() != null && dbf.findByUuid(self.getImageUuid(), ImageVO.class) != null) { msg.setImage(ImageInventory.valueOf(dbf.findByUuid(self.getImageUuid(), ImageVO.class))); } msg.setHostUuid(self.getHostUuid()); msg.setFullAllocate(false); msg.setL3NetworkUuids(VmNicHelper.getL3Uuids(VmNicInventory.valueOf(self.getVmNics()))); msg.setServiceId(bus.makeLocalServiceId(HostAllocatorConstant.SERVICE_ID)); bus.send(msg, new CloudBusCallBack(chain) { @Override public void run(MessageReply reply) { if (!reply.isSuccess()) { ErrorCode err = operr("host[uuid:%s] capacity is not enough to offer cpu[%s], memory[%s bytes]", self.getHostUuid(), cpuNum - oldCpuNum, struct.alignedMemory - oldMemorySize); err.setCause(reply.getError()); chain.fail(err); } else { result = true; logger.debug(String.format("reserve memory %s bytes and cpu %s on host[uuid:%s]", memorySize - self.getMemorySize(), cpuNum - self.getCpuNum(), self.getHostUuid())); chain.next(); } } }); }
private void getStartingCandidateHosts(final NeedReplyMessage msg, final ReturnValueCompletion completion) { refreshVO(); ErrorCode err = validateOperationByState(msg, self.getState(), SysErrors.OPERATION_ERROR); if (err != null) { throw new OperationFailureException(err); } final DesignatedAllocateHostMsg amsg = new DesignatedAllocateHostMsg(); amsg.setCpuCapacity(self.getCpuNum()); amsg.setMemoryCapacity(self.getMemorySize()); amsg.setVmInstance(VmInstanceInventory.valueOf(self)); amsg.setServiceId(bus.makeLocalServiceId(HostAllocatorConstant.SERVICE_ID)); amsg.setAllocatorStrategy(self.getAllocatorStrategy()); amsg.setVmOperation(VmOperation.Start.toString()); if (self.getImageUuid() != null && dbf.findByUuid(self.getImageUuid(), ImageVO.class) != null) { amsg.setImage(ImageInventory.valueOf(dbf.findByUuid(self.getImageUuid(), ImageVO.class))); } amsg.setL3NetworkUuids(VmNicHelper.getL3Uuids(VmNicInventory.valueOf(self.getVmNics()))); amsg.setDryRun(true); amsg.setListAllHosts(true); bus.send(amsg, new CloudBusCallBack(completion) { @Override public void run(MessageReply re) { if (!re.isSuccess()) { completion.fail(re.getError()); } else { completion.success(re); } } }); }
protected VmInstanceInventory(VmInstanceVO vo) { this.setUuid(vo.getUuid()); this.setName(vo.getName()); this.setDescription(vo.getDescription()); this.setZoneUuid(vo.getZoneUuid()); this.setClusterUuid(vo.getClusterUuid()); this.setImageUuid(vo.getImageUuid()); this.setHostUuid(vo.getHostUuid()); this.setLastHostUuid(vo.getLastHostUuid()); this.setInstanceOfferingUuid(vo.getInstanceOfferingUuid()); this.setType(vo.getType()); this.setHypervisorType(vo.getHypervisorType()); this.setCreateDate(vo.getCreateDate()); this.setLastOpDate(vo.getLastOpDate()); this.setState(vo.getState().toString()); this.setRootVolumeUuid(vo.getRootVolumeUuid()); this.setAllVolumes(VolumeInventory.valueOf(vo.getAllVolumes())); this.setVmNics(VmNicInventory.valueOf(vo.getVmNics())); this.setVmCdRoms(VmCdRomInventory.valueOf(vo.getVmCdRoms())); this.setInternalId(vo.getInternalId()); this.setDefaultL3NetworkUuid(vo.getDefaultL3NetworkUuid()); this.setCpuNum(vo.getCpuNum()); this.setCpuSpeed(vo.getCpuSpeed()); this.setMemorySize(vo.getMemorySize()); this.setAllocatorStrategy(vo.getAllocatorStrategy()); this.setPlatform(vo.getPlatform()); }