CS-15644 Implemented UUIDs for templateId, serviceOfferingId, zoneId, domainId replacing the ids being passed to

Netscaler in the API url

Reviewed By: Vijay V.
This commit is contained in:
Deepak Garg 2012-07-30 11:35:19 +05:30
parent 1dab5371cd
commit 211b60ef64
11 changed files with 5929 additions and 5866 deletions

View File

@ -30,7 +30,7 @@ import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.utils.Pair;
public class LoadBalancerTO implements Serializable {
Long id;
String uuid;
String srcIp;
int srcPort;
String protocol;
@ -42,11 +42,11 @@ public class LoadBalancerTO implements Serializable {
private AutoScaleVmGroupTO autoScaleVmGroupTO;
final static int MAX_STICKINESS_POLICIES = 1;
public LoadBalancerTO(Long id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> destinations) {
if(destinations == null) { // for autoscaleconfig destinations will be null;
public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> destinations) {
if (destinations == null) { // for autoscaleconfig destinations will be null;
destinations = new ArrayList<LbDestination>();
}
this.id = id;
this.uuid = uuid;
this.srcIp = srcIp;
this.srcPort = srcPort;
this.protocol = protocol;
@ -61,7 +61,7 @@ public class LoadBalancerTO implements Serializable {
}
}
public LoadBalancerTO(Long id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> arg_destinations, List<LbStickinessPolicy> stickinessPolicies) {
public LoadBalancerTO(String id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> arg_destinations, List<LbStickinessPolicy> stickinessPolicies) {
this(id, srcIp, srcPort, protocol, algorithm, revoked, alreadyAdded, arg_destinations);
this.stickinessPolicies = null;
if (stickinessPolicies != null && stickinessPolicies.size() > 0) {
@ -85,8 +85,8 @@ public class LoadBalancerTO implements Serializable {
protected LoadBalancerTO() {
}
public Long getId() {
return id;
public String getUuid() {
return uuid;
}
public String getSrcIp() {
@ -133,7 +133,7 @@ public class LoadBalancerTO implements Serializable {
return this.autoScaleVmGroupTO != null;
}
public static class StickinessPolicyTO implements Serializable{
public static class StickinessPolicyTO implements Serializable {
private final String _methodName;
private final List<Pair<String, String>> _paramsList;
@ -151,7 +151,7 @@ public class LoadBalancerTO implements Serializable {
}
}
public static class DestinationTO implements Serializable{
public static class DestinationTO implements Serializable {
String destIp;
int destPort;
boolean revoked;
@ -184,7 +184,7 @@ public class LoadBalancerTO implements Serializable {
}
}
public static class CounterTO implements Serializable{
public static class CounterTO implements Serializable {
private final String name;
private final String source;
private final String value;
@ -208,7 +208,7 @@ public class LoadBalancerTO implements Serializable {
}
}
public static class ConditionTO implements Serializable{
public static class ConditionTO implements Serializable {
private final long threshold;
private final String relationalOperator;
private final CounterTO counter;
@ -233,7 +233,7 @@ public class LoadBalancerTO implements Serializable {
}
}
public static class AutoScalePolicyTO implements Serializable{
public static class AutoScalePolicyTO implements Serializable {
private final long id;
private final int duration;
private final int quietTime;
@ -275,11 +275,11 @@ public class LoadBalancerTO implements Serializable {
}
}
public static class AutoScaleVmProfileTO implements Serializable{
private final Long zoneId;
private final Long domainId;
private final Long serviceOfferingId;
private final Long templateId;
public static class AutoScaleVmProfileTO implements Serializable {
private final String zoneId;
private final String domainId;
private final String serviceOfferingId;
private final String templateId;
private final String otherDeployParams;
private final String snmpCommunity;
private final Integer snmpPort;
@ -288,7 +288,7 @@ public class LoadBalancerTO implements Serializable {
private final String autoScaleUserApiKey;
private final String autoScaleUserSecretKey;
public AutoScaleVmProfileTO(Long zoneId, Long domainId, String cloudStackApiUrl, String autoScaleUserApiKey, String autoScaleUserSecretKey, Long serviceOfferingId, Long templateId,
public AutoScaleVmProfileTO(String zoneId, String domainId, String cloudStackApiUrl, String autoScaleUserApiKey, String autoScaleUserSecretKey, String serviceOfferingId, String templateId,
String otherDeployParams, String snmpCommunity, Integer snmpPort, Integer destroyVmGraceperiod) {
this.zoneId = zoneId;
this.domainId = domainId;
@ -303,19 +303,19 @@ public class LoadBalancerTO implements Serializable {
this.autoScaleUserSecretKey = autoScaleUserSecretKey;
}
public Long getZoneId() {
public String getZoneId() {
return zoneId;
}
public Long getDomainId() {
public String getDomainId() {
return domainId;
}
public Long getServiceOfferingId() {
public String getServiceOfferingId() {
return serviceOfferingId;
}
public Long getTemplateId() {
public String getTemplateId() {
return templateId;
}
@ -348,7 +348,7 @@ public class LoadBalancerTO implements Serializable {
}
}
public static class AutoScaleVmGroupTO implements Serializable{
public static class AutoScaleVmGroupTO implements Serializable {
private final int minMembers;
private final int maxMembers;
private final int memberPort;
@ -419,9 +419,9 @@ public class LoadBalancerTO implements Serializable {
LbAutoScaleVmProfile lbAutoScaleVmProfile = lbAutoScaleVmGroup.getProfile();
AutoScaleVmProfile autoScaleVmProfile = lbAutoScaleVmProfile.getProfile();
AutoScaleVmProfileTO autoScaleVmProfileTO = new AutoScaleVmProfileTO(autoScaleVmProfile.getZoneId(), autoScaleVmProfile.getDomainId(),
AutoScaleVmProfileTO autoScaleVmProfileTO = new AutoScaleVmProfileTO(lbAutoScaleVmProfile.getZoneId(), lbAutoScaleVmProfile.getDomainId(),
lbAutoScaleVmProfile.getCsUrl(), lbAutoScaleVmProfile.getAutoScaleUserApiKey(), lbAutoScaleVmProfile.getAutoScaleUserSecretKey(),
autoScaleVmProfile.getServiceOfferingId(), autoScaleVmProfile.getTemplateId(), autoScaleVmProfile.getOtherDeployParams(),
lbAutoScaleVmProfile.getServiceOfferingId(), lbAutoScaleVmProfile.getTemplateId(), autoScaleVmProfile.getOtherDeployParams(),
autoScaleVmProfile.getSnmpCommunity(), autoScaleVmProfile.getSnmpPort(), autoScaleVmProfile.getDestroyVmGraceperiod());
AutoScaleVmGroup autoScaleVmGroup = lbAutoScaleVmGroup.getVmGroup();

View File

@ -49,4 +49,6 @@ public interface AutoScaleVmGroup extends ControlledEntity {
String getState();
String getUuid();
}

View File

@ -75,6 +75,11 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
return lb.getAlgorithm();
}
@Override
public String getUuid() {
return lb.getUuid();
}
@Override
public String getXid() {
return lb.getXid();
@ -298,12 +303,20 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
private final String autoScaleUserApiKey;
private final String autoScaleUserSecretKey;
private final String csUrl;
private final String zoneId;
private final String domainId;
private final String serviceOfferingId;
private final String templateId;
public LbAutoScaleVmProfile(AutoScaleVmProfile profile, String autoScaleUserApiKey, String autoScaleUserSecretKey, String csUrl) {
public LbAutoScaleVmProfile(AutoScaleVmProfile profile, String autoScaleUserApiKey, String autoScaleUserSecretKey, String csUrl, String zoneId, String domainId, String serviceOfferingId, String templateId) {
this.profile = profile;
this.autoScaleUserApiKey = autoScaleUserApiKey;
this.autoScaleUserSecretKey = autoScaleUserSecretKey;
this.csUrl = csUrl;
this.zoneId = zoneId;
this.domainId = domainId;
this.serviceOfferingId = serviceOfferingId;
this.templateId = templateId;
}
public AutoScaleVmProfile getProfile() {
@ -317,9 +330,26 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
public String getAutoScaleUserSecretKey() {
return autoScaleUserSecretKey;
}
public String getCsUrl() {
return csUrl;
}
public String getZoneId() {
return zoneId;
}
public String getDomainId() {
return domainId;
}
public String getServiceOfferingId() {
return serviceOfferingId;
}
public String getTemplateId() {
return templateId;
}
}
public static class LbAutoScaleVmGroup {
@ -345,4 +375,5 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
return profile;
}
}
}

View File

@ -13,7 +13,7 @@
package com.cloud.network.rules;
/**
* Definition for a LoadBalancer
* Definition for a LoadBalancer
*/
public interface LoadBalancer extends FirewallRule {
@ -22,9 +22,10 @@ public interface LoadBalancer extends FirewallRule {
String getDescription();
int getDefaultPortStart();
int getDefaultPortEnd();
String getAlgorithm();
String getUuid();
}

File diff suppressed because it is too large Load Diff

View File

@ -111,6 +111,7 @@ import com.cloud.vm.Nic.State;
import com.cloud.vm.NicVO;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase implements ExternalLoadBalancerDeviceManager, ResourceStateAdapter {
@Inject
@ -148,6 +149,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
@Inject
UserStatisticsDao _userStatsDao;
@Inject
LoadBalancerDao _lbDao;
@Inject
NetworkDao _networkDao;
@Inject
DomainRouterDao _routerDao;
@ -795,7 +798,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
String protocol = rule.getProtocol();
String algorithm = rule.getAlgorithm();
Long lbId = rule.getId();
String uuid = rule.getUuid();
String srcIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress().addr();
int srcPort = rule.getSourcePortStart();
List<LbDestination> destinations = rule.getDestinations();
@ -862,8 +865,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
}
if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) {
LoadBalancerTO loadBalancer = new LoadBalancerTO(lbId, srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies());
if(rule.isAutoScaleConfig())
LoadBalancerTO loadBalancer = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies());
if (rule.isAutoScaleConfig())
loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
loadBalancersToApply.add(loadBalancer);
}

View File

@ -178,4 +178,9 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup {
public void setLoadBalancerId(Long loadBalancerId) {
this.loadBalancerId = loadBalancerId;
}
@Override
public String getUuid() {
return uuid;
}
}

View File

@ -99,7 +99,7 @@ import com.google.gson.Gson;
@Local(value = NetworkElement.class)
public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl implements LoadBalancingServiceProvider, NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager, IpDeployer,
StaticNatServiceProvider {
StaticNatServiceProvider {
private static final Logger s_logger = Logger.getLogger(NetscalerElement.class);
@ -150,7 +150,7 @@ StaticNatServiceProvider {
@Override
public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
InsufficientNetworkCapacityException {
InsufficientNetworkCapacityException {
if (!canHandle(guestConfig, Service.Lb)) {
return false;
@ -163,7 +163,7 @@ StaticNatServiceProvider {
}
if (isBasicZoneNetwok(guestConfig)) {
// in basic zone there is nothing to be implemented/shutdown on the NetScaler appliance
// in basic zone there is nothing to be implemented/shutdown on the NetScaler appliance
return true;
}
@ -176,7 +176,7 @@ StaticNatServiceProvider {
@Override
public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
InsufficientNetworkCapacityException, ResourceUnavailableException {
InsufficientNetworkCapacityException, ResourceUnavailableException {
return true;
}
@ -192,9 +192,9 @@ StaticNatServiceProvider {
}
if (isBasicZoneNetwok(guestConfig)) {
// in basic zone there is nothing to be implemented/shutdown on the NetScaler appliance
// in basic zone there is nothing to be implemented/shutdown on the NetScaler appliance
return true;
}
}
try {
return manageGuestNetworkWithExternalLoadBalancer(false, guestConfig);
@ -523,7 +523,7 @@ StaticNatServiceProvider {
@Override
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException {
ResourceUnavailableException {
// TODO reset the configuration on all of the netscaler devices in this physical network
return true;
}
@ -544,17 +544,17 @@ StaticNatServiceProvider {
}
@Override
public boolean verifyServicesCombination(Set<Service> services) {
public boolean verifyServicesCombination(Set<Service> services) {
Set<Service> netscalerServices = new HashSet<Service>();
netscalerServices.add(Service.Lb);
netscalerServices.add(Service.StaticNat);
// NetScaler can only act as Lb and Static Nat service provider
if (services != null && !services.isEmpty() && !netscalerServices.containsAll(services)) {
String servicesList = "";
for (Service service : services) {
servicesList += service.getName() + " ";
}
String servicesList = "";
for (Service service : services) {
servicesList += service.getName() + " ";
}
s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination "
+ servicesList + " is not supported.");
return false;
@ -616,8 +616,8 @@ StaticNatServiceProvider {
List<LbDestination> destinations = rule.getDestinations();
if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) {
LoadBalancerTO loadBalancer = new LoadBalancerTO(rule.getId(), srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies());
if(rule.isAutoScaleConfig()) {
LoadBalancerTO loadBalancer = new LoadBalancerTO(rule.getUuid(), srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies());
if (rule.isAutoScaleConfig()) {
loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
}
loadBalancersToApply.add(loadBalancer);

View File

@ -133,7 +133,7 @@ import com.cloud.vm.dao.NicDao;
@Local(value = { ElasticLoadBalancerManager.class })
public class ElasticLoadBalancerManagerImpl implements
ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
private static final Logger s_logger = Logger
.getLogger(ElasticLoadBalancerManagerImpl.class);
@ -177,9 +177,9 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
PodVlanMapDao _podVlanMapDao;
@Inject
ElasticLbVmMapDao _elbVmMapDao;
@Inject
@Inject
NetworkDao _networksDao;
@Inject
@Inject
AccountDao _accountDao;
@Inject
PhysicalNetworkServiceProviderDao _physicalProviderDao;
@ -188,7 +188,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
@Inject
NicDao _nicDao;
String _name;
String _instance;
static final private String _elbVmNamePrefix = "l";
@ -203,7 +202,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
String _mgmtCidr;
String _mgmtHost;
Set<Long> _gcCandidateElbVmIds = Collections.newSetFromMap(new ConcurrentHashMap<Long,Boolean>());
Set<Long> _gcCandidateElbVmIds = Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>());
int _elasticLbVmRamSize;
int _elasticLbvmCpuMHz;
@ -218,12 +217,11 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
}
}
public DomainRouterVO deployLoadBalancerVM(Long networkId, IPAddressVO ipAddr, Long accountId) {
public DomainRouterVO deployLoadBalancerVM(Long networkId, IPAddressVO ipAddr, Long accountId) {
NetworkVO network = _networkDao.findById(networkId);
DataCenter dc = _dcDao.findById(network.getDataCenterId());
Long podId = getPodIdForDirectIp(ipAddr);
Pod pod = podId == null?null:_podDao.findById(podId);
Pod pod = podId == null ? null : _podDao.findById(podId);
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(
1);
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
@ -278,7 +276,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
private void createApplyLoadBalancingRulesCommands(
List<LoadBalancingRule> rules, DomainRouterVO elbVm, Commands cmds, long guestNetworkId) {
LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
int i = 0;
for (LoadBalancingRule rule : rules) {
@ -290,19 +287,20 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
String elbIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress()
.addr();
int srcPort = rule.getSourcePortStart();
String uuid = rule.getUuid();
List<LbDestination> destinations = rule.getDestinations();
LoadBalancerTO lb = new LoadBalancerTO(rule.getId(), elbIp, srcPort, protocol, algorithm, revoked, false, destinations);
lbs[i++] = lb;
LoadBalancerTO lb = new LoadBalancerTO(uuid, elbIp, srcPort, protocol, algorithm, revoked, false, destinations);
lbs[i++] = lb;
}
LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs,elbVm.getPublicIpAddress(),
_nicDao.getIpAddress(guestNetworkId, elbVm.getId()),elbVm.getPrivateIpAddress(), null, null);
LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs, elbVm.getPublicIpAddress(),
_nicDao.getIpAddress(guestNetworkId, elbVm.getId()), elbVm.getPrivateIpAddress(), null, null);
cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP,
elbVm.getPrivateIpAddress());
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME,
elbVm.getInstanceName());
//FIXME: why are we setting attributes directly? Ick!! There should be accessors and
//the constructor should set defaults.
// FIXME: why are we setting attributes directly? Ick!! There should be accessors and
// the constructor should set defaults.
cmd.lbStatsVisibility = _configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key());
cmd.lbStatsUri = _configDao.getValue(Config.NetworkLBHaproxyStatsUri.key());
cmd.lbStatsAuth = _configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key());
@ -320,7 +318,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
return sendCommandsToRouter(elbVm, cmds);
}
protected DomainRouterVO findElbVmForLb(FirewallRule lb) {//TODO: use a table to lookup
protected DomainRouterVO findElbVmForLb(FirewallRule lb) {// TODO: use a table to lookup
ElasticLbVmMapVO map = _elbVmMapDao.findOneByIp(lb.getSourceIpAddressId());
if (map == null) {
return null;
@ -332,7 +330,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
@Override
public boolean applyLoadBalancerRules(Network network,
List<? extends FirewallRule> rules)
throws ResourceUnavailableException {
throws ResourceUnavailableException {
if (rules == null || rules.isEmpty()) {
return true;
}
@ -351,7 +349,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
}
if (elbVm.getState() == State.Running) {
//resend all rules for the public ip
// resend all rules for the public ip
List<LoadBalancerVO> lbs = _lbDao.listByIpAddress(rules.get(0).getSourceIpAddressId());
List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
for (LoadBalancerVO lb : lbs) {
@ -359,7 +357,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
LoadBalancingRule loadBalancing = new LoadBalancingRule(
lb, dstList, policyList);
lbRules.add(loadBalancing);
lbRules.add(loadBalancing);
}
return applyLBRules(elbVm, lbRules, network.getId());
} else if (elbVm.getState() == State.Stopped
@ -395,36 +393,33 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
_elasticLbVmRamSize = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmMemory.key()), DEFAULT_ELB_VM_RAMSIZE);
_elasticLbvmCpuMHz = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmCpuMhz.key()), DEFAULT_ELB_VM_CPU_MHZ);
_elasticLbvmNumCpu = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmNumVcpu.key()), 1);
_elasticLbVmOffering = new ServiceOfferingVO("System Offering For Elastic LB VM", _elasticLbvmNumCpu,
_elasticLbVmRamSize, _elasticLbvmCpuMHz, 0, 0, true, null, useLocalStorage,
_elasticLbVmOffering = new ServiceOfferingVO("System Offering For Elastic LB VM", _elasticLbvmNumCpu,
_elasticLbVmRamSize, _elasticLbvmCpuMHz, 0, 0, true, null, useLocalStorage,
true, null, true, VirtualMachine.Type.ElasticLoadBalancerVm, true);
_elasticLbVmOffering.setUniqueName(ServiceOffering.elbVmDefaultOffUniqueName);
_elasticLbVmOffering = _serviceOfferingDao.persistSystemServiceOffering(_elasticLbVmOffering);
String enabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
_enabled = (enabled == null) ? false: Boolean.parseBoolean(enabled);
_enabled = (enabled == null) ? false : Boolean.parseBoolean(enabled);
s_logger.info("Elastic Load balancer enabled: " + _enabled);
if (_enabled) {
String traffType = _configDao.getValue(Config.ElasticLoadBalancerNetwork.key());
if ("guest".equalsIgnoreCase(traffType)) {
_frontendTrafficType = TrafficType.Guest;
} else if ("public".equalsIgnoreCase(traffType)){
} else if ("public".equalsIgnoreCase(traffType)) {
_frontendTrafficType = TrafficType.Public;
} else
throw new ConfigurationException("ELB: Traffic type for front end of load balancer has to be guest or public; found : " + traffType);
s_logger.info("ELB: Elastic Load Balancer: will balance on " + traffType );
int gcIntervalMinutes = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmGcInterval.key()), 5);
if (gcIntervalMinutes < 5)
s_logger.info("ELB: Elastic Load Balancer: will balance on " + traffType);
int gcIntervalMinutes = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmGcInterval.key()), 5);
if (gcIntervalMinutes < 5)
gcIntervalMinutes = 5;
s_logger.info("ELB: Elastic Load Balancer: scheduling GC to run every " + gcIntervalMinutes + " minutes" );
s_logger.info("ELB: Elastic Load Balancer: scheduling GC to run every " + gcIntervalMinutes + " minutes");
_gcThreadPool = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ELBVM-GC"));
_gcThreadPool.scheduleAtFixedRate(new CleanupThread(), gcIntervalMinutes, gcIntervalMinutes, TimeUnit.MINUTES);
_itMgr.registerGuru(VirtualMachine.Type.ElasticLoadBalancerVm, this);
}
return true;
}
@ -447,17 +442,17 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
List<DomainRouterVO> unusedElbVms = _elbVmMapDao.listUnusedElbVms();
if (unusedElbVms.size() > 0) {
List<DomainRouterVO> candidateVms = new ArrayList<DomainRouterVO>();
for (DomainRouterVO candidateVm: unusedElbVms) {
for (DomainRouterVO candidateVm : unusedElbVms) {
if (candidateVm.getPodIdToDeployIn() == getPodIdForDirectIp(ipAddr))
candidateVms.add(candidateVm);
}
return candidateVms.size()==0?null:candidateVms.get(new Random().nextInt(candidateVms.size()));
return candidateVms.size() == 0 ? null : candidateVms.get(new Random().nextInt(candidateVms.size()));
}
return null;
}
public DomainRouterVO deployELBVm(Network guestNetwork, DeployDestination dest, Account owner, Map<Param, Object> params) throws
ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
long dcId = dest.getDataCenter().getId();
// lock guest network
@ -477,10 +472,9 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Starting a ELB vm for network configurations: " + guestNetwork + " in " + dest);
}
assert guestNetwork.getState() == Network.State.Implemented
|| guestNetwork.getState() == Network.State.Setup
|| guestNetwork.getState() == Network.State.Implementing
: "Network is not yet fully implemented: "+ guestNetwork;
assert guestNetwork.getState() == Network.State.Implemented
|| guestNetwork.getState() == Network.State.Setup
|| guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork;
DataCenterDeployment plan = null;
DomainRouterVO elbVm = null;
@ -503,7 +497,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
networks.add(new Pair<NetworkVO, NicProfile>(controlConfig, null));
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, guestNic));
VMTemplateVO template = _templateDao.findSystemVMTemplate(dcId);
String typeString = "ElasticLoadBalancerVm";
@ -517,13 +510,13 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId());
}
elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(),
elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(),
VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(),
template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN,
_elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm, null);
elbVm.setRole(Role.LB);
elbVm = _itMgr.allocate(elbVm, template, _elasticLbVmOffering, networks, plan, null, owner);
//TODO: create usage stats
// TODO: create usage stats
}
State state = elbVm.getState();
@ -531,7 +524,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
elbVm = this.start(elbVm, _accountService.getSystemUser(), _accountService.getSystemAccount(), params);
}
return elbVm;
} finally {
_networkDao.releaseFromLockTable(guestNetworkId);
@ -539,7 +531,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
}
private DomainRouterVO start(DomainRouterVO elbVm, User user, Account caller, Map<Param, Object> params) throws StorageUnavailableException, InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException {
ConcurrentOperationException, ResourceUnavailableException {
s_logger.debug("Starting ELB VM " + elbVm);
if (_itMgr.start(elbVm, params, user, caller) != null) {
return _routerDao.findById(elbVm.getId());
@ -548,11 +540,10 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
}
}
private DomainRouterVO stop(DomainRouterVO elbVm, boolean forced, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException {
s_logger.debug("Stopping ELB vm " + elbVm);
try {
if (_itMgr.advanceStop( elbVm, forced, user, caller)) {
if (_itMgr.advanceStop(elbVm, forced, user, caller)) {
return _routerDao.findById(elbVm.getId());
} else {
return null;
@ -564,7 +555,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
protected List<LoadBalancerVO> findExistingLoadBalancers(String lbName, Long ipId, Long accountId, Long domainId, Integer publicPort) {
SearchBuilder<LoadBalancerVO> sb = _lbDao.createSearchBuilder();
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
sb.and("publicPort", sb.entity().getSourcePortStart(), SearchCriteria.Op.EQ);
if (ipId != null) {
@ -581,16 +572,16 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
sc.setParameters("accountId", accountId);
if (ipId != null) {
sc.setParameters("sourceIpAddress", ipId);
}
}
if (domainId != null) {
sc.setParameters("domainId",domainId);
sc.setParameters("domainId", domainId);
}
if (publicPort != null) {
sc.setParameters("publicPort", publicPort);
}
List<LoadBalancerVO> lbs = _lbDao.search(sc, null);
return lbs == null || lbs.size()==0 ? null: lbs;
return lbs == null || lbs.size() == 0 ? null : lbs;
}
@DB
@ -601,7 +592,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
PublicIp ip = _networkMgr.assignPublicIpAddress(frontEndNetwork.getDataCenterId(), null, account, VlanType.DirectAttached, frontEndNetwork.getId(), null, true);
IPAddressVO ipvo = _ipAddressDao.findById(ip.getId());
ipvo.setAssociatedWithNetworkId(frontEndNetwork.getId());
ipvo.setAssociatedWithNetworkId(frontEndNetwork.getId());
_ipAddressDao.update(ipvo.getId(), ipvo);
txn.commit();
s_logger.info("Acquired frontend IP for ELB " + ip);
@ -612,7 +603,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
public void releaseIp(long ipId, long userId, Account caller) {
s_logger.info("ELB: Release public IP for loadbalancing " + ipId);
IPAddressVO ipvo = _ipAddressDao.findById(ipId);
ipvo.setAssociatedWithNetworkId(null);
ipvo.setAssociatedWithNetworkId(null);
_ipAddressDao.update(ipvo.getId(), ipvo);
_networkMgr.disassociatePublicIpAddress(ipId, userId, caller);
_ipAddressDao.unassignIpAddress(ipId);
@ -620,8 +611,8 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
@Override
@DB
public LoadBalancer handleCreateLoadBalancerRule(CreateLoadBalancerRuleCmd lb, Account account, long networkId) throws InsufficientAddressCapacityException, NetworkRuleConflictException {
//this part of code is executed when the LB provider is Elastic Load Balancer vm
public LoadBalancer handleCreateLoadBalancerRule(CreateLoadBalancerRuleCmd lb, Account account, long networkId) throws InsufficientAddressCapacityException, NetworkRuleConflictException {
// this part of code is executed when the LB provider is Elastic Load Balancer vm
if (!_networkMgr.isProviderSupportServiceInNetwork(lb.getNetworkId(), Service.Lb, Provider.ElasticLoadBalancerVm)) {
return null;
}
@ -638,14 +629,14 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
}
try {
List<LoadBalancerVO> existingLbs = findExistingLoadBalancers(lb.getName(), lb.getSourceIpAddressId(), lb.getAccountId(), lb.getDomainId(), lb.getSourcePortStart());
if (existingLbs == null ){
if (existingLbs == null) {
existingLbs = findExistingLoadBalancers(lb.getName(), lb.getSourceIpAddressId(), lb.getAccountId(), lb.getDomainId(), null);
if (existingLbs == null) {
if (lb.getSourceIpAddressId() != null) {
existingLbs = findExistingLoadBalancers(lb.getName(), null, lb.getAccountId(), lb.getDomainId(), null);
if (existingLbs != null) {
throw new InvalidParameterValueException("Supplied LB name " + lb.getName() + " is not associated with IP " + lb.getSourceIpAddressId(), null);
}
}
} else {
s_logger.debug("Could not find any existing frontend ips for this account for this LB rule, acquiring a new frontent IP for ELB");
PublicIp ip = allocDirectIp(account, networkId);
@ -678,7 +669,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
DomainRouterVO elbVm = null;
if (existingLbs == null) {
elbVm = findELBVmWithCapacity(network, ipAddr);
if (elbVm == null) {
@ -721,7 +711,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
if (unusedElbVms != null && unusedElbVms.size() > 0)
s_logger.info("Found " + unusedElbVms.size() + " unused ELB vms");
Set<Long> currentGcCandidates = new HashSet<Long>();
for (DomainRouterVO elbVm: unusedElbVms) {
for (DomainRouterVO elbVm : unusedElbVms) {
currentGcCandidates.add(elbVm.getId());
}
_gcCandidateElbVmIds.retainAll(currentGcCandidates);
@ -782,7 +772,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
}
}
@Override
public DomainRouterVO findByName(String name) {
if (!VirtualMachineName.isValidSystemVmName(name, _instance, _elbVmNamePrefix)) {
@ -792,19 +781,16 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
return _routerDao.findById(VirtualMachineName.getSystemVmId(name));
}
@Override
public DomainRouterVO findById(long id) {
return _routerDao.findById(id);
}
@Override
public DomainRouterVO persist(DomainRouterVO elbVm) {
return _routerDao.persist(elbVm);
}
@Override
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest, ReservationContext context) {
DomainRouterVO elbVm = profile.getVirtualMachine();
@ -841,7 +827,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
if (nic.getTrafficType() == TrafficType.Management) {
buf.append(" localgw=").append(dest.getPod().getGateway());
} else if (nic.getTrafficType() == TrafficType.Control) {
// control command is sent over management network in VMware
// control command is sent over management network in VMware
if (dest.getHost().getHypervisorType() == HypervisorType.VMware) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Check if we need to add management server explicit route to ELB vm. pod cidr: " + dest.getPod().getCidrAddress() + "/" + dest.getPod().getCidrSize()
@ -868,7 +854,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
String domain = guestNetwork.getNetworkDomain();
if (domain != null) {
buf.append(" domain=" + domain);
}
}
buf.append(" dns1=").append(defaultDns1);
if (defaultDns2 != null) {
@ -886,7 +872,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
return true;
}
@Override
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
DomainRouterVO elbVm = profile.getVirtualMachine();
@ -908,7 +893,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
return true;
}
@Override
public boolean finalizeStart(VirtualMachineProfile<DomainRouterVO> profile, long hostId, Commands cmds, ReservationContext context) {
CheckSshAnswer answer = (CheckSshAnswer) cmds.getAnswer("checkSsh");
@ -920,7 +904,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
return true;
}
@Override
public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile) {
DomainRouterVO elbVm = profile.getVirtualMachine();
@ -929,7 +912,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
NicProfile controlNic = null;
Long guestNetworkId = null;
if(profile.getHypervisorType() == HypervisorType.VMware && dcVo.getNetworkType() == NetworkType.Basic) {
if (profile.getHypervisorType() == HypervisorType.VMware && dcVo.getNetworkType() == NetworkType.Basic) {
// TODO this is a ugly to test hypervisor type here
// for basic network mode, we will use the guest NIC for control NIC
for (NicProfile nic : profile.getNics()) {
@ -973,7 +956,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
return true;
}
@Override
public void finalizeStop(VirtualMachineProfile<DomainRouterVO> profile, StopAnswer answer) {
if (answer != null) {
@ -984,10 +966,9 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
}
public void processStopOrRebootAnswer(final DomainRouterVO elbVm, Answer answer) {
//TODO: process network usage stats
// TODO: process network usage stats
}
@Override
public void finalizeExpunge(DomainRouterVO vm) {
// no-op
@ -1007,25 +988,22 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru<DomainRouterVO> {
public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
//not supported
// not supported
throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType());
}
@Override
public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
//not supported
// not supported
throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType());
}
@Override
public void prepareStop(VirtualMachineProfile<DomainRouterVO> profile) {
}
@Override
public boolean recreateNeeded(
VirtualMachineProfile<DomainRouterVO> profile, long hostId,

View File

@ -106,6 +106,8 @@ import com.cloud.network.vpc.VpcManager;
import com.cloud.offering.NetworkOffering;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.tags.ResourceTagVO;
import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.template.TemplateManager;
@ -194,6 +196,10 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
@Inject
ResourceTagDao _resourceTagDao;
@Inject
VMTemplateDao _templateDao;
@Inject
ServiceOfferingDao _offeringsDao;
@Inject
CounterDao _counterDao;
@Inject
ConditionDao _conditionDao;
@ -262,20 +268,24 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
String apiKey = user.getApiKey();
String secretKey = user.getSecretKey();
String csUrl = _configDao.getValue(Config.EndpointeUrl.key());
String zoneId = _dcDao.findById(autoScaleVmProfile.getZoneId()).getUuid();
String domainId = _domainDao.findById(autoScaleVmProfile.getDomainId()).getUuid();
String serviceOfferingId = _offeringsDao.findById(autoScaleVmProfile.getServiceOfferingId()).getUuid();
String templateId = _templateDao.findById(autoScaleVmProfile.getTemplateId()).getUuid();
if(apiKey == null) {
if (apiKey == null) {
throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it", null);
}
if(secretKey == null) {
if (secretKey == null) {
throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it", null);
}
if(csUrl == null || csUrl.contains("localhost")) {
if (csUrl == null || csUrl.contains("localhost")) {
throw new InvalidParameterValueException("Global setting endpointe.url has to be set to the Management Server's API end point", null);
}
LbAutoScaleVmProfile lbAutoScaleVmProfile = new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl);
LbAutoScaleVmProfile lbAutoScaleVmProfile = new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl, zoneId, domainId, serviceOfferingId, templateId);
return new LbAutoScaleVmGroup(vmGroup, autoScalePolicies, lbAutoScaleVmProfile);
}
@ -1547,7 +1557,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
protected void removeLBRule(LoadBalancerVO rule) {
//remove the rule
// remove the rule
_lbDao.remove(rule.getId());
// if the rule is the last one for the ip address assigned to VPC, unassign it from the network