@Transactional(readOnly = true) private void checkIfVmAlreadyHasVipNetwork(String vmUuid, VipVO vip) { String sql = "select count(*) from VmNicVO nic, VmInstanceVO vm where nic.vmInstanceUuid = vm.uuid" + " and vm.uuid = :vmUuid and nic.l3NetworkUuid = :vipL3Uuid"; TypedQuery<Long> q = dbf.getEntityManager().createQuery(sql, Long.class); q.setParameter("vmUuid", vmUuid); q.setParameter("vipL3Uuid", vip.getL3NetworkUuid()); Long c = q.getSingleResult(); if (c > 0) { throw new ApiMessageInterceptionException(argerr("the vm[uuid:%s] that the EIP is about to attach is already on the public network[uuid:%s] from which" + " the vip[uuid:%s, name:%s, ip:%s] comes", vmUuid, vip.getL3NetworkUuid(), vip.getUuid(), vip.getName(), vip.getIp())); } }
public static VipInventory valueOf(VipVO vo) { VipInventory inv = new VipInventory(); inv.setName(vo.getName()); inv.setDescription(vo.getDescription()); inv.setCreateDate(vo.getCreateDate()); inv.setGateway(vo.getGateway()); inv.setIp(vo.getIp()); inv.setIpRangeUuid(vo.getIpRangeUuid()); inv.setServiceProvider(vo.getServiceProvider()); inv.setL3NetworkUuid(vo.getL3NetworkUuid()); inv.setLastOpDate(vo.getLastOpDate()); inv.setNetmask(vo.getNetmask()); inv.setPrefixLen(vo.getPrefixLen()); inv.setUseFor(vo.getUseFor()); inv.setUuid(vo.getUuid()); inv.setState(vo.getState().toString()); inv.setUsedIpUuid(vo.getUsedIpUuid()); if (vo.getPeerL3NetworkRefs() != null && !vo.getPeerL3NetworkRefs().isEmpty()) { inv.setPeerL3NetworkUuids(vo.getPeerL3NetworkRefs().stream() .map(ref -> ref.getL3NetworkUuid()) .collect(Collectors.toList())); } return inv; }
@Override public void fail(ErrorCode errorCode) { logger.warn(String.format("failed to release vip[uuid:%s, name:%s, ip:%s] on service[%s], its garbage collector should" + " handle this", self.getUuid(), self.getName(), self.getIp(), self.getServiceProvider())); completion.fail(errorCode); } });
@Override public void success() { logger.debug(String.format("successfully released vip[uuid:%s, name:%s, ip:%s] on virtual router vm[uuid:%s]", self.getUuid(), self.getName(), self.getIp(), vrvo.getUuid())); dbf.removeByPrimaryKey(vrvip.getUuid(), vrvip.getClass()); completion.success(); }
protected void refresh() { VipVO vo = dbf.reload(self); if (vo == null) { throw new OperationFailureException(err(SysErrors.RESOURCE_NOT_FOUND, "cannot find the vip[name:%s, uuid:%s, ip:%s], it may have been deleted", self.getName(), self.getUuid(), self.getIp() )); } self = vo; }
List<VirtualRouterVipVO> refs = new ArrayList<>(); for (VipVO vip : vips) { if (vipTOS.stream().anyMatch(v -> v.getIp().equals(vip.getIp()))) { logger.warn(String.format( "found duplicate vip ip[uuid; %s, uuids: %s] for vr[uuid: %s]", vip.getIp(), vips.stream(). filter(v -> v.getIp().equals(vip.getIp())) .map(v -> v.getUuid()) .collect(Collectors.toSet()), to.setIp(vip.getIp()); to.setGateway(vip.getGateway()); to.setNetmask(vip.getNetmask());
@Override public void success() { logger.debug(String.format("successfully released vip[uuid:%s, name:%s, ip:%s] on service[%s]", self.getUuid(), self.getName(), self.getIp(), self.getServiceProvider())); VipUseForList useForList = new VipUseForList(self.getUseFor()); self.setUseFor(null); clearPeerL3Network(); self.setServiceProvider(null); dbf.update(self); completion.success(); }
@Override public void success() { logger.debug(String.format("successfully acquired vip[uuid:%s, name:%s, ip:%s] on service[%s]", self.getUuid(), self.getName(), self.getIp(), s.getServiceProvider())); VipUseForList useForList = new VipUseForList(self.getUseFor()); useForList.add(s.getUseFor()); VipVO vo = Q.New(VipVO.class).eq(VipVO_.uuid, self.getUuid()).find(); vo.setUseFor(useForList.toString()); dbf.updateAndRefresh(vo); addPeerL3NetworkUuid(s.getPeerL3NetworkUuid()); completion.success(); }
evt.setError(operr("Vip [uuid %s, ip %s] of router public interface can not be deleted", self.getUuid(), self.getIp())); bus.publish(evt); return;
" by other service", self.getUuid(), self.getName(), self.getIp())); for (VipCleanupExtensionPoint ext : pluginRgty.getExtensionList(VipCleanupExtensionPoint.class)) { ext.cleanupVip(self.getUuid());
protected boolean acquireCheckModifyVipAttributeStruct(ModifyVipAttributesStruct s) { if (s.isUserFor()) { VipUseForList useForList = new VipUseForList(self.getUseFor()); useForList.add(s.getUseFor()); self.setUseFor(useForList.toString()); } if (s.isServiceProvider()) { if (self.getServiceProvider() != null && s.getServiceProvider() != null && !s.getServiceProvider().equals(self.getServiceProvider())) { throw new OperationFailureException(operr("service provider of the vip[uuid:%s, name:%s, ip: %s] has been set to %s", self.getUuid(), self.getName(), self.getIp(), self.getServiceProvider())); } self.setServiceProvider(s.getServiceProvider()); } if (s.isPeerL3NetworkUuid()) { try { if (s.isServiceProvider()) { addPeerL3NetworkUuid(s.getPeerL3NetworkUuid()); } } catch (CloudRuntimeException e) { throw new OperationFailureException(operr(e.getMessage())); } } self = dbf.updateAndRefresh(self); /* snat service is bound the router interface, don't need to bound to backend */ if (s.getUseFor().equals(NetworkServiceType.SNAT.toString())) { return false; } return s.isPeerL3NetworkUuid() && s.isServiceProvider(); }
chain.setName(String.format("prepare-vr-for-vip-%s-%s", self.getUuid(), self.getIp())); chain.then(new NoRollbackFlow() { @Override
vo.setAllowedCidr(msg.getAllowedCidr()); vo.setVipUuid(vip.getUuid()); vo.setVipIp(vip.getIp()); vo.setVipPortStart(msg.getVipPortStart()); vo.setVipPortEnd(vipPortEnd);