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;
}
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());
}
}
}
}
}
}
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;
}
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;
}
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;
}
Aggregations