@Override public boolean equals(Object t) { if (t == null || !(t instanceof IpAllocatorType)) { return false; } IpAllocatorType type = (IpAllocatorType) t; return type.toString().equals(typeName); }
private IpAllocatorType getIpAllocatorType(AllocateIpMsg msg) { if (msg.getAllocatorStrategy() != null) { return IpAllocatorType.valueOf(msg.getAllocatorStrategy()); } L3NetworkVO l3Vo = Q.New(L3NetworkVO.class).eq(L3NetworkVO_.uuid, msg.getL3NetworkUuid()).find(); if (l3Vo.getIpVersion() == IPv6Constants.IPv4) { return RandomIpAllocatorStrategy.type; } return RandomIpv6AllocatorStrategy.type; }
private void validate(APICreateVipMsg msg) { if (msg.getAllocatorStrategy() != null && !IpAllocatorType.hasType(msg.getAllocatorStrategy())) { throw new ApiMessageInterceptionException(argerr("unsupported ip allocation strategy[%s]", msg.getAllocatorStrategy())); } if (msg.getRequiredIp() != null) { L3NetworkVO l3NetworkVO = dbf.findByUuid(msg.getL3NetworkUuid(), L3NetworkVO.class); if (l3NetworkVO.getIpVersion() == IPv6Constants.IPv4) { if (!NetworkUtils.isIpv4Address(msg.getRequiredIp())) { throw new ApiMessageInterceptionException(argerr("requiredIp[%s] is not in valid IPv4 mediaType", msg.getRequiredIp())); } } else { if (!IPv6NetworkUtils.isIpv6UnicastAddress(msg.getRequiredIp())) { if (!NetworkUtils.isIpv4Address(msg.getRequiredIp())) { throw new ApiMessageInterceptionException(argerr("requiredIp[%s] is not in valid IPv6 mediaType", msg.getRequiredIp())); } } } SimpleQuery<VipVO> q = dbf.createQuery(VipVO.class); q.add(VipVO_.ip, Op.EQ, msg.getRequiredIp()); q.add(VipVO_.l3NetworkUuid, Op.EQ, msg.getL3NetworkUuid()); if (q.isExists()) { throw new ApiMessageInterceptionException(operr("there is already a vip[%s] on l3Network[uuid:%s]", msg.getRequiredIp(), msg.getL3NetworkUuid())); } } } }
@Override public IpAllocatorStrategy getIpAllocatorStrategy(IpAllocatorType type) { IpAllocatorStrategy factory = ipAllocatorStrategies.get(type.toString()); if (factory == null) { throw new CloudRuntimeException(String.format("Cannot find IpAllocatorStrategy for type(%s)", type)); } return factory; }
private void populateExtensions() { for (L3NetworkFactory f : pluginRgty.getExtensionList(L3NetworkFactory.class)) { L3NetworkFactory old = l3NetworkFactories.get(f.getType().toString()); if (old != null) { throw new CloudRuntimeException(String.format("duplicate L3NetworkFactory[%s, %s] for type[%s]", f.getClass().getName(), old.getClass().getName(), f.getType())); } l3NetworkFactories.put(f.getType().toString(), f); } for (IpAllocatorStrategy f : pluginRgty.getExtensionList(IpAllocatorStrategy.class)) { IpAllocatorStrategy old = ipAllocatorStrategies.get(f.getType().toString()); if (old != null) { throw new CloudRuntimeException(String.format("duplicate IpAllocatorStrategy[%s, %s] for type[%s]", f.getClass().getName(), old.getClass().getName(), f.getType())); } ipAllocatorStrategies.put(f.getType().toString(), f); } for (UsedIpNotAccountMetaDataExtensionPoint f : pluginRgty.getExtensionList(UsedIpNotAccountMetaDataExtensionPoint.class)) { notAccountMetaDatas.add(f.usedIpNotAccountMetaData()); } }