Search in sources :

Example 11 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method getServiceProvidersMap.

private Map<Service, Set<Provider>> getServiceProvidersMap(final long networkId) {
    final Map<Service, Set<Provider>> map = new HashMap<>();
    final List<NetworkServiceMapVO> nsms = _ntwkSrvcDao.getServicesInNetwork(networkId);
    for (final NetworkServiceMapVO nsm : nsms) {
        Set<Provider> providers = map.get(Service.getService(nsm.getService()));
        if (providers == null) {
            providers = new HashSet<>();
        }
        providers.add(Provider.getProvider(nsm.getProvider()));
        map.put(Service.getService(nsm.getService()), providers);
    }
    return map;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(com.cloud.legacymodel.network.Network.Service) ResourceLimitService(com.cloud.user.ResourceLimitService) VpcVirtualNetworkApplianceService(com.cloud.network.VpcVirtualNetworkApplianceService) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) NetworkServiceMapVO(com.cloud.network.dao.NetworkServiceMapVO) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider)

Example 12 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method prepareAllNicsForMigration.

/*
      Prepare All Nics for migration including the nics dynamically created and not stored in DB
      This is a temporary workaround work KVM migration
      Once clean fix is added by stored dynamically nics is DB, this workaround won't be needed
     */
@Override
public void prepareAllNicsForMigration(final VirtualMachineProfile vm, final DeployDestination dest) {
    final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
    final ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), null, null);
    Long guestNetworkId = null;
    for (final NicVO nic : nics) {
        final NetworkVO network = _networksDao.findById(nic.getNetworkId());
        if (network.getTrafficType().equals(TrafficType.Guest) && network.getGuestType().equals(GuestType.Isolated)) {
            guestNetworkId = network.getId();
        }
        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.getNetworkTag(vm.getHypervisorType(), network));
        if (guru instanceof NetworkMigrationResponder) {
            if (!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)) {
                // XXX: Transaction error
                s_logger.error("NetworkGuru " + guru + " prepareForMigration failed.");
            }
        }
        final List<Provider> providersToImplement = getNetworkProviders(network.getId());
        for (final NetworkElement element : networkElements) {
            if (providersToImplement.contains(element.getProvider())) {
                if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
                    throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + "" + network.getPhysicalNetworkId());
                }
                if (element instanceof NetworkMigrationResponder) {
                    if (!((NetworkMigrationResponder) element).prepareMigration(profile, network, vm, dest, context)) {
                        // XXX: Transaction error
                        s_logger.error("NetworkElement " + element + " prepareForMigration failed.");
                    }
                }
            }
        }
        guru.updateNicProfile(profile, network);
        vm.addNic(profile);
    }
    final List<String> addedURIs = new ArrayList<>();
    if (guestNetworkId != null) {
        final List<IPAddressVO> publicIps = _ipAddressDao.listByAssociatedNetwork(guestNetworkId, null);
        for (final IPAddressVO userIp : publicIps) {
            final PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
            final URI broadcastUri = BroadcastDomainType.Vlan.toUri(publicIp.getVlanTag());
            final long ntwkId = publicIp.getNetworkId();
            final Nic nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(ntwkId, vm.getId(), broadcastUri.toString());
            if (nic == null && !addedURIs.contains(broadcastUri.toString())) {
                // Nic details are not available in DB
                // Create nic profile for migration
                s_logger.debug("Creating nic profile for migration. BroadcastUri: " + broadcastUri.toString() + " NetworkId: " + ntwkId + " Vm: " + vm.getId());
                final NetworkVO network = _networksDao.findById(ntwkId);
                _networkModel.getNetworkRate(network.getId(), vm.getId());
                final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
                final NicProfile profile = new NicProfile();
                profile.setIPv4Address(userIp.getAddress().toString());
                profile.setIPv4Netmask(publicIp.getNetmask());
                profile.setIPv4Gateway(publicIp.getGateway());
                profile.setMacAddress(publicIp.getMacAddress());
                profile.setBroadcastType(network.getBroadcastDomainType());
                profile.setTrafficType(network.getTrafficType());
                profile.setBroadcastUri(broadcastUri);
                profile.setIsolationUri(Networks.IsolationType.Vlan.toUri(publicIp.getVlanTag()));
                profile.setName(_networkModel.getNetworkTag(vm.getHypervisorType(), network));
                profile.setNetworId(network.getId());
                guru.updateNicProfile(profile, network);
                vm.addNic(profile);
                addedURIs.add(broadcastUri.toString());
            }
        }
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkMigrationResponder(com.cloud.network.NetworkMigrationResponder) PublicIp(com.cloud.network.addr.PublicIp) NetworkGuru(com.cloud.network.guru.NetworkGuru) ArrayList(java.util.ArrayList) Nic(com.cloud.legacymodel.network.Nic) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) URI(java.net.URI) ReservationContext(com.cloud.vm.ReservationContext) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) IPAddressVO(com.cloud.network.dao.IPAddressVO) NicVO(com.cloud.vm.NicVO)

Example 13 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method rollbackNicForMigration.

@Override
public void rollbackNicForMigration(final VirtualMachineProfile src, final VirtualMachineProfile dst) {
    for (final NicProfile nicDst : dst.getNics()) {
        final NetworkVO network = _networksDao.findById(nicDst.getNetworkId());
        final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
        final NicProfile nicSrc = findNicProfileById(src, nicDst.getId());
        final ReservationContext src_context = new ReservationContextImpl(nicSrc.getReservationId(), null, null);
        final ReservationContext dst_context = new ReservationContextImpl(nicDst.getReservationId(), null, null);
        if (guru instanceof NetworkMigrationResponder) {
            ((NetworkMigrationResponder) guru).rollbackMigration(nicDst, network, dst, src_context, dst_context);
        }
        final List<Provider> providersToImplement = getNetworkProviders(network.getId());
        for (final NetworkElement element : networkElements) {
            if (providersToImplement.contains(element.getProvider())) {
                if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
                    throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId());
                }
                if (element instanceof NetworkMigrationResponder) {
                    ((NetworkMigrationResponder) element).rollbackMigration(nicDst, network, dst, src_context, dst_context);
                }
            }
        }
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkMigrationResponder(com.cloud.network.NetworkMigrationResponder) NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NetworkGuru(com.cloud.network.guru.NetworkGuru) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider)

Example 14 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method implementNetworkElementsAndResources.

@Override
public void implementNetworkElementsAndResources(final DeployDestination dest, final ReservationContext context, final Network network, final NetworkOffering offering) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException {
    // Associate a source NAT IP (if one isn't already associated with the network) if this is a
    // 1) 'Isolated' or 'Shared' guest virtual network in the advance zone
    // 2) network has sourceNat service
    // 3) network offering does not support a shared source NAT rule
    final boolean sharedSourceNat = offering.getSharedSourceNat();
    final Zone zone = _zoneRepository.findById(network.getDataCenterId()).orElse(null);
    if (!sharedSourceNat && _networkModel.areServicesSupportedInNetwork(network.getId(), Service.SourceNat) && (network.getGuestType() == GuestType.Isolated || network.getGuestType() == GuestType.Shared && zone.getNetworkType() == com.cloud.model.enumeration.NetworkType.Advanced)) {
        List<IPAddressVO> ips = null;
        final Account owner = _entityMgr.findById(Account.class, network.getAccountId());
        if (network.getVpcId() != null) {
            ips = _ipAddressDao.listByVpc(network.getVpcId(), true);
            if (ips.isEmpty()) {
                final Vpc vpc = _vpcMgr.getActiveVpc(network.getVpcId());
                s_logger.debug("Creating a source nat ip for vpc " + vpc);
                _vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc);
            }
        } else {
            ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
            if (ips.isEmpty()) {
                s_logger.debug("Creating a source nat ip for network " + network);
                _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
            }
        }
    }
    // get providers to implement
    final List<Provider> providersToImplement = getNetworkProviders(network.getId());
    implementNetworkElements(dest, context, network, offering, providersToImplement);
    for (final NetworkElement element : networkElements) {
        if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
            ((AggregatedCommandExecutor) element).prepareAggregatedExecution(network, dest);
        }
    }
    try {
        // reapply all the firewall/staticNat/lb rules
        s_logger.debug("Reprogramming network " + network + " as a part of network implement");
        if (!reprogramNetworkRules(network.getId(), CallContext.current().getCallingAccount(), network)) {
            s_logger.warn("Failed to re-program the network as a part of network " + network + " implement");
            // see DataCenterVO.java
            final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
            ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
            throw ex;
        }
        for (final NetworkElement element : networkElements) {
            if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
                if (!((AggregatedCommandExecutor) element).completeAggregatedExecution(network, dest)) {
                    s_logger.warn("Failed to re-program the network as a part of network " + network + " implement due to aggregated commands execution failure!");
                    // see DataCenterVO.java
                    final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
                    ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
                    throw ex;
                }
            }
        }
    } finally {
        for (final NetworkElement element : networkElements) {
            if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
                ((AggregatedCommandExecutor) element).cleanupAggregatedExecution(network, dest);
            }
        }
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) AggregatedCommandExecutor(com.cloud.network.element.AggregatedCommandExecutor) NetworkElement(com.cloud.network.element.NetworkElement) Zone(com.cloud.db.model.Zone) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) IPAddressVO(com.cloud.network.dao.IPAddressVO) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider)

Example 15 with Provider

use of com.cloud.legacymodel.network.Network.Provider in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method rollingRestartIsolatedNetwork.

private boolean rollingRestartIsolatedNetwork(final NetworkVO network, final List<DomainRouterVO> routers, final ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
    final Account caller = CallContext.current().getCallingAccount();
    final long callerUserId = CallContext.current().getCallingUserId();
    final int sleepTimeInMsAfterRouterStart = 10000;
    final int numberOfRoutersWhenSingle = 1;
    final int numberOfRoutersWhenRedundant = 2;
    // check the master and backup redundant state
    DomainRouterVO masterRouter = null;
    DomainRouterVO backupRouter = null;
    if (routers != null && routers.size() == numberOfRoutersWhenSingle) {
        masterRouter = routers.get(0);
    }
    if (routers != null && routers.size() == numberOfRoutersWhenRedundant) {
        final DomainRouterVO router1 = routers.get(0);
        final DomainRouterVO router2 = routers.get(1);
        if (router1.getRedundantState() == RedundantState.MASTER || router2.getRedundantState() == RedundantState.BACKUP) {
            masterRouter = router1;
            backupRouter = router2;
        } else if (router1.getRedundantState() == RedundantState.BACKUP || router2.getRedundantState() == RedundantState.MASTER) {
            masterRouter = router2;
            backupRouter = router1;
        } else {
            // both routers are in UNKNOWN state or in the same state. Order doesn't matter.
            masterRouter = router1;
            backupRouter = router2;
        }
    }
    final NetworkOfferingVO offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
    final DeployDestination dest = new DeployDestination(_zoneRepository.findById(network.getDataCenterId()).orElse(null), null, null, null);
    final List<Provider> providersToImplement = getNetworkProviders(network.getId());
    // destroy backup router
    if (backupRouter != null) {
        _routerService.destroyRouter(backupRouter.getId(), caller, callerUserId);
    }
    // create new backup router
    implementNetworkElements(dest, context, network, offering, providersToImplement);
    // destroy master router
    if (masterRouter != null) {
        try {
            // wait for the keepalived/conntrackd on router
            Thread.sleep(sleepTimeInMsAfterRouterStart);
        } catch (final InterruptedException e) {
            s_logger.trace("Ignoring InterruptedException.", e);
        }
        _routerService.destroyRouter(masterRouter.getId(), caller, callerUserId);
        // create a new router
        implementNetworkElements(dest, context, network, offering, providersToImplement);
    }
    return true;
}
Also used : Account(com.cloud.legacymodel.user.Account) DeployDestination(com.cloud.deploy.DeployDestination) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider)

Aggregations

Provider (com.cloud.legacymodel.network.Network.Provider)55 Service (com.cloud.legacymodel.network.Network.Service)29 HashSet (java.util.HashSet)25 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)22 HashMap (java.util.HashMap)22 Set (java.util.Set)22 ArrayList (java.util.ArrayList)21 NetworkElement (com.cloud.network.element.NetworkElement)19 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)15 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)14 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)14 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)13 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)13 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)12 ResourceLimitService (com.cloud.user.ResourceLimitService)12 Network (com.cloud.legacymodel.network.Network)11 VpcProvider (com.cloud.network.element.VpcProvider)10 NicProfile (com.cloud.vm.NicProfile)10 SortedSet (java.util.SortedSet)10 NetworkVO (com.cloud.network.dao.NetworkVO)8