CLOUDSTACK-664:AWS-Health Check feature: Patch applied cleanly , RAT build is successful

This commit is contained in:
Rajesh Battala 2013-03-18 14:01:15 +05:30 committed by Pranav Saxena
parent 99ed891804
commit 183b989d30
40 changed files with 2449 additions and 217 deletions

View File

@ -0,0 +1,42 @@
// 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.agent.api.routing;
import java.util.List;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.agent.api.to.NicTO;
/**
* LoadBalancerConfigCommand sends the load balancer configuration
*/
public class HealthCheckLBConfigAnswer extends Answer {
List<LoadBalancerTO> loadBalancers;
protected HealthCheckLBConfigAnswer() {
}
public HealthCheckLBConfigAnswer(List<LoadBalancerTO> loadBalancers) {
this.loadBalancers = loadBalancers;
}
public List<LoadBalancerTO> getLoadBalancers() {
return loadBalancers;
}
}

View File

@ -0,0 +1,39 @@
// 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.agent.api.routing;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.agent.api.to.NicTO;
/**
* LoadBalancerConfigCommand sends the load balancer configuration
*/
public class HealthCheckLBConfigCommand extends NetworkElementCommand {
LoadBalancerTO[] loadBalancers;
protected HealthCheckLBConfigCommand() {
}
public HealthCheckLBConfigCommand(LoadBalancerTO[] loadBalancers) {
this.loadBalancers = loadBalancers;
}
public LoadBalancerTO[] getLoadBalancers() {
return loadBalancers;
}
}

View File

