bug 9579: allow domain name suffix update for existing networks.

Block update only in these cases:

* when DNS capability AllowDnsSuffixModification is false for the network
* when target network has running network elements (dhcps or domRs)

Conflicts:

	server/src/com/cloud/vm/dao/DomainRouterDao.java
	server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java
This commit is contained in:
alena 2011-06-09 16:24:07 -07:00
parent 7e2fe6b6c9
commit 53bdd625b8
18 changed files with 116 additions and 69 deletions

View File

@ -27,6 +27,7 @@ import com.cloud.api.BaseCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.NetworkResponse;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
@ -55,6 +56,9 @@ public class UpdateNetworkCmd extends BaseCmd {
@Parameter(name=ApiConstants.TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="tags for the network")
private List<String> tags;
@Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
private String networkDomain;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -76,6 +80,10 @@ public class UpdateNetworkCmd extends BaseCmd {
return tags;
}
private String getNetworkDomain() {
return networkDomain;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
@ -99,7 +107,7 @@ public class UpdateNetworkCmd extends BaseCmd {
@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException{
Network result = _networkService.updateNetwork(getId(), getNetworkName(), getDisplayText(), tags, UserContext.current().getCaller());
Network result = _networkService.updateNetwork(getId(), getNetworkName(), getDisplayText(), tags, UserContext.current().getCaller(), getNetworkDomain());
if (result != null) {
NetworkResponse response = _responseGenerator.createNetworkResponse(result);
response.setResponseName(getCommandName());

View File

@ -47,7 +47,7 @@ public interface Network extends ControlledEntity {
public static final Service Vpn = new Service("Vpn", Capability.SupportedVpnTypes);
public static final Service Dhcp = new Service("Dhcp");
public static final Service Dns = new Service("Dns");
public static final Service Dns = new Service("Dns", Capability.AllowDnsSuffixModification);
public static final Service Gateway = new Service("Gateway");
public static final Service Firewall = new Service("Firewall", Capability.PortForwarding, Capability.StaticNat, Capability.SupportedProtocols, Capability.MultipleIps, Capability.SupportedSourceNatTypes, Capability.TrafficStatistics);
public static final Service Lb = new Service("Lb", Capability.SupportedLBAlgorithms, Capability.SupportedProtocols, Capability.TrafficStatistics, Capability.LoadBalancingSupportedIps);
@ -117,6 +117,7 @@ public interface Network extends ControlledEntity {
public static final Capability SupportedVpnTypes = new Capability("SupportedVpnTypes");
public static final Capability TrafficStatistics = new Capability("TrafficStatistics");
public static final Capability LoadBalancingSupportedIps = new Capability("LoadBalancingSupportedIps");
public static final Capability AllowDnsSuffixModification = new Capability("AllowDnsSuffixModification");
private String name;

View File

@ -75,13 +75,13 @@ public interface NetworkService {
Map<Service, Map<Capability, String>> getZoneCapabilities(long zoneId);
Map<Service, Map<Capability, String>> getNetworkCapabilities(long networkId);
Map<Service, Map<Capability, String>> getNetworkCapabilities(long networkId, long zoneId);
boolean isNetworkAvailableInDomain(long networkId, long domainId);
Long getDedicatedNetworkDomain(long networkId);
Network updateNetwork(long networkId, String name, String displayText, List<String> tags, Account caller);
Network updateNetwork(long networkId, String name, String displayText, List<String> tags, Account caller, String domainSuffix);
Integer getNetworkRate(long networkId, Long vmId);

View File

@ -533,8 +533,8 @@ public class ApiDBUtils {
return _networkDao.findById(id);
}
public static Map<Service, Map<Capability, String>> getNetworkCapabilities(long networkId) {
return _networkMgr.getNetworkCapabilities(networkId);
public static Map<Service, Map<Capability, String>> getNetworkCapabilities(long networkOfferingId, long zoneId) {
return _networkMgr.getNetworkCapabilities(networkOfferingId, zoneId);
}
public static long getPublicNetworkIdByZone(long zoneId) {

View File

@ -2484,7 +2484,7 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setTags(network.getTags());
// populate capability
Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(network.getId());
Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(networkOffering.getId(), network.getDataCenterId());
List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
if (serviceCapabilitiesMap != null) {
for (Service service : serviceCapabilitiesMap.keySet()) {

View File

@ -188,7 +188,7 @@ public interface NetworkManager extends NetworkService {
boolean zoneIsConfiguredForExternalNetworking(long zoneId);
Map<Capability, String> getServiceCapabilities(long zoneId, Service service);
Map<Capability, String> getServiceCapabilities(long zoneId, Long networkOfferingId, Service service);
boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException;

View File

@ -133,6 +133,7 @@ import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
@ -143,6 +144,7 @@ import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
@ -211,6 +213,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
NetworkDomainDao _networkDomainDao;
@Inject
VMInstanceDao _vmDao;
@Inject DomainRouterDao _routerDao;
private final HashMap<String, NetworkOfferingVO> _systemNetworks = new HashMap<String, NetworkOfferingVO>(5);
@ -903,7 +907,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
NetworkVO vo = new NetworkVO(id, network, offering.getId(), plan.getDataCenterId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText, isShared, isDefault,
predefined.isSecurityGroupEnabled(), (domainId != null));
predefined.isSecurityGroupEnabled(), (domainId != null), predefined.getNetworkDomain());
vo.setTags(tags);
networks.add(_networksDao.persist(vo, vo.getGuestType() != null));
@ -1675,14 +1679,22 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
// If networkDomain is not specified, take it from the global configuration
if (networkDomain == null) {
networkDomain = "cs" + Long.toHexString(owner.getId()) + _networkDomain;
Map<Network.Capability, String> dnsCapabilities = getServiceCapabilities(zoneId, networkOfferingId, Service.Dns);
String isUpdateDnsSupported = dnsCapabilities.get(Capability.AllowDnsSuffixModification);
if (isUpdateDnsSupported == null || !Boolean.valueOf(isUpdateDnsSupported)) {
if (networkDomain != null) {
throw new InvalidParameterValueException("Domain name change is not supported by network offering id=" + networkOfferingId + " in zone id=" + zoneId);
}
} else {
// validate network domain
if (!NetUtils.verifyDomainName(networkDomain)) {
throw new InvalidParameterValueException(
"Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', "
+ "and the hyphen ('-'); can't start or end with \"-\"");
if (networkDomain == null) {
networkDomain = "cs" + Long.toHexString(owner.getId()) + _networkDomain;
} else {
// validate network domain
if (!NetUtils.verifyDomainName(networkDomain)) {
throw new InvalidParameterValueException(
"Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters 'a' through 'z', the digits '0' through '9', "
+ "and the hyphen ('-'); can't start or end with \"-\"");
}
}
}
@ -2420,17 +2432,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
public Map<Service, Map<Capability, String>> getNetworkCapabilities(long networkId) {
Network network = getNetwork(networkId);
if (network == null) {
throw new InvalidParameterValueException("Unable to find network by id " + networkId);
}
public Map<Service, Map<Capability, String>> getNetworkCapabilities(long networkOfferingId, long zoneId) {
Map<Service, Map<Capability, String>> zoneCapabilities = getZoneCapabilities(network.getDataCenterId());
Map<Service, Map<Capability, String>> zoneCapabilities = getZoneCapabilities(zoneId);
Map<Service, Map<Capability, String>> networkCapabilities = new HashMap<Service, Map<Capability, String>>();
for (Service service : zoneCapabilities.keySet()) {
if (isServiceSupported(networkId, service)) {
if (isServiceSupported(networkOfferingId, service)) {
networkCapabilities.put(service, zoneCapabilities.get(service));
}
}
@ -2439,7 +2447,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
public Map<Capability, String> getServiceCapabilities(long zoneId, Service service) {
public Map<Capability, String> getServiceCapabilities(long zoneId, Long networkOfferingId, Service service) {
if (!isServiceSupported(networkOfferingId, service)) {
throw new UnsupportedServiceException("Service " + service.getName() + " is not by the network offering id=" + networkOfferingId);
}
Map<Service, Map<Capability, String>> networkCapabilities = getZoneCapabilities(zoneId);
if (networkCapabilities.get(service) == null) {
throw new UnsupportedServiceException("Service " + service.getName() + " is not supported in zone id=" + zoneId);
@ -2673,9 +2686,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
public boolean isServiceSupported(long networkId, Network.Service service) {
Network network = getNetwork(networkId);
NetworkOffering offering = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
public boolean isServiceSupported(long networkOfferingId, Network.Service service) {
NetworkOffering offering = _configMgr.getNetworkOffering(networkOfferingId);
if (service == Service.Lb) {
return offering.isLbService();
} else if (service == Service.Dhcp) {
@ -2761,7 +2773,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
NetworkOfferingVO no = _networkOfferingDao.findById(network.getNetworkOfferingId());
if (!no.isSystemOnly()) {
if (network.getIsShared() || !_networksDao.listBy(accountId, network.getId()).isEmpty()) {
if ((guestType == null || guestType == network.getGuestType()) && (isDefault == null || isDefault == network.isDefault)) {
if ((guestType == null || guestType == network.getGuestType()) && (isDefault == null || isDefault.booleanValue() == network.isDefault)) {
accountNetworks.add(network);
}
}
@ -2858,7 +2870,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_UPDATE, eventDescription = "updating network", async = false)
public Network updateNetwork(long networkId, String name, String displayText, List<String> tags, Account caller) {
public Network updateNetwork(long networkId, String name, String displayText, List<String> tags, Account caller, String domainSuffix) {
// verify input parameters
NetworkVO network = _networksDao.findById(networkId);
@ -2875,6 +2887,23 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (offering.isSystemOnly()) {
throw new InvalidParameterValueException("Can't update system networks");
}
//don't allow to modify network domain if the service is not supported
if (domainSuffix != null) {
Map<Network.Capability, String> dnsCapabilities = getServiceCapabilities(network.getDataCenterId(), network.getNetworkOfferingId(), Service.Dns);
String isUpdateDnsSupported = dnsCapabilities.get(Capability.AllowDnsSuffixModification);
if (isUpdateDnsSupported == null || !Boolean.valueOf(isUpdateDnsSupported)) {
throw new InvalidParameterValueException("Domain name change is not supported for network id=" + network.getNetworkOfferingId() + " in zone id=" + network.getDataCenterId());
}
List<DomainRouterVO> routers = _routerDao.listActive(networkId);
if (!routers.isEmpty()) {
throw new CloudRuntimeException("Unable to update network id=" + networkId + " with new network domain as the network has running network elements");
}
network.setNetworkDomain(domainSuffix);
}
_accountMgr.checkAccess(caller, network);

View File

@ -178,15 +178,14 @@ public class NetworkVO implements Network {
this.guestType = guestType;
}
public NetworkVO(long id, Network that, long offeringId, long dataCenterId, String guruName, long domainId, long accountId, long related, String name, String displayText, Boolean isShared, boolean isDefault, boolean isSecurityGroupEnabled, boolean isDomainSpecific) {
this(id, that.getTrafficType(), that.getGuestType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related, name, displayText, isShared, isDefault, isDomainSpecific);
public NetworkVO(long id, Network that, long offeringId, long dataCenterId, String guruName, long domainId, long accountId, long related, String name, String displayText, Boolean isShared, boolean isDefault, boolean isSecurityGroupEnabled, boolean isDomainSpecific, String networkDomain) {
this(id, that.getTrafficType(), that.getGuestType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related, name, displayText, isShared, isDefault, isDomainSpecific, networkDomain);
this.gateway = that.getGateway();
this.cidr = that.getCidr();
this.broadcastUri = that.getBroadcastUri();
this.broadcastDomainType = that.getBroadcastDomainType();
this.guruName = guruName;
this.state = that.getState();
this.networkDomain = that.getNetworkDomain();
this.securityGroupEnabled = isSecurityGroupEnabled;
if (state == null) {
state = State.Allocated;
@ -207,8 +206,9 @@ public class NetworkVO implements Network {
* @param isShared
* @param isDefault
* @param isDomainSpecific
* @param networkDomain
*/
public NetworkVO(long id, TrafficType trafficType, GuestIpType guestType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long dataCenterId, long domainId, long accountId, long related, String name, String displayText, Boolean isShared, boolean isDefault, boolean isDomainSpecific) {
public NetworkVO(long id, TrafficType trafficType, GuestIpType guestType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long dataCenterId, long domainId, long accountId, long related, String name, String displayText, Boolean isShared, boolean isDefault, boolean isDomainSpecific, String networkDomain) {
this(trafficType, guestType, mode, broadcastDomainType, networkOfferingId, dataCenterId, State.Allocated);
this.domainId = domainId;
this.accountId = accountId;
@ -219,6 +219,7 @@ public class NetworkVO implements Network {
this.isShared = isShared;
this.isDefault = isDefault;
this.isDomainSpecific = isDomainSpecific;
this.networkDomain = networkDomain;
}
@Override

View File

@ -179,7 +179,10 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password
private static Map<Service, Map<Capability, String>> setCapabilities() {
Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
capabilities.put(Service.Dns, null);
Map<Capability, String> dnsCapabilities = new HashMap<Capability, String>();
dnsCapabilities.put(Capability.AllowDnsSuffixModification, "true");
capabilities.put(Service.Dns, dnsCapabilities);
capabilities.put(Service.UserData, null);
capabilities.put(Service.Dhcp, null);

View File

@ -257,9 +257,12 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
//Set capabilities for vpn
Map<Capability, String> vpnCapabilities = new HashMap<Capability, String>();
vpnCapabilities.put(Capability.SupportedVpnTypes, "pptp,l2tp,ipsec");
capabilities.put(Service.Vpn, vpnCapabilities);
capabilities.put(Service.Dns, null);
Map<Capability, String> dnsCapabilities = new HashMap<Capability, String>();
dnsCapabilities.put(Capability.AllowDnsSuffixModification, "true");
capabilities.put(Service.Dns, dnsCapabilities);
capabilities.put(Service.UserData, null);
capabilities.put(Service.Dhcp, null);
capabilities.put(Service.Gateway, null);

View File

@ -122,6 +122,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
if (userSpecified.getBroadcastDomainType() != null) {
config.setBroadcastDomainType(userSpecified.getBroadcastDomainType());
}
}
if (config.isSecurityGroupEnabled()) {

View File

@ -118,9 +118,6 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
network.setBroadcastUri(userSpecified.getBroadcastUri());
network.setState(State.Setup);
}
if (userSpecified.getNetworkDomain() != null) {
network.setNetworkDomain(userSpecified.getNetworkDomain());
}
} else {
String guestNetworkCidr = dc.getGuestNetworkCidr();

View File

@ -49,6 +49,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.IPAddressVO;
import com.cloud.network.LoadBalancerVMMapVO;
import com.cloud.network.LoadBalancerVO;
import com.cloud.network.Network;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkManager;
import com.cloud.network.dao.FirewallRulesDao;
@ -388,7 +389,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
_accountMgr.checkAccess(caller.getCaller(), ipAddr);
// verify that lb service is supported by the network
if (!_networkMgr.isServiceSupported(networkId, Service.Lb)) {
Network network = _networkMgr.getNetwork(networkId);
if (!_networkMgr.isServiceSupported(network.getNetworkOfferingId(), Service.Lb)) {
throw new InvalidParameterValueException("LB service is not supported in network id=" + networkId);
}

View File

@ -233,13 +233,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
Network network = _networkMgr.getNetwork(networkId);
assert network != null : "Can't create port forwarding rule as network associated with public ip address is null...how is it possible?";
// verify that firewall service is supported by the network
if (!_networkMgr.isServiceSupported(networkId, Service.Firewall)) {
throw new InvalidParameterValueException("Firewall service is not supported in network id=" + networkId);
}
// Verify that the network guru supports the protocol specified
Map<Network.Capability, String> firewallCapabilities = _networkMgr.getServiceCapabilities(network.getDataCenterId(), Service.Firewall);
Map<Network.Capability, String> firewallCapabilities = _networkMgr.getServiceCapabilities(network.getDataCenterId(), network.getNetworkOfferingId(), Service.Firewall);
String supportedProtocols = firewallCapabilities.get(Capability.SupportedProtocols).toLowerCase();
if (!supportedProtocols.contains(rule.getProtocol().toLowerCase())) {
throw new InvalidParameterValueException("Protocol " + rule.getProtocol() + " is not supported in zone " + network.getDataCenterId());
@ -323,13 +318,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
assert (guestNic != null && guestNic.getIp4Address() != null) : "Vm doesn't belong to network associated with ipAddress or ip4 address is null...how is it possible?";
String dstIp = guestNic.getIp4Address();
// verify that firewall service is supported by the network
if (!_networkMgr.isServiceSupported(networkId, Service.Firewall)) {
throw new InvalidParameterValueException("Firewall service is not supported in network id=" + networkId);
}
// Verify that the network guru supports the protocol specified
Map<Network.Capability, String> firewallCapability = _networkMgr.getServiceCapabilities(network.getDataCenterId(), Service.Firewall);
Map<Network.Capability, String> firewallCapability = _networkMgr.getServiceCapabilities(network.getDataCenterId(), network.getNetworkOfferingId(), Service.Firewall);
String supportedProtocols = firewallCapability.get(Capability.SupportedProtocols).toLowerCase();
if (!supportedProtocols.contains(rule.getProtocol().toLowerCase())) {
throw new InvalidParameterValueException("Protocol " + rule.getProtocol() + " is not supported in zone " + network.getDataCenterId());
@ -396,7 +386,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
throw new InvalidParameterValueException("Vm doesn't belong to the network " + networkId);
}
if (!_networkMgr.isServiceSupported(networkId, Service.Firewall)) {
Network network = _networkMgr.getNetwork(networkId);
if (!_networkMgr.isServiceSupported(network.getNetworkOfferingId(), Service.Firewall)) {
throw new InvalidParameterValueException("Unable to create static nat rule; Firewall service is not supported in network id=" + networkId);
}

View File

@ -131,7 +131,8 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag
}
//Verify that vpn service is enabled for the network
if (!_networkMgr.isServiceSupported(ipAddr.getAssociatedWithNetworkId(), Service.Vpn)) {
Network network = _networkMgr.getNetwork(ipAddr.getAssociatedWithNetworkId());
if (!_networkMgr.isServiceSupported(network.getNetworkOfferingId(), Service.Vpn)) {
throw new InvalidParameterValueException("Vpn service is not supported in network id=" + ipAddr.getAssociatedWithNetworkId());
}
@ -149,7 +150,6 @@ public class RemoteAccessVpnManagerImpl implements RemoteAccessVpnService, Manag
throw new InvalidParameterValueException("Invalid ip range " + ipRange);
}
Network network = _networkMgr.getNetwork(ipAddr.getAssociatedWithNetworkId());
Pair<String, Integer> cidr = NetUtils.getCidr(network.getCidr());
// FIXME: This check won't work for the case where the guest ip range

View File

@ -921,7 +921,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
}
if (broadcastDomainType != null) {
NetworkVO network = new NetworkVO(id, trafficType, null, mode, broadcastDomainType, networkOfferingId, zoneId, domainId, accountId, related, null, null, true, isNetworkDefault, false);
NetworkVO network = new NetworkVO(id, trafficType, null, mode, broadcastDomainType, networkOfferingId, zoneId, domainId, accountId, related, null, null, true, isNetworkDefault, false, null);
network.setGuruName(guruNames.get(network.getTrafficType()));
network.setDns1(zone.getDns1());
network.setDns2(zone.getDns2());

View File

@ -81,4 +81,6 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
List<DomainRouterVO> findByNetwork(long networkId);
List<DomainRouterVO> findByNetworkAndPod(long networkId, long podId);
List<DomainRouterVO> listActive(long networkId);
}

View File

@ -43,7 +43,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
private static final Logger s_logger = Logger.getLogger(DomainRouterDaoImpl.class);
protected final SearchBuilder<DomainRouterVO> AllFieldsSearch;
protected final SearchBuilder<DomainRouterVO> IdStatesSearch;
protected final SearchBuilder<DomainRouterVO> IdNetworkIdStatesSearch;
protected final SearchBuilder<DomainRouterVO> HostUpSearch;
NetworkDaoImpl _networksDao = ComponentLocator.inject(NetworkDaoImpl.class);
@ -60,10 +60,11 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
AllFieldsSearch.and("podId", AllFieldsSearch.entity().getPodIdToDeployIn(), Op.EQ);
AllFieldsSearch.done();
IdStatesSearch = createSearchBuilder();
IdStatesSearch.and("id", IdStatesSearch.entity().getId(), Op.EQ);
IdStatesSearch.and("states", IdStatesSearch.entity().getState(), Op.IN);
IdStatesSearch.done();
IdNetworkIdStatesSearch = createSearchBuilder();
IdNetworkIdStatesSearch.and("id", IdNetworkIdStatesSearch.entity().getId(), Op.EQ);
IdNetworkIdStatesSearch.and("network", IdNetworkIdStatesSearch.entity().getNetworkId(), Op.EQ);
IdNetworkIdStatesSearch.and("states", IdNetworkIdStatesSearch.entity().getState(), Op.IN);
IdNetworkIdStatesSearch.done();
HostUpSearch = createSearchBuilder();
HostUpSearch.and("host", HostUpSearch.entity().getHostId(), Op.EQ);
@ -72,7 +73,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
joinNetwork.and("guestType", joinNetwork.entity().getGuestType(), Op.EQ);
HostUpSearch.join("network", joinNetwork, joinNetwork.entity().getId(), HostUpSearch.entity().getNetworkId(), JoinType.INNER);
HostUpSearch.done();
}
@Override
@ -105,7 +106,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
sc.setParameters("role", Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
return listBy(sc);
}
@Override
public List<DomainRouterVO> findBy(long accountId, long dcId, Role role) {
SearchCriteria<DomainRouterVO> sc = AllFieldsSearch.create();
@ -128,11 +129,11 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
sc.setParameters("host", hostId);
return listBy(sc);
}
@Override
public List<DomainRouterVO> listVirtualUpByHostId(Long hostId) {
SearchCriteria<DomainRouterVO> sc = HostUpSearch.create();
if(hostId != null){
if (hostId != null) {
sc.setParameters("host", hostId);
}
sc.setParameters("states", State.Destroyed, State.Stopped, State.Expunging);
@ -153,10 +154,10 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
sc.setParameters("network", networkId);
return listBy(sc);
}
@Override
public List<DomainRouterVO> listByLastHostId(Long hostId) {
SearchCriteria<DomainRouterVO> sc = AllFieldsSearch.create();
@Override
public List<DomainRouterVO> listByLastHostId(Long hostId) {
SearchCriteria<DomainRouterVO> sc = AllFieldsSearch.create();
sc.setParameters("lastHost", hostId);
sc.setParameters("state", State.Stopped);
return listBy(sc);
@ -169,4 +170,12 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
sc.setParameters("podId", podId);
return listBy(sc);
}
@Override
public List<DomainRouterVO> listActive(long networkId) {
SearchCriteria<DomainRouterVO> sc = IdNetworkIdStatesSearch.create();
sc.setParameters("network", networkId);
sc.setParameters("states", State.Running, State.Migrating, State.Stopping, State.Starting);
return listBy(sc);
}
}