Search in sources :

Example 21 with NetworkGuru

use of com.cloud.network.guru.NetworkGuru in project cloudstack by apache.

the class NetworkOrchestrator method commitNicForMigration.

@Override
public void commitNicForMigration(final VirtualMachineProfile src, final VirtualMachineProfile dst) {
    for (final NicProfile nicSrc : src.getNics()) {
        final NetworkVO network = _networksDao.findById(nicSrc.getNetworkId());
        final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
        final NicProfile nicDst = findNicProfileById(dst, nicSrc.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).commitMigration(nicSrc, network, src, 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).commitMigration(nicSrc, network, src, src_context, dst_context);
                }
            }
        }
        // update the reservation id
        final NicVO nicVo = _nicDao.findById(nicDst.getId());
        nicVo.setReservationId(nicDst.getReservationId());
        _nicDao.persist(nicVo);
    }
}
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.utils.exception.CloudRuntimeException) NetworkGuru(com.cloud.network.guru.NetworkGuru) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) NicVO(com.cloud.vm.NicVO) ReservationContext(com.cloud.vm.ReservationContext) DnsServiceProvider(com.cloud.network.element.DnsServiceProvider) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 22 with NetworkGuru

use of com.cloud.network.guru.NetworkGuru in project cloudstack by apache.

the class NetworkOrchestrator method implementNetwork.

@Override
@DB
public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final Pair<NetworkGuru, NetworkVO> implemented = new Pair<NetworkGuru, NetworkVO>(null, null);
    NetworkVO network = _networksDao.findById(networkId);
    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
    if (isNetworkImplemented(network)) {
        s_logger.debug("Network id=" + networkId + " is already implemented");
        implemented.set(guru, network);
        return implemented;
    }
    // Acquire lock only when network needs to be implemented
    network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
    if (network == null) {
        // see NetworkVO.java
        final ConcurrentOperationException ex = new ConcurrentOperationException("Unable to acquire network configuration");
        ex.addProxyObject(_entityMgr.findById(Network.class, networkId).getUuid());
        throw ex;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Lock is acquired for network id " + networkId + " as a part of network implement");
    }
    try {
        if (isNetworkImplemented(network)) {
            s_logger.debug("Network id=" + networkId + " is already implemented");
            implemented.set(guru, network);
            return implemented;
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Asking " + guru.getName() + " to implement " + network);
        }
        final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
        network.setReservationId(context.getReservationId());
        if (isSharedNetworkWithServices(network)) {
            network.setState(Network.State.Implementing);
        } else {
            stateTransitTo(network, Event.ImplementNetwork);
        }
        final Network result = guru.implement(network, offering, dest, context);
        network.setCidr(result.getCidr());
        network.setBroadcastUri(result.getBroadcastUri());
        network.setGateway(result.getGateway());
        network.setMode(result.getMode());
        network.setPhysicalNetworkId(result.getPhysicalNetworkId());
        _networksDao.update(networkId, network);
        // implement network elements and re-apply all the network rules
        implementNetworkElementsAndResources(dest, context, network, offering);
        if (isSharedNetworkWithServices(network)) {
            network.setState(Network.State.Implemented);
        } else {
            stateTransitTo(network, Event.OperationSucceeded);
        }
        network.setRestartRequired(false);
        _networksDao.update(network.getId(), network);
        implemented.set(guru, network);
        return implemented;
    } catch (final NoTransitionException e) {
        s_logger.error(e.getMessage());
        return null;
    } catch (final CloudRuntimeException e) {
        s_logger.error("Caught exception: " + e.getMessage());
        return null;
    } finally {
        if (implemented.first() == null) {
            s_logger.debug("Cleaning up because we're unable to implement the network " + network);
            try {
                if (isSharedNetworkWithServices(network)) {
                    network.setState(Network.State.Shutdown);
                    _networksDao.update(networkId, network);
                } else {
                    stateTransitTo(network, Event.OperationFailed);
                }
            } catch (final NoTransitionException e) {
                s_logger.error(e.getMessage());
            }
            try {
                shutdownNetwork(networkId, context, false);
            } catch (final Exception e) {
                // Don't throw this exception as it would hide the original thrown exception, just log
                s_logger.error("Exception caught while shutting down a network as part of a failed implementation", e);
            }
        }
        _networksDao.releaseFromLockTable(networkId);
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Lock is released for network id " + networkId + " as a part of network implement");
        }
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkGuru(com.cloud.network.guru.NetworkGuru) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConnectionException(com.cloud.exception.ConnectionException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) ConfigurationException(javax.naming.ConfigurationException) Pair(com.cloud.utils.Pair) DB(com.cloud.utils.db.DB)

Aggregations

NetworkGuru (com.cloud.network.guru.NetworkGuru)22 NetworkVO (com.cloud.network.dao.NetworkVO)19 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 NicProfile (com.cloud.vm.NicProfile)11 DhcpServiceProvider (com.cloud.network.element.DhcpServiceProvider)9 NicVO (com.cloud.vm.NicVO)9 Provider (com.cloud.network.Network.Provider)8 DnsServiceProvider (com.cloud.network.element.DnsServiceProvider)8 LoadBalancingServiceProvider (com.cloud.network.element.LoadBalancingServiceProvider)8 NetworkElement (com.cloud.network.element.NetworkElement)8 StaticNatServiceProvider (com.cloud.network.element.StaticNatServiceProvider)8 UserDataServiceProvider (com.cloud.network.element.UserDataServiceProvider)8 DB (com.cloud.utils.db.DB)7 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 Pair (com.cloud.utils.Pair)6 ArrayList (java.util.ArrayList)6 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)5 Network (com.cloud.network.Network)5