@ -31,6 +31,7 @@ import com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup;
import com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile;
import com.cloud.network.lb.LoadBalancingRule.LbCondition;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.utils.Pair;
@ -46,8 +47,10 @@ public class LoadBalancerTO {
boolean inline;
DestinationTO[] destinations;
private StickinessPolicyTO[] stickinessPolicies;
private HealthCheckPolicyTO[] healthCheckPolicies;
private AutoScaleVmGroupTO autoScaleVmGroupTO;
final static int MAX_STICKINESS_POLICIES = 1;
final static int MAX_HEALTHCHECK_POLICIES = 1;
public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, boolean inline, List<LbDestination> destinations) {
if (destinations == null) { // for autoscaleconfig destinations will be null;
@ -69,23 +72,52 @@ public class LoadBalancerTO {
}
}
public LoadBalancerTO(String id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, boolean inline, List<LbDestination> arg_destinations, List<LbStickinessPolicy> stickinessPolicies) {
public LoadBalancerTO(String id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked,
boolean alreadyAdded, boolean inline, List<LbDestination> arg_destinations,
List<LbStickinessPolicy> stickinessPolicies) {
this(id, srcIp, srcPort, protocol, algorithm, revoked, alreadyAdded, inline, arg_destinations,
stickinessPolicies, null);
}
public LoadBalancerTO(String id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked,
boolean alreadyAdded, boolean inline, List<LbDestination> arg_destinations,
List<LbStickinessPolicy> stickinessPolicies, List<LbHealthCheckPolicy> healthCheckPolicies) {
this(id, srcIp, srcPort, protocol, algorithm, revoked, alreadyAdded, inline, arg_destinations);
this.stickinessPolicies = null;
this.healthCheckPolicies = null;
if (stickinessPolicies != null && stickinessPolicies.size() > 0) {
this.stickinessPolicies = new StickinessPolicyTO[MAX_STICKINESS_POLICIES];
int index = 0;
for (LbStickinessPolicy stickinesspolicy : stickinessPolicies) {
if (!stickinesspolicy.isRevoked()) {
this.stickinessPolicies[index] = new StickinessPolicyTO(stickinesspolicy.getMethodName(), stickinesspolicy.getParams());
this.stickinessPolicies[index] = new StickinessPolicyTO(stickinesspolicy.getMethodName(),
stickinesspolicy.getParams());
index++;
if (index == MAX_STICKINESS_POLICIES) break;
}
if (index == MAX_STICKINESS_POLICIES)
break;
}
if (index == 0) this.stickinessPolicies = null;
}
if (index == 0)
this.stickinessPolicies = null;
}
if (healthCheckPolicies != null && healthCheckPolicies.size() > 0) {
this.healthCheckPolicies = new HealthCheckPolicyTO[MAX_HEALTHCHECK_POLICIES];
int index = 0;
for (LbHealthCheckPolicy hcp : healthCheckPolicies) {
this.healthCheckPolicies[0] = new HealthCheckPolicyTO(hcp.getpingpath(), hcp.getDescription(),
hcp.getResponseTime(), hcp.getHealthcheckInterval(), hcp.getHealthcheckThresshold(),
hcp.getUnhealthThresshold(), hcp.isRevoked());
index++;
if (index == MAX_HEALTHCHECK_POLICIES)
break;
}
if (index == 0)
this.healthCheckPolicies = null;
}
}
protected LoadBalancerTO() {
}
@ -126,6 +158,10 @@ public class LoadBalancerTO {
return stickinessPolicies;
}
public HealthCheckPolicyTO[] getHealthCheckPolicies() {
return healthCheckPolicies;
}
public DestinationTO[] getDestinations() {
return destinations;
}
@ -158,6 +194,65 @@ public class LoadBalancerTO {
this._methodName = methodName;
this._paramsList = paramsList;
}
}
public static class HealthCheckPolicyTO {
private String pingPath;
private String description;
private int responseTime;
private int healthcheckInterval;
private int healthcheckThresshold;
private int unhealthThresshold;
private boolean revoke = false;
public HealthCheckPolicyTO(String pingPath, String description, int responseTime, int healthcheckInterval,
int healthcheckThresshold, int unhealthThresshold, boolean revoke) {
this.description = description;
this.pingPath = pingPath;
this.responseTime = responseTime;
this.healthcheckInterval = healthcheckInterval;
this.healthcheckThresshold = healthcheckThresshold;
this.unhealthThresshold = unhealthThresshold;
this.revoke = revoke;
}
public HealthCheckPolicyTO() {
}
public String getpingPath() {
return pingPath;
}
public String getDescription() {
return description;
}
public int getResponseTime() {
return responseTime;
}
public int getHealthcheckInterval() {
return healthcheckInterval;
}
public int getHealthcheckThresshold() {
return healthcheckThresshold;
}
public int getUnhealthThresshold() {
return unhealthThresshold;
}
public void setRevoke(boolean revoke) {
this.revoke = revoke;
}
public boolean isRevoked() {
return revoke;
}
}
public static class DestinationTO {
@ -165,6 +260,7 @@ public class LoadBalancerTO {
int destPort;
boolean revoked;
boolean alreadyAdded;
String monitorState;
public DestinationTO(String destIp, int destPort, boolean revoked, boolean alreadyAdded) {
this.destIp = destIp;
this.destPort = destPort;
@ -190,6 +286,14 @@ public class LoadBalancerTO {
public boolean isAlreadyAdded() {
return alreadyAdded;
}
public void setMonitorState(String state) {
this.monitorState = state;
}
public String getMonitorState() {
return monitorState;
}
}
public static class CounterTO implements Serializable {
private final String name;

View File

@ -110,6 +110,8 @@ public class EventTypes {
public static final String EVENT_LOAD_BALANCER_DELETE = "LB.DELETE";
public static final String EVENT_LB_STICKINESSPOLICY_CREATE = "LB.STICKINESSPOLICY.CREATE";
public static final String EVENT_LB_STICKINESSPOLICY_DELETE = "LB.STICKINESSPOLICY.DELETE";
public static final String EVENT_LB_HEALTHCHECKPOLICY_CREATE = "LB.HEALTHCHECKPOLICY.CREATE";
public static final String EVENT_LB_HEALTHCHECKPOLICY_DELETE = "LB.HEALTHCHECKPOLICY.DELETE";
public static final String EVENT_LOAD_BALANCER_UPDATE = "LB.UPDATE";
// Account events

View File

@ -188,6 +188,7 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I
public static final Capability InlineMode = new Capability("InlineMode");
public static final Capability SupportedTrafficDirection = new Capability("SupportedTrafficDirection");
public static final Capability SupportedEgressProtocols = new Capability("SupportedEgressProtocols");
public static final Capability HealthCheckPolicy = new Capability("HealthCheckPolicy");
private String name;

View File

@ -18,6 +18,7 @@ package com.cloud.network.element;
import java.util.List;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.lb.LoadBalancingRule;
@ -25,6 +26,7 @@ import com.cloud.network.lb.LoadBalancingRule;
public interface LoadBalancingServiceProvider extends NetworkElement, IpDeployingRequester {
/**
* Apply rules
*
* @param network
* @param rules
* @return
@ -34,10 +36,14 @@ public interface LoadBalancingServiceProvider extends NetworkElement, IpDeployin
/**
* Validate rules
*
* @param network
* @param rule
* @return true/false. true should be return if there are no validations. false should be return if any oneof the validation fails.
* @return true/false. true should be return if there are no validations.
*false should be return if any oneof the validation fails.
* @throws
*/
boolean validateLBRule(Network network, LoadBalancingRule rule);
List<LoadBalancerTO> updateHealthChecks(Network network, List<LoadBalancingRule> lbrules);
}

View File

@ -32,11 +32,14 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
private List<LbDestination> destinations;
private List<LbStickinessPolicy> stickinessPolicies;
private LbAutoScaleVmGroup autoScaleVmGroup;
private List<LbHealthCheckPolicy> healthCheckPolicies;
public LoadBalancingRule(LoadBalancer lb, List<LbDestination> destinations, List<LbStickinessPolicy> stickinessPolicies) {
public LoadBalancingRule(LoadBalancer lb, List<LbDestination> destinations,
List<LbStickinessPolicy> stickinessPolicies, List<LbHealthCheckPolicy> healthCheckPolicies) {
this.lb = lb;
this.destinations = destinations;
this.stickinessPolicies = stickinessPolicies;
this.healthCheckPolicies = healthCheckPolicies;
}
@Override
@ -136,11 +139,17 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
return stickinessPolicies;
}
public List<LbHealthCheckPolicy> getHealthCheckPolicies() {
return healthCheckPolicies;
}
public interface Destination {
String getIpAddress();
int getDestinationPortStart();
int getDestinationPortEnd();
boolean isRevoked();
}
@ -174,6 +183,64 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
}
}
public static class LbHealthCheckPolicy {
private String pingpath;
private String description;
private int responseTime;
private int healthcheckInterval;
private int healthcheckThresshold;
private int unhealthThresshold;
private boolean _revoke;
public LbHealthCheckPolicy(String pingpath, String description, int responseTime, int healthcheckInterval,
int healthcheckThresshold, int unhealthThresshold) {
this(pingpath, description, responseTime, healthcheckInterval, healthcheckThresshold, unhealthThresshold, false);
}
public LbHealthCheckPolicy(String pingpath, String description, int responseTime, int healthcheckInterval,
int healthcheckThresshold, int unhealthThresshold, boolean revoke) {
this.pingpath = pingpath;
this.description = description;
this.responseTime = responseTime;
this.healthcheckInterval = healthcheckInterval;
this.healthcheckThresshold = healthcheckThresshold;
this.unhealthThresshold = unhealthThresshold;
this._revoke = revoke;
}
public LbHealthCheckPolicy() {
}
public String getpingpath() {
return pingpath;
}
public String getDescription() {
return description;
}
public int getResponseTime() {
return responseTime;
}
public int getHealthcheckInterval() {
return healthcheckInterval;
}
public int getHealthcheckThresshold() {
return healthcheckThresshold;
}
public int getUnhealthThresshold() {
return unhealthThresshold;
}
public boolean isRevoked() {
return _revoke;
}
}
public static class LbDestination implements Destination {
private int portStart;
private int portEnd;
@ -191,10 +258,12 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
public String getIpAddress() {
return ip;
}
@Override
public int getDestinationPortStart() {
return portStart;
}
@Override
public int getDestinationPortEnd() {
return portEnd;
@ -230,15 +299,16 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
return null;
}
@Override
public TrafficType getTrafficType() {
return null;
}
@Override
public FirewallRuleType getType() {
return FirewallRuleType.User;
}
public LbAutoScaleVmGroup getAutoScaleVmGroup() {
return autoScaleVmGroup;
}
@ -274,8 +344,7 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
private final AutoScalePolicy policy;
private boolean revoked;
public LbAutoScalePolicy(AutoScalePolicy policy, List<LbCondition> conditions)
{
public LbAutoScalePolicy(AutoScalePolicy policy, List<LbCondition> conditions) {
this.policy = policy;
this.conditions = conditions;
}
@ -309,7 +378,9 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
private final String networkId;
private final String vmName;
public LbAutoScaleVmProfile(AutoScaleVmProfile profile, String autoScaleUserApiKey, String autoScaleUserSecretKey, String csUrl, String zoneId, String domainId, String serviceOfferingId, String templateId, String vmName, String networkId) {
public LbAutoScaleVmProfile(AutoScaleVmProfile profile, String autoScaleUserApiKey,
String autoScaleUserSecretKey, String csUrl, String zoneId, String domainId, String serviceOfferingId,
String templateId, String vmName, String networkId) {
this.profile = profile;
this.autoScaleUserApiKey = autoScaleUserApiKey;
this.autoScaleUserSecretKey = autoScaleUserSecretKey;
@ -369,7 +440,8 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
private final LbAutoScaleVmProfile profile;
private final String currentState;
public LbAutoScaleVmGroup(AutoScaleVmGroup vmGroup, List<LbAutoScalePolicy> policies, LbAutoScaleVmProfile profile, String currentState) {
public LbAutoScaleVmGroup(AutoScaleVmGroup vmGroup, List<LbAutoScalePolicy> policies,
LbAutoScaleVmProfile profile, String currentState) {
this.vmGroup = vmGroup;
this.policies = policies;
this.profile = profile;

View File

@ -18,8 +18,10 @@ package com.cloud.network.lb;
import java.util.List;
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBHealthCheckPolicyCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLBStickinessPolicyCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLBHealthCheckPoliciesCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLBStickinessPoliciesCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRuleInstancesCmd;
import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRulesCmd;
@ -28,6 +30,8 @@ import org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRul
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.network.rules.HealthCheckPolicy;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.network.rules.StickinessPolicy;
import com.cloud.uservm.UserVm;
@ -66,6 +70,22 @@ public interface LoadBalancingRulesService {
public boolean applyLBStickinessPolicy(CreateLBStickinessPolicyCmd cmd) throws ResourceUnavailableException;
boolean deleteLBStickinessPolicy(long stickinessPolicyId, boolean apply);
/**
* Create a healthcheck policy to a load balancer from the given healthcheck
* parameters in (name,value) pairs.
*
* @param cmd
* the command specifying the stickiness method name, params
* (name,value pairs), policy name and description.
* @return the newly created stickiness policy if successfull, null
* otherwise
* @thows NetworkRuleConflictException
*/
public HealthCheckPolicy createLBHealthCheckPolicy(CreateLBHealthCheckPolicyCmd cmd);
public boolean applyLBHealthCheckPolicy(CreateLBHealthCheckPolicyCmd cmd) throws ResourceUnavailableException;
boolean deleteLBHealthCheckPolicy(long healthCheckPolicyId, boolean apply);
/**
* Assign a virtual machine, or list of virtual machines, to a load balancer.
*/
@ -104,8 +124,18 @@ public interface LoadBalancingRulesService {
*/
List<? extends StickinessPolicy> searchForLBStickinessPolicies(ListLBStickinessPoliciesCmd cmd);
/**
* List healthcheck policies based on the given criteria
*
* @param cmd
* the command specifies the load balancing rule id.
* @return list of healthcheck policies that match the criteria.
*/
List<? extends HealthCheckPolicy> searchForLBHealthCheckPolicies(ListLBHealthCheckPoliciesCmd cmd);
List<LoadBalancingRule> listByNetworkId(long networkId);
LoadBalancer findById(long LoadBalancer);
public void updateLBHealthChecks() throws ResourceUnavailableException;
}

View File

@ -0,0 +1,45 @@
// 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.rules;
import java.util.List;
import com.cloud.utils.Pair;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
/**
*/
public interface HealthCheckPolicy extends InternalIdentity, Identity {
public long getLoadBalancerId();
public String getpingpath();
public String getDescription();
public int getResponseTime();
public int getHealthcheckInterval();
public int getHealthcheckThresshold();
public int getUnhealthThresshold();
public boolean isRevoke();
}

View File

@ -460,6 +460,11 @@ public class ApiConstants {
public static final String UCS_BLADE_ID = "bladeid";
public static final String VM_GUEST_IP = "vmguestip";
public static final String OLDER_THAN = "olderthan";
public static final String HEALTHCHECK_RESPONSE_TIMEOUT = "responsetimeout";
public static final String HEALTHCHECK_INTERVAL_TIME = "intervaltime";
public static final String HEALTHCHECK_HEALTHY_THRESHOLD = "healthythreshold";
public static final String HEALTHCHECK_UNHEALTHY_THRESHOLD = "unhealthythreshold";
public static final String HEALTHCHECK_PINGPATH = "pingpath";
public enum HostDetails {
all, capacity, events, stats, min;

View File

@ -47,6 +47,7 @@ import org.apache.cloudstack.api.response.HypervisorCapabilitiesResponse;
import org.apache.cloudstack.api.response.IPAddressResponse;
import org.apache.cloudstack.api.response.InstanceGroupResponse;
import org.apache.cloudstack.api.response.IpForwardingRuleResponse;
import org.apache.cloudstack.api.response.LBHealthCheckResponse;
import org.apache.cloudstack.api.response.LBStickinessResponse;
import org.apache.cloudstack.api.response.LDAPConfigResponse;
import org.apache.cloudstack.api.response.LoadBalancerResponse;
@ -133,6 +134,7 @@ import com.cloud.network.as.Condition;
import com.cloud.network.as.Counter;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.HealthCheckPolicy;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.network.rules.StaticNatRule;
@ -213,6 +215,11 @@ public interface ResponseGenerator {
LBStickinessResponse createLBStickinessPolicyResponse(StickinessPolicy stickinessPolicy, LoadBalancer lb);
LBHealthCheckResponse createLBHealthCheckPolicyResponse(List<? extends HealthCheckPolicy> healthcheckPolicies,
LoadBalancer lb);
LBHealthCheckResponse createLBHealthCheckPolicyResponse(HealthCheckPolicy healthcheckPolicy, LoadBalancer lb);
PodResponse createPodResponse(Pod pod, Boolean showCapacities);
ZoneResponse createZoneResponse(DataCenter dataCenter, Boolean showCapacities);

View File

@ -0,0 +1,168 @@
// 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.api.command.user.loadbalancer;
import org.apache.cloudstack.api.response.FirewallRuleResponse;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.rules.HealthCheckPolicy;
import org.apache.cloudstack.api.response.LBHealthCheckResponse;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@APICommand(name = "createLBHealthCheckPolicy", description = "Creates a Load Balancer healthcheck policy ", responseObject = LBHealthCheckResponse.class, since="4.2.0")
@SuppressWarnings("rawtypes")
public class CreateLBHealthCheckPolicyCmd extends BaseAsyncCreateCmd {
public static final Logger s_logger = Logger
.getLogger(CreateLBHealthCheckPolicyCmd.class.getName());
private static final String s_name = "createlbhealthcheckpolicyresponse";
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@Parameter(name = ApiConstants.LBID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, required = true, description = "the ID of the load balancer rule")
private Long lbRuleId;
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "the description of the load balancer HealthCheck policy")
private String description;
@Parameter(name = ApiConstants.HEALTHCHECK_PINGPATH, type = CommandType.STRING, required = false, description = "HTTP Ping Path")
private String pingPath;
@Parameter(name = ApiConstants.HEALTHCHECK_RESPONSE_TIMEOUT, type = CommandType.INTEGER, required = false, description = "Time to wait when receiving a response from the health check (2sec - 60 sec)")
private int responsTimeOut;
@Parameter(name = ApiConstants.HEALTHCHECK_INTERVAL_TIME, type = CommandType.INTEGER, required = false, description = "Amount of time between health checks (1 sec - 20940 sec)")
private int healthCheckInterval;
@Parameter(name = ApiConstants.HEALTHCHECK_HEALTHY_THRESHOLD, type = CommandType.INTEGER, required = false, description = "Number of consecutive health check success before declaring an instance healthy")
private int healthyThreshold;
@Parameter(name = ApiConstants.HEALTHCHECK_UNHEALTHY_THRESHOLD, type = CommandType.INTEGER, required = false, description = "Number of consecutive health check failures before declaring an instance unhealthy")
private int unhealthyThreshold;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getLbRuleId() {
return lbRuleId;
}
public String getDescription() {
return description;
}
public String getPingPath() {
return pingPath;
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Account account = UserContext.current().getCaller();
if (account != null) {
return account.getId();
}
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
}
public int getResponsTimeOut() {
return responsTimeOut;
}
public int getHealthCheckInterval() {
return healthCheckInterval;
}
public int getHealthyThreshold() {
return healthyThreshold;
}
public int getUnhealthyThreshold() {
return unhealthyThreshold;
}
@Override
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
HealthCheckPolicy policy = null;
boolean success = false;
try {
UserContext.current().setEventDetails("Load balancer healthcheck policy Id : " + getEntityId());
success = _lbService.applyLBHealthCheckPolicy(this);
if (success) {
// State might be different after the rule is applied, so get new object here
policy = _entityMgr.findById(HealthCheckPolicy.class, getEntityId());
LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
LBHealthCheckResponse hcResponse = _responseGenerator.createLBHealthCheckPolicyResponse(policy, lb);
setResponseObject(hcResponse);
hcResponse.setResponseName(getCommandName());
}
} finally {
if (!success || (policy == null)) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create healthcheck policy ");
}
}
}
@Override
public void create() {
try {
HealthCheckPolicy result = _lbService.createLBHealthCheckPolicy(this);
this.setEntityId(result.getId());
this.setEntityUuid(result.getUuid());
} catch (InvalidParameterValueException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR , e.getMessage());
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_LB_HEALTHCHECKPOLICY_CREATE;
}
@Override
public String getEventDescription() {
return "Create Load Balancer HealthCheck policy";
}
}

View File

@ -0,0 +1,116 @@
// 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.api.command.user.loadbalancer;
import org.apache.cloudstack.api.response.LBHealthCheckResponse;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.rules.HealthCheckPolicy;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@APICommand(name = "deleteLBHealthCheckPolicy", description = "Deletes a load balancer HealthCheck policy.", responseObject = SuccessResponse.class, since="4.2.0")
public class DeleteLBHealthCheckPolicyCmd extends BaseAsyncCmd {
public static final Logger s_logger = Logger.getLogger(DeleteLBHealthCheckPolicyCmd.class.getName());
private static final String s_name = "deletelbhealthcheckpolicyresponse";
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = LBHealthCheckResponse.class,
required = true, description = "the ID of the load balancer HealthCheck policy")
private Long id;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getId() {
return id;
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
Account account = UserContext.current().getCaller();
if (account != null) {
return account.getId();
}
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
}
@Override
public String getEventType() {
return EventTypes.EVENT_LB_HEALTHCHECKPOLICY_DELETE;
}
@Override
public String getEventDescription() {
return "deleting load balancer HealthCheck policy: " + getId();
}
@Override
public void execute() {
UserContext.current().setEventDetails("Load balancer healthcheck policy Id: " + getId());
boolean result = _lbService.deleteLBHealthCheckPolicy(getId() , true);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete load balancer healthcheck policy");
}
}
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
}
@Override
public Long getSyncObjId() {
HealthCheckPolicy policy = _entityMgr.findById(HealthCheckPolicy.class,
getId());
if (policy == null) {
throw new InvalidParameterValueException("Unable to find load balancer healthcheck rule: " + id);
}
LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
if (lb == null) {
throw new InvalidParameterValueException("Unable to find load balancer rule for healthcheck rule: " + id);
}
return lb.getNetworkId();
}
}

View File

@ -0,0 +1,85 @@
// 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.api.command.user.loadbalancer;
import java.util.ArrayList;
import java.util.List;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.response.FirewallRuleResponse;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.LBHealthCheckResponse;
import org.apache.cloudstack.api.response.LBStickinessResponse;
import org.apache.cloudstack.api.response.ListResponse;
import com.cloud.network.rules.HealthCheckPolicy;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
@APICommand(name = "listLBHealthCheckPolicies", description = "Lists load balancer HealthCheck policies.", responseObject = LBHealthCheckResponse.class, since="4.2.0")
public class ListLBHealthCheckPoliciesCmd extends BaseListCmd {
public static final Logger s_logger = Logger
.getLogger(ListLBHealthCheckPoliciesCmd.class.getName());
private static final String s_name = "listlbhealthcheckpoliciesresponse";
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@Parameter(name = ApiConstants.LBID, type = CommandType.UUID, entityType = FirewallRuleResponse.class,
required = true, description = "the ID of the load balancer rule")
private Long lbRuleId;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getLbRuleId() {
return lbRuleId;
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public void execute() {
List<LBHealthCheckResponse> hcpResponses = new ArrayList<LBHealthCheckResponse>();
LoadBalancer lb = _lbService.findById(getLbRuleId());
ListResponse<LBHealthCheckResponse> response = new ListResponse<LBHealthCheckResponse>();
if (lb != null) {
List<? extends HealthCheckPolicy> healthCheckPolicies = _lbService.searchForLBHealthCheckPolicies(this);
LBHealthCheckResponse spResponse = _responseGenerator.createLBHealthCheckPolicyResponse(healthCheckPolicies, lb);
hcpResponses.add(spResponse);
response.setResponses(hcpResponses);
}
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -0,0 +1,98 @@
// 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.api.response;
import com.cloud.network.rules.HealthCheckPolicy;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.BaseResponse;
public class LBHealthCheckPolicyResponse extends BaseResponse {
@SerializedName("id")
@Param(description = "the LB HealthCheck policy ID")
private String id;
@SerializedName("pingpath")
@Param(description = "the pingpath of the healthcheck policy")
private String pingpath;
@SerializedName("description")
@Param(description = "the description of the healthcheck policy")
private String description;
@SerializedName("state")
@Param(description = "the state of the policy")
private String state;
@SerializedName("responsetime")
@Param(description = "Time to wait when receiving a response from the health check")
private int responseTime;
@SerializedName("healthcheckinterval")
@Param(description = "Amount of time between health checks")
private int healthcheckInterval;
@SerializedName("healthcheckthresshold")
@Param(description = "Number of consecutive health check success before declaring an instance healthy")
private int healthcheckthresshold;
@SerializedName("unhealthcheckthresshold")
@Param(description = "Number of consecutive health check failures before declaring an instance unhealthy.")
private int unhealthcheckthresshold;
public void setId(String id) {
this.id = id;
}
public String getpingpath() {
return pingpath;
}
public void setpingpath(String pingpath) {
this.pingpath = pingpath;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public LBHealthCheckPolicyResponse(HealthCheckPolicy healthcheckpolicy) {
if (healthcheckpolicy.isRevoke()) {
this.setState("Revoked");
}
if (healthcheckpolicy.getUuid() != null)
setId(healthcheckpolicy.getUuid());
this.pingpath = healthcheckpolicy.getpingpath();
this.healthcheckInterval = healthcheckpolicy.getHealthcheckInterval();
this.responseTime = healthcheckpolicy.getResponseTime();
this.healthcheckthresshold = healthcheckpolicy.getHealthcheckThresshold();
this.unhealthcheckthresshold = healthcheckpolicy.getUnhealthThresshold();
setObjectName("healthcheckpolicy");
}
}

View File

@ -0,0 +1,102 @@
// 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.api.response;
import com.cloud.network.rules.HealthCheckPolicy;
import org.apache.cloudstack.api.ApiConstants;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;
import java.util.List;
import java.util.UUID;
@EntityReference(value=HealthCheckPolicy.class)
public class LBHealthCheckResponse extends BaseResponse {
@SerializedName("lbruleid")
@Param(description = "the LB rule ID")
private String lbRuleId;
@SerializedName("account")
@Param(description = "the account of the HealthCheck policy")
private String accountName;
@SerializedName(ApiConstants.DOMAIN_ID)
@Param(description = "the domain ID of the HealthCheck policy")
private String domainId;
@SerializedName("domain")
@Param(description = "the domain of the HealthCheck policy")
private String domainName;
@SerializedName(ApiConstants.ZONE_ID)
@Param(description = "the id of the zone the HealthCheck policy belongs to")
private String zoneId;
@SerializedName("healthcheckpolicy")
@Param(description = "the list of healthcheckpolicies", responseObject = LBHealthCheckPolicyResponse.class)
private List<LBHealthCheckPolicyResponse> healthCheckPolicies;
public void setlbRuleId(String lbRuleId) {
this.lbRuleId = lbRuleId;
}
public void setRules(List<LBHealthCheckPolicyResponse> policies) {
this.healthCheckPolicies = policies;
}
public List<LBHealthCheckPolicyResponse> getHealthCheckPolicies() {
return healthCheckPolicies;
}
public void setHealthCheckPolicies(List<LBHealthCheckPolicyResponse> healthCheckPolicies) {
this.healthCheckPolicies = healthCheckPolicies;
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public void setDomainId(String domainId) {
this.domainId = domainId;
}
public void setZoneId(String zoneId) {
this.zoneId = zoneId;
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public LBHealthCheckResponse() {
}
public LBHealthCheckResponse(HealthCheckPolicy healthcheckpolicy) {
setObjectName("healthcheckpolicy");
}
}

View File

@ -151,6 +151,9 @@ createLBStickinessPolicy=15
deleteLBStickinessPolicy=15
listLoadBalancerRules=15
listLBStickinessPolicies=15
listLBHealthCheckPolicies=15
createLBHealthCheckPolicy=15
deleteLBHealthCheckPolicy=15
listLoadBalancerRuleInstances=15
updateLoadBalancerRule=15

View File

@ -155,6 +155,8 @@ under the License.
</adapters>
<manager name="OvsTunnelManager" key="com.cloud.network.ovs.OvsTunnelManager" class="com.cloud.network.ovs.OvsTunnelManagerImpl"/>
<manager name="ElasticLoadBalancerManager" key="com.cloud.network.lb.ElasticLoadBalancerManager" class="com.cloud.network.lb.ElasticLoadBalancerManagerImpl"/>
<manager name="LBHealthCheckManager" key="com.cloud.network.lb.LBHealthCheckManager" class="com.cloud.network.lb.LBHealthCheckManagerImpl"/>
<pluggableservice name="ApiDiscoveryService" key="org.apache.cloudstack.discovery.ApiDiscoveryService" class="org.apache.cloudstack.discovery.ApiDiscoveryServiceImpl"/>
<pluggableservice name="VirtualRouterElementService" key="com.cloud.network.element.VirtualRouterElementService" class="com.cloud.network.element.VirtualRouterElement"/>
<pluggableservice name="NiciraNvpElementService" key="com.cloud.network.element.NiciraNvpElementService" class="com.cloud.network.element.NiciraNvpElement"/>
<dao name="OvsTunnelInterfaceDao" class="com.cloud.network.ovs.dao.OvsTunnelInterfaceDaoImpl" singleton="false"/>

View File

@ -28,6 +28,7 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.deploy.DeployDestination;
@ -197,4 +198,10 @@ public class ElasticLoadBalancerElement extends AdapterBase implements LoadBalan
public IpDeployer getIpDeployer(Network network) {
return this;
}
@Override
public List<LoadBalancerTO> updateHealthChecks(Network network, List<LoadBalancingRule> lbrules) {
return null;
}
}

View File

@ -94,6 +94,7 @@ import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.network.lb.dao.ElasticLbVmMapDao;
import com.cloud.network.router.VirtualRouter;
@ -367,9 +368,10 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
for (LoadBalancerVO lb : lbs) {
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId());
LoadBalancingRule loadBalancing = new LoadBalancingRule(
lb, dstList, policyList);
lbRules.add(loadBalancing);
lb, dstList, policyList, hcPolicyList);
lbRules.add(loadBalancing);
}
return applyLBRules(elbVm, lbRules, network.getId());
} else if (elbVm.getState() == State.Stopped
@ -940,7 +942,8 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
for (LoadBalancerVO lb : lbs) {
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList);
List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId());
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList);
lbRules.add(loadBalancing);
}

View File

@ -29,6 +29,7 @@ import org.apache.cloudstack.api.response.ExternalLoadBalancerResponse;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import org.apache.log4j.Logger;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.commands.AddExternalLoadBalancerCmd;
import com.cloud.api.commands.AddF5LoadBalancerCmd;
@ -496,4 +497,11 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
}
return this;
}
@Override
public List<LoadBalancerTO> updateHealthChecks(Network network,
List<LoadBalancingRule> lbrules) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -292,7 +292,8 @@ StaticNatServiceProvider {
lbCapabilities.put(Capability.SupportedStickinessMethods, stickyMethodList);
lbCapabilities.put(Capability.ElasticLb, "true");
//Setting HealthCheck Capability to True for Netscaler element
lbCapabilities.put(Capability.HealthCheckPolicy, "true");
capabilities.put(Service.Lb, lbCapabilities);
Map<Capability, String> staticNatCapabilities = new HashMap<Capability, String>();
@ -814,4 +815,26 @@ StaticNatServiceProvider {
}
return null;
}
@Override
public List<LoadBalancerTO> updateHealthChecks(Network network, List<LoadBalancingRule> lbrules) {
if (canHandle(network, Service.Lb)) {
try {
return getLBHealthChecks(network, lbrules);
} catch (ResourceUnavailableException e) {
s_logger.error("Error in getting the LB Rules from NetScaler " + e);
}
} else {
s_logger.error("Network cannot handle to LB service ");
}
return null;
}
@Override
public List<LoadBalancerTO> getLBHealthChecks(Network network, List<? extends FirewallRule> rules)
throws ResourceUnavailableException {
return super.getLBHealthChecks(network, rules);
}
}

View File

@ -11,11 +11,12 @@
// 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
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.resource;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.HashMap;
import java.util.List;
@ -31,6 +32,7 @@ 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.service_lbmonitor_binding;
import com.citrix.netscaler.nitro.resource.config.basic.servicegroup;
import com.citrix.netscaler.nitro.resource.config.basic.servicegroup_lbmonitor_binding;
import com.citrix.netscaler.nitro.resource.config.lb.lbmetrictable;
@ -71,6 +73,8 @@ import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupExternalLoadBalancerCommand;
import com.cloud.agent.api.routing.CreateLoadBalancerApplianceCommand;
import com.cloud.agent.api.routing.DestroyLoadBalancerApplianceCommand;
import com.cloud.agent.api.routing.HealthCheckLBConfigAnswer;
import com.cloud.agent.api.routing.HealthCheckLBConfigCommand;
import com.cloud.agent.api.routing.IpAssocAnswer;
import com.cloud.agent.api.routing.IpAssocCommand;
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
@ -84,6 +88,7 @@ import com.cloud.agent.api.to.LoadBalancerTO.AutoScaleVmProfileTO;
import com.cloud.agent.api.to.LoadBalancerTO.ConditionTO;
import com.cloud.agent.api.to.LoadBalancerTO.CounterTO;
import com.cloud.agent.api.to.LoadBalancerTO.DestinationTO;
import com.cloud.agent.api.to.LoadBalancerTO.HealthCheckPolicyTO;
import com.cloud.agent.api.to.LoadBalancerTO.StickinessPolicyTO;
import com.cloud.agent.api.to.StaticNatRuleTO;
import org.apache.cloudstack.api.ApiConstants;
@ -396,12 +401,14 @@ public class NetscalerResource implements ServerResource {
return execute((DestroyLoadBalancerApplianceCommand) cmd, numRetries);
} else if (cmd instanceof SetStaticNatRulesCommand) {
return execute((SetStaticNatRulesCommand) cmd, numRetries);
} else {
} else if (cmd instanceof HealthCheckLBConfigCommand) {
return execute((HealthCheckLBConfigCommand) cmd, numRetries);
}else {
return Answer.createUnsupportedCommandAnswer(cmd);
}
}
private Answer execute(ReadyCommand cmd) {
private Answer execute(ReadyCommand cmd) {
return new ReadyAnswer(cmd);
}
@ -450,6 +457,65 @@ public class NetscalerResource implements ServerResource {
return new IpAssocAnswer(cmd, results);
}
private Answer execute(HealthCheckLBConfigCommand cmd, int numRetries) {
List<LoadBalancerTO> hcLB = new ArrayList<LoadBalancerTO>();
try {
if (_isSdx) {
return Answer.createUnsupportedCommandAnswer(cmd);
}
LoadBalancerTO[] loadBalancers = cmd.getLoadBalancers();
if (loadBalancers == null) {
return new HealthCheckLBConfigAnswer(hcLB);
}
for (LoadBalancerTO loadBalancer : loadBalancers) {
HealthCheckPolicyTO[] healthCheckPolicies = loadBalancer.getHealthCheckPolicies();
if ((healthCheckPolicies != null) && (healthCheckPolicies.length > 0)
&& (healthCheckPolicies[0] != null)) {
String nsVirtualServerName = generateNSVirtualServerName(loadBalancer.getSrcIp(),
loadBalancer.getSrcPort());
com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding[] serviceBindings = com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding
.get(_netscalerService, nsVirtualServerName);
if (serviceBindings != null) {
for (DestinationTO destination : loadBalancer.getDestinations()) {
String nsServiceName = generateNSServiceName(destination.getDestIp(),
destination.getDestPort());
for (com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding binding : serviceBindings) {
if (nsServiceName.equalsIgnoreCase(binding.get_servicename())) {
destination.setMonitorState(binding.get_curstate());
break;
}
}
}
hcLB.add(loadBalancer);
}
}
}
} catch (ExecutionException e) {
s_logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e);
if (shouldRetry(numRetries)) {
return retry(cmd, numRetries);
} else {
return new HealthCheckLBConfigAnswer(hcLB);
}
} catch (Exception e) {
s_logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e);
if (shouldRetry(numRetries)) {
return retry(cmd, numRetries);
} else {
return new HealthCheckLBConfigAnswer(hcLB);
}
}
return new HealthCheckLBConfigAnswer(hcLB);
}
private synchronized Answer execute(LoadBalancerConfigCommand cmd, int numRetries) {
try {
if (_isSdx) {
@ -467,12 +533,13 @@ public class NetscalerResource implements ServerResource {
String lbProtocol = getNetScalerProtocol(loadBalancer);
String lbAlgorithm = loadBalancer.getAlgorithm();
String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort);
String nsMonitorName = generateNSMonitorName(srcIp, srcPort);
if(loadBalancer.isAutoScaleVmGroupTO()) {
applyAutoScaleConfig(loadBalancer);
return new Answer(cmd);
}
boolean hasMonitor = false;
boolean deleteMonitor = false;
boolean destinationsToAdd = false;
for (DestinationTO destination : loadBalancer.getDestinations()) {
if (!destination.isRevoked()) {
@ -489,11 +556,28 @@ public class NetscalerResource implements ServerResource {
s_logger.debug("Created load balancing virtual server " + nsVirtualServerName + " on the Netscaler device");
}
// create a new monitor
HealthCheckPolicyTO[] healthCheckPolicies = loadBalancer.getHealthCheckPolicies();
if ((healthCheckPolicies != null) && (healthCheckPolicies.length > 0)
&& (healthCheckPolicies[0] != null)) {
for (HealthCheckPolicyTO healthCheckPolicyTO : healthCheckPolicies) {
if ( !healthCheckPolicyTO.isRevoked() ) {
addLBMonitor(nsMonitorName, lbProtocol, healthCheckPolicyTO);
hasMonitor = true;
}
else {
deleteMonitor = true;
hasMonitor = false;
}
}
}
for (DestinationTO destination : loadBalancer.getDestinations()) {
String nsServerName = generateNSServerName(destination.getDestIp());
String nsServiceName = generateNSServiceName(destination.getDestIp(), destination.getDestPort());
if (!destination.isRevoked()) {
// add a new destination to deployed load balancing rule
@ -534,6 +618,26 @@ public class NetscalerResource implements ServerResource {
throw new ExecutionException("Failed to bind service: " + nsServiceName + " to the lb virtual server: " + nsVirtualServerName + " on Netscaler device");
}
}
// After binding the service to the LB Vserver
// successfully, bind the created monitor to the
// service.
if (hasMonitor) {
if (!isServiceBoundToMonitor(nsServiceName, nsMonitorName)) {
bindServiceToMonitor(nsServiceName, nsMonitorName);
}
} else {
// check if any monitor created by CS is already
// existing, if yes, unbind it from services and
// delete it.
if (nsMonitorExist(nsMonitorName)) {
// unbind the service from the monitor and
// delete the monitor
unBindServiceToMonitor(nsServiceName, nsMonitorName);
deleteMonitor = true;
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Successfully added LB destination: " + destination.getDestIp() + ":" + destination.getDestPort() + " to load balancer " + srcIp + ":" + srcPort);
}
@ -609,8 +713,13 @@ public class NetscalerResource implements ServerResource {
}
}
removeLBVirtualServer(nsVirtualServerName);
deleteMonitor = true;
}
}
if(deleteMonitor) {
removeLBMonitor(nsMonitorName);
}
}
if (s_logger.isInfoEnabled()) {
@ -1223,23 +1332,64 @@ public class NetscalerResource implements ServerResource {
}
}
private lbmonitor getMonitorIfExisits(String lbMonitorName) throws ExecutionException {
try {
return lbmonitor.get(_netscalerService, lbMonitorName);
} catch (nitro_exception e) {
if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
return null;
} else {
throw new ExecutionException(e.getMessage());
}
} catch (Exception e) {
throw new ExecutionException(e.getMessage());
}
}
private boolean isServiceBoundToVirtualServer(String serviceName) throws ExecutionException {
try {
lbvserver[] lbservers = lbvserver.get(_netscalerService);
for (lbvserver vserver : lbservers) {
filtervalue[] filter = new filtervalue[1];
filter[0] = new filtervalue("servicename", serviceName);
lbvserver_service_binding[] result = lbvserver_service_binding.get_filtered(_netscalerService, vserver.get_name(), filter);
lbvserver_service_binding[] result = lbvserver_service_binding.get_filtered(_netscalerService,
vserver.get_name(), filter);
if (result != null && result.length > 0) {
return true;
}
}
return false;
} catch (Exception e) {
throw new ExecutionException("Failed to verify service " + serviceName + " is bound to any virtual server due to " + e.getMessage());
throw new ExecutionException("Failed to verify service " + serviceName
+ " is bound to any virtual server due to " + e.getMessage());
}
}
private boolean isServiceBoundToMonitor(String nsServiceName, String nsMonitorName) throws ExecutionException {
filtervalue[] filter = new filtervalue[1];
filter[0] = new filtervalue("monitor_name", nsMonitorName);
service_lbmonitor_binding[] result;
try {
result = service_lbmonitor_binding.get_filtered(_netscalerService, nsServiceName, filter);
if (result != null && result.length > 0) {
return true;
}
} catch (Exception e) {
throw new ExecutionException("Failed to verify service " + nsServiceName
+ " is bound to any monitor due to " + e.getMessage());
}
return false;
}
private boolean nsMonitorExist(String nsMonitorname) throws ExecutionException {
if (getMonitorIfExisits(nsMonitorname) != null)
return true;
else
return false;
}
private boolean nsServiceExists(String serviceName) throws ExecutionException {
try {
if (com.citrix.netscaler.nitro.resource.config.basic.service.get(_netscalerService, serviceName) != null) {
@ -1480,6 +1630,126 @@ public class NetscalerResource implements ServerResource {
}
}
// Monitor related methods
private void addLBMonitor(String nsMonitorName, String lbProtocol, HealthCheckPolicyTO hcp)
throws ExecutionException {
try {
// check if the monitor exists
boolean csMonitorExisis = false;
lbmonitor csMonitor = getMonitorIfExisits(nsMonitorName);
if (csMonitor != null) {
if (!csMonitor.get_type().equalsIgnoreCase(lbProtocol)) {
throw new ExecutionException("Can not update monitor :" + nsMonitorName + " as current protocol:"
+ csMonitor.get_type() + " of monitor is different from the " + " intended protocol:"
+ lbProtocol);
}
csMonitorExisis = true;
}
if (!csMonitorExisis) {
lbmonitor csMon = new lbmonitor();
csMon.set_monitorname(nsMonitorName);
csMon.set_type(lbProtocol);
if (lbProtocol.equalsIgnoreCase("HTTP")) {
csMon.set_httprequest(hcp.getpingPath());
s_logger.trace("LB Protocol is HTTP, Applying ping path on HealthCheck Policy");
} else {
s_logger.debug("LB Protocol is not HTTP, Skipping to apply ping path on HealthCheck Policy");
}
csMon.set_interval(hcp.getHealthcheckInterval());
csMon.set_resptimeout(hcp.getResponseTime());
csMon.set_failureretries(hcp.getUnhealthThresshold());
csMon.set_successretries(hcp.getHealthcheckThresshold());
s_logger.debug("Monitor properites going to get created :interval :: " + csMon.get_interval() + "respTimeOUt:: " + csMon.get_resptimeout()
+"failure retires(unhealththresshold) :: " + csMon.get_failureretries() + "successtries(healththresshold) ::" + csMon.get_successretries());
lbmonitor.add(_netscalerService, csMon);
} else {
s_logger.debug("Monitor :" + nsMonitorName + " is already existing. Skipping to delete and create it");
}
} catch (nitro_exception e) {
throw new ExecutionException("Failed to create new monitor :" + nsMonitorName + " due to " + e.getMessage());
} catch (Exception e) {
throw new ExecutionException("Failed to create new monitor :" + nsMonitorName + " due to " + e.getMessage());
}
}
private void bindServiceToMonitor(String nsServiceName, String nsMonitorName) throws ExecutionException {
try {
com.citrix.netscaler.nitro.resource.config.basic.service serviceObject = new com.citrix.netscaler.nitro.resource.config.basic.service();
serviceObject = com.citrix.netscaler.nitro.resource.config.basic.service.get(_netscalerService,
nsServiceName);
if (serviceObject != null) {
com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding serviceMonitor = new com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding();
serviceMonitor.set_monitor_name(nsMonitorName);
serviceMonitor.set_name(nsServiceName);
serviceMonitor.set_monstate("ENABLED");
s_logger.debug("Trying to bind the monitor :" + nsMonitorName + " to the service :" + nsServiceName);
com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding.add(_netscalerService,
serviceMonitor);
s_logger.debug("Successfully binded the monitor :" + nsMonitorName + " to the service :"
+ nsServiceName);
}
} catch (nitro_exception e) {
throw new ExecutionException("Failed to create new monitor :" + nsMonitorName + " due to " + e.getMessage());
} catch (Exception e) {
throw new ExecutionException("Failed to create new monitor :" + nsMonitorName + " due to " + e.getMessage());
}
}
private void unBindServiceToMonitor(String nsServiceName, String nsMonitorName) throws ExecutionException {
try {
com.citrix.netscaler.nitro.resource.config.basic.service serviceObject = new com.citrix.netscaler.nitro.resource.config.basic.service();
serviceObject = com.citrix.netscaler.nitro.resource.config.basic.service.get(_netscalerService,
nsServiceName);
if (serviceObject != null) {
com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding serviceMonitor = new com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding();
serviceMonitor.set_monitor_name(nsMonitorName);
serviceMonitor.set_name(nsServiceName);
s_logger.debug("Trying to unbind the monitor :" + nsMonitorName + " from the service :"
+ nsServiceName);
service_lbmonitor_binding.delete(_netscalerService, serviceMonitor);
s_logger.debug("Successfully unbinded the monitor :" + nsMonitorName + " from the service :"
+ nsServiceName);
}
} catch (nitro_exception e) {
if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
return;
} else {
throw new ExecutionException("Failed to unbind monitor :" + nsMonitorName + "from the service :"
+ nsServiceName + "due to " + e.getMessage());
}
} catch (Exception e) {
throw new ExecutionException("Failed to unbind monitor :" + nsMonitorName + "from the service :"
+ nsServiceName + "due to " + e.getMessage());
}
}
private void removeLBMonitor(String nsMonitorName) throws ExecutionException {
try {
if (nsMonitorExist(nsMonitorName)) {
lbmonitor monitorObj = lbmonitor.get(_netscalerService, nsMonitorName);
monitorObj.set_respcode(null);
lbmonitor.delete(_netscalerService, monitorObj);
s_logger.info("Successfully deleted monitor : " + nsMonitorName);
}
} catch (nitro_exception e) {
if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
return;
} else {
throw new ExecutionException("Failed to delete monitor :" + nsMonitorName + " due to " + e.getMessage());
}
} catch (Exception e) {
throw new ExecutionException("Failed to delete monitor :" + nsMonitorName + " due to " + e.getMessage());
}
}
public synchronized void applyAutoScaleConfig(LoadBalancerTO loadBalancer) throws Exception, ExecutionException {
AutoScaleVmGroupTO vmGroupTO = loadBalancer.getAutoScaleVmGroupTO();
@ -2229,6 +2499,11 @@ public class NetscalerResource implements ServerResource {
return genObjectName("Cloud-VirtualServer", srcIp, srcPort);
}
private String generateNSMonitorName(String srcIp, long srcPort) {
// maximum length supported by NS is 31
return genObjectName("Cloud-Hc", srcIp, srcPort);
}
private String generateNSServerName(String serverIP) {
return genObjectName("Cloud-Server-", serverIP);
}

View File

@ -46,6 +46,8 @@ import org.apache.cloudstack.api.response.ControlledViewEntityResponse;
import org.apache.cloudstack.api.response.IPAddressResponse;
import org.apache.cloudstack.api.response.InstanceGroupResponse;
import org.apache.cloudstack.api.response.IpForwardingRuleResponse;
import org.apache.cloudstack.api.response.LBHealthCheckPolicyResponse;
import org.apache.cloudstack.api.response.LBHealthCheckResponse;
import org.apache.cloudstack.api.response.LBStickinessPolicyResponse;
import org.apache.cloudstack.api.response.LBStickinessResponse;
import org.apache.cloudstack.api.response.LDAPConfigResponse;
@ -143,6 +145,13 @@ import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.*;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.network.rules.HealthCheckPolicy;
import com.cloud.network.rules.LoadBalancer;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.network.rules.StaticNatRule;
import com.cloud.network.rules.StickinessPolicy;
import com.cloud.network.security.SecurityGroup;
import com.cloud.network.security.SecurityGroupVO;
import com.cloud.network.security.SecurityRule;
@ -2750,6 +2759,58 @@ public class ApiResponseHelper implements ResponseGenerator {
return spResponse;
}
@Override
public LBHealthCheckResponse createLBHealthCheckPolicyResponse(
List<? extends HealthCheckPolicy> healthcheckPolicies, LoadBalancer lb) {
LBHealthCheckResponse hcResponse = new LBHealthCheckResponse();
if (lb == null)
return hcResponse;
hcResponse.setlbRuleId(lb.getUuid());
Account account = ApiDBUtils.findAccountById(lb.getAccountId());
if (account != null) {
hcResponse.setAccountName(account.getAccountName());
Domain domain = ApiDBUtils.findDomainById(account.getDomainId());
if (domain != null) {
hcResponse.setDomainId(domain.getUuid());
hcResponse.setDomainName(domain.getName());
}
}
List<LBHealthCheckPolicyResponse> responses = new ArrayList<LBHealthCheckPolicyResponse>();
for (HealthCheckPolicy healthcheckPolicy : healthcheckPolicies) {
LBHealthCheckPolicyResponse ruleResponse = new LBHealthCheckPolicyResponse(healthcheckPolicy);
responses.add(ruleResponse);
}
hcResponse.setRules(responses);
hcResponse.setObjectName("healthcheckpolicies");
return hcResponse;
}
@Override
public LBHealthCheckResponse createLBHealthCheckPolicyResponse(HealthCheckPolicy healthcheckPolicy, LoadBalancer lb) {
LBHealthCheckResponse hcResponse = new LBHealthCheckResponse();
hcResponse.setlbRuleId(lb.getUuid());
Account accountTemp = ApiDBUtils.findAccountById(lb.getAccountId());
if (accountTemp != null) {
hcResponse.setAccountName(accountTemp.getAccountName());
Domain domain = ApiDBUtils.findDomainById(accountTemp.getDomainId());
if (domain != null) {
hcResponse.setDomainId(domain.getUuid());
hcResponse.setDomainName(domain.getName());
}
}
List<LBHealthCheckPolicyResponse> responses = new ArrayList<LBHealthCheckPolicyResponse>();
LBHealthCheckPolicyResponse ruleResponse = new LBHealthCheckPolicyResponse(healthcheckPolicy);
responses.add(ruleResponse);
hcResponse.setRules(responses);
hcResponse.setObjectName("healthcheckpolicies");
return hcResponse;
}
@Override
public LDAPConfigResponse createLDAPConfigResponse(String hostname,
Integer port, Boolean useSSL, String queryFilter,

View File

@ -207,7 +207,11 @@ public enum Config {
AlertPurgeInterval("Advanced", ManagementServer.class, Integer.class, "alert.purge.interval", "86400", "The interval (in seconds) to wait before running the alert purge thread", null),
AlertPurgeDelay("Advanced", ManagementServer.class, Integer.class, "alert.purge.delay", "0", "Alerts older than specified number days will be purged. Set this value to 0 to never delete alerts", null),
DirectAttachNetworkEnabled("Advanced", ManagementServer.class, Boolean.class, "direct.attach.network.externalIpAllocator.enabled", "false", "Direct-attach VMs using external DHCP server", "true,false"),
// LB HealthCheck Interval.
LBHealthCheck("Advanced", ManagementServer.class, String.class, "healthcheck.update.interval", "600",
"Time Interval to fetch the LB health check states (in sec)", null),
DirectAttachNetworkEnabled("Advanced", ManagementServer.class, Boolean.class, "direct.attach.network.externalIpAllocator.enabled", "false", "Direct-attach VMs using external DHCP server", "true,false"),
DirectAttachNetworkExternalAPIURL("Advanced", ManagementServer.class, String.class, "direct.attach.network.externalIpAllocator.url", null, "Direct-attach VMs using external DHCP server (API url)", null),
CheckPodCIDRs("Advanced", ManagementServer.class, String.class, "check.pod.cidrs", "true", "If true, different pods must belong to different CIDR subnets.", "true,false"),
NetworkGcWait("Advanced", ManagementServer.class, Integer.class, "network.gc.wait", "600", "Time (in seconds) to wait before shutting down a network that's not in used", null),

View File

@ -18,6 +18,7 @@ package com.cloud.network;
import java.util.List;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.host.Host;
@ -96,7 +97,9 @@ public interface ExternalLoadBalancerDeviceManager extends Manager{
* @throws ResourceUnavailableException
* @throws InsufficientCapacityException
*/
public boolean manageGuestNetworkWithExternalLoadBalancer(boolean add, Network guestConfig) throws ResourceUnavailableException,
public boolean manageGuestNetworkWithExternalLoadBalancer(boolean add, Network guestConfig) throws ResourceUnavailableException,
InsufficientCapacityException;
public List<LoadBalancerTO> getLBHealthChecks(Network network, List<? extends FirewallRule> rules)
throws ResourceUnavailableException;
}

View File

@ -34,6 +34,8 @@ import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupExternalLoadBalancerCommand;
import com.cloud.agent.api.routing.CreateLoadBalancerApplianceCommand;
import com.cloud.agent.api.routing.DestroyLoadBalancerApplianceCommand;
import com.cloud.agent.api.routing.HealthCheckLBConfigAnswer;
import com.cloud.agent.api.routing.HealthCheckLBConfigCommand;
import com.cloud.agent.api.routing.IpAssocCommand;
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
import com.cloud.agent.api.routing.NetworkElementCommand;
@ -888,7 +890,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) {
boolean inline = _networkMgr.isNetworkInlineMode(network);
LoadBalancerTO loadBalancer = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, rule.getStickinessPolicies());
LoadBalancerTO loadBalancer = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, rule.getStickinessPolicies(), rule.getHealthCheckPolicies());
if (rule.isAutoScaleConfig()) {
loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
}
@ -1111,4 +1113,95 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
s_logger.info("Let " + element.getName() + " handle ip association for " + getName() + " in network " + network.getId());
return (IpDeployer)element;
}
@Override
public List<LoadBalancerTO> getLBHealthChecks(Network network, List<? extends FirewallRule> rules)
throws ResourceUnavailableException {
// Find the external load balancer in this zone
long zoneId = network.getDataCenterId();
DataCenterVO zone = _dcDao.findById(zoneId);
HealthCheckLBConfigAnswer answer = null;
List<LoadBalancingRule> loadBalancingRules = new ArrayList<LoadBalancingRule>();
for (FirewallRule rule : rules) {
if (rule.getPurpose().equals(Purpose.LoadBalancing)) {
loadBalancingRules.add((LoadBalancingRule) rule);
}
}
if (loadBalancingRules == null || loadBalancingRules.isEmpty()) {
return null;
}
ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network);
if (lbDeviceVO == null) {
s_logger.warn("There is no external load balancer device assigned to this network either network is not implement are already shutdown so just returning");
return null;
}
HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
boolean externalLoadBalancerIsInline = _networkMgr.isNetworkInlineMode(network);
if (network.getState() == Network.State.Allocated) {
s_logger.debug("External load balancer was asked to apply LB rules for network with ID " + network.getId()
+ "; this network is not implemented. Skipping backend commands.");
return null;
}
List<LoadBalancerTO> loadBalancersToApply = new ArrayList<LoadBalancerTO>();
List<MappingState> mappingStates = new ArrayList<MappingState>();
for (int i = 0; i < loadBalancingRules.size(); i++) {
LoadBalancingRule rule = loadBalancingRules.get(i);
boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
String protocol = rule.getProtocol();
String algorithm = rule.getAlgorithm();
String uuid = rule.getUuid();
String srcIp = _networkModel.getIp(rule.getSourceIpAddressId()).getAddress().addr();
int srcPort = rule.getSourcePortStart();
List<LbDestination> destinations = rule.getDestinations();
if (externalLoadBalancerIsInline) {
MappingNic nic = getLoadBalancingIpNic(zone, network, rule.getSourceIpAddressId(), revoked, null);
mappingStates.add(nic.getState());
NicVO loadBalancingIpNic = nic.getNic();
if (loadBalancingIpNic == null) {
continue;
}
// Change the source IP address for the load balancing rule to
// be the load balancing IP address
srcIp = loadBalancingIpNic.getIp4Address();
}
if ((destinations != null && !destinations.isEmpty()) || !rule.isAutoScaleConfig()) {
boolean inline = _networkMgr.isNetworkInlineMode(network);
LoadBalancerTO loadBalancer = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked,
false, inline, destinations, rule.getStickinessPolicies(), rule.getHealthCheckPolicies());
loadBalancersToApply.add(loadBalancer);
}
}
try {
if (loadBalancersToApply.size() > 0) {
int numLoadBalancersForCommand = loadBalancersToApply.size();
LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply
.toArray(new LoadBalancerTO[numLoadBalancersForCommand]);
// LoadBalancerConfigCommand cmd = new
// LoadBalancerConfigCommand(loadBalancersForCommand, null);
HealthCheckLBConfigCommand cmd = new HealthCheckLBConfigCommand(loadBalancersForCommand);
long guestVlanTag = Integer.parseInt(network.getBroadcastUri().getHost());
cmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag));
answer = (HealthCheckLBConfigAnswer) _agentMgr.easySend(externalLoadBalancer.getId(), cmd);
}
} catch (Exception ex) {
s_logger.error("Exception Occured ", ex);
}
return answer.getLoadBalancers();
}
}

