protected String getThreadSyncSignature() { return String.format("vip-%s-%s", self.getName(), self.getUuid()); }
@Override public void run(MessageReply reply) { if(!reply.isSuccess()){ logger.debug(String.format("VirtualRouter remove the vip[uuid %s] on the public interface failed.", vo.getUuid())); } completion.success(); } });
@Override protected void scripts() { persist(vipvo); persist(vrvip); tagMgr.copySystemTag(vr.getUuid(), VirtualRouterVmVO.class.getSimpleName(), vipvo.getUuid(), VipVO.class.getSimpleName(), false); } }.execute();
@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 void addPeerL3NetworkUuid(String peerL3NetworkUuid) { if (checkPeerL3Additive(peerL3NetworkUuid) == false) { logger.debug(String.format("can not add peer l3[uuid:%s] to vip[uuid:%s]", peerL3NetworkUuid, self.getUuid())); return; } if (Q.New(VipPeerL3NetworkRefVO.class) .eq(VipPeerL3NetworkRefVO_.vipUuid, self.getUuid()) .eq(VipPeerL3NetworkRefVO_.l3NetworkUuid, peerL3NetworkUuid) .find() != null) { logger.debug(String.format("peer l3 [uuid:%s] has already add to vip[uuid:%s], skip to add", peerL3NetworkUuid, self.getUuid())); return; } VipPeerL3NetworkRefVO vo = new VipPeerL3NetworkRefVO(); vo.setVipUuid(self.getUuid()); vo.setL3NetworkUuid(peerL3NetworkUuid); dbf.persistAndRefresh(vo); logger.debug(String.format("added peer l3[uuid:%s] to vip[uuid:%s]", peerL3NetworkUuid, self.getUuid())); }
@Override public void success() { List<VirtualRouterVipVO> vrvips = new ArrayList<>(); for (VipVO vip : vips) { VirtualRouterVipVO vo = dbf.findByUuid(vip.getUuid(), VirtualRouterVipVO.class); if (vo == null) { vo = new VirtualRouterVipVO(); vo.setUuid(vip.getUuid()); vo.setVirtualRouterVmUuid(vr.getUuid()); vrvips.add(vo); } } if (!vrvips.isEmpty()) { dbf.persistCollection(vrvips); } chain.next(); }
public void deletePeerL3NetworkUuid(String peerL3NetworkUuid) { if (checkPeerL3Deleteable(peerL3NetworkUuid) == false) { return; } VipPeerL3NetworkRefVO vo = Q.New(VipPeerL3NetworkRefVO.class) .eq(VipPeerL3NetworkRefVO_.vipUuid, self.getUuid()) .eq(VipPeerL3NetworkRefVO_.l3NetworkUuid, peerL3NetworkUuid) .find(); if (vo != null) { dbf.remove(vo); } logger.debug(String.format("deleted peer l3[uuid:%s] from vip[uuid:%s]", peerL3NetworkUuid, self.getUuid())); }
@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(); }
public void clearPeerL3Network() { List<VipPeerL3NetworkRefVO> vos = Q.New(VipPeerL3NetworkRefVO.class) .eq(VipPeerL3NetworkRefVO_.vipUuid, self.getUuid()) .list(); if (vos != null && !vos.isEmpty()) { dbf.removeCollection(vos, VipPeerL3NetworkRefVO.class); } self.setPeerL3NetworkRefs(null); refresh(); } }
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; }
@Override public void handle(Map data) { final VirtualRouterVmInventory vr = (VirtualRouterVmInventory) data.get(VirtualRouterConstant.Param.VR.toString()); if (!dbf.isExist(self.getUuid(), VirtualRouterVipVO.class)) { VirtualRouterVipVO vrvip = new VirtualRouterVipVO(); vrvip.setUuid(self.getUuid()); vrvip.setVirtualRouterVmUuid(vr.getUuid()); dbf.persist(vrvip); } CollectionUtils.safeForEach(pluginRgty.getExtensionList(AfterAcquireVipExtensionPoint.class), new ForEachFunction<AfterAcquireVipExtensionPoint>() { @Override public void run(AfterAcquireVipExtensionPoint ext) { logger.debug(String.format("execute after acquire vip extension point %s", ext)); ext.afterAcquireVip(VipInventory.valueOf(getSelf())); } }); completion.success(); } }).error(new FlowErrorHandler(completion) {
private void deleteVips(List<VipVO> vos, Completion completion){ for (VipVO vo: vos) { VipDeletionMsg msg = new VipDeletionMsg(); msg.setVipUuid(vo.getUuid()); bus.makeTargetServiceIdByResourceUuid(msg, VipConstant.SERVICE_ID, msg.getVipUuid()); bus.send(msg, new CloudBusCallBack(completion) { @Override public void run(MessageReply reply) { if(!reply.isSuccess()){ logger.debug(String.format("VirtualRouter remove the vip[uuid %s] on the public interface failed.", vo.getUuid())); } completion.success(); } }); } }
.anyMatch(ref -> ref.getL3NetworkUuid().equals(peerL3NetworkUuid))) { logger.debug(String.format("peer l3 [uuid:%s] has already add to vip[uuid:%s], skip to add", peerL3NetworkUuid, self.getUuid())); return false; if (nnic == null) { logger.debug(String.format("add peer l3[uuid:%s] to vip[uuid:%s], the l3 has no vr attached now", peerL3NetworkUuid, self.getUuid())); return true; "attched vr[uuid:%s] and is not vr[uuid:%s] which exists peer l3 attached", peerL3NetworkUuid, self.getUuid(), nnic.getVmInstanceUuid(), enic.getVmInstanceUuid()));
@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(); }
@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(); }
protected boolean releaseCheckModifyVipAttributeStruct( ModifyVipAttributesStruct s) { VipUseForList useForList = new VipUseForList(self.getUseFor()); if (s.isUserFor() && s.getUseFor().equals(NetworkServiceType.SNAT.toString())) { useForList.del(s.getUseFor()); if (useForList.getUseForList().isEmpty()){ /* snat is bound to router public interface, it is created automatically, * so it should be deleted automatically, but don't need to remove from backend */ dbf.remove(self); } else { self.setUseFor(useForList.toString()); dbf.update(self); } return false; } for (VipGetServiceReferencePoint ext : pluginRgty.getExtensionList(VipGetServiceReferencePoint.class)) { VipGetServiceReferencePoint.ServiceReference service = ext.getServiceReference(self.getUuid()); if (service.useFor.equals(s.getUseFor()) && service.count <= 1){ useForList.del(s.getUseFor()); self.setUseFor(useForList.toString()); dbf.update(self); } } if (useForList.getUseForList().isEmpty()){ return true; } else { return false; } }
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; }
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(); }
checkIfAnotherVip(vip.getUuid(), msg.getVmNicUuid());