public static List<L3NetworkInventory> valueOf(Collection<L3NetworkVO> vos) { List<L3NetworkInventory> invs = new ArrayList<L3NetworkInventory>(vos.size()); for (L3NetworkVO vo : vos) { invs.add(valueOf(vo)); } return invs; }
protected L3NetworkInventory getSelfInventory() { return L3NetworkInventory.valueOf(getSelf()); }
public boolean isL3NetworkNeedSecurityGroupService(String l3NetworkUuid) { L3NetworkVO l3 = dbf.findByUuid(l3NetworkUuid, L3NetworkVO.class); L3NetworkInventory l3inv = L3NetworkInventory.valueOf(l3); return isL3NetworkNeedSecurityGroupService(l3inv); }
@Override @Transactional public L3NetworkInventory createL3Network(L3NetworkVO l3vo, APICreateL3NetworkMsg msg) { l3vo.setType(type.toString()); dbf.getEntityManager().persist(l3vo); dbf.getEntityManager().flush(); dbf.getEntityManager().refresh(l3vo); return L3NetworkInventory.valueOf(l3vo); }
private List<VmNicSpec> getVmNicSpecsFromAPICreateVmInstanceMsg(APICreateVmInstanceMsg msg) { List<VmNicSpec> nicSpecs = new ArrayList<>(); Map<String, List<String>> secondaryNetworksMap = new DualStackNicSecondaryNetworksOperator().getSecondaryNetworksFromSystemTags(msg.getSystemTags()); for (String l3Uuid : msg.getL3NetworkUuids()) { List<L3NetworkInventory> l3Invs = new ArrayList<>(); L3NetworkInventory inv = L3NetworkInventory.valueOf(dbf.findByUuid(l3Uuid, L3NetworkVO.class)); l3Invs.add(inv); List<String> secondaryNetworksList = secondaryNetworksMap.get(l3Uuid); if (secondaryNetworksList == null || secondaryNetworksList.isEmpty()) { nicSpecs.add(new VmNicSpec(l3Invs)); continue; } for (String secondaryL3Uuid : secondaryNetworksList) { if (secondaryL3Uuid.equals(l3Uuid)) { continue; } L3NetworkInventory secInv = L3NetworkInventory.valueOf(dbf.findByUuid(secondaryL3Uuid, L3NetworkVO.class)); l3Invs.add(secInv); } nicSpecs.add(new VmNicSpec(l3Invs)); } return nicSpecs; }
private void handle(APIListL3NetworkMsg msg) { List<L3NetworkVO> vos = dl.listByApiMessage(msg, L3NetworkVO.class); List<L3NetworkInventory> invs = L3NetworkInventory.valueOf(vos); APIListL3NetworkReply reply = new APIListL3NetworkReply(); reply.setInventories(invs); bus.reply(msg, reply); }
private void handle(L3NetworkDeletionMsg msg) { L3NetworkInventory inv = L3NetworkInventory.valueOf(self); extpEmitter.beforeDelete(inv); deleteHook(); extpEmitter.afterDelete(inv); L3NetworkDeletionReply reply = new L3NetworkDeletionReply(); bus.reply(msg, reply); }
private void handle(APIDetachNetworkServiceFromL3NetworkMsg msg) { for (Map.Entry<String, List<String>> e : msg.getNetworkServices().entrySet()) { SimpleQuery<NetworkServiceL3NetworkRefVO> q = dbf.createQuery(NetworkServiceL3NetworkRefVO.class); q.add(NetworkServiceL3NetworkRefVO_.networkServiceProviderUuid, Op.EQ, e.getKey()); q.add(NetworkServiceL3NetworkRefVO_.l3NetworkUuid, Op.EQ, self.getUuid()); q.add(NetworkServiceL3NetworkRefVO_.networkServiceType, Op.IN, e.getValue()); List<NetworkServiceL3NetworkRefVO> refs = q.list(); if (refs.isEmpty()) { logger.warn(String.format("no network service references found for the provider[uuid:%s] and L3 network[uuid:%s]", e.getKey(), self.getUuid())); } else { dbf.removeCollection(refs, NetworkServiceL3NetworkRefVO.class); } logger.debug(String.format("successfully detached network service provider[uuid:%s] to l3network[uuid:%s, name:%s] with services%s", e.getKey(), self.getUuid(), self.getName(), e.getValue())); } self = dbf.reload(self); APIDetachNetworkServiceFromL3NetworkEvent evt = new APIDetachNetworkServiceFromL3NetworkEvent(msg.getId()); evt.setInventory(L3NetworkInventory.valueOf(self)); bus.publish(evt); }
private void handle(APIGetAttachablePublicL3ForVRouterMsg msg) { APIGetAttachablePublicL3ForVRouterReply reply = new APIGetAttachablePublicL3ForVRouterReply(); List<L3NetworkVO> l3NetworkVOS = Q.New(L3NetworkVO.class).notEq(L3NetworkVO_.category, L3NetworkCategory.Private).list(); List<VmNicVO> vmNicVOS = Q.New(VmNicVO.class).eq(VmNicVO_.vmInstanceUuid, msg.getVmInstanceUuid()).list(); if (l3NetworkVOS == null || l3NetworkVOS.isEmpty()) { reply.setInventories(new ArrayList<L3NetworkInventory>()); bus.reply(msg, reply); return; } Set<L3NetworkVO> attachableL3NetworkVOS = new HashSet<>(l3NetworkVOS); for (L3NetworkVO l3NetworkVO : l3NetworkVOS) { for (VmNicVO vmNicVO : vmNicVOS) { if (l3NetworkVO.getIpRanges() == null || l3NetworkVO.getIpRanges().isEmpty()) { attachableL3NetworkVOS.remove(l3NetworkVO); } String vmNicCidr = NetworkUtils.getCidrFromIpMask(vmNicVO.getIp(), vmNicVO.getNetmask()); if (NetworkUtils.isCidrOverlap(l3NetworkVO.getIpRanges().stream().findFirst().get().getNetworkCidr(), vmNicCidr)) { attachableL3NetworkVOS.remove(l3NetworkVO); } attachableL3NetworkVOS.removeAll(attachableL3NetworkVOS.stream() .filter(vo -> vo.getUuid().equals(vmNicVO.getL3NetworkUuid())) .collect(Collectors.toSet())); } } reply.setInventories(L3NetworkInventory.valueOf(attachableL3NetworkVOS)); bus.reply(msg, reply); }
@Override public void run(FlowTrigger trigger, Map data) { ApplianceVmVO avo = (ApplianceVmVO) chain.getData().get(ApplianceVmVO.class.getSimpleName()); final ApplianceVmInventory inv = ApplianceVmInventory.valueOf(avo); StartNewCreatedApplianceVmMsg msg = new StartNewCreatedApplianceVmMsg(); List<VmNicSpec> nicSpecs = new ArrayList<>(); L3NetworkInventory mnL3 = L3NetworkInventory.valueOf(dbf.findByUuid(spec.getManagementNic().getL3NetworkUuid(), L3NetworkVO.class)); nicSpecs.add(new VmNicSpec(mnL3)); for (ApplianceVmNicSpec aSpec : spec.getAdditionalNics()) { L3NetworkInventory l3 = L3NetworkInventory.valueOf(dbf.findByUuid(aSpec.getL3NetworkUuid(), L3NetworkVO.class)); nicSpecs.add(new VmNicSpec(l3)); } msg.setL3NetworkUuids(nicSpecs); msg.setVmInstanceInventory(inv); msg.setApplianceVmSpec(spec); bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, inv.getUuid()); bus.send(msg, new CloudBusCallBack(complete) { @Override public void run(MessageReply reply) { if (reply.isSuccess()) { trigger.next(); } else { trigger.fail(reply.getError()); } } }); }
private void handle(APIChangeL3NetworkStateMsg msg) { if (L3NetworkStateEvent.enable.toString().equals(msg.getStateEvent())) { self.setState(L3NetworkState.Enabled); } else { self.setState(L3NetworkState.Disabled); } self = dbf.updateAndRefresh(self); APIChangeL3NetworkStateEvent evt = new APIChangeL3NetworkStateEvent(msg.getId()); evt.setInventory(L3NetworkInventory.valueOf(self)); bus.publish(evt); }
private void prepareLifeCycleInfo(FlowChain chain) { ApplianceVmPostLifeCycleInfo info = new ApplianceVmPostLifeCycleInfo(); ApplianceVmInventory ainv = ApplianceVmInventory.valueOf(getSelf()); L3NetworkVO defaultRouteL3VO = dbf.findByUuid(ainv.getDefaultRouteL3NetworkUuid(), L3NetworkVO.class); info.setDefaultRouteL3Network(L3NetworkInventory.valueOf(defaultRouteL3VO)); info.setManagementNic(ainv.getManagementNic()); chain.getData().put(ApplianceVmConstant.Params.applianceVmInfoForPostLifeCycle.toString(), info); }
@Override public void run(MessageReply reply) { if (reply.isSuccess()) { self = dbf.reload(self); evt.setInventory(L3NetworkInventory.valueOf(self)); bus.publish(evt); } else { evt.setError(reply.getError()); bus.publish(evt); } } });
private void handle(final RemoveDnsMsg msg) { final RemoveDnsReply reply = new RemoveDnsReply(); L3NetworkInventory l3 = L3NetworkInventory.valueOf(dbf.findByUuid(msg.getL3NetworkUuid(), L3NetworkVO.class)); NetworkServiceProviderType ptype = getNetworkServiceProviderType(NetworkServiceType.DNS, l3); if (ptype == null) { bus.reply(msg, reply); return; } NetworkServiceDnsBackend bkd = dnsBackends.get(ptype); bkd.removeDns(l3, list(msg.getDns()), new Completion(msg) { @Override public void success() { bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { reply.setError(errorCode); bus.reply(msg, reply); } }); }
private void handle(final AddDnsMsg msg) { final AddDnsReply reply = new AddDnsReply(); L3NetworkInventory l3 = L3NetworkInventory.valueOf(dbf.findByUuid(msg.getL3NetworkUuid(), L3NetworkVO.class)); NetworkServiceProviderType ptype = getNetworkServiceProviderType(NetworkServiceType.DNS, l3); if (ptype == null) { bus.reply(msg, reply); return; } NetworkServiceDnsBackend bkd = dnsBackends.get(ptype); bkd.addDns(l3, list(msg.getDns()), new Completion(msg) { @Override public void success() { bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { reply.setError(errorCode); bus.reply(msg, reply); } }); }
@Override @Transactional(readOnly = true) public NetworkServiceProviderType getTypeOfNetworkServiceProviderForService(String l3NetworkUuid, NetworkServiceType serviceType) { L3NetworkVO l3vo = Q.New(L3NetworkVO.class).eq(L3NetworkVO_.uuid, l3NetworkUuid).find(); L3NetworkInventory l3inv = L3NetworkInventory.valueOf(l3vo); NetworkServiceL3NetworkRefInventory targetRef = null; for (NetworkServiceL3NetworkRefInventory ref : l3inv.getNetworkServices()) { if (ref.getNetworkServiceType().equals(serviceType.toString())) { targetRef = ref; break; } } if (targetRef == null) { throw new OperationFailureException(operr("L3Network[uuid:%s] doesn't have network service[type:%s] enabled or no provider provides this network service", l3NetworkUuid, serviceType)); } String providerType = Q.New(NetworkServiceProviderVO.class) .select(NetworkServiceProviderVO_.type) .eq(NetworkServiceProviderVO_.uuid, targetRef.getNetworkServiceProviderUuid()) .findValue(); return NetworkServiceProviderType.valueOf(providerType); }
private void handle(final RemoveHostRouteMsg msg) { final RemoveHostRouteReply reply = new RemoveHostRouteReply(); L3NetworkInventory l3 = L3NetworkInventory.valueOf(dbf.findByUuid(msg.getL3NetworkUuid(), L3NetworkVO.class)); NetworkServiceProviderType ptype = getNetworkServiceProviderType(NetworkServiceType.HostRoute, l3); if (ptype == null) { reply.setError(operr("L3Network [uuid: %s] provide type null", msg.getL3NetworkUuid())); bus.reply(msg, reply); return; } NetworkServiceHostRouteBackend bkd = hostRouteBackends.get(ptype); bkd.removeHostRoute(msg.getL3NetworkUuid(), asList(msg), new Completion(msg) { @Override public void fail(ErrorCode errorCode) { reply.setError(errorCode); bus.reply(msg, reply); } @Override public void success() { bus.reply(msg, reply); } }); }
private void handle(final AddHostRouteMsg msg) { final AddHostRouteReply reply = new AddHostRouteReply(); L3NetworkInventory l3 = L3NetworkInventory.valueOf(dbf.findByUuid(msg.getL3NetworkUuid(), L3NetworkVO.class)); NetworkServiceProviderType ptype = getNetworkServiceProviderType(NetworkServiceType.HostRoute, l3); if (ptype == null) { reply.setError(operr("L3Network [uuid: %s] does not have host route service", msg.getL3NetworkUuid())); bus.reply(msg, reply); return; } NetworkServiceHostRouteBackend bkd = hostRouteBackends.get(ptype); bkd.addHostRoute(msg.getL3NetworkUuid(), asList(msg), new Completion(msg) { @Override public void success() { bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { reply.setError(errorCode); bus.reply(msg, reply); } }); }
private PortForwardingStruct makePortForwardingStruct(PortForwardingRuleInventory rule) { VipVO vipvo = dbf.findByUuid(rule.getVipUuid(), VipVO.class); L3NetworkVO vipL3vo = dbf.findByUuid(vipvo.getL3NetworkUuid(), L3NetworkVO.class); VmNicVO nic = dbf.findByUuid(rule.getVmNicUuid(), VmNicVO.class); L3NetworkVO guestL3vo = dbf.findByUuid(nic.getL3NetworkUuid(), L3NetworkVO.class); PortForwardingStruct struct = new PortForwardingStruct(); struct.setRule(rule); struct.setVip(VipInventory.valueOf(vipvo)); struct.setGuestIp(nic.getIp()); struct.setGuestMac(nic.getMac()); struct.setGuestL3Network(L3NetworkInventory.valueOf(guestL3vo)); struct.setSnatInboundTraffic(PortForwardingGlobalConfig.SNAT_INBOUND_TRAFFIC.value(Boolean.class)); struct.setVipL3Network(L3NetworkInventory.valueOf(vipL3vo)); return struct; }
struct.setGuestL3Network(l3); struct.setSnatInboundTraffic(PortForwardingGlobalConfig.SNAT_INBOUND_TRAFFIC.value(Boolean.class)); struct.setVipL3Network(L3NetworkInventory.valueOf(l3vo)); struct.setReleaseVmNicInfoWhenDetaching(releaseVmNicInfo); struct.setReleaseVip(false);