139139import org .apache .commons .collections .CollectionUtils ;
140140import org .apache .commons .collections .MapUtils ;
141141import org .apache .commons .lang .math .NumberUtils ;
142+ import org .apache .commons .lang3 .ObjectUtils ;
142143import org .apache .commons .lang3 .StringUtils ;
143144import org .apache .commons .lang3 .builder .ToStringBuilder ;
144145import org .apache .commons .lang3 .builder .ToStringStyle ;
@@ -658,7 +659,7 @@ public void setKubernetesServiceHelpers(final List<KubernetesServiceHelper> kube
658659 "Wait Interval (in seconds) for shared network vm dhcp ip addr fetch for next iteration " , true );
659660
660661 private static final ConfigKey <Integer > VmIpFetchTrialMax = new ConfigKey <Integer >("Advanced" , Integer .class , "externaldhcp.vmip.max.retry" , "10" ,
661- "The max number of retrieval times for shared entwork vm dhcp ip fetch, in case of failures" , true );
662+ "The max number of retrieval times for shared network vm dhcp ip fetch, in case of failures" , true );
662663
663664 private static final ConfigKey <Integer > VmIpFetchThreadPoolMax = new ConfigKey <Integer >("Advanced" , Integer .class , "externaldhcp.vmipFetch.threadPool.max" , "10" ,
664665 "number of threads for fetching vms ip address" , true );
@@ -2674,7 +2675,7 @@ protected void runInContext() {
26742675
26752676 if (vmIdAndCount .getRetrievalCount () <= 0 ) {
26762677 vmIdCountMap .remove (nicId );
2677- logger .debug ("Vm " + vmId + " nic " + nicId + " count is zero .. removing vm nic from map " );
2678+ logger .debug ("Vm {} nic {} count is zero .. removing vm nic from map " , vmId , nicId );
26782679
26792680 ActionEventUtils .onActionEvent (User .UID_SYSTEM , Account .ACCOUNT_ID_SYSTEM ,
26802681 Domain .ROOT_DOMAIN , EventTypes .EVENT_NETWORK_EXTERNAL_DHCP_VM_IPFETCH ,
@@ -2683,12 +2684,15 @@ protected void runInContext() {
26832684 continue ;
26842685 }
26852686
2686-
26872687 UserVm userVm = _vmDao .findById (vmId );
26882688 VMInstanceVO vmInstance = _vmInstanceDao .findById (vmId );
26892689 NicVO nicVo = _nicDao .findById (nicId );
2690- NetworkVO network = _networkDao .findById (nicVo .getNetworkId ());
2690+ if (ObjectUtils .anyNull (userVm , vmInstance , nicVo )) {
2691+ logger .warn ("Couldn't fetch ip addr, Vm {} or nic {} doesn't exists" , vmId , nicId );
2692+ continue ;
2693+ }
26912694
2695+ NetworkVO network = _networkDao .findById (nicVo .getNetworkId ());
26922696 VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl (userVm );
26932697 VirtualMachine vm = vmProfile .getVirtualMachine ();
26942698 boolean isWindows = _guestOSCategoryDao .findById (_guestOSDao .findById (vm .getGuestOSId ()).getCategoryId ()).getName ().equalsIgnoreCase ("Windows" );
0 commit comments