1) Removed tags from the network object

2) Get hypervisor tags from the physical network instead.
This commit is contained in:
alena 2011-11-01 17:41:35 -07:00
parent da78937d30
commit 2250dff349
22 changed files with 147 additions and 282 deletions

View File

@ -163,11 +163,6 @@ public class CreateNetworkCmd extends BaseCmd {
return zoneId;
}
public List<String> getTags() {
//FIXME - remove this method
return null;
}
public Long getPhysicalNetworkId() {
NetworkOffering offering = _configService.getNetworkOffering(networkOfferingId);
if (offering == null) {

View File

@ -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<String> 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;

View File

@ -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;

View File

@ -269,8 +269,6 @@ public interface Network extends ControlledEntity {
String getNetworkDomain();
List<String> getTags();
GuestType getGuestType();
boolean getIsShared();

View File

@ -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<String> 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<String> getTags() {
return tags;
}
public String getDns1() {
return dns1;
}

View File

@ -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<String> 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;

View File

@ -2192,9 +2192,6 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setDns1(profile.getDns1());
response.setDns2(profile.getDns2());
response.setTags(network.getTags());
// populate capability
Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(networkOffering.getId(), network.getDataCenterId());
List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();

View File

@ -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);
}
}
}

View File

@ -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<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean errorIfAlreadySetup,
Long domainId, List<String> tags, boolean isShared) throws ConcurrentOperationException;
Long domainId, boolean isShared) throws ConcurrentOperationException;
List<NetworkOfferingVO> 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<String> 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<String> getNetworkTags(HypervisorType hType, Network network);
}

View File

@ -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<NetworkVO> 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<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean errorIfAlreadySetup,
Long domainId, List<String> 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<String> 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<String> 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<NetworkVO> networks = setupNetwork(owner, networkOffering, userNetwork, plan, name, displayText, isDefault, true, domainId, tags, isShared);
List<NetworkVO> 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<? extends NetworkOffering> 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<String> 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<String>(Collections.singletonList(networkTag));
}
} else {
List<PhysicalNetworkVO> 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<String>();
}
}

View File

