http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e245efed/api/src/com/cloud/network/as/AutoScaleVmGroup.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/as/AutoScaleVmGroup.java b/api/src/com/cloud/network/as/AutoScaleVmGroup.java new file mode 100644 index 0000000..02b8f50 --- /dev/null +++ b/api/src/com/cloud/network/as/AutoScaleVmGroup.java @@ -0,0 +1,52 @@ +// 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 +// +// 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; + +import com.cloud.acl.ControlledEntity; + +/** + * @author Deepak Garg + */ + +public interface AutoScaleVmGroup extends ControlledEntity { + + String State_New = "new"; + String State_Revoke = "revoke"; + String State_Enabled = "enabled"; + String State_Disabled = "disabled"; + + long getId(); + + @Override + long getAccountId(); + + Long getLoadBalancerId(); + + long getProfileId(); + + int getMinMembers(); + + int getMaxMembers(); + + int getMemberPort(); + + int getInterval(); + + String getState(); + +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e245efed/api/src/com/cloud/network/as/AutoScaleVmProfile.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/as/AutoScaleVmProfile.java b/api/src/com/cloud/network/as/AutoScaleVmProfile.java new file mode 100644 index 0000000..7fc6191 --- /dev/null +++ b/api/src/com/cloud/network/as/AutoScaleVmProfile.java @@ -0,0 +1,44 @@ +// 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 +// +// 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; + +import com.cloud.acl.ControlledEntity; + +/** + * AutoScaleVmProfile + */ +public interface AutoScaleVmProfile extends ControlledEntity { + + public long getId(); + + public Long getZoneId(); + + public Long getServiceOfferingId(); + + public Long getTemplateId(); + + public String getOtherDeployParams(); + + public String getSnmpCommunity(); + + public Integer getSnmpPort(); + + public Integer getDestroyVmGraceperiod(); + + public long getAutoScaleUserId(); +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e245efed/api/src/com/cloud/network/as/Condition.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/as/Condition.java b/api/src/com/cloud/network/as/Condition.java new file mode 100644 index 0000000..117827d --- /dev/null +++ b/api/src/com/cloud/network/as/Condition.java @@ -0,0 +1,37 @@ +// 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 +// +// 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; + +import com.cloud.acl.ControlledEntity; + +public interface Condition extends ControlledEntity { + + static enum Operator { + EQ, GT, LT, GE, LE + }; + + long getCounterid(); + + long getThreshold(); + + Operator getRelationalOperator(); + + String getUuid(); + + long getId(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e245efed/api/src/com/cloud/network/as/Counter.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/as/Counter.java b/api/src/com/cloud/network/as/Counter.java new file mode 100644 index 0000000..b4be1b8 --- /dev/null +++ b/api/src/com/cloud/network/as/Counter.java @@ -0,0 +1,36 @@ +// 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 +// +// 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; + +public interface Counter { + + public static enum Source { + netscaler, + snmp + } + + String getName(); + + String getValue(); + + Source getSource(); + + String getUuid(); + + long getId(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e245efed/api/src/com/cloud/network/lb/LoadBalancingRule.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/lb/LoadBalancingRule.java b/api/src/com/cloud/network/lb/LoadBalancingRule.java index c79ab18..5c39f31 100644 --- a/api/src/com/cloud/network/lb/LoadBalancingRule.java +++ b/api/src/com/cloud/network/lb/LoadBalancingRule.java @@ -18,6 +18,11 @@ package com.cloud.network.lb; import java.util.List; +import com.cloud.network.as.AutoScalePolicy; +import com.cloud.network.as.AutoScaleVmGroup; +import com.cloud.network.as.AutoScaleVmProfile; +import com.cloud.network.as.Condition; +import com.cloud.network.as.Counter; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.LoadBalancer; import com.cloud.utils.Pair; @@ -26,42 +31,44 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer{ private LoadBalancer lb; private List<LbDestination> destinations; private List<LbStickinessPolicy> stickinessPolicies; - - public LoadBalancingRule(LoadBalancer lb, List<LbDestination> destinations, List<LbStickinessPolicy> stickinessPolicies) { + private LbAutoScaleVmGroup autoScaleVmGroup; + + public LoadBalancingRule(LoadBalancer lb, List<LbDestination> destinations, List<LbStickinessPolicy> stickinessPolicies) { this.lb = lb; this.destinations = destinations; this.stickinessPolicies = stickinessPolicies; } - + @Override public long getId() { return lb.getId(); } - + @Override public long getAccountId() { return lb.getAccountId(); } - + @Override public long getDomainId() { return lb.getDomainId(); } - + @Override public String getName() { return lb.getName(); } - + @Override public String getDescription() { return lb.getDescription(); } + @Override public int getDefaultPortStart() { return lb.getDefaultPortStart(); } - + @Override public int getDefaultPortEnd() { return lb.getDefaultPortEnd(); @@ -71,22 +78,22 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer{ public String getAlgorithm() { return lb.getAlgorithm(); } - + @Override public String getXid() { return lb.getXid(); } - + @Override public long getSourceIpAddressId() { return lb.getSourceIpAddressId(); } - + @Override public Integer getSourcePortStart() { return lb.getSourcePortStart(); } - + @Override public Integer getSourcePortEnd() { return lb.getSourcePortEnd(); @@ -96,22 +103,22 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer{ public String getProtocol() { return lb.getProtocol(); } - + @Override public Purpose getPurpose() { return Purpose.LoadBalancing; } - + @Override public State getState() { return lb.getState(); } - + @Override public long getNetworkId() { return lb.getNetworkId(); } - + public LoadBalancer getLb() { return lb; } @@ -119,12 +126,12 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer{ public List<LbDestination> getDestinations() { return destinations; } - + public List<LbStickinessPolicy> getStickinessPolicies() { return stickinessPolicies; } - - + + public interface Destination { String getIpAddress(); int getDestinationPortStart(); @@ -148,7 +155,7 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer{ this._params = params; this._revoke = false; } - + public String getMethodName() { return _methodName; } @@ -161,61 +168,175 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer{ return _revoke; } } - + public static class LbDestination implements Destination { private int portStart; private int portEnd; private String ip; boolean revoked; - + public LbDestination(int portStart, int portEnd, String ip, boolean revoked) { this.portStart = portStart; this.portEnd = portEnd; this.ip = ip; this.revoked = revoked; } - + + @Override public String getIpAddress() { return ip; } + @Override public int getDestinationPortStart() { return portStart; } + @Override public int getDestinationPortEnd() { return portEnd; } - + + @Override public boolean isRevoked() { return revoked; } - + public void setRevoked(boolean revoked) { this.revoked = revoked; } } - + @Override public Integer getIcmpCode() { return null; } - + @Override public Integer getIcmpType() { return null; } - + @Override public List<String> getSourceCidrList() { return null; } - + @Override public Long getRelated() { return null; } - @Override - public FirewallRuleType getType() { - return FirewallRuleType.User; - } + @Override + public FirewallRuleType getType() { + return FirewallRuleType.User; + } + public LbAutoScaleVmGroup getAutoScaleVmGroup() { + return autoScaleVmGroup; + } + + public boolean isAutoScaleConfig() { + return this.autoScaleVmGroup != null; + } + + public void setAutoScaleVmGroup(LbAutoScaleVmGroup autoScaleVmGroup) { + this.autoScaleVmGroup = autoScaleVmGroup; + } + + public static class LbCondition { + private final Condition condition; + private final Counter counter; + + public LbCondition(Counter counter, Condition condition) { + this.condition = condition; + this.counter = counter; + } + + public Condition getCondition() { + return condition; + } + + public Counter getCounter() { + return counter; + } + } + + public static class LbAutoScalePolicy { + private final List<LbCondition> conditions; + private final AutoScalePolicy policy; + private boolean revoked; + + public LbAutoScalePolicy(AutoScalePolicy policy, List<LbCondition> conditions) + { + this.policy = policy; + this.conditions = conditions; + } + + public List<LbCondition> getConditions() { + return conditions; + } + + public AutoScalePolicy getPolicy() { + return policy; + } + + public boolean isRevoked() { + return revoked; + } + + public void setRevoked(boolean revoked) { + this.revoked = revoked; + } + } + + public static class LbAutoScaleVmProfile { + AutoScaleVmProfile profile; + private final String autoScaleUserApiKey; + private final String autoScaleUserSecretKey; + private final String csUrl; + + public LbAutoScaleVmProfile(AutoScaleVmProfile profile, String autoScaleUserApiKey, String autoScaleUserSecretKey, String csUrl) { + this.profile = profile; + this.autoScaleUserApiKey = autoScaleUserApiKey; + this.autoScaleUserSecretKey = autoScaleUserSecretKey; + this.csUrl = csUrl; + } + + public AutoScaleVmProfile getProfile() { + return profile; + } + + public String getAutoScaleUserApiKey() { + return autoScaleUserApiKey; + } + + public String getAutoScaleUserSecretKey() { + return autoScaleUserSecretKey; + } + public String getCsUrl() { + return csUrl; + } + } + + public static class LbAutoScaleVmGroup { + AutoScaleVmGroup vmGroup; + private final List<LbAutoScalePolicy> policies; + private final LbAutoScaleVmProfile profile; + + public LbAutoScaleVmGroup(AutoScaleVmGroup vmGroup, List<LbAutoScalePolicy> policies, LbAutoScaleVmProfile profile) { + this.vmGroup = vmGroup; + this.policies = policies; + this.profile = profile; + } + + public AutoScaleVmGroup getVmGroup() { + return vmGroup; + } + + public List<LbAutoScalePolicy> getPolicies() { + return policies; + } + + public LbAutoScaleVmProfile getProfile() { + return profile; + } + } } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e245efed/client/tomcatconf/commands.properties.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 28beade..72fd02f 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -136,6 +136,28 @@ listLBStickinessPolicies=com.cloud.api.commands.ListLBStickinessPoliciesCmd;15 listLoadBalancerRuleInstances=com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;15 updateLoadBalancerRule=com.cloud.api.commands.UpdateLoadBalancerRuleCmd;15 +#### autoscale commands +createCounter = com.cloud.api.commands.CreateCounterCmd;1 +createCondition = com.cloud.api.commands.CreateConditionCmd;15 +createAutoScalePolicy=com.cloud.api.commands.CreateAutoScalePolicyCmd;15 +createAutoScaleVmProfile=com.cloud.api.commands.CreateAutoScaleVmProfileCmd;15 +createAutoScaleVmGroup=com.cloud.api.commands.CreateAutoScaleVmGroupCmd;15 +deleteCounter = com.cloud.api.commands.DeleteCounterCmd;1 +deleteCondition = com.cloud.api.commands.DeleteConditionCmd;15 +deleteAutoScalePolicy=com.cloud.api.commands.DeleteAutoScalePolicyCmd;15 +deleteAutoScaleVmProfile=com.cloud.api.commands.DeleteAutoScaleVmProfileCmd;15 +deleteAutoScaleVmGroup=com.cloud.api.commands.DeleteAutoScaleVmGroupCmd;15 +listCounters = com.cloud.api.commands.ListCountersCmd;15 +listConditions = com.cloud.api.commands.ListConditionsCmd;15 +listAutoScalePolicies=com.cloud.api.commands.ListAutoScalePoliciesCmd;15 +listAutoScaleVmProfiles=com.cloud.api.commands.ListAutoScaleVmProfilesCmd;15 +listAutoScaleVmGroups=com.cloud.api.commands.ListAutoScaleVmGroupsCmd;15 +enableAutoScaleVmGroup=com.cloud.api.commands.EnableAutoScaleVmGroupCmd;15 +disableAutoScaleVmGroup=com.cloud.api.commands.DisableAutoScaleVmGroupCmd;15 +updateAutoScalePolicy=com.cloud.api.commands.UpdateAutoScalePolicyCmd;15 +updateAutoScaleVmProfile=com.cloud.api.commands.UpdateAutoScaleVmProfileCmd;15 +updateAutoScaleVmGroup=com.cloud.api.commands.UpdateAutoScaleVmGroupCmd;15 + #### router commands startRouter=com.cloud.api.commands.StartRouterCmd;7 rebootRouter=com.cloud.api.commands.RebootRouterCmd;7 http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e245efed/deps/cloud-netscaler.jar ---------------------------------------------------------------------- diff --git a/deps/cloud-netscaler.jar b/deps/cloud-netscaler.jar index a073b50..ab5be74 100755 Binary files a/deps/cloud-netscaler.jar and b/deps/cloud-netscaler.jar differ http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e245efed/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java ---------------------------------------------------------------------- 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 8d1963d..57e631e 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 @@ -135,10 +135,10 @@ import com.cloud.vm.dao.DomainRouterDao; @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); - + .getLogger(ElasticLoadBalancerManagerImpl.class); + @Inject IPAddressDao _ipAddressDao; @Inject @@ -181,9 +181,9 @@ public class ElasticLoadBalancerManagerImpl implements PodVlanMapDao _podVlanMapDao; @Inject ElasticLbVmMapDao _elbVmMapDao; - @Inject + @Inject NetworkDao _networksDao; - @Inject + @Inject AccountDao _accountDao; @Inject PhysicalNetworkServiceProviderDao _physicalProviderDao; @@ -195,7 +195,7 @@ public class ElasticLoadBalancerManagerImpl implements String _instance; static final private String _elbVmNamePrefix = "l"; static final private String _systemVmType = "elbvm"; - + boolean _enabled; TrafficType _frontendTrafficType = TrafficType.Guest; @@ -204,13 +204,13 @@ public class ElasticLoadBalancerManagerImpl implements ScheduledExecutorService _gcThreadPool; String _mgmtCidr; String _mgmtHost; - + Set<Long> _gcCandidateElbVmIds = Collections.newSetFromMap(new ConcurrentHashMap<Long,Boolean>()); - + int _elasticLbVmRamSize; int _elasticLbvmCpuMHz; int _elasticLbvmNumCpu; - + private Long getPodIdForDirectIp(IPAddressVO ipAddr) { PodVlanMapVO podVlanMaps = _podVlanMapDao.listPodVlanMapsByVlan(ipAddr.getVlanId()); if (podVlanMaps == null) { @@ -221,7 +221,7 @@ public class ElasticLoadBalancerManagerImpl implements } - 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); @@ -241,14 +241,14 @@ public class ElasticLoadBalancerManagerImpl implements s_logger.debug("Deployed ELB vm = " + elbVm); return elbVm; - + } catch (Throwable t) { s_logger.warn("Error while deploying ELB VM: ", t); return null; } } - + private boolean sendCommandsToRouter(final DomainRouterVO elbVm, Commands cmds) throws AgentUnavailableException { Answer[] answers = null; @@ -290,11 +290,11 @@ public class ElasticLoadBalancerManagerImpl implements String algorithm = rule.getAlgorithm(); String elbIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress() - .addr(); + .addr(); int srcPort = rule.getSourcePortStart(); List<LbDestination> destinations = rule.getDestinations(); - LoadBalancerTO lb = new LoadBalancerTO(elbIp, srcPort, protocol, algorithm, revoked, false, destinations); - lbs[i++] = lb; + LoadBalancerTO lb = new LoadBalancerTO(rule.getId(), elbIp, srcPort, protocol, algorithm, revoked, false, destinations); + lbs[i++] = lb; } LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs,elbVm.getPublicIpAddress(),elbVm.getGuestIpAddress(),elbVm.getPrivateIpAddress()); @@ -308,7 +308,7 @@ public class ElasticLoadBalancerManagerImpl implements cmd.lbStatsUri = _configDao.getValue(Config.NetworkLBHaproxyStatsUri.key()); cmd.lbStatsAuth = _configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key()); cmd.lbStatsPort = _configDao.getValue(Config.NetworkLBHaproxyStatsPort.key()); - + cmds.addCommand(cmd); } @@ -320,7 +320,7 @@ public class ElasticLoadBalancerManagerImpl implements // Send commands to elbVm return sendCommandsToRouter(elbVm, cmds); } - + protected DomainRouterVO findElbVmForLb(FirewallRule lb) {//TODO: use a table to lookup ElasticLbVmMapVO map = _elbVmMapDao.findOneByIp(lb.getSourceIpAddressId()); if (map == null) { @@ -330,9 +330,10 @@ public class ElasticLoadBalancerManagerImpl implements return elbVm; } + @Override public boolean applyLoadBalancerRules(Network network, List<? extends FirewallRule> rules) - throws ResourceUnavailableException { + throws ResourceUnavailableException { if (rules == null || rules.isEmpty()) { return true; } @@ -340,9 +341,9 @@ public class ElasticLoadBalancerManagerImpl implements s_logger.warn("ELB: Not handling non-LB firewall rules"); return false; } - + DomainRouterVO elbVm = findElbVmForLb(rules.get(0)); - + if (elbVm == null) { s_logger.warn("Unable to apply lb rules, ELB vm doesn't exist in the network " + network.getId()); @@ -359,7 +360,7 @@ public class ElasticLoadBalancerManagerImpl implements List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId()); LoadBalancingRule loadBalancing = new LoadBalancingRule( lb, dstList, policyList); - lbRules.add(loadBalancing); + lbRules.add(loadBalancing); } return applyLBRules(elbVm, lbRules); } else if (elbVm.getState() == State.Stopped @@ -379,7 +380,7 @@ public class ElasticLoadBalancerManagerImpl implements @Override public boolean configure(String name, Map<String, Object> params) - throws ConfigurationException { + throws ConfigurationException { _name = name; final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params); _systemAcct = _accountService.getSystemAccount(); @@ -389,20 +390,20 @@ public class ElasticLoadBalancerManagerImpl implements } _mgmtCidr = _configDao.getValue(Config.ManagementNetwork.key()); _mgmtHost = _configDao.getValue(Config.ManagementHostIPAdr.key()); - + boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key())); _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); @@ -416,14 +417,14 @@ public class ElasticLoadBalancerManagerImpl implements 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")); _gcThreadPool.scheduleAtFixedRate(new CleanupThread(), gcIntervalMinutes, gcIntervalMinutes, TimeUnit.MINUTES); _itMgr.registerGuru(VirtualMachine.Type.ElasticLoadBalancerVm, this); } - + return true; } @@ -455,9 +456,9 @@ public class ElasticLoadBalancerManagerImpl implements } 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,14 +478,14 @@ public class ElasticLoadBalancerManagerImpl implements 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; - + plan = new DataCenterDeployment(dcId, dest.getPod().getId(), null, null, null, null); if (elbVm == null) { @@ -492,7 +493,7 @@ public class ElasticLoadBalancerManagerImpl implements if (s_logger.isDebugEnabled()) { s_logger.debug("Creating the ELB vm " + id); } - + List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); NetworkOfferingVO controlOffering = offerings.get(0); NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); @@ -502,7 +503,7 @@ public class ElasticLoadBalancerManagerImpl implements guestNic.setDefaultNic(true); networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, guestNic)); networks.add(new Pair<NetworkVO, NicProfile>(controlConfig, null)); - + VMTemplateVO template = _templateDao.findSystemVMTemplate(dcId); String typeString = "ElasticLoadBalancerVm"; @@ -515,7 +516,7 @@ public class ElasticLoadBalancerManagerImpl implements if (vrProvider == null) { throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId()); } - + elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, false, RedundantState.UNKNOWN, _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm); elbVm.setRole(Role.LB); @@ -534,7 +535,7 @@ public class ElasticLoadBalancerManagerImpl implements _networkDao.releaseFromLockTable(guestNetworkId); } } - + private DomainRouterVO start(DomainRouterVO elbVm, User user, Account caller, Map<Param, Object> params) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Starting ELB VM " + elbVm); @@ -544,8 +545,8 @@ public class ElasticLoadBalancerManagerImpl implements return null; } } - - + + private DomainRouterVO stop(DomainRouterVO elbVm, boolean forced, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Stopping ELB vm " + elbVm); try { @@ -558,10 +559,10 @@ public class ElasticLoadBalancerManagerImpl implements throw new CloudRuntimeException("Unable to stop " + elbVm, e); } } - + 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) { @@ -578,7 +579,7 @@ public class ElasticLoadBalancerManagerImpl implements sc.setParameters("accountId", accountId); if (ipId != null) { sc.setParameters("sourceIpAddress", ipId); - } + } if (domainId != null) { sc.setParameters("domainId",domainId); } @@ -586,44 +587,44 @@ public class ElasticLoadBalancerManagerImpl implements sc.setParameters("publicPort", publicPort); } List<LoadBalancerVO> lbs = _lbDao.search(sc, null); - + return lbs == null || lbs.size()==0 ? null: lbs; } - + @DB public PublicIp allocDirectIp(Account account, long guestNetworkId) throws InsufficientAddressCapacityException { Network frontEndNetwork = _networkMgr.getNetwork(guestNetworkId); Transaction txn = Transaction.currentTxn(); txn.start(); - + 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); return ip; } - + 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.releasePublicIpAddress(ipId, userId, caller); - _ipAddressDao.unassignIpAddress(ipId); + _networkMgr.releasePublicIpAddress(ipId, userId, caller); + _ipAddressDao.unassignIpAddress(ipId); } @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 - if (!_networkMgr.isProviderSupportServiceInNetwork(lb.getNetworkId(), Service.Lb, Provider.ElasticLoadBalancerVm)) { - return null; - } - - Long ipId = lb.getSourceIpAddressId(); + if (!_networkMgr.isProviderSupportServiceInNetwork(lb.getNetworkId(), Service.Lb, Provider.ElasticLoadBalancerVm)) { + return null; + } + + Long ipId = lb.getSourceIpAddressId(); if (ipId != null) { return null; } @@ -642,7 +643,7 @@ public class ElasticLoadBalancerManagerImpl implements 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); @@ -660,7 +661,7 @@ public class ElasticLoadBalancerManagerImpl implements Network network = _networkMgr.getNetwork(networkId); IPAddressVO ipAddr = _ipAddressDao.findById(ipId); - + LoadBalancer result = null; try { lb.setSourceIpAddressId(ipId); @@ -693,26 +694,26 @@ public class ElasticLoadBalancerManagerImpl implements elbVm = _routerDao.findById(elbVmMap.getElbVmId()); } } - + if (elbVm == null) { s_logger.warn("No ELB VM can be found or deployed"); s_logger.warn("Deleting LB since we failed to deploy ELB VM"); _lbDao.remove(result.getId()); return null; } - + ElasticLbVmMapVO mapping = new ElasticLbVmMapVO(ipId, elbVm.getId(), result.getId()); _elbVmMapDao.persist(mapping); return result; - + } finally { if (account != null) { _accountDao.releaseFromLockTable(account.getId()); } } - + } - + void garbageCollectUnusedElbVms() { List<DomainRouterVO> unusedElbVms = _elbVmMapDao.listUnusedElbVms(); if (unusedElbVms != null && unusedElbVms.size() > 0) @@ -754,12 +755,12 @@ public class ElasticLoadBalancerManagerImpl implements } _gcCandidateElbVmIds = currentGcCandidates; } - + public class CleanupThread implements Runnable { @Override public void run() { garbageCollectUnusedElbVms(); - + } CleanupThread() { @@ -779,7 +780,7 @@ public class ElasticLoadBalancerManagerImpl implements } } - + @Override public DomainRouterVO findByName(String name) { if (!VirtualMachineName.isValidSystemVmName(name, _instance, _elbVmNamePrefix)) { @@ -854,13 +855,13 @@ public class ElasticLoadBalancerManagerImpl implements String domain = network.getNetworkDomain(); if (domain != null) { buf.append(" domain=" + domain); - } + } buf.append(" dns1=").append(defaultDns1); if (defaultDns2 != null) { buf.append(" dns2=").append(defaultDns2); } - + if (s_logger.isDebugEnabled()) { s_logger.debug("Boot Args for " + profile + ": " + buf.toString()); } @@ -915,7 +916,7 @@ public class ElasticLoadBalancerManagerImpl implements DataCenterVO dcVo = _dcDao.findById(elbVm.getDataCenterIdToDeployIn()); NicProfile controlNic = null; - + 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 @@ -966,7 +967,7 @@ public class ElasticLoadBalancerManagerImpl implements processStopOrRebootAnswer(elbVm, answer); } } - + public void processStopOrRebootAnswer(final DomainRouterVO elbVm, Answer answer) { //TODO: process network usage stats } @@ -975,7 +976,7 @@ public class ElasticLoadBalancerManagerImpl implements @Override public void finalizeExpunge(DomainRouterVO vm) { // no-op - + } @@ -989,11 +990,11 @@ public class ElasticLoadBalancerManagerImpl implements } - @Override - public boolean recreateNeeded( - VirtualMachineProfile<DomainRouterVO> profile, long hostId, - Commands cmds, ReservationContext context) { - // TODO Auto-generated method stub - return false; - } + @Override + public boolean recreateNeeded( + VirtualMachineProfile<DomainRouterVO> profile, long hostId, + Commands cmds, ReservationContext context) { + // TODO Auto-generated method stub + return false; + } } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e245efed/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java ---------------------------------------------------------------------- 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 7fcb6d0..1b5f17a 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 @@ -8,7 +8,7 @@ // 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. -// +// // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.element; @@ -104,7 +104,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); @@ -138,7 +138,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl NetScalerPodDao _netscalerPodDao; @Inject DataCenterIpAddressDao _privateIpAddressDao; - + private boolean canHandle(Network config, Service service) { DataCenter zone = _dcDao.findById(config.getDataCenterId()); boolean handleInAdvanceZone = (zone.getNetworkType() == NetworkType.Advanced && config.getGuestType() == Network.GuestType.Isolated && config.getTrafficType() == TrafficType.Guest); @@ -159,14 +159,14 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl @Override public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, - InsufficientNetworkCapacityException { + InsufficientNetworkCapacityException { if (!canHandle(guestConfig, Service.Lb)) { return false; } if (_ntwkSrvcDao.canProviderSupportServiceInNetwork(guestConfig.getId(), Service.StaticNat, Network.Provider.Netscaler) && !isBasicZoneNetwok(guestConfig)) { - s_logger.error("NetScaler provider can not be Static Nat service provider for the network " + guestConfig.getGuestType() + + s_logger.error("NetScaler provider can not be Static Nat service provider for the network " + guestConfig.getGuestType() + " and traffic type " + guestConfig.getTrafficType()); return false; } @@ -180,7 +180,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl @Override public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, - InsufficientNetworkCapacityException, ResourceUnavailableException { + InsufficientNetworkCapacityException, ResourceUnavailableException { return true; } @@ -248,6 +248,9 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl // Specifies that load balancing rules can only be made with public IPs that aren't source NAT IPs lbCapabilities.put(Capability.LoadBalancingSupportedIps, "additional"); + // Specifies that load balancing rules can support autoscaling + lbCapabilities.put(Capability.AutoScaleCounters, "snmp,netscaler"); + LbStickinessMethod method; List<LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>(); method = new LbStickinessMethod(StickinessMethodType.LBCookieBased, "This is cookie based sticky method, can be used only for http"); @@ -311,7 +314,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl throw new InvalidParameterValueException(msg); } - ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceName, (ServerResource) new NetscalerResource()); + ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource()); return lbDeviceVO; } @@ -402,7 +405,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl } if (inline != null) { - boolean _setInline = Boolean.parseBoolean((String) lbDetails.get("inline")); + boolean _setInline = Boolean.parseBoolean(lbDetails.get("inline")); if (inline != _setInline) { throw new CloudRuntimeException("There are networks already using this netscaler device to change the device inline or side-by-side configuration"); } @@ -535,13 +538,13 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl response.setProvider(lbDeviceVO.getProviderName()); response.setDeviceState(lbDeviceVO.getState().name()); response.setObjectName("netscalerloadbalancer"); - + List<Long> associatedPods = new ArrayList<Long>(); List<NetScalerPodVO> currentPodVOs = _netscalerPodDao.listByNetScalerDeviceId(lbDeviceVO.getId()); if (currentPodVOs != null && currentPodVOs.size() > 0) { - for (NetScalerPodVO nsPodVo: currentPodVOs) { - associatedPods.add(nsPodVo.getPodId()); - } + for (NetScalerPodVO nsPodVo: currentPodVOs) { + associatedPods.add(nsPodVo.getPodId()); + } } response.setAssociatedPods(associatedPods); return response; @@ -557,7 +560,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl List<ExternalLoadBalancerDeviceVO> lbDevices = _lbDeviceDao.listByPhysicalNetworkAndProvider(provider.getPhysicalNetworkId(), Provider.Netscaler.getName()); // true if at-least one Netscaler device is added in to physical network and is in configured (in enabled state) -// state + // state if (lbDevices != null && !lbDevices.isEmpty()) { for (ExternalLoadBalancerDeviceVO lbDevice : lbDevices) { if (lbDevice.getState() == LBDeviceState.Enabled) { @@ -570,7 +573,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl @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; } @@ -598,8 +601,8 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl // NetScaler can only act as Lb and Static Nat service provider if (services != null && !services.isEmpty() && !netscalerServices.containsAll(services)) { - s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " - + services + " is not supported."); + s_logger.warn("NetScaler network element can only support LB and Static NAT services and service combination " + + services + " is not supported."); return false; } @@ -658,8 +661,11 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl int srcPort = rule.getSourcePortStart(); List<LbDestination> destinations = rule.getDestinations(); - if (destinations != null && !destinations.isEmpty()) { - LoadBalancerTO loadBalancer = new LoadBalancerTO(srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies()); + 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()) { + loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup()); + } loadBalancersToApply.add(loadBalancer); } } @@ -731,7 +737,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl } else { if (rules != null) { for (StaticNat rule : rules) { - // validate if EIP rule can be configured. + // validate if EIP rule can be configured. ExternalLoadBalancerDeviceVO lbDevice = getNetScalerForEIP(rule); if (lbDevice == null) { String errMsg = "There is no NetScaler device configured to perform EIP to guest IP address: " + rule.getDestIpAddress(); @@ -777,7 +783,7 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl return lbDeviceVO; } } - } + } } return null; }
