From c22ce365936ac08e28527d9192277d8768ecabfa Mon Sep 17 00:00:00 2001 From: Suresh Kumar Anaparti Date: Mon, 21 Sep 2015 19:57:03 +0530 Subject: [PATCH 1/3] CLOUDSTACK-7151: Support multiple physical networks at cluster level for guest traffic over VMware deployments. --- api/src/com/cloud/agent/api/to/NetworkTO.java | 9 + api/src/com/cloud/network/NetworkModel.java | 12 + .../com/cloud/resource/ResourceService.java | 3 +- api/src/com/cloud/vm/NicProfile.java | 12 +- .../apache/cloudstack/api/ApiConstants.java | 1 + .../command/admin/cluster/AddClusterCmd.java | 17 +- .../admin/cluster/UpdateClusterCmd.java | 15 +- .../cloud/agent/api/UnregisterNicCommand.java | 8 +- .../cloud/vm/VirtualMachineManagerImpl.java | 11 +- .../orchestration/NetworkOrchestrator.java | 27 +- ...spring-engine-schema-core-daos-context.xml | 1 + .../ClusterPhysicalNetworkTrafficInfoDao.java | 35 ++ ...sterPhysicalNetworkTrafficInfoDaoImpl.java | 132 +++++++ .../ClusterPhysicalNetworkTrafficInfoVO.java | 91 +++++ .../dao/PhysicalNetworkTrafficTypeDao.java | 4 + .../PhysicalNetworkTrafficTypeDaoImpl.java | 24 +- .../cloud/upgrade/dao/Upgrade452to460.java | 76 +++- .../com/cloud/hypervisor/guru/VMwareGuru.java | 3 +- .../vmware/VmwareServerDiscoverer.java | 358 +++++++++++------- .../vmware/resource/VmwareResource.java | 85 +++-- .../lb/InternalLoadBalancerVMManagerImpl.java | 4 +- .../guru/MidoNetPublicNetworkGuru.java | 1 + .../cloud/hypervisor/HypervisorGuruBase.java | 1 + .../com/cloud/network/NetworkModelImpl.java | 191 +++++++--- .../network/router/CommandSetupHelper.java | 3 +- .../network/router/NicProfileHelperImpl.java | 5 +- .../VirtualNetworkApplianceManagerImpl.java | 6 +- .../cloud/resource/ResourceManagerImpl.java | 84 +++- .../src/com/cloud/vm/UserVmManagerImpl.java | 15 +- .../cloud/network/MockNetworkModelImpl.java | 46 +++ .../resource/MockResourceManagerImpl.java | 2 +- .../com/cloud/vpc/MockNetworkModelImpl.java | 46 +++ setup/db/db/schema-452to460.sql | 14 + 33 files changed, 1084 insertions(+), 258 deletions(-) create mode 100644 engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDao.java create mode 100644 engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDaoImpl.java create mode 100644 engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoVO.java diff --git a/api/src/com/cloud/agent/api/to/NetworkTO.java b/api/src/com/cloud/agent/api/to/NetworkTO.java index be11deaa1ec8..0712a65121cb 100644 --- a/api/src/com/cloud/agent/api/to/NetworkTO.java +++ b/api/src/com/cloud/agent/api/to/NetworkTO.java @@ -33,6 +33,7 @@ public class NetworkTO { protected String dns1; protected String dns2; protected BroadcastDomainType broadcastType; + protected long trafficId; protected TrafficType type; protected URI broadcastUri; protected URI isolationUri; @@ -82,6 +83,10 @@ public void setDns2(String dns2) { this.dns2 = dns2; } + public void setTrafficId(long trafficId) { + this.trafficId = trafficId; + } + public void setType(TrafficType type) { this.type = type; } @@ -154,6 +159,10 @@ public String getDns2() { return dns2; } + public long getTrafficId() { + return trafficId; + } + public TrafficType getType() { return type; } diff --git a/api/src/com/cloud/network/NetworkModel.java b/api/src/com/cloud/network/NetworkModel.java index 780f97d22f4e..ae09045f46f4 100644 --- a/api/src/com/cloud/network/NetworkModel.java +++ b/api/src/com/cloud/network/NetworkModel.java @@ -39,6 +39,8 @@ import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachine; +import com.cloud.utils.Pair; + /** * The NetworkModel presents a read-only view into the Network data such as L2 networks, * Nics, PublicIps, NetworkOfferings, traffic labels, physical networks and the like @@ -164,6 +166,14 @@ public interface NetworkModel { String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervisorType); + Map getPublicTrafficInfo(long dcId, HypervisorType vmware); + + Map getGuestTrafficInfo(long dcId, HypervisorType vmware); + + Pair getDefaultPublicTrafficInfo(long dcId, HypervisorType vmware); + + Pair getDefaultGuestTrafficInfo(long dcId, HypervisorType vmware); + String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware); String getDefaultGuestTrafficLabel(long dcId, HypervisorType vmware); @@ -226,6 +236,8 @@ public interface NetworkModel { long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficType); + long getPhysicalNetworkTrafficId(Long networkId, TrafficType trafficType); + Integer getNetworkRate(long networkId, Long vmId); boolean isVmPartOfNetwork(long vmId, long ntwkId); diff --git a/api/src/com/cloud/resource/ResourceService.java b/api/src/com/cloud/resource/ResourceService.java index 7461455aaeed..d9fa9bda8b79 100644 --- a/api/src/com/cloud/resource/ResourceService.java +++ b/api/src/com/cloud/resource/ResourceService.java @@ -17,6 +17,7 @@ package com.cloud.resource; import java.util.List; +import java.util.Map; import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd; import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd; @@ -64,7 +65,7 @@ public interface ResourceService { boolean deleteCluster(DeleteClusterCmd cmd); - Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState, String managedstate); + Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState, String managedstate, Map physicalNetworkTrafficLabels); List discoverHosts(AddHostCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException; diff --git a/api/src/com/cloud/vm/NicProfile.java b/api/src/com/cloud/vm/NicProfile.java index 58e05124c89f..757a5c02e54f 100644 --- a/api/src/com/cloud/vm/NicProfile.java +++ b/api/src/com/cloud/vm/NicProfile.java @@ -33,6 +33,7 @@ public class NicProfile implements InternalIdentity, Serializable { long id; long networkId; + long trafficId; long vmId; String reservationId; Integer deviceId; @@ -75,9 +76,10 @@ public class NicProfile implements InternalIdentity, Serializable { public NicProfile() { } - public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled, String name) { + public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled, String name, long trafficId) { id = nic.getId(); networkId = network.getId(); + this.trafficId = trafficId; mode = network.getMode(); broadcastType = network.getBroadcastDomainType(); trafficType = network.getTrafficType(); @@ -144,6 +146,14 @@ public void setNetworId(long networkId){ this.networkId = networkId; } + public long getTrafficId() { + return trafficId; + } + + public void setTrafficId(long trafficId){ + this.trafficId = trafficId; + } + public long getVirtualMachineId() { return vmId; } diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java index 2728bcc6fef9..e032af77fab7 100644 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -442,6 +442,7 @@ public class ApiConstants { public static final String VSWITCH_TYPE_PUBLIC_TRAFFIC = "publicvswitchtype"; public static final String VSWITCH_NAME_GUEST_TRAFFIC = "guestvswitchname"; public static final String VSWITCH_NAME_PUBLIC_TRAFFIC = "publicvswitchname"; + public static final String PHYSICAL_NETWORK_TRAFFIC_LABELS = "physicalnetworktrafficlabels"; // Ovs controller public static final String OVS_DEVICE_ID = "ovsdeviceid"; public static final String OVS_DEVICE_NAME = "ovsdevicename"; diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java index 3d0d71497403..3d41cbf813d2 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java @@ -19,15 +19,16 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.BaseCmd.CommandType; import org.apache.cloudstack.api.response.ClusterResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.PodResponse; @@ -99,15 +100,21 @@ public class AddClusterCmd extends BaseCmd { @Parameter(name = ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC, type = CommandType.STRING, required = false, - description = "Name of virtual switch used for guest traffic in the cluster. This would override zone wide traffic label setting.") + description = "Name of virtual switch used for guest traffic in the cluster. This would override zone wide traffic label setting for first guest traffic in the physical networks defined.") private String vSwitchNameGuestTraffic; @Parameter(name = ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC, type = CommandType.STRING, required = false, - description = "Name of virtual switch used for public traffic in the cluster. This would override zone wide traffic label setting.") + description = "Name of virtual switch used for public traffic in the cluster. This would override zone wide traffic label setting for first public traffic in the physical networks defined.") private String vSwitchNamePublicTraffic; + @Parameter(name = ApiConstants.PHYSICAL_NETWORK_TRAFFIC_LABELS, + type = CommandType.MAP, + required = false, + description = "Map of physical network traffic id (of guest and public traffic in the zone) and vmware network label (vSwitch name) in the cluster. This would override zone wide traffic label setting for the specified guest and public traffic in the physical networks defined.") + private Map physicalNetworkTrafficLabels; + @Parameter(name = ApiConstants.OVM3_POOL, type = CommandType.STRING, required = false, description = "Ovm3 native pooling enabled for cluster") private String ovm3pool; @Parameter(name = ApiConstants.OVM3_CLUSTER, type = CommandType.STRING, required = false, description = "Ovm3 native OCFS2 clustering enabled for cluster") @@ -140,6 +147,10 @@ public String getVSwitchNamePublicTraffic() { return vSwitchNamePublicTraffic; } + public Map getPhysicalNetworkTrafficLabels() { + return physicalNetworkTrafficLabels; + } + public String getVSMIpaddress() { return vsmipaddress; } diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java index 53d01c58a561..cab40139b320 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java @@ -16,14 +16,16 @@ // under the License. package org.apache.cloudstack.api.command.admin.cluster; -import org.apache.log4j.Logger; +import java.util.Map; +import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.BaseCmd.CommandType; import org.apache.cloudstack.api.response.ClusterResponse; import com.cloud.exception.InvalidParameterValueException; @@ -33,7 +35,7 @@ @APICommand(name = "updateCluster", description = "Updates an existing cluster", responseObject = ClusterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateClusterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddClusterCmd.class.getName()); + public static final Logger s_logger = Logger.getLogger(UpdateClusterCmd.class.getName()); private static final String s_name = "updateclusterresponse"; @@ -55,6 +57,9 @@ public class UpdateClusterCmd extends BaseCmd { @Parameter(name = ApiConstants.MANAGED_STATE, type = CommandType.STRING, description = "whether this cluster is managed by cloudstack") private String managedState; + @Parameter(name = ApiConstants.PHYSICAL_NETWORK_TRAFFIC_LABELS, type = CommandType.MAP, description = "Map of physical network traffic id (of guest and public traffic in the zone) and vmware network label (vSwitch name) in the cluster.") + private Map physicalNetworkTrafficLabels; + public String getClusterName() { return clusterName; } @@ -101,13 +106,17 @@ public void setManagedstate(String managedstate) { this.managedState = managedstate; } + public Map getPhysicalNetworkTrafficLabels() { + return physicalNetworkTrafficLabels; + } + @Override public void execute() { Cluster cluster = _resourceService.getCluster(getId()); if (cluster == null) { throw new InvalidParameterValueException("Unable to find the cluster by id=" + getId()); } - Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate()); + Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate(), getPhysicalNetworkTrafficLabels()); if (result != null) { ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false); clusterResponse.setResponseName(getCommandName()); diff --git a/core/src/com/cloud/agent/api/UnregisterNicCommand.java b/core/src/com/cloud/agent/api/UnregisterNicCommand.java index f3c03832298c..785c56615c41 100644 --- a/core/src/com/cloud/agent/api/UnregisterNicCommand.java +++ b/core/src/com/cloud/agent/api/UnregisterNicCommand.java @@ -31,11 +31,13 @@ public class UnregisterNicCommand extends Command { private String vmName; private String trafficLabel; private UUID nicUuid; + private long trafficId; - public UnregisterNicCommand(String vmName, String trafficLabel, UUID nicUuid) { + public UnregisterNicCommand(String vmName, String trafficLabel, UUID nicUuid, long trafficId) { this.nicUuid = nicUuid; this.vmName = vmName; this.trafficLabel = trafficLabel; + this.trafficId = trafficId; } public UUID getNicUuid() { @@ -50,6 +52,10 @@ public String getTrafficLabel() { return trafficLabel; } + public long getTrafficId() { + return trafficId; + } + @Override public boolean executeInSequence() { return false; diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index 9dea90a41d15..d955ee955ead 100644 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -39,6 +39,7 @@ import javax.naming.ConfigurationException; import com.cloud.agent.api.AttachOrDettachConfigDriveCommand; + import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; @@ -2693,9 +2694,10 @@ private void ensureVmRunningContext(final long hostId, VMInstanceVO vm, final Ev final List nics = _nicsDao.listByVmId(profile.getId()); for (final NicVO nic : nics) { final Network network = _networkModel.getNetwork(nic.getNetworkId()); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.isSecurityGroupSupportedInNetwork(network), - _networkModel.getNetworkTag(profile.getHypervisorType(), network)); + _networkModel.getNetworkTag(profile.getHypervisorType(), network), trafficId); profile.addNic(nicProfile); } @@ -3103,10 +3105,10 @@ private boolean orchestrateRemoveNicFromVm(final VirtualMachine vm, final Nic ni final DeployDestination dest = new DeployDestination(dc, null, null, host); final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); final VirtualMachineTO vmTO = hvGuru.implement(vmProfile); - + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(network.getId(), vm.getId()), - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); + _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network), trafficId); //1) Unplug the nic if (vm.getState() == State.Running) { @@ -3194,9 +3196,10 @@ private boolean orchestrateRemoveVmFromNetwork(final VirtualMachine vm, final Ne } try { + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(network.getId(), vm.getId()), - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); + _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network), trafficId); //1) Unplug the nic if (vm.getState() == State.Running) { 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 2a87bf5eb728..4fdb1da75559 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java @@ -819,8 +819,9 @@ public Pair allocateNic(NicProfile requested, Network netwo vo = _nicDao.persist(vo); Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), - _networkModel.getNetworkTag(vm.getHypervisorType(), network)); + _networkModel.getNetworkTag(vm.getHypervisorType(), network), trafficId); return new Pair(vmNic, Integer.valueOf(deviceId)); } @@ -1327,10 +1328,9 @@ public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination } URI isolationUri = nic.getIsolationUri(); - + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); profile = new NicProfile(nic, network, broadcastUri, isolationUri, - - networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); + networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network), trafficId); guru.reserve(profile, network, vmProfile, dest, context); nic.setIPv4Address(profile.getIPv4Address()); nic.setAddressFormat(profile.getFormat()); @@ -1349,8 +1349,9 @@ public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination updateNic(nic, network.getId(), 1); } else { + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), - _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); + _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network), trafficId); guru.updateNicProfile(profile, network); nic.setState(Nic.State.Reserved); updateNic(nic, network.getId(), 1); @@ -1391,8 +1392,9 @@ public void prepareNicForMigration(VirtualMachineProfile vm, DeployDestination d Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), - _networkModel.getNetworkTag(vm.getHypervisorType(), network)); + _networkModel.getNetworkTag(vm.getHypervisorType(), network), trafficId); if (guru instanceof NetworkMigrationResponder) { if (!((NetworkMigrationResponder)guru).prepareMigration(profile, network, vm, dest, context)) { s_logger.error("NetworkGuru " + guru + " prepareForMigration failed."); // XXX: Transaction error @@ -1435,8 +1437,9 @@ public void prepareAllNicsForMigration(VirtualMachineProfile vm, DeployDestinati Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network)); + _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network), trafficId); if(guru instanceof NetworkMigrationResponder){ if(!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)){ s_logger.error("NetworkGuru "+guru+" prepareForMigration failed."); // XXX: Transaction error @@ -1488,6 +1491,7 @@ public void prepareAllNicsForMigration(VirtualMachineProfile vm, DeployDestinati profile.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network)); profile.setName(_networkModel.getNetworkTag(vm.getHypervisorType(), network)); profile.setNetworId(network.getId()); + profile.setTrafficId(_networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType())); guru.updateNicProfile(profile, network); vm.addNic(profile); @@ -1597,8 +1601,9 @@ public Pair doInTransaction(TransactionStatus status) { NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); nic.setState(Nic.State.Releasing); _nicDao.update(nic.getId(), nic); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel - .isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); + .isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network), trafficId); if (guru.release(profile, vmProfile, nic.getReservationId())) { applyProfileToNicForRelease(nic, profile); nic.setState(Nic.State.Allocated); @@ -1681,8 +1686,9 @@ protected void removeNic(VirtualMachineProfile vm, NicVO nic) { nic.setState(Nic.State.Deallocating); _nicDao.update(nic.getId(), nic); NetworkVO network = _networksDao.findById(nic.getNetworkId()); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag( - vm.getHypervisorType(), network)); + vm.getHypervisorType(), network), trafficId); /* * We need to release the nics with a Create ReservationStrategy here @@ -3187,8 +3193,9 @@ public List getNicProfiles(VirtualMachine vm) { Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network)); + _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network), trafficId); guru.updateNicProfile(profile, network); profiles.add(profile); } diff --git a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml index 13f35196a5aa..4b408ee389c7 100644 --- a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml +++ b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml @@ -130,6 +130,7 @@ + diff --git a/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDao.java b/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDao.java new file mode 100644 index 000000000000..93bb0d620d93 --- /dev/null +++ b/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDao.java @@ -0,0 +1,35 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.dc; + +import java.util.Map; + +import com.cloud.utils.db.GenericDao; + +public interface ClusterPhysicalNetworkTrafficInfoDao extends GenericDao { + void persist(long clusterId, long physicalNetworkTrafficId, String vmwareNetworkLabel); + + void persist(long clusterId, Map physicalNetworkTrafficLabels); + + ClusterPhysicalNetworkTrafficInfoVO findDetail(long clusterId, long physicalNetworkTrafficId); + + String getVmwareNetworkLabel(long clusterId, long physicalNetworkTrafficId); + + Map getTrafficInfo(long clusterId); + + void deleteDetails(long clusterId); +} diff --git a/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDaoImpl.java b/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDaoImpl.java new file mode 100644 index 000000000000..f6e7ca22a7b9 --- /dev/null +++ b/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDaoImpl.java @@ -0,0 +1,132 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.dc; + +import java.util.List; +import java.util.Map; +import java.util.HashMap; + +import javax.ejb.Local; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.TransactionLegacy; + +@Local(value = ClusterDetailsDao.class) +public class ClusterPhysicalNetworkTrafficInfoDaoImpl extends GenericDaoBase implements ClusterPhysicalNetworkTrafficInfoDao { + protected final SearchBuilder ClusterSearch; + protected final SearchBuilder clusterPhysicalNetworkTrafficSearch; + + protected ClusterPhysicalNetworkTrafficInfoDaoImpl() { + super(); + ClusterSearch = createSearchBuilder(); + ClusterSearch.and("clusterId", ClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ); + ClusterSearch.done(); + + clusterPhysicalNetworkTrafficSearch = createSearchBuilder(); + clusterPhysicalNetworkTrafficSearch.and("clusterId", clusterPhysicalNetworkTrafficSearch.entity().getClusterId(), SearchCriteria.Op.EQ); + clusterPhysicalNetworkTrafficSearch.and("physicalNetworkTrafficId", clusterPhysicalNetworkTrafficSearch.entity().getPhysicalNetworkTrafficId(), Op.EQ); + clusterPhysicalNetworkTrafficSearch.done(); + } + + @Override + public ClusterPhysicalNetworkTrafficInfoVO findDetail(long clusterId, long physicalNetworkTrafficId) { + SearchCriteria sc = clusterPhysicalNetworkTrafficSearch.create(); + sc.setParameters("clusterId", clusterId); + sc.setParameters("physicalNetworkTrafficId", physicalNetworkTrafficId); + + ClusterPhysicalNetworkTrafficInfoVO detail = findOneBy(sc); + return detail; + } + + @Override + public void persist(long clusterId, long physicalNetworkTrafficId, String vmwareNetworkLabel) { + TransactionLegacy txn = TransactionLegacy.currentTxn(); + txn.start(); + SearchCriteria sc = clusterPhysicalNetworkTrafficSearch.create(); + sc.setParameters("clusterId", clusterId); + sc.setParameters("physicalNetworkTrafficId", physicalNetworkTrafficId); + expunge(sc); + + ClusterPhysicalNetworkTrafficInfoVO vo = new ClusterPhysicalNetworkTrafficInfoVO(clusterId, physicalNetworkTrafficId, vmwareNetworkLabel); + persist(vo); + txn.commit(); + } + + @Override + public void persist(long clusterId, Map physicalNetworkTrafficLabels) { + if(physicalNetworkTrafficLabels == null || physicalNetworkTrafficLabels.isEmpty()) { + return; + } + + TransactionLegacy txn = TransactionLegacy.currentTxn(); + txn.start(); + SearchCriteria sc = ClusterSearch.create(); + sc.setParameters("clusterId", clusterId); + for (Map.Entry detail : physicalNetworkTrafficLabels.entrySet()) { + sc.setParameters("physicalNetworkTrafficId", detail.getKey()); + expunge(sc); + } + + for (Map.Entry detail : physicalNetworkTrafficLabels.entrySet()) { + ClusterPhysicalNetworkTrafficInfoVO vo = new ClusterPhysicalNetworkTrafficInfoVO(clusterId, detail.getKey(), detail.getValue()); + persist(vo); + } + txn.commit(); + } + + @Override + public String getVmwareNetworkLabel(long clusterId, long physicalNetworkTrafficId) { + ClusterPhysicalNetworkTrafficInfoVO trafficInfo = findDetail(clusterId, physicalNetworkTrafficId); + if (trafficInfo == null) { + return null; + } + + return trafficInfo.getVmwareNetworkLabel(); + } + + @Override + public Map getTrafficInfo(long clusterId) { + SearchCriteria sc = ClusterSearch.create(); + sc.setParameters("clusterId", clusterId); + List trafficInfoList= listBy(sc); + + if (trafficInfoList == null || trafficInfoList.size() == 0) { + return null; + } + + Map trafficInfoMap = new HashMap(); + for (ClusterPhysicalNetworkTrafficInfoVO trafficInfo : trafficInfoList) { + trafficInfoMap.put(new Long(trafficInfo.getPhysicalNetworkTrafficId()), trafficInfo.getVmwareNetworkLabel()); + } + + return trafficInfoMap; + } + + @Override + public void deleteDetails(long clusterId) { + SearchCriteria sc = ClusterSearch.create(); + sc.setParameters("clusterId", clusterId); + + List results = search(sc, null); + for (ClusterPhysicalNetworkTrafficInfoVO result : results) { + remove(result.getId()); + } + } +} diff --git a/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoVO.java b/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoVO.java new file mode 100644 index 000000000000..c77325e6ef0d --- /dev/null +++ b/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoVO.java @@ -0,0 +1,91 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.dc; + +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +@Entity +@Table(name = "cluster_physical_network_traffic_info") +public class ClusterPhysicalNetworkTrafficInfoVO implements InternalIdentity, Identity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "cluster_id") + private long clusterId; + + @Column(name = "physical_network_traffic_id") + private long physicalNetworkTrafficId; + + @Column(name = "vmware_network_label") + private String vmwareNetworkLabel; + + public ClusterPhysicalNetworkTrafficInfoVO() { + } + + public ClusterPhysicalNetworkTrafficInfoVO(long clusterId, long physicalNetworkTrafficId, String vmwareLabel) { + this.clusterId = clusterId; + this.physicalNetworkTrafficId = physicalNetworkTrafficId; + this.vmwareNetworkLabel = vmwareLabel; + this.uuid = UUID.randomUUID().toString(); + } + + @Override + public long getId() { + return id; + } + + public long getClusterId() { + return clusterId; + } + + public long getPhysicalNetworkTrafficId() { + return physicalNetworkTrafficId; + } + + public void setVmwareNetworkLabel(String vmwareNetworkLabel) { + this.vmwareNetworkLabel = vmwareNetworkLabel; + } + + public String getVmwareNetworkLabel() { + return vmwareNetworkLabel; + } + + @Override + public String getUuid() { + return this.uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } +} \ No newline at end of file diff --git a/engine/schema/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java index 5744a81e30d8..125253cf9d83 100644 --- a/engine/schema/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java +++ b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java @@ -28,9 +28,13 @@ public interface PhysicalNetworkTrafficTypeDao extends GenericDao, Integer> listAndCountBy(long phy @Override public boolean isTrafficTypeSupported(long physicalNetworkId, TrafficType trafficType) { - SearchCriteria sc = physicalNetworkSearch.create(); - sc.setParameters("physicalNetworkId", physicalNetworkId); - sc.setParameters("trafficType", trafficType); - if (findOneBy(sc) != null) { + if (findBy(physicalNetworkId, trafficType) != null) { return true; } else { return false; } } + @Override + public long getPhysicalNetworkTrafficId(long physicalNetworkId, TrafficType trafficType) { + PhysicalNetworkTrafficTypeVO physicalNetworkTrafficType = findBy(physicalNetworkId, trafficType); + if(physicalNetworkTrafficType == null) { + return 0; + } + + return physicalNetworkTrafficType.getId(); + } + @Override public String getNetworkTag(long physicalNetworkId, TrafficType trafficType, HypervisorType hType) { SearchCriteria sc = null; @@ -159,4 +166,13 @@ public void deleteTrafficTypes(long physicalNetworkId) { sc.setParameters("physicalNetworkId", physicalNetworkId); remove(sc); } + + @Override + public TrafficType getTrafficType(long physicalNetworkTrafficId) { + PhysicalNetworkTrafficTypeVO PhysicalNetworkTrafficTypeVO = findById(physicalNetworkTrafficId); + if(PhysicalNetworkTrafficTypeVO == null) + return TrafficType.None; + + return PhysicalNetworkTrafficTypeVO.getTrafficType(); + } } diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java index 0ad26035ca7d..267f14c3a061 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java @@ -24,9 +24,11 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import org.apache.log4j.Logger; +import com.cloud.network.Networks.TrafficType; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.Script; @@ -60,8 +62,10 @@ public File[] getPrepareScripts() { @Override public void performDataMigration(final Connection conn) { - updateVMInstanceUserId(conn); - addIndexForVMInstance(conn); + //updateVMInstanceUserId(conn); + //addIndexForVMInstance(conn); + updateClusterLevelPhysicalNetworkTrafficInfo(conn, TrafficType.Guest); + updateClusterLevelPhysicalNetworkTrafficInfo(conn, TrafficType.Public); } public void updateVMInstanceUserId(final Connection conn) { @@ -155,6 +159,74 @@ private void addIndexForVMInstance(Connection conn) { } } + private void updateClusterLevelPhysicalNetworkTrafficInfo(Connection conn, TrafficType trafficType) { + if (conn == null) { + s_logger.debug("DB connection is null"); + return; + } + + if (trafficType != TrafficType.Guest && trafficType != TrafficType.Public) { + s_logger.debug("Cluster level physical network traffic info update is supported for guest and public traffic only"); + return; + } + + String phyNetworktrafficType = (trafficType == TrafficType.Guest) ? "Guest" : "Public"; + String vswitchParamName = (trafficType == TrafficType.Guest) ? "guestvswitchname" : "publicvswitchname"; + + String vswitchNameAtClusterDetailsSelectSql = "SELECT cluster_id, value FROM `cloud`.`cluster_details` where name = ?"; + String vswitchNameAtClusterDetailsDeleteSql = "DELETE FROM `cloud`.`cluster_details` where name = ?"; + String physicalNetworkTrafficIdSelectSql = "SELECT traffictype.id FROM `cloud`.`physical_network` as network, `cloud`.`physical_network_traffic_types` as traffictype where network.id=traffictype.physical_network_id and network.data_center_id=(SELECT data_center_id FROM `cloud`.`cluster` where id=?) and traffictype.traffic_type=?"; + String clusterPhysicalNwTrafficInsertSql = "INSERT INTO `cloud`.`cluster_physical_network_traffic_info` (uuid, cluster_id, physical_network_traffic_id, vmware_network_label) VALUES (?,?,?,?)"; + + s_logger.debug("Updating cluster level physical network traffic info for " + phyNetworktrafficType + " traffic"); + + try (PreparedStatement pstmtSelectVswitchNameAtClusterDetails = conn.prepareStatement(vswitchNameAtClusterDetailsSelectSql); + PreparedStatement pstmtDeleteVswitchNameAtClusterDetails = conn.prepareStatement(vswitchNameAtClusterDetailsDeleteSql);) { + pstmtSelectVswitchNameAtClusterDetails.setString(1, vswitchParamName); + ResultSet rsVswitchNameAtClusters = pstmtSelectVswitchNameAtClusterDetails.executeQuery(); + + // for each vswitch name at the cluster + while (rsVswitchNameAtClusters.next()) { + // get the cluster id + long clusterId = rsVswitchNameAtClusters.getLong(1); + // get vswitch name at cluster + String vswitchNameAtCluster = rsVswitchNameAtClusters.getString(2); + if (vswitchNameAtCluster == null || vswitchNameAtCluster.isEmpty()) { + continue; + } + + try (PreparedStatement pstmtSelectPhysicalNetworkTrafficId = conn.prepareStatement(physicalNetworkTrafficIdSelectSql); + PreparedStatement pstmtInsertClusterPhysicalNwTraffic = conn.prepareStatement(clusterPhysicalNwTrafficInsertSql);) { + pstmtSelectPhysicalNetworkTrafficId.setLong(1, clusterId); + pstmtSelectPhysicalNetworkTrafficId.setString(2, phyNetworktrafficType); + ResultSet rsPhysicalNetworkTrafficIds = pstmtSelectPhysicalNetworkTrafficId.executeQuery(); + + while (rsPhysicalNetworkTrafficIds.next()) { + long physicalNetworkTrafficId = rsPhysicalNetworkTrafficIds.getLong(1); + String uuid = UUID.randomUUID().toString(); + + pstmtInsertClusterPhysicalNwTraffic.setString(1, uuid); + pstmtInsertClusterPhysicalNwTraffic.setLong(2, clusterId); + pstmtInsertClusterPhysicalNwTraffic.setLong(3, physicalNetworkTrafficId); + pstmtInsertClusterPhysicalNwTraffic.setString(4, vswitchNameAtCluster); + + pstmtInsertClusterPhysicalNwTraffic.executeUpdate(); + break; // Perform only for first physical network traffic id + } + } catch (SQLException e) { + throw new CloudRuntimeException("Exception while adding cluster level traffic info for " + phyNetworktrafficType + " traffic", e); + } + } + + pstmtDeleteVswitchNameAtClusterDetails.setString(1, vswitchParamName); + pstmtDeleteVswitchNameAtClusterDetails.executeUpdate(); + } catch (SQLException e) { + throw new CloudRuntimeException("Exception while updating cluster level physical network traffic info for " + phyNetworktrafficType + " traffic", e); + } + + s_logger.debug("Updated cluster level physical network traffic info for " + phyNetworktrafficType + " traffic"); + } + @Override public File[] getCleanupScripts() { final String script = Script.findScript("", "db/schema-452to460-cleanup.sql"); diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java index 62d82c24b2ee..bc6d905cbc84 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java @@ -505,8 +505,9 @@ public List finalizeExpungeNics(VirtualMachine vm, List nic // We need the traffic label to figure out which vSwitch has the // portgroup PhysicalNetworkTrafficTypeVO trafficTypeVO = _physicalNetworkTrafficTypeDao.findBy(networkVO.getPhysicalNetworkId(), networkVO.getTrafficType()); + long trafficId = _networkMgr.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); UnregisterNicCommand unregisterNicCommand = - new UnregisterNicCommand(vm.getInstanceName(), trafficTypeVO.getVmwareNetworkLabel(), UUID.fromString(nic.getUuid())); + new UnregisterNicCommand(vm.getInstanceName(), trafficTypeVO.getVmwareNetworkLabel(), UUID.fromString(nic.getUuid()), trafficId); commands.add(unregisterNicCommand); } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java index 20eb6595f83a..1134ede4edbb 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java @@ -40,6 +40,7 @@ import com.cloud.alert.AlertManager; import com.cloud.configuration.Config; import com.cloud.dc.ClusterDetailsDao; +import com.cloud.dc.ClusterPhysicalNetworkTrafficInfoDao; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenterVO; @@ -64,6 +65,7 @@ import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetwork; import com.cloud.network.VmwareTrafficLabel; +import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao; import com.cloud.network.dao.CiscoNexusVSMDeviceDao; import com.cloud.network.element.CiscoNexusVSMElement; import com.cloud.network.element.NetworkElement; @@ -83,6 +85,7 @@ @Local(value = Discoverer.class) public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter { private static final Logger s_logger = Logger.getLogger(VmwareServerDiscoverer.class); + private static final int MAX_FIELDS_VMWARE_LABEL_AT_CLUSTER = 1; @Inject VmwareManager _vmwareMgr; @@ -93,6 +96,10 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer @Inject ClusterDetailsDao _clusterDetailsDao; @Inject + ClusterPhysicalNetworkTrafficInfoDao _clusterPhysicalNetworkTrafficInfoDao; + @Inject + PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao; + @Inject CiscoNexusVSMDeviceDao _nexusDao; @Inject NetworkModel _netmgr; @@ -188,64 +195,102 @@ public VmwareServerDiscoverer() { } String privateTrafficLabel = null; - String publicTrafficLabel = null; - String guestTrafficLabel = null; - Map vsmCredentials = null; - VirtualSwitchType defaultVirtualSwitchType = VirtualSwitchType.StandardVirtualSwitch; - - String paramGuestVswitchType = null; - String paramGuestVswitchName = null; - String paramPublicVswitchType = null; - String paramPublicVswitchName = null; + Map vsmCredentials = null; - VmwareTrafficLabel guestTrafficLabelObj = new VmwareTrafficLabel(TrafficType.Guest); - VmwareTrafficLabel publicTrafficLabelObj = new VmwareTrafficLabel(TrafficType.Public); DataCenterVO zone = _dcDao.findById(dcId); NetworkType zoneType = zone.getNetworkType(); _readGlobalConfigParameters(); - // Set default physical network end points for public and guest traffic - // Private traffic will be only on standard vSwitch for now. - if (useDVS) { - // Parse url parameters for type of vswitch and name of vswitch specified at cluster level - paramGuestVswitchType = _urlParams.get(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC); - paramGuestVswitchName = _urlParams.get(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC); - paramPublicVswitchType = _urlParams.get(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC); - paramPublicVswitchName = _urlParams.get(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC); - defaultVirtualSwitchType = getDefaultVirtualSwitchType(); - } - - // Zone level vSwitch Type depends on zone level traffic labels + // Zone level vSwitch type depends on zone level traffic labels // - // User can override Zone wide vswitch type (for public and guest) by providing following optional parameters in addClusterCmd + // User can override Zone wide vswitch type and name (for public and guest) by providing following optional parameters in addClusterCmd // param "guestvswitchtype" with valid values vmwaredvs, vmwaresvs, nexusdvs // param "publicvswitchtype" with valid values vmwaredvs, vmwaresvs, nexusdvs + // param "guestvswitchname" with valid name for the vswitch type for the first guest traffic + // param "publicvswitchname" with valid name for the vswitch type for the first public traffic + // param "physicalnetworktrafficlabels" - Map of physical network traffic id (of guest and public traffic in the zone) and vmware network label(valid vswitch name) for the vswitch type + // param "physicalnetworktrafficlabels" would precede over the params "guestvswitchname" and "publicvswitchname" for the first guest and public traffic respectively // - // Format of label is ,, - // If a field OR is not present leave it empty. + // Format of zone level network label is ,, + // If a field OR is not present leave it empty. // Ex: 1) vswitch0 // 2) dvswitch0,200,vmwaredvs // 3) nexusepp0,300,nexusdvs // 4) vswitch1,400,vmwaresvs // 5) vswitch0 // default vswitchtype is 'vmwaresvs'. - // 'vmwaresvs' is for vmware standard vswitch - // 'vmwaredvs' is for vmware distributed virtual switch - // 'nexusdvs' is for cisco nexus distributed virtual switch - // Get zone wide traffic labels for Guest traffic and Public traffic - guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(dcId, HypervisorType.VMware); + // 'vmwaresvs' is for vmware standard vswitch + // 'vmwaredvs' is for vmware distributed virtual switch + // 'nexusdvs' is for cisco nexus distributed virtual switch + // + // Format of cluster level network label is + + // Parse url parameters for vswitch type and name specified at cluster level + String guestVswitchTypeAtClusterLevel = _urlParams.get(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC); + validateVswitchType(guestVswitchTypeAtClusterLevel); + clusterDetails.put(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC, guestVswitchTypeAtClusterLevel); + + String publicVswitchTypeAtClusterLevel = _urlParams.get(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC); + validateVswitchType(publicVswitchTypeAtClusterLevel); + clusterDetails.put(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC, publicVswitchTypeAtClusterLevel); + + // Save cluster level override configuration to cluster details + _clusterDetailsDao.persist(clusterId, clusterDetails); + + String guestVswitchNameAtClusterLevel = _urlParams.get(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC); + validateVswitchNameAtCluster(guestVswitchTypeAtClusterLevel); + + String publicVswitchNameAtClusterLevel = _urlParams.get(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC); + validateVswitchNameAtCluster(guestVswitchTypeAtClusterLevel); + + // Zone level traffic info with physical network traffic id and network label + Map guestTrafficInfoAtZoneLevel = _netmgr.getGuestTrafficInfo(dcId, HypervisorType.VMware); + Map publicTrafficInfoAtZoneLevel = _netmgr.getPublicTrafficInfo(dcId, HypervisorType.VMware); + + // Cluster level traffic info with physical network traffic id and network label (vswitch name) + Map guestTrafficInfoAtClusterLevel = getGuestTrafficInfoForCluster(clusterId); + Map publicTrafficInfoAtClusterLevel = getPublicTrafficInfoForCluster(clusterId); + + Map guestTrafficLabelInfo = null; + Map publicTrafficLabelInfo = null; + + // When "guestvswitchname" param is defined, add the vswitch name to the first guest traffic when the same is not defined in "physicalnetworktrafficlabels" param + if (guestVswitchNameAtClusterLevel != null) { + // Get zone wide traffic label for first guest traffic + Pair firstGuestTrafficInfoAtZone = _netmgr.getDefaultGuestTrafficInfo(dcId, HypervisorType.VMware); //Returns first guest traffic found in the physical networks on that zone + if (firstGuestTrafficInfoAtZone != null) { + s_logger.debug("Zone level first guest traffic id: " + firstGuestTrafficInfoAtZone.first() + " and label: " + firstGuestTrafficInfoAtZone.second()); + + long firstGuestPhysicalNetworkTrafficIdAtZoneLevel = firstGuestTrafficInfoAtZone.first(); + if (guestTrafficInfoAtClusterLevel == null || !guestTrafficInfoAtClusterLevel.containsKey(firstGuestPhysicalNetworkTrafficIdAtZoneLevel)) { + _clusterPhysicalNetworkTrafficInfoDao.persist(clusterId, firstGuestPhysicalNetworkTrafficIdAtZoneLevel, guestVswitchNameAtClusterLevel); + guestTrafficInfoAtClusterLevel = getGuestTrafficInfoForCluster(clusterId); // Update cluster level traffic info for guest traffic + } + } + } - // Process traffic label information provided at zone level and cluster level - guestTrafficLabelObj = getTrafficInfo(TrafficType.Guest, guestTrafficLabel, defaultVirtualSwitchType, paramGuestVswitchType, paramGuestVswitchName, clusterId); + // Process guest traffic label information provided at zone level and cluster level + guestTrafficLabelInfo = getTrafficInfo(TrafficType.Guest, guestTrafficInfoAtZoneLevel, guestTrafficInfoAtClusterLevel, guestVswitchTypeAtClusterLevel); if (zoneType == NetworkType.Advanced) { - // Get zone wide traffic label for Public traffic - publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(dcId, HypervisorType.VMware); + // When "publicvswitchname" param is defined, add the vswitch name to the first public traffic when the same is not defined in "physicalnetworktrafficlabels" param + if (publicVswitchNameAtClusterLevel != null) { + // Get zone wide traffic label for first public traffic + Pair firstPublicTrafficInfoAtZone = _netmgr.getDefaultPublicTrafficInfo(dcId, HypervisorType.VMware); ////Returns first public traffic found in the physical networks on that zone + if (firstPublicTrafficInfoAtZone != null) { + s_logger.debug("Zone level first public traffic id: " + firstPublicTrafficInfoAtZone.first() + " and label: " + firstPublicTrafficInfoAtZone.second()); + + long firstPublicPhysicalNetworkTrafficIdAtZoneLevel = firstPublicTrafficInfoAtZone.first(); + if(publicTrafficInfoAtClusterLevel == null || !publicTrafficInfoAtClusterLevel.containsKey(firstPublicPhysicalNetworkTrafficIdAtZoneLevel)) { + _clusterPhysicalNetworkTrafficInfoDao.persist(clusterId, firstPublicPhysicalNetworkTrafficIdAtZoneLevel, publicVswitchNameAtClusterLevel); + publicTrafficInfoAtClusterLevel = getPublicTrafficInfoForCluster(clusterId); // Update cluster level traffic info for public traffic + } + } + } - // Process traffic label information provided at zone level and cluster level - publicTrafficLabelObj = - getTrafficInfo(TrafficType.Public, publicTrafficLabel, defaultVirtualSwitchType, paramPublicVswitchType, paramPublicVswitchName, clusterId); + // Process public traffic label information provided at zone level and cloud level + publicTrafficLabelInfo = getTrafficInfo(TrafficType.Public, publicTrafficInfoAtZoneLevel, publicTrafficInfoAtClusterLevel, publicVswitchTypeAtClusterLevel); // Configuration Check: A physical network cannot be shared by different types of virtual switches. // @@ -263,6 +308,12 @@ public VmwareServerDiscoverer() { // Public network would be on single physical network hence getting first object of the list would suffice. PhysicalNetwork pNetworkPublic = pNetworkListPublicTraffic.get(0); if (pNetworkListGuestTraffic.contains(pNetworkPublic)) { + VmwareTrafficLabel publicTrafficLabelObj = (publicTrafficLabelInfo != null) ? (VmwareTrafficLabel)publicTrafficLabelInfo.values().toArray()[0] : null; + VirtualSwitchType publicTrafficVirtualSwitchType = (publicTrafficLabelObj != null) ? publicTrafficLabelObj.getVirtualSwitchType() : VirtualSwitchType.None; + + long guestTrafficId = _physicalNetworkTrafficTypeDao.getPhysicalNetworkTrafficId(pNetworkPublic.getId(), TrafficType.Guest); + VmwareTrafficLabel guestTrafficLabelObj = (guestTrafficLabelInfo != null) ? guestTrafficLabelInfo.get(guestTrafficId) : null; + VirtualSwitchType guestTrafficVirtualSwitchType = (guestTrafficLabelObj != null) ? guestTrafficLabelObj.getVirtualSwitchType() : VirtualSwitchType.None; if (publicTrafficLabelObj.getVirtualSwitchType() != guestTrafficLabelObj.getVirtualSwitchType()) { String msg = "Both public traffic and guest traffic is over same physical network " + pNetworkPublic + @@ -279,37 +330,53 @@ public VmwareServerDiscoverer() { s_logger.info("Detected private network label : " + privateTrafficLabel); } Pair vsmInfo = new Pair(false, 0L); - if (nexusDVS && (guestTrafficLabelObj.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) || - ((zoneType == NetworkType.Advanced) && (publicTrafficLabelObj.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch))) { + if (nexusDVS) { // Expect Cisco Nexus VSM details only if following 2 condition met // 1) The global config parameter vmware.use.nexus.vswitch // 2) Atleast 1 traffic type uses Nexus distributed virtual switch as backend. - if (zoneType != NetworkType.Basic) { - publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(dcId, HypervisorType.VMware); - if (publicTrafficLabel != null) { - s_logger.info("Detected public network label : " + publicTrafficLabel); + boolean nexusDVSUsedAtGuestTraffic = false; + for (Map.Entry guestTrafficLabel : guestTrafficLabelInfo.entrySet()) { + if (guestTrafficLabel.getValue().getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) { + nexusDVSUsedAtGuestTraffic = true; + // Get physical network label + String guestTrafficNWLabel = guestTrafficLabel.getValue().getVirtualSwitchName(); + if (guestTrafficNWLabel != null) { + s_logger.info("Detected guest network label : " + guestTrafficNWLabel); + } } } - // Get physical network label - guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(dcId, HypervisorType.VMware); - if (guestTrafficLabel != null) { - s_logger.info("Detected guest network label : " + guestTrafficLabel); + + boolean nexusDVSUsedAtPublicTraffic = false; + if(zoneType == NetworkType.Advanced) { + for (Map.Entry publicTrafficLabel : publicTrafficLabelInfo.entrySet()) { + if (publicTrafficLabel.getValue().getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) { + nexusDVSUsedAtPublicTraffic = true; + // Get physical network label + String publicTrafficNWLabel = publicTrafficLabel.getValue().getVirtualSwitchName(); + if (publicTrafficNWLabel != null) { + s_logger.info("Detected public network label : " + publicTrafficNWLabel); + } + } + } } - // Before proceeding with validation of Nexus 1000v VSM check if an instance of Nexus 1000v VSM is already associated with this cluster. - boolean clusterHasVsm = _vmwareMgr.hasNexusVSM(clusterId); - if (!clusterHasVsm) { - vsmIp = _urlParams.get("vsmipaddress"); - String vsmUser = _urlParams.get("vsmusername"); - String vsmPassword = _urlParams.get("vsmpassword"); - String clusterName = cluster.getName(); - try { - vsmInfo = _nexusElement.validateAndAddVsm(vsmIp, vsmUser, vsmPassword, clusterId, clusterName); - } catch (ResourceInUseException ex) { - DiscoveryException discEx = new DiscoveryException(ex.getLocalizedMessage() + ". The resource is " + ex.getResourceName()); - throw discEx; + + if (nexusDVSUsedAtGuestTraffic || nexusDVSUsedAtPublicTraffic) { + // Before proceeding with validation of Nexus 1000v VSM check if an instance of Nexus 1000v VSM is already associated with this cluster. + boolean clusterHasVsm = _vmwareMgr.hasNexusVSM(clusterId); + if (!clusterHasVsm) { + vsmIp = _urlParams.get("vsmipaddress"); + String vsmUser = _urlParams.get("vsmusername"); + String vsmPassword = _urlParams.get("vsmpassword"); + String clusterName = cluster.getName(); + try { + vsmInfo = _nexusElement.validateAndAddVsm(vsmIp, vsmUser, vsmPassword, clusterId, clusterName); + } catch (ResourceInUseException ex) { + DiscoveryException discEx = new DiscoveryException(ex.getLocalizedMessage() + ". The resource is " + ex.getResourceName()); + throw discEx; + } } + vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId); } - vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId); } VmwareContext context = null; @@ -384,8 +451,8 @@ public VmwareServerDiscoverer() { if (privateTrafficLabel != null) { params.put("private.network.vswitch.name", privateTrafficLabel); } - params.put("guestTrafficInfo", guestTrafficLabelObj); - params.put("publicTrafficInfo", publicTrafficLabelObj); + params.put("guestTrafficInfo", guestTrafficLabelInfo); + params.put("publicTrafficInfo", publicTrafficLabelInfo); params.put("router.aggregation.command.each.timeout", _configDao.getValue(Config.RouterAggregationCommandEachTimeout.toString())); @@ -627,74 +694,34 @@ public boolean stop() { return super.stop(); } - private VmwareTrafficLabel getTrafficInfo(TrafficType trafficType, String zoneWideTrafficLabel, VirtualSwitchType defaultVirtualSwitchType, String vSwitchType, - String vSwitchName, Long clusterId) { - VmwareTrafficLabel trafficLabelObj = null; - Map clusterDetails = null; - try { - trafficLabelObj = new VmwareTrafficLabel(zoneWideTrafficLabel, trafficType, defaultVirtualSwitchType); - } catch (InvalidParameterValueException e) { - s_logger.error("Failed to recognize virtual switch type specified for " + trafficType + " traffic due to " + e.getMessage()); - throw e; - } - - clusterDetails = _clusterDetailsDao.findDetails(clusterId); - if (vSwitchName != null) { - trafficLabelObj.setVirtualSwitchName(vSwitchName); - } - if (trafficType == TrafficType.Guest) { - clusterDetails.put(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC, trafficLabelObj.getVirtualSwitchName()); - } else { - clusterDetails.put(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC, trafficLabelObj.getVirtualSwitchName()); - } - - if (vSwitchType != null) { - validateVswitchType(vSwitchType); - trafficLabelObj.setVirtualSwitchType(VirtualSwitchType.getType(vSwitchType)); - } - if (trafficType == TrafficType.Guest) { - clusterDetails.put(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC, trafficLabelObj.getVirtualSwitchType().toString()); - } else { - clusterDetails.put(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC, trafficLabelObj.getVirtualSwitchType().toString()); - } + private Map getTrafficInfo(TrafficType trafficType, Map zoneLevelTrafficInfo, Map clusterLevelTrafficInfo, + String clusterLevelSwitchType) { + Map trafficInfo = new HashMap(); - // Save cluster level override configuration to cluster details - _clusterDetailsDao.persist(clusterId, clusterDetails); - - return trafficLabelObj; - } - - private VmwareTrafficLabel getTrafficInfo(TrafficType trafficType, String zoneWideTrafficLabel, Map clusterDetails, - VirtualSwitchType defVirtualSwitchType) { - VmwareTrafficLabel trafficLabelObj = null; - try { - trafficLabelObj = new VmwareTrafficLabel(zoneWideTrafficLabel, trafficType, defVirtualSwitchType); - } catch (InvalidParameterValueException e) { - s_logger.error("Failed to recognize virtual switch type specified for " + trafficType + " traffic due to " + e.getMessage()); - throw e; - } - - if (defVirtualSwitchType.equals(VirtualSwitchType.StandardVirtualSwitch)) { - return trafficLabelObj; - } - - if (trafficType == TrafficType.Guest) { - if (clusterDetails.containsKey(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC)) { - trafficLabelObj.setVirtualSwitchName(clusterDetails.get(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC)); - } - if (clusterDetails.containsKey(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC)) { - trafficLabelObj.setVirtualSwitchType(VirtualSwitchType.getType(clusterDetails.get(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC))); - } - } else if (trafficType == TrafficType.Public) { - if (clusterDetails.containsKey(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC)) { - trafficLabelObj.setVirtualSwitchName(clusterDetails.get(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC)); + // Iterate through each zone level entry and Apply the cluster level overridden settings found with the physical network traffic id + for (Map.Entry zoneLevelTrafficDetail : zoneLevelTrafficInfo.entrySet()) { + VmwareTrafficLabel trafficLabelObj = null; + try { + trafficLabelObj = new VmwareTrafficLabel(zoneLevelTrafficDetail.getValue(), trafficType, getDefaultVirtualSwitchTypeAtCloudLevel()); + } catch (InvalidParameterValueException e) { + s_logger.error("Failed to recognize virtual switch type specified for " + trafficType + " traffic due to " + e.getMessage()); + throw e; } - if (clusterDetails.containsKey(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC)) { - trafficLabelObj.setVirtualSwitchType(VirtualSwitchType.getType(clusterDetails.get(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC))); + + // Check if any cluster level traffic override settings for that traffic id + if (clusterLevelTrafficInfo != null && clusterLevelSwitchType != null && VirtualSwitchType.getType(clusterLevelSwitchType) != VirtualSwitchType.None + && clusterLevelTrafficInfo.containsKey(zoneLevelTrafficDetail.getKey())) { + s_logger.debug("Cluster level traffic override found for the physical network traffic id: " + zoneLevelTrafficDetail.getKey()); + s_logger.debug("Replacing zone level label: " + zoneLevelTrafficDetail.getValue() + " with cluster vswitch type: " + clusterLevelSwitchType + " and name: " + + clusterLevelTrafficInfo.get(zoneLevelTrafficDetail.getKey())); + trafficLabelObj.setVirtualSwitchType(VirtualSwitchType.getType(clusterLevelSwitchType)); + trafficLabelObj.setVirtualSwitchName(clusterLevelTrafficInfo.get(zoneLevelTrafficDetail.getKey())); } + + trafficInfo.put(zoneLevelTrafficDetail.getKey(), trafficLabelObj); } - return trafficLabelObj; + return trafficInfo; } private void _readGlobalConfigParameters() { @@ -712,25 +739,32 @@ protected HashMap buildConfigParams(HostVO host) { HashMap params = super.buildConfigParams(host); Map clusterDetails = _clusterDetailsDao.findDetails(host.getClusterId()); - // Get zone wide traffic labels from guest traffic and public traffic - String guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(host.getDataCenterId(), HypervisorType.VMware); - String publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(host.getDataCenterId(), HypervisorType.VMware); + + // Zone level traffic info with physical network traffic id and network label + Map guestTrafficInfoAtZoneLevel = _netmgr.getGuestTrafficInfo(host.getDataCenterId(), HypervisorType.VMware); + Map publicTrafficInfoAtZoneLevel = _netmgr.getPublicTrafficInfo(host.getDataCenterId(), HypervisorType.VMware); + + // Cluster level traffic info with physical network traffic id and network label (vswitch name) + Map guestTrafficInfoAtClusterLevel = getGuestTrafficInfoForCluster(host.getClusterId()); + Map publicTrafficInfoAtClusterLevel = getPublicTrafficInfoForCluster(host.getClusterId()); + + String guestVswitchTypeAtClusterLevel = clusterDetails.get(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC); + String publicVswitchTypeAtClusterLevel = clusterDetails.get(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC); + _readGlobalConfigParameters(); - VirtualSwitchType defaultVirtualSwitchType = getDefaultVirtualSwitchType(); - params.put("guestTrafficInfo", getTrafficInfo(TrafficType.Guest, guestTrafficLabel, clusterDetails, defaultVirtualSwitchType)); - params.put("publicTrafficInfo", getTrafficInfo(TrafficType.Public, publicTrafficLabel, clusterDetails, defaultVirtualSwitchType)); + params.put("guestTrafficInfo", getTrafficInfo(TrafficType.Guest, guestTrafficInfoAtZoneLevel, guestTrafficInfoAtClusterLevel, guestVswitchTypeAtClusterLevel)); + params.put("publicTrafficInfo", getTrafficInfo(TrafficType.Public, publicTrafficInfoAtZoneLevel, publicTrafficInfoAtClusterLevel, publicVswitchTypeAtClusterLevel)); return params; } - private VirtualSwitchType getDefaultVirtualSwitchType() { - if (nexusDVS) - return VirtualSwitchType.NexusDistributedVirtualSwitch; - else if (useDVS) - return VirtualSwitchType.VMwareDistributedVirtualSwitch; - else - return VirtualSwitchType.StandardVirtualSwitch; + private VirtualSwitchType getDefaultVirtualSwitchTypeAtCloudLevel() { + if (useDVS) { + return (nexusDVS)? VirtualSwitchType.NexusDistributedVirtualSwitch:VirtualSwitchType.VMwareDistributedVirtualSwitch; + } + + return VirtualSwitchType.StandardVirtualSwitch; } @Override @@ -757,6 +791,14 @@ public ServerResource reloadResource(HostVO host) { } private void validateVswitchType(String inputVswitchType) { + if (inputVswitchType == null) { + return; + } + + if (inputVswitchType.isEmpty()) { + throw new InvalidParameterValueException("Switch type shouldn't be empty"); + } + VirtualSwitchType vSwitchType = VirtualSwitchType.getType(inputVswitchType); if (vSwitchType == VirtualSwitchType.None) { s_logger.error("Unable to resolve " + inputVswitchType + " to a valid virtual switch type in VMware environment."); @@ -764,6 +806,21 @@ private void validateVswitchType(String inputVswitchType) { } } + private void validateVswitchNameAtCluster(String inputVswitchName) { + if (inputVswitchName == null) { + return; + } + + if (inputVswitchName.isEmpty()) { + throw new InvalidParameterValueException("Switch name shouldn't be empty"); + } + + String[] tokens = inputVswitchName.split(","); + if (tokens.length > MAX_FIELDS_VMWARE_LABEL_AT_CLUSTER) { + throw new InvalidParameterValueException("Found extraneous fields in vmware traffic label at cluster: " + inputVswitchName); + } + } + @Override public void putParam(Map params) { if (_urlParams == null) { @@ -781,4 +838,27 @@ public void setNetworkElements(List networkElements) { this.networkElements = networkElements; } + private Map getTrafficInfoForCluster(long clusterId, TrafficType trafficType) { + Map trafficInfo = _clusterPhysicalNetworkTrafficInfoDao.getTrafficInfo(clusterId); + if(trafficInfo == null || trafficInfo.size() == 0) { + return null; + } + + Map actualtrafficInfo = new HashMap(); + for (Map.Entry trafficDetail : trafficInfo.entrySet()) { + if(_physicalNetworkTrafficTypeDao.getTrafficType(trafficDetail.getKey().longValue()) == trafficType) { + actualtrafficInfo.put(trafficDetail.getKey(), trafficDetail.getValue()); + } + } + + return actualtrafficInfo; + } + + private Map getGuestTrafficInfoForCluster(long clusterId) { + return getTrafficInfoForCluster(clusterId, TrafficType.Guest); + } + + private Map getPublicTrafficInfoForCluster(long clusterId) { + return getTrafficInfoForCluster(clusterId, TrafficType.Public); + } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index da97cdd04a7b..9a520d377234 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -301,8 +301,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa protected String _vCenterAddress; protected String _privateNetworkVSwitchName; - protected VmwareTrafficLabel _guestTrafficInfo = new VmwareTrafficLabel(TrafficType.Guest); - protected VmwareTrafficLabel _publicTrafficInfo = new VmwareTrafficLabel(TrafficType.Public); + protected Map _guestTrafficInfo = new HashMap(); + protected Map _publicTrafficInfo = new HashMap(); + protected VmwareTrafficLabel _publicTrafficLabel = null; protected Map _vsmCredentials = null; protected int _portsPerDvPortGroup; protected boolean _fullCloneFlag = false; @@ -1028,9 +1029,11 @@ private UnPlugNicAnswer execute(UnPlugNicCommand cmd) { private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final String vifMacAddress) throws Exception { // TODO : probably need to set traffic shaping Pair networkInfo = null; + String vSwitchName = null; //TODO-Suresh - Zone level VirtualSwitchType vSwitchType = VirtualSwitchType.StandardVirtualSwitch; - if (_publicTrafficInfo != null) { - vSwitchType = _publicTrafficInfo.getVirtualSwitchType(); + if (_publicTrafficLabel != null) { + vSwitchName = _publicTrafficLabel.getVirtualSwitchName(); + vSwitchType = _publicTrafficLabel.getVirtualSwitchType(); } /** FIXME We have no clue which network this nic is on and that means that we can't figure out the BroadcastDomainType * so we assume that it's VLAN for now @@ -1038,12 +1041,12 @@ private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final Str if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) { synchronized (vmMo.getRunningHost().getMor().getValue().intern()) { networkInfo = - HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, + HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.public", vmMo.getRunningHost(), vlanId, null, null, _opsTimeout, true, BroadcastDomainType.Vlan, null); } } else { networkInfo = - HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, null, + HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.public", vmMo.getRunningHost(), vlanId, null, null, null, _opsTimeout, vSwitchType, _portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, _vsmCredentials); } @@ -2534,7 +2537,17 @@ private Ternary getTargetSwitch(NicTO nicTo) throws Clou VirtualSwitchType switchType = VirtualSwitchType.StandardVirtualSwitch; String vlanId = Vlan.UNTAGGED; - if(nicTo.getName() != null && !nicTo.getName().isEmpty()) { + // Get switch type/name from resource property which is dictated by cluster property + // If a virtual switch type is specified while adding cluster that will be used. + // Else If virtual switch type/name is specified in physical traffic label that will be used + // Else use standard vSwitch + if (trafficType == TrafficType.Guest && _guestTrafficInfo != null && _guestTrafficInfo.containsKey(nicTo.getTrafficId())) { + switchType = _guestTrafficInfo.get(nicTo.getTrafficId()).getVirtualSwitchType(); + switchName = _guestTrafficInfo.get(nicTo.getTrafficId()).getVirtualSwitchName(); + } else if (trafficType == TrafficType.Public && _publicTrafficLabel != null) { + switchType = _publicTrafficLabel.getVirtualSwitchType(); + switchName = _publicTrafficLabel.getVirtualSwitchName(); + } else if (nicTo.getName() != null && !nicTo.getName().isEmpty()) { // Format of network traffic label is ,, // If all 3 fields are mentioned then number of tokens would be 3. // If only , are mentioned then number of tokens would be 2. @@ -2544,14 +2557,6 @@ private Ternary getTargetSwitch(NicTO nicTo) throws Clou switchName = mgmtTrafficLabelObj.getVirtualSwitchName(); vlanId = mgmtTrafficLabelObj.getVlanId(); switchType = mgmtTrafficLabelObj.getVirtualSwitchType(); - } else { - if (trafficType == TrafficType.Guest && _guestTrafficInfo != null) { - switchType = _guestTrafficInfo.getVirtualSwitchType(); - switchName = _guestTrafficInfo.getVirtualSwitchName(); - } else if (trafficType == TrafficType.Public && _publicTrafficInfo != null) { - switchType = _publicTrafficInfo.getVirtualSwitchType(); - switchName = _publicTrafficInfo.getVirtualSwitchName(); - } } if (switchName == null @@ -2586,6 +2591,24 @@ private String getNetworkNamePrefix(NicTO nicTo) throws Exception { } } + private boolean doesGuestTrafficContainsDistributedVirtualSwitch() { + return (doesGuestTrafficContainsVirtualSwitchType(VirtualSwitchType.VMwareDistributedVirtualSwitch) || doesGuestTrafficContainsVirtualSwitchType(VirtualSwitchType.NexusDistributedVirtualSwitch)); + } + + private boolean doesGuestTrafficContainsVirtualSwitchType(VirtualSwitchType virtualSwitchType) { + if (_guestTrafficInfo == null || _guestTrafficInfo.isEmpty()) { + return false; + } + + for (Map.Entry trafficInfo : _guestTrafficInfo.entrySet()) { + if (trafficInfo.getValue().getVirtualSwitchType() == virtualSwitchType) { + return true; + } + } + + return false; + } + private VirtualMachineMO takeVmFromOtherHyperHost(VmwareHypervisorHost hyperHost, String vmName) throws Exception { VirtualMachineMO vmMo = hyperHost.findVmOnPeerHyperHost(vmName); @@ -4027,18 +4050,23 @@ protected Answer execute(UnregisterVMCommand cmd) { protected Answer execute(UnregisterNicCommand cmd) { s_logger.info("Executing resource UnregisterNicCommand: " + _gson.toJson(cmd)); - if (_guestTrafficInfo == null) { + if (cmd.getTrafficId() == 0) { + return new Answer(cmd, false, "No Guest Traffic Id in cmd, unable to determine where to clean up"); + } + + if (_guestTrafficInfo == null || _guestTrafficInfo.isEmpty() || !_guestTrafficInfo.containsKey(cmd.getTrafficId())) { return new Answer(cmd, false, "No Guest Traffic Info found, unable to determine where to clean up"); } try { - if (_guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) { + if (_guestTrafficInfo.get(cmd.getTrafficId()).getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) { // For now we only need to cleanup the nvp specific portgroups // on the standard switches return new Answer(cmd, true, "Nothing to do"); } - s_logger.debug("Cleaning up portgroup " + cmd.getNicUuid() + " on switch " + _guestTrafficInfo.getVirtualSwitchName()); + s_logger.debug("Cleaning up portgroup " + cmd.getNicUuid() + " of traffic id: " + cmd.getTrafficId() + " on switch type: " + + _guestTrafficInfo.get(cmd.getTrafficId()).getVirtualSwitchType() + " and name: " + _guestTrafficInfo.get(cmd.getTrafficId()).getVirtualSwitchName()); VmwareContext context = getServiceContext(); VmwareHypervisorHost host = getHyperHost(context); ManagedObjectReference clusterMO = host.getHyperHostCluster(); @@ -4920,8 +4948,10 @@ public boolean configure(String name, Map params) throws Configu _morHyperHost.setType(hostTokens[0]); _morHyperHost.setValue(hostTokens[1]); - _guestTrafficInfo = (VmwareTrafficLabel)params.get("guestTrafficInfo"); - _publicTrafficInfo = (VmwareTrafficLabel)params.get("publicTrafficInfo"); + _guestTrafficInfo = (Map)params.get("guestTrafficInfo"); // Map of Physical Network Traffic Id and VMware Traffic Label for Guest Traffic + _publicTrafficInfo = (Map)params.get("publicTrafficInfo"); // Map of Physical Network Traffic Id and VMware Traffic Label for Public Traffic (only one item in the list as Public network would be on single physical network) + _publicTrafficLabel = (_publicTrafficInfo != null) ? (VmwareTrafficLabel)_publicTrafficInfo.values().toArray()[0] : new VmwareTrafficLabel(TrafficType.Public); // Public network would be on single physical network hence getting first object of the list would suffice. + VmwareContext context = getServiceContext(); VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); if (mgr == null) { @@ -4931,8 +4961,8 @@ public boolean configure(String name, Map params) throws Configu CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(context, context.getServiceContent().getCustomFieldsManager()); cfmMo.ensureCustomFieldDef("Datastore", CustomFieldConstants.CLOUD_UUID); - if (_publicTrafficInfo != null && _publicTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch || _guestTrafficInfo != null && - _guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) { + if (_publicTrafficLabel.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch || + doesGuestTrafficContainsDistributedVirtualSwitch()) { cfmMo.ensureCustomFieldDef("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP); } cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC); @@ -4945,8 +4975,8 @@ public boolean configure(String name, Map params) throws Configu VmwareHypervisorHost hostMo = this.getHyperHost(context); _hostName = hostMo.getHyperHostName(); - if (_guestTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch || - _publicTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) { + if (doesGuestTrafficContainsVirtualSwitchType(VirtualSwitchType.NexusDistributedVirtualSwitch) || + _publicTrafficLabel.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) { _privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware); _vsmCredentials = mgr.getNexusVSMCredentialsByClusterId(Long.parseLong(_cluster)); } @@ -4970,8 +5000,11 @@ public boolean configure(String name, Map params) throws Configu _portsPerDvPortGroup = intObj.intValue(); s_logger.info("VmwareResource network configuration info." + " private traffic over vSwitch: " + _privateNetworkVSwitchName + ", public traffic over " + - _publicTrafficInfo.getVirtualSwitchType() + " : " + _publicTrafficInfo.getVirtualSwitchName() + ", guest traffic over " + - _guestTrafficInfo.getVirtualSwitchType() + " : " + _guestTrafficInfo.getVirtualSwitchName()); + _publicTrafficLabel.getVirtualSwitchType() + " : " + _publicTrafficLabel.getVirtualSwitchName() + ", guest traffic over =>"); + + for (Map.Entry trafficInfo : _guestTrafficInfo.entrySet()) { + s_logger.info(trafficInfo.getValue().getVirtualSwitchType() + " : " + trafficInfo.getValue().getVirtualSwitchName()); + } Boolean boolObj = (Boolean)params.get("vmware.create.full.clone"); if (boolObj != null && boolObj.booleanValue()) { diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java index 88ab512dbe99..7f2476580383 100644 --- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java +++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java @@ -467,10 +467,11 @@ private void createApplyLoadBalancingRulesCommands(final List final Network guestNetwork = _ntwkModel.getNetwork(guestNetworkId); final Nic guestNic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), internalLbVm.getId()); + final long trafficId = _ntwkModel.getPhysicalNetworkTrafficId(guestNetwork.getPhysicalNetworkId(), guestNetwork.getTrafficType()); final NicProfile guestNicProfile = new NicProfile(guestNic, guestNetwork, guestNic.getBroadcastUri(), guestNic.getIsolationUri(), _ntwkModel.getNetworkRate(guestNetwork.getId(), internalLbVm.getId()), _ntwkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _ntwkModel.getNetworkTag(internalLbVm.getHypervisorType(), - guestNetwork)); + guestNetwork), trafficId); final NetworkOffering offering = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()); String maxconn = null; @@ -684,6 +685,7 @@ protected LinkedHashMap> createInternalLbVmN final String gatewayCidr = guestNetwork.getCidr(); guestNic.setIPv4Netmask(NetUtils.getCidrNetmask(gatewayCidr)); guestNic.setDefaultNic(true); + guestNic.setTrafficId(_ntwkModel.getPhysicalNetworkTrafficId(guestNetwork.getPhysicalNetworkId(), guestNetwork.getTrafficType())); networks.put(guestNetwork, new ArrayList(Arrays.asList(guestNic))); } diff --git a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java index bb1b6f9b3de6..61dd7b887006 100644 --- a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java +++ b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java @@ -155,6 +155,7 @@ public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfil } nic.setBroadcastUri(generateBroadcastUri(network)); + nic.setTrafficId(_networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType())); return nic; } diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java index fb14dc4408a3..1ee1b5e4fd65 100644 --- a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java @@ -84,6 +84,7 @@ public NicTO toNicTO(NicProfile profile) { NicTO to = new NicTO(); to.setDeviceId(profile.getDeviceId()); to.setBroadcastType(profile.getBroadcastType()); + to.setTrafficId(profile.getTrafficId()); to.setType(profile.getTrafficType()); to.setIp(profile.getIPv4Address()); to.setNetmask(profile.getIPv4Netmask()); diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java index 154e666c7a3f..ded2ac7edbb2 100644 --- a/server/src/com/cloud/network/NetworkModelImpl.java +++ b/server/src/com/cloud/network/NetworkModelImpl.java @@ -115,6 +115,7 @@ import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; +import com.cloud.utils.Pair; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; @@ -1164,6 +1165,15 @@ public long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficTy } } + @Override + public long getPhysicalNetworkTrafficId(Long networkId, TrafficType trafficType) { + if(networkId == null) { + return 0; + } + + return _pNTrafficTypeDao.getPhysicalNetworkTrafficId(networkId.longValue(), trafficType); + } + @Override public List listNetworkOfferingsForUpgrade(long networkId) { List offeringsToReturn = new ArrayList(); @@ -1631,34 +1641,45 @@ public void checkNetworkPermissions(Account owner, Network network) { } @Override - public String getDefaultPublicTrafficLabel(long dcId, HypervisorType hypervisorType) { + public Map getPublicTrafficInfo(long dcId, HypervisorType vmware) + { + Map publicTrafficInfo = null; try { - PhysicalNetwork publicPhyNetwork = getOnePhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Public); - PhysicalNetworkTrafficTypeVO publicTraffic = _pNTrafficTypeDao.findBy(publicPhyNetwork.getId(), TrafficType.Public); - if (publicTraffic != null) { - String label = null; - switch (hypervisorType) { - case XenServer: - label = publicTraffic.getXenNetworkLabel(); - break; - case KVM: - label = publicTraffic.getKvmNetworkLabel(); - break; - case VMware: - label = publicTraffic.getVmwareNetworkLabel(); - break; - case Hyperv: - label = publicTraffic.getHypervNetworkLabel(); - break; - case Ovm3: - label = publicTraffic.getOvm3NetworkLabel(); - break; - } - return label; + publicTrafficInfo = getTrafficInfo(dcId, TrafficType.Public, vmware); + + return publicTrafficInfo; + } catch (Exception ex) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Failed to get the public traffic info in zone due to: " + ex.getMessage()); } + } + return publicTrafficInfo; + } + + @Override + public Map getGuestTrafficInfo(long dcId, HypervisorType vmware) + { + Map guestTrafficInfo = null; + try { + guestTrafficInfo = getTrafficInfo(dcId, TrafficType.Guest, vmware); + + return guestTrafficInfo; + } catch (Exception ex) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Failed to get the guest traffic info in zone due to: " + ex.getMessage()); + } + } + return guestTrafficInfo; + } + + @Override + public Pair getDefaultPublicTrafficInfo(long dcId, HypervisorType hypervisorType) { + try { + PhysicalNetwork publicPhyNetwork = getFirstPhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Public); + return getPhysicalNetworkTrafficInfo(publicPhyNetwork, TrafficType.Public, hypervisorType); } catch (Exception ex) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to retrieve the default label for public traffic." + "zone: " + dcId + " hypervisor: " + hypervisorType + " due to: " + + s_logger.debug("Failed to retrieve the default label for public traffic in zone: " + dcId + " for hypervisor: " + hypervisorType + " due to: " + ex.getMessage()); } } @@ -1666,37 +1687,96 @@ public String getDefaultPublicTrafficLabel(long dcId, HypervisorType hypervisorT } @Override - public String getDefaultGuestTrafficLabel(long dcId, HypervisorType hypervisorType) { + public Pair getDefaultGuestTrafficInfo(long dcId, HypervisorType hypervisorType) { try { - PhysicalNetwork guestPhyNetwork = getOnePhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Guest); - PhysicalNetworkTrafficTypeVO guestTraffic = _pNTrafficTypeDao.findBy(guestPhyNetwork.getId(), TrafficType.Guest); - if (guestTraffic != null) { - String label = null; - switch (hypervisorType) { - case XenServer: - label = guestTraffic.getXenNetworkLabel(); - break; - case KVM: - label = guestTraffic.getKvmNetworkLabel(); - break; - case VMware: - label = guestTraffic.getVmwareNetworkLabel(); - break; - case Hyperv: - label = guestTraffic.getHypervNetworkLabel(); - break; - case Ovm3: - label = guestTraffic.getOvm3NetworkLabel(); - break; + PhysicalNetwork guestPhyNetwork = getFirstPhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Guest); + return getPhysicalNetworkTrafficInfo(guestPhyNetwork, TrafficType.Guest, hypervisorType); + } catch (Exception ex) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Failed to retrive the default label for guest traffic in zone: " + dcId + " for hypervisor: " + hypervisorType + " due to: " + + ex.getMessage()); + } + } + return null; + } + + @Override + public String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware) { + Pair publicTrafficInfo = getDefaultPublicTrafficInfo(dcId, vmware); + if(publicTrafficInfo == null) { + return null; + } + + return publicTrafficInfo.second(); + } + + @Override + public String getDefaultGuestTrafficLabel(long dcId, HypervisorType vmware) { + Pair guestTrafficInfo = getDefaultGuestTrafficInfo(dcId, vmware); + if(guestTrafficInfo == null) { + return null; + } + + return guestTrafficInfo.second(); + } + + private Map getTrafficInfo(long dcId, TrafficType trafficType, HypervisorType hypervisor) + { + Map trafficInfo = null; + try { + trafficInfo = new HashMap(); + List phyNetworks = getPhysicalNetworksByZoneAndTrafficType(dcId, trafficType); + for (PhysicalNetwork phyNetwork : phyNetworks) { + Pair phyNetworkTrafficInfo = getPhysicalNetworkTrafficInfo(phyNetwork, trafficType, hypervisor); + if(phyNetworkTrafficInfo == null) { + continue; } - return label; + + trafficInfo.put(phyNetworkTrafficInfo.first(), phyNetworkTrafficInfo.second()); } + + return trafficInfo; } catch (Exception ex) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to retrive the default label for management traffic:" + "zone: " + dcId + " hypervisor: " + hypervisorType + " due to:" + + s_logger.debug("Failed to retrieve " + trafficType + " traffic info in zone: " + dcId + " for hypervisor: " + hypervisor + " due to: " + ex.getMessage()); } } + return trafficInfo; + } + + private Pair getPhysicalNetworkTrafficInfo(PhysicalNetwork physicalNetwork, TrafficType trafficType, HypervisorType hypervisor) { + if(physicalNetwork == null) { + return null; + } + + try { + PhysicalNetworkTrafficTypeVO physicalNetworkTrafficType = _pNTrafficTypeDao.findBy(physicalNetwork.getId(), trafficType); + if (physicalNetworkTrafficType == null) { + return null; + } + + switch (hypervisor) { + case XenServer: + return new Pair(physicalNetworkTrafficType.getId(), physicalNetworkTrafficType.getXenNetworkLabel()); + case KVM: + return new Pair(physicalNetworkTrafficType.getId(), physicalNetworkTrafficType.getKvmNetworkLabel()); + case VMware: + return new Pair(physicalNetworkTrafficType.getId(), physicalNetworkTrafficType.getVmwareNetworkLabel()); + case Hyperv: + return new Pair(physicalNetworkTrafficType.getId(), physicalNetworkTrafficType.getHypervNetworkLabel()); + case Ovm3: + return new Pair(physicalNetworkTrafficType.getId(), physicalNetworkTrafficType.getOvm3NetworkLabel()); + default: + return null; + } + } catch (Exception ex) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Failed to retrive the label for traffic type:" + trafficType + " and hypervisor: " + hypervisor + " in physical network: " + + physicalNetwork.getName() + " due to:" + ex.getMessage()); + } + } + return null; } @@ -1882,10 +1962,10 @@ String getZoneNetworkDomain(long zoneId) { return _dcDao.findById(zoneId).getDomain(); } - PhysicalNetwork getOnePhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType) { + PhysicalNetwork getFirstPhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType) { List networkList = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, trafficType); - if (networkList.isEmpty()) { + if (networkList == null || networkList.isEmpty()) { throw new InvalidParameterValueException("Unable to find the default physical network with traffic=" + trafficType + " in zone id=" + zoneId + ". "); } @@ -1896,6 +1976,16 @@ PhysicalNetwork getOnePhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficTy return networkList.get(0); } + List getPhysicalNetworksByZoneAndTrafficType(long zoneId, TrafficType trafficType) { + List networkList = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, trafficType); + + if (networkList == null || networkList.isEmpty()) { + throw new InvalidParameterValueException("Unable to find the default physical network with traffic=" + trafficType + " in zone id=" + zoneId + ". "); + } + + return networkList; + } + protected Long getNonGuestNetworkPhysicalNetworkId(Network network, TrafficType trafficType) { // VMware control network is management network // we need to retrieve traffic label information through physical network @@ -1966,9 +2056,10 @@ public NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadc Integer networkRate = getNetworkRate(network.getId(), vm.getId()); // NetworkGuru guru = _networkGurus.get(network.getGuruName()); + final long trafficId = getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag( - vm.getHypervisorType(), network)); + vm.getHypervisorType(), network), trafficId); // guru.updateNicProfile(profile, network); return profile; } diff --git a/server/src/com/cloud/network/router/CommandSetupHelper.java b/server/src/com/cloud/network/router/CommandSetupHelper.java index f701218f2ac2..d12b204da23c 100644 --- a/server/src/com/cloud/network/router/CommandSetupHelper.java +++ b/server/src/com/cloud/network/router/CommandSetupHelper.java @@ -323,8 +323,9 @@ public void createApplyLoadBalancingRulesCommands(final List final Network guestNetwork = _networkModel.getNetwork(guestNetworkId); final Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), router.getId()); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(guestNetwork.getPhysicalNetworkId(), guestNetwork.getTrafficType()); final NicProfile nicProfile = new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(guestNetwork.getId(), - router.getId()), _networkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork)); + router.getId()), _networkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork), trafficId); final NetworkOffering offering = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()); String maxconn = null; if (offering.getConcurrentConnections() == null) { diff --git a/server/src/com/cloud/network/router/NicProfileHelperImpl.java b/server/src/com/cloud/network/router/NicProfileHelperImpl.java index 09e52119dc4a..9e4994cf927b 100644 --- a/server/src/com/cloud/network/router/NicProfileHelperImpl.java +++ b/server/src/com/cloud/network/router/NicProfileHelperImpl.java @@ -67,13 +67,14 @@ public NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGate final Nic privateNic = _nicDao.findByIp4AddressAndNetworkId(ipVO.getIpAddress(), privateNetwork.getId()); NicProfile privateNicProfile = new NicProfile(); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(privateNetwork.getPhysicalNetworkId(), privateNetwork.getTrafficType()); if (privateNic != null) { final VirtualMachine vm = _vmDao.findById(privateNic.getInstanceId()); privateNicProfile = new NicProfile(privateNic, privateNetwork, privateNic.getBroadcastUri(), privateNic.getIsolationUri(), _networkModel.getNetworkRate( privateNetwork.getId(), vm.getId()), _networkModel.isSecurityGroupSupportedInNetwork(privateNetwork), _networkModel.getNetworkTag( - vm.getHypervisorType(), privateNetwork)); + vm.getHypervisorType(), privateNetwork), trafficId); } else { final String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr()); final PrivateIpAddress ip = @@ -92,6 +93,7 @@ public NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGate privateNicProfile.setFormat(AddressFormat.Ip4); privateNicProfile.setReservationId(String.valueOf(ip.getBroadcastUri())); privateNicProfile.setMacAddress(ip.getMacAddress()); + privateNicProfile.setTrafficId(trafficId); } return privateNicProfile; @@ -113,6 +115,7 @@ public NicProfile createGuestNicProfileForVpcRouter(final RouterDeploymentDefini guestNic.setMode(guestNetwork.getMode()); final String gatewayCidr = guestNetwork.getCidr(); guestNic.setIPv4Netmask(NetUtils.getCidrNetmask(gatewayCidr)); + guestNic.setTrafficId(_networkModel.getPhysicalNetworkTrafficId(guestNetwork.getPhysicalNetworkId(), guestNetwork.getTrafficType())); return guestNic; } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index c32aeba1a35a..dad1a0c30805 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -2097,7 +2097,8 @@ public boolean finalizeStart(final VirtualMachineProfile profile, final long hos if (network.getTrafficType() == TrafficType.Guest) { guestNetworks.add(network); if (nic.getBroadcastUri().getScheme().equals("pvlan")) { - final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic"); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); + final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic", trafficId); final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO); try { @@ -2130,7 +2131,8 @@ public void finalizeStop(final VirtualMachineProfile profile, final Answer answe final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId()); if (network.getTrafficType() == TrafficType.Guest && nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) { - final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic"); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); + final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic", trafficId); final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO); try { diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index b450e31f83a8..06bfe0554ddd 100644 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -20,6 +20,7 @@ import java.net.URISyntaxException; import java.net.URLDecoder; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -76,6 +77,7 @@ import com.cloud.configuration.ConfigurationManager; import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterDetailsVO; +import com.cloud.dc.ClusterPhysicalNetworkTrafficInfoDao; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenterIpAddressVO; @@ -122,6 +124,11 @@ import com.cloud.hypervisor.kvm.discoverer.KvmDummyResourceBase; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressVO; +import com.cloud.network.dao.PhysicalNetworkDao; +import com.cloud.network.dao.PhysicalNetworkVO; +import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao; +import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO; +import com.cloud.network.Networks; import com.cloud.org.Cluster; import com.cloud.org.Grouping; import com.cloud.org.Managed; @@ -191,6 +198,8 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, @Inject private ClusterDetailsDao _clusterDetailsDao; @Inject + private ClusterPhysicalNetworkTrafficInfoDao _clusterPhysicalNetworkTrafficInfoDao; + @Inject private ClusterDao _clusterDao; @Inject private CapacityDao _capacityDao; @@ -215,6 +224,10 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, @Inject private IPAddressDao _publicIPAddressDao; @Inject + private PhysicalNetworkDao _physicalNetworkDao; + @Inject + private PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao; + @Inject private VirtualMachineManager _vmMgr; @Inject private VMInstanceDao _vmDao; @@ -431,6 +444,15 @@ public List discoverCluster(final AddClusterCmd cmd) throws I } } + if ((cmd.getVSwitchTypeGuestTraffic() != null || cmd.getVSwitchTypePublicTraffic() != null || cmd.getVSwitchNameGuestTraffic() != null || cmd.getVSwitchNamePublicTraffic() != null) + && hypervisorType != HypervisorType.VMware) { + throw new InvalidParameterValueException("vSwitch details not are supported for hypervisor type " + hypervisorType); + } + + if (cmd.getPhysicalNetworkTrafficLabels() != null && hypervisorType != HypervisorType.VMware) { + throw new InvalidParameterValueException("Physical network traffic labels not are supported for hypervisor type " + hypervisorType); + } + Cluster.ClusterType clusterType = null; if (cmd.getClusterType() != null && !cmd.getClusterType().isEmpty()) { clusterType = Cluster.ClusterType.valueOf(cmd.getClusterType()); @@ -505,6 +527,14 @@ public List discoverCluster(final AddClusterCmd cmd) throws I details.put("memoryOvercommitRatio", CapacityManager.MemOverprovisioningFactor.value().toString()); _clusterDetailsDao.persist(cluster.getId(), details); + // save cluster physical network traffic labels + if (cmd.getPhysicalNetworkTrafficLabels() != null && !cmd.getPhysicalNetworkTrafficLabels().isEmpty()) { + final Map physicalNetworkTrafficLabels = getPhysicalNetworkTrafficLabels(cmd.getPhysicalNetworkTrafficLabels(), dcId); + if(physicalNetworkTrafficLabels != null) { + _clusterPhysicalNetworkTrafficInfoDao.persist(cluster.getId(), physicalNetworkTrafficLabels); + } + } + boolean success = false; try { try { @@ -543,12 +573,51 @@ public List discoverCluster(final AddClusterCmd cmd) throws I throw new DiscoveryException("Unable to add the external cluster"); } finally { if (!success) { + _clusterPhysicalNetworkTrafficInfoDao.deleteDetails(cluster.getId()); _clusterDetailsDao.deleteDetails(cluster.getId()); _clusterDao.remove(cluster.getId()); } } } + private Map getPhysicalNetworkTrafficLabels(Map physicalNetworkTrafficLabelsMap, long dcId) throws InvalidParameterValueException { + if(physicalNetworkTrafficLabelsMap == null || physicalNetworkTrafficLabelsMap.isEmpty()) { + return null; + } + + final Map physicalNetworkTrafficLabels = new HashMap(); + Collection physicalNetworkTrafficLabelsCollection = physicalNetworkTrafficLabelsMap.values(); + Iterator iter = physicalNetworkTrafficLabelsCollection.iterator(); + while (iter.hasNext()) { + HashMap trafficLabelMap = (HashMap)iter.next(); + String physicalNetworkTrafficUuid = trafficLabelMap.get("physicalnetworktrafficid"); + String networkLabel = trafficLabelMap.get("networklabel"); + + final PhysicalNetworkTrafficTypeVO physicalNetworkTrafficType = _physicalNetworkTrafficTypeDao.findByUuid(physicalNetworkTrafficUuid); + if (physicalNetworkTrafficType == null) { + throw new InvalidParameterValueException("Can't find physical network traffic id: " + physicalNetworkTrafficUuid + " in the zone of the cluster"); + } + + if (physicalNetworkTrafficType.getTrafficType() != Networks.TrafficType.Guest && physicalNetworkTrafficType.getTrafficType() != Networks.TrafficType.Public) { + throw new InvalidParameterValueException("Physical network traffic type not supported. Only guest and public are supported"); + } + + final PhysicalNetworkVO physicalNetworkVO = _physicalNetworkDao.findById(physicalNetworkTrafficType.getPhysicalNetworkId()); + if(physicalNetworkVO == null) { + throw new InvalidParameterValueException("No physical network exists for the traffic id: " + physicalNetworkTrafficUuid + " in the zone of the cluster"); + } + + if(physicalNetworkVO.getDataCenterId() != dcId) { + throw new InvalidParameterValueException("Can't find physical network for the traffic id: " + physicalNetworkTrafficUuid + " in the zone of the cluster"); + } + + Long physicalNetworkTrafficId = physicalNetworkTrafficType.getId(); + physicalNetworkTrafficLabels.put(physicalNetworkTrafficId, networkLabel); + } + + return physicalNetworkTrafficLabels; + } + @Override public Discoverer getMatchingDiscover(final Hypervisor.HypervisorType hypervisorType) { for (final Discoverer discoverer : _discoverers) { @@ -1002,7 +1071,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) { @Override @DB - public Cluster updateCluster(final Cluster clusterToUpdate, final String clusterType, final String hypervisor, final String allocationState, final String managedstate) { + public Cluster updateCluster(final Cluster clusterToUpdate, final String clusterType, final String hypervisor, final String allocationState, final String managedstate, Map physicalNetworkTrafficLabels) { final ClusterVO cluster = (ClusterVO)clusterToUpdate; // Verify cluster information and update the cluster if needed @@ -1010,7 +1079,7 @@ public Cluster updateCluster(final Cluster clusterToUpdate, final String cluster if (hypervisor != null && !hypervisor.isEmpty()) { final Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.getType(hypervisor); - if (hypervisorType == null) { + if (hypervisorType == HypervisorType.None) { s_logger.error("Unable to resolve " + hypervisor + " to a valid supported hypervisor type"); throw new InvalidParameterValueException("Unable to resolve " + hypervisor + " to a supported type"); } else { @@ -1035,6 +1104,10 @@ public Cluster updateCluster(final Cluster clusterToUpdate, final String cluster } } + if (physicalNetworkTrafficLabels != null && cluster.getHypervisorType() != HypervisorType.VMware) { + throw new InvalidParameterValueException("Physical network traffic labels not are supported for hypervisor type " + cluster.getHypervisorType()); + } + Grouping.AllocationState newAllocationState = null; if (allocationState != null && !allocationState.isEmpty()) { try { @@ -1067,6 +1140,13 @@ public Cluster updateCluster(final Cluster clusterToUpdate, final String cluster } } + if (physicalNetworkTrafficLabels != null && !physicalNetworkTrafficLabels.isEmpty()) { + final Map physicalNetworkTrafficLabelsInfo = getPhysicalNetworkTrafficLabels(physicalNetworkTrafficLabels, cluster.getDataCenterId()); + if(physicalNetworkTrafficLabelsInfo != null) { + _clusterPhysicalNetworkTrafficInfoDao.persist(cluster.getId(), physicalNetworkTrafficLabelsInfo); + } + } + if (doUpdate) { _clusterDao.update(cluster.getId(), cluster); } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 97eceaf4b43a..0d5448627875 100644 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -716,8 +716,9 @@ private boolean resetVMPasswordInternal(Long vmId, String password) throws Resou } Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId()); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(defaultNetwork.getPhysicalNetworkId(), defaultNetwork.getTrafficType()); NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork), - _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork)); + _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork), trafficId); VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance); vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password); @@ -823,8 +824,9 @@ private boolean resetVMSSHKeyInternal(Long vmId, String sshPublicKey, String pas } Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId()); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(defaultNetwork.getPhysicalNetworkId(), defaultNetwork.getTrafficType()); NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork), - _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork)); + _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork), trafficId); VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance); @@ -2354,8 +2356,9 @@ private boolean updateUserDataInternal(UserVm vm) throws ResourceUnavailableExce for (Nic nic : nics) { Network network = _networkDao.findById(nic.getNetworkId()); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile nicProfile = new NicProfile(nic, network, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag( - template.getHypervisorType(), network)); + template.getHypervisorType(), network), trafficId); VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm); @@ -3641,7 +3644,8 @@ public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Command // In vmware, we will be effecting pvlan settings in portgroups in StartCommand. if (profile.getHypervisorType() != HypervisorType.VMware) { if (nic.getBroadcastUri().getScheme().equals("pvlan")) { - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic"); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic", trafficId); if (!setupVmForPvlan(true, hostId, nicProfile)) { return false; } @@ -3747,7 +3751,8 @@ public void finalizeStop(VirtualMachineProfile profile, Answer answer) { NetworkVO network = _networkDao.findById(nic.getNetworkId()); if (network.getTrafficType() == TrafficType.Guest) { if (nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) { - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic"); + final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic", trafficId); setupVmForPvlan(false, vm.getHostId(), nicProfile); } } diff --git a/server/test/com/cloud/network/MockNetworkModelImpl.java b/server/test/com/cloud/network/MockNetworkModelImpl.java index 5c89a161bb71..fdf3a53ee715 100644 --- a/server/test/com/cloud/network/MockNetworkModelImpl.java +++ b/server/test/com/cloud/network/MockNetworkModelImpl.java @@ -44,6 +44,7 @@ import com.cloud.offerings.NetworkOfferingVO; import com.cloud.user.Account; import com.cloud.utils.component.ManagerBase; +import com.cloud.utils.Pair; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachine; @@ -538,6 +539,33 @@ public String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervis return null; } + /* (non-Javadoc) + * @see com.cloud.network.NetworkModel#getPublicTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) + */ + @Override + public Map getPublicTrafficInfo(long dcId, HypervisorType vmware) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkModel#getGuestTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) + */ + @Override + public Map getGuestTrafficInfo(long dcId, HypervisorType vmware) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkModel#getDefaultPublicTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) + */ + @Override + public Pair getDefaultPublicTrafficInfo(long dcId, HypervisorType vmware) { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getDefaultPublicTrafficLabel(long, com.cloud.hypervisor.Hypervisor.HypervisorType) */ @@ -547,6 +575,15 @@ public String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware) { return null; } + /* (non-Javadoc) + * @see com.cloud.network.NetworkModel#getDefaultGuestTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) + */ + @Override + public Pair getDefaultGuestTrafficInfo(long dcId, HypervisorType vmware) { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getDefaultGuestTrafficLabel(long, com.cloud.hypervisor.Hypervisor.HypervisorType) */ @@ -691,6 +728,15 @@ public long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficTy return 0; } + /* (non-Javadoc) + * @see com.cloud.network.NetworkModel#getPhysicalNetworkTrafficId(Long, java.lang.String, com.cloud.network.Networks.TrafficType) + */ + @Override + public long getPhysicalNetworkTrafficId(Long networkId, TrafficType trafficType) { + // TODO Auto-generated method stub + return 0; + } + /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getNetworkRate(long, java.lang.Long) */ diff --git a/server/test/com/cloud/resource/MockResourceManagerImpl.java b/server/test/com/cloud/resource/MockResourceManagerImpl.java index d4f2210417d2..57e15e270a46 100644 --- a/server/test/com/cloud/resource/MockResourceManagerImpl.java +++ b/server/test/com/cloud/resource/MockResourceManagerImpl.java @@ -109,7 +109,7 @@ public boolean deleteCluster(final DeleteClusterCmd cmd) { * @see com.cloud.resource.ResourceService#updateCluster(com.cloud.org.Cluster, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @Override - public Cluster updateCluster(final Cluster cluster, final String clusterType, final String hypervisor, final String allocationState, final String managedstate) { + public Cluster updateCluster(final Cluster cluster, final String clusterType, final String hypervisor, final String allocationState, final String managedstate, Map physicalNetworkTrafficLabels) { // TODO Auto-generated method stub return null; } diff --git a/server/test/com/cloud/vpc/MockNetworkModelImpl.java b/server/test/com/cloud/vpc/MockNetworkModelImpl.java index 8ed3b7c3db59..01cb5accc5c0 100644 --- a/server/test/com/cloud/vpc/MockNetworkModelImpl.java +++ b/server/test/com/cloud/vpc/MockNetworkModelImpl.java @@ -52,6 +52,7 @@ import com.cloud.offerings.dao.NetworkOfferingServiceMapDao; import com.cloud.user.Account; import com.cloud.utils.component.ManagerBase; +import com.cloud.utils.Pair; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachine; @@ -555,6 +556,33 @@ public String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervis return null; } + /* (non-Javadoc) + * @see com.cloud.network.NetworkModel#getPublicTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) + */ + @Override + public Map getPublicTrafficInfo(long dcId, HypervisorType vmware) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkModel#getGuestTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) + */ + @Override + public Map getGuestTrafficInfo(long dcId, HypervisorType vmware) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.cloud.network.NetworkModel#getDefaultPublicTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) + */ + @Override + public Pair getDefaultPublicTrafficInfo(long dcId, HypervisorType vmware) { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getDefaultPublicTrafficLabel(long, com.cloud.hypervisor.Hypervisor.HypervisorType) */ @@ -564,6 +592,15 @@ public String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware) { return null; } + /* (non-Javadoc) + * @see com.cloud.network.NetworkModel#getDefaultGuestTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) + */ + @Override + public Pair getDefaultGuestTrafficInfo(long dcId, HypervisorType vmware) { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getDefaultGuestTrafficLabel(long, com.cloud.hypervisor.Hypervisor.HypervisorType) */ @@ -707,6 +744,15 @@ public long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficTy return 0; } + /* (non-Javadoc) + * @see com.cloud.network.NetworkModel#getPhysicalNetworkTrafficId(Long, java.lang.String, com.cloud.network.Networks.TrafficType) + */ + @Override + public long getPhysicalNetworkTrafficId(Long networkId, TrafficType trafficType) { + // TODO Auto-generated method stub + return 0; + } + /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getNetworkRate(long, java.lang.Long) */ diff --git a/setup/db/db/schema-452to460.sql b/setup/db/db/schema-452to460.sql index 5887e5389041..98ba274eaab1 100644 --- a/setup/db/db/schema-452to460.sql +++ b/setup/db/db/schema-452to460.sql @@ -413,3 +413,17 @@ CREATE TABLE `cloud`.`ldap_trust_map` ( UNIQUE KEY `uk_ldap_trust_map__domain_id` (`domain_id`), CONSTRAINT `fk_ldap_trust_map__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +DROP TABLE IF EXISTS `cloud`.`cluster_physical_network_traffic_info`; +CREATE TABLE `cloud`.`cluster_physical_network_traffic_info` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `uuid` varchar(40), + `cluster_id` bigint unsigned NOT NULL COMMENT 'cluster id', + `physical_network_traffic_id` bigint unsigned NOT NULL COMMENT 'id of physical network traffic in the zone of the cluster', + `vmware_network_label` varchar(255) COMMENT 'network label of the physical device dedicated to this traffic on a VMware host at cluster level', + PRIMARY KEY (`id`), + CONSTRAINT `fk_cluster_physical_network_traffic_info__cluster_id` FOREIGN KEY (`cluster_id`) REFERENCES `cluster`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_cluster_physical_network_traffic_info__traffic_id` FOREIGN KEY (`physical_network_traffic_id`) REFERENCES `physical_network_traffic_types`(`id`) ON DELETE CASCADE, + CONSTRAINT `uc_cluster_physical_network_traffic_info__uuid` UNIQUE (`uuid`), + UNIQUE KEY (`cluster_id`, `physical_network_traffic_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; From 0d51865f0f7d679d068dd510e00e431ba02c36d8 Mon Sep 17 00:00:00 2001 From: Suresh Kumar Anaparti Date: Tue, 15 Dec 2015 17:18:31 +0530 Subject: [PATCH 2/3] Revert "CLOUDSTACK-7151: Support multiple physical networks at cluster level for guest traffic over VMware deployments." This reverts commit c22ce365936ac08e28527d9192277d8768ecabfa. --- api/src/com/cloud/agent/api/to/NetworkTO.java | 9 - api/src/com/cloud/network/NetworkModel.java | 12 - .../com/cloud/resource/ResourceService.java | 3 +- api/src/com/cloud/vm/NicProfile.java | 12 +- .../apache/cloudstack/api/ApiConstants.java | 1 - .../command/admin/cluster/AddClusterCmd.java | 17 +- .../admin/cluster/UpdateClusterCmd.java | 15 +- .../cloud/agent/api/UnregisterNicCommand.java | 8 +- .../cloud/vm/VirtualMachineManagerImpl.java | 11 +- .../orchestration/NetworkOrchestrator.java | 27 +- ...spring-engine-schema-core-daos-context.xml | 1 - .../ClusterPhysicalNetworkTrafficInfoDao.java | 35 -- ...sterPhysicalNetworkTrafficInfoDaoImpl.java | 132 ------- .../ClusterPhysicalNetworkTrafficInfoVO.java | 91 ----- .../dao/PhysicalNetworkTrafficTypeDao.java | 4 - .../PhysicalNetworkTrafficTypeDaoImpl.java | 24 +- .../cloud/upgrade/dao/Upgrade452to460.java | 76 +--- .../com/cloud/hypervisor/guru/VMwareGuru.java | 3 +- .../vmware/VmwareServerDiscoverer.java | 358 +++++++----------- .../vmware/resource/VmwareResource.java | 85 ++--- .../lb/InternalLoadBalancerVMManagerImpl.java | 4 +- .../guru/MidoNetPublicNetworkGuru.java | 1 - .../cloud/hypervisor/HypervisorGuruBase.java | 1 - .../com/cloud/network/NetworkModelImpl.java | 191 +++------- .../network/router/CommandSetupHelper.java | 3 +- .../network/router/NicProfileHelperImpl.java | 5 +- .../VirtualNetworkApplianceManagerImpl.java | 6 +- .../cloud/resource/ResourceManagerImpl.java | 84 +--- .../src/com/cloud/vm/UserVmManagerImpl.java | 15 +- .../cloud/network/MockNetworkModelImpl.java | 46 --- .../resource/MockResourceManagerImpl.java | 2 +- .../com/cloud/vpc/MockNetworkModelImpl.java | 46 --- setup/db/db/schema-452to460.sql | 14 - 33 files changed, 258 insertions(+), 1084 deletions(-) delete mode 100644 engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDao.java delete mode 100644 engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDaoImpl.java delete mode 100644 engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoVO.java diff --git a/api/src/com/cloud/agent/api/to/NetworkTO.java b/api/src/com/cloud/agent/api/to/NetworkTO.java index 0712a65121cb..be11deaa1ec8 100644 --- a/api/src/com/cloud/agent/api/to/NetworkTO.java +++ b/api/src/com/cloud/agent/api/to/NetworkTO.java @@ -33,7 +33,6 @@ public class NetworkTO { protected String dns1; protected String dns2; protected BroadcastDomainType broadcastType; - protected long trafficId; protected TrafficType type; protected URI broadcastUri; protected URI isolationUri; @@ -83,10 +82,6 @@ public void setDns2(String dns2) { this.dns2 = dns2; } - public void setTrafficId(long trafficId) { - this.trafficId = trafficId; - } - public void setType(TrafficType type) { this.type = type; } @@ -159,10 +154,6 @@ public String getDns2() { return dns2; } - public long getTrafficId() { - return trafficId; - } - public TrafficType getType() { return type; } diff --git a/api/src/com/cloud/network/NetworkModel.java b/api/src/com/cloud/network/NetworkModel.java index ae09045f46f4..780f97d22f4e 100644 --- a/api/src/com/cloud/network/NetworkModel.java +++ b/api/src/com/cloud/network/NetworkModel.java @@ -39,8 +39,6 @@ import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachine; -import com.cloud.utils.Pair; - /** * The NetworkModel presents a read-only view into the Network data such as L2 networks, * Nics, PublicIps, NetworkOfferings, traffic labels, physical networks and the like @@ -166,14 +164,6 @@ public interface NetworkModel { String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervisorType); - Map getPublicTrafficInfo(long dcId, HypervisorType vmware); - - Map getGuestTrafficInfo(long dcId, HypervisorType vmware); - - Pair getDefaultPublicTrafficInfo(long dcId, HypervisorType vmware); - - Pair getDefaultGuestTrafficInfo(long dcId, HypervisorType vmware); - String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware); String getDefaultGuestTrafficLabel(long dcId, HypervisorType vmware); @@ -236,8 +226,6 @@ public interface NetworkModel { long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficType); - long getPhysicalNetworkTrafficId(Long networkId, TrafficType trafficType); - Integer getNetworkRate(long networkId, Long vmId); boolean isVmPartOfNetwork(long vmId, long ntwkId); diff --git a/api/src/com/cloud/resource/ResourceService.java b/api/src/com/cloud/resource/ResourceService.java index d9fa9bda8b79..7461455aaeed 100644 --- a/api/src/com/cloud/resource/ResourceService.java +++ b/api/src/com/cloud/resource/ResourceService.java @@ -17,7 +17,6 @@ package com.cloud.resource; import java.util.List; -import java.util.Map; import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd; import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd; @@ -65,7 +64,7 @@ public interface ResourceService { boolean deleteCluster(DeleteClusterCmd cmd); - Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState, String managedstate, Map physicalNetworkTrafficLabels); + Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState, String managedstate); List discoverHosts(AddHostCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException; diff --git a/api/src/com/cloud/vm/NicProfile.java b/api/src/com/cloud/vm/NicProfile.java index 757a5c02e54f..58e05124c89f 100644 --- a/api/src/com/cloud/vm/NicProfile.java +++ b/api/src/com/cloud/vm/NicProfile.java @@ -33,7 +33,6 @@ public class NicProfile implements InternalIdentity, Serializable { long id; long networkId; - long trafficId; long vmId; String reservationId; Integer deviceId; @@ -76,10 +75,9 @@ public class NicProfile implements InternalIdentity, Serializable { public NicProfile() { } - public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled, String name, long trafficId) { + public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled, String name) { id = nic.getId(); networkId = network.getId(); - this.trafficId = trafficId; mode = network.getMode(); broadcastType = network.getBroadcastDomainType(); trafficType = network.getTrafficType(); @@ -146,14 +144,6 @@ public void setNetworId(long networkId){ this.networkId = networkId; } - public long getTrafficId() { - return trafficId; - } - - public void setTrafficId(long trafficId){ - this.trafficId = trafficId; - } - public long getVirtualMachineId() { return vmId; } diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java index e032af77fab7..2728bcc6fef9 100644 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -442,7 +442,6 @@ public class ApiConstants { public static final String VSWITCH_TYPE_PUBLIC_TRAFFIC = "publicvswitchtype"; public static final String VSWITCH_NAME_GUEST_TRAFFIC = "guestvswitchname"; public static final String VSWITCH_NAME_PUBLIC_TRAFFIC = "publicvswitchname"; - public static final String PHYSICAL_NETWORK_TRAFFIC_LABELS = "physicalnetworktrafficlabels"; // Ovs controller public static final String OVS_DEVICE_ID = "ovsdeviceid"; public static final String OVS_DEVICE_NAME = "ovsdevicename"; diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java index 3d41cbf813d2..3d0d71497403 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java @@ -19,16 +19,15 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.apache.log4j.Logger; + import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.BaseCmd.CommandType; import org.apache.cloudstack.api.response.ClusterResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.PodResponse; @@ -100,21 +99,15 @@ public class AddClusterCmd extends BaseCmd { @Parameter(name = ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC, type = CommandType.STRING, required = false, - description = "Name of virtual switch used for guest traffic in the cluster. This would override zone wide traffic label setting for first guest traffic in the physical networks defined.") + description = "Name of virtual switch used for guest traffic in the cluster. This would override zone wide traffic label setting.") private String vSwitchNameGuestTraffic; @Parameter(name = ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC, type = CommandType.STRING, required = false, - description = "Name of virtual switch used for public traffic in the cluster. This would override zone wide traffic label setting for first public traffic in the physical networks defined.") + description = "Name of virtual switch used for public traffic in the cluster. This would override zone wide traffic label setting.") private String vSwitchNamePublicTraffic; - @Parameter(name = ApiConstants.PHYSICAL_NETWORK_TRAFFIC_LABELS, - type = CommandType.MAP, - required = false, - description = "Map of physical network traffic id (of guest and public traffic in the zone) and vmware network label (vSwitch name) in the cluster. This would override zone wide traffic label setting for the specified guest and public traffic in the physical networks defined.") - private Map physicalNetworkTrafficLabels; - @Parameter(name = ApiConstants.OVM3_POOL, type = CommandType.STRING, required = false, description = "Ovm3 native pooling enabled for cluster") private String ovm3pool; @Parameter(name = ApiConstants.OVM3_CLUSTER, type = CommandType.STRING, required = false, description = "Ovm3 native OCFS2 clustering enabled for cluster") @@ -147,10 +140,6 @@ public String getVSwitchNamePublicTraffic() { return vSwitchNamePublicTraffic; } - public Map getPhysicalNetworkTrafficLabels() { - return physicalNetworkTrafficLabels; - } - public String getVSMIpaddress() { return vsmipaddress; } diff --git a/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java b/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java index cab40139b320..53d01c58a561 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java @@ -16,16 +16,14 @@ // under the License. package org.apache.cloudstack.api.command.admin.cluster; -import java.util.Map; - import org.apache.log4j.Logger; + import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.BaseCmd.CommandType; import org.apache.cloudstack.api.response.ClusterResponse; import com.cloud.exception.InvalidParameterValueException; @@ -35,7 +33,7 @@ @APICommand(name = "updateCluster", description = "Updates an existing cluster", responseObject = ClusterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateClusterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateClusterCmd.class.getName()); + public static final Logger s_logger = Logger.getLogger(AddClusterCmd.class.getName()); private static final String s_name = "updateclusterresponse"; @@ -57,9 +55,6 @@ public class UpdateClusterCmd extends BaseCmd { @Parameter(name = ApiConstants.MANAGED_STATE, type = CommandType.STRING, description = "whether this cluster is managed by cloudstack") private String managedState; - @Parameter(name = ApiConstants.PHYSICAL_NETWORK_TRAFFIC_LABELS, type = CommandType.MAP, description = "Map of physical network traffic id (of guest and public traffic in the zone) and vmware network label (vSwitch name) in the cluster.") - private Map physicalNetworkTrafficLabels; - public String getClusterName() { return clusterName; } @@ -106,17 +101,13 @@ public void setManagedstate(String managedstate) { this.managedState = managedstate; } - public Map getPhysicalNetworkTrafficLabels() { - return physicalNetworkTrafficLabels; - } - @Override public void execute() { Cluster cluster = _resourceService.getCluster(getId()); if (cluster == null) { throw new InvalidParameterValueException("Unable to find the cluster by id=" + getId()); } - Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate(), getPhysicalNetworkTrafficLabels()); + Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate()); if (result != null) { ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false); clusterResponse.setResponseName(getCommandName()); diff --git a/core/src/com/cloud/agent/api/UnregisterNicCommand.java b/core/src/com/cloud/agent/api/UnregisterNicCommand.java index 785c56615c41..f3c03832298c 100644 --- a/core/src/com/cloud/agent/api/UnregisterNicCommand.java +++ b/core/src/com/cloud/agent/api/UnregisterNicCommand.java @@ -31,13 +31,11 @@ public class UnregisterNicCommand extends Command { private String vmName; private String trafficLabel; private UUID nicUuid; - private long trafficId; - public UnregisterNicCommand(String vmName, String trafficLabel, UUID nicUuid, long trafficId) { + public UnregisterNicCommand(String vmName, String trafficLabel, UUID nicUuid) { this.nicUuid = nicUuid; this.vmName = vmName; this.trafficLabel = trafficLabel; - this.trafficId = trafficId; } public UUID getNicUuid() { @@ -52,10 +50,6 @@ public String getTrafficLabel() { return trafficLabel; } - public long getTrafficId() { - return trafficId; - } - @Override public boolean executeInSequence() { return false; diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index d955ee955ead..9dea90a41d15 100644 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -39,7 +39,6 @@ import javax.naming.ConfigurationException; import com.cloud.agent.api.AttachOrDettachConfigDriveCommand; - import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; @@ -2694,10 +2693,9 @@ private void ensureVmRunningContext(final long hostId, VMInstanceVO vm, final Ev final List nics = _nicsDao.listByVmId(profile.getId()); for (final NicVO nic : nics) { final Network network = _networkModel.getNetwork(nic.getNetworkId()); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.isSecurityGroupSupportedInNetwork(network), - _networkModel.getNetworkTag(profile.getHypervisorType(), network), trafficId); + _networkModel.getNetworkTag(profile.getHypervisorType(), network)); profile.addNic(nicProfile); } @@ -3105,10 +3103,10 @@ private boolean orchestrateRemoveNicFromVm(final VirtualMachine vm, final Nic ni final DeployDestination dest = new DeployDestination(dc, null, null, host); final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); final VirtualMachineTO vmTO = hvGuru.implement(vmProfile); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); + final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(network.getId(), vm.getId()), - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network), trafficId); + _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); //1) Unplug the nic if (vm.getState() == State.Running) { @@ -3196,10 +3194,9 @@ private boolean orchestrateRemoveVmFromNetwork(final VirtualMachine vm, final Ne } try { - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(network.getId(), vm.getId()), - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network), trafficId); + _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network)); //1) Unplug the nic if (vm.getState() == State.Running) { 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 4fdb1da75559..2a87bf5eb728 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java @@ -819,9 +819,8 @@ public Pair allocateNic(NicProfile requested, Network netwo vo = _nicDao.persist(vo); Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), - _networkModel.getNetworkTag(vm.getHypervisorType(), network), trafficId); + _networkModel.getNetworkTag(vm.getHypervisorType(), network)); return new Pair(vmNic, Integer.valueOf(deviceId)); } @@ -1328,9 +1327,10 @@ public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination } URI isolationUri = nic.getIsolationUri(); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); + profile = new NicProfile(nic, network, broadcastUri, isolationUri, - networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network), trafficId); + + networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); guru.reserve(profile, network, vmProfile, dest, context); nic.setIPv4Address(profile.getIPv4Address()); nic.setAddressFormat(profile.getFormat()); @@ -1349,9 +1349,8 @@ public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination updateNic(nic, network.getId(), 1); } else { - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), - _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network), trafficId); + _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); guru.updateNicProfile(profile, network); nic.setState(Nic.State.Reserved); updateNic(nic, network.getId(), 1); @@ -1392,9 +1391,8 @@ public void prepareNicForMigration(VirtualMachineProfile vm, DeployDestination d Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), - _networkModel.getNetworkTag(vm.getHypervisorType(), network), trafficId); + _networkModel.getNetworkTag(vm.getHypervisorType(), network)); if (guru instanceof NetworkMigrationResponder) { if (!((NetworkMigrationResponder)guru).prepareMigration(profile, network, vm, dest, context)) { s_logger.error("NetworkGuru " + guru + " prepareForMigration failed."); // XXX: Transaction error @@ -1437,9 +1435,8 @@ public void prepareAllNicsForMigration(VirtualMachineProfile vm, DeployDestinati Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network), trafficId); + _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network)); if(guru instanceof NetworkMigrationResponder){ if(!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)){ s_logger.error("NetworkGuru "+guru+" prepareForMigration failed."); // XXX: Transaction error @@ -1491,7 +1488,6 @@ public void prepareAllNicsForMigration(VirtualMachineProfile vm, DeployDestinati profile.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network)); profile.setName(_networkModel.getNetworkTag(vm.getHypervisorType(), network)); profile.setNetworId(network.getId()); - profile.setTrafficId(_networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType())); guru.updateNicProfile(profile, network); vm.addNic(profile); @@ -1601,9 +1597,8 @@ public Pair doInTransaction(TransactionStatus status) { NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); nic.setState(Nic.State.Releasing); _nicDao.update(nic.getId(), nic); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel - .isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network), trafficId); + .isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); if (guru.release(profile, vmProfile, nic.getReservationId())) { applyProfileToNicForRelease(nic, profile); nic.setState(Nic.State.Allocated); @@ -1686,9 +1681,8 @@ protected void removeNic(VirtualMachineProfile vm, NicVO nic) { nic.setState(Nic.State.Deallocating); _nicDao.update(nic.getId(), nic); NetworkVO network = _networksDao.findById(nic.getNetworkId()); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag( - vm.getHypervisorType(), network), trafficId); + vm.getHypervisorType(), network)); /* * We need to release the nics with a Create ReservationStrategy here @@ -3193,9 +3187,8 @@ public List getNicProfiles(VirtualMachine vm) { Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, - _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network), trafficId); + _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network)); guru.updateNicProfile(profile, network); profiles.add(profile); } diff --git a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml index 4b408ee389c7..13f35196a5aa 100644 --- a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml +++ b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml @@ -130,7 +130,6 @@ - diff --git a/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDao.java b/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDao.java deleted file mode 100644 index 93bb0d620d93..000000000000 --- a/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDao.java +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc; - -import java.util.Map; - -import com.cloud.utils.db.GenericDao; - -public interface ClusterPhysicalNetworkTrafficInfoDao extends GenericDao { - void persist(long clusterId, long physicalNetworkTrafficId, String vmwareNetworkLabel); - - void persist(long clusterId, Map physicalNetworkTrafficLabels); - - ClusterPhysicalNetworkTrafficInfoVO findDetail(long clusterId, long physicalNetworkTrafficId); - - String getVmwareNetworkLabel(long clusterId, long physicalNetworkTrafficId); - - Map getTrafficInfo(long clusterId); - - void deleteDetails(long clusterId); -} diff --git a/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDaoImpl.java b/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDaoImpl.java deleted file mode 100644 index f6e7ca22a7b9..000000000000 --- a/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoDaoImpl.java +++ /dev/null @@ -1,132 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc; - -import java.util.List; -import java.util.Map; -import java.util.HashMap; - -import javax.ejb.Local; - -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.SearchCriteria.Op; -import com.cloud.utils.db.TransactionLegacy; - -@Local(value = ClusterDetailsDao.class) -public class ClusterPhysicalNetworkTrafficInfoDaoImpl extends GenericDaoBase implements ClusterPhysicalNetworkTrafficInfoDao { - protected final SearchBuilder ClusterSearch; - protected final SearchBuilder clusterPhysicalNetworkTrafficSearch; - - protected ClusterPhysicalNetworkTrafficInfoDaoImpl() { - super(); - ClusterSearch = createSearchBuilder(); - ClusterSearch.and("clusterId", ClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ); - ClusterSearch.done(); - - clusterPhysicalNetworkTrafficSearch = createSearchBuilder(); - clusterPhysicalNetworkTrafficSearch.and("clusterId", clusterPhysicalNetworkTrafficSearch.entity().getClusterId(), SearchCriteria.Op.EQ); - clusterPhysicalNetworkTrafficSearch.and("physicalNetworkTrafficId", clusterPhysicalNetworkTrafficSearch.entity().getPhysicalNetworkTrafficId(), Op.EQ); - clusterPhysicalNetworkTrafficSearch.done(); - } - - @Override - public ClusterPhysicalNetworkTrafficInfoVO findDetail(long clusterId, long physicalNetworkTrafficId) { - SearchCriteria sc = clusterPhysicalNetworkTrafficSearch.create(); - sc.setParameters("clusterId", clusterId); - sc.setParameters("physicalNetworkTrafficId", physicalNetworkTrafficId); - - ClusterPhysicalNetworkTrafficInfoVO detail = findOneBy(sc); - return detail; - } - - @Override - public void persist(long clusterId, long physicalNetworkTrafficId, String vmwareNetworkLabel) { - TransactionLegacy txn = TransactionLegacy.currentTxn(); - txn.start(); - SearchCriteria sc = clusterPhysicalNetworkTrafficSearch.create(); - sc.setParameters("clusterId", clusterId); - sc.setParameters("physicalNetworkTrafficId", physicalNetworkTrafficId); - expunge(sc); - - ClusterPhysicalNetworkTrafficInfoVO vo = new ClusterPhysicalNetworkTrafficInfoVO(clusterId, physicalNetworkTrafficId, vmwareNetworkLabel); - persist(vo); - txn.commit(); - } - - @Override - public void persist(long clusterId, Map physicalNetworkTrafficLabels) { - if(physicalNetworkTrafficLabels == null || physicalNetworkTrafficLabels.isEmpty()) { - return; - } - - TransactionLegacy txn = TransactionLegacy.currentTxn(); - txn.start(); - SearchCriteria sc = ClusterSearch.create(); - sc.setParameters("clusterId", clusterId); - for (Map.Entry detail : physicalNetworkTrafficLabels.entrySet()) { - sc.setParameters("physicalNetworkTrafficId", detail.getKey()); - expunge(sc); - } - - for (Map.Entry detail : physicalNetworkTrafficLabels.entrySet()) { - ClusterPhysicalNetworkTrafficInfoVO vo = new ClusterPhysicalNetworkTrafficInfoVO(clusterId, detail.getKey(), detail.getValue()); - persist(vo); - } - txn.commit(); - } - - @Override - public String getVmwareNetworkLabel(long clusterId, long physicalNetworkTrafficId) { - ClusterPhysicalNetworkTrafficInfoVO trafficInfo = findDetail(clusterId, physicalNetworkTrafficId); - if (trafficInfo == null) { - return null; - } - - return trafficInfo.getVmwareNetworkLabel(); - } - - @Override - public Map getTrafficInfo(long clusterId) { - SearchCriteria sc = ClusterSearch.create(); - sc.setParameters("clusterId", clusterId); - List trafficInfoList= listBy(sc); - - if (trafficInfoList == null || trafficInfoList.size() == 0) { - return null; - } - - Map trafficInfoMap = new HashMap(); - for (ClusterPhysicalNetworkTrafficInfoVO trafficInfo : trafficInfoList) { - trafficInfoMap.put(new Long(trafficInfo.getPhysicalNetworkTrafficId()), trafficInfo.getVmwareNetworkLabel()); - } - - return trafficInfoMap; - } - - @Override - public void deleteDetails(long clusterId) { - SearchCriteria sc = ClusterSearch.create(); - sc.setParameters("clusterId", clusterId); - - List results = search(sc, null); - for (ClusterPhysicalNetworkTrafficInfoVO result : results) { - remove(result.getId()); - } - } -} diff --git a/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoVO.java b/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoVO.java deleted file mode 100644 index c77325e6ef0d..000000000000 --- a/engine/schema/src/com/cloud/dc/ClusterPhysicalNetworkTrafficInfoVO.java +++ /dev/null @@ -1,91 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.dc; - -import java.util.UUID; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.apache.cloudstack.api.Identity; -import org.apache.cloudstack.api.InternalIdentity; - -@Entity -@Table(name = "cluster_physical_network_traffic_info") -public class ClusterPhysicalNetworkTrafficInfoVO implements InternalIdentity, Identity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id") - private long id; - - @Column(name = "uuid") - private String uuid; - - @Column(name = "cluster_id") - private long clusterId; - - @Column(name = "physical_network_traffic_id") - private long physicalNetworkTrafficId; - - @Column(name = "vmware_network_label") - private String vmwareNetworkLabel; - - public ClusterPhysicalNetworkTrafficInfoVO() { - } - - public ClusterPhysicalNetworkTrafficInfoVO(long clusterId, long physicalNetworkTrafficId, String vmwareLabel) { - this.clusterId = clusterId; - this.physicalNetworkTrafficId = physicalNetworkTrafficId; - this.vmwareNetworkLabel = vmwareLabel; - this.uuid = UUID.randomUUID().toString(); - } - - @Override - public long getId() { - return id; - } - - public long getClusterId() { - return clusterId; - } - - public long getPhysicalNetworkTrafficId() { - return physicalNetworkTrafficId; - } - - public void setVmwareNetworkLabel(String vmwareNetworkLabel) { - this.vmwareNetworkLabel = vmwareNetworkLabel; - } - - public String getVmwareNetworkLabel() { - return vmwareNetworkLabel; - } - - @Override - public String getUuid() { - return this.uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } -} \ No newline at end of file diff --git a/engine/schema/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java index 125253cf9d83..5744a81e30d8 100644 --- a/engine/schema/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java +++ b/engine/schema/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java @@ -28,13 +28,9 @@ public interface PhysicalNetworkTrafficTypeDao extends GenericDao, Integer> listAndCountBy(long phy @Override public boolean isTrafficTypeSupported(long physicalNetworkId, TrafficType trafficType) { - if (findBy(physicalNetworkId, trafficType) != null) { + SearchCriteria sc = physicalNetworkSearch.create(); + sc.setParameters("physicalNetworkId", physicalNetworkId); + sc.setParameters("trafficType", trafficType); + if (findOneBy(sc) != null) { return true; } else { return false; } } - @Override - public long getPhysicalNetworkTrafficId(long physicalNetworkId, TrafficType trafficType) { - PhysicalNetworkTrafficTypeVO physicalNetworkTrafficType = findBy(physicalNetworkId, trafficType); - if(physicalNetworkTrafficType == null) { - return 0; - } - - return physicalNetworkTrafficType.getId(); - } - @Override public String getNetworkTag(long physicalNetworkId, TrafficType trafficType, HypervisorType hType) { SearchCriteria sc = null; @@ -166,13 +159,4 @@ public void deleteTrafficTypes(long physicalNetworkId) { sc.setParameters("physicalNetworkId", physicalNetworkId); remove(sc); } - - @Override - public TrafficType getTrafficType(long physicalNetworkTrafficId) { - PhysicalNetworkTrafficTypeVO PhysicalNetworkTrafficTypeVO = findById(physicalNetworkTrafficId); - if(PhysicalNetworkTrafficTypeVO == null) - return TrafficType.None; - - return PhysicalNetworkTrafficTypeVO.getTrafficType(); - } } diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java index 267f14c3a061..0ad26035ca7d 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java @@ -24,11 +24,9 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import org.apache.log4j.Logger; -import com.cloud.network.Networks.TrafficType; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.Script; @@ -62,10 +60,8 @@ public File[] getPrepareScripts() { @Override public void performDataMigration(final Connection conn) { - //updateVMInstanceUserId(conn); - //addIndexForVMInstance(conn); - updateClusterLevelPhysicalNetworkTrafficInfo(conn, TrafficType.Guest); - updateClusterLevelPhysicalNetworkTrafficInfo(conn, TrafficType.Public); + updateVMInstanceUserId(conn); + addIndexForVMInstance(conn); } public void updateVMInstanceUserId(final Connection conn) { @@ -159,74 +155,6 @@ private void addIndexForVMInstance(Connection conn) { } } - private void updateClusterLevelPhysicalNetworkTrafficInfo(Connection conn, TrafficType trafficType) { - if (conn == null) { - s_logger.debug("DB connection is null"); - return; - } - - if (trafficType != TrafficType.Guest && trafficType != TrafficType.Public) { - s_logger.debug("Cluster level physical network traffic info update is supported for guest and public traffic only"); - return; - } - - String phyNetworktrafficType = (trafficType == TrafficType.Guest) ? "Guest" : "Public"; - String vswitchParamName = (trafficType == TrafficType.Guest) ? "guestvswitchname" : "publicvswitchname"; - - String vswitchNameAtClusterDetailsSelectSql = "SELECT cluster_id, value FROM `cloud`.`cluster_details` where name = ?"; - String vswitchNameAtClusterDetailsDeleteSql = "DELETE FROM `cloud`.`cluster_details` where name = ?"; - String physicalNetworkTrafficIdSelectSql = "SELECT traffictype.id FROM `cloud`.`physical_network` as network, `cloud`.`physical_network_traffic_types` as traffictype where network.id=traffictype.physical_network_id and network.data_center_id=(SELECT data_center_id FROM `cloud`.`cluster` where id=?) and traffictype.traffic_type=?"; - String clusterPhysicalNwTrafficInsertSql = "INSERT INTO `cloud`.`cluster_physical_network_traffic_info` (uuid, cluster_id, physical_network_traffic_id, vmware_network_label) VALUES (?,?,?,?)"; - - s_logger.debug("Updating cluster level physical network traffic info for " + phyNetworktrafficType + " traffic"); - - try (PreparedStatement pstmtSelectVswitchNameAtClusterDetails = conn.prepareStatement(vswitchNameAtClusterDetailsSelectSql); - PreparedStatement pstmtDeleteVswitchNameAtClusterDetails = conn.prepareStatement(vswitchNameAtClusterDetailsDeleteSql);) { - pstmtSelectVswitchNameAtClusterDetails.setString(1, vswitchParamName); - ResultSet rsVswitchNameAtClusters = pstmtSelectVswitchNameAtClusterDetails.executeQuery(); - - // for each vswitch name at the cluster - while (rsVswitchNameAtClusters.next()) { - // get the cluster id - long clusterId = rsVswitchNameAtClusters.getLong(1); - // get vswitch name at cluster - String vswitchNameAtCluster = rsVswitchNameAtClusters.getString(2); - if (vswitchNameAtCluster == null || vswitchNameAtCluster.isEmpty()) { - continue; - } - - try (PreparedStatement pstmtSelectPhysicalNetworkTrafficId = conn.prepareStatement(physicalNetworkTrafficIdSelectSql); - PreparedStatement pstmtInsertClusterPhysicalNwTraffic = conn.prepareStatement(clusterPhysicalNwTrafficInsertSql);) { - pstmtSelectPhysicalNetworkTrafficId.setLong(1, clusterId); - pstmtSelectPhysicalNetworkTrafficId.setString(2, phyNetworktrafficType); - ResultSet rsPhysicalNetworkTrafficIds = pstmtSelectPhysicalNetworkTrafficId.executeQuery(); - - while (rsPhysicalNetworkTrafficIds.next()) { - long physicalNetworkTrafficId = rsPhysicalNetworkTrafficIds.getLong(1); - String uuid = UUID.randomUUID().toString(); - - pstmtInsertClusterPhysicalNwTraffic.setString(1, uuid); - pstmtInsertClusterPhysicalNwTraffic.setLong(2, clusterId); - pstmtInsertClusterPhysicalNwTraffic.setLong(3, physicalNetworkTrafficId); - pstmtInsertClusterPhysicalNwTraffic.setString(4, vswitchNameAtCluster); - - pstmtInsertClusterPhysicalNwTraffic.executeUpdate(); - break; // Perform only for first physical network traffic id - } - } catch (SQLException e) { - throw new CloudRuntimeException("Exception while adding cluster level traffic info for " + phyNetworktrafficType + " traffic", e); - } - } - - pstmtDeleteVswitchNameAtClusterDetails.setString(1, vswitchParamName); - pstmtDeleteVswitchNameAtClusterDetails.executeUpdate(); - } catch (SQLException e) { - throw new CloudRuntimeException("Exception while updating cluster level physical network traffic info for " + phyNetworktrafficType + " traffic", e); - } - - s_logger.debug("Updated cluster level physical network traffic info for " + phyNetworktrafficType + " traffic"); - } - @Override public File[] getCleanupScripts() { final String script = Script.findScript("", "db/schema-452to460-cleanup.sql"); diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java index bc6d905cbc84..62d82c24b2ee 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java @@ -505,9 +505,8 @@ public List finalizeExpungeNics(VirtualMachine vm, List nic // We need the traffic label to figure out which vSwitch has the // portgroup PhysicalNetworkTrafficTypeVO trafficTypeVO = _physicalNetworkTrafficTypeDao.findBy(networkVO.getPhysicalNetworkId(), networkVO.getTrafficType()); - long trafficId = _networkMgr.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); UnregisterNicCommand unregisterNicCommand = - new UnregisterNicCommand(vm.getInstanceName(), trafficTypeVO.getVmwareNetworkLabel(), UUID.fromString(nic.getUuid()), trafficId); + new UnregisterNicCommand(vm.getInstanceName(), trafficTypeVO.getVmwareNetworkLabel(), UUID.fromString(nic.getUuid())); commands.add(unregisterNicCommand); } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java index 1134ede4edbb..20eb6595f83a 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java @@ -40,7 +40,6 @@ import com.cloud.alert.AlertManager; import com.cloud.configuration.Config; import com.cloud.dc.ClusterDetailsDao; -import com.cloud.dc.ClusterPhysicalNetworkTrafficInfoDao; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenterVO; @@ -65,7 +64,6 @@ import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetwork; import com.cloud.network.VmwareTrafficLabel; -import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao; import com.cloud.network.dao.CiscoNexusVSMDeviceDao; import com.cloud.network.element.CiscoNexusVSMElement; import com.cloud.network.element.NetworkElement; @@ -85,7 +83,6 @@ @Local(value = Discoverer.class) public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter { private static final Logger s_logger = Logger.getLogger(VmwareServerDiscoverer.class); - private static final int MAX_FIELDS_VMWARE_LABEL_AT_CLUSTER = 1; @Inject VmwareManager _vmwareMgr; @@ -96,10 +93,6 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer @Inject ClusterDetailsDao _clusterDetailsDao; @Inject - ClusterPhysicalNetworkTrafficInfoDao _clusterPhysicalNetworkTrafficInfoDao; - @Inject - PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao; - @Inject CiscoNexusVSMDeviceDao _nexusDao; @Inject NetworkModel _netmgr; @@ -195,102 +188,64 @@ public VmwareServerDiscoverer() { } String privateTrafficLabel = null; - + String publicTrafficLabel = null; + String guestTrafficLabel = null; Map vsmCredentials = null; + VirtualSwitchType defaultVirtualSwitchType = VirtualSwitchType.StandardVirtualSwitch; + + String paramGuestVswitchType = null; + String paramGuestVswitchName = null; + String paramPublicVswitchType = null; + String paramPublicVswitchName = null; + + VmwareTrafficLabel guestTrafficLabelObj = new VmwareTrafficLabel(TrafficType.Guest); + VmwareTrafficLabel publicTrafficLabelObj = new VmwareTrafficLabel(TrafficType.Public); DataCenterVO zone = _dcDao.findById(dcId); NetworkType zoneType = zone.getNetworkType(); _readGlobalConfigParameters(); - // Zone level vSwitch type depends on zone level traffic labels + // Set default physical network end points for public and guest traffic + // Private traffic will be only on standard vSwitch for now. + if (useDVS) { + // Parse url parameters for type of vswitch and name of vswitch specified at cluster level + paramGuestVswitchType = _urlParams.get(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC); + paramGuestVswitchName = _urlParams.get(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC); + paramPublicVswitchType = _urlParams.get(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC); + paramPublicVswitchName = _urlParams.get(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC); + defaultVirtualSwitchType = getDefaultVirtualSwitchType(); + } + + // Zone level vSwitch Type depends on zone level traffic labels // - // User can override Zone wide vswitch type and name (for public and guest) by providing following optional parameters in addClusterCmd + // User can override Zone wide vswitch type (for public and guest) by providing following optional parameters in addClusterCmd // param "guestvswitchtype" with valid values vmwaredvs, vmwaresvs, nexusdvs // param "publicvswitchtype" with valid values vmwaredvs, vmwaresvs, nexusdvs - // param "guestvswitchname" with valid name for the vswitch type for the first guest traffic - // param "publicvswitchname" with valid name for the vswitch type for the first public traffic - // param "physicalnetworktrafficlabels" - Map of physical network traffic id (of guest and public traffic in the zone) and vmware network label(valid vswitch name) for the vswitch type - // param "physicalnetworktrafficlabels" would precede over the params "guestvswitchname" and "publicvswitchname" for the first guest and public traffic respectively // - // Format of zone level network label is ,, - // If a field OR is not present leave it empty. + // Format of label is ,, + // If a field OR is not present leave it empty. // Ex: 1) vswitch0 // 2) dvswitch0,200,vmwaredvs // 3) nexusepp0,300,nexusdvs // 4) vswitch1,400,vmwaresvs // 5) vswitch0 // default vswitchtype is 'vmwaresvs'. - // 'vmwaresvs' is for vmware standard vswitch - // 'vmwaredvs' is for vmware distributed virtual switch - // 'nexusdvs' is for cisco nexus distributed virtual switch - // - // Format of cluster level network label is - - // Parse url parameters for vswitch type and name specified at cluster level - String guestVswitchTypeAtClusterLevel = _urlParams.get(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC); - validateVswitchType(guestVswitchTypeAtClusterLevel); - clusterDetails.put(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC, guestVswitchTypeAtClusterLevel); - - String publicVswitchTypeAtClusterLevel = _urlParams.get(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC); - validateVswitchType(publicVswitchTypeAtClusterLevel); - clusterDetails.put(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC, publicVswitchTypeAtClusterLevel); - - // Save cluster level override configuration to cluster details - _clusterDetailsDao.persist(clusterId, clusterDetails); - - String guestVswitchNameAtClusterLevel = _urlParams.get(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC); - validateVswitchNameAtCluster(guestVswitchTypeAtClusterLevel); - - String publicVswitchNameAtClusterLevel = _urlParams.get(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC); - validateVswitchNameAtCluster(guestVswitchTypeAtClusterLevel); - - // Zone level traffic info with physical network traffic id and network label - Map guestTrafficInfoAtZoneLevel = _netmgr.getGuestTrafficInfo(dcId, HypervisorType.VMware); - Map publicTrafficInfoAtZoneLevel = _netmgr.getPublicTrafficInfo(dcId, HypervisorType.VMware); - - // Cluster level traffic info with physical network traffic id and network label (vswitch name) - Map guestTrafficInfoAtClusterLevel = getGuestTrafficInfoForCluster(clusterId); - Map publicTrafficInfoAtClusterLevel = getPublicTrafficInfoForCluster(clusterId); - - Map guestTrafficLabelInfo = null; - Map publicTrafficLabelInfo = null; - - // When "guestvswitchname" param is defined, add the vswitch name to the first guest traffic when the same is not defined in "physicalnetworktrafficlabels" param - if (guestVswitchNameAtClusterLevel != null) { - // Get zone wide traffic label for first guest traffic - Pair firstGuestTrafficInfoAtZone = _netmgr.getDefaultGuestTrafficInfo(dcId, HypervisorType.VMware); //Returns first guest traffic found in the physical networks on that zone - if (firstGuestTrafficInfoAtZone != null) { - s_logger.debug("Zone level first guest traffic id: " + firstGuestTrafficInfoAtZone.first() + " and label: " + firstGuestTrafficInfoAtZone.second()); - - long firstGuestPhysicalNetworkTrafficIdAtZoneLevel = firstGuestTrafficInfoAtZone.first(); - if (guestTrafficInfoAtClusterLevel == null || !guestTrafficInfoAtClusterLevel.containsKey(firstGuestPhysicalNetworkTrafficIdAtZoneLevel)) { - _clusterPhysicalNetworkTrafficInfoDao.persist(clusterId, firstGuestPhysicalNetworkTrafficIdAtZoneLevel, guestVswitchNameAtClusterLevel); - guestTrafficInfoAtClusterLevel = getGuestTrafficInfoForCluster(clusterId); // Update cluster level traffic info for guest traffic - } - } - } + // 'vmwaresvs' is for vmware standard vswitch + // 'vmwaredvs' is for vmware distributed virtual switch + // 'nexusdvs' is for cisco nexus distributed virtual switch + // Get zone wide traffic labels for Guest traffic and Public traffic + guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(dcId, HypervisorType.VMware); - // Process guest traffic label information provided at zone level and cluster level - guestTrafficLabelInfo = getTrafficInfo(TrafficType.Guest, guestTrafficInfoAtZoneLevel, guestTrafficInfoAtClusterLevel, guestVswitchTypeAtClusterLevel); + // Process traffic label information provided at zone level and cluster level + guestTrafficLabelObj = getTrafficInfo(TrafficType.Guest, guestTrafficLabel, defaultVirtualSwitchType, paramGuestVswitchType, paramGuestVswitchName, clusterId); if (zoneType == NetworkType.Advanced) { - // When "publicvswitchname" param is defined, add the vswitch name to the first public traffic when the same is not defined in "physicalnetworktrafficlabels" param - if (publicVswitchNameAtClusterLevel != null) { - // Get zone wide traffic label for first public traffic - Pair firstPublicTrafficInfoAtZone = _netmgr.getDefaultPublicTrafficInfo(dcId, HypervisorType.VMware); ////Returns first public traffic found in the physical networks on that zone - if (firstPublicTrafficInfoAtZone != null) { - s_logger.debug("Zone level first public traffic id: " + firstPublicTrafficInfoAtZone.first() + " and label: " + firstPublicTrafficInfoAtZone.second()); - - long firstPublicPhysicalNetworkTrafficIdAtZoneLevel = firstPublicTrafficInfoAtZone.first(); - if(publicTrafficInfoAtClusterLevel == null || !publicTrafficInfoAtClusterLevel.containsKey(firstPublicPhysicalNetworkTrafficIdAtZoneLevel)) { - _clusterPhysicalNetworkTrafficInfoDao.persist(clusterId, firstPublicPhysicalNetworkTrafficIdAtZoneLevel, publicVswitchNameAtClusterLevel); - publicTrafficInfoAtClusterLevel = getPublicTrafficInfoForCluster(clusterId); // Update cluster level traffic info for public traffic - } - } - } + // Get zone wide traffic label for Public traffic + publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(dcId, HypervisorType.VMware); - // Process public traffic label information provided at zone level and cloud level - publicTrafficLabelInfo = getTrafficInfo(TrafficType.Public, publicTrafficInfoAtZoneLevel, publicTrafficInfoAtClusterLevel, publicVswitchTypeAtClusterLevel); + // Process traffic label information provided at zone level and cluster level + publicTrafficLabelObj = + getTrafficInfo(TrafficType.Public, publicTrafficLabel, defaultVirtualSwitchType, paramPublicVswitchType, paramPublicVswitchName, clusterId); // Configuration Check: A physical network cannot be shared by different types of virtual switches. // @@ -308,12 +263,6 @@ public VmwareServerDiscoverer() { // Public network would be on single physical network hence getting first object of the list would suffice. PhysicalNetwork pNetworkPublic = pNetworkListPublicTraffic.get(0); if (pNetworkListGuestTraffic.contains(pNetworkPublic)) { - VmwareTrafficLabel publicTrafficLabelObj = (publicTrafficLabelInfo != null) ? (VmwareTrafficLabel)publicTrafficLabelInfo.values().toArray()[0] : null; - VirtualSwitchType publicTrafficVirtualSwitchType = (publicTrafficLabelObj != null) ? publicTrafficLabelObj.getVirtualSwitchType() : VirtualSwitchType.None; - - long guestTrafficId = _physicalNetworkTrafficTypeDao.getPhysicalNetworkTrafficId(pNetworkPublic.getId(), TrafficType.Guest); - VmwareTrafficLabel guestTrafficLabelObj = (guestTrafficLabelInfo != null) ? guestTrafficLabelInfo.get(guestTrafficId) : null; - VirtualSwitchType guestTrafficVirtualSwitchType = (guestTrafficLabelObj != null) ? guestTrafficLabelObj.getVirtualSwitchType() : VirtualSwitchType.None; if (publicTrafficLabelObj.getVirtualSwitchType() != guestTrafficLabelObj.getVirtualSwitchType()) { String msg = "Both public traffic and guest traffic is over same physical network " + pNetworkPublic + @@ -330,53 +279,37 @@ public VmwareServerDiscoverer() { s_logger.info("Detected private network label : " + privateTrafficLabel); } Pair vsmInfo = new Pair(false, 0L); - if (nexusDVS) { + if (nexusDVS && (guestTrafficLabelObj.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) || + ((zoneType == NetworkType.Advanced) && (publicTrafficLabelObj.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch))) { // Expect Cisco Nexus VSM details only if following 2 condition met // 1) The global config parameter vmware.use.nexus.vswitch // 2) Atleast 1 traffic type uses Nexus distributed virtual switch as backend. - boolean nexusDVSUsedAtGuestTraffic = false; - for (Map.Entry guestTrafficLabel : guestTrafficLabelInfo.entrySet()) { - if (guestTrafficLabel.getValue().getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) { - nexusDVSUsedAtGuestTraffic = true; - // Get physical network label - String guestTrafficNWLabel = guestTrafficLabel.getValue().getVirtualSwitchName(); - if (guestTrafficNWLabel != null) { - s_logger.info("Detected guest network label : " + guestTrafficNWLabel); - } + if (zoneType != NetworkType.Basic) { + publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(dcId, HypervisorType.VMware); + if (publicTrafficLabel != null) { + s_logger.info("Detected public network label : " + publicTrafficLabel); } } - - boolean nexusDVSUsedAtPublicTraffic = false; - if(zoneType == NetworkType.Advanced) { - for (Map.Entry publicTrafficLabel : publicTrafficLabelInfo.entrySet()) { - if (publicTrafficLabel.getValue().getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) { - nexusDVSUsedAtPublicTraffic = true; - // Get physical network label - String publicTrafficNWLabel = publicTrafficLabel.getValue().getVirtualSwitchName(); - if (publicTrafficNWLabel != null) { - s_logger.info("Detected public network label : " + publicTrafficNWLabel); - } - } - } + // Get physical network label + guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(dcId, HypervisorType.VMware); + if (guestTrafficLabel != null) { + s_logger.info("Detected guest network label : " + guestTrafficLabel); } - - if (nexusDVSUsedAtGuestTraffic || nexusDVSUsedAtPublicTraffic) { - // Before proceeding with validation of Nexus 1000v VSM check if an instance of Nexus 1000v VSM is already associated with this cluster. - boolean clusterHasVsm = _vmwareMgr.hasNexusVSM(clusterId); - if (!clusterHasVsm) { - vsmIp = _urlParams.get("vsmipaddress"); - String vsmUser = _urlParams.get("vsmusername"); - String vsmPassword = _urlParams.get("vsmpassword"); - String clusterName = cluster.getName(); - try { - vsmInfo = _nexusElement.validateAndAddVsm(vsmIp, vsmUser, vsmPassword, clusterId, clusterName); - } catch (ResourceInUseException ex) { - DiscoveryException discEx = new DiscoveryException(ex.getLocalizedMessage() + ". The resource is " + ex.getResourceName()); - throw discEx; - } + // Before proceeding with validation of Nexus 1000v VSM check if an instance of Nexus 1000v VSM is already associated with this cluster. + boolean clusterHasVsm = _vmwareMgr.hasNexusVSM(clusterId); + if (!clusterHasVsm) { + vsmIp = _urlParams.get("vsmipaddress"); + String vsmUser = _urlParams.get("vsmusername"); + String vsmPassword = _urlParams.get("vsmpassword"); + String clusterName = cluster.getName(); + try { + vsmInfo = _nexusElement.validateAndAddVsm(vsmIp, vsmUser, vsmPassword, clusterId, clusterName); + } catch (ResourceInUseException ex) { + DiscoveryException discEx = new DiscoveryException(ex.getLocalizedMessage() + ". The resource is " + ex.getResourceName()); + throw discEx; } - vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId); } + vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId); } VmwareContext context = null; @@ -451,8 +384,8 @@ public VmwareServerDiscoverer() { if (privateTrafficLabel != null) { params.put("private.network.vswitch.name", privateTrafficLabel); } - params.put("guestTrafficInfo", guestTrafficLabelInfo); - params.put("publicTrafficInfo", publicTrafficLabelInfo); + params.put("guestTrafficInfo", guestTrafficLabelObj); + params.put("publicTrafficInfo", publicTrafficLabelObj); params.put("router.aggregation.command.each.timeout", _configDao.getValue(Config.RouterAggregationCommandEachTimeout.toString())); @@ -694,34 +627,74 @@ public boolean stop() { return super.stop(); } - private Map getTrafficInfo(TrafficType trafficType, Map zoneLevelTrafficInfo, Map clusterLevelTrafficInfo, - String clusterLevelSwitchType) { - Map trafficInfo = new HashMap(); + private VmwareTrafficLabel getTrafficInfo(TrafficType trafficType, String zoneWideTrafficLabel, VirtualSwitchType defaultVirtualSwitchType, String vSwitchType, + String vSwitchName, Long clusterId) { + VmwareTrafficLabel trafficLabelObj = null; + Map clusterDetails = null; + try { + trafficLabelObj = new VmwareTrafficLabel(zoneWideTrafficLabel, trafficType, defaultVirtualSwitchType); + } catch (InvalidParameterValueException e) { + s_logger.error("Failed to recognize virtual switch type specified for " + trafficType + " traffic due to " + e.getMessage()); + throw e; + } - // Iterate through each zone level entry and Apply the cluster level overridden settings found with the physical network traffic id - for (Map.Entry zoneLevelTrafficDetail : zoneLevelTrafficInfo.entrySet()) { - VmwareTrafficLabel trafficLabelObj = null; - try { - trafficLabelObj = new VmwareTrafficLabel(zoneLevelTrafficDetail.getValue(), trafficType, getDefaultVirtualSwitchTypeAtCloudLevel()); - } catch (InvalidParameterValueException e) { - s_logger.error("Failed to recognize virtual switch type specified for " + trafficType + " traffic due to " + e.getMessage()); - throw e; - } + clusterDetails = _clusterDetailsDao.findDetails(clusterId); + if (vSwitchName != null) { + trafficLabelObj.setVirtualSwitchName(vSwitchName); + } + if (trafficType == TrafficType.Guest) { + clusterDetails.put(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC, trafficLabelObj.getVirtualSwitchName()); + } else { + clusterDetails.put(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC, trafficLabelObj.getVirtualSwitchName()); + } - // Check if any cluster level traffic override settings for that traffic id - if (clusterLevelTrafficInfo != null && clusterLevelSwitchType != null && VirtualSwitchType.getType(clusterLevelSwitchType) != VirtualSwitchType.None - && clusterLevelTrafficInfo.containsKey(zoneLevelTrafficDetail.getKey())) { - s_logger.debug("Cluster level traffic override found for the physical network traffic id: " + zoneLevelTrafficDetail.getKey()); - s_logger.debug("Replacing zone level label: " + zoneLevelTrafficDetail.getValue() + " with cluster vswitch type: " + clusterLevelSwitchType + " and name: " - + clusterLevelTrafficInfo.get(zoneLevelTrafficDetail.getKey())); - trafficLabelObj.setVirtualSwitchType(VirtualSwitchType.getType(clusterLevelSwitchType)); - trafficLabelObj.setVirtualSwitchName(clusterLevelTrafficInfo.get(zoneLevelTrafficDetail.getKey())); - } + if (vSwitchType != null) { + validateVswitchType(vSwitchType); + trafficLabelObj.setVirtualSwitchType(VirtualSwitchType.getType(vSwitchType)); + } + if (trafficType == TrafficType.Guest) { + clusterDetails.put(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC, trafficLabelObj.getVirtualSwitchType().toString()); + } else { + clusterDetails.put(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC, trafficLabelObj.getVirtualSwitchType().toString()); + } + + // Save cluster level override configuration to cluster details + _clusterDetailsDao.persist(clusterId, clusterDetails); + + return trafficLabelObj; + } - trafficInfo.put(zoneLevelTrafficDetail.getKey(), trafficLabelObj); + private VmwareTrafficLabel getTrafficInfo(TrafficType trafficType, String zoneWideTrafficLabel, Map clusterDetails, + VirtualSwitchType defVirtualSwitchType) { + VmwareTrafficLabel trafficLabelObj = null; + try { + trafficLabelObj = new VmwareTrafficLabel(zoneWideTrafficLabel, trafficType, defVirtualSwitchType); + } catch (InvalidParameterValueException e) { + s_logger.error("Failed to recognize virtual switch type specified for " + trafficType + " traffic due to " + e.getMessage()); + throw e; + } + + if (defVirtualSwitchType.equals(VirtualSwitchType.StandardVirtualSwitch)) { + return trafficLabelObj; } - return trafficInfo; + if (trafficType == TrafficType.Guest) { + if (clusterDetails.containsKey(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC)) { + trafficLabelObj.setVirtualSwitchName(clusterDetails.get(ApiConstants.VSWITCH_NAME_GUEST_TRAFFIC)); + } + if (clusterDetails.containsKey(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC)) { + trafficLabelObj.setVirtualSwitchType(VirtualSwitchType.getType(clusterDetails.get(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC))); + } + } else if (trafficType == TrafficType.Public) { + if (clusterDetails.containsKey(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC)) { + trafficLabelObj.setVirtualSwitchName(clusterDetails.get(ApiConstants.VSWITCH_NAME_PUBLIC_TRAFFIC)); + } + if (clusterDetails.containsKey(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC)) { + trafficLabelObj.setVirtualSwitchType(VirtualSwitchType.getType(clusterDetails.get(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC))); + } + } + + return trafficLabelObj; } private void _readGlobalConfigParameters() { @@ -739,32 +712,25 @@ protected HashMap buildConfigParams(HostVO host) { HashMap params = super.buildConfigParams(host); Map clusterDetails = _clusterDetailsDao.findDetails(host.getClusterId()); - - // Zone level traffic info with physical network traffic id and network label - Map guestTrafficInfoAtZoneLevel = _netmgr.getGuestTrafficInfo(host.getDataCenterId(), HypervisorType.VMware); - Map publicTrafficInfoAtZoneLevel = _netmgr.getPublicTrafficInfo(host.getDataCenterId(), HypervisorType.VMware); - - // Cluster level traffic info with physical network traffic id and network label (vswitch name) - Map guestTrafficInfoAtClusterLevel = getGuestTrafficInfoForCluster(host.getClusterId()); - Map publicTrafficInfoAtClusterLevel = getPublicTrafficInfoForCluster(host.getClusterId()); - - String guestVswitchTypeAtClusterLevel = clusterDetails.get(ApiConstants.VSWITCH_TYPE_GUEST_TRAFFIC); - String publicVswitchTypeAtClusterLevel = clusterDetails.get(ApiConstants.VSWITCH_TYPE_PUBLIC_TRAFFIC); - + // Get zone wide traffic labels from guest traffic and public traffic + String guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(host.getDataCenterId(), HypervisorType.VMware); + String publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(host.getDataCenterId(), HypervisorType.VMware); _readGlobalConfigParameters(); + VirtualSwitchType defaultVirtualSwitchType = getDefaultVirtualSwitchType(); - params.put("guestTrafficInfo", getTrafficInfo(TrafficType.Guest, guestTrafficInfoAtZoneLevel, guestTrafficInfoAtClusterLevel, guestVswitchTypeAtClusterLevel)); - params.put("publicTrafficInfo", getTrafficInfo(TrafficType.Public, publicTrafficInfoAtZoneLevel, publicTrafficInfoAtClusterLevel, publicVswitchTypeAtClusterLevel)); + params.put("guestTrafficInfo", getTrafficInfo(TrafficType.Guest, guestTrafficLabel, clusterDetails, defaultVirtualSwitchType)); + params.put("publicTrafficInfo", getTrafficInfo(TrafficType.Public, publicTrafficLabel, clusterDetails, defaultVirtualSwitchType)); return params; } - private VirtualSwitchType getDefaultVirtualSwitchTypeAtCloudLevel() { - if (useDVS) { - return (nexusDVS)? VirtualSwitchType.NexusDistributedVirtualSwitch:VirtualSwitchType.VMwareDistributedVirtualSwitch; - } - - return VirtualSwitchType.StandardVirtualSwitch; + private VirtualSwitchType getDefaultVirtualSwitchType() { + if (nexusDVS) + return VirtualSwitchType.NexusDistributedVirtualSwitch; + else if (useDVS) + return VirtualSwitchType.VMwareDistributedVirtualSwitch; + else + return VirtualSwitchType.StandardVirtualSwitch; } @Override @@ -791,14 +757,6 @@ public ServerResource reloadResource(HostVO host) { } private void validateVswitchType(String inputVswitchType) { - if (inputVswitchType == null) { - return; - } - - if (inputVswitchType.isEmpty()) { - throw new InvalidParameterValueException("Switch type shouldn't be empty"); - } - VirtualSwitchType vSwitchType = VirtualSwitchType.getType(inputVswitchType); if (vSwitchType == VirtualSwitchType.None) { s_logger.error("Unable to resolve " + inputVswitchType + " to a valid virtual switch type in VMware environment."); @@ -806,21 +764,6 @@ private void validateVswitchType(String inputVswitchType) { } } - private void validateVswitchNameAtCluster(String inputVswitchName) { - if (inputVswitchName == null) { - return; - } - - if (inputVswitchName.isEmpty()) { - throw new InvalidParameterValueException("Switch name shouldn't be empty"); - } - - String[] tokens = inputVswitchName.split(","); - if (tokens.length > MAX_FIELDS_VMWARE_LABEL_AT_CLUSTER) { - throw new InvalidParameterValueException("Found extraneous fields in vmware traffic label at cluster: " + inputVswitchName); - } - } - @Override public void putParam(Map params) { if (_urlParams == null) { @@ -838,27 +781,4 @@ public void setNetworkElements(List networkElements) { this.networkElements = networkElements; } - private Map getTrafficInfoForCluster(long clusterId, TrafficType trafficType) { - Map trafficInfo = _clusterPhysicalNetworkTrafficInfoDao.getTrafficInfo(clusterId); - if(trafficInfo == null || trafficInfo.size() == 0) { - return null; - } - - Map actualtrafficInfo = new HashMap(); - for (Map.Entry trafficDetail : trafficInfo.entrySet()) { - if(_physicalNetworkTrafficTypeDao.getTrafficType(trafficDetail.getKey().longValue()) == trafficType) { - actualtrafficInfo.put(trafficDetail.getKey(), trafficDetail.getValue()); - } - } - - return actualtrafficInfo; - } - - private Map getGuestTrafficInfoForCluster(long clusterId) { - return getTrafficInfoForCluster(clusterId, TrafficType.Guest); - } - - private Map getPublicTrafficInfoForCluster(long clusterId) { - return getTrafficInfoForCluster(clusterId, TrafficType.Public); - } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 9a520d377234..da97cdd04a7b 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -301,9 +301,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa protected String _vCenterAddress; protected String _privateNetworkVSwitchName; - protected Map _guestTrafficInfo = new HashMap(); - protected Map _publicTrafficInfo = new HashMap(); - protected VmwareTrafficLabel _publicTrafficLabel = null; + protected VmwareTrafficLabel _guestTrafficInfo = new VmwareTrafficLabel(TrafficType.Guest); + protected VmwareTrafficLabel _publicTrafficInfo = new VmwareTrafficLabel(TrafficType.Public); protected Map _vsmCredentials = null; protected int _portsPerDvPortGroup; protected boolean _fullCloneFlag = false; @@ -1029,11 +1028,9 @@ private UnPlugNicAnswer execute(UnPlugNicCommand cmd) { private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final String vifMacAddress) throws Exception { // TODO : probably need to set traffic shaping Pair networkInfo = null; - String vSwitchName = null; //TODO-Suresh - Zone level VirtualSwitchType vSwitchType = VirtualSwitchType.StandardVirtualSwitch; - if (_publicTrafficLabel != null) { - vSwitchName = _publicTrafficLabel.getVirtualSwitchName(); - vSwitchType = _publicTrafficLabel.getVirtualSwitchType(); + if (_publicTrafficInfo != null) { + vSwitchType = _publicTrafficInfo.getVirtualSwitchType(); } /** FIXME We have no clue which network this nic is on and that means that we can't figure out the BroadcastDomainType * so we assume that it's VLAN for now @@ -1041,12 +1038,12 @@ private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final Str if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) { synchronized (vmMo.getRunningHost().getMor().getValue().intern()) { networkInfo = - HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.public", vmMo.getRunningHost(), vlanId, null, null, + HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, _opsTimeout, true, BroadcastDomainType.Vlan, null); } } else { networkInfo = - HypervisorHostHelper.prepareNetwork(vSwitchName, "cloud.public", vmMo.getRunningHost(), vlanId, null, null, null, + HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, null, _opsTimeout, vSwitchType, _portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, _vsmCredentials); } @@ -2537,17 +2534,7 @@ private Ternary getTargetSwitch(NicTO nicTo) throws Clou VirtualSwitchType switchType = VirtualSwitchType.StandardVirtualSwitch; String vlanId = Vlan.UNTAGGED; - // Get switch type/name from resource property which is dictated by cluster property - // If a virtual switch type is specified while adding cluster that will be used. - // Else If virtual switch type/name is specified in physical traffic label that will be used - // Else use standard vSwitch - if (trafficType == TrafficType.Guest && _guestTrafficInfo != null && _guestTrafficInfo.containsKey(nicTo.getTrafficId())) { - switchType = _guestTrafficInfo.get(nicTo.getTrafficId()).getVirtualSwitchType(); - switchName = _guestTrafficInfo.get(nicTo.getTrafficId()).getVirtualSwitchName(); - } else if (trafficType == TrafficType.Public && _publicTrafficLabel != null) { - switchType = _publicTrafficLabel.getVirtualSwitchType(); - switchName = _publicTrafficLabel.getVirtualSwitchName(); - } else if (nicTo.getName() != null && !nicTo.getName().isEmpty()) { + if(nicTo.getName() != null && !nicTo.getName().isEmpty()) { // Format of network traffic label is ,, // If all 3 fields are mentioned then number of tokens would be 3. // If only , are mentioned then number of tokens would be 2. @@ -2557,6 +2544,14 @@ private Ternary getTargetSwitch(NicTO nicTo) throws Clou switchName = mgmtTrafficLabelObj.getVirtualSwitchName(); vlanId = mgmtTrafficLabelObj.getVlanId(); switchType = mgmtTrafficLabelObj.getVirtualSwitchType(); + } else { + if (trafficType == TrafficType.Guest && _guestTrafficInfo != null) { + switchType = _guestTrafficInfo.getVirtualSwitchType(); + switchName = _guestTrafficInfo.getVirtualSwitchName(); + } else if (trafficType == TrafficType.Public && _publicTrafficInfo != null) { + switchType = _publicTrafficInfo.getVirtualSwitchType(); + switchName = _publicTrafficInfo.getVirtualSwitchName(); + } } if (switchName == null @@ -2591,24 +2586,6 @@ private String getNetworkNamePrefix(NicTO nicTo) throws Exception { } } - private boolean doesGuestTrafficContainsDistributedVirtualSwitch() { - return (doesGuestTrafficContainsVirtualSwitchType(VirtualSwitchType.VMwareDistributedVirtualSwitch) || doesGuestTrafficContainsVirtualSwitchType(VirtualSwitchType.NexusDistributedVirtualSwitch)); - } - - private boolean doesGuestTrafficContainsVirtualSwitchType(VirtualSwitchType virtualSwitchType) { - if (_guestTrafficInfo == null || _guestTrafficInfo.isEmpty()) { - return false; - } - - for (Map.Entry trafficInfo : _guestTrafficInfo.entrySet()) { - if (trafficInfo.getValue().getVirtualSwitchType() == virtualSwitchType) { - return true; - } - } - - return false; - } - private VirtualMachineMO takeVmFromOtherHyperHost(VmwareHypervisorHost hyperHost, String vmName) throws Exception { VirtualMachineMO vmMo = hyperHost.findVmOnPeerHyperHost(vmName); @@ -4050,23 +4027,18 @@ protected Answer execute(UnregisterVMCommand cmd) { protected Answer execute(UnregisterNicCommand cmd) { s_logger.info("Executing resource UnregisterNicCommand: " + _gson.toJson(cmd)); - if (cmd.getTrafficId() == 0) { - return new Answer(cmd, false, "No Guest Traffic Id in cmd, unable to determine where to clean up"); - } - - if (_guestTrafficInfo == null || _guestTrafficInfo.isEmpty() || !_guestTrafficInfo.containsKey(cmd.getTrafficId())) { + if (_guestTrafficInfo == null) { return new Answer(cmd, false, "No Guest Traffic Info found, unable to determine where to clean up"); } try { - if (_guestTrafficInfo.get(cmd.getTrafficId()).getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) { + if (_guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) { // For now we only need to cleanup the nvp specific portgroups // on the standard switches return new Answer(cmd, true, "Nothing to do"); } - s_logger.debug("Cleaning up portgroup " + cmd.getNicUuid() + " of traffic id: " + cmd.getTrafficId() + " on switch type: " - + _guestTrafficInfo.get(cmd.getTrafficId()).getVirtualSwitchType() + " and name: " + _guestTrafficInfo.get(cmd.getTrafficId()).getVirtualSwitchName()); + s_logger.debug("Cleaning up portgroup " + cmd.getNicUuid() + " on switch " + _guestTrafficInfo.getVirtualSwitchName()); VmwareContext context = getServiceContext(); VmwareHypervisorHost host = getHyperHost(context); ManagedObjectReference clusterMO = host.getHyperHostCluster(); @@ -4948,10 +4920,8 @@ public boolean configure(String name, Map params) throws Configu _morHyperHost.setType(hostTokens[0]); _morHyperHost.setValue(hostTokens[1]); - _guestTrafficInfo = (Map)params.get("guestTrafficInfo"); // Map of Physical Network Traffic Id and VMware Traffic Label for Guest Traffic - _publicTrafficInfo = (Map)params.get("publicTrafficInfo"); // Map of Physical Network Traffic Id and VMware Traffic Label for Public Traffic (only one item in the list as Public network would be on single physical network) - _publicTrafficLabel = (_publicTrafficInfo != null) ? (VmwareTrafficLabel)_publicTrafficInfo.values().toArray()[0] : new VmwareTrafficLabel(TrafficType.Public); // Public network would be on single physical network hence getting first object of the list would suffice. - + _guestTrafficInfo = (VmwareTrafficLabel)params.get("guestTrafficInfo"); + _publicTrafficInfo = (VmwareTrafficLabel)params.get("publicTrafficInfo"); VmwareContext context = getServiceContext(); VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME); if (mgr == null) { @@ -4961,8 +4931,8 @@ public boolean configure(String name, Map params) throws Configu CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(context, context.getServiceContent().getCustomFieldsManager()); cfmMo.ensureCustomFieldDef("Datastore", CustomFieldConstants.CLOUD_UUID); - if (_publicTrafficLabel.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch || - doesGuestTrafficContainsDistributedVirtualSwitch()) { + if (_publicTrafficInfo != null && _publicTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch || _guestTrafficInfo != null && + _guestTrafficInfo.getVirtualSwitchType() != VirtualSwitchType.StandardVirtualSwitch) { cfmMo.ensureCustomFieldDef("DistributedVirtualPortgroup", CustomFieldConstants.CLOUD_GC_DVP); } cfmMo.ensureCustomFieldDef("Network", CustomFieldConstants.CLOUD_GC); @@ -4975,8 +4945,8 @@ public boolean configure(String name, Map params) throws Configu VmwareHypervisorHost hostMo = this.getHyperHost(context); _hostName = hostMo.getHyperHostName(); - if (doesGuestTrafficContainsVirtualSwitchType(VirtualSwitchType.NexusDistributedVirtualSwitch) || - _publicTrafficLabel.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) { + if (_guestTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch || + _publicTrafficInfo.getVirtualSwitchType() == VirtualSwitchType.NexusDistributedVirtualSwitch) { _privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware); _vsmCredentials = mgr.getNexusVSMCredentialsByClusterId(Long.parseLong(_cluster)); } @@ -5000,11 +4970,8 @@ public boolean configure(String name, Map params) throws Configu _portsPerDvPortGroup = intObj.intValue(); s_logger.info("VmwareResource network configuration info." + " private traffic over vSwitch: " + _privateNetworkVSwitchName + ", public traffic over " + - _publicTrafficLabel.getVirtualSwitchType() + " : " + _publicTrafficLabel.getVirtualSwitchName() + ", guest traffic over =>"); - - for (Map.Entry trafficInfo : _guestTrafficInfo.entrySet()) { - s_logger.info(trafficInfo.getValue().getVirtualSwitchType() + " : " + trafficInfo.getValue().getVirtualSwitchName()); - } + _publicTrafficInfo.getVirtualSwitchType() + " : " + _publicTrafficInfo.getVirtualSwitchName() + ", guest traffic over " + + _guestTrafficInfo.getVirtualSwitchType() + " : " + _guestTrafficInfo.getVirtualSwitchName()); Boolean boolObj = (Boolean)params.get("vmware.create.full.clone"); if (boolObj != null && boolObj.booleanValue()) { diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java index 7f2476580383..88ab512dbe99 100644 --- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java +++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java @@ -467,11 +467,10 @@ private void createApplyLoadBalancingRulesCommands(final List final Network guestNetwork = _ntwkModel.getNetwork(guestNetworkId); final Nic guestNic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), internalLbVm.getId()); - final long trafficId = _ntwkModel.getPhysicalNetworkTrafficId(guestNetwork.getPhysicalNetworkId(), guestNetwork.getTrafficType()); final NicProfile guestNicProfile = new NicProfile(guestNic, guestNetwork, guestNic.getBroadcastUri(), guestNic.getIsolationUri(), _ntwkModel.getNetworkRate(guestNetwork.getId(), internalLbVm.getId()), _ntwkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _ntwkModel.getNetworkTag(internalLbVm.getHypervisorType(), - guestNetwork), trafficId); + guestNetwork)); final NetworkOffering offering = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()); String maxconn = null; @@ -685,7 +684,6 @@ protected LinkedHashMap> createInternalLbVmN final String gatewayCidr = guestNetwork.getCidr(); guestNic.setIPv4Netmask(NetUtils.getCidrNetmask(gatewayCidr)); guestNic.setDefaultNic(true); - guestNic.setTrafficId(_ntwkModel.getPhysicalNetworkTrafficId(guestNetwork.getPhysicalNetworkId(), guestNetwork.getTrafficType())); networks.put(guestNetwork, new ArrayList(Arrays.asList(guestNic))); } diff --git a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java index 61dd7b887006..bb1b6f9b3de6 100644 --- a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java +++ b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java @@ -155,7 +155,6 @@ public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfil } nic.setBroadcastUri(generateBroadcastUri(network)); - nic.setTrafficId(_networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType())); return nic; } diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java index 1ee1b5e4fd65..fb14dc4408a3 100644 --- a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java @@ -84,7 +84,6 @@ public NicTO toNicTO(NicProfile profile) { NicTO to = new NicTO(); to.setDeviceId(profile.getDeviceId()); to.setBroadcastType(profile.getBroadcastType()); - to.setTrafficId(profile.getTrafficId()); to.setType(profile.getTrafficType()); to.setIp(profile.getIPv4Address()); to.setNetmask(profile.getIPv4Netmask()); diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java index ded2ac7edbb2..154e666c7a3f 100644 --- a/server/src/com/cloud/network/NetworkModelImpl.java +++ b/server/src/com/cloud/network/NetworkModelImpl.java @@ -115,7 +115,6 @@ import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; -import com.cloud.utils.Pair; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; @@ -1165,15 +1164,6 @@ public long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficTy } } - @Override - public long getPhysicalNetworkTrafficId(Long networkId, TrafficType trafficType) { - if(networkId == null) { - return 0; - } - - return _pNTrafficTypeDao.getPhysicalNetworkTrafficId(networkId.longValue(), trafficType); - } - @Override public List listNetworkOfferingsForUpgrade(long networkId) { List offeringsToReturn = new ArrayList(); @@ -1641,45 +1631,34 @@ public void checkNetworkPermissions(Account owner, Network network) { } @Override - public Map getPublicTrafficInfo(long dcId, HypervisorType vmware) - { - Map publicTrafficInfo = null; + public String getDefaultPublicTrafficLabel(long dcId, HypervisorType hypervisorType) { try { - publicTrafficInfo = getTrafficInfo(dcId, TrafficType.Public, vmware); - - return publicTrafficInfo; - } catch (Exception ex) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to get the public traffic info in zone due to: " + ex.getMessage()); - } - } - return publicTrafficInfo; - } - - @Override - public Map getGuestTrafficInfo(long dcId, HypervisorType vmware) - { - Map guestTrafficInfo = null; - try { - guestTrafficInfo = getTrafficInfo(dcId, TrafficType.Guest, vmware); - - return guestTrafficInfo; - } catch (Exception ex) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to get the guest traffic info in zone due to: " + ex.getMessage()); + PhysicalNetwork publicPhyNetwork = getOnePhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Public); + PhysicalNetworkTrafficTypeVO publicTraffic = _pNTrafficTypeDao.findBy(publicPhyNetwork.getId(), TrafficType.Public); + if (publicTraffic != null) { + String label = null; + switch (hypervisorType) { + case XenServer: + label = publicTraffic.getXenNetworkLabel(); + break; + case KVM: + label = publicTraffic.getKvmNetworkLabel(); + break; + case VMware: + label = publicTraffic.getVmwareNetworkLabel(); + break; + case Hyperv: + label = publicTraffic.getHypervNetworkLabel(); + break; + case Ovm3: + label = publicTraffic.getOvm3NetworkLabel(); + break; + } + return label; } - } - return guestTrafficInfo; - } - - @Override - public Pair getDefaultPublicTrafficInfo(long dcId, HypervisorType hypervisorType) { - try { - PhysicalNetwork publicPhyNetwork = getFirstPhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Public); - return getPhysicalNetworkTrafficInfo(publicPhyNetwork, TrafficType.Public, hypervisorType); } catch (Exception ex) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to retrieve the default label for public traffic in zone: " + dcId + " for hypervisor: " + hypervisorType + " due to: " + + s_logger.debug("Failed to retrieve the default label for public traffic." + "zone: " + dcId + " hypervisor: " + hypervisorType + " due to: " + ex.getMessage()); } } @@ -1687,96 +1666,37 @@ public Pair getDefaultPublicTrafficInfo(long dcId, HypervisorType } @Override - public Pair getDefaultGuestTrafficInfo(long dcId, HypervisorType hypervisorType) { + public String getDefaultGuestTrafficLabel(long dcId, HypervisorType hypervisorType) { try { - PhysicalNetwork guestPhyNetwork = getFirstPhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Guest); - return getPhysicalNetworkTrafficInfo(guestPhyNetwork, TrafficType.Guest, hypervisorType); - } catch (Exception ex) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to retrive the default label for guest traffic in zone: " + dcId + " for hypervisor: " + hypervisorType + " due to: " + - ex.getMessage()); - } - } - return null; - } - - @Override - public String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware) { - Pair publicTrafficInfo = getDefaultPublicTrafficInfo(dcId, vmware); - if(publicTrafficInfo == null) { - return null; - } - - return publicTrafficInfo.second(); - } - - @Override - public String getDefaultGuestTrafficLabel(long dcId, HypervisorType vmware) { - Pair guestTrafficInfo = getDefaultGuestTrafficInfo(dcId, vmware); - if(guestTrafficInfo == null) { - return null; - } - - return guestTrafficInfo.second(); - } - - private Map getTrafficInfo(long dcId, TrafficType trafficType, HypervisorType hypervisor) - { - Map trafficInfo = null; - try { - trafficInfo = new HashMap(); - List phyNetworks = getPhysicalNetworksByZoneAndTrafficType(dcId, trafficType); - for (PhysicalNetwork phyNetwork : phyNetworks) { - Pair phyNetworkTrafficInfo = getPhysicalNetworkTrafficInfo(phyNetwork, trafficType, hypervisor); - if(phyNetworkTrafficInfo == null) { - continue; + PhysicalNetwork guestPhyNetwork = getOnePhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Guest); + PhysicalNetworkTrafficTypeVO guestTraffic = _pNTrafficTypeDao.findBy(guestPhyNetwork.getId(), TrafficType.Guest); + if (guestTraffic != null) { + String label = null; + switch (hypervisorType) { + case XenServer: + label = guestTraffic.getXenNetworkLabel(); + break; + case KVM: + label = guestTraffic.getKvmNetworkLabel(); + break; + case VMware: + label = guestTraffic.getVmwareNetworkLabel(); + break; + case Hyperv: + label = guestTraffic.getHypervNetworkLabel(); + break; + case Ovm3: + label = guestTraffic.getOvm3NetworkLabel(); + break; } - - trafficInfo.put(phyNetworkTrafficInfo.first(), phyNetworkTrafficInfo.second()); + return label; } - - return trafficInfo; } catch (Exception ex) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to retrieve " + trafficType + " traffic info in zone: " + dcId + " for hypervisor: " + hypervisor + " due to: " + + s_logger.debug("Failed to retrive the default label for management traffic:" + "zone: " + dcId + " hypervisor: " + hypervisorType + " due to:" + ex.getMessage()); } } - return trafficInfo; - } - - private Pair getPhysicalNetworkTrafficInfo(PhysicalNetwork physicalNetwork, TrafficType trafficType, HypervisorType hypervisor) { - if(physicalNetwork == null) { - return null; - } - - try { - PhysicalNetworkTrafficTypeVO physicalNetworkTrafficType = _pNTrafficTypeDao.findBy(physicalNetwork.getId(), trafficType); - if (physicalNetworkTrafficType == null) { - return null; - } - - switch (hypervisor) { - case XenServer: - return new Pair(physicalNetworkTrafficType.getId(), physicalNetworkTrafficType.getXenNetworkLabel()); - case KVM: - return new Pair(physicalNetworkTrafficType.getId(), physicalNetworkTrafficType.getKvmNetworkLabel()); - case VMware: - return new Pair(physicalNetworkTrafficType.getId(), physicalNetworkTrafficType.getVmwareNetworkLabel()); - case Hyperv: - return new Pair(physicalNetworkTrafficType.getId(), physicalNetworkTrafficType.getHypervNetworkLabel()); - case Ovm3: - return new Pair(physicalNetworkTrafficType.getId(), physicalNetworkTrafficType.getOvm3NetworkLabel()); - default: - return null; - } - } catch (Exception ex) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to retrive the label for traffic type:" + trafficType + " and hypervisor: " + hypervisor + " in physical network: " - + physicalNetwork.getName() + " due to:" + ex.getMessage()); - } - } - return null; } @@ -1962,10 +1882,10 @@ String getZoneNetworkDomain(long zoneId) { return _dcDao.findById(zoneId).getDomain(); } - PhysicalNetwork getFirstPhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType) { + PhysicalNetwork getOnePhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType) { List networkList = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, trafficType); - if (networkList == null || networkList.isEmpty()) { + if (networkList.isEmpty()) { throw new InvalidParameterValueException("Unable to find the default physical network with traffic=" + trafficType + " in zone id=" + zoneId + ". "); } @@ -1976,16 +1896,6 @@ PhysicalNetwork getFirstPhysicalNetworkByZoneAndTrafficType(long zoneId, Traffic return networkList.get(0); } - List getPhysicalNetworksByZoneAndTrafficType(long zoneId, TrafficType trafficType) { - List networkList = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, trafficType); - - if (networkList == null || networkList.isEmpty()) { - throw new InvalidParameterValueException("Unable to find the default physical network with traffic=" + trafficType + " in zone id=" + zoneId + ". "); - } - - return networkList; - } - protected Long getNonGuestNetworkPhysicalNetworkId(Network network, TrafficType trafficType) { // VMware control network is management network // we need to retrieve traffic label information through physical network @@ -2056,10 +1966,9 @@ public NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadc Integer networkRate = getNetworkRate(network.getId(), vm.getId()); // NetworkGuru guru = _networkGurus.get(network.getGuruName()); - final long trafficId = getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag( - vm.getHypervisorType(), network), trafficId); + vm.getHypervisorType(), network)); // guru.updateNicProfile(profile, network); return profile; } diff --git a/server/src/com/cloud/network/router/CommandSetupHelper.java b/server/src/com/cloud/network/router/CommandSetupHelper.java index d12b204da23c..f701218f2ac2 100644 --- a/server/src/com/cloud/network/router/CommandSetupHelper.java +++ b/server/src/com/cloud/network/router/CommandSetupHelper.java @@ -323,9 +323,8 @@ public void createApplyLoadBalancingRulesCommands(final List final Network guestNetwork = _networkModel.getNetwork(guestNetworkId); final Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), router.getId()); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(guestNetwork.getPhysicalNetworkId(), guestNetwork.getTrafficType()); final NicProfile nicProfile = new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(guestNetwork.getId(), - router.getId()), _networkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork), trafficId); + router.getId()), _networkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork)); final NetworkOffering offering = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()); String maxconn = null; if (offering.getConcurrentConnections() == null) { diff --git a/server/src/com/cloud/network/router/NicProfileHelperImpl.java b/server/src/com/cloud/network/router/NicProfileHelperImpl.java index 9e4994cf927b..09e52119dc4a 100644 --- a/server/src/com/cloud/network/router/NicProfileHelperImpl.java +++ b/server/src/com/cloud/network/router/NicProfileHelperImpl.java @@ -67,14 +67,13 @@ public NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGate final Nic privateNic = _nicDao.findByIp4AddressAndNetworkId(ipVO.getIpAddress(), privateNetwork.getId()); NicProfile privateNicProfile = new NicProfile(); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(privateNetwork.getPhysicalNetworkId(), privateNetwork.getTrafficType()); if (privateNic != null) { final VirtualMachine vm = _vmDao.findById(privateNic.getInstanceId()); privateNicProfile = new NicProfile(privateNic, privateNetwork, privateNic.getBroadcastUri(), privateNic.getIsolationUri(), _networkModel.getNetworkRate( privateNetwork.getId(), vm.getId()), _networkModel.isSecurityGroupSupportedInNetwork(privateNetwork), _networkModel.getNetworkTag( - vm.getHypervisorType(), privateNetwork), trafficId); + vm.getHypervisorType(), privateNetwork)); } else { final String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr()); final PrivateIpAddress ip = @@ -93,7 +92,6 @@ public NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGate privateNicProfile.setFormat(AddressFormat.Ip4); privateNicProfile.setReservationId(String.valueOf(ip.getBroadcastUri())); privateNicProfile.setMacAddress(ip.getMacAddress()); - privateNicProfile.setTrafficId(trafficId); } return privateNicProfile; @@ -115,7 +113,6 @@ public NicProfile createGuestNicProfileForVpcRouter(final RouterDeploymentDefini guestNic.setMode(guestNetwork.getMode()); final String gatewayCidr = guestNetwork.getCidr(); guestNic.setIPv4Netmask(NetUtils.getCidrNetmask(gatewayCidr)); - guestNic.setTrafficId(_networkModel.getPhysicalNetworkTrafficId(guestNetwork.getPhysicalNetworkId(), guestNetwork.getTrafficType())); return guestNic; } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index dad1a0c30805..c32aeba1a35a 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -2097,8 +2097,7 @@ public boolean finalizeStart(final VirtualMachineProfile profile, final long hos if (network.getTrafficType() == TrafficType.Guest) { guestNetworks.add(network); if (nic.getBroadcastUri().getScheme().equals("pvlan")) { - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); - final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic", trafficId); + final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic"); final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO); try { @@ -2131,8 +2130,7 @@ public void finalizeStop(final VirtualMachineProfile profile, final Answer answe final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId()); if (network.getTrafficType() == TrafficType.Guest && nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) { - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); - final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic", trafficId); + final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic"); final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO); try { diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 06bfe0554ddd..b450e31f83a8 100644 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -20,7 +20,6 @@ import java.net.URISyntaxException; import java.net.URLDecoder; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -77,7 +76,6 @@ import com.cloud.configuration.ConfigurationManager; import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterDetailsVO; -import com.cloud.dc.ClusterPhysicalNetworkTrafficInfoDao; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenterIpAddressVO; @@ -124,11 +122,6 @@ import com.cloud.hypervisor.kvm.discoverer.KvmDummyResourceBase; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressVO; -import com.cloud.network.dao.PhysicalNetworkDao; -import com.cloud.network.dao.PhysicalNetworkVO; -import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao; -import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO; -import com.cloud.network.Networks; import com.cloud.org.Cluster; import com.cloud.org.Grouping; import com.cloud.org.Managed; @@ -198,8 +191,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, @Inject private ClusterDetailsDao _clusterDetailsDao; @Inject - private ClusterPhysicalNetworkTrafficInfoDao _clusterPhysicalNetworkTrafficInfoDao; - @Inject private ClusterDao _clusterDao; @Inject private CapacityDao _capacityDao; @@ -224,10 +215,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, @Inject private IPAddressDao _publicIPAddressDao; @Inject - private PhysicalNetworkDao _physicalNetworkDao; - @Inject - private PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao; - @Inject private VirtualMachineManager _vmMgr; @Inject private VMInstanceDao _vmDao; @@ -444,15 +431,6 @@ public List discoverCluster(final AddClusterCmd cmd) throws I } } - if ((cmd.getVSwitchTypeGuestTraffic() != null || cmd.getVSwitchTypePublicTraffic() != null || cmd.getVSwitchNameGuestTraffic() != null || cmd.getVSwitchNamePublicTraffic() != null) - && hypervisorType != HypervisorType.VMware) { - throw new InvalidParameterValueException("vSwitch details not are supported for hypervisor type " + hypervisorType); - } - - if (cmd.getPhysicalNetworkTrafficLabels() != null && hypervisorType != HypervisorType.VMware) { - throw new InvalidParameterValueException("Physical network traffic labels not are supported for hypervisor type " + hypervisorType); - } - Cluster.ClusterType clusterType = null; if (cmd.getClusterType() != null && !cmd.getClusterType().isEmpty()) { clusterType = Cluster.ClusterType.valueOf(cmd.getClusterType()); @@ -527,14 +505,6 @@ public List discoverCluster(final AddClusterCmd cmd) throws I details.put("memoryOvercommitRatio", CapacityManager.MemOverprovisioningFactor.value().toString()); _clusterDetailsDao.persist(cluster.getId(), details); - // save cluster physical network traffic labels - if (cmd.getPhysicalNetworkTrafficLabels() != null && !cmd.getPhysicalNetworkTrafficLabels().isEmpty()) { - final Map physicalNetworkTrafficLabels = getPhysicalNetworkTrafficLabels(cmd.getPhysicalNetworkTrafficLabels(), dcId); - if(physicalNetworkTrafficLabels != null) { - _clusterPhysicalNetworkTrafficInfoDao.persist(cluster.getId(), physicalNetworkTrafficLabels); - } - } - boolean success = false; try { try { @@ -573,51 +543,12 @@ public List discoverCluster(final AddClusterCmd cmd) throws I throw new DiscoveryException("Unable to add the external cluster"); } finally { if (!success) { - _clusterPhysicalNetworkTrafficInfoDao.deleteDetails(cluster.getId()); _clusterDetailsDao.deleteDetails(cluster.getId()); _clusterDao.remove(cluster.getId()); } } } - private Map getPhysicalNetworkTrafficLabels(Map physicalNetworkTrafficLabelsMap, long dcId) throws InvalidParameterValueException { - if(physicalNetworkTrafficLabelsMap == null || physicalNetworkTrafficLabelsMap.isEmpty()) { - return null; - } - - final Map physicalNetworkTrafficLabels = new HashMap(); - Collection physicalNetworkTrafficLabelsCollection = physicalNetworkTrafficLabelsMap.values(); - Iterator iter = physicalNetworkTrafficLabelsCollection.iterator(); - while (iter.hasNext()) { - HashMap trafficLabelMap = (HashMap)iter.next(); - String physicalNetworkTrafficUuid = trafficLabelMap.get("physicalnetworktrafficid"); - String networkLabel = trafficLabelMap.get("networklabel"); - - final PhysicalNetworkTrafficTypeVO physicalNetworkTrafficType = _physicalNetworkTrafficTypeDao.findByUuid(physicalNetworkTrafficUuid); - if (physicalNetworkTrafficType == null) { - throw new InvalidParameterValueException("Can't find physical network traffic id: " + physicalNetworkTrafficUuid + " in the zone of the cluster"); - } - - if (physicalNetworkTrafficType.getTrafficType() != Networks.TrafficType.Guest && physicalNetworkTrafficType.getTrafficType() != Networks.TrafficType.Public) { - throw new InvalidParameterValueException("Physical network traffic type not supported. Only guest and public are supported"); - } - - final PhysicalNetworkVO physicalNetworkVO = _physicalNetworkDao.findById(physicalNetworkTrafficType.getPhysicalNetworkId()); - if(physicalNetworkVO == null) { - throw new InvalidParameterValueException("No physical network exists for the traffic id: " + physicalNetworkTrafficUuid + " in the zone of the cluster"); - } - - if(physicalNetworkVO.getDataCenterId() != dcId) { - throw new InvalidParameterValueException("Can't find physical network for the traffic id: " + physicalNetworkTrafficUuid + " in the zone of the cluster"); - } - - Long physicalNetworkTrafficId = physicalNetworkTrafficType.getId(); - physicalNetworkTrafficLabels.put(physicalNetworkTrafficId, networkLabel); - } - - return physicalNetworkTrafficLabels; - } - @Override public Discoverer getMatchingDiscover(final Hypervisor.HypervisorType hypervisorType) { for (final Discoverer discoverer : _discoverers) { @@ -1071,7 +1002,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) { @Override @DB - public Cluster updateCluster(final Cluster clusterToUpdate, final String clusterType, final String hypervisor, final String allocationState, final String managedstate, Map physicalNetworkTrafficLabels) { + public Cluster updateCluster(final Cluster clusterToUpdate, final String clusterType, final String hypervisor, final String allocationState, final String managedstate) { final ClusterVO cluster = (ClusterVO)clusterToUpdate; // Verify cluster information and update the cluster if needed @@ -1079,7 +1010,7 @@ public Cluster updateCluster(final Cluster clusterToUpdate, final String cluster if (hypervisor != null && !hypervisor.isEmpty()) { final Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.getType(hypervisor); - if (hypervisorType == HypervisorType.None) { + if (hypervisorType == null) { s_logger.error("Unable to resolve " + hypervisor + " to a valid supported hypervisor type"); throw new InvalidParameterValueException("Unable to resolve " + hypervisor + " to a supported type"); } else { @@ -1104,10 +1035,6 @@ public Cluster updateCluster(final Cluster clusterToUpdate, final String cluster } } - if (physicalNetworkTrafficLabels != null && cluster.getHypervisorType() != HypervisorType.VMware) { - throw new InvalidParameterValueException("Physical network traffic labels not are supported for hypervisor type " + cluster.getHypervisorType()); - } - Grouping.AllocationState newAllocationState = null; if (allocationState != null && !allocationState.isEmpty()) { try { @@ -1140,13 +1067,6 @@ public Cluster updateCluster(final Cluster clusterToUpdate, final String cluster } } - if (physicalNetworkTrafficLabels != null && !physicalNetworkTrafficLabels.isEmpty()) { - final Map physicalNetworkTrafficLabelsInfo = getPhysicalNetworkTrafficLabels(physicalNetworkTrafficLabels, cluster.getDataCenterId()); - if(physicalNetworkTrafficLabelsInfo != null) { - _clusterPhysicalNetworkTrafficInfoDao.persist(cluster.getId(), physicalNetworkTrafficLabelsInfo); - } - } - if (doUpdate) { _clusterDao.update(cluster.getId(), cluster); } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 0d5448627875..97eceaf4b43a 100644 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -716,9 +716,8 @@ private boolean resetVMPasswordInternal(Long vmId, String password) throws Resou } Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId()); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(defaultNetwork.getPhysicalNetworkId(), defaultNetwork.getTrafficType()); NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork), - _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork), trafficId); + _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork)); VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance); vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password); @@ -824,9 +823,8 @@ private boolean resetVMSSHKeyInternal(Long vmId, String sshPublicKey, String pas } Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId()); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(defaultNetwork.getPhysicalNetworkId(), defaultNetwork.getTrafficType()); NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork), - _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork), trafficId); + _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork)); VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance); @@ -2356,9 +2354,8 @@ private boolean updateUserDataInternal(UserVm vm) throws ResourceUnavailableExce for (Nic nic : nics) { Network network = _networkDao.findById(nic.getNetworkId()); - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); NicProfile nicProfile = new NicProfile(nic, network, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag( - template.getHypervisorType(), network), trafficId); + template.getHypervisorType(), network)); VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm); @@ -3644,8 +3641,7 @@ public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Command // In vmware, we will be effecting pvlan settings in portgroups in StartCommand. if (profile.getHypervisorType() != HypervisorType.VMware) { if (nic.getBroadcastUri().getScheme().equals("pvlan")) { - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic", trafficId); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic"); if (!setupVmForPvlan(true, hostId, nicProfile)) { return false; } @@ -3751,8 +3747,7 @@ public void finalizeStop(VirtualMachineProfile profile, Answer answer) { NetworkVO network = _networkDao.findById(nic.getNetworkId()); if (network.getTrafficType() == TrafficType.Guest) { if (nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) { - final long trafficId = _networkModel.getPhysicalNetworkTrafficId(network.getPhysicalNetworkId(), network.getTrafficType()); - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic", trafficId); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic"); setupVmForPvlan(false, vm.getHostId(), nicProfile); } } diff --git a/server/test/com/cloud/network/MockNetworkModelImpl.java b/server/test/com/cloud/network/MockNetworkModelImpl.java index fdf3a53ee715..5c89a161bb71 100644 --- a/server/test/com/cloud/network/MockNetworkModelImpl.java +++ b/server/test/com/cloud/network/MockNetworkModelImpl.java @@ -44,7 +44,6 @@ import com.cloud.offerings.NetworkOfferingVO; import com.cloud.user.Account; import com.cloud.utils.component.ManagerBase; -import com.cloud.utils.Pair; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachine; @@ -539,33 +538,6 @@ public String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervis return null; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getPublicTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) - */ - @Override - public Map getPublicTrafficInfo(long dcId, HypervisorType vmware) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getGuestTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) - */ - @Override - public Map getGuestTrafficInfo(long dcId, HypervisorType vmware) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getDefaultPublicTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) - */ - @Override - public Pair getDefaultPublicTrafficInfo(long dcId, HypervisorType vmware) { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getDefaultPublicTrafficLabel(long, com.cloud.hypervisor.Hypervisor.HypervisorType) */ @@ -575,15 +547,6 @@ public String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware) { return null; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getDefaultGuestTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) - */ - @Override - public Pair getDefaultGuestTrafficInfo(long dcId, HypervisorType vmware) { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getDefaultGuestTrafficLabel(long, com.cloud.hypervisor.Hypervisor.HypervisorType) */ @@ -728,15 +691,6 @@ public long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficTy return 0; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getPhysicalNetworkTrafficId(Long, java.lang.String, com.cloud.network.Networks.TrafficType) - */ - @Override - public long getPhysicalNetworkTrafficId(Long networkId, TrafficType trafficType) { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getNetworkRate(long, java.lang.Long) */ diff --git a/server/test/com/cloud/resource/MockResourceManagerImpl.java b/server/test/com/cloud/resource/MockResourceManagerImpl.java index 57e15e270a46..d4f2210417d2 100644 --- a/server/test/com/cloud/resource/MockResourceManagerImpl.java +++ b/server/test/com/cloud/resource/MockResourceManagerImpl.java @@ -109,7 +109,7 @@ public boolean deleteCluster(final DeleteClusterCmd cmd) { * @see com.cloud.resource.ResourceService#updateCluster(com.cloud.org.Cluster, java.lang.String, java.lang.String, java.lang.String, java.lang.String) */ @Override - public Cluster updateCluster(final Cluster cluster, final String clusterType, final String hypervisor, final String allocationState, final String managedstate, Map physicalNetworkTrafficLabels) { + public Cluster updateCluster(final Cluster cluster, final String clusterType, final String hypervisor, final String allocationState, final String managedstate) { // TODO Auto-generated method stub return null; } diff --git a/server/test/com/cloud/vpc/MockNetworkModelImpl.java b/server/test/com/cloud/vpc/MockNetworkModelImpl.java index 01cb5accc5c0..8ed3b7c3db59 100644 --- a/server/test/com/cloud/vpc/MockNetworkModelImpl.java +++ b/server/test/com/cloud/vpc/MockNetworkModelImpl.java @@ -52,7 +52,6 @@ import com.cloud.offerings.dao.NetworkOfferingServiceMapDao; import com.cloud.user.Account; import com.cloud.utils.component.ManagerBase; -import com.cloud.utils.Pair; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachine; @@ -556,33 +555,6 @@ public String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervis return null; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getPublicTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) - */ - @Override - public Map getPublicTrafficInfo(long dcId, HypervisorType vmware) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getGuestTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) - */ - @Override - public Map getGuestTrafficInfo(long dcId, HypervisorType vmware) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getDefaultPublicTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) - */ - @Override - public Pair getDefaultPublicTrafficInfo(long dcId, HypervisorType vmware) { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getDefaultPublicTrafficLabel(long, com.cloud.hypervisor.Hypervisor.HypervisorType) */ @@ -592,15 +564,6 @@ public String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware) { return null; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getDefaultGuestTrafficInfo(long, com.cloud.hypervisor.Hypervisor.HypervisorType) - */ - @Override - public Pair getDefaultGuestTrafficInfo(long dcId, HypervisorType vmware) { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getDefaultGuestTrafficLabel(long, com.cloud.hypervisor.Hypervisor.HypervisorType) */ @@ -744,15 +707,6 @@ public long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficTy return 0; } - /* (non-Javadoc) - * @see com.cloud.network.NetworkModel#getPhysicalNetworkTrafficId(Long, java.lang.String, com.cloud.network.Networks.TrafficType) - */ - @Override - public long getPhysicalNetworkTrafficId(Long networkId, TrafficType trafficType) { - // TODO Auto-generated method stub - return 0; - } - /* (non-Javadoc) * @see com.cloud.network.NetworkModel#getNetworkRate(long, java.lang.Long) */ diff --git a/setup/db/db/schema-452to460.sql b/setup/db/db/schema-452to460.sql index 98ba274eaab1..5887e5389041 100644 --- a/setup/db/db/schema-452to460.sql +++ b/setup/db/db/schema-452to460.sql @@ -413,17 +413,3 @@ CREATE TABLE `cloud`.`ldap_trust_map` ( UNIQUE KEY `uk_ldap_trust_map__domain_id` (`domain_id`), CONSTRAINT `fk_ldap_trust_map__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -DROP TABLE IF EXISTS `cloud`.`cluster_physical_network_traffic_info`; -CREATE TABLE `cloud`.`cluster_physical_network_traffic_info` ( - `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', - `uuid` varchar(40), - `cluster_id` bigint unsigned NOT NULL COMMENT 'cluster id', - `physical_network_traffic_id` bigint unsigned NOT NULL COMMENT 'id of physical network traffic in the zone of the cluster', - `vmware_network_label` varchar(255) COMMENT 'network label of the physical device dedicated to this traffic on a VMware host at cluster level', - PRIMARY KEY (`id`), - CONSTRAINT `fk_cluster_physical_network_traffic_info__cluster_id` FOREIGN KEY (`cluster_id`) REFERENCES `cluster`(`id`) ON DELETE CASCADE, - CONSTRAINT `fk_cluster_physical_network_traffic_info__traffic_id` FOREIGN KEY (`physical_network_traffic_id`) REFERENCES `physical_network_traffic_types`(`id`) ON DELETE CASCADE, - CONSTRAINT `uc_cluster_physical_network_traffic_info__uuid` UNIQUE (`uuid`), - UNIQUE KEY (`cluster_id`, `physical_network_traffic_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; From d3c3f498d19ae623e6b658627087cfc2ec734e67 Mon Sep 17 00:00:00 2001 From: Suresh Kumar Anaparti Date: Wed, 16 Dec 2015 15:59:14 +0530 Subject: [PATCH 3/3] CLOUDSTACK-9175: [VMware DRS] Adding new host to DRS cluster does not participate in load balancing. Summary: When a new host is added to a cluster, Cloudstack doesn't create all the port groups (created by cloudstack earlier in other hosts) present in the cluster. Since the new host doesn't have all the necessary networking port groups of cloudstack, it is not eligible to participate in DRS load balancing or HA. Solution: When adding a host to the cluster in Cloudstack, use VMware API to find the list of unique port groups on a previously added host (older host in the cluster) if exists and then create them on the new host. --- .../src/com/cloud/host/dao/HostDao.java | 2 + .../src/com/cloud/host/dao/HostDaoImpl.java | 17 +++++ .../vmware/manager/VmwareManagerImpl.java | 34 +++++++++ .../cloud/hypervisor/vmware/mo/HostMO.java | 73 +++++++++++++++++++ .../vmware/mo/HypervisorHostHelper.java | 24 ++++++ 5 files changed, 150 insertions(+) diff --git a/engine/schema/src/com/cloud/host/dao/HostDao.java b/engine/schema/src/com/cloud/host/dao/HostDao.java index bd484825c812..a9dfb63f6473 100644 --- a/engine/schema/src/com/cloud/host/dao/HostDao.java +++ b/engine/schema/src/com/cloud/host/dao/HostDao.java @@ -71,6 +71,8 @@ public interface HostDao extends GenericDao, StateDao findHypervisorHostInCluster(long clusterId); + HostVO findOlderHypervisorHostInCluster(long clusterId); + /** * @param type * @param clusterId diff --git a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java index 8342f1fcf773..698b4e385766 100644 --- a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java +++ b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java @@ -1081,6 +1081,23 @@ public List findHypervisorHostInCluster(long clusterId) { return listBy(sc); } + @Override + public HostVO findOlderHypervisorHostInCluster(long clusterId) { + SearchCriteria sc = TypeClusterStatusSearch.create(); + sc.setParameters("type", Host.Type.Routing); + sc.setParameters("cluster", clusterId); + sc.setParameters("status", Status.Up); + sc.setParameters("resourceState", ResourceState.Enabled); + Filter orderByFilter = new Filter(HostVO.class, "created", true, null, null); + + List hosts = search(sc, orderByFilter, null, false); + if (hosts != null && hosts.size() > 0) { + return hosts.get(0); + } + + return null; + } + @Override public List listAllHosts(long zoneId) { SearchCriteria sc = HostIdSearch.create(); diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java index 575801fa6034..f902430cba39 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java @@ -21,6 +21,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLDecoder; import java.rmi.RemoteException; import java.util.ArrayList; import java.util.HashMap; @@ -71,6 +72,8 @@ import com.cloud.exception.DiscoveryException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceInUseException; +import com.cloud.host.dao.HostDao; +import com.cloud.host.HostVO; import com.cloud.host.Host; import com.cloud.host.Status; import com.cloud.hypervisor.Hypervisor.HypervisorType; @@ -120,6 +123,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SshHelper; +import com.cloud.utils.UriUtils; import com.cloud.vm.DomainRouterVO; public class VmwareManagerImpl extends ManagerBase implements VmwareManager, VmwareStorageMount, Listener, VmwareDatacenterService { @@ -138,6 +142,8 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw @Inject private NetworkModel _netMgr; @Inject + private HostDao _hostDao; + @Inject private ClusterDao _clusterDao; @Inject private ClusterDetailsDao _clusterDetailsDao; @@ -374,6 +380,29 @@ private void prepareHost(HostMO hostMo, String privateTrafficLabel) throws Excep } } + private HostMO getOlderHostInCluster(Long clusterId, VmwareContext serviceContext) throws Exception { + HostVO host = _hostDao.findOlderHypervisorHostInCluster(clusterId); + if (host == null) { + return null; + } + + ManagedObjectReference morSrcHost = HypervisorHostHelper.getHypervisorHostMorFromGuid(host.getGuid()); + if (morSrcHost == null) { + Map clusterDetails = _clusterDetailsDao.findDetails(clusterId); + if (clusterDetails.get("url") == null) { + return null; + } + + URI uriForHost = new URI(UriUtils.encodeURIComponent(clusterDetails.get("url") + "/" + host.getName())); + morSrcHost = serviceContext.getHostMorByPath(URLDecoder.decode(uriForHost.getPath(), "UTF-8")); + if (morSrcHost == null) { + return null; + } + } + + return new HostMO(serviceContext, morSrcHost); + } + @Override public List addHostToPodCluster(VmwareContext serviceContext, long dcId, Long podId, Long clusterId, String hostInventoryPath) throws Exception { @@ -426,6 +455,11 @@ public List addHostToPodCluster(VmwareContext serviceCon // For ESX host, we need to enable host firewall to allow VNC access HostMO hostMo = new HostMO(serviceContext, mor); prepareHost(hostMo, privateTrafficLabel); + HostMO olderHostMo = getOlderHostInCluster(clusterId, serviceContext); + if (olderHostMo != null) { + hostMo.copyPortGroupsFromHost(olderHostMo); + } + returnedHostList.add(mor); return returnedHostList; } else { diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java index d8fa7f355db1..249def0b6966 100644 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java @@ -48,6 +48,7 @@ import com.vmware.vim25.HostNetworkTrafficShapingPolicy; import com.vmware.vim25.HostOpaqueNetworkInfo; import com.vmware.vim25.HostPortGroup; +import com.vmware.vim25.HostPortGroupPort; import com.vmware.vim25.HostPortGroupSpec; import com.vmware.vim25.HostRuntimeInfo; import com.vmware.vim25.HostSystemConnectionState; @@ -127,6 +128,43 @@ public HostPortGroupSpec getHostPortGroupSpec(String portGroupName) throws Excep return null; } + public List getHostPortGroupSpecs() throws Exception { + HostNetworkInfo hostNetInfo = getHostNetworkInfo(); + if (hostNetInfo == null) { + return null; + } + + List portGroups = hostNetInfo.getPortgroup(); + if (portGroups == null) { + return null; + } + + List portGroupSpecs = new ArrayList(); + for (HostPortGroup portGroup : portGroups) { + if (!isVMKernelPort(portGroup)) { + portGroupSpecs.add(portGroup.getSpec()); + } + } + + return portGroupSpecs; + } + + private boolean isVMKernelPort(HostPortGroup portGroup) { + assert (portGroup != null); + List ports = portGroup.getPort(); + if (ports == null) { + return false; + } + + for (HostPortGroupPort port : ports) { + if (port.getType().equalsIgnoreCase("host")) { + return true; + } + } + + return false; + } + @Override public String getHyperHostName() throws Exception { return getName(); @@ -1110,4 +1148,39 @@ public String getNetworkName(String netMorVal) throws Exception { } return networkName; } + + public void createPortGroup(HostPortGroupSpec spec) throws Exception { + if (spec == null) { + return; + } + + synchronized (_mor.getValue().intern()) { + HostNetworkSystemMO hostNetMo = getHostNetworkSystemMO(); + if (hostNetMo == null) { + return; + } + + ManagedObjectReference morNetwork = getNetworkMor(spec.getName()); + if (morNetwork == null) { + hostNetMo.addPortGroup(spec); + } + } + } + + public void copyPortGroupsFromHost(HostMO srcHost) throws Exception { + if (srcHost == null) { + return; + } + + List portGroupSpecs = srcHost.getHostPortGroupSpecs(); + if (portGroupSpecs == null || portGroupSpecs.isEmpty()) { + s_logger.debug("No port groups in the host: " + srcHost.getName()); + return; + } + + for (HostPortGroupSpec spec : portGroupSpecs) { + s_logger.debug("Creating port group: " + spec.getName() + " in the host: " + getName()); + createPortGroup(spec); + } + } } diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java index fc27d1f8e430..74e21d89c94d 100644 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java @@ -1571,6 +1571,30 @@ public void action(Long param) { } } + public static ManagedObjectReference getHypervisorHostMorFromGuid(String guid) { + if (guid == null) { + return null; + } + + String[] tokens = guid.split("@"); + if (tokens == null || tokens.length != 2) { + s_logger.error("Invalid content in host guid"); + return null; + } + + String[] hostTokens = tokens[0].split(":"); + if (hostTokens == null || hostTokens.length != 2) { + s_logger.error("Invalid content in host guid"); + return null; + } + + ManagedObjectReference morHyperHost = new ManagedObjectReference(); + morHyperHost.setType(hostTokens[0]); + morHyperHost.setValue(hostTokens[1]); + + return morHyperHost; + } + public static String getScsiController(Pair controllerInfo, String recommendedController) { String rootDiskController = controllerInfo.first(); String dataDiskController = controllerInfo.second();