private void validate(APICreateEipMsg msg) { String useFor = Q.New(VipVO.class).select(VipVO_.useFor).eq(VipVO_.uuid, msg.getVipUuid()).findValue(); VipUseForList vipUseForList; if (useFor != null){ vipUseForList = new VipUseForList(useFor); } else { vipUseForList = new VipUseForList(); } if(!vipUseForList.validateNewAdded(EipConstant.EIP_NETWORK_SERVICE_TYPE)){ throw new ApiMessageInterceptionException(operr("the vip[uuid:%s] already has bound to other service[%s]", msg.getVipUuid(), vipUseForList.toString())); } }
public boolean validate(){ /* eip and other services(SNAT,LB,IPSec,PF) can not be attached to same vip */ if(isIncluded(EIP_NETWORK_SERVICE_TYPE) && this.useForList.size() > 1){ return false; } else{ return true; } }
public boolean validateNewAdded(VipUseForList newList){ Iterator<String> it = newList.getUseForList().iterator(); while (it.hasNext()){ String useFor = it.next(); if(!validateNewAdded(useFor)){ return false; } } return true; }
VipVO vip = dbf.findByUuid(vvipVO.getUuid(), VipVO.class); if (vip != null && vip.getUseFor() != null){ VipUseForList useForList = new VipUseForList(vip.getUseFor()); if(useForList.isIncluded(VirtualRouterConstant.SNAT_NETWORK_SERVICE_TYPE)) { vips.add(vip);
@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(); }
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; } }
private void validate(APICreateEipMsg msg) { VipVO vip = dbf.findByUuid(msg.getVipUuid(), VipVO.class); if (vip.getUseFor() != null) { VipUseForList useForList = new VipUseForList(vip.getUseFor()); if(!useForList.validateNewAdded(EipConstant.EIP_NETWORK_SERVICE_TYPE)) { throw new ApiMessageInterceptionException(operr("vip[uuid:%s] has been occupied other network service entity[%s]", msg.getVipUuid(), vip.getUseFor())); } } if (vip.getState() != VipState.Enabled) { throw new ApiMessageInterceptionException(operr("vip[uuid:%s] is not in state[%s], current state is %s", msg.getVipUuid(), VipState.Enabled, vip.getState())); } if (msg.getVmNicUuid() != null) { SimpleQuery<VmNicVO> nicq = dbf.createQuery(VmNicVO.class); nicq.add(VmNicVO_.uuid, Op.EQ, msg.getVmNicUuid()); VmNicVO nic = nicq.find(); if (VmNicHelper.getL3Uuids(nic).contains(vip.getL3NetworkUuid())) { throw new ApiMessageInterceptionException(argerr("guest l3Network of vm nic[uuid:%s] and vip l3Network of vip[uuid: %s] are the same network", msg.getVmNicUuid(), msg.getVipUuid())); } if (msg.getUsedIpUuid() == null) { msg.setUsedIpUuid(nic.getUsedIpUuid()); } else { validateEipGuestIpUuid(msg.getVmNicUuid(), msg.getUsedIpUuid()); } // check if the vm already has a network where the vip comes checkIfVmAlreadyHasVipNetwork(nic.getVmInstanceUuid(), vip); } if (msg.getUsedIpUuid() != null) { isVipInVmNicSubnet(msg.getVipUuid(), msg.getUsedIpUuid()); } }
private List<String> getVipUsedPortList(String vipUuid, String protocol){ String useFor = Q.New(VipVO.class).select(VipVO_.useFor).eq(VipVO_.uuid, vipUuid).findValue(); VipUseForList vipUseForList; if (useFor != null){ vipUseForList = new VipUseForList(useFor); } else { vipUseForList = new VipUseForList(); } List<RangeSet.Range> portRangeList = new ArrayList<RangeSet.Range>(); for (VipGetUsedPortRangeExtensionPoint ext : vipGetUsedPortRangeExtensionPoints) { RangeSet range = ext.getVipUsePortRange(vipUuid, protocol, vipUseForList); portRangeList.addAll(range.getRanges()); } RangeSet portRange = new RangeSet(); portRange.setRanges(portRangeList); return portRange.sortAndToString(); }
public String del(String delItem) { boolean exist = false; Iterator<String> it = this.useForList.iterator(); while (it.hasNext()) { String item = it.next(); if (item.equals(delItem)) { it.remove(); } } return this.toString(); }
VipUseForList useForList = new VipUseForList(self.getUseFor()); if(useForList.isIncluded(VipUseForList.SNAT_NETWORK_SERVICE_TYPE)){ evt.setError(operr("Vip [uuid %s, ip %s] of router public interface can not be deleted", self.getUuid(), self.getIp())); bus.publish(evt);
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(); }
private RangeSet getVipPortRangeList(String vipUuid, String protocol){ String useFor = Q.New(VipVO.class).select(VipVO_.useFor).eq(VipVO_.uuid, vipUuid).findValue(); VipUseForList vipUseForList; if (useFor != null){ vipUseForList = new VipUseForList(useFor); } else { vipUseForList = new VipUseForList(); } List<RangeSet.Range> portRangeList = new ArrayList<RangeSet.Range>(); for (VipGetUsedPortRangeExtensionPoint ext : pluginRgty.getExtensionList(VipGetUsedPortRangeExtensionPoint.class)){ RangeSet range = ext.getVipUsePortRange(vipUuid, protocol, vipUseForList); portRangeList.addAll(range.getRanges()); } RangeSet portRange = new RangeSet(); portRange.setRanges(portRangeList); portRange.sort(); return portRange; }
public String add(String newItem){ boolean exist = false; Iterator<String> it = this.useForList.iterator(); while (it.hasNext()) { String item = it.next(); if (item.equals(newItem)) { exist = true; break; } } if (!exist) { this.useForList.add(newItem); } return this.toString(); }
private void validate(APICreateLoadBalancerMsg msg) { SimpleQuery<VipVO> q = dbf.createQuery(VipVO.class); q.select(VipVO_.useFor); q.add(VipVO_.uuid, Op.EQ, msg.getVipUuid()); String useFor = q.findValue(); if(useFor != null){ VipUseForList useForList = new VipUseForList(useFor); if(!useForList.validateNewAdded(LoadBalancerConstants.LB_NETWORK_SERVICE_TYPE_STRING)){ throw new ApiMessageInterceptionException(argerr("the vip[uuid:%s] has been occupied other network service entity[%s]", msg.getVipUuid(), useForList.toString())); } } }
final VipInventory vip = VipInventory.valueOf(dbf.findByUuid(struct.getLb().getVipUuid(), VipVO.class)); VipUseForList useForList = new VipUseForList(vip.getUseFor()); if (!useForList.isIncluded(LoadBalancerConstants.LB_NETWORK_SERVICE_TYPE_STRING)) { logger.warn(String.format("the vip[uuid:%s, name:%s, ip:%s, useFor: %s] is not for load balancer", vip.getUuid(), vip.getName(), vip.getIp(), vip.getUseFor()));
@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(); }
public boolean validateNewAdded(String newItem){ /* eip and other services(SNAT,LB,IPSec,PF) can not be attached to same vip */ if(newItem.equals(EIP_NETWORK_SERVICE_TYPE)){ if (this.useForList.isEmpty()){ return true; } else { return false; } } else{ if (isIncluded(EIP_NETWORK_SERVICE_TYPE)){ return false; } else { return true; } } }
VipUseForList useForList = new VipUseForList(useFor); if(!useForList.validateNewAdded(PortForwardingConstant.PORTFORWARDING_NETWORK_SERVICE_TYPE)){ throw new ApiMessageInterceptionException(argerr("the vip[uuid:%s] has been occupied other network service entity[%s]", msg.getVipUuid(), useForList.toString()));
VipUseForList useForList = new VipUseForList(vipVO.getUseFor()); boolean isTcpProto = msg.getProtocol().equals(LoadBalancerConstants.LB_PROTOCOL_TCP) || msg.getProtocol().equals(LoadBalancerConstants.LB_PROTOCOL_HTTP) boolean isTcpReservePort = msg.getLoadBalancerPort() == LoadBalancerConstants.SSH_PORT || msg.getLoadBalancerPort() == LoadBalancerConstants.ZVR_PORT; if (isTcpProto && isTcpReservePort && useForList.isIncluded(useForList.SNAT_NETWORK_SERVICE_TYPE)) { throw new ApiMessageInterceptionException(argerr("tcp port 22, 7272 is used by vrouter"));