Search in sources :

Example 91 with Network

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

the class NetworkHelperImpl method configureSyncNic.

protected LinkedHashMap<Network, List<? extends NicProfile>> configureSyncNic(final RouterDeploymentDefinition routerDeploymentDefinition) {
    final LinkedHashMap<Network, List<? extends NicProfile>> syncConfig = new LinkedHashMap<>(3);
    logger.debug("Adding nic for Virtual Router in Sync network ");
    final Network syncNic = _networkMgr.setupSyncNetwork(routerDeploymentDefinition.getOwner(), routerDeploymentDefinition.getPlan(), routerDeploymentDefinition.isVpcRouter(), routerDeploymentDefinition.getVpc(), routerDeploymentDefinition.getGuestNetwork());
    syncConfig.put(syncNic, new ArrayList<>());
    return syncConfig;
}
Also used : Network(com.cloud.legacymodel.network.Network) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap)

Example 92 with Network

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

the class VirtualNetworkApplianceManagerImpl method prepareStop.

@Override
public void prepareStop(final VirtualMachineProfile profile) {
    // Collect network usage before stopping Vm
    final DomainRouterVO router = _routerDao.findById(profile.getVirtualMachine().getId());
    if (router == null) {
        return;
    }
    final String privateIP = router.getPrivateIpAddress();
    if (privateIP != null) {
        final boolean forVpc = router.getVpcId() != null;
        final List<? extends Nic> routerNics = _nicDao.listByVmId(router.getId());
        for (final Nic routerNic : routerNics) {
            final Network network = _networkModel.getNetwork(routerNic.getNetworkId());
            // VR
            if (network == null) {
                s_logger.error("Could not find a network with ID => " + routerNic.getNetworkId() + ".");
                continue;
            }
            if (forVpc && network.getTrafficType() == TrafficType.Public || !forVpc && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestType.Isolated) {
                final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName(), forVpc, routerNic.getIPv4Address());
                final String routerType = router.getType().toString();
                final UserStatisticsVO previousStats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterId(), network.getId(), forVpc ? routerNic.getIPv4Address() : null, router.getId(), routerType);
                NetworkUsageAnswer answer = null;
                try {
                    answer = (NetworkUsageAnswer) _agentMgr.easySend(router.getHostId(), usageCmd);
                } catch (final Exception e) {
                    s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId(), e);
                    continue;
                }
                if (answer != null) {
                    if (!answer.getResult()) {
                        s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId() + "; details: " + answer.getDetails());
                        continue;
                    }
                    try {
                        if (answer.getBytesReceived() == 0 && answer.getBytesSent() == 0) {
                            s_logger.debug("Recieved and Sent bytes are both 0. Not updating user_statistics");
                            continue;
                        }
                        final NetworkUsageAnswer answerFinal = answer;
                        Transaction.execute(new TransactionCallbackNoReturn() {

                            @Override
                            public void doInTransactionWithoutResult(final TransactionStatus status) {
                                final UserStatisticsVO stats = _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), network.getId(), forVpc ? routerNic.getIPv4Address() : null, router.getId(), routerType);
                                if (stats == null) {
                                    s_logger.warn("unable to find stats for account: " + router.getAccountId());
                                    return;
                                }
                                if (previousStats != null && (previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived() || previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent())) {
                                    s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. " + "Ignoring current answer. Router: " + answerFinal.getRouterName() + " Rcvd: " + answerFinal.getBytesReceived() + "Sent: " + answerFinal.getBytesSent());
                                    return;
                                }
                                if (stats.getCurrentBytesReceived() > answerFinal.getBytesReceived()) {
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug("Received # of bytes that's less than the last one.  " + "Assuming something went wrong and persisting it. Router: " + answerFinal.getRouterName() + " Reported: " + answerFinal.getBytesReceived() + " Stored: " + stats.getCurrentBytesReceived());
                                    }
                                    stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
                                }
                                stats.setCurrentBytesReceived(answerFinal.getBytesReceived());
                                if (stats.getCurrentBytesSent() > answerFinal.getBytesSent()) {
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug("Received # of bytes that's less than the last one.  " + "Assuming something went wrong and persisting it. Router: " + answerFinal.getRouterName() + " Reported: " + answerFinal.getBytesSent() + " Stored: " + stats.getCurrentBytesSent());
                                    }
                                    stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
                                }
                                stats.setCurrentBytesSent(answerFinal.getBytesSent());
                                if (!_dailyOrHourly) {
                                    // update agg bytes
                                    stats.setAggBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
                                    stats.setAggBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
                                }
                                _userStatsDao.update(stats.getId(), stats);
                            }
                        });
                    } catch (final Exception e) {
                        s_logger.warn("Unable to update user statistics for account: " + router.getAccountId() + " Rx: " + answer.getBytesReceived() + "; Tx: " + answer.getBytesSent());
                    }
                }
            }
        }
    }
}
Also used : Nic(com.cloud.legacymodel.network.Nic) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) NetworkUsageCommand(com.cloud.legacymodel.communication.command.NetworkUsageCommand) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Network(com.cloud.legacymodel.network.Network) NetworkUsageAnswer(com.cloud.legacymodel.communication.answer.NetworkUsageAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO) UserStatisticsVO(com.cloud.user.UserStatisticsVO)

Example 93 with Network

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

the class LoadBalancingRulesManagerImpl method validateLbRule.

@Override
public boolean validateLbRule(final LoadBalancingRule lbRule) {
    final Network network = _networkDao.findById(lbRule.getNetworkId());
    final Purpose purpose = lbRule.getPurpose();
    if (purpose != Purpose.LoadBalancing) {
        s_logger.debug("Unable to validate network rules for purpose: " + purpose.toString());
        return false;
    }
    for (final LoadBalancingServiceProvider ne : _lbProviders) {
        final boolean validated = ne.validateLBRule(network, lbRule);
        if (!validated) {
            return false;
        }
    }
    return true;
}
Also used : Network(com.cloud.legacymodel.network.Network) Purpose(com.cloud.legacymodel.network.FirewallRule.Purpose) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider)

Example 94 with Network

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

the class LoadBalancingRulesManagerImpl method applyLbRules.

public boolean applyLbRules(final List<LoadBalancingRule> rules, final boolean continueOnError) throws ResourceUnavailableException {
    if (rules == null || rules.size() == 0) {
        s_logger.debug("There are no Load Balancing Rules to forward to the network elements");
        return true;
    }
    boolean success = true;
    final Network network = _networkModel.getNetwork(rules.get(0).getNetworkId());
    final List<PublicIp> publicIps = new ArrayList<>();
    // get the list of public ip's owned by the network
    final List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
    if (userIps != null && !userIps.isEmpty()) {
        for (final IPAddressVO userIp : userIps) {
            final PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
            publicIps.add(publicIp);
        }
    }
    // rules can not programmed unless IP is associated with network
    // service provider, so run IP assoication for
    // the network so as to ensure IP is associated before applying
    // rules (in add state)
    _ipAddrMgr.applyIpAssociations(network, false, continueOnError, publicIps);
    try {
        applyLbRules(network, rules);
    } catch (final ResourceUnavailableException e) {
        if (!continueOnError) {
            throw e;
        }
        s_logger.warn("Problems with applying load balancing rules but pushing on", e);
        success = false;
    }
    // if all the rules configured on public IP are revoked then
    // dis-associate IP with network service provider
    _ipAddrMgr.applyIpAssociations(network, true, continueOnError, publicIps);
    return success;
}
Also used : PublicIp(com.cloud.network.addr.PublicIp) Network(com.cloud.legacymodel.network.Network) ArrayList(java.util.ArrayList) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 95 with Network

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

the class LoadBalancingRulesManagerImpl method isRollBackAllowedForProvider.

private boolean isRollBackAllowedForProvider(final LoadBalancerVO loadBalancer) {
    final Network network = _networkDao.findById(loadBalancer.getNetworkId());
    final List<Provider> provider = _networkMgr.getProvidersForServiceInNetwork(network, Service.Lb);
    if (provider == null || provider.size() == 0) {
        return false;
    }
    if (provider.get(0) == Provider.VirtualRouter) {
        return true;
    }
    return false;
}
Also used : Network(com.cloud.legacymodel.network.Network) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider)

Aggregations

Network (com.cloud.legacymodel.network.Network)160 ArrayList (java.util.ArrayList)57 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)56 Account (com.cloud.legacymodel.user.Account)46 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)42 NetworkOffering (com.cloud.offering.NetworkOffering)36 PhysicalNetwork (com.cloud.network.PhysicalNetwork)34 IPAddressVO (com.cloud.network.dao.IPAddressVO)32 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)30 NetworkVO (com.cloud.network.dao.NetworkVO)28 List (java.util.List)28 Zone (com.cloud.db.model.Zone)27 DB (com.cloud.utils.db.DB)27 NicProfile (com.cloud.vm.NicProfile)26 Nic (com.cloud.legacymodel.network.Nic)21 DataCenter (com.cloud.legacymodel.dc.DataCenter)20 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)20 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)19 DomainRouterVO (com.cloud.vm.DomainRouterVO)18 ActionEvent (com.cloud.event.ActionEvent)17