@ -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;
@ -143,11 +137,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<String> tags;
@Column(name="guest_type")
@Enumerated(value=EnumType.STRING)
Network.GuestType guestType;
@ -254,22 +243,6 @@ public class NetworkVO implements Network {
return id;
}
@Override
public List<String> getTags() {
return tags != null ? tags : new ArrayList<String>();
}
public void addTag(String tag) {
if (tags == null) {
tags = new ArrayList<String>();
}
tags.add(tag);
}
public void setTags(List<String> tags) {
this.tags = tags;
}
@Override
public Mode getMode() {
return mode;

View File

@ -202,7 +202,6 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
NetworkOpVO op = new NetworkOpVO(network.getId(), gc);
_opDao.persist(op);
txn.commit();
newNetwork.setTags(network.getTags());
return newNetwork;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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<NetworkTagVO, Long> implements GenericDao<NetworkTagVO, Long> {
private final GenericSearchBuilder<NetworkTagVO, String> TagSearch;
private final SearchBuilder<NetworkTagVO> 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<String> getTags(long networkId) {
SearchCriteria<String> sc = TagSearch.create();
sc.setParameters("networkid", networkId);
return customSearch(sc, null);
}
public int clearTags(long networkId) {
SearchCriteria<NetworkTagVO> sc = AllFieldsSearch.create();
sc.setParameters("networkid", networkId);
return remove(sc);
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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;
}
}

View File

@ -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<PhysicalNetworkTrafficTypeVO, Long> {
List<PhysicalNetworkTrafficTypeVO> listBy(long physicalNetworkId);
boolean isTrafficTypeSupported(long physicalNetworkId, TrafficType trafficType);
String getNetworkTag (long physicalNetworkId, TrafficType trafficType, HypervisorType hType);
}

View File

@ -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<PhysicalNetworkTrafficTypeVO, Long> implements PhysicalNetworkTrafficTypeDao {
final SearchBuilder<PhysicalNetworkTrafficTypeVO> physicalNetworkSearch;
final SearchBuilder<PhysicalNetworkTrafficTypeVO> kvmAllFieldsSearch;
final SearchBuilder<PhysicalNetworkTrafficTypeVO> xenAllFieldsSearch;
final SearchBuilder<PhysicalNetworkTrafficTypeVO> vmWareAllFieldsSearch;
protected PhysicalNetworkTrafficTypeDaoImpl() {
super();
@ -39,6 +43,23 @@ public class PhysicalNetworkTrafficTypeDaoImpl extends GenericDaoBase<PhysicalNe
physicalNetworkSearch.and("trafficType", physicalNetworkSearch.entity().getTrafficType(), Op.EQ);
physicalNetworkSearch.done();
kvmAllFieldsSearch = createSearchBuilder();
kvmAllFieldsSearch.and("physicalNetworkId", kvmAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
kvmAllFieldsSearch.and("trafficType", kvmAllFieldsSearch.entity().getTrafficType(), Op.EQ);
kvmAllFieldsSearch.and("kvm_network_label", kvmAllFieldsSearch.entity().getKvmNetworkLabel(), Op.NNULL);
kvmAllFieldsSearch.done();
xenAllFieldsSearch = createSearchBuilder();
xenAllFieldsSearch.and("physicalNetworkId", xenAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
xenAllFieldsSearch.and("trafficType", xenAllFieldsSearch.entity().getTrafficType(), Op.EQ);
xenAllFieldsSearch.and("xen_network_label", xenAllFieldsSearch.entity().getKvmNetworkLabel(), Op.NNULL);
xenAllFieldsSearch.done();
vmWareAllFieldsSearch = createSearchBuilder();
vmWareAllFieldsSearch.and("physicalNetworkId", vmWareAllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ);
vmWareAllFieldsSearch.and("trafficType", vmWareAllFieldsSearch.entity().getTrafficType(), Op.EQ);
vmWareAllFieldsSearch.and("vmware_network_label", vmWareAllFieldsSearch.entity().getKvmNetworkLabel(), Op.NNULL);
vmWareAllFieldsSearch.done();
}
@Override
@ -59,4 +80,33 @@ public class PhysicalNetworkTrafficTypeDaoImpl extends GenericDaoBase<PhysicalNe
return false;
}
}
@Override
public String getNetworkTag(long physicalNetworkId, TrafficType trafficType, HypervisorType hType) {
SearchCriteria<PhysicalNetworkTrafficTypeVO> 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;
}
}

View File

@ -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;
}

View File

@ -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<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(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<NetworkVO> 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");

View File

@ -1836,7 +1836,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
List<NicVO> 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);
}

View File

@ -206,7 +206,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
@Override
public List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isDefault, boolean errorIfAlreadySetup,
Long domainId, List<String> 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<String> 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;
}

View File

@ -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<String> tags = new ArrayList<String>();
tags.add("a");
tags.add("b");
network.setTags(tags);
network = dao.persist(network);
List<String> saveTags = network.getTags();
Assert.assertTrue(saveTags.size() == 2 && saveTags.contains("a") && saveTags.contains("b"));
NetworkVO retrieved = dao.findById(1001l);
List<String> retrievedTags = retrieved.getTags();
Assert.assertTrue(retrievedTags.size() == 2 && retrievedTags.contains("a") && retrievedTags.contains("b"));
List<String> updateTags = new ArrayList<String>();
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<String> tags = new ArrayList<String>();
//
// tags.add("a");
// tags.add("b");
// network.setTags(tags);
//
// network = dao.persist(network);
// List<String> saveTags = network.getTags();
// Assert.assertTrue(saveTags.size() == 2 && saveTags.contains("a") && saveTags.contains("b"));
//
// NetworkVO retrieved = dao.findById(1001l);
// List<String> retrievedTags = retrieved.getTags();
// Assert.assertTrue(retrievedTags.size() == 2 && retrievedTags.contains("a") && retrievedTags.contains("b"));
//
// List<String> updateTags = new ArrayList<String>();
// 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");
}
}

View File

@ -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',