View File

@ -0,0 +1,157 @@
// 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;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import com.cloud.network.rules.HealthCheckPolicy;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name = ("load_balancer_healthcheck_policies"))
@PrimaryKeyJoinColumn(name = "load_balancer_id", referencedColumnName = "id")
public class LBHealthCheckPolicyVO implements HealthCheckPolicy {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "load_balancer_id")
private long loadBalancerId;
@Column(name = "pingpath")
private String pingPath;
@Column(name = "description")
private String description;
@Column(name = "uuid")
private String uuid;
@Column(name = "response_time")
private int responseTime;
@Column(name = "healthcheck_interval")
private int healthcheckInterval;
@Column(name = "healthcheck_thresshold")
private int healthcheckThresshold;
@Column(name = "unhealth_thresshold")
private int unhealthThresshold;
@Column(name = "revoke")
private boolean revoke = false;
protected LBHealthCheckPolicyVO() {
this.uuid = UUID.randomUUID().toString();
}
public LBHealthCheckPolicyVO(long loadBalancerId, String pingPath, String description, int responseTime,
int healthcheckInterval, int healthcheckThresshold, int unhealthThresshold) {
this.loadBalancerId = loadBalancerId;
if (pingPath == null || pingPath.isEmpty())
this.pingPath = "/";
else
this.pingPath = pingPath;
if (responseTime == 0)
this.responseTime = 2;
else
this.responseTime = responseTime;
if (healthcheckInterval == 0)
this.healthcheckInterval = 5;
else
this.healthcheckInterval = healthcheckInterval;
if (healthcheckThresshold == 0)
this.healthcheckThresshold = 2;
else
this.healthcheckThresshold = healthcheckThresshold;
if (unhealthThresshold == 0)
this.unhealthThresshold = 1;
else
this.unhealthThresshold = unhealthThresshold;
this.uuid = UUID.randomUUID().toString();
}
public int getResponseTime() {
return responseTime;
}
public int getHealthcheckInterval() {
return healthcheckInterval;
}
public int getHealthcheckThresshold() {
return healthcheckThresshold;
}
public int getUnhealthThresshold() {
return unhealthThresshold;
}
public long getId() {
return id;
}
public long getLoadBalancerId() {
return loadBalancerId;
}
public String getpingpath() {
return pingPath;
}
public String getDescription() {
return description;
}
public boolean isRevoke() {
return revoke;
}
public void setRevoke(boolean revoke) {
this.revoke = revoke;
}
@Override
public String getUuid() {
return this.uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

View File

@ -106,6 +106,7 @@ import com.cloud.network.element.UserDataServiceProvider;
import com.cloud.network.guru.NetworkGuru;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.network.rules.*;
@ -2310,52 +2311,51 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
@Override
public boolean applyRules(List<? extends FirewallRule> rules, FirewallRule.Purpose purpose,
NetworkRuleApplier applier, boolean continueOnError) throws ResourceUnavailableException {
if (rules == null || rules.size() == 0) {
s_logger.debug("There are no rules to forward to the network elements");
return true;
}
if (rules == null || rules.size() == 0) {
s_logger.debug("There are no rules to forward to the network elements");
return true;
}
boolean success = true;
Network network = _networksDao.findById(rules.get(0).getNetworkId());
boolean success = true;
Network network = _networksDao.findById(rules.get(0).getNetworkId());
FirewallRuleVO.TrafficType trafficType = rules.get(0).getTrafficType();
List<PublicIp> publicIps = new ArrayList<PublicIp>();
List<PublicIp> publicIps = new ArrayList<PublicIp>();
if (! (rules.get(0).getPurpose() == FirewallRule.Purpose.Firewall && trafficType == FirewallRule.TrafficType.Egress)) {
if (!(rules.get(0).getPurpose() == FirewallRule.Purpose.Firewall && trafficType == FirewallRule.TrafficType.Egress)) {
// get the list of public ip's owned by the network
List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
if (userIps != null && !userIps.isEmpty()) {
for (IPAddressVO userIp : userIps) {
PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
publicIps.add(publicIp);
}
}
PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
publicIps.add(publicIp);
}
}
// rules can not programmed unless IP is associated with network service provider, so run IP assoication for
// the network so as to ensure IP is associated before applying rules (in add state)
applyIpAssociations(network, false, continueOnError, publicIps);
}
try {
applier.applyRules(network, purpose, rules);
} catch (ResourceUnavailableException e) {
if (!continueOnError) {
throw e;
}
s_logger.warn("Problems with applying " + purpose + " rules but pushing on", e);
success = false;
}
if (! (rules.get(0).getPurpose() == FirewallRule.Purpose.Firewall && trafficType == FirewallRule.TrafficType.Egress) ) {
// if all the rules configured on public IP are revoked then dis-associate IP with network service provider
// rules can not programmed unless IP is associated with network
// service provider, so run IP assoication for
// the network so as to ensure IP is associated before applying
// rules (in add state)
applyIpAssociations(network, false, continueOnError, publicIps);
}
try {
applier.applyRules(network, purpose, rules);
} catch (ResourceUnavailableException e) {
if (!continueOnError) {
throw e;
}
s_logger.warn("Problems with applying " + purpose + " rules but pushing on", e);
success = false;
}
if (!(rules.get(0).getPurpose() == FirewallRule.Purpose.Firewall && trafficType == FirewallRule.TrafficType.Egress)) {
// if all the rules configured on public IP are revoked then
// dis-associate IP with network service provider
applyIpAssociations(network, true, continueOnError, publicIps);
}
return success;
return success;
}
public class NetworkGarbageCollector implements Runnable {
@ -3099,13 +3099,14 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
lb.setState(FirewallRule.State.Revoke);
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies (lb.getId());
// mark all destination with revoke state
for (LbDestination dst : dstList) {
s_logger.trace("Marking lb destination " + dst + " with Revoke state");
dst.setRevoked(true);
}
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList);
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList);
lbRules.add(loadBalancing);
}

View File

@ -0,0 +1,35 @@
// 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.dao;
import java.util.List;
import com.cloud.network.LBHealthCheckPolicyVO;
import com.cloud.utils.db.GenericDao;
public interface LBHealthCheckPolicyDao extends
GenericDao<LBHealthCheckPolicyVO, Long> {
void remove(long loadBalancerId);
void remove(long loadBalancerId, Boolean pending);
List<LBHealthCheckPolicyVO> listByLoadBalancerId(long loadBalancerId);
List<LBHealthCheckPolicyVO> listByLoadBalancerId(long loadBalancerId,
boolean revoke);
}

View File

@ -0,0 +1,71 @@
// 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.dao;
import java.util.List;
import javax.ejb.Local;
import org.springframework.stereotype.Component;
import com.cloud.network.LBHealthCheckPolicyVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchCriteria;
@Component
@Local(value = { LBHealthCheckPolicyDao.class })
public class LBHealthCheckPolicyDaoImpl extends
GenericDaoBase<LBHealthCheckPolicyVO, Long> implements
LBHealthCheckPolicyDao {
@Override
public void remove(long loadBalancerId) {
SearchCriteria<LBHealthCheckPolicyVO> sc = createSearchCriteria();
sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
expunge(sc);
}
@Override
public void remove(long loadBalancerId, Boolean revoke) {
SearchCriteria<LBHealthCheckPolicyVO> sc = createSearchCriteria();
sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
sc.addAnd("revoke", SearchCriteria.Op.EQ, revoke);
expunge(sc);
}
@Override
public List<LBHealthCheckPolicyVO> listByLoadBalancerId(long loadBalancerId) {
SearchCriteria<LBHealthCheckPolicyVO> sc = createSearchCriteria();
sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
return listBy(sc);
}
@Override
public List<LBHealthCheckPolicyVO> listByLoadBalancerId(long loadBalancerId,
boolean pending) {
SearchCriteria<LBHealthCheckPolicyVO> sc = createSearchCriteria();
sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
sc.addAnd("revoke", SearchCriteria.Op.EQ, pending);
return listBy(sc);
}
}

