protected DomainRouterVO start( DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params, final DeploymentPlan planToDeploy) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Starting router " + router); try { _itMgr.advanceStart(router.getUuid(), params, planToDeploy, null); } catch (final OperationTimedoutException e) { throw new ResourceUnavailableException( "Starting router " + router + " failed! " + e.toString(), DataCenter.class, router.getDataCenterId()); } if (router.isStopPending()) { s_logger.info( "Clear the stop pending flag of router " + router.getHostName() + " after start router successfully!"); router.setStopPending(false); router = _routerDao.persist(router); } // We don't want the failure of VPN Connection affect the status of // router, so we try to make connection // only after router start successfully final Long vpcId = router.getVpcId(); if (vpcId != null) { _s2sVpnMgr.reconnectDisconnectedVpnByVpc(vpcId); } return _routerDao.findById(router.getId()); }
@Override public void handleSingleWorkingRedundantRouter( final List<? extends VirtualRouter> connectedRouters, final List<? extends VirtualRouter> disconnectedRouters, final String reason) throws ResourceUnavailableException { if (connectedRouters.isEmpty() || disconnectedRouters.isEmpty()) { return; } for (final VirtualRouter virtualRouter : connectedRouters) { if (!virtualRouter.getIsRedundantRouter()) { throw new ResourceUnavailableException( "Who is calling this with non-redundant router or non-domain router?", DataCenter.class, virtualRouter.getDataCenterId()); } } for (final VirtualRouter virtualRouter : disconnectedRouters) { if (!virtualRouter.getIsRedundantRouter()) { throw new ResourceUnavailableException( "Who is calling this with non-redundant router or non-domain router?", DataCenter.class, virtualRouter.getDataCenterId()); } } final DomainRouterVO connectedRouter = (DomainRouterVO) connectedRouters.get(0); DomainRouterVO disconnectedRouter = (DomainRouterVO) disconnectedRouters.get(0); if (s_logger.isDebugEnabled()) { s_logger.debug( "About to stop the router " + disconnectedRouter.getInstanceName() + " due to: " + reason); } final String title = "Virtual router " + disconnectedRouter.getInstanceName() + " would be stopped after connecting back, due to " + reason; final String context = "Virtual router (name: " + disconnectedRouter.getInstanceName() + ", id: " + disconnectedRouter.getId() + ") would be stopped after connecting back, due to: " + reason; _alertMgr.sendAlert( AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, disconnectedRouter.getDataCenterId(), disconnectedRouter.getPodIdToDeployIn(), title, context); disconnectedRouter.setStopPending(true); disconnectedRouter = _routerDao.persist(disconnectedRouter); }
/** @param network */ private void mockDAOs(final NetworkVO network, final NetworkOfferingVO offering) { when(_networkDao.acquireInLockTable( network.getId(), NetworkOrchestrationService.NetworkLockTimeout.value())) .thenReturn(network); when(_networksDao.acquireInLockTable( network.getId(), NetworkOrchestrationService.NetworkLockTimeout.value())) .thenReturn(network); when(_physicalProviderDao.findByServiceProvider(0L, "VirtualRouter")) .thenReturn(new PhysicalNetworkServiceProviderVO()); when(_vrProviderDao.findByNspIdAndType(0L, Type.VirtualRouter)) .thenReturn(new VirtualRouterProviderVO()); when(_networkOfferingDao.findById(0L)).thenReturn(offering); // watchit: (in this test) there can be only one when(_routerDao.getNextInSequence(Long.class, "id")).thenReturn(0L); final ServiceOfferingVO svcoff = new ServiceOfferingVO( "name", /* cpu */ 1, /* ramsize */ 1024 * 1024, /* (clock?)speed */ 1024 * 1024 * 1024, /* rateMbps */ 1, /* multicastRateMbps */ 0, /* offerHA */ false, "displayText", ProvisioningType.THIN, /* useLocalStorage */ false, /* recreatable */ false, "tags", /* systemUse */ false, VirtualMachine.Type.DomainRouter, /* defaultUse */ false); when(_serviceOfferingDao.findById(0L)).thenReturn(svcoff); final DomainRouterVO router = new DomainRouterVO( /* id */ 1L, /* serviceOfferingId */ 1L, /* elementId */ 0L, "name", /* templateId */ 0L, HypervisorType.XenServer, /* guestOSId */ 0L, /* domainId */ 0L, /* accountId */ 1L, /* userId */ 1L, /* isRedundantRouter */ false, RedundantState.UNKNOWN, /* haEnabled */ false, /* stopPending */ false, /* vpcId */ null); when(_routerDao.getNextInSequence(Long.class, "id")).thenReturn(1L); when(_templateDao.findRoutingTemplate( HypervisorType.XenServer, "SystemVM Template (XenServer)")) .thenReturn(new VMTemplateVO()); when(_routerDao.persist(any(DomainRouterVO.class))).thenReturn(router); when(_routerDao.findById(router.getId())).thenReturn(router); }
@Override public DomainRouterVO deployRouter( final RouterDeploymentDefinition routerDeploymentDefinition, final boolean startRouter) throws InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(routerDeploymentDefinition.getServiceOfferingId()); final Account owner = routerDeploymentDefinition.getOwner(); // Router is the network element, we don't know the hypervisor type yet. // Try to allocate the domR twice using diff hypervisors, and when // failed both times, throw the exception up final List<HypervisorType> hypervisors = getHypervisors(routerDeploymentDefinition); int allocateRetry = 0; int startRetry = 0; DomainRouterVO router = null; for (final Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext(); ) { final HypervisorType hType = iter.next(); try { final long id = _routerDao.getNextInSequence(Long.class, "id"); if (s_logger.isDebugEnabled()) { s_logger.debug( String.format( "Allocating the VR with id=%s in datacenter %s with the hypervisor type %s", id, routerDeploymentDefinition.getDest().getDataCenter(), hType)); } final String templateName = retrieveTemplateName( hType, routerDeploymentDefinition.getDest().getDataCenter().getId()); final VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName); if (template == null) { s_logger.debug(hType + " won't support system vm, skip it"); continue; } final boolean offerHA = routerOffering.getOfferHA(); // routerDeploymentDefinition.getVpc().getId() ==> do not use // VPC because it is not a VPC offering. final Long vpcId = routerDeploymentDefinition.getVpc() != null ? routerDeploymentDefinition.getVpc().getId() : null; long userId = CallContext.current().getCallingUserId(); if (CallContext.current().getCallingAccount().getId() != owner.getId()) { final List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId()); if (!userVOs.isEmpty()) { userId = userVOs.get(0).getId(); } } router = new DomainRouterVO( id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), VirtualMachineName.getRouterName(id, s_vmInstanceName), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, routerDeploymentDefinition.isRedundant(), RedundantState.UNKNOWN, offerHA, false, vpcId); router.setDynamicallyScalable(template.isDynamicallyScalable()); router.setRole(Role.VIRTUAL_ROUTER); router = _routerDao.persist(router); reallocateRouterNetworks(routerDeploymentDefinition, router, template, null); router = _routerDao.findById(router.getId()); } catch (final InsufficientCapacityException ex) { if (allocateRetry < 2 && iter.hasNext()) { s_logger.debug( "Failed to allocate the VR with hypervisor type " + hType + ", retrying one more time"); continue; } else { throw ex; } } finally { allocateRetry++; } if (startRouter) { try { router = startVirtualRouter( router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), routerDeploymentDefinition.getParams()); break; } catch (final InsufficientCapacityException ex) { if (startRetry < 2 && iter.hasNext()) { s_logger.debug( "Failed to start the VR " + router + " with hypervisor type " + hType + ", " + "destroying it and recreating one more time"); // destroy the router destroyRouter( router.getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), User.UID_SYSTEM); continue; } else { throw ex; } } finally { startRetry++; } } else { // return stopped router return router; } } return router; }
@Override public DomainRouterVO persist(DomainRouterVO elbVm) { return _routerDao.persist(elbVm); }