@Test public void testStart() throws Exception { when(router.getId()).thenReturn(1L); when(router.getVpcId()).thenReturn(null); final DomainRouterDao routerDao = mock(DomainRouterDao.class); when(routerDao.findById(anyLong())).thenReturn(router); when(routerDao.persist(any(DomainRouterVO.class))).thenReturn(router); nwHelper._itMgr = mock(VirtualMachineManager.class); nwHelper._routerDao = routerDao; assertEquals(router, nwHelper.start(router, null, null)); }
protected DomainRouterVO start(DomainRouterVO router, final Map<Param, Object> params, final DeploymentPlan planToDeploy) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { 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()) { logger.info("Clear the stop pending flag of router " + router.getHostName() + " after start router successfully!"); router.setStopPending(false); router = _routerDao.persist(router); } router.setLastStartDateTime(getCurrentLocalDateTimeStamp()); router.setLastStartVersion(NetworkHelperImpl.class.getPackage().getImplementationVersion()); if (router.getComplianceStatus() == ComplianceStatus.VMNeedsRestart) { router.setComplianceStatus(ComplianceStatus.Compliant); } router = _routerDao.persist(router); final Long vpcId = router.getVpcId(); if (vpcId != null) { _s2sVpnMgr.reconnectDisconnectedVpnByVpc(vpcId); } return _routerDao.findById(router.getId()); }
NetworkHelperImpl implements NetworkHelper { protected DomainRouterVO start(DomainRouterVO router, final Map<Param, Object> params, final DeploymentPlan planToDeploy) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { 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()) { logger.info("Clear the stop pending flag of router " + router.getHostName() + " after start router successfully!"); router.setStopPending(false); router = _routerDao.persist(router); } router.setLastStartDateTime(getCurrentLocalDateTimeStamp()); router.setLastStartVersion(NetworkHelperImpl.class.getPackage().getImplementationVersion()); if (router.getComplianceStatus() == ComplianceStatus.VMNeedsRestart) { router.setComplianceStatus(ComplianceStatus.Compliant); } router = _routerDao.persist(router); final Long vpcId = router.getVpcId(); if (vpcId != null) { _s2sVpnMgr.reconnectDisconnectedVpnByVpc(vpcId); } return _routerDao.findById(router.getId()); } }
NetworkHelperImpl implements NetworkHelper { protected DomainRouterVO start(DomainRouterVO router, final Map<Param, Object> params, final DeploymentPlan planToDeploy) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { 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()) { logger.info("Clear the stop pending flag of router " + router.getHostName() + " after start router successfully!"); router.setStopPending(false); router = _routerDao.persist(router); } router.setLastStartDateTime(getCurrentLocalDateTimeStamp()); router.setLastStartVersion(NetworkHelperImpl.class.getPackage().getImplementationVersion()); if (router.getComplianceStatus() == ComplianceStatus.VMNeedsRestart) { router.setComplianceStatus(ComplianceStatus.Compliant); } router = _routerDao.persist(router); final Long vpcId = router.getVpcId(); if (vpcId != null) { _s2sVpnMgr.reconnectDisconnectedVpnByVpc(vpcId); } return _routerDao.findById(router.getId()); }  }
NetworkHelperImpl implements NetworkHelper { protected DomainRouterVO start(DomainRouterVO router, final Map<Param, Object> params, final DeploymentPlan planToDeploy) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { 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()) { logger.info("Clear the stop pending flag of router " + router.getHostName() + " after start router successfully!"); router.setStopPending(false); router = _routerDao.persist(router); } router.setLastStartDateTime(getCurrentLocalDateTimeStamp()); router.setLastStartVersion(NetworkHelperImpl.class.getPackage().getImplementationVersion()); if (router.getComplianceStatus() == ComplianceStatus.VMNeedsRestart) { router.setComplianceStatus(ComplianceStatus.Compliant); } router = _routerDao.persist(router); final Long vpcId = router.getVpcId(); if (vpcId != null) { _s2sVpnMgr.reconnectDisconnectedVpnByVpc(vpcId); } return _routerDao.findById(router.getId()); }  static void setSystemAccount(final Account systemAccount); static void setVMInstanceName(final String vmInstanceName); @Override boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds); @Override void handleSingleWorkingRedundantRouter(final List<? extends VirtualRouter> connectedRouters, final List<? extends VirtualRouter> disconnectedRouters,
                                                   final String reason); @Override NicTO getNicTO(final VirtualRouter router, final Long networkId, final String broadcastUri); @Override VirtualRouter destroyRouter(final long routerId, final Account caller, final Long callerUserId); @Override boolean checkRouterVersion(final VirtualRouter router); @Override List<DomainRouterVO> startRouters(final RouterDeploymentDefinition routerDeploymentDefinition); @Override DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params); @Override DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean startRouter); @Override void reallocateRouterNetworks(final RouterDeploymentDefinition routerDeploymentDefinition, final VirtualRouter router, final VMTemplateVO template, final
    HypervisorType hType); @Override LinkedHashMap<Network, List<? extends NicProfile>> configureDefaultNics(final RouterDeploymentDefinition routerDeploymentDefinition); @Override LinkedHashMap<Network, List<? extends NicProfile>> configureGuestNic(final RouterDeploymentDefinition routerDeploymentDefinition); }
NetworkHelperImpl implements NetworkHelper { protected DomainRouterVO start(DomainRouterVO router, final Map<Param, Object> params, final DeploymentPlan planToDeploy) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { 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()) { logger.info("Clear the stop pending flag of router " + router.getHostName() + " after start router successfully!"); router.setStopPending(false); router = _routerDao.persist(router); } router.setLastStartDateTime(getCurrentLocalDateTimeStamp()); router.setLastStartVersion(NetworkHelperImpl.class.getPackage().getImplementationVersion()); if (router.getComplianceStatus() == ComplianceStatus.VMNeedsRestart) { router.setComplianceStatus(ComplianceStatus.Compliant); } router = _routerDao.persist(router); final Long vpcId = router.getVpcId(); if (vpcId != null) { _s2sVpnMgr.reconnectDisconnectedVpnByVpc(vpcId); } return _routerDao.findById(router.getId()); }  static void setSystemAccount(final Account systemAccount); static void setVMInstanceName(final String vmInstanceName); @Override boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds); @Override void handleSingleWorkingRedundantRouter(final List<? extends VirtualRouter> connectedRouters, final List<? extends VirtualRouter> disconnectedRouters,
                                                   final String reason); @Override NicTO getNicTO(final VirtualRouter router, final Long networkId, final String broadcastUri); @Override VirtualRouter destroyRouter(final long routerId, final Account caller, final Long callerUserId); @Override boolean checkRouterVersion(final VirtualRouter router); @Override List<DomainRouterVO> startRouters(final RouterDeploymentDefinition routerDeploymentDefinition); @Override DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params); @Override DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean startRouter); @Override void reallocateRouterNetworks(final RouterDeploymentDefinition routerDeploymentDefinition, final VirtualRouter router, final VMTemplateVO template, final
    HypervisorType hType); @Override LinkedHashMap<Network, List<? extends NicProfile>> configureDefaultNics(final RouterDeploymentDefinition routerDeploymentDefinition); @Override LinkedHashMap<Network, List<? extends NicProfile>> configureGuestNic(final RouterDeploymentDefinition routerDeploymentDefinition);  }