View File

@ -39,10 +39,14 @@ public class LoadBalancerVMMapVO implements InternalIdentity {
@Column(name="instance_id")
private long instanceId;
@Column(name="revoke")
@Column(name = "revoke")
private boolean revoke = false;
public LoadBalancerVMMapVO() { }
@Column(name = "state")
private String state;
public LoadBalancerVMMapVO() {
}
public LoadBalancerVMMapVO(long loadBalancerId, long instanceId) {
this.loadBalancerId = loadBalancerId;
@ -74,4 +78,12 @@ public class LoadBalancerVMMapVO implements InternalIdentity {
public void setRevoke(boolean revoke) {
this.revoke = revoke;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
}

View File

@ -31,6 +31,7 @@ import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElement
import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
import org.apache.log4j.Logger;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenter;
@ -363,7 +364,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
return true;
}
} else {
return true;
return false;
}
}
@ -938,4 +939,11 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
protected VirtualRouterProviderType getVirtualRouterProvider() {
return VirtualRouterProviderType.VirtualRouter;
}
@Override
public List<LoadBalancerTO> updateHealthChecks(Network network,
List<LoadBalancingRule> lbrules) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,24 @@
// 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.lb;
public interface LBHealthCheckManager {
void updateLBHealthCheck();
}

View File

@ -0,0 +1,110 @@
// 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.lb;
import static java.lang.String.format;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.Manager;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory;
@Component
@Local(value = {LBHealthCheckManager.class})
public class LBHealthCheckManagerImpl extends ManagerBase implements LBHealthCheckManager, Manager {
private static final Logger s_logger = Logger.getLogger(LBHealthCheckManagerImpl.class);
@Inject
ConfigurationDao _configDao;
@Inject
LoadBalancingRulesService _lbService;
private String name;
private Map<String, String> _configs;
ScheduledExecutorService _executor;
private long _interval;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_configs = _configDao.getConfiguration("management-server", params);
if (s_logger.isInfoEnabled()) {
s_logger.info(format("Configuring LBHealthCheck Manager %1$s", name));
}
this.name = name;
_interval = NumbersUtil.parseLong(_configs.get(Config.LBHealthCheck.key()), 600);
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("LBHealthCheck"));
return true;
}
@Override
public boolean start() {
s_logger.debug("LB HealthCheckmanager is getting Started");
_executor.scheduleAtFixedRate(new UpdateLBHealthCheck(), 10, _interval, TimeUnit.SECONDS);
return true;
}
@Override
public boolean stop() {
s_logger.debug("HealthCheckmanager is getting Stopped");
_executor.shutdown();
return true;
}
@Override
public String getName() {
return this.name;
}
protected class UpdateLBHealthCheck implements Runnable {
@Override
public void run() {
try {
updateLBHealthCheck();
} catch (Exception e) {
s_logger.error("Exception in LB HealthCheck Update Checker", e);
}
}
}
@Override
public void updateLBHealthCheck() {
try {
_lbService.updateLBHealthChecks();
} catch (ResourceUnavailableException e) {
s_logger.debug("Error while updating the LB HealtCheck ", e);
}
s_logger.debug("LB HealthCheck Manager is running and getting the updates from LB providers and updating service status");
}
}

View File

@ -20,6 +20,7 @@ import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.LbStickinessMethod;
@ -38,6 +39,7 @@ public interface LoadBalancingRulesManager extends LoadBalancingRulesService {
List<LbDestination> getExistingDestinations(long lbId);
List<LbStickinessPolicy> getStickinessPolicies(long lbId);
List<LbStickinessMethod> getStickinessMethods(long networkid);
List<LbHealthCheckPolicy> getHealthCheckPolicies(long lbId);
/**
* Remove vm from all load balancers

View File

@ -167,6 +167,7 @@ import com.cloud.network.dao.VirtualRouterProviderDao;
import com.cloud.network.dao.VpnUserDao;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy;
import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.network.router.VirtualRouter.RedundantState;
@ -2382,11 +2383,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
for (LoadBalancerVO lb : lbs) {
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList);
List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId());
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList);
lbRules.add(loadBalancing);
}
}
s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of domR " + router + " start.");
if (!lbRules.isEmpty()) {
createApplyLoadBalancingRulesCommands(lbRules, router, cmds, guestNetworkId);
@ -3284,7 +3286,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
for (LoadBalancerVO lb : lbs) {
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList,policyList);
List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId() );
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList);
lbRules.add(loadBalancing);
}
return sendLBRules(router, lbRules, network.getId());

View File

@ -2103,10 +2103,13 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
cmdList.add(QueryAsyncJobResultCmd.class);
cmdList.add(AssignToLoadBalancerRuleCmd.class);
cmdList.add(CreateLBStickinessPolicyCmd.class);
cmdList.add(CreateLBHealthCheckPolicyCmd .class);
cmdList.add(CreateLoadBalancerRuleCmd.class);
cmdList.add(DeleteLBStickinessPolicyCmd.class);
cmdList.add(DeleteLBHealthCheckPolicyCmd .class);
cmdList.add(DeleteLoadBalancerRuleCmd.class);
cmdList.add(ListLBStickinessPoliciesCmd.class);
cmdList.add(ListLBHealthCheckPoliciesCmd .class);
cmdList.add(ListLoadBalancerRuleInstancesCmd.class);
cmdList.add(ListLoadBalancerRulesCmd.class);
cmdList.add(RemoveFromLoadBalancerRuleCmd.class);

View File

@ -27,6 +27,7 @@ UPDATE `cloud`.`hypervisor_capabilities` SET `max_hosts_per_cluster`=32 WHERE `h
INSERT IGNORE INTO `cloud`.`hypervisor_capabilities`(hypervisor_type, hypervisor_version, max_guests_limit, security_group_enabled, max_hosts_per_cluster) VALUES ('VMware', '5.1', 128, 0, 32);
DELETE FROM `cloud`.`configuration` where name='vmware.percluster.host.max';
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'AgentManager', 'xen.nics.max', '7', 'Maximum allowed nics for Vms created on Xen');
ALTER TABLE `cloud`.`load_balancer_vm_map` ADD state VARCHAR(40) NULL COMMENT 'service status updated by LB healthcheck manager';
alter table template_host_ref add state varchar(255);
alter table template_host_ref add update_count bigint unsigned;
@ -97,6 +98,21 @@ CREATE TABLE `vpc_service_map` (
UNIQUE (`vpc_id`, `service`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`load_balancer_healthcheck_policies` (
`id` bigint(20) NOT NULL auto_increment,
`uuid` varchar(40),
`load_balancer_id` bigint unsigned NOT NULL,
`pingpath` varchar(225) NULL DEFAULT '/',
`description` varchar(4096) NULL,
`response_time` int(11) DEFAULT 5,
`healthcheck_interval` int(11) DEFAULT 5,
`healthcheck_thresshold` int(11) DEFAULT 2,
`unhealth_thresshold` int(11) DEFAULT 10,
`revoke` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 is when rule is set for Revoke',
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`),
CONSTRAINT `fk_load_balancer_healthcheck_policies_loadbalancer_id` FOREIGN KEY(`load_balancer_id`) REFERENCES `load_balancing_rules`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'vm.instancename.flag', 'false', 'Append guest VM display Name (if set) to the internal name of the VM');