protected void pushToUpdateQueue(final List<NetworkVO> networks) throws InterruptedException { for (final NetworkVO network : networks) { if (!_vrUpdateQueue.offer(network.getId(), 500, TimeUnit.MILLISECONDS)) { s_logger.warn("Cannot insert into virtual router update queue! Adjustment of router.check.interval and router.check.poolsize maybe needed."); break; } } } }
@Override public String getIpOfNetworkElementInVirtualNetwork(long accountId, long dataCenterId) { List<NetworkVO> virtualNetworks = _networksDao.listByZoneAndGuestType(accountId, dataCenterId, GuestType.Isolated, false); if (virtualNetworks.isEmpty()) { s_logger.trace("Unable to find default Virtual network account id=" + accountId); return null; } NetworkVO virtualNetwork = virtualNetworks.get(0); NicVO networkElementNic = _nicDao.findByNetworkIdAndType(virtualNetwork.getId(), Type.DomainRouter); if (networkElementNic != null) { return networkElementNic.getIPv4Address(); } else { s_logger.warn("Unable to set find network element for the network id=" + virtualNetwork.getId()); return null; } }
private void setRestartRequired(final NetworkVO network, final boolean restartRequired) { s_logger.debug("Marking network " + network + " with restartRequired=" + restartRequired); network.setRestartRequired(restartRequired); _networksDao.update(network.getId(), network); }
@Override public StorageNetworkIpRangeVO doInTransaction(TransactionStatus status) throws SQLException { StorageNetworkIpRangeVO range = new StorageNetworkIpRangeVO(zoneId, podId, nw.getId(), startIp, endIpFinal, vlan, netmask, cmd.getGateWay()); _sNwIpRangeDao.persist(range); try { createStorageIpEntires(TransactionLegacy.currentTxn(), range.getId(), startIp, endIpFinal, zoneId); } catch (SQLException e) { StringBuilder err = new StringBuilder(); err.append("Create storage network range failed."); err.append("startIp=" + startIp); err.append("endIp=" + endIpFinal); err.append("netmask=" + netmask); err.append("zoneId=" + zoneId); s_logger.debug(err.toString(), e); throw e; } return range; } });
private void saveVmNetworks(VMEntityVO vm) { List<Long> networks = new ArrayList<Long>(); List<String> networksIds = vm.getNetworkIds(); if (networksIds == null || (networksIds != null && networksIds.isEmpty())) { return; } for (String uuid : networksIds) { NetworkVO network = _networkDao.findByUuid(uuid); if (network != null) { networks.add(network.getId()); } } _vmNetworkMapDao.persist(vm.getId(), networks); }
/** * Swaps the UUID's of the given networks * @param oldNetwork * @param newNetwork */ private void swapUuids(NetworkVO oldNetwork, NetworkVO newNetwork) { String realUuid = oldNetwork.getUuid(); String dummyUuid = newNetwork.getUuid(); oldNetwork.setUuid(dummyUuid.replace("-","+")); newNetwork.setUuid(realUuid); _networksDao.update(oldNetwork.getId(), oldNetwork); _networksDao.update(newNetwork.getId(), newNetwork); oldNetwork.setUuid(dummyUuid); _networksDao.update(oldNetwork.getId(), oldNetwork); }
@Override public List<NetworkVO> listNetworksForAccount(long accountId, long zoneId, GuestType type) { List<NetworkVO> accountNetworks = new ArrayList<NetworkVO>(); List<NetworkVO> zoneNetworks = _networksDao.listByZone(zoneId); for (NetworkVO network : zoneNetworks) { if (!isNetworkSystem(network)) { if (network.getGuestType() == GuestType.Shared || !_networksDao.listBy(accountId, network.getId()).isEmpty()) { if (type == null || type == network.getGuestType()) { accountNetworks.add(network); } } } } return accountNetworks; }
public VspDomainCleanUp buildVspDomainCleanUp(Domain domain) { VspDomainCleanUp.Builder vspDomainCleanUpBuilder = new VspDomainCleanUp.Builder().uuid(domain.getUuid()); Map<String, List<String>> sharedNetworkUuids = Maps.newHashMap(); List<NetworkVO> allSharedNetworks = _networkDao.listByGuestType(Network.GuestType.Shared); for (NetworkVO sharedNetwork : allSharedNetworks) { if (_networkModel.isNetworkAvailableInDomain(sharedNetwork.getId(), domain.getId())) { String preConfiguredDomainTemplateName = _nuageVspManager.getPreConfiguredDomainTemplateName(sharedNetwork); if (!sharedNetworkUuids.containsKey(preConfiguredDomainTemplateName)) { sharedNetworkUuids.put(preConfiguredDomainTemplateName, Lists.<String>newArrayList()); } sharedNetworkUuids.get(preConfiguredDomainTemplateName).add(sharedNetwork.getUuid()); } } vspDomainCleanUpBuilder.sharedNetworkUuids(sharedNetworkUuids); return vspDomainCleanUpBuilder.build(); }
@Override @DB public NetworkVO persist(final NetworkVO network, final boolean gc, final Map<String, String> serviceProviderMap) { final TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); // 1) create network final NetworkVO newNetwork = super.persist(network); // 2) add account to the network addAccountToNetwork(network.getId(), network.getAccountId(), true); // 3) add network to gc monitor table final NetworkOpVO op = new NetworkOpVO(network.getId(), gc); _opDao.persist(op); // 4) add services/providers for the network persistNetworkServiceProviders(newNetwork.getId(), serviceProviderMap); txn.commit(); return newNetwork; }
@Override public boolean updateState(final State currentState, final Event event, final State nextState, final Network vo, final Object data) { // TODO: ensure this update is correct final TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); final NetworkVO networkVo = (NetworkVO)vo; networkVo.setState(nextState); super.update(networkVo.getId(), networkVo); txn.commit(); return true; }
@Override public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { NetworkVO network = _networkDao.findById(nic.getNetworkId()); if (network != null && _networkModel.networkIsConfiguredForExternalNetworking(network.getDataCenterId(), network.getId())) { return true; } else { return super.release(nic, vm, reservationId); } }
private void loadVmDetailsInMapForExternalDhcpIp() { List<NetworkVO> networks = _networkDao.listByGuestType(Network.GuestType.Shared); for (NetworkVO network: networks) { if(_networkModel.isSharedNetworkWithoutServices(network.getId())) { List<NicVO> nics = _nicDao.listByNetworkId(network.getId()); for (NicVO nic : nics) { if (nic.getIPv4Address() == null) { long nicId = nic.getId(); long vmId = nic.getInstanceId(); VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId); // only load running vms. For stopped vms get loaded on starting if (vmInstance.getState() == State.Running) { VmAndCountDetails vmAndCount = new VmAndCountDetails(vmId, VmIpFetchTrialMax.value()); vmIdCountMap.put(nicId, vmAndCount); } } } } } }
@Override public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { if (_networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.Connectivity)) { return null; } NetworkVO config = (NetworkVO)super.design(offering, plan, userSpecified, owner); if (config == null) { return null; } else if (_networkModel.networkIsConfiguredForExternalNetworking(plan.getDataCenterId(), config.getId())) { /* In order to revert userSpecified network setup */ config.setState(State.Allocated); } return config; }
@Override public void deleteCopyOfNetwork(long networkCopyId, long originalNetworkId) { NetworkVO networkCopy = _networksDao.findById(networkCopyId); NicVO userNic = _nicDao.findByNetworkIdAndType(networkCopyId, VirtualMachine.Type.User); if (userNic != null) { s_logger.error("Something went wrong while migrating nics from the old network to the new network. Failed to delete copy of network. There are still user nics present in the network."); throw new CloudRuntimeException("Failed to delete copy of network. There are still user nics present in the network."); } NetworkVO originalNetwork = _networksDao.findById(originalNetworkId); swapUuids(originalNetwork, networkCopy); try { if (!_networkService.deleteNetwork(networkCopy.getId(), true)) { throw new CloudRuntimeException("Failed to delete network. Clean up not successful."); } } finally { swapUuids(networkCopy, originalNetwork); } originalNetwork.setRelated(originalNetworkId); _networksDao.persist(originalNetwork); }
@Override public List<NicProfile> getNicProfiles(final VirtualMachine vm) { final List<NicVO> nics = _nicDao.listByVmId(vm.getId()); final List<NicProfile> profiles = new ArrayList<NicProfile>(); if (nics != null) { for (final Nic nic : nics) { final NetworkVO network = _networksDao.findById(nic.getNetworkId()); final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network)); guru.updateNicProfile(profile, network); profiles.add(profile); } } return profiles; }
private void buildNicResources(VirtualMachineModel vmModel, VMInstanceVO dbVm, StringBuffer syncLogMsg) throws IOException { List<NicVO> nics = _nicDao.listByVmId(dbVm.getId()); for (NicVO nic : nics) { VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid()); if (vmiModel == null) { vmiModel = new VMInterfaceModel(nic.getUuid()); NetworkVO network = _networksDao.findById(nic.getNetworkId()); VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType()); if (vnModel == null) { s_logger.warn("Unable to locate virtual-network for network id " + network.getId()); continue; } vmiModel.addToVirtualMachine(vmModel); vmiModel.addToVirtualNetwork(vnModel); } vmiModel.build(_manager.getModelController(), dbVm, nic); } }
@Override public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { AllocatedIpSearch = _ipAddressDao.createSearchBuilder(); AllocatedIpSearch.and("allocated", AllocatedIpSearch.entity().getAllocatedTime(), Op.NNULL); AllocatedIpSearch.and("dc", AllocatedIpSearch.entity().getDataCenterId(), Op.EQ); SearchBuilder<NetworkVO> networkJoin = _networksDao.createSearchBuilder(); networkJoin.and("guestType", networkJoin.entity().getGuestType(), Op.EQ); AllocatedIpSearch.join("network", networkJoin, AllocatedIpSearch.entity().getSourceNetworkId(), networkJoin.entity().getId(), JoinBuilder.JoinType.INNER); AllocatedIpSearch.done(); _networkStatsInterval = NumbersUtil.parseInt(_configDao.getValue(Config.DirectNetworkStatsInterval.key()), 86400); _TSinclZones = _configDao.getValue(Config.TrafficSentinelIncludeZones.key()); _TSexclZones = _configDao.getValue(Config.TrafficSentinelExcludeZones.key()); _agentMgr.registerForHostEvents(new DirectNetworkStatsListener(_networkStatsInterval), true, false, false); _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); return true; }
@Override public NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadcastUri) { NicVO nic = null; if (broadcastUri != null) { nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(networkId, vm.getId(), broadcastUri); } else { nic = _nicDao.findByNtwkIdAndInstanceId(networkId, vm.getId()); } if (nic == null) { return null; } NetworkVO network = _networksDao.findById(networkId); Integer networkRate = getNetworkRate(network.getId(), vm.getId()); // NetworkGuru guru = _networkGurus.get(network.getGuruName()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag( vm.getHypervisorType(), network)); // guru.updateNicProfile(profile, network); return profile; }
@Override public List<NetworkVO> listByPhysicalNetworkAndProvider(final long physicalNetworkId, final String providerName) { final SearchBuilder<NetworkServiceMapVO> svcProviderMapSearch = _ntwkSvcMap.createSearchBuilder(); final NetworkServiceMapVO svcProviderEntry = svcProviderMapSearch.entity(); svcProviderMapSearch.and("Provider", svcProviderMapSearch.entity().getProvider(), SearchCriteria.Op.EQ); final SearchBuilder<NetworkVO> networksSearch = createSearchBuilder(); networksSearch.and("physicalNetworkId", networksSearch.entity().getPhysicalNetworkId(), Op.EQ); networksSearch.join("svcProviderMapSearch", svcProviderMapSearch, networksSearch.entity().getId(), svcProviderEntry.getNetworkId(), JoinBuilder.JoinType.INNER); final SearchCriteria<NetworkVO> sc = networksSearch.create(); sc.setJoinParameters("svcProviderMapSearch", "Provider", providerName); sc.setParameters("physicalNetworkId", physicalNetworkId); return listBy(sc); }
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { final NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), relatedFile, name, displayText, predefined .getNetworkDomain(), offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.isSpecifyIpRanges(), vpcId, offering.isRedundantRouter(), predefined.getExternalId()); vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled); vo.setStrechedL2Network(offering.isSupportingStrechedL2()); final NetworkVO networkPersisted = _networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())); networks.add(networkPersisted); if (predefined instanceof NetworkVO && guru instanceof NetworkGuruAdditionalFunctions){ final NetworkGuruAdditionalFunctions functions = (NetworkGuruAdditionalFunctions) guru; functions.finalizeNetworkDesign(networkPersisted.getId(), ((NetworkVO)predefined).getVlanIdAsUUID()); } if (domainId != null && aclType == ACLType.Domain) { _networksDao.addDomainToNetwork(id, domainId, subdomainAccess == null ? true : subdomainAccess); } } });