mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
server: Fix NPE during VM IP fetch for shared networks (#11389)
* Fix NPE during VM IP fetch for shared networks * PR 11389: add missing import org.apache.commons.lang3.ObjectUtils --------- Co-authored-by: Wei Zhou <weizhou@apache.org>
This commit is contained in:
parent
7c76a3c12a
commit
cd69f2ce16
@ -139,6 +139,7 @@ import org.apache.cloudstack.vm.UnmanagedVMsManager;
|
|||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.MapUtils;
|
import org.apache.commons.collections.MapUtils;
|
||||||
import org.apache.commons.lang.math.NumberUtils;
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
@ -658,7 +659,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
"Wait Interval (in seconds) for shared network vm dhcp ip addr fetch for next iteration ", true);
|
"Wait Interval (in seconds) for shared network vm dhcp ip addr fetch for next iteration ", true);
|
||||||
|
|
||||||
private static final ConfigKey<Integer> VmIpFetchTrialMax = new ConfigKey<Integer>("Advanced", Integer.class, "externaldhcp.vmip.max.retry", "10",
|
private static final ConfigKey<Integer> VmIpFetchTrialMax = new ConfigKey<Integer>("Advanced", Integer.class, "externaldhcp.vmip.max.retry", "10",
|
||||||
"The max number of retrieval times for shared entwork vm dhcp ip fetch, in case of failures", true);
|
"The max number of retrieval times for shared network vm dhcp ip fetch, in case of failures", true);
|
||||||
|
|
||||||
private static final ConfigKey<Integer> VmIpFetchThreadPoolMax = new ConfigKey<Integer>("Advanced", Integer.class, "externaldhcp.vmipFetch.threadPool.max", "10",
|
private static final ConfigKey<Integer> VmIpFetchThreadPoolMax = new ConfigKey<Integer>("Advanced", Integer.class, "externaldhcp.vmipFetch.threadPool.max", "10",
|
||||||
"number of threads for fetching vms ip address", true);
|
"number of threads for fetching vms ip address", true);
|
||||||
@ -2674,7 +2675,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
|
|
||||||
if (vmIdAndCount.getRetrievalCount() <= 0) {
|
if (vmIdAndCount.getRetrievalCount() <= 0) {
|
||||||
vmIdCountMap.remove(nicId);
|
vmIdCountMap.remove(nicId);
|
||||||
logger.debug("Vm " + vmId +" nic "+nicId + " count is zero .. removing vm nic from map ");
|
logger.debug("Vm {} nic {} count is zero .. removing vm nic from map ", vmId, nicId);
|
||||||
|
|
||||||
ActionEventUtils.onActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM,
|
ActionEventUtils.onActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM,
|
||||||
Domain.ROOT_DOMAIN, EventTypes.EVENT_NETWORK_EXTERNAL_DHCP_VM_IPFETCH,
|
Domain.ROOT_DOMAIN, EventTypes.EVENT_NETWORK_EXTERNAL_DHCP_VM_IPFETCH,
|
||||||
@ -2683,12 +2684,15 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UserVm userVm = _vmDao.findById(vmId);
|
UserVm userVm = _vmDao.findById(vmId);
|
||||||
VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
|
VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
|
||||||
NicVO nicVo = _nicDao.findById(nicId);
|
NicVO nicVo = _nicDao.findById(nicId);
|
||||||
NetworkVO network = _networkDao.findById(nicVo.getNetworkId());
|
if (ObjectUtils.anyNull(userVm, vmInstance, nicVo)) {
|
||||||
|
logger.warn("Couldn't fetch ip addr, Vm {} or nic {} doesn't exists", vmId, nicId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkVO network = _networkDao.findById(nicVo.getNetworkId());
|
||||||
VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(userVm);
|
VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(userVm);
|
||||||
VirtualMachine vm = vmProfile.getVirtualMachine();
|
VirtualMachine vm = vmProfile.getVirtualMachine();
|
||||||
boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
|
boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user