@@ -477,6 +477,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
477477 protected IpAddressManager _ipAddrMgr ;
478478
479479 protected ScheduledExecutorService _executor = null ;
480+ protected ScheduledExecutorService _vmIpFetchExecutor = null ;
480481 protected int _expungeInterval ;
481482 protected int _expungeDelay ;
482483 protected boolean _dailyOrHourly = false ;
@@ -514,6 +515,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
514515 static final ConfigKey <Integer > VmIpFetchThreadPoolMax = new ConfigKey <Integer >("Advanced" , Integer .class , "externaldhcp.vmipFetch.threadPool.max" , "10" ,
515516 "number of threads for fetching vms ip address" , true );
516517
518+ static final ConfigKey <Integer > VmIpFetchTaskWorkers = new ConfigKey <Integer >("Advanced" , Integer .class , "externaldhcp.vmipfetchtask.workers" , "10" ,
519+ "number of worker threads for vm ip fetch task " , true );
520+
517521
518522 @ Override
519523 public UserVmVO getVirtualMachine (long vmId ) {
@@ -1947,6 +1951,11 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
19471951
19481952 _executor = Executors .newScheduledThreadPool (wrks , new NamedThreadFactory ("UserVm-Scavenger" ));
19491953
1954+ String vmIpWorkers = configs .get (VmIpFetchTaskWorkers .value ());
1955+ int vmipwrks = NumbersUtil .parseInt (vmIpWorkers , 10 );
1956+
1957+ _vmIpFetchExecutor = Executors .newScheduledThreadPool (vmipwrks , new NamedThreadFactory ("UserVm-ipfetch" ));
1958+
19501959 String aggregationRange = configs .get ("usage.stats.job.aggregation.range" );
19511960 int _usageAggregationRange = NumbersUtil .parseInt (aggregationRange , 1440 );
19521961 int HOURLY_TIME = 60 ;
@@ -1966,7 +1975,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
19661975 String value = _configDao .getValue (Config .SetVmInternalNameUsingDisplayName .key ());
19671976 _instanceNameFlag = (value == null ) ? false : Boolean .parseBoolean (value );
19681977
1969- _scaleRetry = NumbersUtil .parseInt (configs .get (Config .ScaleRetry .key ()), 2 );
1978+ _scaleRetry = NumbersUtil .parseInt (configs .get (Config .ScaleRetry .key ()), 2 );
1979+
1980+ _vmIpFetchThreadExecutor = Executors .newFixedThreadPool (VmIpFetchThreadPoolMax .value (), new NamedThreadFactory ("vmIpFetchThread" ));
19701981
19711982 s_logger .info ("User VM Manager is configured." );
19721983
@@ -1981,7 +1992,7 @@ public String getName() {
19811992 @ Override
19821993 public boolean start () {
19831994 _executor .scheduleWithFixedDelay (new ExpungeTask (), _expungeInterval , _expungeInterval , TimeUnit .SECONDS );
1984- _executor .scheduleWithFixedDelay (new VmIpFetchTask (), VmIpFetchWaitInterval .value (), VmIpFetchWaitInterval .value (), TimeUnit .SECONDS );
1995+ _vmIpFetchExecutor .scheduleWithFixedDelay (new VmIpFetchTask (), VmIpFetchWaitInterval .value (), VmIpFetchWaitInterval .value (), TimeUnit .SECONDS );
19851996 loadVmDetailsInMapForExternalDhcpIp ();
19861997 return true ;
19871998 }
@@ -2015,6 +2026,7 @@ private void loadVmDetailsInMapForExternalDhcpIp() {
20152026 @ Override
20162027 public boolean stop () {
20172028 _executor .shutdown ();
2029+ _vmIpFetchExecutor .shutdown ();
20182030 return true ;
20192031 }
20202032
@@ -2599,7 +2611,21 @@ public UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityE
25992611 throw new InvalidParameterValueException ("Unable to find service offering: " + serviceOfferingId + " corresponding to the vm" );
26002612 }
26012613
2602- return rebootVirtualMachine (CallContext .current ().getCallingUserId (), vmId );
2614+ UserVm userVm = rebootVirtualMachine (CallContext .current ().getCallingUserId (), vmId );
2615+ if (userVm != null ) {
2616+ // update the vmIdCountMap if the vm is in advanced shared network with out services
2617+ final List <NicVO > nics = _nicDao .listByVmId (vmId );
2618+ for (NicVO nic : nics ) {
2619+ Network network = _networkModel .getNetwork (nic .getNetworkId ());
2620+ if (_networkModel .isSharedNetworkWithoutServices (network .getId ())) {
2621+ s_logger .debug ("Adding vm " +vmId +" nic id " + nic .getId () +" into vmIdCountMap as part of vm " +
2622+ "reboot for vm ip fetch " );
2623+ vmIdCountMap .put (nic .getId (), new VmAndCountDetails (nic .getInstanceId (), VmIpFetchTrialMax .value ()));
2624+ }
2625+ }
2626+ return userVm ;
2627+ }
2628+ return null ;
26032629 }
26042630
26052631 @ Override
@@ -3808,7 +3834,7 @@ public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile prof
38083834 }
38093835
38103836 @ Override
3811- public boolean finalizeStart (VirtualMachineProfile profile , long hostId , Commands cmds , ReservationContext context ) {
3837+ public boolean finalizeStart (VirtualMachineProfile profile , long hostId , Commands cmds , ReservationContext context ) {
38123838 UserVmVO vm = _vmDao .findById (profile .getId ());
38133839
38143840 Answer [] answersToCmds = cmds .getAnswers ();
@@ -3896,6 +3922,21 @@ public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Command
38963922 }
38973923 }
38983924
3925+ final VirtualMachineProfile vmProfile = profile ;
3926+ Transaction .execute (new TransactionCallbackNoReturn () {
3927+ @ Override
3928+ public void doInTransactionWithoutResult (TransactionStatus status ) {
3929+ final UserVmVO vm = _vmDao .findById (vmProfile .getId ());
3930+ final List <NicVO > nics = _nicDao .listByVmId (vm .getId ());
3931+ for (NicVO nic : nics ) {
3932+ Network network = _networkModel .getNetwork (nic .getNetworkId ());
3933+ if (_networkModel .isSharedNetworkWithoutServices (network .getId ())) {
3934+ vmIdCountMap .put (nic .getId (), new VmAndCountDetails (nic .getInstanceId (), VmIpFetchTrialMax .value ()));
3935+ }
3936+ }
3937+ }
3938+ });
3939+
38993940 return true ;
39003941 }
39013942
@@ -5835,7 +5876,7 @@ public String getConfigComponentName() {
58355876
58365877 @ Override
58375878 public ConfigKey <?>[] getConfigKeys () {
5838- return new ConfigKey <?>[] {EnableDynamicallyScaleVm , AllowUserExpungeRecoverVm , VmIpFetchWaitInterval , VmIpFetchTrialMax , VmIpFetchThreadPoolMax };
5879+ return new ConfigKey <?>[] {EnableDynamicallyScaleVm , AllowUserExpungeRecoverVm , VmIpFetchWaitInterval , VmIpFetchTrialMax , VmIpFetchThreadPoolMax , VmIpFetchTaskWorkers };
58395880 }
58405881
58415882 @ Override
0 commit comments