mirror of https://github.com/apache/cloudstack.git
1) Different format for LoadBalancerCommand.
2) When apply lb rule for domR, resend all lb rules belonging to the lb network
This commit is contained in:
parent
ce4ad3993a
commit
0049c74a5e
|
|
@ -19,89 +19,20 @@ package com.cloud.agent.api.routing;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
||||
import com.cloud.agent.api.to.LoadBalancerTO;
|
||||
|
||||
/**
|
||||
* LoadBalancerConfigCommand sends the load balancer configuration
|
||||
* to the load balancer. Isn't that kinda obvious?
|
||||
*/
|
||||
public class LoadBalancerConfigCommand extends RoutingCommand {
|
||||
String srcIp;
|
||||
int srcPort;
|
||||
String protocol;
|
||||
String algorithm;
|
||||
boolean revoked;
|
||||
boolean alreadyAdded;
|
||||
DestinationTO[] destinations;
|
||||
List<LoadBalancerTO> loadBalancers;
|
||||
|
||||
public LoadBalancerConfigCommand(String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> destinations) {
|
||||
this.srcIp = srcIp;
|
||||
this.srcPort = srcPort;
|
||||
this.protocol = protocol;
|
||||
this.algorithm = algorithm;
|
||||
this.revoked = revoked;
|
||||
this.alreadyAdded = alreadyAdded;
|
||||
this.destinations = new DestinationTO[destinations.size()];
|
||||
int i = 0;
|
||||
for (LbDestination destination : destinations) {
|
||||
this.destinations[i++] = new DestinationTO(destination.getIpAddress(), destination.getDestinationPortStart(), destination.isRevoked(), false);
|
||||
}
|
||||
}
|
||||
|
||||
public String getSrcIp() {
|
||||
return srcIp;
|
||||
public LoadBalancerConfigCommand(List<LoadBalancerTO> loadBalancers) {
|
||||
this.loadBalancers = loadBalancers;
|
||||
}
|
||||
|
||||
public int getSrcPort() {
|
||||
return srcPort;
|
||||
}
|
||||
|
||||
public String getAlgorithm() {
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public boolean isRevoked() {
|
||||
return revoked;
|
||||
}
|
||||
|
||||
public boolean isAlreadyAdded() {
|
||||
return alreadyAdded;
|
||||
}
|
||||
|
||||
public DestinationTO[] getDestinations() {
|
||||
return destinations;
|
||||
}
|
||||
|
||||
public class DestinationTO {
|
||||
String destIp;
|
||||
int destPort;
|
||||
boolean revoked;
|
||||
boolean alreadyAdded;
|
||||
public DestinationTO(String destIp, int destPort, boolean revoked, boolean alreadyAdded) {
|
||||
this.destIp = destIp;
|
||||
this.destPort = destPort;
|
||||
this.revoked = revoked;
|
||||
this.alreadyAdded = alreadyAdded;
|
||||
}
|
||||
|
||||
public String getDestIp() {
|
||||
return destIp;
|
||||
}
|
||||
|
||||
public int getDestPort() {
|
||||
return destPort;
|
||||
}
|
||||
|
||||
public boolean isRevoked() {
|
||||
return revoked;
|
||||
}
|
||||
|
||||
public boolean isAlreadyAdded() {
|
||||
return alreadyAdded;
|
||||
}
|
||||
public List<LoadBalancerTO> getLoadBalancers() {
|
||||
return loadBalancers;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,107 @@
|
|||
/**
|
||||
* 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.agent.api.to;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
||||
|
||||
|
||||
public class LoadBalancerTO {
|
||||
String srcIp;
|
||||
int srcPort;
|
||||
String protocol;
|
||||
String algorithm;
|
||||
boolean revoked;
|
||||
boolean alreadyAdded;
|
||||
DestinationTO[] destinations;
|
||||
|
||||
|
||||
public LoadBalancerTO (String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> destinations) {
|
||||
this.srcIp = srcIp;
|
||||
this.srcPort = srcPort;
|
||||
this.protocol = protocol;
|
||||
this.algorithm = algorithm;
|
||||
this.revoked = revoked;
|
||||
this.alreadyAdded = alreadyAdded;
|
||||
this.destinations = new DestinationTO[destinations.size()];
|
||||
int i = 0;
|
||||
for (LbDestination destination : destinations) {
|
||||
this.destinations[i++] = new DestinationTO(destination.getIpAddress(), destination.getDestinationPortStart(), destination.isRevoked(), false);
|
||||
}
|
||||
}
|
||||
|
||||
public String getSrcIp() {
|
||||
return srcIp;
|
||||
}
|
||||
|
||||
public int getSrcPort() {
|
||||
return srcPort;
|
||||
}
|
||||
|
||||
public String getAlgorithm() {
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public boolean isRevoked() {
|
||||
return revoked;
|
||||
}
|
||||
|
||||
public boolean isAlreadyAdded() {
|
||||
return alreadyAdded;
|
||||
}
|
||||
|
||||
public DestinationTO[] getDestinations() {
|
||||
return destinations;
|
||||
}
|
||||
|
||||
|
||||
public class DestinationTO {
|
||||
String destIp;
|
||||
int destPort;
|
||||
boolean revoked;
|
||||
boolean alreadyAdded;
|
||||
public DestinationTO(String destIp, int destPort, boolean revoked, boolean alreadyAdded) {
|
||||
this.destIp = destIp;
|
||||
this.destPort = destPort;
|
||||
this.revoked = revoked;
|
||||
this.alreadyAdded = alreadyAdded;
|
||||
}
|
||||
|
||||
public String getDestIp() {
|
||||
return destIp;
|
||||
}
|
||||
|
||||
public int getDestPort() {
|
||||
return destPort;
|
||||
}
|
||||
|
||||
public boolean isRevoked() {
|
||||
return revoked;
|
||||
}
|
||||
|
||||
public boolean isAlreadyAdded() {
|
||||
return alreadyAdded;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -26,9 +26,9 @@ public interface Vlan {
|
|||
|
||||
public final static String UNTAGGED = "untagged";
|
||||
|
||||
public Long getId();
|
||||
public long getId();
|
||||
|
||||
public String getVlanId();
|
||||
public String getVlanTag();
|
||||
|
||||
public String getVlanGateway();
|
||||
|
||||
|
|
|
|||
|
|
@ -65,4 +65,6 @@ public interface DomainRouterService {
|
|||
|
||||
VirtualRouter upgradeRouter(UpgradeRouterCmd cmd);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import com.cloud.acl.ControlledEntity;
|
||||
|
||||
/**
|
||||
* PublicIp is a combo object of IPAddressVO and VLAN information.
|
||||
*/
|
||||
|
||||
public interface PublicIpAddress extends ControlledEntity, IpAddress{
|
||||
|
||||
String getMacAddress();
|
||||
|
||||
public String getNetmask();
|
||||
|
||||
public String getGateway();
|
||||
|
||||
public String getVlanTag();
|
||||
}
|
||||
|
|
@ -10,8 +10,8 @@ import com.cloud.exception.ConcurrentOperationException;
|
|||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientNetworkCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.utils.component.Adapter;
|
||||
|
|
@ -76,7 +76,7 @@ public interface NetworkElement extends Adapter {
|
|||
* @return
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
boolean applyIps(Network network, List<? extends IpAddress> ipAddress) throws ResourceUnavailableException;
|
||||
boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException;
|
||||
|
||||
/**
|
||||
* Apply rules
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer{
|
|||
|
||||
@Override
|
||||
public String getProtocol() {
|
||||
return null;
|
||||
return lb.getProtocol();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -548,7 +548,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
VlanIpRangeResponse vlanResponse = new VlanIpRangeResponse();
|
||||
vlanResponse.setId(vlan.getId());
|
||||
vlanResponse.setForVirtualNetwork(vlan.getVlanType().equals(VlanType.VirtualNetwork));
|
||||
vlanResponse.setVlan(vlan.getVlanId());
|
||||
vlanResponse.setVlan(vlan.getVlanTag());
|
||||
vlanResponse.setZoneId(vlan.getDataCenterId());
|
||||
|
||||
if (podId != null) {
|
||||
|
|
@ -617,7 +617,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
Account account = UserContext.current().getAccount();
|
||||
if ((account == null) || account.getType() == Account.ACCOUNT_TYPE_ADMIN) {
|
||||
ipResponse.setVlanId(ipAddress.getVlanId());
|
||||
ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddress.getVlanId()).getVlanId());
|
||||
ipResponse.setVlanName(ApiDBUtils.findVlanById(ipAddress.getVlanId()).getVlanTag());
|
||||
}
|
||||
ipResponse.setObjectName("ipaddress");
|
||||
return ipResponse;
|
||||
|
|
@ -2178,7 +2178,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
response.setEndIp(range[1]);
|
||||
response.setGateway(singleVlan.getVlanGateway());
|
||||
response.setNetmask(singleVlan.getVlanNetmask());
|
||||
response.setVlan(singleVlan.getVlanId());
|
||||
response.setVlan(singleVlan.getVlanTag());
|
||||
}
|
||||
|
||||
response.setZoneId(network.getDataCenterId());
|
||||
|
|
|
|||
|
|
@ -1775,17 +1775,17 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
otherVlanEndIP = otherVlanIpRange[1];
|
||||
}
|
||||
|
||||
if (!vlanId.equals(vlan.getVlanId()) && newVlanSubnet.equals(otherVlanSubnet)) {
|
||||
throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanId() + " in zone " + zone.getName() + " has the same subnet. Please specify a different gateway/netmask.");
|
||||
if (!vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet)) {
|
||||
throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " in zone " + zone.getName() + " has the same subnet. Please specify a different gateway/netmask.");
|
||||
}
|
||||
|
||||
if (vlanId.equals(vlan.getVlanId()) && newVlanSubnet.equals(otherVlanSubnet)) {
|
||||
if (vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet)) {
|
||||
if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) {
|
||||
throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanId() + " already has IPs that overlap with the new range. Please specify a different start IP/end IP.");
|
||||
throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " already has IPs that overlap with the new range. Please specify a different start IP/end IP.");
|
||||
}
|
||||
|
||||
if (!vlanGateway.equals(otherVlanGateway)) {
|
||||
throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanId() + " has already been added with gateway " + otherVlanGateway + ". Please specify a different tag.");
|
||||
throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " has already been added with gateway " + otherVlanGateway + ". Please specify a different tag.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1966,14 +1966,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||
String[] ipRange = vlan.getIpRange().split("\\-");
|
||||
String startIP = ipRange[0];
|
||||
String endIP = (ipRange.length > 1) ? ipRange[1] : null;
|
||||
String eventMsg = "Successfully deleted IP range (tag = " + vlan.getVlanId() + ", gateway = " + vlan.getVlanGateway() + ", netmask = " + vlan.getVlanNetmask() + ", start IP = " + startIP;
|
||||
String eventMsg = "Successfully deleted IP range (tag = " + vlan.getVlanTag() + ", gateway = " + vlan.getVlanGateway() + ", netmask = " + vlan.getVlanNetmask() + ", start IP = " + startIP;
|
||||
if (endIP != null) {
|
||||
eventMsg += ", end IP = " + endIP;
|
||||
}
|
||||
eventMsg += ".";
|
||||
saveConfigurationEvent(userId, null, EventTypes.EVENT_VLAN_IP_RANGE_DELETE, eventMsg, "vlanType=" + vlan.getVlanType(), "dcId=" + vlan.getDataCenterId(),
|
||||
"accountId=" + accountId, "podId=" + podId,
|
||||
"vlanId=" + vlan.getVlanId(), "vlanGateway=" + vlan.getVlanGateway(),
|
||||
"vlanId=" + vlan.getVlanTag(), "vlanGateway=" + vlan.getVlanGateway(),
|
||||
"vlanNetmask=" + vlan.getVlanNetmask(), "startIP=" + startIP,
|
||||
"endIP=" + endIP);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class VlanVO implements Vlan {
|
|||
Long id;
|
||||
|
||||
@Column(name="vlan_id")
|
||||
String vlanId;
|
||||
String vlanTag;
|
||||
|
||||
@Column(name="vlan_gateway")
|
||||
String vlanGateway;
|
||||
|
|
@ -60,7 +60,7 @@ public class VlanVO implements Vlan {
|
|||
|
||||
public VlanVO(VlanType vlanType, String vlanTag, String vlanGateway, String vlanNetmask, long dataCenterId, String ipRange, Long networkId) {
|
||||
this.vlanType = vlanType;
|
||||
this.vlanId = vlanTag;
|
||||
this.vlanTag = vlanTag;
|
||||
this.vlanGateway = vlanGateway;
|
||||
this.vlanNetmask = vlanNetmask;
|
||||
this.dataCenterId = dataCenterId;
|
||||
|
|
@ -72,12 +72,12 @@ public class VlanVO implements Vlan {
|
|||
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getVlanId() {
|
||||
return vlanId;
|
||||
public String getVlanTag() {
|
||||
return vlanTag;
|
||||
}
|
||||
|
||||
public String getVlanGateway() {
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
|||
public VlanDaoImpl() {
|
||||
ZoneVlanIdSearch = createSearchBuilder();
|
||||
ZoneVlanIdSearch.and("zoneId", ZoneVlanIdSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
ZoneVlanIdSearch.and("vlanId", ZoneVlanIdSearch.entity().getVlanId(), SearchCriteria.Op.EQ);
|
||||
ZoneVlanIdSearch.and("vlanId", ZoneVlanIdSearch.entity().getVlanTag(), SearchCriteria.Op.EQ);
|
||||
ZoneVlanIdSearch.done();
|
||||
|
||||
ZoneSearch = createSearchBuilder();
|
||||
|
|
@ -222,7 +222,7 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
|||
// Try to find an empty VLAN with the same tag/subnet as a VLAN that is full
|
||||
for (VlanVO fullVlan : fullVlans) {
|
||||
for (VlanVO emptyVlan : emptyVlans) {
|
||||
if (fullVlan.getVlanId().equals(emptyVlan.getVlanId()) &&
|
||||
if (fullVlan.getVlanTag().equals(emptyVlan.getVlanTag()) &&
|
||||
fullVlan.getVlanGateway().equals(emptyVlan.getVlanGateway()) &&
|
||||
fullVlan.getVlanNetmask().equals(emptyVlan.getVlanNetmask())) {
|
||||
return emptyVlan;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package com.cloud.network;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
|
|
@ -30,6 +29,7 @@ import com.cloud.exception.InsufficientNetworkCapacityException;
|
|||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.FirewallRuleVO;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.user.Account;
|
||||
|
|
@ -126,5 +126,4 @@ public interface NetworkManager extends NetworkService {
|
|||
String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException;
|
||||
|
||||
boolean applyRules(Ip ip, List<? extends FirewallRule> rules, boolean continueOnError) throws ResourceUnavailableException;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ import com.cloud.network.Networks.Availability;
|
|||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.dao.FirewallRulesDao;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.RemoteAccessVpnDao;
|
||||
|
|
@ -181,6 +182,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
@Inject DomainRouterManager _routerMgr;
|
||||
@Inject RulesManager _rulesMgr;
|
||||
@Inject LoadBalancingRulesManager _lbMgr;
|
||||
@Inject FirewallRulesDao _firewallRulesDao;
|
||||
|
||||
@Inject(adapter=NetworkGuru.class)
|
||||
Adapters<NetworkGuru> _networkGurus;
|
||||
|
|
@ -372,7 +374,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
for (final IPAddressVO ip: ipList) {
|
||||
sourceNat = ip.isSourceNat();
|
||||
VlanVO vlan = vlanAndIp.getKey();
|
||||
String vlanId = vlan.getVlanId();
|
||||
String vlanId = vlan.getVlanTag();
|
||||
String vlanGateway = vlan.getVlanGateway();
|
||||
String vlanNetmask = vlan.getVlanNetmask();
|
||||
|
||||
|
|
@ -455,11 +457,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
|
||||
public boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException {
|
||||
List<IPAddressVO> userIps = _ipAddressDao.listByNetwork(network.getId());
|
||||
|
||||
List<PublicIp> publicIps = new ArrayList<PublicIp>();
|
||||
if (userIps != null && !userIps.isEmpty()) {
|
||||
for (IPAddressVO userIp : userIps) {
|
||||
PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), userIp.getMacAddress());
|
||||
publicIps.add(publicIp);
|
||||
}
|
||||
}
|
||||
|
||||
boolean success = true;
|
||||
for (NetworkElement element : _networkElements) {
|
||||
try {
|
||||
element.applyIps(network, userIps);
|
||||
element.applyIps(network, publicIps);
|
||||
} catch (ResourceUnavailableException e) {
|
||||
success = false;
|
||||
if (!continueOnError) {
|
||||
|
|
@ -2049,8 +2058,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationException{
|
||||
String accountName = cmd.getAccountName();
|
||||
|
|
@ -2082,5 +2089,4 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,13 +21,13 @@ import java.util.Date;
|
|||
|
||||
import com.cloud.dc.VlanVO;
|
||||
import com.cloud.network.IPAddressVO;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
/**
|
||||
* PublicIp is a combo object of IPAddressVO and VLAN information.
|
||||
*/
|
||||
public class PublicIp implements IpAddress {
|
||||
public class PublicIp implements PublicIpAddress{
|
||||
IPAddressVO _addr;
|
||||
VlanVO _vlan;
|
||||
String macAddress;
|
||||
|
|
@ -43,16 +43,19 @@ public class PublicIp implements IpAddress {
|
|||
return _addr.getAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNetmask() {
|
||||
return _vlan.getVlanNetmask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGateway() {
|
||||
return _vlan.getVlanGateway();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVlanTag() {
|
||||
return _vlan.getVlanId();
|
||||
return _vlan.getVlanTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -118,6 +121,7 @@ public class PublicIp implements IpAddress {
|
|||
return _vlan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMacAddress() {
|
||||
return macAddress;
|
||||
}
|
||||
|
|
@ -126,4 +130,5 @@ public class PublicIp implements IpAddress {
|
|||
public Long getAssociatedNetworkId() {
|
||||
return _addr.getAssociatedNetworkId();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
|
|||
AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), Op.EQ);
|
||||
AllFieldsSearch.and("domain", AllFieldsSearch.entity().getDomainId(), Op.EQ);
|
||||
AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
|
||||
AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
|
||||
AllFieldsSearch.done();
|
||||
|
||||
|
||||
|
|
@ -69,7 +70,7 @@ public class FirewallRulesDaoImpl extends GenericDaoBase<FirewallRuleVO, Long> i
|
|||
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean setStateToAdd(FirewallRuleVO rule) {
|
||||
SearchCriteria<FirewallRuleVO> sc = AllFieldsSearch.create();
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
package com.cloud.network.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.network.LoadBalancerVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
|
|
@ -27,5 +27,6 @@ public interface LoadBalancerDao extends GenericDao<LoadBalancerVO, Long> {
|
|||
List<Long> listInstancesByLoadBalancer(long loadBalancerId);
|
||||
List<LoadBalancerVO> listByIpAddress(String ipAddress);
|
||||
LoadBalancerVO findByIpAddressAndPublicPort(String ipAddress, String publicPort);
|
||||
LoadBalancerVO findByAccountAndName(Long accountId, String name);
|
||||
LoadBalancerVO findByAccountAndName(Long accountId, String name);
|
||||
List<LoadBalancerVO> listByNetworkId(long networkId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import javax.ejb.Local;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.network.LoadBalancerVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
|
|
@ -51,7 +50,8 @@ public class LoadBalancerDaoImpl extends GenericDaoBase<LoadBalancerVO, Long> im
|
|||
|
||||
protected LoadBalancerDaoImpl() {
|
||||
ListByIp = createSearchBuilder();
|
||||
ListByIp.and("ipAddress", ListByIp.entity().getSourceIpAddress(), SearchCriteria.Op.EQ);
|
||||
ListByIp.and("ipAddress", ListByIp.entity().getSourceIpAddress(), SearchCriteria.Op.EQ);
|
||||
ListByIp.and("networkId", ListByIp.entity().getNetworkId(), SearchCriteria.Op.EQ);
|
||||
ListByIp.done();
|
||||
|
||||
IpAndPublicPortSearch = createSearchBuilder();
|
||||
|
|
@ -91,6 +91,13 @@ public class LoadBalancerDaoImpl extends GenericDaoBase<LoadBalancerVO, Long> im
|
|||
SearchCriteria<LoadBalancerVO> sc = ListByIp.create();
|
||||
sc.setParameters("ipAddress", ipAddress);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LoadBalancerVO> listByNetworkId(long networkId) {
|
||||
SearchCriteria<LoadBalancerVO> sc = ListByIp.create();
|
||||
sc.setParameters("networkId", networkId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ import com.cloud.exception.ConcurrentOperationException;
|
|||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientNetworkCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.router.DomainRouterManager;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
|
|
@ -122,7 +122,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean applyIps(Network network, List<? extends IpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
package com.cloud.network.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
|
@ -30,10 +31,15 @@ import com.cloud.exception.ConcurrentOperationException;
|
|||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientNetworkCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.LoadBalancerVO;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.dao.LoadBalancerDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
||||
import com.cloud.network.lb.LoadBalancingRulesManager;
|
||||
import com.cloud.network.router.DomainRouterManager;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.FirewallRule.Purpose;
|
||||
|
|
@ -60,12 +66,14 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
|
|||
|
||||
@Inject NetworkDao _networkConfigDao;
|
||||
@Inject NetworkManager _networkMgr;
|
||||
@Inject LoadBalancingRulesManager _lbMgr;
|
||||
@Inject NetworkOfferingDao _networkOfferingDao;
|
||||
@Inject DomainRouterManager _routerMgr;
|
||||
@Inject UserVmManager _userVmMgr;
|
||||
@Inject UserVmDao _userVmDao;
|
||||
@Inject DomainRouterDao _routerDao;
|
||||
@Inject DataCenterDao _dataCenterDao;
|
||||
@Inject LoadBalancerDao _lbDao;
|
||||
|
||||
|
||||
private boolean canHandle(GuestIpType ipType, DataCenter dc) {
|
||||
|
|
@ -123,7 +131,16 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
|
|||
if (canHandle(config.getGuestType(),dc)) {
|
||||
if (rules != null && !rules.isEmpty()) {
|
||||
if (rules.get(0).getPurpose() == Purpose.LoadBalancing) {
|
||||
return _routerMgr.applyLBRules(config, rules);
|
||||
//for load balancer we have to resend all lb rules for the network
|
||||
List<LoadBalancerVO> lbs = _lbDao.listByNetworkId(config.getId());
|
||||
List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
|
||||
for (LoadBalancerVO lb : lbs) {
|
||||
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
|
||||
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList);
|
||||
lbRules.add(loadBalancing);
|
||||
}
|
||||
|
||||
return _routerMgr.applyLBRules(config, lbRules);
|
||||
} else if (rules.get(0).getPurpose() == Purpose.PortForwarding) {
|
||||
return _routerMgr.applyPortForwardingRules(config, rules);
|
||||
}
|
||||
|
|
@ -135,7 +152,7 @@ public class DomainRouterElement extends AdapterBase implements NetworkElement {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean applyIps(Network network, List<? extends IpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
DataCenter dc = _dataCenterDao.findById(network.getDataCenterId());
|
||||
if (canHandle(network.getGuestType(),dc)) {
|
||||
return _routerMgr.associateIP(network, ipAddress);
|
||||
|
|
|
|||
|
|
@ -92,11 +92,11 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
nic.setIp4Address(ip.getAddress());
|
||||
nic.setGateway(ip.getGateway());
|
||||
nic.setNetmask(ip.getNetmask());
|
||||
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
|
||||
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanId()));
|
||||
nic.setBroadcastType(BroadcastDomainType.Vlan);
|
||||
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
|
||||
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanId()));
|
||||
nic.setFormat(AddressFormat.Ip4);
|
||||
nic.setReservationId(ip.getVlanTag());
|
||||
nic.setReservationId(String.valueOf(ip.getVlanId()));
|
||||
nic.setMacAddress(ip.getMacAddress());
|
||||
}
|
||||
nic.setDns1(dc.getDns1());
|
||||
|
|
|
|||
|
|
@ -75,11 +75,11 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
nic.setIp4Address(ip.getAddress());
|
||||
nic.setGateway(ip.getGateway());
|
||||
nic.setNetmask(ip.getNetmask());
|
||||
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
|
||||
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanId()));
|
||||
nic.setBroadcastType(BroadcastDomainType.Vlan);
|
||||
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
|
||||
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanId()));
|
||||
nic.setFormat(AddressFormat.Ip4);
|
||||
nic.setReservationId(ip.getVlanTag());
|
||||
nic.setReservationId(String.valueOf(ip.getVlanId()));
|
||||
nic.setMacAddress(ip.getMacAddress());
|
||||
}
|
||||
nic.setDns1(dc.getDns1());
|
||||
|
|
|
|||
|
|
@ -17,8 +17,12 @@
|
|||
*/
|
||||
package com.cloud.network.lb;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
||||
import com.cloud.utils.net.Ip;
|
||||
|
||||
public interface LoadBalancingRulesManager extends LoadBalancingRulesService {
|
||||
boolean removeAllLoadBalanacers(Ip ip);
|
||||
List<LbDestination> getExistingDestinations(long lbId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||
}
|
||||
|
||||
|
||||
@Override @DB
|
||||
@Override
|
||||
public boolean removeFromLoadBalancer(long loadBalancerId, List<Long> instanceIds) {
|
||||
UserContext caller = UserContext.current();
|
||||
|
||||
|
|
@ -375,7 +375,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||
return true;
|
||||
}
|
||||
|
||||
private List<LbDestination> getExistingDestinations(long lbId) {
|
||||
@Override
|
||||
public List<LbDestination> getExistingDestinations(long lbId) {
|
||||
List<LbDestination> dstList = new ArrayList<LbDestination>();
|
||||
List<LoadBalancerVMMapVO> lbVmMaps = _lb2VmMapDao.listByLoadBalancerId(lbId);
|
||||
LoadBalancerVO lb = _lbDao.findById(lbId);
|
||||
|
|
|
|||
|
|
@ -28,11 +28,12 @@ import com.cloud.exception.InsufficientNetworkCapacityException;
|
|||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.RemoteAccessVpnVO;
|
||||
import com.cloud.network.VpnUserVO;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.component.Manager;
|
||||
|
|
@ -103,8 +104,9 @@ public interface DomainRouterManager extends Manager {
|
|||
|
||||
DomainRouterVO addVirtualMachineIntoNetwork(Network config, NicProfile nic, VirtualMachineProfile<UserVm> vm, DeployDestination dest, ReservationContext context, Boolean startDhcp) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException;
|
||||
|
||||
boolean associateIP (Network network, List<? extends IpAddress> ipAddress);
|
||||
boolean associateIP (Network network, List<? extends PublicIpAddress> ipAddress);
|
||||
|
||||
boolean applyLBRules(Network network, List<? extends FirewallRule> rules);
|
||||
boolean applyPortForwardingRules(Network network, List<? extends FirewallRule> rules);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package com.cloud.network.router;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -55,6 +54,7 @@ import com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand;
|
|||
import com.cloud.agent.api.routing.SavePasswordCommand;
|
||||
import com.cloud.agent.api.routing.VmDataCommand;
|
||||
import com.cloud.agent.api.routing.VpnUsersCfgCommand;
|
||||
import com.cloud.agent.api.to.LoadBalancerTO;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.api.commands.RebootRouterCmd;
|
||||
|
|
@ -72,6 +72,8 @@ import com.cloud.configuration.dao.ConfigurationDao;
|
|||
import com.cloud.configuration.dao.ResourceLimitDao;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.Vlan;
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
import com.cloud.dc.VlanVO;
|
||||
import com.cloud.dc.dao.AccountVlanMapDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
|
|
@ -79,6 +81,7 @@ import com.cloud.dc.dao.HostPodDao;
|
|||
import com.cloud.dc.dao.VlanDao;
|
||||
import com.cloud.deploy.DataCenterDeployment;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.Event;
|
||||
import com.cloud.event.EventTypes;
|
||||
|
|
@ -109,6 +112,7 @@ import com.cloud.network.NetworkVO;
|
|||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.IsolationType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.PublicIpAddress;
|
||||
import com.cloud.network.RemoteAccessVpnVO;
|
||||
import com.cloud.network.SshKeysDistriMonitor;
|
||||
import com.cloud.network.VpnUserVO;
|
||||
|
|
@ -127,7 +131,6 @@ import com.cloud.network.router.VirtualRouter.Role;
|
|||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.PortForwardingRuleVO;
|
||||
import com.cloud.network.rules.RulesManager;
|
||||
import com.cloud.network.rules.FirewallRule.Purpose;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
|
|
@ -145,6 +148,7 @@ import com.cloud.storage.dao.VolumeDao;
|
|||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountService;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.UserStatisticsVO;
|
||||
|
|
@ -168,7 +172,6 @@ import com.cloud.vm.NicProfile;
|
|||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.State;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineGuru;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
|
|
@ -283,7 +286,322 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public DomainRouterVO createDhcpServerForDirectlyAttachedGuests(long userId, long accountId, DataCenterVO dc, HostPodVO pod, Long candidateHost, VlanVO guestVlan) throws ConcurrentOperationException{
|
||||
|
||||
final AccountVO account = _accountDao.findById(accountId);
|
||||
boolean podVlan = guestVlan.getVlanType().equals(VlanType.DirectAttached) && guestVlan.getVlanTag().equals(Vlan.UNTAGGED);
|
||||
long accountIdForDHCPServer = podVlan ? Account.ACCOUNT_ID_SYSTEM : accountId;
|
||||
long domainIdForDHCPServer = podVlan ? DomainVO.ROOT_DOMAIN : account.getDomainId();
|
||||
String domainNameForDHCPServer = podVlan ? "root" : _domainDao.findById(account.getDomainId()).getName();
|
||||
|
||||
final VMTemplateVO rtrTemplate = _templateDao.findRoutingTemplate();
|
||||
|
||||
final Transaction txn = Transaction.currentTxn();
|
||||
DomainRouterVO router = null;
|
||||
Long podId = pod.getId();
|
||||
pod = _podDao.acquireInLockTable(podId, 20*60);
|
||||
if (pod == null) {
|
||||
throw new ConcurrentOperationException("Unable to acquire lock on pod " + podId );
|
||||
}
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Lock on pod " + podId + " is acquired");
|
||||
}
|
||||
|
||||
final long id = _routerDao.getNextInSequence(Long.class, "id");
|
||||
final String[] macAddresses = _dcDao.getNextAvailableMacAddressPair(dc.getId());
|
||||
final String mgmtMacAddress = macAddresses[0];
|
||||
final String guestMacAddress = macAddresses[1];
|
||||
final String name = VirtualMachineName.getRouterName(id, _instance).intern();
|
||||
|
||||
boolean routerLockAcquired = false;
|
||||
try {
|
||||
List<DomainRouterVO> rtrs = _routerDao.listByVlanDbId(guestVlan.getId());
|
||||
assert rtrs.size() < 2 : "How did we get more than one router per vlan?";
|
||||
if (rtrs.size() == 1) {
|
||||
return rtrs.get(0);
|
||||
}
|
||||
String mgmtNetmask = NetUtils.getCidrNetmask(pod.getCidrSize());
|
||||
final String guestIp = null;//_ipAddressDao.assignIpAddress(accountIdForDHCPServer, domainIdForDHCPServer, guestVlan.getId(), false).getAddress();
|
||||
|
||||
router =
|
||||
new DomainRouterVO(id,
|
||||
_offering.getId(),
|
||||
name,
|
||||
mgmtMacAddress,
|
||||
null,
|
||||
mgmtNetmask,
|
||||
_routerTemplateId,
|
||||
rtrTemplate.getGuestOSId(),
|
||||
guestMacAddress,
|
||||
guestIp,
|
||||
guestVlan.getVlanNetmask(),
|
||||
accountIdForDHCPServer,
|
||||
domainIdForDHCPServer,
|
||||
"FE:FF:FF:FF:FF:FF",
|
||||
null,
|
||||
"255.255.255.255",
|
||||
guestVlan.getId(),
|
||||
guestVlan.getVlanTag(),
|
||||
pod.getId(),
|
||||
dc.getId(),
|
||||
_routerRamSize,
|
||||
guestVlan.getVlanGateway(),
|
||||
domainNameForDHCPServer,
|
||||
dc.getDns1(),
|
||||
dc.getDns2());
|
||||
router.setRole(Role.DHCP_USERDATA);
|
||||
router.setVnet(guestVlan.getVlanTag());
|
||||
|
||||
router.setLastHostId(candidateHost);
|
||||
|
||||
txn.start();
|
||||
router = _routerDao.persist(router);
|
||||
router = _routerDao.acquireInLockTable(router.getId());
|
||||
if (router == null) {
|
||||
s_logger.debug("Unable to acquire lock on router " + id);
|
||||
throw new CloudRuntimeException("Unable to acquire lock on router " + id);
|
||||
}
|
||||
|
||||
routerLockAcquired = true;
|
||||
|
||||
txn.commit();
|
||||
|
||||
List<VolumeVO> vols = _storageMgr.create(account, router, rtrTemplate, dc, pod, _offering, null,0);
|
||||
if (vols == null){
|
||||
_ipAddressDao.unassignIpAddress(guestIp);
|
||||
_routerDao.expunge(router.getId());
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Unable to create dhcp server in storage host or pool in pod " + pod.getName() + " (id:" + pod.getId() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
final EventVO event = new EventVO();
|
||||
event.setUserId(userId);
|
||||
event.setAccountId(accountIdForDHCPServer);
|
||||
event.setType(EventTypes.EVENT_ROUTER_CREATE);
|
||||
|
||||
if (vols == null) {
|
||||
event.setDescription("failed to create DHCP Server : " + router.getName());
|
||||
event.setLevel(EventVO.LEVEL_ERROR);
|
||||
_eventDao.persist(event);
|
||||
throw new ExecutionException("Unable to create DHCP Server");
|
||||
}
|
||||
_itMgr.stateTransitTo(router, VirtualMachine.Event.OperationSucceeded, null);
|
||||
|
||||
s_logger.info("DHCP server created: id=" + router.getId() + "; name=" + router.getName() + "; vlan=" + guestVlan.getVlanTag() + "; pod=" + pod.getName());
|
||||
|
||||
event.setDescription("successfully created DHCP Server : " + router.getName() + " with ip : " + router.getGuestIpAddress());
|
||||
_eventDao.persist(event);
|
||||
|
||||
return router;
|
||||
} catch (final Throwable th) {
|
||||
if (th instanceof ExecutionException) {
|
||||
s_logger.error("Error while starting router due to " + th.getMessage());
|
||||
} else {
|
||||
s_logger.error("Unable to create router", th);
|
||||
}
|
||||
txn.rollback();
|
||||
|
||||
if (router.getState() == State.Creating) {
|
||||
_routerDao.expunge(router.getId());
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
if (routerLockAcquired) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Releasing lock on router " + id);
|
||||
}
|
||||
_routerDao.releaseFromLockTable(id);
|
||||
}
|
||||
if (pod != null) {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Releasing lock on pod " + podId);
|
||||
}
|
||||
_podDao.releaseFromLockTable(pod.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean releaseRouter(final long routerId) {
|
||||
// return destroyRouter(routerId);
|
||||
// }
|
||||
//
|
||||
// @Override @DB
|
||||
// public DomainRouterVO createRouter(final long accountId, final String publicIpAddress, final long dataCenterId,
|
||||
// String domain, final ServiceOfferingVO offering, long startEventId)
|
||||
// throws ConcurrentOperationException {
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Creating a router for account=" + accountId + "; publicIpAddress=" + publicIpAddress + "; dc=" + dataCenterId + "domain=" + domain);
|
||||
// }
|
||||
//
|
||||
// final AccountVO account = _accountDao.acquireInLockTable(accountId);
|
||||
// if (account == null) {
|
||||
// throw new ConcurrentOperationException("Unable to acquire account " + accountId);
|
||||
// }
|
||||
//
|
||||
// if(s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("lock on account " + accountId + " for createRouter is acquired");
|
||||
// }
|
||||
//
|
||||
// final Transaction txn = Transaction.currentTxn();
|
||||
// DomainRouterVO router = null;
|
||||
// boolean success = false;
|
||||
// try {
|
||||
// router = _routerDao.findBy(accountId, dataCenterId);
|
||||
// if (router != null && router.getState() != State.Creating) {
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Router " + router.toString() + " found for account " + accountId + " in data center " + dataCenterId);
|
||||
// }
|
||||
// success = true;
|
||||
// return router;
|
||||
// }
|
||||
// EventVO event = new EventVO();
|
||||
// event.setUserId(1L);
|
||||
// event.setAccountId(accountId);
|
||||
// event.setType(EventTypes.EVENT_ROUTER_CREATE);
|
||||
// event.setState(Event.State.Started);
|
||||
// event.setStartId(startEventId);
|
||||
// event.setDescription("Creating Router for account with Id: "+accountId);
|
||||
// event = _eventDao.persist(event);
|
||||
//
|
||||
// final DataCenterVO dc = _dcDao.findById(dataCenterId);
|
||||
// final VMTemplateVO template = _templateDao.findRoutingTemplate();
|
||||
//
|
||||
// String[] macAddresses = getMacAddressPair(dataCenterId);
|
||||
// String privateMacAddress = macAddresses[0];
|
||||
// String publicMacAddress = macAddresses[1];
|
||||
//
|
||||
// final long id = _routerDao.getNextInSequence(Long.class, "id");
|
||||
//
|
||||
// if (domain == null) {
|
||||
// domain = "v" + Long.toHexString(accountId) + "." + _domain;
|
||||
// }
|
||||
//
|
||||
// final String name = VirtualMachineName.getRouterName(id, _instance).intern();
|
||||
// long routerMacAddress = NetUtils.mac2Long(dc.getRouterMacAddress()) | ((dc.getId() & 0xff) << 32);
|
||||
//
|
||||
// //set the guestNetworkCidr from the dc obj
|
||||
// String guestNetworkCidr = dc.getGuestNetworkCidr();
|
||||
// String[] cidrTuple = guestNetworkCidr.split("\\/");
|
||||
// String guestIpAddress = NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1]));
|
||||
// String guestNetmask = NetUtils.getCidrNetmask(Long.parseLong(cidrTuple[1]));
|
||||
//
|
||||
//// String path = null;
|
||||
//// final int numVolumes = offering.isMirroredVolumes()?2:1;
|
||||
//// long routerId = 0;
|
||||
//
|
||||
// // Find the VLAN ID, VLAN gateway, and VLAN netmask for publicIpAddress
|
||||
// IPAddressVO ipVO = _ipAddressDao.findById(publicIpAddress);
|
||||
// VlanVO vlan = _vlanDao.findById(ipVO.getVlanId());
|
||||
// String vlanId = vlan.getVlanTag();
|
||||
// String vlanGateway = vlan.getVlanGateway();
|
||||
// String vlanNetmask = vlan.getVlanNetmask();
|
||||
//
|
||||
// Pair<HostPodVO, Long> pod = null;
|
||||
// Set<Long> avoids = new HashSet<Long>();
|
||||
// boolean found = false;
|
||||
// while ((pod = _agentMgr.findPod(template, offering, dc, accountId, avoids)) != null) {
|
||||
//
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Attempting to create in pod " + pod.first().getName());
|
||||
// }
|
||||
//
|
||||
// router = new DomainRouterVO(id,
|
||||
// _offering.getId(),
|
||||
// name,
|
||||
// privateMacAddress,
|
||||
// null,
|
||||
// null,
|
||||
// _routerTemplateId,
|
||||
// template.getGuestOSId(),
|
||||
// NetUtils.long2Mac(routerMacAddress),
|
||||
// guestIpAddress,
|
||||
// guestNetmask,
|
||||
// accountId,
|
||||
// account.getDomainId(),
|
||||
// publicMacAddress,
|
||||
// publicIpAddress,
|
||||
// vlanNetmask,
|
||||
// vlan.getId(),
|
||||
// vlanId,
|
||||
// pod.first().getId(),
|
||||
// dataCenterId,
|
||||
// _routerRamSize,
|
||||
// vlanGateway,
|
||||
// domain,
|
||||
// dc.getDns1(),
|
||||
// dc.getDns2());
|
||||
// router.setMirroredVols(offering.isMirrored());
|
||||
//
|
||||
// router.setLastHostId(pod.second());
|
||||
// router = _routerDao.persist(router);
|
||||
//
|
||||
// List<VolumeVO> vols = _storageMgr.create(account, router, template, dc, pod.first(), _offering, null,0);
|
||||
// if(vols != null) {
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// _routerDao.expunge(router.getId());
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Unable to find storage host or pool in pod " + pod.first().getName() + " (id:" + pod.first().getId() + "), checking other pods");
|
||||
// }
|
||||
// avoids.add(pod.first().getId());
|
||||
// }
|
||||
//
|
||||
// if (!found) {
|
||||
// event.setDescription("failed to create Domain Router : " + name);
|
||||
// event.setLevel(EventVO.LEVEL_ERROR);
|
||||
// _eventDao.persist(event);
|
||||
// throw new ExecutionException("Unable to create DomainRouter");
|
||||
// }
|
||||
// _itMgr.stateTransitTo(router, VirtualMachine.Event.OperationSucceeded, null);
|
||||
//
|
||||
// s_logger.debug("Router created: id=" + router.getId() + "; name=" + router.getName());
|
||||
//
|
||||
// event = new EventVO();
|
||||
// event.setUserId(1L); // system user performed the action
|
||||
// event.setAccountId(accountId);
|
||||
// event.setType(EventTypes.EVENT_ROUTER_CREATE);
|
||||
// event.setStartId(startEventId);
|
||||
// event.setDescription("successfully created Domain Router : " + router.getName() + " with ip : " + publicIpAddress);
|
||||
// _eventDao.persist(event);
|
||||
// success = true;
|
||||
// return router;
|
||||
// } catch (final Throwable th) {
|
||||
// if (th instanceof ExecutionException) {
|
||||
// s_logger.error("Error while starting router due to " + th.getMessage());
|
||||
// } else {
|
||||
// s_logger.error("Unable to create router", th);
|
||||
// }
|
||||
// txn.rollback();
|
||||
//
|
||||
// if (router != null && router.getState() == State.Creating) {
|
||||
// _routerDao.expunge(router.getId());
|
||||
// }
|
||||
// return null;
|
||||
// } finally {
|
||||
// if (account != null) {
|
||||
// if(s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Releasing lock on account " + account.getId() + " for createRouter");
|
||||
// }
|
||||
// _accountDao.releaseFromLockTable(account.getId());
|
||||
// }
|
||||
// if(!success){
|
||||
// EventVO event = new EventVO();
|
||||
// event.setUserId(1L); // system user performed the action
|
||||
// event.setAccountId(accountId);
|
||||
// event.setType(EventTypes.EVENT_ROUTER_CREATE);
|
||||
// event.setStartId(startEventId);
|
||||
// event.setLevel(EventVO.LEVEL_ERROR);
|
||||
// event.setDescription("Failed to create router for account " + accountId + " in data center " + dataCenterId);
|
||||
// _eventDao.persist(event);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public boolean destroyRouter(final long routerId) {
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
|
|
@ -478,9 +796,9 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||
}
|
||||
|
||||
private boolean resendDhcpEntries(final DomainRouterVO router){
|
||||
final List<UserVmVO> vms = _vmDao.listBy(router.getId(), State.Creating, State.Starting, State.Running, State.Stopping, State.Stopped, State.Migrating);
|
||||
final List<? extends UserVm> vms = _vmDao.listBy(router.getId(), State.Creating, State.Starting, State.Running, State.Stopping, State.Stopped, State.Migrating);
|
||||
Commands cmds = new Commands(OnError.Continue);
|
||||
for (UserVmVO vm: vms) {
|
||||
for (UserVm vm: vms) {
|
||||
if (vm.getGuestIpAddress() == null || vm.getGuestMacAddress() == null || vm.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1477,9 +1795,17 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||
}
|
||||
//source NAT address is stored in /proc/cmdline of the domR and gets
|
||||
//reassigned upon powerup. Source NAT rule gets configured in StartRouter command
|
||||
final List<IPAddressVO> ipAddrs = _networkMgr.listPublicIpAddressesInVirtualNetwork(router.getAccountId(), router.getDataCenterId(), null);
|
||||
if (!ipAddrs.isEmpty()) {
|
||||
cmds = getAssociateIPCommands(router, ipAddrs, cmds, 0);
|
||||
final List<IPAddressVO> userIps = _networkMgr.listPublicIpAddressesInVirtualNetwork(router.getAccountId(), router.getDataCenterId(), null);
|
||||
List<PublicIpAddress> publicIps = new ArrayList<PublicIpAddress>();
|
||||
if (userIps != null && !userIps.isEmpty()) {
|
||||
for (IPAddressVO userIp : userIps) {
|
||||
PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), userIp.getMacAddress());
|
||||
publicIps.add((PublicIpAddress)publicIp);
|
||||
}
|
||||
|
||||
}
|
||||
if (!publicIps.isEmpty()) {
|
||||
cmds = getAssociateIPCommands(router, publicIps, cmds, 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1840,49 +2166,34 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||
// }
|
||||
|
||||
|
||||
private Commands getAssociateIPCommands(final DomainRouterVO router, final List<? extends IpAddress> ipAddrList, Commands cmds, long vmId) {
|
||||
boolean sourceNat = false;
|
||||
Map<VlanVO, ArrayList<IpAddress>> vlanIpMap = new HashMap<VlanVO, ArrayList<IpAddress>>();
|
||||
for (final IpAddress ip: ipAddrList) {
|
||||
VlanVO vlan = _vlanDao.findById(ip.getVlanId());
|
||||
ArrayList<IpAddress> ipList = vlanIpMap.get(vlan);
|
||||
if (ipList == null) {
|
||||
ipList = new ArrayList<IpAddress>();
|
||||
private Commands getAssociateIPCommands(final DomainRouterVO router, final List<? extends PublicIpAddress> ipAddrList, Commands cmds, long vmId) {
|
||||
|
||||
//Ip addresses have to be sorted before sending
|
||||
Collections.sort(ipAddrList, new Comparator<IpAddress>() {
|
||||
@Override
|
||||
public int compare(IpAddress o1, IpAddress o2) {
|
||||
return o1.getAddress().compareTo(o2.getAddress());
|
||||
} });
|
||||
|
||||
boolean firstIP = true;
|
||||
|
||||
for (final PublicIpAddress ip: ipAddrList) {
|
||||
|
||||
boolean add = (ip.getState() == IpAddress.State.Releasing ? false : true);
|
||||
boolean sourceNat = ip.isSourceNat();
|
||||
String vlanId = ip.getVlanTag();
|
||||
String vlanGateway = ip.getGateway();
|
||||
String vlanNetmask = ip.getNetmask();
|
||||
String vifMacAddress = ip.getMacAddress();
|
||||
|
||||
String vmGuestAddress = null;
|
||||
if(vmId!=0){
|
||||
vmGuestAddress = _vmDao.findById(vmId).getGuestIpAddress();
|
||||
}
|
||||
ipList.add(ip);
|
||||
vlanIpMap.put(vlan, ipList);
|
||||
}
|
||||
for (Map.Entry<VlanVO, ArrayList<IpAddress>> vlanAndIp: vlanIpMap.entrySet()) {
|
||||
boolean firstIP = true;
|
||||
ArrayList<IpAddress> ipList = vlanAndIp.getValue();
|
||||
Collections.sort(ipList, new Comparator<IpAddress>() {
|
||||
@Override
|
||||
public int compare(IpAddress o1, IpAddress o2) {
|
||||
return o1.getAddress().compareTo(o2.getAddress());
|
||||
} });
|
||||
|
||||
for (final IpAddress ip: ipList) {
|
||||
boolean add = (ip.getState() == IpAddress.State.Releasing ? false : true);
|
||||
sourceNat = ip.isSourceNat();
|
||||
VlanVO vlan = vlanAndIp.getKey();
|
||||
String vlanId = vlan.getVlanId();
|
||||
String vlanGateway = vlan.getVlanGateway();
|
||||
String vlanNetmask = vlan.getVlanNetmask();
|
||||
cmds.addCommand("IPAssocCommand", new IPAssocCommand(router.getInstanceName(), router.getPrivateIpAddress(), ip.getAddress(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress));
|
||||
|
||||
String vifMacAddress = null;
|
||||
if (firstIP && add) {
|
||||
String[] macAddresses = _dcDao.getNextAvailableMacAddressPair(ip.getDataCenterId());
|
||||
vifMacAddress = macAddresses[1];
|
||||
}
|
||||
String vmGuestAddress = null;
|
||||
if(vmId!=0){
|
||||
vmGuestAddress = _vmDao.findById(vmId).getGuestIpAddress();
|
||||
}
|
||||
|
||||
cmds.addCommand("IPAssocCommand", new IPAssocCommand(router.getInstanceName(), router.getPrivateIpAddress(), ip.getAddress(), add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, vmGuestAddress));
|
||||
|
||||
firstIP = false;
|
||||
}
|
||||
firstIP = false;
|
||||
}
|
||||
return cmds;
|
||||
}
|
||||
|
|
@ -1914,7 +2225,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean associateIP (Network network, List<? extends IpAddress> ipAddress) {
|
||||
public boolean associateIP (Network network, List<? extends PublicIpAddress> ipAddress) {
|
||||
DomainRouterVO router = _routerDao.findByNetworkConfiguration(network.getId());
|
||||
if (router == null) {
|
||||
s_logger.warn("Unable to associate ip addresses, virtual router doesn't exist in the network " + network.getId());
|
||||
|
|
@ -1942,27 +2253,25 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||
throw new ResourceUnavailableException("Unable to apply lb rules");
|
||||
}
|
||||
|
||||
if (router.getState() == State.Running || router.getState() == State.Starting) {
|
||||
List<LoadBalancingRule> loadBalancingRules = new ArrayList<LoadBalancingRule>();
|
||||
|
||||
for (FirewallRule rule : rules) {
|
||||
loadBalancingRules.add((LoadBalancingRule) rule);
|
||||
}
|
||||
|
||||
if (router.getState() == State.Running || router.getState() == State.Starting || router.getState() == State.Stopped) {
|
||||
|
||||
Commands cmds = new Commands(OnError.Continue);
|
||||
|
||||
for (LoadBalancingRule rule : loadBalancingRules) {
|
||||
List<LoadBalancerTO> lbs = new ArrayList<LoadBalancerTO>();
|
||||
for (FirewallRule fwRule : rules) {
|
||||
LoadBalancingRule rule = (LoadBalancingRule) fwRule;
|
||||
boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
|
||||
String protocol = rule.getProtocol();
|
||||
String algorithm = rule.getAlgorithm();
|
||||
String srcIp = rule.getSourceIpAddress().addr();
|
||||
int srcPort = rule.getSourcePortStart();
|
||||
List<LbDestination> destinations = rule.getDestinations();
|
||||
|
||||
LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(srcIp, srcPort, protocol, algorithm, revoked, false, destinations);
|
||||
cmds.addCommand(cmd);
|
||||
List<LbDestination> destinations = rule.getDestinations();
|
||||
LoadBalancerTO lb = new LoadBalancerTO(srcIp, srcPort, protocol, algorithm, revoked, false, destinations);
|
||||
lbs.add(lb);
|
||||
}
|
||||
|
||||
LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs);
|
||||
cmds.addCommand(cmd);
|
||||
|
||||
//Send commands to router
|
||||
return sendCommandsToRouter(router, cmds);
|
||||
|
||||
|
|
@ -1973,7 +2282,6 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||
s_logger.warn("Unable to apply load balancer rules, virtual router is not in the right state " + router.getState());
|
||||
throw new ResourceUnavailableException("Unable to apply load balancer rules, domR is not in right state " + router.getState());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1420,9 +1420,9 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
|
||||
SearchBuilder<VlanVO> sb = _vlanDao.createSearchBuilder();
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("vlan", sb.entity().getVlanId(), SearchCriteria.Op.EQ);
|
||||
sb.and("vlan", sb.entity().getVlanTag(), SearchCriteria.Op.EQ);
|
||||
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
sb.and("vlan", sb.entity().getVlanId(), SearchCriteria.Op.EQ);
|
||||
sb.and("vlan", sb.entity().getVlanTag(), SearchCriteria.Op.EQ);
|
||||
sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ);
|
||||
sb.and("vlanType", sb.entity().getVlanType(), SearchCriteria.Op.EQ);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -132,9 +132,7 @@ import com.cloud.network.dao.LoadBalancerVMMapDao;
|
|||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.router.DomainRouterManager;
|
||||
import com.cloud.network.rules.RulesManager;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.network.security.SecurityGroupManager;
|
||||
import com.cloud.network.security.SecurityGroupVO;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
|
|
@ -350,6 +348,35 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopVirtualMachine(long userId, long vmId, long eventId) {
|
||||
boolean status = false;
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Stopping vm=" + vmId);
|
||||
}
|
||||
UserVmVO vm = _vmDao.findById(vmId);
|
||||
if (vm == null || vm.getRemoved() != null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("VM is either removed or deleted.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_STOP, "stopping Vm with Id: "+vmId, eventId);
|
||||
|
||||
status = stop(userId, vm, 0);
|
||||
|
||||
if(status){
|
||||
EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_STOP, "Successfully stopped VM instance : " + vmId);
|
||||
return status;
|
||||
}
|
||||
else {
|
||||
EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP, "Error stopping VM instance : " + vmId);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Volume attachVolumeToVM(AttachVolumeCmd command) {
|
||||
Long vmId = command.getVirtualMachineId();
|
||||
|
|
@ -786,36 +813,25 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
return (a != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopVirtualMachine(long userId, long vmId, long eventId) {
|
||||
boolean status = false;
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Stopping vm=" + vmId);
|
||||
}
|
||||
|
||||
UserVmVO vm = _vmDao.findById(vmId);
|
||||
if (vm == null || vm.getRemoved() != null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("VM is either removed or deleted.");
|
||||
|
||||
private void checkIfPoolAvailable(long vmId) throws StorageUnavailableException {
|
||||
//check if the sp is up before starting
|
||||
List<VolumeVO> rootVolList = _volsDao.findByInstanceAndType(vmId, VolumeType.ROOT);
|
||||
if(rootVolList == null || rootVolList.size() == 0){
|
||||
throw new StorageUnavailableException("Could not find the root disk for this vm to verify if the pool on which it exists is Up or not");
|
||||
}else{
|
||||
Long poolId = rootVolList.get(0).getPoolId();//each vm has 1 root vol
|
||||
StoragePoolVO sp = _storagePoolDao.findById(poolId);
|
||||
if(sp == null){
|
||||
throw new StorageUnavailableException("Could not find the pool for the root disk of vm"+vmId+", to confirm if it is Up or not");
|
||||
}else{
|
||||
//found pool
|
||||
if(!sp.getStatus().equals(com.cloud.host.Status.Up) && !sp.getStatus().equals(com.cloud.host.Status.CancelMaintenance)){
|
||||
throw new StorageUnavailableException("Could not start the vm; the associated storage pool is in:"+sp.getStatus().toString()+" state");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
EventUtils.saveStartedEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_STOP, "stopping Vm with Id: "+vmId, eventId);
|
||||
|
||||
status = stop(userId, vm, 0);
|
||||
|
||||
if(status)
|
||||
{
|
||||
EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_STOP, "Successfully stopped VM instance : " + vmId);
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventUtils.saveEvent(userId, vm.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_VM_STOP, "Error stopping VM instance : " + vmId);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean rebootVirtualMachine(long userId, long vmId) {
|
||||
UserVmVO vm = _vmDao.findById(vmId);
|
||||
|
|
@ -1976,6 +1992,267 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
|||
return privateTemplate;
|
||||
}
|
||||
|
||||
// @DB
|
||||
// @Override
|
||||
// public UserVmVO createDirectlyAttachedVM(Long vmId, long userId, AccountVO account, DataCenterVO dc, ServiceOfferingVO offering, VMTemplateVO template, DiskOfferingVO diskOffering, String displayName, String userData, List<StoragePoolVO> a, List<NetworkGroupVO> networkGroups, long startEventId, long size) throws CloudRuntimeException, ResourceAllocationException {
|
||||
//
|
||||
// long accountId = account.getId();
|
||||
// long dataCenterId = dc.getId();
|
||||
// long serviceOfferingId = offering.getId();
|
||||
// long templateId = -1;
|
||||
// if (template != null) {
|
||||
// templateId = template.getId();
|
||||
// }
|
||||
//
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Creating directly attached vm for account id=" + account.getId() +
|
||||
// ", name="+ account.getAccountName() + "; dc=" + dc.getName() +
|
||||
// "; offering=" + offering.getId() + "; diskOffering=" + ((diskOffering != null) ? diskOffering.getName() : "none") +
|
||||
// "; template=" + templateId);
|
||||
// }
|
||||
//
|
||||
// // Determine the Guest OS Id
|
||||
// long guestOSId;
|
||||
// if (template != null) {
|
||||
// guestOSId = template.getGuestOSId();
|
||||
// } else {
|
||||
// throw new CloudRuntimeException("No template or ISO was specified for the VM.");
|
||||
// }
|
||||
//
|
||||
// Transaction txn = Transaction.currentTxn();
|
||||
// txn.start();
|
||||
//
|
||||
// account = _accountDao.lockRow(accountId, true);
|
||||
// if (account == null) {
|
||||
// throw new CloudRuntimeException("Unable to lock up the account: " + accountId);
|
||||
// }
|
||||
//
|
||||
// // First check that the maximum number of UserVMs for the given accountId will not be exceeded
|
||||
// if (_accountMgr.resourceLimitExceeded(account, ResourceType.user_vm)) {
|
||||
// ResourceAllocationException rae = new ResourceAllocationException("Maximum number of virtual machines for account: " + account.getAccountName() + " has been exceeded.");
|
||||
// rae.setResourceType("vm");
|
||||
// throw rae;
|
||||
// }
|
||||
// _accountMgr.incrementResourceCount(account.getId(), ResourceType.user_vm);
|
||||
// boolean isIso = Storage.ImageFormat.ISO.equals(template.getFormat());
|
||||
// long numVolumes = (isIso || (diskOffering == null)) ? 1 : 2;
|
||||
// _accountMgr.incrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
|
||||
// txn.commit();
|
||||
//
|
||||
// try {
|
||||
// UserVmVO vm = null;
|
||||
//
|
||||
// final String name = VirtualMachineName.getVmName(vmId, accountId, _instance);
|
||||
//
|
||||
// final String[] macAddresses = _dcDao.getNextAvailableMacAddressPair(dc.getId());
|
||||
// long routerId = -1;
|
||||
// long poolId = 0;
|
||||
// Pair<HostPodVO, Long> pod = null;
|
||||
// DomainRouterVO router = null;
|
||||
// Set<Long> avoids = new HashSet<Long>();
|
||||
// VlanVO guestVlan = null;
|
||||
// List<VlanVO> vlansForAccount = _vlanDao.listVlansForAccountByType(dc.getId(), account.getId(), VlanType.DirectAttached);
|
||||
// List<VlanVO> vlansForPod = null;
|
||||
// List<VlanVO> zoneWideVlans = null;
|
||||
//
|
||||
// boolean forAccount = false;
|
||||
// boolean forZone = false;
|
||||
// if (vlansForAccount.size() > 0) {
|
||||
// forAccount = true;
|
||||
// guestVlan = vlansForAccount.get(0);//FIXME: iterate over all vlans
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //list zone wide vlans that are direct attached and tagged
|
||||
// //if exists pick random one
|
||||
// //set forZone = true
|
||||
//
|
||||
// //note the dao method below does a NEQ on vlan id, hence passing untagged
|
||||
// zoneWideVlans = _vlanDao.searchForZoneWideVlans(dc.getId(),VlanType.DirectAttached.toString(),"untagged");
|
||||
//
|
||||
// if(zoneWideVlans!=null && zoneWideVlans.size()>0){
|
||||
// forZone = true;
|
||||
// guestVlan = zoneWideVlans.get(0);//FIXME: iterate over all vlans
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// while ((pod = _agentMgr.findPod(template, offering, dc, account.getId(), avoids)) != null) {
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Attempting to create direct attached vm in pod " + pod.first().getName());
|
||||
// }
|
||||
// if (!forAccount && !forZone) {
|
||||
// vlansForPod = _vlanDao.listVlansForPodByType(pod.first().getId(), VlanType.DirectAttached);
|
||||
// if (vlansForPod.size() < 1) {
|
||||
// avoids.add(pod.first().getId());
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("No direct attached vlans available in pod " + pod.first().getName() + " (id:" + pod.first().getId() + "), checking other pods");
|
||||
// }
|
||||
// continue;
|
||||
// }
|
||||
// guestVlan = vlansForPod.get(0);//FIXME: iterate over all vlans
|
||||
// }
|
||||
//
|
||||
// List<DomainRouterVO> rtrs = _routerDao.listByVlanDbId(guestVlan.getId());
|
||||
// assert rtrs.size() < 2 : "How did we get more than one router per vlan?";
|
||||
// if (rtrs.size() > 0) {
|
||||
// router = rtrs.get(0);
|
||||
// routerId = router.getId();
|
||||
// } else if (rtrs.size() == 0) {
|
||||
// router = _routerMgr.createDhcpServerForDirectlyAttachedGuests(userId, accountId, dc, pod.first(), pod.second(), guestVlan);
|
||||
// if (router == null) {
|
||||
// avoids.add(pod.first().getId());
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Unable to create DHCP server in vlan " + guestVlan.getVlanTag() + ", pod=" + pod.first().getName() + " (podid:" + pod.first().getId() + "), checking other pods");
|
||||
// }
|
||||
// continue;
|
||||
// }
|
||||
// routerId = router.getId();
|
||||
// }
|
||||
// String guestIp = null;
|
||||
//
|
||||
// if(forAccount)
|
||||
// {
|
||||
// for(VlanVO vlanForAcc : vlansForAccount)
|
||||
// {
|
||||
// guestIp = null;//_ipAddressDao.assignIpAddress(accountId, account.getDomainId(), vlanForAcc.getId(), false).getAddress();
|
||||
// if(guestIp!=null) {
|
||||
// break; //got an ip
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if(!forAccount && !forZone)
|
||||
// {
|
||||
// //i.e. for pod
|
||||
// for(VlanVO vlanForPod : vlansForPod)
|
||||
// {
|
||||
// guestIp = null; // _ipAddressDao.assignIpAddress(accountId, account.getDomainId(), vlanForPod.getId(), false).getAddress();
|
||||
// if(guestIp!=null) {
|
||||
// break;//got an ip
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //for zone
|
||||
// for(VlanVO vlanForZone : zoneWideVlans)
|
||||
// {
|
||||
// guestIp = null;// _ipAddressDao.assignIpAddress(accountId, account.getDomainId(), vlanForZone.getId(), false).getAddress();
|
||||
// if(guestIp!=null) {
|
||||
// break;//found an ip
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (guestIp == null) {
|
||||
// s_logger.debug("No guest IP available in pod id=" + pod.first().getId());
|
||||
// avoids.add(pod.first().getId());
|
||||
// continue;
|
||||
// }
|
||||
// s_logger.debug("Acquired a guest IP, ip=" + guestIp);
|
||||
// String guestMacAddress = macAddresses[0];
|
||||
// String externalMacAddress = macAddresses[1];
|
||||
// Long externalVlanDbId = null;
|
||||
//
|
||||
// vm = new UserVmVO(vmId, name, templateId, guestOSId, accountId, account.getDomainId(),
|
||||
// serviceOfferingId, guestMacAddress, guestIp, guestVlan.getVlanNetmask(),
|
||||
// null, externalMacAddress, externalVlanDbId,
|
||||
// routerId, pod.first().getId(), dataCenterId,
|
||||
// offering.getOfferHA(), displayName, userData);
|
||||
//
|
||||
// if (diskOffering != null) {
|
||||
// vm.setMirroredVols(diskOffering.isMirrored());
|
||||
// }
|
||||
//
|
||||
// vm.setLastHostId(pod.second());
|
||||
// vm = _vmDao.persist(vm);
|
||||
// boolean addedToGroups = _networkGroupMgr.addInstanceToGroups(vmId, networkGroups);
|
||||
// if (!addedToGroups) {
|
||||
// s_logger.warn("Not all specified network groups can be found");
|
||||
// _vmDao.expunge(vm.getId());
|
||||
// throw new InvalidParameterValueException("Not all specified network groups can be found");
|
||||
// }
|
||||
//
|
||||
// vm = _vmDao.findById(vmId);
|
||||
// try {
|
||||
// poolId = _storageMgr.createUserVM(account, vm, template, dc, pod.first(), offering, diskOffering, a,size);
|
||||
// } catch (CloudRuntimeException e) {
|
||||
// _vmDao.expunge(vmId);
|
||||
// _ipAddressDao.unassignIpAddress(guestIp);
|
||||
// s_logger.debug("Released a guest ip address because we could not find storage: ip=" + guestIp);
|
||||
// guestIp = null;
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("Unable to find storage host in pod " + pod.first().getName() + " (id:" + pod.first().getId() + "), checking other pods");
|
||||
// }
|
||||
// avoids.add(pod.first().getId());
|
||||
// continue; // didn't find a storage host in pod, go to the next pod
|
||||
// }
|
||||
//
|
||||
// EventVO event = new EventVO();
|
||||
// event.setUserId(userId);
|
||||
// event.setAccountId(accountId);
|
||||
// event.setType(EventTypes.EVENT_NET_IP_ASSIGN);
|
||||
// event.setParameters("guestIPaddress=" + guestIp + "\nvmName=" + vm.getName() + "\ndcId=" + vm.getDataCenterId());
|
||||
// event.setDescription("acquired a public ip: " + guestIp);
|
||||
// _eventDao.persist(event);
|
||||
//
|
||||
// break; // if we got here, we found a host and can stop searching the pods
|
||||
// }
|
||||
//
|
||||
// if (poolId == 0) {
|
||||
// if(vm != null && vm.getName()!=null && vm.getDisplayName() != null)
|
||||
// {
|
||||
// if(!vm.getName().equals(vm.getDisplayName())) {
|
||||
// s_logger.debug("failed to create VM instance : " + name+"("+vm.getInstanceName()+")");
|
||||
// } else {
|
||||
// s_logger.debug("failed to create VM instance : " + name);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// s_logger.debug("failed to create VM instance : " + name);
|
||||
// throw new CloudRuntimeException("We could not find a suitable pool for creating this directly attached vm");
|
||||
//
|
||||
// }
|
||||
// _accountMgr.decrementResourceCount(account.getId(), ResourceType.user_vm);
|
||||
// _accountMgr.decrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// txn.start();
|
||||
// EventVO event = new EventVO();
|
||||
// event.setUserId(userId);
|
||||
// event.setAccountId(accountId);
|
||||
// event.setType(EventTypes.EVENT_VM_CREATE);
|
||||
// event.setStartId(startEventId);
|
||||
// event.setState(Event.State.Completed);
|
||||
// String diskOfferingIdentifier = (diskOffering != null) ? String.valueOf(diskOffering.getId()) : "-1";
|
||||
// String eventParams = "id=" + vm.getId() + "\nvmName=" + vm.getName() + "\nsoId=" + vm.getServiceOfferingId() + "\ndoId=" + diskOfferingIdentifier + "\ntId=" + vm.getTemplateId() + "\ndcId=" + vm.getDataCenterId();
|
||||
// event.setParameters(eventParams);
|
||||
// if(!vm.getName().equals(vm.getDisplayName())) {
|
||||
// event.setDescription("successfully created VM instance : " + vm.getName()+"("+vm.getInstanceName()+")");
|
||||
// } else {
|
||||
// event.setDescription("successfully created VM instance : " + vm.getName());
|
||||
// }
|
||||
// _eventDao.persist(event);
|
||||
//
|
||||
// _itMgr.stateTransitTo(vm, VirtualMachine.Event.OperationSucceeded, null);
|
||||
// if (s_logger.isDebugEnabled()) {
|
||||
// s_logger.debug("vm created " + vmId);
|
||||
// }
|
||||
// txn.commit();
|
||||
//
|
||||
// return _vmDao.findById(vmId);
|
||||
// } catch (Throwable th) {
|
||||
// _accountMgr.decrementResourceCount(account.getId(), ResourceType.user_vm);
|
||||
// _accountMgr.decrementResourceCount(account.getId(), ResourceType.volume, numVolumes);
|
||||
//
|
||||
// s_logger.error("Unable to create vm", th);
|
||||
// throw new CloudRuntimeException("Unable to create vm: "+th.getMessage(), th);
|
||||
// } finally{
|
||||
// updateVmStateForFailedVmCreation(vmId);
|
||||
// }
|
||||
// }
|
||||
|
||||
//used for vm transitioning to error state
|
||||
private void updateVmStateForFailedVmCreation(Long vmId) {
|
||||
UserVmVO vm = _vmDao.findById(vmId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue