This is an automated email from the ASF dual-hosted git repository. weizhou pushed a commit to branch 4.18 in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.18 by this push: new af942e2260f vpc: optimize createMonitorServiceCommand() execution (#8385) af942e2260f is described below commit af942e2260f8fa6b183b3da14a41fc355400cb47 Author: Phsm Qwerty <p...@users.noreply.github.com> AuthorDate: Mon Feb 19 11:07:48 2024 +0100 vpc: optimize createMonitorServiceCommand() execution (#8385) * Optimize createMonitorServiceCommand() execution. Avoid an expensive getRouterHealthChecksConfig() execution multiple times during VPC restart. Fixes #8055 * Move getRouterHealthChecksConfig() outside of loop --- .../router/VirtualNetworkApplianceManagerImpl.java | 15 ++++++++------- .../router/VpcVirtualNetworkApplianceManagerImpl.java | 7 ++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index a0e8a2a2f0d..de2d9d80d2b 100644 --- a/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1619,7 +1619,7 @@ Configurable, StateListener<VirtualMachine.State, VirtualMachine.Event, VirtualM } private SetMonitorServiceCommand createMonitorServiceCommand(DomainRouterVO router, List<MonitorServiceTO> services, - boolean reconfigure, boolean deleteFromProcessedCache) { + boolean reconfigure, boolean deleteFromProcessedCache, Map<String, String> routerHealthCheckConfig) { final SetMonitorServiceCommand command = new SetMonitorServiceCommand(services); command.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); @@ -1637,7 +1637,7 @@ Configurable, StateListener<VirtualMachine.State, VirtualMachine.Event, VirtualM } command.setAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_EXCLUDED, excludedTests); - command.setHealthChecksConfig(getRouterHealthChecksConfig(router)); + command.setHealthChecksConfig(routerHealthCheckConfig); command.setReconfigureAfterUpdate(reconfigure); command.setDeleteFromProcessedCache(deleteFromProcessedCache); // As part of updating return command; @@ -1662,7 +1662,7 @@ Configurable, StateListener<VirtualMachine.State, VirtualMachine.Event, VirtualM s_logger.info("Updating data for router health checks for router " + router.getUuid()); Answer origAnswer = null; try { - SetMonitorServiceCommand command = createMonitorServiceCommand(router, null, true, true); + SetMonitorServiceCommand command = createMonitorServiceCommand(router, null, true, true, getRouterHealthChecksConfig(router)); origAnswer = _agentMgr.easySend(router.getHostId(), command); } catch (final Exception e) { s_logger.error("Error while sending update data for health check to router: " + router.getInstanceName(), e); @@ -1777,7 +1777,7 @@ Configurable, StateListener<VirtualMachine.State, VirtualMachine.Event, VirtualM } } - private Map<String, String> getRouterHealthChecksConfig(final DomainRouterVO router) { + protected Map<String, String> getRouterHealthChecksConfig(final DomainRouterVO router) { Map<String, String> data = new HashMap<>(); List<DomainRouterJoinVO> routerJoinVOs = domainRouterJoinDao.searchByIds(router.getId()); StringBuilder vmsData = new StringBuilder(); @@ -2342,6 +2342,7 @@ Configurable, StateListener<VirtualMachine.State, VirtualMachine.Event, VirtualM final Provider provider = getVrProvider(router); final List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId()); + Map <String, String> routerHealthChecksConfig = getRouterHealthChecksConfig(router); for (final Long guestNetworkId : routerGuestNtwkIds) { final AggregationControlCommand startCmd = new AggregationControlCommand(Action.Start, router.getInstanceName(), controlNic.getIPv4Address(), _routerControlHelper.getRouterIpInNetwork( guestNetworkId, router.getId())); @@ -2350,7 +2351,7 @@ Configurable, StateListener<VirtualMachine.State, VirtualMachine.Event, VirtualM if (reprogramGuestNtwks) { finalizeIpAssocForNetwork(cmds, router, provider, guestNetworkId, null); finalizeNetworkRulesForNetwork(cmds, router, provider, guestNetworkId); - finalizeMonitorService(cmds, profile, router, provider, guestNetworkId, true); + finalizeMonitorService(cmds, profile, router, provider, guestNetworkId, true, routerHealthChecksConfig); } finalizeUserDataAndDhcpOnStart(cmds, router, provider, guestNetworkId); @@ -2364,7 +2365,7 @@ Configurable, StateListener<VirtualMachine.State, VirtualMachine.Event, VirtualM } protected void finalizeMonitorService(final Commands cmds, final VirtualMachineProfile profile, final DomainRouterVO router, final Provider provider, - final long networkId, boolean onStart) { + final long networkId, boolean onStart, Map<String, String> routerHealthCheckConfig) { final NetworkOffering offering = _networkOfferingDao.findById(_networkDao.findById(networkId).getNetworkOfferingId()); if (offering.isRedundantRouter()) { // service monitoring is currently not added in RVR @@ -2414,7 +2415,7 @@ Configurable, StateListener<VirtualMachine.State, VirtualMachine.Event, VirtualM } // As part of aggregate command we don't need to reconfigure if onStart and persist in processed cache. Subsequent updates are not needed. - SetMonitorServiceCommand command = createMonitorServiceCommand(router, servicesTO, !onStart, false); + SetMonitorServiceCommand command = createMonitorServiceCommand(router, servicesTO, !onStart, false, routerHealthCheckConfig); command.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(networkId, router.getId())); if (!isMonitoringServicesEnabled) { command.setAccessDetail(SetMonitorServiceCommand.ROUTER_MONITORING_ENABLED, isMonitoringServicesEnabled.toString()); diff --git a/server/src/main/java/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/main/java/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index aebeb5c9398..74b0dddfd45 100644 --- a/server/src/main/java/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/main/java/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -499,8 +499,9 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian throw new CloudRuntimeException("Cannot find related provider of virtual router provider: " + vrProvider.getType().toString()); } + Map<String, String> routerHealthCheckConfig = getRouterHealthChecksConfig(domainRouterVO); if (reprogramGuestNtwks && publicNics.size() > 0) { - finalizeMonitorService(cmds, profile, domainRouterVO, provider, publicNics.get(0).second().getId(), true); + finalizeMonitorService(cmds, profile, domainRouterVO, provider, publicNics.get(0).second().getId(), true, routerHealthCheckConfig); } for (final Pair<Nic, Network> nicNtwk : guestNics) { @@ -512,7 +513,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian if (reprogramGuestNtwks) { finalizeIpAssocForNetwork(cmds, domainRouterVO, provider, guestNetworkId, vlanMacAddress); finalizeNetworkRulesForNetwork(cmds, domainRouterVO, provider, guestNetworkId); - finalizeMonitorService(cmds, profile, domainRouterVO, provider, guestNetworkId, true); + finalizeMonitorService(cmds, profile, domainRouterVO, provider, guestNetworkId, true, routerHealthCheckConfig); } finalizeUserDataAndDhcpOnStart(cmds, domainRouterVO, provider, guestNetworkId); @@ -571,7 +572,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian finalizeNetworkRulesForNetwork(cmds, router, provider, networkId); } - finalizeMonitorService(cmds, getVirtualMachineProfile(router), router, provider, networkId, false); + finalizeMonitorService(cmds, getVirtualMachineProfile(router), router, provider, networkId, false, getRouterHealthChecksConfig(router)); return _nwHelper.sendCommandsToRouter(router, cmds); }