From bf1e6ed9915569e4422a45c0b169322bebfb09b3 Mon Sep 17 00:00:00 2001 From: Deepak Garg Date: Wed, 26 Sep 2012 21:25:08 +0530 Subject: [PATCH] CS-15644-Autoscale: Implemented UUIDs for templateId-serviceOff Reviewed-By:Vijay --- .../cloud/agent/api/to/LoadBalancerTO.java | 55 +++--- .../cloud/network/as/AutoScaleVmGroup.java | 30 +-- .../cloud/network/lb/LoadBalancingRule.java | 33 +++- .../com/cloud/network/rules/LoadBalancer.java | 7 +- .../lb/ElasticLoadBalancerManagerImpl.java | 65 +++---- .../network/element/NetscalerElement.java | 67 +++---- .../network/resource/NetscalerResource.java | 183 ++++++++++-------- ...ExternalLoadBalancerDeviceManagerImpl.java | 41 ++-- .../cloud/network/as/AutoScaleVmGroupVO.java | 5 + .../lb/LoadBalancingRulesManagerImpl.java | 36 ++-- .../VirtualNetworkApplianceManagerImpl.java | 3 +- 11 files changed, 292 insertions(+), 233 deletions(-) diff --git a/api/src/com/cloud/agent/api/to/LoadBalancerTO.java b/api/src/com/cloud/agent/api/to/LoadBalancerTO.java index 04f718ecb2b..9a58d9a46b3 100644 --- a/api/src/com/cloud/agent/api/to/LoadBalancerTO.java +++ b/api/src/com/cloud/agent/api/to/LoadBalancerTO.java @@ -36,7 +36,7 @@ import com.cloud.utils.Pair; public class LoadBalancerTO { - Long id; + String uuid; String srcIp; int srcPort; String protocol; @@ -48,11 +48,11 @@ public class LoadBalancerTO { 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 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 destinations) { + if(destinations == null) { // for autoscaleconfig destinations will be null; destinations = new ArrayList(); } - this.id = id; + this.uuid = uuid; this.srcIp = srcIp; this.srcPort = srcPort; this.protocol = protocol; @@ -67,7 +67,7 @@ public class LoadBalancerTO { } } - public LoadBalancerTO (Long id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List arg_destinations, List stickinessPolicies) { + public LoadBalancerTO(String id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List arg_destinations, List stickinessPolicies) { this(id, srcIp, srcPort, protocol, algorithm, revoked, alreadyAdded, arg_destinations); this.stickinessPolicies = null; if (stickinessPolicies != null && stickinessPolicies.size() > 0) { @@ -78,19 +78,18 @@ public class LoadBalancerTO { this.stickinessPolicies[index] = new StickinessPolicyTO(stickinesspolicy.getMethodName(), stickinesspolicy.getParams()); index++; if (index == MAX_STICKINESS_POLICIES) break; + } } - } if (index == 0) this.stickinessPolicies = null; - } - } + } + } protected LoadBalancerTO() { } - - public Long getId() { - return id; + public String getUuid() { + return uuid; } public String getSrcIp() { @@ -186,7 +185,7 @@ public class LoadBalancerTO { return alreadyAdded; } } - public static class CounterTO implements Serializable { + public static class CounterTO implements Serializable{ private final String name; private final String source; private final String value; @@ -210,7 +209,7 @@ public class LoadBalancerTO { } } - public static class ConditionTO implements Serializable { + public static class ConditionTO implements Serializable{ private final long threshold; private final String relationalOperator; private final CounterTO counter; @@ -235,7 +234,7 @@ public class LoadBalancerTO { } } - public static class AutoScalePolicyTO implements Serializable { + public static class AutoScalePolicyTO implements Serializable{ private final long id; private final int duration; private final int quietTime; @@ -277,11 +276,11 @@ public class LoadBalancerTO { } } - 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; @@ -290,7 +289,7 @@ public class LoadBalancerTO { 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; @@ -305,19 +304,19 @@ public class LoadBalancerTO { 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; } @@ -350,7 +349,7 @@ public class LoadBalancerTO { } } - public static class AutoScaleVmGroupTO implements Serializable { + public static class AutoScaleVmGroupTO implements Serializable{ private final int minMembers; private final int maxMembers; private final int memberPort; @@ -402,7 +401,7 @@ public class LoadBalancerTO { public String getCurrentState() { return currentState; - } + } } public void setAutoScaleVmGroup(LbAutoScaleVmGroup lbAutoScaleVmGroup) @@ -427,9 +426,9 @@ public class LoadBalancerTO { 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(); diff --git a/api/src/com/cloud/network/as/AutoScaleVmGroup.java b/api/src/com/cloud/network/as/AutoScaleVmGroup.java index 7b882fc30f7..6d41ae3a7e0 100644 --- a/api/src/com/cloud/network/as/AutoScaleVmGroup.java +++ b/api/src/com/cloud/network/as/AutoScaleVmGroup.java @@ -1,19 +1,19 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. package com.cloud.network.as; @@ -46,4 +46,6 @@ public interface AutoScaleVmGroup extends ControlledEntity { String getState(); + String getUuid(); + } diff --git a/api/src/com/cloud/network/lb/LoadBalancingRule.java b/api/src/com/cloud/network/lb/LoadBalancingRule.java index ffa6cbc65d3..33d592672b1 100644 --- a/api/src/com/cloud/network/lb/LoadBalancingRule.java +++ b/api/src/com/cloud/network/lb/LoadBalancingRule.java @@ -79,6 +79,11 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer { return lb.getAlgorithm(); } + @Override + public String getUuid() { + return lb.getUuid(); + } + @Override public String getXid() { return lb.getXid(); @@ -297,12 +302,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() { @@ -316,11 +329,28 @@ 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 { AutoScaleVmGroup vmGroup; private final List policies; @@ -350,4 +380,5 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer { return currentState; } } + } diff --git a/api/src/com/cloud/network/rules/LoadBalancer.java b/api/src/com/cloud/network/rules/LoadBalancer.java index 9c67f29cc6b..9734e7e3cb6 100644 --- a/api/src/com/cloud/network/rules/LoadBalancer.java +++ b/api/src/com/cloud/network/rules/LoadBalancer.java @@ -17,7 +17,7 @@ package com.cloud.network.rules; /** - * Definition for a LoadBalancer + * Definition for a LoadBalancer */ public interface LoadBalancer extends FirewallRule { @@ -26,9 +26,10 @@ public interface LoadBalancer extends FirewallRule { String getDescription(); int getDefaultPortStart(); - + int getDefaultPortEnd(); String getAlgorithm(); - + + String getUuid(); } diff --git a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index 141e3ba013e..366070af21f 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -140,7 +140,7 @@ import com.cloud.vm.dao.NicDao; public class ElasticLoadBalancerManagerImpl implements ElasticLoadBalancerManager, Manager, VirtualMachineGuru { private static final Logger s_logger = Logger - .getLogger(ElasticLoadBalancerManagerImpl.class); + .getLogger(ElasticLoadBalancerManagerImpl.class); @Inject IPAddressDao _ipAddressDao; @@ -184,9 +184,9 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { PodVlanMapDao _podVlanMapDao; @Inject ElasticLbVmMapDao _elbVmMapDao; - @Inject + @Inject NetworkDao _networksDao; - @Inject + @Inject AccountDao _accountDao; @Inject PhysicalNetworkServiceProviderDao _physicalProviderDao; @@ -195,7 +195,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { @Inject NicDao _nicDao; - String _name; String _instance; static final private String _elbVmNamePrefix = "l"; @@ -225,8 +224,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { } } - - 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); @@ -285,7 +283,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { private void createApplyLoadBalancingRulesCommands( List rules, DomainRouterVO elbVm, Commands cmds, long guestNetworkId) { - LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()]; int i = 0; for (LoadBalancingRule rule : rules) { @@ -295,11 +292,12 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { String algorithm = rule.getAlgorithm(); String elbIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress() - .addr(); + .addr(); int srcPort = rule.getSourcePortStart(); + String uuid = rule.getUuid(); List 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(), @@ -339,7 +337,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { @Override public boolean applyLoadBalancerRules(Network network, List rules) - throws ResourceUnavailableException { + throws ResourceUnavailableException { if (rules == null || rules.isEmpty()) { return true; } @@ -366,7 +364,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { List 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 @@ -386,7 +384,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { @Override public boolean configure(String name, Map params) - throws ConfigurationException { + throws ConfigurationException { _name = name; final Map configs = _configDao.getConfiguration("AgentManager", params); _systemAcct = _accountService.getSystemAccount(); @@ -402,14 +400,12 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { _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); s_logger.info("Elastic Load balancer enabled: " + _enabled); @@ -423,7 +419,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { 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) + if (gcIntervalMinutes < 5) gcIntervalMinutes = 5; s_logger.info("ELB: Elastic Load Balancer: scheduling GC to run every " + gcIntervalMinutes + " minutes" ); _gcThreadPool = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ELBVM-GC")); @@ -431,7 +427,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { _itMgr.registerGuru(VirtualMachine.Type.ElasticLoadBalancerVm, this); } - return true; } @@ -484,10 +479,9 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { 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; @@ -537,7 +531,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { elbVm = this.start(elbVm, _accountService.getSystemUser(), _accountService.getSystemAccount(), params); } - return elbVm; } finally { _networkDao.releaseFromLockTable(guestNetworkId); @@ -554,7 +547,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { } } - private DomainRouterVO stop(DomainRouterVO elbVm, boolean forced, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Stopping ELB vm " + elbVm); try { @@ -570,7 +562,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { protected List findExistingLoadBalancers(String lbName, Long ipId, Long accountId, Long domainId, Integer publicPort) { SearchBuilder 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) { @@ -587,7 +579,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { sc.setParameters("accountId", accountId); if (ipId != null) { sc.setParameters("sourceIpAddress", ipId); - } + } if (domainId != null) { sc.setParameters("domainId",domainId); } @@ -607,7 +599,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { 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); @@ -618,7 +610,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { 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); @@ -651,7 +643,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { 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() ); - } + } } 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); @@ -684,7 +676,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { DomainRouterVO elbVm = null; - if (existingLbs == null) { elbVm = findELBVmWithCapacity(network, ipAddr); if (elbVm == null) { @@ -788,7 +779,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { } } - @Override public DomainRouterVO findByName(String name) { if (!VirtualMachineName.isValidSystemVmName(name, _instance, _elbVmNamePrefix)) { @@ -798,19 +788,16 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { 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 profile, DeployDestination dest, ReservationContext context) { DomainRouterVO elbVm = profile.getVirtualMachine(); @@ -874,7 +861,7 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { String domain = guestNetwork.getNetworkDomain(); if (domain != null) { buf.append(" domain=" + domain); - } + } buf.append(" dns1=").append(defaultDns1); if (defaultDns2 != null) { @@ -892,7 +879,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { return true; } - @Override public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { DomainRouterVO elbVm = profile.getVirtualMachine(); @@ -914,7 +900,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { return true; } - @Override public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { CheckSshAnswer answer = (CheckSshAnswer) cmds.getAnswer("checkSsh"); @@ -926,7 +911,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { return true; } - @Override public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { DomainRouterVO elbVm = profile.getVirtualMachine(); @@ -979,7 +963,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { return true; } - @Override public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { if (answer != null) { @@ -993,7 +976,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { //TODO: process network usage stats } - @Override public void finalizeExpunge(DomainRouterVO vm) { // no-op @@ -1017,7 +999,6 @@ ElasticLoadBalancerManager, Manager, VirtualMachineGuru { 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 { diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java index 6aa7cf4e6e8..4ac0d806021 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java +++ b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java @@ -371,7 +371,7 @@ StaticNatServiceProvider { HostPodVO pod = _podDao.findById(podId); if (pod == null) { throw new InvalidParameterValueException("Can't find pod by id " + podId); - } + } } for (Long podId: newPodsConfig) { @@ -669,12 +669,13 @@ StaticNatServiceProvider { boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke)); String protocol = rule.getProtocol(); String algorithm = rule.getAlgorithm(); + String lbUuid = rule.getUuid(); String srcIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress().addr(); int srcPort = rule.getSourcePortStart(); List 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()); + LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies()); if(rule.isAutoScaleConfig()) { loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup()); } @@ -711,41 +712,41 @@ StaticNatServiceProvider { try { if (!multiNetScalerDeployment) { - String errMsg; - ExternalLoadBalancerDeviceVO lbDevice = getExternalLoadBalancerForNetwork(config); - if (lbDevice == null) { - try { - lbDevice = allocateLoadBalancerForNetwork(config); - } catch (Exception e) { - errMsg = "Could not allocate a NetSclaer load balancer for configuring static NAT rules due to" + e.getMessage(); - s_logger.error(errMsg); - throw new ResourceUnavailableException(errMsg, this.getClass(), 0); - } - } + String errMsg; + ExternalLoadBalancerDeviceVO lbDevice = getExternalLoadBalancerForNetwork(config); + if (lbDevice == null) { + try { + lbDevice = allocateLoadBalancerForNetwork(config); + } catch (Exception e) { + errMsg = "Could not allocate a NetSclaer load balancer for configuring static NAT rules due to" + e.getMessage(); + s_logger.error(errMsg); + throw new ResourceUnavailableException(errMsg, this.getClass(), 0); + } + } - if (!isNetscalerDevice(lbDevice.getDeviceName())) { - errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element will not be handling the static nat rules."; - s_logger.error(errMsg); - throw new ResourceUnavailableException(errMsg, this.getClass(), 0); - } - SetStaticNatRulesAnswer answer = null; - List rulesTO = null; - if (rules != null) { - rulesTO = new ArrayList(); - for (StaticNat rule : rules) { - IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId()); - StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false); - rulesTO.add(ruleTO); - } + if (!isNetscalerDevice(lbDevice.getDeviceName())) { + errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element will not be handling the static nat rules."; + s_logger.error(errMsg); + throw new ResourceUnavailableException(errMsg, this.getClass(), 0); + } + SetStaticNatRulesAnswer answer = null; + List rulesTO = null; + if (rules != null) { + rulesTO = new ArrayList(); + for (StaticNat rule : rules) { + IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId()); + StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false); + rulesTO.add(ruleTO); } + } SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, null); - answer = (SetStaticNatRulesAnswer) _agentMgr.send(lbDevice.getHostId(), cmd); - if (answer == null) { - return false; - } else { - return answer.getResult(); - } + answer = (SetStaticNatRulesAnswer) _agentMgr.send(lbDevice.getHostId(), cmd); + if (answer == null) { + return false; + } else { + return answer.getResult(); + } } else { if (rules != null) { for (StaticNat rule : rules) { diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java index 21486e62d97..9bcace3270a 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java +++ b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java @@ -28,6 +28,7 @@ import org.apache.log4j.Logger; import com.citrix.netscaler.nitro.exception.nitro_exception; import com.citrix.netscaler.nitro.resource.base.base_response; +import com.citrix.netscaler.nitro.resource.config.autoscale.autoscalepolicy; import com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleprofile; import com.citrix.netscaler.nitro.resource.config.basic.server_service_binding; import com.citrix.netscaler.nitro.resource.config.basic.servicegroup; @@ -49,7 +50,6 @@ import com.citrix.netscaler.nitro.resource.config.ns.nshardware; import com.citrix.netscaler.nitro.resource.config.ns.nsip; import com.citrix.netscaler.nitro.resource.config.ns.nstimer; import com.citrix.netscaler.nitro.resource.config.ns.nstimer_autoscalepolicy_binding; -import com.citrix.netscaler.nitro.resource.config.autoscale.*; import com.citrix.netscaler.nitro.resource.stat.lb.lbvserver_stats; import com.citrix.netscaler.nitro.service.nitro_service; import com.citrix.netscaler.nitro.util.filtervalue; @@ -619,14 +619,14 @@ public class NetscalerResource implements ServerResource { saveConfiguration(); return new Answer(cmd); } catch (ExecutionException e) { - s_logger.error("Failed to execute LoadBalancerConfigCommand due to " + e.getMessage()); + s_logger.error("Failed to execute LoadBalancerConfigCommand due to ", e); if (shouldRetry(numRetries)) { return retry(cmd, numRetries); } else { return new Answer(cmd, e); } } catch (Exception e) { - s_logger.error("Failed to execute LoadBalancerConfigCommand due to " + e.getMessage()); + s_logger.error("Failed to execute LoadBalancerConfigCommand due to ", e); if (shouldRetry(numRetries)) { return retry(cmd, numRetries); } else { @@ -1367,7 +1367,8 @@ public class NetscalerResource implements ServerResource { return nsProtocol; } - private void addLBVirtualServer(String virtualServerName, String publicIp, int publicPort, String lbAlgorithm, String protocol, StickinessPolicyTO[] stickyPolicies, AutoScaleVmGroupTO vmGroupTO) throws ExecutionException { + private void addLBVirtualServer(String virtualServerName, String publicIp, int publicPort, String lbAlgorithm, String protocol, StickinessPolicyTO[] stickyPolicies, AutoScaleVmGroupTO vmGroupTO) + throws ExecutionException { try { String lbMethod; if ("roundrobin".equalsIgnoreCase(lbAlgorithm)) { @@ -1516,6 +1517,7 @@ public class NetscalerResource implements ServerResource { int srcPort = loadBalancerTO.getSrcPort(); String lbProtocol = getNetScalerProtocol(loadBalancerTO); String lbAlgorithm = loadBalancerTO.getAlgorithm(); + String vmGroupIdentifier = generateAutoScaleVmGroupIdentifier(loadBalancerTO); String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort); AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO(); if (s_logger.isDebugEnabled()) { @@ -1523,7 +1525,7 @@ public class NetscalerResource implements ServerResource { } addLBVirtualServer(nsVirtualServerName, srcIp, srcPort, lbAlgorithm, lbProtocol, loadBalancerTO.getStickinessPolicies(), vmGroupTO); - String serviceGroupName = generateAutoScaleServiceGroupName(srcIp, srcPort); + String serviceGroupName = generateAutoScaleServiceGroupName(vmGroupIdentifier); if(!nsServiceGroupExists(serviceGroupName)) { // add servicegroup lb_autoscaleGroup -autoscale POLICY -memberPort 80 int memberPort = vmGroupTO.getMemberPort(); @@ -1562,15 +1564,16 @@ public class NetscalerResource implements ServerResource { private synchronized boolean removeAutoScaleConfig(LoadBalancerTO loadBalancerTO) throws Exception, ExecutionException { String srcIp = loadBalancerTO.getSrcIp(); int srcPort = loadBalancerTO.getSrcPort(); + String vmGroupIdentifier = generateAutoScaleVmGroupIdentifier(loadBalancerTO); String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort); - String serviceGroupName = generateAutoScaleServiceGroupName(srcIp, srcPort); + String serviceGroupName = generateAutoScaleServiceGroupName(vmGroupIdentifier); if (loadBalancerTO.getAutoScaleVmGroupTO().getCurrentState().equals("enabled")) { disableAutoScaleConfig(loadBalancerTO, false); } - if (isServiceGroupBoundToVirtualServer(nsVirtualServerName, serviceGroupName)) { + if(isServiceGroupBoundToVirtualServer(nsVirtualServerName, serviceGroupName)) { // UnBind autoscale service group // unbind lb vserver lb lb_autoscaleGroup lbvserver_servicegroup_binding vserver_servicegroup_binding = new lbvserver_servicegroup_binding(); @@ -1601,17 +1604,18 @@ public class NetscalerResource implements ServerResource { @SuppressWarnings("static-access") private synchronized boolean enableAutoScaleConfig(LoadBalancerTO loadBalancerTO, boolean isCleanUp) throws Exception { + String vmGroupIdentifier = generateAutoScaleVmGroupIdentifier(loadBalancerTO); String srcIp = loadBalancerTO.getSrcIp(); int srcPort = loadBalancerTO.getSrcPort(); String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort); - String serviceGroupName = generateAutoScaleServiceGroupName(srcIp, srcPort); - String profileName = generateAutoScaleProfileName(srcIp, srcPort); - String timerName = generateAutoScaleTimerName(srcIp, srcPort); - String scaleDownActionName = generateAutoScaleScaleDownActionName(srcIp, srcPort); - String scaleUpActionName = generateAutoScaleScaleUpActionName(srcIp, srcPort); - String mtName = generateSnmpMetricTableName(srcIp, srcPort); - String monitorName = generateSnmpMonitorName(srcIp, srcPort); + String serviceGroupName = generateAutoScaleServiceGroupName(vmGroupIdentifier); + String profileName = generateAutoScaleProfileName(vmGroupIdentifier); + String timerName = generateAutoScaleTimerName(vmGroupIdentifier); + String scaleDownActionName = generateAutoScaleScaleDownActionName(vmGroupIdentifier); + String scaleUpActionName = generateAutoScaleScaleUpActionName(vmGroupIdentifier); + String mtName = generateSnmpMetricTableName(vmGroupIdentifier); + String monitorName = generateSnmpMonitorName(vmGroupIdentifier); AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO(); AutoScaleVmProfileTO profileTO = vmGroupTO.getProfile(); List policies = vmGroupTO.getPolicies(); @@ -1634,7 +1638,8 @@ public class NetscalerResource implements ServerResource { vserver.update(_netscalerService, vserver); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } /* AutoScale Config */ @@ -1655,7 +1660,8 @@ public class NetscalerResource implements ServerResource { autoscaleProfile.add(_netscalerService, autoscaleProfile); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // Add Timer @@ -1666,7 +1672,8 @@ public class NetscalerResource implements ServerResource { timer.add(_netscalerService, timer); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // AutoScale Actions @@ -1707,12 +1714,13 @@ public class NetscalerResource implements ServerResource { ApiConstants.SERVICE_OFFERING_ID + "=" + profileTO.getServiceOfferingId()+ "&" + ApiConstants.TEMPLATE_ID + "=" + profileTO.getTemplateId()+ "&" + ((profileTO.getOtherDeployParams() == null)? "" : (profileTO.getOtherDeployParams() + "&")) + - "lbruleid=" + loadBalancerTO.getId(); + "lbruleid=" + loadBalancerTO.getUuid(); scaleUpAction.set_parameters(scaleUpParameters); scaleUpAction.add(_netscalerService, scaleUpAction); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction scaleDownAction = new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction(); @@ -1725,23 +1733,24 @@ public class NetscalerResource implements ServerResource { scaleDownAction.set_profilename(profileName); scaleDownAction.set_quiettime(scaleDownQuietTime); String scaleDownParameters = "command=destroyVirtualMachine" + "&" + - "lbruleid=" + loadBalancerTO.getId(); + "lbruleid=" + loadBalancerTO.getUuid(); scaleDownAction.set_parameters(scaleDownParameters); scaleDownAction.set_vmdestroygraceperiod(destroyVmGracePeriod); scaleDownAction.add(_netscalerService, scaleDownAction); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } /* Create min member policy */ - String minMemberPolicyName = generateAutoScaleMinPolicyName(srcIp, srcPort); + String minMemberPolicyName = generateAutoScaleMinPolicyName(vmGroupIdentifier); String minMemberPolicyExp = "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.LT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MINAUTOSCALEMEMBERS)"; addAutoScalePolicy(timerName, minMemberPolicyName, cur_prirotiy++, minMemberPolicyExp, scaleUpActionName, interval, interval, isCleanUp); /* Create max member policy */ - String maxMemberPolicyName = generateAutoScaleMaxPolicyName(srcIp, srcPort); + String maxMemberPolicyName = generateAutoScaleMaxPolicyName(vmGroupIdentifier); String maxMemberPolicyExp = "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.GT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MAXAUTOSCALEMEMBERS)"; addAutoScalePolicy(timerName, maxMemberPolicyName, cur_prirotiy++, maxMemberPolicyExp, scaleDownActionName, interval, interval, isCleanUp); @@ -1773,7 +1782,8 @@ public class NetscalerResource implements ServerResource { metricTable.add(_netscalerService, metricTable); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // Create Monitor @@ -1790,7 +1800,8 @@ public class NetscalerResource implements ServerResource { monitor.add(_netscalerService, monitor); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // Bind monitor to servicegroup. @@ -1807,7 +1818,8 @@ public class NetscalerResource implements ServerResource { servicegroup_lbmonitor_binding.add(_netscalerService, servicegroup_monitor_binding); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } } @@ -1828,7 +1840,8 @@ public class NetscalerResource implements ServerResource { metrictable_metric_binding.add(_netscalerService, metrictable_metric_binding); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // bind lb monitor lb_metric_table_mon -metric cpu -metricThreshold 1 @@ -1845,11 +1858,13 @@ public class NetscalerResource implements ServerResource { monitor_metric_binding.add(_netscalerService, monitor_metric_binding); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } } // SYS.VSERVER("abcd").SNMP_TABLE(0).AVERAGE_VALUE.GT(80) - int counterIndex = snmpMetrics.get(counterName); // TODO: temporary fix. later on counter name will be added as a param to SNMP_TABLE. + int counterIndex = snmpMetrics.get(counterName); // TODO: temporary fix. later on counter name +// will be added as a param to SNMP_TABLE. formatter.format("SYS.VSERVER(\"%s\").SNMP_TABLE(%d).AVERAGE_VALUE.%s(%d)",nsVirtualServerName, counterIndex, operator, threshold); } else if (counterTO.getSource().equals("netscaler")) @@ -1865,7 +1880,7 @@ public class NetscalerResource implements ServerResource { policyExpression = "(" + policyExpression + ")"; String policyId = Long.toString(autoScalePolicyTO.getId()); - String policyName = generateAutoScalePolicyName(srcIp, srcPort, policyId); + String policyName = generateAutoScalePolicyName(vmGroupIdentifier, policyId); String action = null; if(isScaleUpPolicy(autoScalePolicyTO)) { action = scaleUpActionName; @@ -1896,24 +1911,22 @@ public class NetscalerResource implements ServerResource { return true; } - @SuppressWarnings("static-access") private synchronized boolean disableAutoScaleConfig(LoadBalancerTO loadBalancerTO, boolean isCleanUp) throws Exception { - String srcIp = loadBalancerTO.getSrcIp(); - int srcPort = loadBalancerTO.getSrcPort(); - String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort); - String profileName = generateAutoScaleProfileName(srcIp, srcPort); - String timerName = generateAutoScaleTimerName(srcIp, srcPort); - String scaleDownActionName = generateAutoScaleScaleDownActionName(srcIp, srcPort); - String scaleUpActionName = generateAutoScaleScaleUpActionName(srcIp, srcPort); - String mtName = generateSnmpMetricTableName(srcIp, srcPort); - String monitorName = generateSnmpMonitorName(srcIp, srcPort); - String serviceGroupName = generateAutoScaleServiceGroupName(srcIp, srcPort); + String vmGroupIdentifier = generateAutoScaleVmGroupIdentifier(loadBalancerTO); + + String profileName = generateAutoScaleProfileName(vmGroupIdentifier); + String timerName = generateAutoScaleTimerName(vmGroupIdentifier); + String scaleDownActionName = generateAutoScaleScaleDownActionName(vmGroupIdentifier); + String scaleUpActionName = generateAutoScaleScaleUpActionName(vmGroupIdentifier); + String mtName = generateSnmpMetricTableName(vmGroupIdentifier); + String monitorName = generateSnmpMonitorName(vmGroupIdentifier); + String serviceGroupName = generateAutoScaleServiceGroupName(vmGroupIdentifier); AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO(); List policies = vmGroupTO.getPolicies(); - String minMemberPolicyName = generateAutoScaleMinPolicyName(srcIp, srcPort); - String maxMemberPolicyName = generateAutoScaleMaxPolicyName(srcIp, srcPort); + String minMemberPolicyName = generateAutoScaleMinPolicyName(vmGroupIdentifier); + String maxMemberPolicyName = generateAutoScaleMaxPolicyName(vmGroupIdentifier); try { @@ -1935,7 +1948,7 @@ public class NetscalerResource implements ServerResource { } } String policyId = Long.toString(autoScalePolicyTO.getId()); - String policyName = generateAutoScalePolicyName(srcIp, srcPort,policyId); + String policyName = generateAutoScalePolicyName(vmGroupIdentifier, policyId); // Removing Timer policy removeAutoScalePolicy(timerName, policyName, isCleanUp); @@ -1949,7 +1962,8 @@ public class NetscalerResource implements ServerResource { scaleDownAction.delete(_netscalerService, scaleDownAction); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // Delete AutoScale ScaleUp action @@ -1959,7 +1973,8 @@ public class NetscalerResource implements ServerResource { scaleUpAction.delete(_netscalerService, scaleUpAction); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // Delete Timer @@ -1969,7 +1984,8 @@ public class NetscalerResource implements ServerResource { timer.delete(_netscalerService, timer); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // Delete AutoScale Profile @@ -1979,7 +1995,8 @@ public class NetscalerResource implements ServerResource { autoscaleProfile.delete(_netscalerService, autoscaleProfile); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } if(isSnmp) { @@ -1990,7 +2007,8 @@ public class NetscalerResource implements ServerResource { servicegroup_lbmonitor_binding.delete(_netscalerService, servicegroup_monitor_binding); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // Delete Monitor @@ -2002,7 +2020,8 @@ public class NetscalerResource implements ServerResource { monitor.delete(_netscalerService, monitor); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // Delete Metric Table @@ -2012,7 +2031,8 @@ public class NetscalerResource implements ServerResource { metricTable.delete(_netscalerService, metricTable); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } } } catch (Exception ex) { @@ -2029,7 +2049,6 @@ public class NetscalerResource implements ServerResource { return true; } - private synchronized void addAutoScalePolicy(String timerName,String policyName, long priority, String policyExpression, String action, int duration, int interval, boolean isCleanUp) throws Exception { // Adding a autoscale policy @@ -2043,13 +2062,15 @@ public class NetscalerResource implements ServerResource { timerPolicy.add(_netscalerService, timerPolicy); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // bind timer policy // For now it is bound globally. // bind timer trigger lb_astimer -policyName lb_policy_scaleUp -vserver lb -priority 1 -samplesize 5 - // TODO: later bind to lbvserver. bind timer trigger lb_astimer -policyName lb_policy_scaleUp -vserver lb -priority 1 -samplesize 5 + // TODO: later bind to lbvserver. bind timer trigger lb_astimer -policyName lb_policy_scaleUp -vserver lb +// -priority 1 -samplesize 5 // -thresholdsize 5 nstimer_autoscalepolicy_binding timer_policy_binding = new nstimer_autoscalepolicy_binding(); int sampleSize = duration/interval; @@ -2063,7 +2084,8 @@ public class NetscalerResource implements ServerResource { timer_policy_binding.add(_netscalerService, timer_policy_binding); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } } @@ -2077,7 +2099,8 @@ public class NetscalerResource implements ServerResource { timer_policy_binding.delete(_netscalerService, timer_policy_binding); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } // Removing Timer policy @@ -2088,12 +2111,12 @@ public class NetscalerResource implements ServerResource { timerPolicy.delete(_netscalerService, timerPolicy); } catch (Exception e) { // Ignore Exception on cleanup - if(!isCleanUp) throw e; + if (!isCleanUp) + throw e; } } - private boolean isAutoScaleSupportedInNetScaler() throws ExecutionException { autoscaleprofile autoscaleProfile = new autoscaleprofile(); try { @@ -2200,44 +2223,48 @@ public class NetscalerResource implements ServerResource { return genObjectName("Cloud-Service", ip, port); } - private String generateAutoScaleServiceGroupName(String srcIp, long srcPort) { - return genObjectName("Cloud-AutoScaleServiceGroup", srcIp, srcPort); + private String generateAutoScaleVmGroupIdentifier(LoadBalancerTO lbTO) { + return lbTO.getSrcIp() + "-" + lbTO.getSrcPort(); } - private String generateAutoScaleTimerName(String srcIp, long srcPort) { - return genObjectName("Cloud-AutoScale-Timer", srcIp, srcPort); + private String generateAutoScaleServiceGroupName(String vmGroupIdentifier) { + return genObjectName("Cloud-AutoScale-SvcGrp", vmGroupIdentifier); } - private String generateAutoScaleProfileName(String srcIp, long srcPort) { - return genObjectName("Cloud-AutoScale-Profile", srcIp, srcPort); + private String generateAutoScaleTimerName(String vmGroupIdentifier) { + return genObjectName("Cloud-AutoScale-Timer", vmGroupIdentifier); } - private String generateAutoScaleScaleUpActionName(String srcIp, long srcPort) { - return genObjectName("Cloud-AutoScale-ScaleUpAction", srcIp, srcPort); + private String generateAutoScaleProfileName(String vmGroupIdentifier) { + return genObjectName("Cloud-AutoScale-Profile", vmGroupIdentifier); } - private String generateAutoScaleScaleDownActionName(String srcIp, long srcPort) { - return genObjectName("Cloud-AutoScale-ScaleDownAction", srcIp, srcPort); + private String generateAutoScaleScaleUpActionName(String vmGroupIdentifier) { + return genObjectName("Cloud-AutoScale-ScaleUpAction", vmGroupIdentifier); } - private String generateAutoScalePolicyName(String srcIp, long srcPort, String poilcyId) { - return genObjectName("Cloud-AutoScale-Policy", srcIp, srcPort, poilcyId); + private String generateAutoScaleScaleDownActionName(String vmGroupIdentifier) { + return genObjectName("Cloud-AutoScale-ScaleDownAction", vmGroupIdentifier); } - private String generateAutoScaleMinPolicyName(String srcIp, long srcPort) { - return genObjectName("Cloud-AutoScale-Policy-Min", srcIp, srcPort); + private String generateAutoScalePolicyName(String vmGroupIdentifier, String poilcyId) { + return genObjectName("Cloud-AutoScale-Policy", vmGroupIdentifier, poilcyId); } - private String generateAutoScaleMaxPolicyName(String srcIp, long srcPort) { - return genObjectName("Cloud-AutoScale-Policy-Max", srcIp, srcPort); + private String generateAutoScaleMinPolicyName(String vmGroupIdentifier) { + return genObjectName("Cloud-AutoScale-Policy-Min", vmGroupIdentifier); } - private String generateSnmpMetricTableName(String srcIp, long srcPort) { - return genObjectName("Cloud-MTbl", srcIp, srcPort); + private String generateAutoScaleMaxPolicyName(String vmGroupIdentifier) { + return genObjectName("Cloud-AutoScale-Policy-Max", vmGroupIdentifier); } - private String generateSnmpMonitorName(String srcIp, long srcPort) { - return genObjectName("Cloud-Mon", srcIp, srcPort); + private String generateSnmpMetricTableName(String vmGroupIdentifier) { + return genObjectName("Cloud-MTbl", vmGroupIdentifier); + } + + private String generateSnmpMonitorName(String vmGroupIdentifier) { + return genObjectName("Cloud-Mon", vmGroupIdentifier); } private String generateSnmpMetricName(String counterName) { diff --git a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java index bc7f2c14b54..8c69bf6d852 100644 --- a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java +++ b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java @@ -115,6 +115,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 @@ -384,7 +385,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase if (deviceMapLock.lock(120)) { try { boolean dedicatedLB = offering.getDedicatedLB(); // does network offering supports a dedicated - // load balancer? +// load balancer? long lbDeviceId; txn.start(); @@ -398,7 +399,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase // persist the load balancer device id that will be used for this network. Once a network // is implemented on a LB device then later on all rules will be programmed on to same - // device +// device NetworkExternalLoadBalancerVO networkLB = new NetworkExternalLoadBalancerVO(guestConfig.getId(), lbDeviceId); _networkExternalLBDao.persist(networkLB); @@ -416,12 +417,12 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase if (tryLbProvisioning) { retry = false; // TODO: throwing warning instead of error for now as its possible another provider can - // service this network +// service this network s_logger.warn("There are no load balancer device with the capacity for implementing this network"); throw exception; } else { tryLbProvisioning = true; // if possible provision a LB appliance in to the physical - // network +// network } } } finally { @@ -436,7 +437,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase } // there are no LB devices or there is no free capacity on the devices in the physical network so provision - // a new LB appliance +// a new LB appliance if (tryLbProvisioning) { // check if LB appliance can be dynamically provisioned List providerLbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Provider); @@ -444,7 +445,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase for (ExternalLoadBalancerDeviceVO lbProviderDevice : providerLbDevices) { if (lbProviderDevice.getState() == LBDeviceState.Enabled) { // acquire a private IP from the data center which will be used as management IP of - // provisioned LB appliance, +// provisioned LB appliance, DataCenterIpAddressVO dcPrivateIp = _dcDao.allocatePrivateIpAddress(guestConfig.getDataCenterId(), lbProviderDevice.getUuid()); if (dcPrivateIp == null) { throw new InsufficientNetworkCapacityException("failed to acquire a priavate IP in the zone " + guestConfig.getDataCenterId() + @@ -475,12 +476,12 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase String privateIf = createLbAnswer.getPrivateInterface(); // we have provisioned load balancer so add the appliance as cloudstack provisioned external - // load balancer +// load balancer String dedicatedLb = offering.getDedicatedLB() ? "true" : "false"; String capacity = Long.toString(lbProviderDevice.getCapacity()); // acquire a public IP to associate with lb appliance (used as subnet IP to make the - // appliance part of private network) +// appliance part of private network) PublicIp publicIp = _networkMgr.assignPublicIpAddress(guestConfig.getDataCenterId(), null, _accountMgr.getSystemAccount(), VlanType.VirtualNetwork, null, null, false); String publicIPNetmask = publicIp.getVlanNetmask(); String publicIPgateway = publicIp.getVlanGateway(); @@ -488,8 +489,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase String publicIP = publicIp.getAddress().toString(); String url = "https://" + lbIP + "?publicinterface=" + publicIf + "&privateinterface=" + privateIf + "&lbdevicededicated=" + dedicatedLb + - "&cloudmanaged=true" + "&publicip=" + publicIP + "&publicipnetmask=" + publicIPNetmask + "&lbdevicecapacity=" + capacity + - "&publicipvlan=" + publicIPVlanTag + "&publicipgateway=" + publicIPgateway; + "&cloudmanaged=true" + "&publicip=" + publicIP + "&publicipnetmask=" + publicIPNetmask + "&lbdevicecapacity=" + capacity + + "&publicipvlan=" + publicIPVlanTag + "&publicipgateway=" + publicIPgateway; ExternalLoadBalancerDeviceVO lbAppliance = null; try { lbAppliance = addExternalLoadBalancer(physicalNetworkId, url, username, password, createLbAnswer.getDeviceName(), createLbAnswer.getServerResource()); @@ -499,7 +500,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase if (lbAppliance != null) { // mark the load balancer as cloudstack managed and set parent host id on which lb - // appliance is provisioned +// appliance is provisioned ExternalLoadBalancerDeviceVO managedLb = _externalLoadBalancerDeviceDao.findById(lbAppliance.getId()); managedLb.setIsManagedDevice(true); managedLb.setParentHostId(lbProviderDevice.getHostId()); @@ -514,7 +515,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase s_logger.warn("Failed to destroy load balancer appliance created"); } else { // release the public & private IP back to dc pool, as the load balancer - // appliance is now destroyed +// appliance is now destroyed _dcDao.releasePrivateIpAddress(lbIP, guestConfig.getDataCenterId(), null); _networkMgr.disassociatePublicIpAddress(publicIp.getId(), _accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount()); } @@ -594,7 +595,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase } // if we are here then there are no existing LB devices in shared use or the devices in shared use has no - // free capacity left +// free capacity left // so allocate a new load balancer configured for shared use from the pool of free LB devices lbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Free); if (lbDevices != null && !lbDevices.isEmpty()) { @@ -631,7 +632,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase if (!lbInUse && !lbCloudManaged) { // this is the last network mapped to the load balancer device so set device allocation state to be - // free +// free lbDevice.setAllocationState(LBDeviceAllocationState.Free); _externalLoadBalancerDeviceDao.update(lbDevice.getId(), lbDevice); } @@ -797,9 +798,9 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase LoadBalancingRule rule = loadBalancingRules.get(i); boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke)); - Long lbId = rule.getId(); String protocol = rule.getProtocol(); String algorithm = rule.getAlgorithm(); + String uuid = rule.getUuid(); String srcIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress().addr(); int srcPort = rule.getSourcePortStart(); List destinations = rule.getDestinations(); @@ -836,7 +837,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase _inlineLoadBalancerNicMapDao.persist(mapping); // On the firewall provider for the network, create a static NAT rule between the source IP - // address and the load balancing IP address +// address and the load balancing IP address applyStaticNatRuleForInlineLBRule(zone, network, firewallProviderHost, revoked, srcIp, loadBalancingIpNic.getIp4Address()); } else { loadBalancingIpNic = _nicDao.findById(mapping.getNicId()); @@ -847,7 +848,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase loadBalancingIpNic = _nicDao.findById(mapping.getNicId()); // On the firewall provider for the network, delete the static NAT rule between the source IP - // address and the load balancing IP address +// address and the load balancing IP address applyStaticNatRuleForInlineLBRule(zone, network, firewallProviderHost, revoked, srcIp, loadBalancingIpNic.getIp4Address()); // Delete the mapping between the source IP address and the load balancing IP address @@ -866,7 +867,7 @@ 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()); + LoadBalancerTO loadBalancer = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies()); if(rule.isAutoScaleConfig()) { loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup()); } @@ -917,7 +918,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(guestConfig); if (lbDeviceVO == null) { s_logger.warn("Network shutdwon requested on external load balancer element, which did not implement the network." + - " Either network implement failed half way through or already network shutdown is completed. So just returning."); + " Either network implement failed half way through or already network shutdown is completed. So just returning."); return true; } @@ -944,7 +945,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase NicVO selfipNic = getPlaceholderNic(guestConfig); if (selfipNic == null) { s_logger.warn("Network shutdwon requested on external load balancer element, which did not implement the network." + - " Either network implement failed half way through or already network shutdown is completed. So just returning."); + " Either network implement failed half way through or already network shutdown is completed. So just returning."); return true; } selfIp = selfipNic.getIp4Address(); diff --git a/server/src/com/cloud/network/as/AutoScaleVmGroupVO.java b/server/src/com/cloud/network/as/AutoScaleVmGroupVO.java index 3de9f9b541e..ab3ee1a059a 100644 --- a/server/src/com/cloud/network/as/AutoScaleVmGroupVO.java +++ b/server/src/com/cloud/network/as/AutoScaleVmGroupVO.java @@ -182,4 +182,9 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup { public void setLoadBalancerId(Long loadBalancerId) { this.loadBalancerId = loadBalancerId; } + + @Override + public String getUuid() { + return uuid; + } } diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index df18c0475cc..2d3a6755774 100755 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -110,6 +110,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; @@ -199,6 +201,10 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa @Inject VpcManager _vpcMgr; @Inject + VMTemplateDao _templateDao; + @Inject + ServiceOfferingDao _offeringsDao; + @Inject CounterDao _counterDao; @Inject ConditionDao _conditionDao; @@ -263,20 +269,24 @@ public class LoadBalancingRulesManagerImpl 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"); } - if (secretKey == null) { + if(secretKey == null) { throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it"); } - 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"); } - 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, currentState); } @@ -326,11 +336,11 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa success = applyAutoScaleConfig(loadBalancer, vmGroup, currentState); } catch (ResourceUnavailableException e) { s_logger.warn("Unable to configure AutoScaleVmGroup to the lb rule: " + loadBalancer.getId() + " because resource is unavaliable:", e); - if (isRollBackAllowedForProvider(loadBalancer)) { - loadBalancer.setState(backupState); - _lbDao.persist(loadBalancer); - s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + " lb state rolback while creating AutoscaleVmGroup"); - } + if (isRollBackAllowedForProvider(loadBalancer)) { + loadBalancer.setState(backupState); + _lbDao.persist(loadBalancer); + s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + " lb state rolback while creating AutoscaleVmGroup"); + } throw e; } finally { if (!success) { @@ -829,10 +839,10 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa if (apply) { try { - if (!applyLoadBalancerConfig(loadBalancerId)) { - s_logger.warn("Unable to apply the load balancer config"); - return false; - } + if (!applyLoadBalancerConfig(loadBalancerId)) { + s_logger.warn("Unable to apply the load balancer config"); + return false; + } } catch (ResourceUnavailableException e) { if (rollBack && isRollBackAllowedForProvider(lb)) { if (backupMaps != null) { diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 19ad591d130..a7f4b5e3479 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -2795,12 +2795,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke)); String protocol = rule.getProtocol(); String algorithm = rule.getAlgorithm(); + String uuid = rule.getUuid(); String srcIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress().addr(); int srcPort = rule.getSourcePortStart(); List destinations = rule.getDestinations(); List stickinessPolicies = rule.getStickinessPolicies(); - LoadBalancerTO lb = new LoadBalancerTO(rule.getId(), srcIp, srcPort, protocol, algorithm, revoked, false, destinations, stickinessPolicies); + LoadBalancerTO lb = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, destinations, stickinessPolicies); lbs[i++] = lb; } String routerPublicIp = null;