mirror of https://github.com/apache/cloudstack.git
InternalLB: implemented list/delete/create web services API commands that will be used for Internal LB creation
This commit is contained in:
parent
9ab31e11f7
commit
34bcb2d026
|
|
@ -101,6 +101,7 @@ import org.apache.cloudstack.api.response.VpcOfferingResponse;
|
|||
import org.apache.cloudstack.api.response.VpcResponse;
|
||||
import org.apache.cloudstack.api.response.VpnUsersResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
|
||||
import org.apache.cloudstack.region.Region;
|
||||
import org.apache.cloudstack.usage.Usage;
|
||||
|
||||
|
|
@ -396,5 +397,5 @@ public interface ResponseGenerator {
|
|||
Long nicId, Long networkId);
|
||||
public NicResponse createNicResponse(Nic result);
|
||||
|
||||
ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(LoadBalancer lb, Map<Ip, UserVm> lbInstances);
|
||||
ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb, Map<Ip, UserVm> lbInstances);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import org.apache.cloudstack.api.ServerApiException;
|
|||
import org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.NetworkResponse;
|
||||
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.async.AsyncJob;
|
||||
|
|
@ -36,7 +37,6 @@ import com.cloud.exception.ResourceAllocationException;
|
|||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.rules.LoadBalancer;
|
||||
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
|
@ -73,7 +73,8 @@ public class CreateApplicationLoadBalancerCmd extends BaseAsyncCreateCmd {
|
|||
@Parameter(name=ApiConstants.SOURCE_IP, type=CommandType.STRING, description="the source ip address the network traffic will be load balanced from")
|
||||
private String sourceIp;
|
||||
|
||||
@Parameter(name=ApiConstants.SOURCE_IP_NETWORK_ID, type=CommandType.LONG, required=true, description="the network id of the source ip address")
|
||||
@Parameter(name=ApiConstants.SOURCE_IP_NETWORK_ID, type=CommandType.UUID, entityType = NetworkResponse.class, required=true,
|
||||
description="the network id of the source ip address")
|
||||
private Long sourceIpNetworkId;
|
||||
|
||||
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the load balancer." +
|
||||
|
|
@ -109,7 +110,6 @@ public class CreateApplicationLoadBalancerCmd extends BaseAsyncCreateCmd {
|
|||
return instancePort;
|
||||
}
|
||||
|
||||
|
||||
public long getNetworkId() {
|
||||
return networkId;
|
||||
}
|
||||
|
|
@ -184,7 +184,7 @@ public class CreateApplicationLoadBalancerCmd extends BaseAsyncCreateCmd {
|
|||
if (scheme.equalsIgnoreCase(Scheme.Internal.toString())) {
|
||||
return Scheme.Internal;
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Invalid value for sheme. Supported value is Internal");
|
||||
throw new InvalidParameterValueException("Invalid value for scheme. Supported value is Internal");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -203,11 +203,11 @@ public class CreateApplicationLoadBalancerCmd extends BaseAsyncCreateCmd {
|
|||
|
||||
@Override
|
||||
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
|
||||
LoadBalancer rule = null;
|
||||
ApplicationLoadBalancerRule rule = null;
|
||||
try {
|
||||
UserContext.current().setEventDetails("Load Balancer Id: " + getEntityId());
|
||||
// State might be different after the rule is applied, so get new object here
|
||||
rule = _entityMgr.findById(LoadBalancer.class, getEntityId());
|
||||
rule = _entityMgr.findById(ApplicationLoadBalancerRule.class, getEntityId());
|
||||
ApplicationLoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerContainerReponse(rule, _lbService.getLbInstances(getEntityId()));
|
||||
setResponseObject(lbResponse);
|
||||
lbResponse.setResponseName(getCommandName());
|
||||
|
|
@ -224,8 +224,8 @@ public class CreateApplicationLoadBalancerCmd extends BaseAsyncCreateCmd {
|
|||
public void create() {
|
||||
try {
|
||||
|
||||
LoadBalancer result = _appLbService.createApplicationLoadBalancer(getName(), getDescription(), getScheme(), getSourceIpNetworkId(), getSourceIp(), getSourcePort(),
|
||||
getInstancePort(), getAlgorithm(), getNetworkId(), getEntityOwnerId());
|
||||
ApplicationLoadBalancerRule result = _appLbService.createApplicationLoadBalancer(getName(), getDescription(), getScheme(),
|
||||
getSourceIpNetworkId(), getSourceIp(), getSourcePort(), getInstancePort(), getAlgorithm(), getNetworkId(), getEntityOwnerId());
|
||||
this.setEntityId(result.getId());
|
||||
this.setEntityUuid(result.getUuid());
|
||||
}catch (NetworkRuleConflictException e) {
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ import org.apache.cloudstack.api.Parameter;
|
|||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.FirewallRuleResponse;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.async.AsyncJob;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.network.rules.LoadBalancer;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@APICommand(name = "deleteLoadBalancer", description="Deletes a load balancer", responseObject=SuccessResponse.class)
|
||||
|
|
@ -64,7 +64,7 @@ public class DeleteApplicationLoadBalancerCmd extends BaseAsyncCmd {
|
|||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
LoadBalancer lb = _entityMgr.findById(LoadBalancer.class, getId());
|
||||
ApplicationLoadBalancerRule lb = _entityMgr.findById(ApplicationLoadBalancerRule.class, getId());
|
||||
if (lb != null) {
|
||||
return lb.getAccountId();
|
||||
} else {
|
||||
|
|
@ -102,7 +102,7 @@ public class DeleteApplicationLoadBalancerCmd extends BaseAsyncCmd {
|
|||
|
||||
@Override
|
||||
public Long getSyncObjId() {
|
||||
LoadBalancer lb = _lbService.findById(id);
|
||||
ApplicationLoadBalancerRule lb = _appLbService.findById(id);
|
||||
if(lb == null){
|
||||
throw new InvalidParameterValueException("Unable to find load balancer by id ");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,14 +26,17 @@ import org.apache.cloudstack.api.Parameter;
|
|||
import org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse;
|
||||
import org.apache.cloudstack.api.response.FirewallRuleResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.NetworkResponse;
|
||||
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.network.rules.ApplicationLoadBalancerRule;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
@APICommand(name = "listLoadBalancers", description = "Lists Load Balancers", responseObject = ApplicationLoadBalancerResponse.class)
|
||||
public class ListApplicationLoadBalancersCmd extends BaseListTaggedResourcesCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListLoadBalancerRulesCmd.class.getName());
|
||||
public static final Logger s_logger = Logger.getLogger(ListApplicationLoadBalancersCmd.class.getName());
|
||||
|
||||
private static final String s_name = "listloadbalancerssresponse";
|
||||
|
||||
|
|
@ -47,6 +50,20 @@ public class ListApplicationLoadBalancersCmd extends BaseListTaggedResourcesCmd
|
|||
|
||||
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the Load Balancer")
|
||||
private String loadBalancerName;
|
||||
|
||||
@Parameter(name = ApiConstants.SOURCE_IP, type = CommandType.STRING, description = "the source ip address of the Load Balancer")
|
||||
private String sourceIp;
|
||||
|
||||
@Parameter(name=ApiConstants.SOURCE_IP_NETWORK_ID, type=CommandType.UUID, entityType = NetworkResponse.class,
|
||||
description="the network id of the source ip address")
|
||||
private Long sourceIpNetworkId;
|
||||
|
||||
@Parameter(name = ApiConstants.SCHEME, type = CommandType.STRING, description = "the scheme of the Load Balancer. Supported value is Internal in the current release")
|
||||
private String scheme;
|
||||
|
||||
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.UUID, entityType = NetworkResponse.class,
|
||||
description="the network id of the Load Balancer")
|
||||
private Long networkId;
|
||||
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
|
|
@ -61,19 +78,44 @@ public class ListApplicationLoadBalancersCmd extends BaseListTaggedResourcesCmd
|
|||
return loadBalancerName;
|
||||
}
|
||||
|
||||
public String getLoadBalancerName() {
|
||||
return loadBalancerName;
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
public String getSourceIp() {
|
||||
return sourceIp;
|
||||
}
|
||||
|
||||
public Long getSourceIpNetworkId() {
|
||||
return sourceIpNetworkId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
public Scheme getScheme() {
|
||||
if (scheme != null) {
|
||||
if (scheme.equalsIgnoreCase(Scheme.Internal.toString())) {
|
||||
return Scheme.Internal;
|
||||
} else {
|
||||
throw new InvalidParameterValueException("Invalid value for scheme. Supported value is Internal");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Long getNetworkId() {
|
||||
return networkId;
|
||||
}
|
||||
// ///////////////////////////////////////////////////
|
||||
// ///////////// API Implementation///////////////////
|
||||
// ///////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
Pair<List<? extends ApplicationLoadBalancerRule>, Integer> loadBalancers = _appLbService.listApplicationLoadBalancers();
|
||||
Pair<List<? extends ApplicationLoadBalancerRule>, Integer> loadBalancers = _appLbService.listApplicationLoadBalancers(this);
|
||||
ListResponse<ApplicationLoadBalancerResponse> response = new ListResponse<ApplicationLoadBalancerResponse>();
|
||||
List<ApplicationLoadBalancerResponse> lbResponses = new ArrayList<ApplicationLoadBalancerResponse>();
|
||||
for (ApplicationLoadBalancerRule loadBalancer : loadBalancers.first()) {
|
||||
|
|
|
|||
|
|
@ -14,14 +14,15 @@
|
|||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.network.rules;
|
||||
package org.apache.cloudstack.network.lb;
|
||||
|
||||
import com.cloud.network.rules.LoadBalancerContainer;
|
||||
import com.cloud.utils.net.Ip;
|
||||
|
||||
public interface ApplicationLoadBalancerContainer extends LoadBalancerContainer{
|
||||
|
||||
public String getSourceIpNetworkUuid();
|
||||
public Long getSourceIpNetworkId();
|
||||
|
||||
public Ip getSourceIpAddress();
|
||||
public Ip getSourceIp();
|
||||
|
||||
}
|
||||
|
|
@ -15,7 +15,9 @@
|
|||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package com.cloud.network.rules;
|
||||
package org.apache.cloudstack.network.lb;
|
||||
|
||||
import com.cloud.network.rules.LoadBalancer;
|
||||
|
||||
public interface ApplicationLoadBalancerRule extends ApplicationLoadBalancerContainer, LoadBalancer{
|
||||
int getInstancePort();
|
||||
|
|
@ -19,9 +19,10 @@ package org.apache.cloudstack.network.lb;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.ListApplicationLoadBalancersCmd;
|
||||
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
import com.cloud.network.rules.ApplicationLoadBalancerRule;
|
||||
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
|
|
@ -33,6 +34,8 @@ public interface ApplicationLoadBalancerService {
|
|||
|
||||
boolean deleteApplicationLoadBalancer(long id);
|
||||
|
||||
Pair<List<? extends ApplicationLoadBalancerRule>, Integer> listApplicationLoadBalancers();
|
||||
Pair<List<? extends ApplicationLoadBalancerRule>, Integer> listApplicationLoadBalancers(ListApplicationLoadBalancersCmd cmd);
|
||||
|
||||
ApplicationLoadBalancerRule findById(long ruleId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -364,6 +364,8 @@
|
|||
<bean id="vpcOfferingServiceMapDaoImpl" class="com.cloud.network.vpc.dao.VpcOfferingServiceMapDaoImpl" />
|
||||
<bean id="vpcServiceMapDaoImpl" class="com.cloud.network.vpc.dao.VpcServiceMapDaoImpl" />
|
||||
<bean id="vpnUserDaoImpl" class="com.cloud.network.dao.VpnUserDaoImpl" />
|
||||
<bean id="applicationLbRuleDaoImpl" class="org.apache.cloudstack.network.lb.dao.ApplicationLoadBalancerRuleDaoImpl" />
|
||||
|
||||
|
||||
<!--
|
||||
Checkers
|
||||
|
|
|
|||
|
|
@ -656,8 +656,8 @@ ElasticLoadBalancerManager, VirtualMachineGuru<DomainRouterVO> {
|
|||
lb.setSourceIpAddressId(ipId);
|
||||
|
||||
result = _lbMgr.createPublicLoadBalancer(lb.getXid(), lb.getName(), lb.getDescription(),
|
||||
lb.getSourcePortStart(), lb.getSourcePortEnd(), lb.getDefaultPortStart(), ipId.longValue(),
|
||||
lb.getProtocol(), lb.getAlgorithm(), false, UserContext.current());
|
||||
lb.getSourcePortStart(), lb.getDefaultPortStart(), ipId.longValue(), lb.getProtocol(),
|
||||
lb.getAlgorithm(), false, UserContext.current());
|
||||
} catch (NetworkRuleConflictException e) {
|
||||
s_logger.warn("Failed to create LB rule, not continuing with ELB deployment");
|
||||
if (newIp) {
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import org.apache.cloudstack.api.response.UserResponse;
|
|||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.network.lb.dao.ApplicationLoadBalancerRuleDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -483,6 +484,7 @@ public class ApiDBUtils {
|
|||
@Inject private VMSnapshotDao vmSnapshotDao;
|
||||
@Inject private NicSecondaryIpDao nicSecondaryIpDao;
|
||||
@Inject private VpcProvisioningService vpcProvSvc;
|
||||
@Inject private ApplicationLoadBalancerRuleDao _appLbDao;
|
||||
@PostConstruct
|
||||
void init() {
|
||||
_ms = ms;
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ import org.apache.cloudstack.api.response.VpcOfferingResponse;
|
|||
import org.apache.cloudstack.api.response.VpcResponse;
|
||||
import org.apache.cloudstack.api.response.VpnUsersResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
|
||||
import org.apache.cloudstack.region.Region;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.usage.Usage;
|
||||
|
|
@ -207,7 +208,6 @@ import com.cloud.network.dao.IPAddressVO;
|
|||
import com.cloud.network.dao.NetworkVO;
|
||||
import com.cloud.network.dao.PhysicalNetworkVO;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.rules.ApplicationLoadBalancerRule;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.FirewallRuleVO;
|
||||
import com.cloud.network.rules.HealthCheckPolicy;
|
||||
|
|
@ -3628,7 +3628,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(LoadBalancer lb, Map<Ip, UserVm> lbInstances) {
|
||||
public ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb, Map<Ip, UserVm> lbInstances) {
|
||||
|
||||
ApplicationLoadBalancerResponse lbResponse = new ApplicationLoadBalancerResponse();
|
||||
lbResponse.setId(lb.getUuid());
|
||||
|
|
@ -3640,9 +3640,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
populateOwner(lbResponse, lb);
|
||||
|
||||
if (lb.getScheme() == Scheme.Internal) {
|
||||
ApplicationLoadBalancerRule ruleInternal = (ApplicationLoadBalancerRule)lb;
|
||||
lbResponse.setSourceIp(ruleInternal.getSourceIpAddress().addr());
|
||||
lbResponse.setSourceIpNetworkId(ruleInternal.getSourceIpNetworkUuid());
|
||||
lbResponse.setSourceIp(lb.getSourceIp().addr());
|
||||
//TODO - create the view for the load balancer rule to reflect the network uuid
|
||||
Network network = ApiDBUtils.findNetworkById(lb.getNetworkId());
|
||||
lbResponse.setSourceIpNetworkId(network.getUuid());
|
||||
} else {
|
||||
//for public, populate the ip information from the ip address
|
||||
IpAddress publicIp = ApiDBUtils.findIpAddressById(lb.getSourceIpAddressId());
|
||||
|
|
|
|||
|
|
@ -1,78 +0,0 @@
|
|||
// 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 javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.cloud.network.rules.ApplicationLoadBalancerRule;
|
||||
import com.cloud.utils.net.Ip;
|
||||
|
||||
/**
|
||||
* This VO represent Internal Load Balancer rule.
|
||||
* Instead of pointing to the public ip address id directly as External Load Balancer rule does, it refers to the ip address by its value/sourceNetworkid
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name=("load_balancing_rules"))
|
||||
@DiscriminatorValue(value="LoadBalancing")
|
||||
@PrimaryKeyJoinColumn(name="id")
|
||||
public class ApplicationLoadBalancerRuleVO extends LoadBalancerVO implements ApplicationLoadBalancerRule{
|
||||
|
||||
|
||||
@Column(name="source_ip_address_network_id")
|
||||
String sourceIpNetworkUuid;
|
||||
|
||||
@Id
|
||||
@Column(name="source_ip_address")
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
private Ip sourceIpAddress = null;
|
||||
|
||||
|
||||
public ApplicationLoadBalancerRuleVO() {
|
||||
}
|
||||
|
||||
public ApplicationLoadBalancerRuleVO(String xId, String name, String description, int srcPort, int dstPort, String algorithm, long networkId,
|
||||
long accountId, long domainId, Ip sourceIp, String sourceIpNtwkUuid) {
|
||||
|
||||
super(xId, name, description, srcPort, dstPort, algorithm, networkId, accountId, domainId);
|
||||
this.sourceIpAddress = sourceIp;
|
||||
this.sourceIpNetworkUuid = sourceIpNtwkUuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceIpNetworkUuid() {
|
||||
return sourceIpNetworkUuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ip getSourceIpAddress() {
|
||||
return sourceIpAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstancePort() {
|
||||
return super.getDefaultPortStart();
|
||||
}
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ public class LoadBalancerVO extends FirewallRuleVO implements LoadBalancer {
|
|||
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
@Column(name="scheme")
|
||||
Scheme scheme;
|
||||
Scheme scheme = Scheme.Public;
|
||||
|
||||
public LoadBalancerVO() {
|
||||
}
|
||||
|
|
@ -72,18 +72,6 @@ public class LoadBalancerVO extends FirewallRuleVO implements LoadBalancer {
|
|||
this.scheme = Scheme.Public;
|
||||
}
|
||||
|
||||
|
||||
protected LoadBalancerVO(String xId, String name, String description, int srcPort, int dstPort, String algorithm, long networkId, long accountId, long domainId) {
|
||||
super(xId, null, srcPort, dstPort, NetUtils.TCP_PROTO, networkId, accountId, domainId, Purpose.LoadBalancing, null, null,
|
||||
null, null, null);
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.algorithm = algorithm;
|
||||
this.defaultPortStart = dstPort;
|
||||
this.defaultPortEnd = dstPort;
|
||||
this.scheme = Scheme.Internal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import com.cloud.user.UserContext;
|
|||
public interface LoadBalancingRulesManager extends LoadBalancingRulesService {
|
||||
|
||||
LoadBalancer createPublicLoadBalancer(String xId, String name, String description,
|
||||
int srcPortStart, int srcPortEnd, int defPortStart, long sourceIpId, String protocol, String algorithm, boolean openFirewall, UserContext caller)
|
||||
int srcPort, int destPort, long sourceIpId, String protocol, String algorithm, boolean openFirewall, UserContext caller)
|
||||
throws NetworkRuleConflictException;
|
||||
|
||||
boolean removeAllLoadBalanacersForIp(long ipId, Account caller, long callerUserId);
|
||||
|
|
@ -51,4 +51,8 @@ public interface LoadBalancingRulesManager extends LoadBalancingRulesService {
|
|||
String getLBCapability(long networkid, String capabilityName);
|
||||
boolean configureLbAutoScaleVmGroup(long vmGroupid, String currentState) throws ResourceUnavailableException;
|
||||
boolean revokeLoadBalancersForNetwork(long networkId) throws ResourceUnavailableException;
|
||||
|
||||
boolean validateLbRule(LoadBalancingRule lbRule);
|
||||
|
||||
void removeLBRule(LoadBalancer rule);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRuleI
|
|||
import org.apache.cloudstack.api.command.user.loadbalancer.ListLoadBalancerRulesCmd;
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRuleCmd;
|
||||
import org.apache.cloudstack.api.response.ServiceResponse;
|
||||
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRuleVO;
|
||||
import org.apache.cloudstack.network.lb.dao.ApplicationLoadBalancerRuleDao;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -241,6 +243,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
UserDao _userDao;
|
||||
@Inject
|
||||
List<LoadBalancingServiceProvider> _lbProviders;
|
||||
@Inject ApplicationLoadBalancerRuleDao _appLbRuleDao;
|
||||
|
||||
// Will return a string. For LB Stickiness this will be a json, for
|
||||
// autoscale this will be "," separated values
|
||||
|
|
@ -337,7 +340,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
* autoscale config as of today.
|
||||
*/
|
||||
List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
|
||||
Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
|
||||
Ip sourceIp = getSourceIp(lb);
|
||||
LoadBalancingRule rule = new LoadBalancingRule(lb, null, policyList, null, sourceIp);
|
||||
rule.setAutoScaleVmGroup(lbAutoScaleVmGroup);
|
||||
|
||||
|
|
@ -357,6 +360,17 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
return true;
|
||||
}
|
||||
|
||||
private Ip getSourceIp(LoadBalancer lb) {
|
||||
Ip sourceIp = null;
|
||||
if (lb.getScheme() == Scheme.Public) {
|
||||
sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
|
||||
} else if (lb.getScheme() == Scheme.Internal) {
|
||||
ApplicationLoadBalancerRuleVO appLbRule = _appLbRuleDao.findById(lb.getId());
|
||||
sourceIp = appLbRule.getSourceIp();
|
||||
}
|
||||
return sourceIp;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public boolean configureLbAutoScaleVmGroup(long vmGroupid, String currentState) throws ResourceUnavailableException {
|
||||
|
|
@ -530,10 +544,10 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
cmd.getStickinessMethodName(), cmd.getparamList(), cmd.getDescription());
|
||||
List<LbStickinessPolicy> policyList = new ArrayList<LbStickinessPolicy>();
|
||||
policyList.add(new LbStickinessPolicy(cmd.getStickinessMethodName(), lbpolicy.getParams()));
|
||||
Ip sourceIp = _networkModel.getPublicIpAddress(loadBalancer.getSourceIpAddressId()).getAddress();
|
||||
Ip sourceIp = getSourceIp(loadBalancer);
|
||||
LoadBalancingRule lbRule = new LoadBalancingRule(loadBalancer, getExistingDestinations(lbpolicy.getId()),
|
||||
policyList, null, sourceIp);
|
||||
if (!validateRule(lbRule)) {
|
||||
if (!validateLbRule(lbRule)) {
|
||||
throw new InvalidParameterValueException("Failed to create Stickiness policy: Validation Failed "
|
||||
+ cmd.getLbRuleId());
|
||||
}
|
||||
|
|
@ -616,7 +630,8 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
return policy;
|
||||
}
|
||||
|
||||
private boolean validateRule(LoadBalancingRule lbRule) {
|
||||
@Override
|
||||
public boolean validateLbRule(LoadBalancingRule lbRule) {
|
||||
Network network = _networkDao.findById(lbRule.getNetworkId());
|
||||
Purpose purpose = lbRule.getPurpose();
|
||||
if (purpose != Purpose.LoadBalancing) {
|
||||
|
|
@ -849,7 +864,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
// adding to lbrules list only if the LB rule
|
||||
// hashealtChecks
|
||||
if (hcPolicyList != null && hcPolicyList.size() > 0) {
|
||||
Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
|
||||
Ip sourceIp = getSourceIp(lb);
|
||||
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, null, hcPolicyList, sourceIp);
|
||||
lbrules.add(loadBalancing);
|
||||
}
|
||||
|
|
@ -1250,16 +1265,9 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
int srcPortStart, int srcPortEnd, int defPortStart, int defPortEnd, Long ipAddrId, String protocol, String algorithm, long networkId, long lbOwnerId, boolean openFirewall)
|
||||
throws NetworkRuleConflictException, InsufficientAddressCapacityException {
|
||||
Account lbOwner = _accountMgr.getAccount(lbOwnerId);
|
||||
|
||||
if (!NetUtils.isValidPort(defPortEnd)) {
|
||||
throw new InvalidParameterValueException("privatePort is an invalid value: " + defPortEnd);
|
||||
}
|
||||
if (defPortStart > defPortEnd) {
|
||||
throw new InvalidParameterValueException("private port range is invalid: " + defPortStart + "-"
|
||||
+ defPortEnd);
|
||||
}
|
||||
if ((algorithm == null) || !NetUtils.isValidAlgorithm(algorithm)) {
|
||||
throw new InvalidParameterValueException("Invalid algorithm: " + algorithm);
|
||||
|
||||
if (srcPortStart != srcPortEnd) {
|
||||
throw new InvalidParameterValueException("Port ranges are not supported by the load balancer");
|
||||
}
|
||||
|
||||
IPAddressVO ipVO = null;
|
||||
|
|
@ -1314,7 +1322,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
+ network);
|
||||
}
|
||||
|
||||
result = createPublicLoadBalancer(xId, name, description, srcPortStart, srcPortEnd, defPortStart, ipVO.getId(), protocol, algorithm, openFirewall, UserContext.current());
|
||||
result = createPublicLoadBalancer(xId, name, description, srcPortStart, defPortStart, ipVO.getId(), protocol, algorithm, openFirewall, UserContext.current());
|
||||
} catch (Exception ex) {
|
||||
s_logger.warn("Failed to create load balancer due to ", ex);
|
||||
if (ex instanceof NetworkRuleConflictException) {
|
||||
|
|
@ -1344,8 +1352,16 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
@DB
|
||||
@Override
|
||||
public LoadBalancer createPublicLoadBalancer(String xId, String name, String description,
|
||||
int srcPortStart, int srcPortEnd, int defPortStart, long sourceIpId, String protocol, String algorithm, boolean openFirewall, UserContext caller)
|
||||
int srcPort, int destPort, long sourceIpId, String protocol, String algorithm, boolean openFirewall, UserContext caller)
|
||||
throws NetworkRuleConflictException {
|
||||
|
||||
if (!NetUtils.isValidPort(destPort)) {
|
||||
throw new InvalidParameterValueException("privatePort is an invalid value: " + destPort);
|
||||
}
|
||||
|
||||
if ((algorithm == null) || !NetUtils.isValidAlgorithm(algorithm)) {
|
||||
throw new InvalidParameterValueException("Invalid algorithm: " + algorithm);
|
||||
}
|
||||
|
||||
IPAddressVO ipAddr = _ipAddressDao.findById(sourceIpId);
|
||||
// make sure ip address exists
|
||||
|
|
@ -1360,6 +1376,9 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
_accountMgr.checkAccess(caller.getCaller(), null, true, ipAddr);
|
||||
|
||||
|
||||
Long networkId = ipAddr.getAssociatedWithNetworkId();
|
||||
if (networkId == null) {
|
||||
|
|
@ -1368,12 +1387,8 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
_firewallMgr.validateFirewallRule(caller.getCaller(), ipAddr, srcPortStart, srcPortEnd, protocol,
|
||||
Purpose.LoadBalancing, FirewallRuleType.User, networkId, null);
|
||||
|
||||
NetworkVO network = _networkDao.findById(networkId);
|
||||
_accountMgr.checkAccess(caller.getCaller(), null, true, ipAddr);
|
||||
|
||||
// verify that lb service is supported by the network
|
||||
if (!_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb)) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException(
|
||||
|
|
@ -1382,26 +1397,30 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
throw ex;
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
_firewallMgr.validateFirewallRule(caller.getCaller(), ipAddr, srcPort, srcPort, protocol,
|
||||
Purpose.LoadBalancing, FirewallRuleType.User, networkId, null);
|
||||
|
||||
LoadBalancerVO newRule = new LoadBalancerVO(xId, name, description,
|
||||
sourceIpId, srcPortEnd, srcPortStart, algorithm,
|
||||
sourceIpId, srcPort, srcPort, algorithm,
|
||||
network.getId(), ipAddr.getAllocatedToAccountId(), ipAddr.getAllocatedInDomainId());
|
||||
|
||||
// verify rule is supported by Lb provider of the network
|
||||
Ip sourceIp = _networkModel.getPublicIpAddress(newRule.getSourceIpAddressId()).getAddress();
|
||||
Ip sourceIp = getSourceIp(newRule);
|
||||
LoadBalancingRule loadBalancing = new LoadBalancingRule(newRule, new ArrayList<LbDestination>(),
|
||||
new ArrayList<LbStickinessPolicy>(), new ArrayList<LbHealthCheckPolicy>(), sourceIp);
|
||||
if (!validateRule(loadBalancing)) {
|
||||
if (!validateLbRule(loadBalancing)) {
|
||||
throw new InvalidParameterValueException("LB service provider cannot support this rule");
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
newRule = _lbDao.persist(newRule);
|
||||
|
||||
//create rule for all CIDRs
|
||||
if (openFirewall) {
|
||||
_firewallMgr.createRuleForAllCidrs(sourceIpId, caller.getCaller(), srcPortStart,
|
||||
srcPortEnd, protocol, null, null, newRule.getId(), networkId);
|
||||
_firewallMgr.createRuleForAllCidrs(sourceIpId, caller.getCaller(), srcPort,
|
||||
srcPort, protocol, null, null, newRule.getId(), networkId);
|
||||
}
|
||||
|
||||
boolean success = true;
|
||||
|
|
@ -1412,7 +1431,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
|
||||
}
|
||||
s_logger.debug("Load balancer " + newRule.getId() + " for Ip address id=" + sourceIpId + ", public port "
|
||||
+ srcPortStart + ", private port " + defPortStart + " is added successfully.");
|
||||
+ srcPort + ", private port " + destPort + " is added successfully.");
|
||||
UserContext.current().setEventDetails("Load balancer Id: " + newRule.getId());
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_LOAD_BALANCER_CREATE, ipAddr.getAllocatedToAccountId(),
|
||||
ipAddr.getDataCenterId(), newRule.getId(), null, LoadBalancingRule.class.getName(),
|
||||
|
|
@ -1499,7 +1518,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
private LoadBalancingRule getLoadBalancerRuleToApply(LoadBalancerVO lb) {
|
||||
|
||||
List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
|
||||
Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
|
||||
Ip sourceIp = getSourceIp(lb);
|
||||
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, null, policyList, null, sourceIp);
|
||||
|
||||
if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(lb.getId())) {
|
||||
|
|
@ -1984,7 +2003,8 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
return _lbDao.findById(lbId);
|
||||
}
|
||||
|
||||
protected void removeLBRule(LoadBalancerVO rule) {
|
||||
@Override
|
||||
public void removeLBRule(LoadBalancer rule) {
|
||||
// remove the rule
|
||||
_lbDao.remove(rule.getId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorType;
|
||||
|
|
@ -35,7 +34,6 @@ import javax.persistence.InheritanceType;
|
|||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import com.cloud.network.dao.FirewallRulesCidrsDao;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,21 +17,51 @@
|
|||
|
||||
package org.apache.cloudstack.network.lb;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.api.command.user.loadbalancer.ListApplicationLoadBalancersCmd;
|
||||
import org.apache.cloudstack.network.lb.dao.ApplicationLoadBalancerRuleDao;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.UsageEventUtils;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.NetworkModel;
|
||||
import com.cloud.network.rules.ApplicationLoadBalancerRule;
|
||||
import com.cloud.network.dao.FirewallRulesDao;
|
||||
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.LoadBalancerContainer.Scheme;
|
||||
import com.cloud.projects.Project.ListProjectResourcesCriteria;
|
||||
import com.cloud.server.ResourceTag.TaggedResourceType;
|
||||
import com.cloud.tags.ResourceTagVO;
|
||||
import com.cloud.tags.dao.ResourceTagDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.Ternary;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.JoinBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.Ip;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
@Component
|
||||
@Local(value = { ApplicationLoadBalancerService.class })
|
||||
|
|
@ -39,23 +69,201 @@ public class ApplicationLoadBalancerManagerImpl extends ManagerBase implements A
|
|||
private static final Logger s_logger = Logger.getLogger(ApplicationLoadBalancerManagerImpl.class);
|
||||
|
||||
@Inject NetworkModel _networkModel;
|
||||
@Inject ApplicationLoadBalancerRuleDao _lbDao;
|
||||
@Inject AccountManager _accountMgr;
|
||||
@Inject LoadBalancingRulesManager _lbMgr;
|
||||
@Inject FirewallRulesDao _firewallDao;
|
||||
@Inject ResourceTagDao _resourceTagDao;
|
||||
|
||||
|
||||
//TODO - add action even annotation here; test it as well
|
||||
@Override
|
||||
public ApplicationLoadBalancerRule createApplicationLoadBalancer(String name, String description, Scheme scheme, long sourceIpNetworkId, String sourceIp,
|
||||
int sourcePort, int instancePort, String algorithm, long networkId, long lbOwnerId) throws InsufficientAddressCapacityException,
|
||||
NetworkRuleConflictException {
|
||||
|
||||
return null;
|
||||
if (!NetUtils.isValidPort(instancePort)) {
|
||||
throw new InvalidParameterValueException("Invalid value for instance port: " + instancePort);
|
||||
}
|
||||
|
||||
|
||||
if (!NetUtils.isValidPort(instancePort)) {
|
||||
throw new InvalidParameterValueException("Invalid value for source port: " + sourcePort);
|
||||
}
|
||||
|
||||
if ((algorithm == null) || !NetUtils.isValidAlgorithm(algorithm)) {
|
||||
throw new InvalidParameterValueException("Invalid algorithm: " + algorithm);
|
||||
}
|
||||
|
||||
Network network = _networkModel.getNetwork(networkId);
|
||||
// verify that lb service is supported by the network
|
||||
if (!_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb)) {
|
||||
InvalidParameterValueException ex = new InvalidParameterValueException(
|
||||
"LB service is not supported in specified network id");
|
||||
ex.addProxyObject(network, networkId, "networkId");
|
||||
throw ex;
|
||||
}
|
||||
|
||||
Account lbOwner = _accountMgr.getAccount(lbOwnerId);
|
||||
if (lbOwner == null) {
|
||||
throw new InvalidParameterValueException("Can't find the lb owner account");
|
||||
}
|
||||
|
||||
//TODO - assign guest ip address here//add validation for the source ip address/network id
|
||||
ApplicationLoadBalancerRuleVO newRule = new ApplicationLoadBalancerRuleVO(name, description, sourcePort, instancePort, algorithm, networkId,
|
||||
lbOwner.getId(), lbOwner.getDomainId(), new Ip(sourceIp), sourceIpNetworkId, scheme);
|
||||
|
||||
|
||||
// verify rule is supported by Lb provider of the network
|
||||
LoadBalancingRule loadBalancing = new LoadBalancingRule(newRule, new ArrayList<LbDestination>(),
|
||||
new ArrayList<LbStickinessPolicy>(), new ArrayList<LbHealthCheckPolicy>(), new Ip(sourceIp));
|
||||
|
||||
if (!_lbMgr.validateLbRule(loadBalancing)) {
|
||||
throw new InvalidParameterValueException("LB service provider cannot support this rule");
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
newRule = _lbDao.persist(newRule);
|
||||
boolean success = true;
|
||||
|
||||
try {
|
||||
//TODO - add validation for the LB rule against other lb rules
|
||||
|
||||
if (!_firewallDao.setStateToAdd(newRule)) {
|
||||
throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
|
||||
}
|
||||
s_logger.debug("Load balancer " + newRule.getId() + " for Ip address " + sourceIp + ", source port "
|
||||
+ sourcePort + ", instance port " + instancePort + " is added successfully.");
|
||||
UserContext.current().setEventDetails("Load balancer Id: " + newRule.getId());
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_LOAD_BALANCER_CREATE, lbOwnerId,
|
||||
network.getDataCenterId(), newRule.getId(), null, LoadBalancingRule.class.getName(),
|
||||
newRule.getUuid());
|
||||
txn.commit();
|
||||
|
||||
return newRule;
|
||||
} catch (Exception e) {
|
||||
success = false;
|
||||
if (e instanceof NetworkRuleConflictException) {
|
||||
throw (NetworkRuleConflictException) e;
|
||||
}
|
||||
throw new CloudRuntimeException("Unable to add lb rule for ip address " + newRule.getSourceIpAddressId(), e);
|
||||
} finally {
|
||||
if (!success && newRule != null) {
|
||||
_lbMgr.removeLBRule(newRule);
|
||||
//TODO - unassign the guest ip address here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteApplicationLoadBalancer(long id) {
|
||||
return true;
|
||||
return _lbMgr.deleteLoadBalancerRule(id, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<List<? extends ApplicationLoadBalancerRule>, Integer> listApplicationLoadBalancers() {
|
||||
return null;
|
||||
public Pair<List<? extends ApplicationLoadBalancerRule>, Integer> listApplicationLoadBalancers(ListApplicationLoadBalancersCmd cmd) {
|
||||
Long id = cmd.getId();
|
||||
String name = cmd.getLoadBalancerRuleName();
|
||||
String ip = cmd.getSourceIp();
|
||||
Long ipNtwkId = cmd.getSourceIpNetworkId();
|
||||
String keyword = cmd.getKeyword();
|
||||
Scheme scheme = cmd.getScheme();
|
||||
Long networkId = cmd.getNetworkId();
|
||||
|
||||
Map<String, String> tags = cmd.getTags();
|
||||
|
||||
Account caller = UserContext.current().getCaller();
|
||||
List<Long> permittedAccounts = new ArrayList<Long>();
|
||||
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
cmd.getDomainId(), cmd.isRecursive(), null);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts,
|
||||
domainIdRecursiveListProject, cmd.listAll(), false);
|
||||
Long domainId = domainIdRecursiveListProject.first();
|
||||
Boolean isRecursive = domainIdRecursiveListProject.second();
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
|
||||
Filter searchFilter = new Filter(ApplicationLoadBalancerRuleVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
SearchBuilder<ApplicationLoadBalancerRuleVO> sb = _lbDao.createSearchBuilder();
|
||||
_accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
|
||||
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
sb.and("sourceIpAddress", sb.entity().getSourceIp(), SearchCriteria.Op.EQ);
|
||||
sb.and("sourceIpAddressNetworkId", sb.entity().getSourceIpNetworkId(), SearchCriteria.Op.EQ);
|
||||
sb.and("scheme", sb.entity().getScheme(), SearchCriteria.Op.EQ);
|
||||
sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ);
|
||||
|
||||
//list only load balancers having not null sourceIp/sourceIpNtwkId
|
||||
sb.and("sourceIpAddress", sb.entity().getSourceIp(), SearchCriteria.Op.NNULL);
|
||||
sb.and("sourceIpAddressNetworkId", sb.entity().getSourceIpNetworkId(), SearchCriteria.Op.NNULL);
|
||||
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
|
||||
for (int count = 0; count < tags.size(); count++) {
|
||||
tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
|
||||
tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
|
||||
tagSearch.cp();
|
||||
}
|
||||
tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
|
||||
sb.groupBy(sb.entity().getId());
|
||||
sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(),
|
||||
JoinBuilder.JoinType.INNER);
|
||||
}
|
||||
|
||||
SearchCriteria<ApplicationLoadBalancerRuleVO> sc = sb.create();
|
||||
_accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
|
||||
|
||||
if (keyword != null) {
|
||||
SearchCriteria<ApplicationLoadBalancerRuleVO> ssc = _lbDao.createSearchCriteria();
|
||||
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
sc.setParameters("name", name);
|
||||
}
|
||||
|
||||
if (id != null) {
|
||||
sc.setParameters("id", id);
|
||||
}
|
||||
|
||||
if (ip != null) {
|
||||
sc.setParameters("sourceIpAddress", ip);
|
||||
}
|
||||
|
||||
if (ipNtwkId != null) {
|
||||
sc.setParameters("sourceIpAddressNetworkId", ipNtwkId);
|
||||
}
|
||||
|
||||
if (scheme != null) {
|
||||
sc.setParameters("scheme", scheme);
|
||||
}
|
||||
|
||||
if (networkId != null) {
|
||||
sc.setParameters("networkId", networkId);
|
||||
}
|
||||
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
int count = 0;
|
||||
sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.LoadBalancer.toString());
|
||||
for (String key : tags.keySet()) {
|
||||
sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
|
||||
sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
Pair<List<ApplicationLoadBalancerRuleVO>, Integer> result = _lbDao.searchAndCount(sc, searchFilter);
|
||||
return new Pair<List<? extends ApplicationLoadBalancerRule>, Integer>(result.first(), result.second());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationLoadBalancerRule findById(long ruleId) {
|
||||
return _lbDao.findById(ruleId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,133 @@
|
|||
// 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.network.lb;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.cloud.network.rules.FirewallRuleVO;
|
||||
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
|
||||
import com.cloud.utils.net.Ip;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
/**
|
||||
* This VO represent Internal Load Balancer rule.
|
||||
* Instead of pointing to the public ip address id directly as External Load Balancer rule does, it refers to the ip address by its value/sourceNetworkid
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name=("load_balancing_rules"))
|
||||
@DiscriminatorValue(value="LoadBalancing")
|
||||
@PrimaryKeyJoinColumn(name="id")
|
||||
public class ApplicationLoadBalancerRuleVO extends FirewallRuleVO implements ApplicationLoadBalancerRule{
|
||||
@Column(name="name")
|
||||
private String name;
|
||||
|
||||
@Column(name="description", length=4096)
|
||||
private String description;
|
||||
|
||||
@Column(name="algorithm")
|
||||
private String algorithm;
|
||||
|
||||
@Column(name="default_port_start")
|
||||
private int defaultPortStart;
|
||||
|
||||
@Column(name="default_port_end")
|
||||
private int defaultPortEnd;
|
||||
|
||||
@Column(name="source_ip_address_network_id")
|
||||
Long sourceIpNetworkId;
|
||||
|
||||
@Column(name="source_ip_address")
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
private Ip sourceIp = null;
|
||||
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
@Column(name="scheme")
|
||||
Scheme scheme;
|
||||
|
||||
|
||||
public ApplicationLoadBalancerRuleVO() {
|
||||
}
|
||||
|
||||
public ApplicationLoadBalancerRuleVO(String name, String description, int srcPort, int instancePort, String algorithm,
|
||||
long networkId, long accountId, long domainId, Ip sourceIp, long sourceIpNtwkId, Scheme scheme) {
|
||||
super(null, null, srcPort, srcPort, NetUtils.TCP_PROTO, networkId, accountId, domainId, Purpose.LoadBalancing, null, null,null, null, null);
|
||||
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.algorithm = algorithm;
|
||||
this.defaultPortStart = instancePort;
|
||||
this.defaultPortEnd = instancePort;
|
||||
this.sourceIp = sourceIp;
|
||||
this.sourceIpNetworkId = sourceIpNtwkId;
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Long getSourceIpNetworkId() {
|
||||
return sourceIpNetworkId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ip getSourceIp() {
|
||||
return sourceIp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlgorithm() {
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultPortStart() {
|
||||
return defaultPortStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultPortEnd() {
|
||||
return defaultPortEnd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scheme getScheme() {
|
||||
return scheme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstancePort() {
|
||||
return defaultPortStart;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// 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.network.lb.dao;
|
||||
|
||||
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRuleVO;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface ApplicationLoadBalancerRuleDao extends GenericDao<ApplicationLoadBalancerRuleVO, Long>{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// 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.network.lb.dao;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRuleVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
||||
@Component
|
||||
@Local(value = { ApplicationLoadBalancerRuleDao.class })
|
||||
public class ApplicationLoadBalancerRuleDaoImpl extends GenericDaoBase<ApplicationLoadBalancerRuleVO, Long> implements ApplicationLoadBalancerRuleDao{
|
||||
|
||||
}
|
||||
|
|
@ -450,7 +450,7 @@ UPDATE `cloud`.`hypervisor_capabilities` SET `vm_snapshot_enabled`=1 WHERE `hype
|
|||
|
||||
|
||||
ALTER TABLE `cloud`.`load_balancing_rules` ADD COLUMN `source_ip_address` varchar(40) COMMENT 'source ip address for the load balancer rule';
|
||||
ALTER TABLE `cloud`.`load_balancing_rules` ADD COLUMN `source_ip_address_network_id` varchar(40) COMMENT 'the UUID of the network where source ip belongs to';
|
||||
ALTER TABLE `cloud`.`load_balancing_rules` ADD COLUMN `source_ip_address_network_id` bigint unsigned COMMENT 'the id of the network where source ip belongs to';
|
||||
ALTER TABLE `cloud`.`load_balancing_rules` ADD COLUMN `scheme` varchar(40) NOT NULL COMMENT 'load balancer scheme; can be Internal or Public';
|
||||
UPDATE `cloud`.`load_balancing_rules` SET `scheme`='Public';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue