use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class RebootRouterCmd method execute.
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
CallContext.current().setEventDetails("Router Id: " + getId());
final VirtualRouter result = _routerService.rebootRouter(getId(), true);
if (result != null) {
final DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
response.setResponseName("router");
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reboot router");
}
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class VirtualNetworkApplianceManagerImpl method stopRouter.
@ActionEvent(eventType = EventTypes.EVENT_ROUTER_STOP, eventDescription = "stopping router Vm", async = true)
@Override
public VirtualRouter stopRouter(final long routerId, final boolean forced) throws ResourceUnavailableException, ConcurrentOperationException {
final CallContext context = CallContext.current();
final Account account = context.getCallingAccount();
// verify parameters
final DomainRouterVO router = _routerDao.findById(routerId);
if (router == null) {
throw new InvalidParameterValueException("Unable to find router by id " + routerId + ".");
}
_accountMgr.checkAccess(account, null, true, router);
final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
final VirtualRouter virtualRouter = stop(router, forced, user, account);
if (virtualRouter == null) {
throw new CloudRuntimeException("Failed to stop router with id " + routerId);
}
// Clear stop pending flag after stopped successfully
if (router.isStopPending()) {
s_logger.info("Clear the stop pending flag of router " + router.getHostName() + " after stop router successfully");
router.setStopPending(false);
_routerDao.persist(router);
virtualRouter.setStopPending(false);
}
return virtualRouter;
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class CommandSetupHelper method configureLoadBalancer.
private void configureLoadBalancer(final VirtualRouter router, final NetworkOverviewTO.LoadBalancerTO loadBalancerTO) {
ArrayList<NetworkOverviewTO.LoadBalancerTO.LoadBalancersTO> loadBalancers = new ArrayList<>();
final List<NetworkVO> networks = _networkDao.listByVpc(router.getVpcId());
List<Long> networkIds = networks.stream().map(NetworkVO::getId).collect(Collectors.toList());
List<LoadBalancerVO> loadBalancerVO = _loadBalancerDao.listAll().stream().filter(lb -> networkIds.contains(lb.getNetworkId())).collect(Collectors.toList());
List<FirewallRuleVO> loadBalancingRuleList = _rulesDao.listAll().stream().filter(rule -> networkIds.contains(rule.getNetworkId()) && rule.getPurpose().toString().equals("LoadBalancing") && (rule.getState().equals(FirewallRule.State.Active) || rule.getState().equals(FirewallRule.State.Add))).collect(Collectors.toList());
loadBalancingRuleList.forEach(rule -> {
final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
final Optional<LoadBalancerVO> ruleVO = loadBalancerVO.stream().filter(r -> r.getId() == rule.getId()).findFirst();
ruleVO.ifPresent(balancerVO -> {
final NetworkOverviewTO.LoadBalancerTO.StickinessPolicy lbStickinessPolicy = _lbStickinessPolicyDao.listByLoadBalancerId(balancerVO.getId(), false).stream().map(policy -> new NetworkOverviewTO.LoadBalancerTO.StickinessPolicy(policy.getMethodName(), policy.getParams())).findFirst().orElse(null);
final List<NetworkOverviewTO.LoadBalancerTO.LBDestinations> lbDestinationList = _loadBalancerVMMapDao.listByLoadBalancerId(balancerVO.getId(), false).stream().map(vm -> new NetworkOverviewTO.LoadBalancerTO.LBDestinations(vm.getInstanceIp(), balancerVO.getDefaultPortStart())).collect(Collectors.toList());
if (_loadBalancerVMMapDao.listByLoadBalancerId(balancerVO.getId()).size() > 0) {
loadBalancers.add(new NetworkOverviewTO.LoadBalancerTO.LoadBalancersTO(rule.getUuid(), balancerVO.getName(), sourceIp.getAddress().addr(), rule.getSourcePortStart(), rule.getProtocol(), balancerVO.getLbProtocol(), balancerVO.getAlgorithm(), lbDestinationList, lbStickinessPolicy, balancerVO.getClientTimeout(), balancerVO.getServerTimeout()));
}
});
});
String routerPublicIp = null;
if (router instanceof DomainRouterVO) {
final DomainRouterVO domr = _routerDao.findById(router.getId());
routerPublicIp = domr.getPublicIpAddress();
if (routerPublicIp == null) {
routerPublicIp = router.getPublicIpAddress();
}
}
if (networkIds.size() > 0) {
final Network guestNetwork = _networkModel.getNetwork(networkIds.get(0));
final NetworkOffering offering = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId());
final String maxconn;
if (offering.getConcurrentConnections() == null) {
maxconn = _configDao.getValue(Config.NetworkLBHaproxyMaxConn.key());
} else {
maxconn = offering.getConcurrentConnections().toString();
}
loadBalancerTO.setMaxconn(maxconn);
loadBalancerTO.setLbStatsGuestIp(_routerControlHelper.getRouterIpInNetwork(networkIds.get(0), router.getId()));
}
loadBalancerTO.setLbStatsVisibility(_configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key()));
loadBalancerTO.setLbStatsUri(_configDao.getValue(Config.NetworkLBHaproxyStatsUri.key()));
loadBalancerTO.setLbStatsAuth(_configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key()));
loadBalancerTO.setLbStatsPort(_configDao.getValue(Config.NetworkLBHaproxyStatsPort.key()));
loadBalancerTO.setLbStatsPublicIp(routerPublicIp);
loadBalancerTO.setLbStatsPrivateIp(router.getPrivateIpAddress());
loadBalancerTO.setLoadBalancers(loadBalancers.toArray(new NetworkOverviewTO.LoadBalancerTO.LoadBalancersTO[0]));
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class AdvancedNetworkTopology method applyStaticRoutes.
@Override
public boolean applyStaticRoutes(final List<StaticRouteProfile> staticRoutes, final List<DomainRouterVO> routers) throws ResourceUnavailableException {
s_logger.debug("APPLYING STATIC ROUTES RULES");
if (staticRoutes == null || staticRoutes.isEmpty()) {
s_logger.debug("No static routes to apply");
return true;
}
final StaticRoutesRules routesRules = new StaticRoutesRules(staticRoutes);
boolean result = true;
for (final VirtualRouter router : routers) {
if (router.getState() == State.Running) {
result = result && routesRules.accept(_advancedVisitor, router);
} else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending StaticRoute command to the backend");
} else {
s_logger.warn("Unable to apply StaticRoute, virtual router is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to apply StaticRoute on the backend," + " virtual router is not in the right state", DataCenter.class, router.getDataCenterId());
}
}
return result;
}
use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.
the class AdvancedNetworkVisitor method visit.
@Override
public boolean visit(final PublicIpAclsRules acls) throws ResourceUnavailableException {
final VirtualRouter router = acls.getRouter();
final Commands commands = new Commands(Command.OnError.Continue);
final List<? extends NetworkACLItem> rules = acls.getRules();
_commandSetupHelper.createPublicIpACLsCommands(rules, router, commands, acls.getPublicIp());
return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Aggregations