Search in sources :

Example 1 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 2 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 3 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 4 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 5 with Provider

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

the class NetworkOrchestrator method shutdownNetworkElementsAndResources.

@Override
public boolean shutdownNetworkElementsAndResources(final ReservationContext context, final boolean cleanupElements, final Network network) {
    // get providers to shutdown
    final List<Provider> providersToShutdown = getNetworkProviders(network.getId());
    // 1) Cleanup all the rules for the network. If it fails, just log the failure and proceed with shutting down
    // the elements
    boolean cleanupResult = true;
    boolean cleanupNeeded = false;
    try {
        for (final Provider provider : providersToShutdown) {
            if (provider.cleanupNeededOnShutdown()) {
                cleanupNeeded = true;
                break;
            }
        }
        if (cleanupNeeded) {
            cleanupResult = shutdownNetworkResources(network.getId(), context.getAccount(), context.getCaller().getId());
        }
    } catch (final Exception ex) {
        s_logger.warn("shutdownNetworkRules failed during the network " + network + " shutdown due to ", ex);
    } finally {
        // just warn the administrator that the network elements failed to shutdown
        if (!cleanupResult) {
            s_logger.warn("Failed to cleanup network id=" + network.getId() + " resources as a part of shutdownNetwork");
        }
    }
    // 2) Shutdown all the network elements
    boolean success = true;
    for (final NetworkElement element : networkElements) {
        if (providersToShutdown.contains(element.getProvider())) {
            try {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Sending network shutdown to " + element.getName());
                }
                if (!element.shutdown(network, context, cleanupElements)) {
                    s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName());
                    success = false;
                }
            } catch (final ResourceUnavailableException e) {
                s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
                success = false;
            } catch (final ConcurrentOperationException e) {
                s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
                success = false;
            } catch (final Exception e) {
                s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e);
                success = false;
            }
        }
    }
    return success;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.legacymodel.exceptions.InsufficientVirtualNetworkCapacityException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) IllegalVirtualMachineException(com.cloud.legacymodel.exceptions.IllegalVirtualMachineException) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) 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