mirror of https://github.com/apache/cloudstack.git
Internal LB - added network-element plugin for internal lb service
This commit is contained in:
parent
76325e6168
commit
3588f46848
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue