From 154c6d9021e6a3ce8ccaa0a3cdcf7969fc4ce550 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 10 May 2011 05:52:39 -0700 Subject: [PATCH] Propagating 1345af2a0e84684a804bde5b281c30df72f148a0 --- .../ha/ManagementIPSystemVMInvestigator.java | 98 +++++++++++-------- .../com/cloud/ha/UserVmDomRInvestigator.java | 73 +++++++------- .../src/com/cloud/network/NetworkManager.java | 2 +- .../com/cloud/network/NetworkManagerImpl.java | 16 ++- .../SecondaryStorageManagerImpl.java | 32 +++--- 5 files changed, 122 insertions(+), 99 deletions(-) diff --git a/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java b/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java index 3cb8e94abfb..30980ae8ae0 100644 --- a/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java +++ b/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java @@ -1,8 +1,8 @@ /** * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. - * + * * This software is licensed under the GNU General Public License v3 or later. - * + * * It is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or any later version. @@ -10,10 +10,10 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * */ package com.cloud.ha; @@ -47,54 +47,66 @@ public class ManagementIPSystemVMInvestigator extends AbstractInvestigatorImpl { @Override public Boolean isVmAlive(VMInstanceVO vm, HostVO host) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("testing if vm (" + vm.getId() + ") is alive"); - } - if (VirtualMachine.Type.isSystemVM(vm.getType())) { - - Nic nic = _networkMgr.getNicForTraffic(vm.getId(), TrafficType.Management); - if (nic == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find a management nic, cannot ping this system VM, unable to determine state of vm (" + vm.getId() + "), returning null"); - } - return null; + if (!VirtualMachine.Type.isSystemVM(vm.getType())) { + s_logger.debug("Not a System Vm, unable to determine state of " + vm + " returning null"); + } + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Testing if " + vm + " is alive"); + } + + if (vm.getHostId() == null) { + s_logger.debug("There's no host id for " + vm); + return null; + } + + HostVO vmHost = _hostDao.findById(vm.getHostId()); + if (vmHost == null) { + s_logger.debug("Unable to retrieve the host by using id " + vm.getHostId()); + return null; + } + + List nics = _networkMgr.getNicsForTraffic(vm.getId(), TrafficType.Management); + if (nics.size() == 0) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Unable to find a management nic, cannot ping this system VM, unable to determine state of " + vm + " returning null"); } - - // get the data center IP address, find a host on the pod, use that host to ping the data center IP address - HostVO vmHost = _hostDao.findById(vm.getHostId()); - List otherHosts = findHostByPod(vm.getPodId(), vm.getHostId()); - for (Long otherHost : otherHosts) { - - Status vmState = testIpAddress(otherHost, vm.getPrivateIpAddress()); - if (vmState == null) { - // can't get information from that host, try the next one + return null; + } + + for (Nic nic : nics) { + if (nic.getIp4Address() == null) { + continue; + } + // get the data center IP address, find a host on the pod, use that host to ping the data center IP address + List otherHosts = findHostByPod(vmHost.getPodId(), vm.getHostId()); + for (Long otherHost : otherHosts) { + Status vmState = testIpAddress(otherHost, nic.getIp4Address()); + if (vmState == null) { + // can't get information from that host, try the next one continue; } if (vmState == Status.Up) { if (s_logger.isDebugEnabled()) { - s_logger.debug("successfully pinged vm's private IP (" + vm.getPrivateIpAddress() + "), returning that the VM is up"); - } - return Boolean.TRUE; - } else if (vmState == Status.Down) { - // We can't ping the VM directly...if we can ping the host, then report the VM down. - // If we can't ping the host, then we don't have enough information. - Status vmHostState = testIpAddress(otherHost, vmHost.getPrivateIpAddress()); - if ((vmHostState != null) && (vmHostState == Status.Up)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("successfully pinged vm's host IP (" + vmHost.getPrivateIpAddress() + "), but could not ping VM, returning that the VM is down"); - } + s_logger.debug("successfully pinged vm's private IP (" + vm.getPrivateIpAddress() + "), returning that the VM is up"); + } + return Boolean.TRUE; + } else if (vmState == Status.Down) { + // We can't ping the VM directly...if we can ping the host, then report the VM down. + // If we can't ping the host, then we don't have enough information. + Status vmHostState = testIpAddress(otherHost, vmHost.getPrivateIpAddress()); + if ((vmHostState != null) && (vmHostState == Status.Up)) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("successfully pinged vm's host IP (" + vmHost.getPrivateIpAddress() + "), but could not ping VM, returning that the VM is down"); + } return Boolean.FALSE; } } - } - }else{ - if (s_logger.isDebugEnabled()) { - s_logger.debug("Not a System Vm, unable to determine state of vm (" + vm.getId() + "), returning null"); } - } - + } + if (s_logger.isDebugEnabled()) { - s_logger.debug("unable to determine state of vm (" + vm.getId() + "), returning null"); + s_logger.debug("unable to determine state of " + vm + " returning null"); } return null; } @@ -124,6 +136,6 @@ public class ManagementIPSystemVMInvestigator extends AbstractInvestigatorImpl { @Override public boolean stop() { return true; - } + } } diff --git a/server/src/com/cloud/ha/UserVmDomRInvestigator.java b/server/src/com/cloud/ha/UserVmDomRInvestigator.java index 98ca3f2c813..5ddec06424c 100644 --- a/server/src/com/cloud/ha/UserVmDomRInvestigator.java +++ b/server/src/com/cloud/ha/UserVmDomRInvestigator.java @@ -1,8 +1,8 @@ /** * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. - * + * * This software is licensed under the GNU General Public License v3 or later. - * + * * It is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or any later version. @@ -10,10 +10,10 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * */ package com.cloud.ha; @@ -58,37 +58,44 @@ public class UserVmDomRInvestigator extends AbstractInvestigatorImpl { @Override public Boolean isVmAlive(VMInstanceVO vm, HostVO host) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("testing if vm (" + vm.getId() + ") is alive"); - } - if (vm.getType() == VirtualMachine.Type.User) { - // to verify that the VM is alive, we ask the domR (router) to ping the VM (private IP) - UserVmVO userVm = _userVmDao.findById(vm.getId()); - - Nic nic = _networkMgr.getNicForTraffic(userVm.getId(), TrafficType.Guest); - if (nic == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find a guest nic for " + vm); - } - return null; + if (vm.getType() != VirtualMachine.Type.User) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Not a User Vm, unable to determine state of " + vm + " returning null"); } - + return null; + } + + if (s_logger.isDebugEnabled()) { + s_logger.debug("testing if " + vm + " is alive"); + } + // to verify that the VM is alive, we ask the domR (router) to ping the VM (private IP) + UserVmVO userVm = _userVmDao.findById(vm.getId()); + + List nics = _networkMgr.getNicsForTraffic(userVm.getId(), TrafficType.Guest); + + for (Nic nic : nics) { + if (nic.getIp4Address() == null) { + continue; + } + VirtualRouter router = _vnaMgr.getRouterForNetwork(nic.getNetworkId()); if (router == null) { if (s_logger.isDebugEnabled()) { s_logger.debug("Unable to find a router in network " + nic.getNetworkId() + " to ping " + vm); } - return null; + continue; } - - return testUserVM(vm, nic, router); - }else{ - if (s_logger.isDebugEnabled()) { - s_logger.debug("Not a User Vm, unable to determine state of vm (" + vm.getId() + "), returning null"); + + Boolean result = testUserVM(vm, nic, router); + if (result == null) { + continue; } - } + + return result; + } + if (s_logger.isDebugEnabled()) { - s_logger.debug("unable to determine state of vm (" + vm.getId() + "), returning null"); + s_logger.debug("Returning null since we're unable to determine state of " + vm); } return null; } @@ -98,13 +105,13 @@ public class UserVmDomRInvestigator extends AbstractInvestigatorImpl { if (s_logger.isDebugEnabled()) { s_logger.debug("checking if agent (" + agent.getId() + ") is alive"); } - + if (agent.getPodId() == null) { return null; } - + List otherHosts = findHostByPod(agent.getPodId(), agent.getId()); - + for (Long hostId : otherHosts) { if (s_logger.isDebugEnabled()) { @@ -155,7 +162,7 @@ public class UserVmDomRInvestigator extends AbstractInvestigatorImpl { public boolean stop() { return true; } - + private Boolean testUserVM(VMInstanceVO vm, Nic nic, VirtualRouter router) { String privateIp = nic.getIp4Address(); String routerPrivateIp = router.getPrivateIpAddress(); @@ -166,7 +173,7 @@ public class UserVmDomRInvestigator extends AbstractInvestigatorImpl { otherHosts.add(router.getHostId()); }else{ otherHosts = findHostByPod(router.getPodId(), null); - } + } for (Long hostId : otherHosts) { try { Answer pingTestAnswer = _agentMgr.send(hostId, new PingTestCommand(routerPrivateIp, privateIp), 30 * 1000); @@ -175,7 +182,7 @@ public class UserVmDomRInvestigator extends AbstractInvestigatorImpl { s_logger.debug("user vm " + vm.getHostName() + " has been successfully pinged, returning that it is alive"); } return Boolean.TRUE; - } + } } catch (AgentUnavailableException e) { if (s_logger.isDebugEnabled()) { s_logger.debug("Couldn't reach " + e.getResourceId()); @@ -192,6 +199,6 @@ public class UserVmDomRInvestigator extends AbstractInvestigatorImpl { s_logger.debug(vm + " could not be pinged, returning that it is unknown"); } return null; - + } } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 16321ddd7e5..38fd847dbaf 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -178,7 +178,7 @@ public interface NetworkManager extends NetworkService { Nic getNicInNetworkIncludingRemoved(long vmId, long networkId); - Nic getNicForTraffic(long vmId, TrafficType type); + List getNicsForTraffic(long vmId, TrafficType type); Network getDefaultNetworkForVm(long vmId); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 2add8bc6f61..16c09b3e417 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1,8 +1,8 @@ /** * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. - * + * * This software is licensed under the GNU General Public License v3 or later. - * + * * It is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or any later version. @@ -10,10 +10,10 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * */ package com.cloud.network; @@ -396,7 +396,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag /** * Returns the target account for an api command - * + * * @param accountName * - non-null if the account name was passed in in the command * @param domainId @@ -2545,14 +2545,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } @Override - public Nic getNicForTraffic(long vmId, TrafficType type) { + public List getNicsForTraffic(long vmId, TrafficType type) { SearchCriteria sc = NicForTrafficTypeSearch.create(); sc.setParameters("instance", vmId); sc.setJoinParameters("network", "traffictype", type); - List vos = _nicDao.search(sc, null); - assert vos.size() <= 1 : "If we have multiple networks of the same type, then this method should no longer be used."; - return vos.size() == 1 ? vos.get(0) : null; + return _nicDao.search(sc, null); } @Override diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index c199d64ba94..4b99781517b 100644 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -1,8 +1,8 @@ /** * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. - * + * * This software is licensed under the GNU General Public License v3 or later. - * + * * It is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or any later version. @@ -10,10 +10,10 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * */ package com.cloud.storage.secondary; @@ -252,7 +252,8 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V allowedCidrs.add(cidr); } } - Nic privateNic = _networkMgr.getNicForTraffic(secStorageVm.getId(), TrafficType.Management); + List nics = _networkMgr.getNicsForTraffic(secStorageVm.getId(), TrafficType.Management); + Nic privateNic = nics.get(0); String privateCidr = NetUtils.ipAndNetMaskToCidr(privateNic.getIp4Address(), privateNic.getNetmask()); String publicCidr = NetUtils.ipAndNetMaskToCidr(secStorageVm.getPublicIpAddress(), secStorageVm.getPublicNetmask()); if (NetUtils.isNetworkAWithinNetworkB(privateCidr, publicCidr) || NetUtils.isNetworkAWithinNetworkB(publicCidr, privateCidr)) { @@ -328,7 +329,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V } } - + private boolean isSecondaryStorageVmRequired(long dcId) { DataCenterVO dc = _dcDao.findById(dcId); _dcDao.loadDetails(dc); @@ -492,7 +493,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V if (s_logger.isTraceEnabled()) { s_logger.trace("Allocate secondary storage vm standby capacity for data center : " + dataCenterId); } - + if (!isSecondaryStorageVmRequired(dataCenterId)) { if (s_logger.isDebugEnabled()) { s_logger.debug("Secondary storage vm not required in zone " + dataCenterId + " acc. to zone config"); @@ -850,10 +851,11 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V buf.append(" zone=").append(dest.getDataCenter().getId()); buf.append(" pod=").append(dest.getPod().getId()); - if (profile.getVirtualMachine().getRole() == SecondaryStorageVm.Role.templateProcessor) + if (profile.getVirtualMachine().getRole() == SecondaryStorageVm.Role.templateProcessor) { buf.append(" guid=").append(secHost.getGuid()); - else + } else { buf.append(" guid=").append(profile.getVirtualMachine().getHostName()); + } String nfsMountPoint = null; try { @@ -865,10 +867,12 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V if (_configDao.isPremium()) { if (profile.getHypervisorType() == HypervisorType.Hyperv) { buf.append(" resource=com.cloud.storage.resource.CifsSecondaryStorageResource"); - } else + } else { buf.append(" resource=com.cloud.storage.resource.PremiumSecondaryStorageResource"); - } else + } + } else { buf.append(" resource=com.cloud.storage.resource.NfsSecondaryStorageResource"); + } buf.append(" instance=SecStorage"); buf.append(" sslcopy=").append(Boolean.toString(_useSSlCopy)); buf.append(" role=").append(profile.getVirtualMachine().getRole().toString()); @@ -1028,13 +1032,15 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V long dataCenterId = pool.longValue(); if (!isZoneReady(_zoneHostInfoMap, dataCenterId)) { - if (s_logger.isDebugEnabled()) + if (s_logger.isDebugEnabled()) { s_logger.debug("Zone " + dataCenterId + " is not ready to launch secondary storage VM yet"); + } return false; } - if (s_logger.isDebugEnabled()) + if (s_logger.isDebugEnabled()) { s_logger.debug("Zone " + dataCenterId + " is ready to launch secondary storage VM"); + } return true; }