diff --git a/api/src/com/cloud/api/commands/CreateNetworkCmd.java b/api/src/com/cloud/api/commands/CreateNetworkCmd.java index c6680ba7c3d..06be18223d7 100644 --- a/api/src/com/cloud/api/commands/CreateNetworkCmd.java +++ b/api/src/com/cloud/api/commands/CreateNetworkCmd.java @@ -163,11 +163,6 @@ public class CreateNetworkCmd extends BaseCmd { return zoneId; } - public List getTags() { - //FIXME - remove this method - return null; - } - public Long getPhysicalNetworkId() { NetworkOffering offering = _configService.getNetworkOffering(networkOfferingId); if (offering == null) { diff --git a/api/src/com/cloud/api/response/NetworkResponse.java b/api/src/com/cloud/api/response/NetworkResponse.java index fe9ff746e8a..a3f7ef63bf6 100644 --- a/api/src/com/cloud/api/response/NetworkResponse.java +++ b/api/src/com/cloud/api/response/NetworkResponse.java @@ -120,9 +120,6 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes @SerializedName(ApiConstants.NETWORK_DOMAIN) @Param(description="the network domain") private String networkDomain; - @SerializedName(ApiConstants.TAGS) @Param(description="comma separated tag") - private String tags; - @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network id") private Long physicalNetworkId; @@ -243,19 +240,6 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes this.networkDomain = networkDomain; } - public void setTags(List tags) { - if (tags == null || tags.size() == 0) { - return; - } - - StringBuilder buf = new StringBuilder(); - for (String tag : tags) { - buf.append(tag).append(","); - } - - this.tags = buf.delete(buf.length()-1, buf.length()).toString(); - } - @Override public void setProjectId(Long projectId) { this.projectId = projectId; diff --git a/api/src/com/cloud/hypervisor/Hypervisor.java b/api/src/com/cloud/hypervisor/Hypervisor.java index 2f50e072512..d791ce254c5 100644 --- a/api/src/com/cloud/hypervisor/Hypervisor.java +++ b/api/src/com/cloud/hypervisor/Hypervisor.java @@ -21,7 +21,6 @@ public class Hypervisor { public static enum HypervisorType { None, //for storage hosts - Xen, XenServer, KVM, VMware, @@ -38,10 +37,7 @@ public class Hypervisor { if (hypervisor == null) { return HypervisorType.None; } - - if (hypervisor.equalsIgnoreCase("Xen")) { - return HypervisorType.Xen; - } else if (hypervisor.equalsIgnoreCase("XenServer")) { + if (hypervisor.equalsIgnoreCase("XenServer")) { return HypervisorType.XenServer; } else if (hypervisor.equalsIgnoreCase("KVM")) { return HypervisorType.KVM; diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index 26a8153ef48..ec2ce371169 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -269,8 +269,6 @@ public interface Network extends ControlledEntity { String getNetworkDomain(); - List getTags(); - GuestType getGuestType(); boolean getIsShared(); diff --git a/api/src/com/cloud/network/NetworkProfile.java b/api/src/com/cloud/network/NetworkProfile.java index bcbf7acc539..e90a58a4e97 100644 --- a/api/src/com/cloud/network/NetworkProfile.java +++ b/api/src/com/cloud/network/NetworkProfile.java @@ -19,7 +19,6 @@ package com.cloud.network; import java.net.URI; -import java.util.List; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.Mode; @@ -47,7 +46,6 @@ public class NetworkProfile implements Network { private String reservationId; private boolean isDefault; private String networkDomain; - private List tags; private Network.GuestType guestType; private boolean isShared; private Long physicalNetworkId; @@ -76,11 +74,6 @@ public class NetworkProfile implements Network { this.physicalNetworkId = network.getPhysicalNetworkId(); } - @Override - public List getTags() { - return tags; - } - public String getDns1() { return dns1; } diff --git a/api/src/com/cloud/vm/NicProfile.java b/api/src/com/cloud/vm/NicProfile.java index e2f737bfa3b..9c9c390f5a2 100644 --- a/api/src/com/cloud/vm/NicProfile.java +++ b/api/src/com/cloud/vm/NicProfile.java @@ -213,7 +213,7 @@ public class NicProfile { return strategy; } - public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled) { + public NicProfile(Nic nic, Network network, URI broadcastUri, URI isolationUri, Integer networkRate, boolean isSecurityGroupEnabled, List tags) { this.id = nic.getId(); this.networkId = network.getId(); this.gateway = nic.getGateway(); @@ -233,7 +233,7 @@ public class NicProfile { this.netmask = nic.getNetmask(); this.isSecurityGroupEnabled = isSecurityGroupEnabled; this.vmId = nic.getInstanceId(); - this.tags = network.getTags(); + this.tags = tags; if (networkRate != null) { this.networkRate = networkRate; diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 4c22de4318a..ec6cd4abc70 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -2192,9 +2192,6 @@ public class ApiResponseHelper implements ResponseGenerator { response.setDns1(profile.getDns1()); response.setDns2(profile.getDns2()); - - response.setTags(network.getTags()); - // populate capability Map> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(networkOffering.getId(), network.getDataCenterId()); List serviceResponses = new ArrayList(); diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 9fb0b4bd990..fe913fa7d74 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1412,7 +1412,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } userNetwork.setBroadcastDomainType(broadcastDomainType); userNetwork.setNetworkDomain(networkDomain); - _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, isNetworkDefault, false, null, null, true); + _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, isNetworkDefault, false, null, true); } } } diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 04df370752d..f2394892a02 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -28,6 +28,7 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.Network.Capability; import com.cloud.network.Network.Provider; import com.cloud.network.Network.Service; @@ -110,7 +111,7 @@ public interface NetworkManager extends NetworkService { throws ConcurrentOperationException; List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean errorIfAlreadySetup, - Long domainId, List tags, boolean isShared) throws ConcurrentOperationException; + Long domainId, boolean isShared) throws ConcurrentOperationException; List getSystemAccountNetworkOfferings(String... offeringNames); @@ -151,7 +152,7 @@ public interface NetworkManager extends NetworkService { boolean destroyNetwork(long networkId, ReservationContext context); Network createNetwork(long networkOfferingId, String name, String displayText, Boolean isDefault, String gateway, String cidr, String vlanId, String networkDomain, Account owner, boolean isSecurityGroupEnabled, - Long domainId, List tags, Boolean isShared, PhysicalNetwork physicalNetwork, long zoneId) throws ConcurrentOperationException, InsufficientCapacityException; + Long domainId, Boolean isShared, PhysicalNetwork physicalNetwork, long zoneId) throws ConcurrentOperationException, InsufficientCapacityException; /** * @throws InsufficientCapacityException @@ -228,4 +229,6 @@ public interface NetworkManager extends NetworkService { boolean isServiceEnabled(Long physicalNetworkId, long networkOfferingId, Service service); + List getNetworkTags(HypervisorType hType, Network network); + } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index c7b8d809453..095c11a643a 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -86,6 +86,7 @@ import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.UnsupportedServiceException; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.IpAddress.State; import com.cloud.network.Network.Capability; import com.cloud.network.Network.GuestType; @@ -999,13 +1000,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public List setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean isShared) throws ConcurrentOperationException { - return setupNetwork(owner, offering, null, plan, name, displayText, isDefault, false, null, null, isShared); + return setupNetwork(owner, offering, null, plan, name, displayText, isDefault, false, null, isShared); } @Override @DB public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean errorIfAlreadySetup, - Long domainId, List tags, boolean isShared) throws ConcurrentOperationException { + Long domainId, boolean isShared) throws ConcurrentOperationException { Account locked = _accountDao.acquireInLockTable(owner.getId()); if (locked == null) { throw new ConcurrentOperationException("Unable to acquire lock on " + owner); @@ -1066,7 +1067,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText, isDefault, (domainId != null), predefined.getNetworkDomain(), offering.getGuestType(), isShared, plan.getDataCenterId(), plan.getPhysicalNetworkId()); - vo.setTags(tags); networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated)); if (domainId != null) { @@ -1164,7 +1164,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag nics.add(vo); Integer networkRate = getNetworkRate(config.getId(), vm.getId()); - vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network.first()))); + vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network.first()), getNetworkTags(vm.getHypervisorType(), network.first()))); } if (nics.size() != networks.size()) { @@ -1414,7 +1414,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag URI isolationUri = nic.getIsolationUri(); - profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate, isSecurityGroupSupportedInNetwork(network)); + profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTags(vmProfile.getHypervisorType(), network)); guru.reserve(profile, network, vmProfile, dest, context); nic.setIp4Address(profile.getIp4Address()); nic.setAddressFormat(profile.getFormat()); @@ -1433,7 +1433,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag updateNic(nic, network.getId(), 1); } else { - profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network)); + profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTags(vmProfile.getHypervisorType(), network)); guru.updateNicProfile(profile, network); nic.setState(Nic.State.Reserved); updateNic(nic, network.getId(), 1); @@ -1460,7 +1460,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Integer networkRate = getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network)); + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTags(vm.getHypervisorType(), network)); guru.updateNicProfile(profile, network); vm.addNic(profile); } @@ -1477,7 +1477,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkGuru guru = _networkGurus.get(network.getGuruName()); nic.setState(Nic.State.Releasing); _nicDao.update(nic.getId(), nic); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, isSecurityGroupSupportedInNetwork(network)); + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, isSecurityGroupSupportedInNetwork(network), getNetworkTags(vmProfile.getHypervisorType(), network)); if (guru.release(profile, vmProfile, nic.getReservationId())) { applyProfileToNicForRelease(nic, profile); nic.setState(Nic.State.Allocated); @@ -1511,7 +1511,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Integer networkRate = getNetworkRate(network.getId(), vm.getId()); NetworkGuru guru = _networkGurus.get(network.getGuruName()); - NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network)); + NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTags(vm.getHypervisorType(), network)); guru.updateNicProfile(profile, network); profiles.add(profile); } @@ -1613,7 +1613,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag nic.setState(Nic.State.Deallocating); _nicDao.update(nic.getId(), nic); NetworkVO network = _networksDao.findById(nic.getNetworkId()); - NicProfile profile = new NicProfile(nic, network, null, null, null, isSecurityGroupSupportedInNetwork(network)); + NicProfile profile = new NicProfile(nic, network, null, null, null, isSecurityGroupSupportedInNetwork(network), getNetworkTags(vm.getHypervisorType(), network)); NetworkGuru guru = _networkGurus.get(network.getGuruName()); guru.deallocate(network, profile, vm); _nicDao.remove(nic.getId()); @@ -1644,16 +1644,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Boolean isDefault = cmd.isDefault(); Long userId = UserContext.current().getCallerUserId(); Account caller = UserContext.current().getCaller(); - List tags = cmd.getTags(); boolean isDomainSpecific = false; Boolean isShared = cmd.getIsShared(); Long physicalNetworkId = cmd.getPhysicalNetworkId(); Long zoneId = cmd.getZoneId(); - if (tags != null && tags.size() > 1) { - throw new InvalidParameterException("Only one tag can be specified for a network at this time"); - } - Transaction txn = Transaction.currentTxn(); // Check if network offering exists @@ -1780,7 +1775,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag domainId = cmd.getDomainId(); } - Network network = createNetwork(networkOfferingId, name, displayText, isDefault, gateway, cidr, vlanId, networkDomain, owner, false, domainId, tags, isShared, pNtwk, zoneId); + Network network = createNetwork(networkOfferingId, name, displayText, isDefault, gateway, cidr, vlanId, networkDomain, owner, false, domainId, isShared, pNtwk, zoneId); // Don't pass owner to create vlan when network offering is of type Shared - done to prevent accountVlanMap entry // creation when vlan is mapped to network @@ -1801,7 +1796,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override @DB public Network createNetwork(long networkOfferingId, String name, String displayText, Boolean isDefault, String gateway, String cidr, String vlanId, String networkDomain, Account owner, - boolean isSecurityGroupEnabled, Long domainId, List tags, Boolean isShared, PhysicalNetwork pNtwk, long zoneId) throws ConcurrentOperationException, InsufficientCapacityException { + boolean isSecurityGroupEnabled, Long domainId, Boolean isShared, PhysicalNetwork pNtwk, long zoneId) throws ConcurrentOperationException, InsufficientCapacityException { NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId); DataCenterVO zone = _dcDao.findById(zoneId); @@ -1920,7 +1915,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - List networks = setupNetwork(owner, networkOffering, userNetwork, plan, name, displayText, isDefault, true, domainId, tags, isShared); + List networks = setupNetwork(owner, networkOffering, userNetwork, plan, name, displayText, isDefault, true, domainId, isShared); Network network = null; if (networks == null || networks.isEmpty()) { @@ -2820,7 +2815,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (createNetwork) { List offerings = _configMgr.listNetworkOfferings(TrafficType.Guest, false); PhysicalNetwork physicalNetwork = translateZoneIdToPhysicalNetwork(zoneId); - network = createNetwork(offerings.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, null, null, null, null, owner, false, null, null, false, physicalNetwork, zoneId); + network = createNetwork(offerings.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, null, null, null, null, owner, false, null, false, physicalNetwork, zoneId); if (network == null) { s_logger.warn("Failed to create default Virtual network for the account " + accountId + "in zone " + zoneId); @@ -4451,4 +4446,34 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag return true; } + + @Override + public List getNetworkTags(HypervisorType hType, Network network) { + Long physicalNetworkId = network.getPhysicalNetworkId(); + + if (physicalNetworkId != null) { + String networkTag = _pNTrafficTypeDao.getNetworkTag(physicalNetworkId, network.getTrafficType(), hType); + if (networkTag != null) { + return new ArrayList(Collections.singletonList(networkTag)); + } + } else { + List pNtwks = _physicalNetworkDao.listByZone(network.getDataCenterId()); + if (pNtwks.size() == 1) { + physicalNetworkId = pNtwks.get(0).getId(); + } else { + //locate physicalNetwork with supported traffic type + //We can make this assumptions based on the fact that Public/Management/Control traffic types are supported only in one physical network in the zone in 3.0 + for (PhysicalNetworkVO pNtwk : pNtwks) { + if (_pNTrafficTypeDao.isTrafficTypeSupported(pNtwk.getId(), network.getTrafficType())) { + physicalNetworkId = pNtwk.getId(); + break; + } + } + } + } + + //in all other cases return empty list + return new ArrayList(); + } + } diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index 8d66cbd5318..325d2f4f91b 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -18,19 +18,13 @@ package com.cloud.network; import java.net.URI; -import java.util.ArrayList; import java.util.Date; -import java.util.List; -import javax.persistence.CollectionTable; import javax.persistence.Column; -import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; -import javax.persistence.FetchType; import javax.persistence.Id; -import javax.persistence.JoinColumn; import javax.persistence.Table; import javax.persistence.TableGenerator; import javax.persistence.Transient; @@ -142,11 +136,6 @@ public class NetworkVO implements Network { @Column(name="is_default") boolean isDefault; - - @ElementCollection(targetClass = String.class, fetch=FetchType.EAGER) - @Column(name="tag") - @CollectionTable(name="network_tags", joinColumns=@JoinColumn(name="network_id")) - List tags; @Column(name="guest_type") @Enumerated(value=EnumType.STRING) @@ -254,22 +243,6 @@ public class NetworkVO implements Network { return id; } - @Override - public List getTags() { - return tags != null ? tags : new ArrayList(); - } - - public void addTag(String tag) { - if (tags == null) { - tags = new ArrayList(); - } - tags.add(tag); - } - - public void setTags(List tags) { - this.tags = tags; - } - @Override public Mode getMode() { return mode; diff --git a/server/src/com/cloud/network/dao/NetworkDaoImpl.java b/server/src/com/cloud/network/dao/NetworkDaoImpl.java index c4114d9dcb0..204d664139e 100644 --- a/server/src/com/cloud/network/dao/NetworkDaoImpl.java +++ b/server/src/com/cloud/network/dao/NetworkDaoImpl.java @@ -202,7 +202,6 @@ public class NetworkDaoImpl extends GenericDaoBase implements N NetworkOpVO op = new NetworkOpVO(network.getId(), gc); _opDao.persist(op); txn.commit(); - newNetwork.setTags(network.getTags()); return newNetwork; } diff --git a/server/src/com/cloud/network/dao/NetworkTagDaoImpl.java b/server/src/com/cloud/network/dao/NetworkTagDaoImpl.java deleted file mode 100644 index 5d8f79bee24..00000000000 --- a/server/src/com/cloud/network/dao/NetworkTagDaoImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. - * - * This software is licensed under the GNU General Public License v3 or later. - * - * It is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package com.cloud.network.dao; - -import java.util.List; - -import com.cloud.utils.db.GenericDao; -import com.cloud.utils.db.GenericDaoBase; -import com.cloud.utils.db.GenericSearchBuilder; -import com.cloud.utils.db.SearchBuilder; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.SearchCriteria.Op; - - -public class NetworkTagDaoImpl extends GenericDaoBase implements GenericDao { - private final GenericSearchBuilder TagSearch; - private final SearchBuilder AllFieldsSearch; - - protected NetworkTagDaoImpl() { - super(); - TagSearch = createSearchBuilder(String.class); - TagSearch.selectField(TagSearch.entity().getTag()); - TagSearch.and("networkid", TagSearch.entity().getNetworkId(), Op.EQ); - TagSearch.done(); - - AllFieldsSearch = createSearchBuilder(); - AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ); - AllFieldsSearch.and("networkid", AllFieldsSearch.entity().getNetworkId(), Op.EQ); - AllFieldsSearch.and("tag", AllFieldsSearch.entity().getTag(), Op.EQ); - AllFieldsSearch.done(); - } - - public List getTags(long networkId) { - SearchCriteria sc = TagSearch.create(); - sc.setParameters("networkid", networkId); - - return customSearch(sc, null); - } - - public int clearTags(long networkId) { - SearchCriteria sc = AllFieldsSearch.create(); - sc.setParameters("networkid", networkId); - - return remove(sc); - } - -} diff --git a/server/src/com/cloud/network/dao/NetworkTagVO.java b/server/src/com/cloud/network/dao/NetworkTagVO.java deleted file mode 100644 index 1afd0339fe9..00000000000 --- a/server/src/com/cloud/network/dao/NetworkTagVO.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. - * - * This software is licensed under the GNU General Public License v3 or later. - * - * It is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package com.cloud.network.dao; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -/** - * This class is just used to work with the DAO. It shouldn't be used anywhere. - * - */ -@Entity -@Table(name = "network_tags") -public class NetworkTagVO { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id") - private long id; - - @Column(name = "network_id") - private long networkId; - - @Column(name = "tag") - private String tag; - - /** - * There should never be a public constructor for this class. Since it's - * only here to define the table for the DAO class. - */ - protected NetworkTagVO() { - } - - protected NetworkTagVO(long networkId, String tag) { - this.networkId = networkId; - this.tag = tag; - } - - public long getId() { - return id; - } - - public long getNetworkId() { - return networkId; - } - - public String getTag() { - return tag; - } -} diff --git a/server/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java b/server/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java index f8b2c06c19f..6b4817b8e95 100644 --- a/server/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java +++ b/server/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDao.java @@ -19,10 +19,12 @@ package com.cloud.network.dao; import java.util.List; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.Networks.TrafficType; import com.cloud.utils.db.GenericDao; public interface PhysicalNetworkTrafficTypeDao extends GenericDao { List listBy(long physicalNetworkId); boolean isTrafficTypeSupported(long physicalNetworkId, TrafficType trafficType); + String getNetworkTag (long physicalNetworkId, TrafficType trafficType, HypervisorType hType); } diff --git a/server/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDaoImpl.java b/server/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDaoImpl.java index 0dcba8f8952..856a8fc98d9 100644 --- a/server/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDaoImpl.java +++ b/server/src/com/cloud/network/dao/PhysicalNetworkTrafficTypeDaoImpl.java @@ -21,6 +21,7 @@ import java.util.List; import javax.ejb.Local; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.Networks.TrafficType; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; @@ -31,6 +32,9 @@ import com.cloud.utils.db.SearchCriteria.Op; @Local(value=PhysicalNetworkTrafficTypeDao.class) @DB(txn=false) public class PhysicalNetworkTrafficTypeDaoImpl extends GenericDaoBase implements PhysicalNetworkTrafficTypeDao { final SearchBuilder physicalNetworkSearch; + final SearchBuilder kvmAllFieldsSearch; + final SearchBuilder xenAllFieldsSearch; + final SearchBuilder vmWareAllFieldsSearch; protected PhysicalNetworkTrafficTypeDaoImpl() { super(); @@ -38,7 +42,24 @@ public class PhysicalNetworkTrafficTypeDaoImpl extends GenericDaoBase sc = null; + if (hType == HypervisorType.XenServer) { + sc = xenAllFieldsSearch.create(); + } else if (hType == HypervisorType.KVM) { + sc = kvmAllFieldsSearch.create(); + } else if (hType == HypervisorType.VMware) { + sc = vmWareAllFieldsSearch.create(); + } else { + return null; + } + + sc.setParameters("physicalNetworkId", physicalNetworkId); + sc.setParameters("trafficType", trafficType); + PhysicalNetworkTrafficTypeVO record = findOneBy(sc); + + if (record != null) { + if (hType == HypervisorType.XenServer) { + return record.getXenNetworkLabel(); + } else if (hType == HypervisorType.KVM) { + return record.getKvmNetworkLabel(); + } else if (hType == HypervisorType.VMware) { + return record.getVmwareNetworkLabel(); + } + } + return null; + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 38517ad81a0..151e508ab5d 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -2189,7 +2189,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian IpAddressTO ip = new IpAddressTO(ipAddr.getAccountId(), ipAddr.getAddress().addr(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress, networkRate, ipAddr.isOneToOneNat()); ip.setTrafficType(network.getTrafficType()); - ip.setNetworkTags(network.getTags()); + ip.setNetworkTags(_networkMgr.getNetworkTags(router.getHypervisorType(), network)); ipsToSend[i++] = ip; firstIP = false; } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 8b47cab543f..a55b4cfc882 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -424,7 +424,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId()); - NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkMgr.isSecurityGroupSupportedInNetwork(defaultNetwork)); + NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkMgr.isSecurityGroupSupportedInNetwork(defaultNetwork), _networkMgr.getNetworkTags(template.getHypervisorType(), defaultNetwork)); VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance); vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password); @@ -2186,7 +2186,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (virtualNetworks.isEmpty()) { s_logger.debug("Creating default Virtual network for account " + owner + " as a part of deployVM process"); Network newNetwork = _networkMgr.createNetwork(defaultVirtualOffering.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, null, - null, null, null, owner, false, null, null, false, physicalNetwork, zone.getId()); + null, null, null, owner, false, null, false, physicalNetwork, zone.getId()); defaultNetwork = _networkDao.findById(newNetwork.getId()); } else if (virtualNetworks.size() > 1) { throw new InvalidParameterValueException("More than 1 default Virtaul networks are found for account " + owner + "; please specify networkIds"); @@ -2199,7 +2199,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (defaultVirtualOffering.get(0).getAvailability() == Availability.Optional) { s_logger.debug("Creating default Virtual network for account " + owner + " as a part of deployVM process"); Network newNetwork = _networkMgr.createNetwork(defaultVirtualOffering.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, null, - null, null, null, owner, false, null, null, false, physicalNetwork, zone.getId()); + null, null, null, owner, false, null, false, physicalNetwork, zone.getId()); defaultNetwork = _networkDao.findById(newNetwork.getId()); } else { throw new InvalidParameterValueException("Unable to find default networks for account " + owner); @@ -3355,7 +3355,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager List virtualNetworks = _networkMgr.listNetworksForAccount(newAccount.getId(), zone.getId(), Network.GuestType.Isolated, true); if (virtualNetworks.isEmpty()) { Network newNetwork = _networkMgr.createNetwork(networkOffering, newAccount.getAccountName() + "-network", newAccount.getAccountName() + "-network", null, null, - null, null, null, newAccount, false, null, null, false, physicalNetwork, zone.getId()); + null, null, null, newAccount, false, null, false, physicalNetwork, zone.getId()); defaultNetwork = _networkDao.findById(newNetwork.getId()); } else if (virtualNetworks.size() > 1) { throw new InvalidParameterValueException("More than 1 default Virtaul networks are found for account " + newAccount + "; please specify networkIds"); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 42a7051e422..27da5fc3b3b 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1836,7 +1836,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene List nics = _nicsDao.listByVmId(profile.getId()); for (NicVO nic : nics) { Network network = _networkMgr.getNetwork(nic.getNetworkId()); - NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkMgr.isSecurityGroupSupportedInNetwork(network)); + NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTags(profile.getHypervisorType(), network)); profile.addNic(nicProfile); } diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index 6c40bcedb0d..4b1182fc3ba 100644 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -206,7 +206,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS @Override public List setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean errorIfAlreadySetup, - Long domainId, List tags, boolean isShared) throws ConcurrentOperationException { + Long domainId, boolean isShared) throws ConcurrentOperationException { // TODO Auto-generated method stub return null; } @@ -341,7 +341,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS @Override public Network createNetwork(long networkOfferingId, String name, String displayText, Boolean isDefault, String gateway, String cidr, String vlanId, String networkDomain, Account owner, - boolean isSecurityGroupEnabled, Long domainId, List tags, Boolean isShared, PhysicalNetwork physicalNetwork, long zoneId) throws ConcurrentOperationException, InsufficientCapacityException { + boolean isSecurityGroupEnabled, Long domainId, Boolean isShared, PhysicalNetwork physicalNetwork, long zoneId) throws ConcurrentOperationException, InsufficientCapacityException { // TODO Auto-generated method stub return null; } diff --git a/server/test/com/cloud/network/dao/NetworkDaoTest.java b/server/test/com/cloud/network/dao/NetworkDaoTest.java index 81b95246319..37ea2d1a8c4 100644 --- a/server/test/com/cloud/network/dao/NetworkDaoTest.java +++ b/server/test/com/cloud/network/dao/NetworkDaoTest.java @@ -1,57 +1,46 @@ package com.cloud.network.dao; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.Assert; import junit.framework.TestCase; -import com.cloud.network.Network.GuestIpType; -import com.cloud.network.NetworkVO; -import com.cloud.network.Networks.BroadcastDomainType; -import com.cloud.network.Networks.Mode; -import com.cloud.network.Networks.TrafficType; -import com.cloud.utils.component.ComponentLocator; - public class NetworkDaoTest extends TestCase { public void testTags() { - NetworkDaoImpl dao = ComponentLocator.inject(NetworkDaoImpl.class); - - dao.expunge(1001l); - NetworkVO network = new NetworkVO(1001, TrafficType.Control, GuestIpType.Direct, Mode.Dhcp, BroadcastDomainType.Native, 1, 1, 1, 1, 1001, "Name", "DisplayText", false, true, true, null, null); - network.setGuruName("guru_name"); - List tags = new ArrayList(); - - tags.add("a"); - tags.add("b"); - network.setTags(tags); - - network = dao.persist(network); - List saveTags = network.getTags(); - Assert.assertTrue(saveTags.size() == 2 && saveTags.contains("a") && saveTags.contains("b")); - - NetworkVO retrieved = dao.findById(1001l); - List retrievedTags = retrieved.getTags(); - Assert.assertTrue(retrievedTags.size() == 2 && retrievedTags.contains("a") && retrievedTags.contains("b")); - - List updateTags = new ArrayList(); - updateTags.add("e"); - updateTags.add("f"); - retrieved.setTags(updateTags); - dao.update(retrieved.getId(), retrieved); - - retrieved = dao.findById(1001l); - retrievedTags = retrieved.getTags(); - Assert.assertTrue("Unable to retrieve back the data updated", retrievedTags.size() == 2 && retrievedTags.contains("e") && retrievedTags.contains("f")); - - dao.expunge(1001l); +// NetworkDaoImpl dao = ComponentLocator.inject(NetworkDaoImpl.class); +// +// dao.expunge(1001l); +// NetworkVO network = new NetworkVO(1001, TrafficType.Control, GuestType.Shared, Mode.Dhcp, BroadcastDomainType.Native, 1, 1, 1, 1, 1001, "Name", "DisplayText", false, true, true, null, null); +// network.setGuruName("guru_name"); +// List tags = new ArrayList(); +// +// tags.add("a"); +// tags.add("b"); +// network.setTags(tags); +// +// network = dao.persist(network); +// List saveTags = network.getTags(); +// Assert.assertTrue(saveTags.size() == 2 && saveTags.contains("a") && saveTags.contains("b")); +// +// NetworkVO retrieved = dao.findById(1001l); +// List retrievedTags = retrieved.getTags(); +// Assert.assertTrue(retrievedTags.size() == 2 && retrievedTags.contains("a") && retrievedTags.contains("b")); +// +// List updateTags = new ArrayList(); +// updateTags.add("e"); +// updateTags.add("f"); +// retrieved.setTags(updateTags); +// dao.update(retrieved.getId(), retrieved); +// +// retrieved = dao.findById(1001l); +// retrievedTags = retrieved.getTags(); +// Assert.assertTrue("Unable to retrieve back the data updated", retrievedTags.size() == 2 && retrievedTags.contains("e") && retrievedTags.contains("f")); +// +// dao.expunge(1001l); } public void testListBy() { - NetworkDaoImpl dao = ComponentLocator.inject(NetworkDaoImpl.class); - - dao.listBy(1l, 1l, 1l, "192.168.192.0/24"); +// NetworkDaoImpl dao = ComponentLocator.inject(NetworkDaoImpl.class); +// +// dao.listBy(1l, 1l, 1l, "192.168.192.0/24"); } } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 5fc0acb503a..1cd90d05255 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -198,15 +198,6 @@ CREATE TABLE `cloud`.`networks` ( INDEX `i_networks__removed`(`removed`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `cloud`.`network_tags` ( - `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', - `network_id` bigint unsigned NOT NULL COMMENT 'id of the network', - `tag` varchar(255) NOT NULL COMMENT 'tag', - PRIMARY KEY (`id`), - CONSTRAINT `fk_network_tags__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`) ON DELETE CASCADE, - UNIQUE KEY(`network_id`, `tag`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - CREATE TABLE `cloud`.`account_network_ref` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', `account_id` bigint unsigned NOT NULL COMMENT 'account id',