Updated Branches: refs/heads/internallb e665f2aaf -> a7b43c3db
Internal LB - added network-element plugin for internal lb service Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f65573bb Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f65573bb Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f65573bb Branch: refs/heads/internallb Commit: f65573bb74c03d2c0d709f4f576fa1bd129a2eaf Parents: e665f2a Author: Alena Prokharchyk <alena.prokharc...@citrix.com> Authored: Mon Apr 8 16:23:03 2013 -0700 Committer: Alena Prokharchyk <alena.prokharc...@citrix.com> Committed: Mon Apr 8 16:38:16 2013 -0700 ---------------------------------------------------------------------- api/src/com/cloud/network/Network.java | 1 + .../com/cloud/network/router/VirtualRouter.java | 2 +- .../network-elements/internal-loadbalancer/pom.xml | 34 +++ .../element/InternalLoadBalancerElement.java | 203 +++++++++++++++ plugins/pom.xml | 1 + .../network/element/VirtualRouterElement.java | 6 +- 6 files changed, 243 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f65573bb/api/src/com/cloud/network/Network.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index 159274b..9f1e579 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -125,6 +125,7 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I public static final Provider None = new Provider("None", false); // NiciraNvp is not an "External" provider, otherwise we get in trouble with NetworkServiceImpl.providersConfiguredForExternalNetworking public static final Provider NiciraNvp = new Provider("NiciraNvp", false); + public static final Provider InternalLoadBalancerVm = new Provider("InternalLoadBalancerVm", false); private String name; private boolean isExternal; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f65573bb/api/src/com/cloud/network/router/VirtualRouter.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/router/VirtualRouter.java b/api/src/com/cloud/network/router/VirtualRouter.java index d7239dd..59410fa 100755 --- a/api/src/com/cloud/network/router/VirtualRouter.java +++ b/api/src/com/cloud/network/router/VirtualRouter.java @@ -23,7 +23,7 @@ import com.cloud.vm.VirtualMachine; */ public interface VirtualRouter extends VirtualMachine { public enum Role { - VIRTUAL_ROUTER, LB + VIRTUAL_ROUTER, LB, InternalLB } Role getRole(); boolean getIsRedundantRouter(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f65573bb/plugins/network-elements/internal-loadbalancer/pom.xml ---------------------------------------------------------------------- diff --git a/plugins/network-elements/internal-loadbalancer/pom.xml b/plugins/network-elements/internal-loadbalancer/pom.xml new file mode 100644 index 0000000..f3c8b37 --- /dev/null +++ b/plugins/network-elements/internal-loadbalancer/pom.xml @@ -0,0 +1,34 @@ +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <artifactId>cloud-plugin-network-internallb</artifactId> + <name>Apache CloudStack Plugin - Network Internal Load Balancer</name> + <parent> + <groupId>org.apache.cloudstack</groupId> + <artifactId>cloudstack-plugins</artifactId> + <version>4.2.0-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + <build> + <defaultGoal>install</defaultGoal> + <sourceDirectory>src</sourceDirectory> + <testSourceDirectory>test</testSourceDirectory> + </build> +</project> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f65573bb/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/element/InternalLoadBalancerElement.java ---------------------------------------------------------------------- diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/element/InternalLoadBalancerElement.java b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/element/InternalLoadBalancerElement.java new file mode 100644 index 0000000..f55465d --- /dev/null +++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/element/InternalLoadBalancerElement.java @@ -0,0 +1,203 @@ +// 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 org.apache.cloudstack.element; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.ejb.Local; +import javax.inject.Inject; + +import org.apache.log4j.Logger; + +import com.cloud.agent.api.to.LoadBalancerTO; +import com.cloud.deploy.DeployDestination; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network; +import com.cloud.network.Network.Capability; +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; +import com.cloud.network.NetworkModel; +import com.cloud.network.Networks.TrafficType; +import com.cloud.network.PhysicalNetworkServiceProvider; +import com.cloud.network.dao.NetworkServiceMapDao; +import com.cloud.network.element.IpDeployer; +import com.cloud.network.element.LoadBalancingServiceProvider; +import com.cloud.network.element.NetworkElement; +import com.cloud.network.element.VirtualRouterElement; +import com.cloud.network.lb.LoadBalancingRule; +import com.cloud.network.router.VirtualRouter.Role; +import com.cloud.network.rules.LoadBalancerContainer; +import com.cloud.offering.NetworkOffering; +import com.cloud.utils.component.AdapterBase; +import com.cloud.vm.DomainRouterVO; +import com.cloud.vm.NicProfile; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineProfile; +import com.cloud.vm.dao.DomainRouterDao; + +@Local(value = {NetworkElement.class}) +public class InternalLoadBalancerElement extends AdapterBase implements LoadBalancingServiceProvider{ + private static final Logger s_logger = Logger.getLogger(InternalLoadBalancerElement.class); + protected static final Map<Service, Map<Capability, String>> capabilities = setCapabilities(); + + @Inject NetworkModel _ntwkModel; + @Inject NetworkServiceMapDao _ntwkSrvcDao; + @Inject DomainRouterDao _routerDao; + + private boolean canHandle(Network config, List<LoadBalancingRule> rules) { + if (config.getGuestType() != Network.GuestType.Isolated || config.getTrafficType() != TrafficType.Guest) { + s_logger.trace("Not handling network with Type " + config.getGuestType() + " and traffic type " + config.getTrafficType()); + return false; + } + + Map<Capability, String> lbCaps = this.getCapabilities().get(Service.Lb); + if (!lbCaps.isEmpty()) { + String schemeCaps = lbCaps.get(Capability.LbSchemes); + if (schemeCaps != null && rules != null && !rules.isEmpty()) { + for (LoadBalancingRule rule : rules) { + if (!schemeCaps.contains(rule.getScheme().toString())) { + s_logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + this.getName()); + return false; + } + } + } + } + + if (!_ntwkModel.isProviderSupportServiceInNetwork(config.getId(), Service.Lb, getProvider())) { + s_logger.trace("Element " + getProvider().getName() + " doesn't support service " + Service.Lb + + " in the network " + config); + return false; + } + return true; + } + + @Override + public Map<Service, Map<Capability, String>> getCapabilities() { + return capabilities; + } + + @Override + public Provider getProvider() { + return Provider.InternalLoadBalancerVm; + } + + @Override + public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) + throws ConcurrentOperationException, ResourceUnavailableException, + InsufficientCapacityException { + return true; + } + + @Override + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + ResourceUnavailableException, InsufficientCapacityException { + return true; + } + + @Override + public boolean release(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { + return true; + } + + @Override + public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { + // TODO Shutdown all the internal lb elements + return false; + } + + @Override + public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { + // TODO Shutdown all the internal lb elements + return false; + } + + @Override + public boolean isReady(PhysicalNetworkServiceProvider provider) { + // TODO Shutdown all the internal lb elements + return false; + } + + @Override + public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { + // TODO Shutdown all the internal lb elements + return false; + } + + @Override + public boolean canEnableIndividualServices() { + return false; + } + + @Override + public boolean verifyServicesCombination(Set<Service> services) { + return true; + } + + @Override + public IpDeployer getIpDeployer(Network network) { + return null; + } + + @Override + public boolean applyLBRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean validateLBRule(Network network, LoadBalancingRule rule) { + List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>(); + rules.add(rule); + if (canHandle(network, rules)) { + List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.InternalLB); + if (routers == null || routers.isEmpty()) { + return true; + } + return VirtualRouterElement.validateHAProxyLBRule(rule); + } + return true; + } + + @Override + public List<LoadBalancerTO> updateHealthChecks(Network network, List<LoadBalancingRule> lbrules) { + return null; + } + + private static Map<Service, Map<Capability, String>> setCapabilities() { + Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>(); + + // Set capabilities for LB service + Map<Capability, String> lbCapabilities = new HashMap<Capability, String>(); + lbCapabilities.put(Capability.SupportedLBAlgorithms, "roundrobin,leastconn,source"); + lbCapabilities.put(Capability.SupportedLBIsolation, "dedicated"); + lbCapabilities.put(Capability.SupportedProtocols, "tcp, udp"); + lbCapabilities.put(Capability.SupportedStickinessMethods, VirtualRouterElement.getHAProxyStickinessCapability()); + lbCapabilities.put(Capability.LbSchemes, LoadBalancerContainer.Scheme.Internal.toString()); + + capabilities.put(Service.Lb, lbCapabilities); + return capabilities; + } + +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f65573bb/plugins/pom.xml ---------------------------------------------------------------------- diff --git a/plugins/pom.xml b/plugins/pom.xml index 607c50c..763b20b 100755 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -62,6 +62,7 @@ <module>storage/volume/default</module> <module>alert-handlers/snmp-alerts</module> <module>alert-handlers/syslog-alerts</module> + <module>network-elements/internal-loadbalancer</module> </modules> <dependencies> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f65573bb/server/src/com/cloud/network/element/VirtualRouterElement.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index ddb35b6..bf9ac49 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -244,7 +244,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl * number like 12 2) time or tablesize like 12h, 34m, 45k, 54m , here * last character is non-digit but from known characters . */ - private boolean containsOnlyNumbers(String str, String endChar) { + private static boolean containsOnlyNumbers(String str, String endChar) { if (str == null) return false; @@ -273,7 +273,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl return true; } - private boolean validateHAProxyLBRule(LoadBalancingRule rule) { + public static boolean validateHAProxyLBRule(LoadBalancingRule rule) { String timeEndChar = "dhms"; for (LbStickinessPolicy stickinessPolicy : rule.getStickinessPolicies()) { @@ -460,7 +460,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl return capabilities; } - private static String getHAProxyStickinessCapability() { + public static String getHAProxyStickinessCapability() { LbStickinessMethod method; List<LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>(1);