Repository: cloudstack Updated Branches: refs/heads/master 9a3712841 -> 3d6c64d26
CLOUDSTACK-7206: Update vm_network_map table correctly Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3d6c64d2 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3d6c64d2 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3d6c64d2 Branch: refs/heads/master Commit: 3d6c64d262897d025652a08587ae1105c7239117 Parents: 9a37128 Author: Saksham Srivastava <[email protected]> Authored: Mon Jul 28 09:57:01 2014 +0530 Committer: Saksham Srivastava <[email protected]> Committed: Fri Aug 1 13:58:06 2014 +0530 ---------------------------------------------------------------------- .../orchestration/NetworkOrchestrator.java | 23 +++++++++++++++++++- .../entity/api/db/dao/VMNetworkMapDao.java | 2 ++ .../entity/api/db/dao/VMNetworkMapDaoImpl.java | 16 ++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3d6c64d2/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java index 64a1f3a..3b7e92a 100755 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java @@ -38,10 +38,11 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.log4j.Logger; - import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.engine.cloud.entity.api.db.VMNetworkMapVO; +import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMNetworkMapDao; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigKey; @@ -261,6 +262,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra protected IpAddressManager _ipAddrMgr; @Inject MessageBus _messageBus; + @Inject + VMNetworkMapDao _vmNetworkMapDao; List<NetworkGuru> networkGurus; @@ -1517,6 +1520,18 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } }); + // cleanup the entry in vm_network_map + if(vmProfile.getType().equals(VirtualMachine.Type.User)) { + NicVO nic = _nicDao.findById(nicId); + if(nic != null) { + NetworkVO vmNetwork = _networksDao.findById(nic.getNetworkId()); + VMNetworkMapVO vno = _vmNetworkMapDao.findByVmAndNetworkId(vmProfile.getVirtualMachine().getId(), vmNetwork.getId()); + if(vno != null) { + _vmNetworkMapDao.remove(vno.getId()); + } + } + } + if (networkToRelease != null) { Network network = networkToRelease.first(); NicProfile profile = networkToRelease.second(); @@ -1615,6 +1630,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); guru.deallocate(network, profile, vm); _nicDao.remove(nic.getId()); + s_logger.debug("Removed nic id=" + nic.getId()); //remove the secondary ip addresses corresponding to to this nic if (!removeVmSecondaryIpsOfNic(nic.getId())) { @@ -3056,6 +3072,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network); } + //Update vm_network_map table + if(vmProfile.getType() == VirtualMachine.Type.User) { + VMNetworkMapVO vno = new VMNetworkMapVO(vm.getId(), network.getId()); + _vmNetworkMapDao.persist(vno); + } s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3d6c64d2/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java b/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java index beab7e5..5c54ac3 100644 --- a/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java +++ b/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java @@ -28,4 +28,6 @@ public interface VMNetworkMapDao extends GenericDao<VMNetworkMapVO, Long> { List<Long> getNetworks(long vmId); + VMNetworkMapVO findByVmAndNetworkId(long vmId, long networkId); + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3d6c64d2/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java b/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java index 6b61472..5e683e1 100644 --- a/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java +++ b/engine/schema/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java @@ -38,6 +38,7 @@ import com.cloud.utils.db.TransactionLegacy; public class VMNetworkMapDaoImpl extends GenericDaoBase<VMNetworkMapVO, Long> implements VMNetworkMapDao { protected SearchBuilder<VMNetworkMapVO> VmIdSearch; + protected SearchBuilder<VMNetworkMapVO> VmNetworkSearch; @Inject protected NetworkDao _networkDao; @@ -51,6 +52,11 @@ public class VMNetworkMapDaoImpl extends GenericDaoBase<VMNetworkMapVO, Long> im VmIdSearch.and("vmId", VmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ); VmIdSearch.done(); + VmNetworkSearch = createSearchBuilder(); + VmNetworkSearch.and("vmId", VmNetworkSearch.entity().getVmId(), SearchCriteria.Op.EQ); + VmNetworkSearch.and("networkId", VmNetworkSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); + VmNetworkSearch.done(); + } @Override @@ -85,4 +91,14 @@ public class VMNetworkMapDaoImpl extends GenericDaoBase<VMNetworkMapVO, Long> im return networks; } + @Override + public VMNetworkMapVO findByVmAndNetworkId(long vmId, long networkId) { + + SearchCriteria<VMNetworkMapVO> sc = VmNetworkSearch.create(); + sc.setParameters("vmId", vmId); + sc.setParameters("networkId", networkId); + VMNetworkMapVO network = findOneBy(sc); + + return network; + } }
