Skip to content

Commit 8277584

Browse files
author
Chiradeep Vittal
committed
merge ELB / nectarine branch
2 parents b8c9205 + 52e8d5c commit 8277584

45 files changed

Lines changed: 3357 additions & 1114 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/com/cloud/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,6 @@ public class ApiConstants {
249249
public static final String SNAPSHOT_RESERVATION = "snapshotreservation";
250250
public static final String IP_NETWORK_LIST = "iptonetworklist";
251251
public static final String REDUNDANT_ROUTER = "redundantrouter";
252+
public static final String FOR_LOAD_BALANCING = "forloadbalancing";
252253
public static final String KEYBOARD="keyboard";
253254
}

api/src/com/cloud/api/commands/AssociateIPAddrCmd.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,13 @@ public Long getSyncObjId() {
189189
@Override
190190
public AsyncJob.Type getInstanceType() {
191191
return AsyncJob.Type.IpAddress;
192+
}
193+
194+
public AssociateIPAddrCmd(String accountName, Long domainId, Long zoneId, Long networkId) {
195+
super();
196+
this.accountName = accountName;
197+
this.domainId = domainId;
198+
this.zoneId = zoneId;
199+
this.networkId = networkId;
192200
}
193201
}

api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java

Lines changed: 91 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,38 @@
1616
*
1717
*/
1818

19-
package com.cloud.api.commands;
20-
19+
package com.cloud.api.commands;
20+
2121
import java.util.List;
2222

2323
import org.apache.log4j.Logger;
2424

2525
import com.cloud.api.ApiConstants;
26+
import com.cloud.api.BaseAsyncCmd;
2627
import com.cloud.api.BaseCmd;
2728
import com.cloud.api.Implementation;
2829
import com.cloud.api.Parameter;
2930
import com.cloud.api.ServerApiException;
3031
import com.cloud.api.BaseCmd.CommandType;
3132
import com.cloud.api.response.LoadBalancerResponse;
33+
import com.cloud.event.EventTypes;
34+
import com.cloud.exception.InsufficientAddressCapacityException;
3235
import com.cloud.exception.InvalidParameterValueException;
3336
import com.cloud.exception.NetworkRuleConflictException;
37+
import com.cloud.exception.ResourceAllocationException;
38+
import com.cloud.exception.ResourceUnavailableException;
3439
import com.cloud.network.IpAddress;
3540
import com.cloud.network.rules.LoadBalancer;
41+
import com.cloud.user.Account;
42+
import com.cloud.user.UserContext;
3643
import com.cloud.utils.net.NetUtils;
37-
44+
3845
@Implementation(description="Creates a load balancer rule", responseObject=LoadBalancerResponse.class)
39-
public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer {
40-
public static final Logger s_logger = Logger.getLogger(CreateLoadBalancerRuleCmd.class.getName());
41-
42-
private static final String s_name = "createloadbalancerruleresponse";
43-
46+
public class CreateLoadBalancerRuleCmd extends BaseAsyncCmd /*implements LoadBalancer */{
47+
public static final Logger s_logger = Logger.getLogger(CreateLoadBalancerRuleCmd.class.getName());
48+
49+
private static final String s_name = "createloadbalancerruleresponse";
50+
4451
/////////////////////////////////////////////////////
4552
//////////////// API parameters /////////////////////
4653
/////////////////////////////////////////////////////
@@ -57,26 +64,31 @@ public class CreateLoadBalancerRuleCmd extends BaseCmd implements LoadBalancer
5764
@Parameter(name=ApiConstants.PRIVATE_PORT, type=CommandType.INTEGER, required=true, description="the private port of the private ip address/virtual machine where the network traffic will be load balanced to")
5865
private Integer privatePort;
5966

60-
@Parameter(name=ApiConstants.PUBLIC_IP_ID, type=CommandType.LONG, required=true, description="public ip address id from where the network traffic will be load balanced from")
67+
@Parameter(name=ApiConstants.PUBLIC_IP_ID, type=CommandType.LONG, required=false, description="public ip address id from where the network traffic will be load balanced from")
6168
private Long publicIpId;
69+
70+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=false, description="public ip address id from where the network traffic will be load balanced from")
71+
private Long zoneId;
6272

6373
@Parameter(name=ApiConstants.PUBLIC_PORT, type=CommandType.INTEGER, required=true, description="the public port from where the network traffic will be load balanced from")
6474
private Integer publicPort;
6575

6676
@Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from")
6777
private List<String> cidrlist;
78+
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the load balancer. Must be used with the domainId parameter.")
79+
private String accountName;
6880

69-
81+
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the load balancer")
82+
private Long domainId;
83+
7084
/////////////////////////////////////////////////////
7185
/////////////////// Accessors ///////////////////////
7286
/////////////////////////////////////////////////////
7387

74-
@Override
7588
public String getAlgorithm() {
7689
return algorithm;
7790
}
7891

79-
@Override
8092
public String getDescription() {
8193
return description;
8294
}
@@ -92,7 +104,7 @@ public Integer getPrivatePort() {
92104
public Long getPublicIpId() {
93105
IpAddress ipAddr = _networkService.getIp(publicIpId);
94106
if (ipAddr == null || !ipAddr.readyToUse()) {
95-
throw new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id" + ipAddr.getId());
107+
throw new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id " + ipAddr.getId());
96108
}
97109

98110
return publicIpId;
@@ -115,12 +127,12 @@ public List<String> getSourceCidrList() {
115127
/////////////////////////////////////////////////////
116128

117129
@Override
118-
public String getCommandName() {
119-
return s_name;
130+
public String getCommandName() {
131+
return s_name;
120132
}
121133

122134
@Override
123-
public void execute() {
135+
public void execute() throws ResourceAllocationException, ResourceUnavailableException {
124136
if (cidrlist != null){
125137
for (String cidr: cidrlist){
126138
if (!NetUtils.isValidCIDR(cidr)){
@@ -135,80 +147,107 @@ public void execute() {
135147
} catch (NetworkRuleConflictException e) {
136148
s_logger.warn("Exception: ", e);
137149
throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
150+
} catch (InsufficientAddressCapacityException e) {
151+
s_logger.warn("Exception: ", e);
152+
throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
138153
}
139154
LoadBalancerResponse response = _responseGenerator.createLoadBalancerResponse(result);
140155
response.setResponseName(getCommandName());
141156
this.setResponseObject(response);
142157
}
143158

144-
@Override
145-
public long getId() {
146-
throw new UnsupportedOperationException("not supported");
147-
}
148-
149-
@Override
150-
public String getXid() {
151-
// FIXME: Should fix this.
152-
return null;
153-
}
159+
154160

155-
@Override
156-
public long getSourceIpAddressId() {
161+
public Long getSourceIpAddressId() {
157162
return publicIpId;
158163
}
159164

160-
@Override
161165
public int getSourcePortStart() {
162166
return publicPort.intValue();
163167
}
164168

165-
@Override
166169
public int getSourcePortEnd() {
167170
return publicPort.intValue();
168171
}
169172

170-
@Override
171173
public String getProtocol() {
172174
return NetUtils.TCP_PROTO;
173175
}
174176

175-
@Override
176-
public Purpose getPurpose() {
177-
return Purpose.LoadBalancing;
178-
}
177+
179178

180-
@Override
181-
public State getState() {
182-
throw new UnsupportedOperationException("not supported");
183-
}
179+
public long getAccountId() {
180+
if (publicIpId != null)
181+
return _networkService.getIp(getPublicIpId()).getAccountId();
182+
Account account = UserContext.current().getCaller();
183+
if ((account == null) ) {
184+
if ((domainId != null) && (accountName != null)) {
185+
Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
186+
if (userAccount != null) {
187+
return userAccount.getId();
188+
}
189+
}
190+
}
184191

185-
@Override
186-
public long getNetworkId() {
187-
return -1;
188-
}
192+
if (account != null) {
193+
return account.getId();
194+
}
189195

190-
@Override
191-
public long getAccountId() {
192-
return _networkService.getIp(getPublicIpId()).getAccountId();
196+
return Account.ACCOUNT_ID_SYSTEM;
193197
}
194198

195-
@Override
196199
public long getDomainId() {
197-
return _networkService.getIp(getPublicIpId()).getDomainId();
200+
if (publicIpId != null)
201+
return _networkService.getIp(getPublicIpId()).getDomainId();
202+
if (domainId != null) {
203+
return domainId;
204+
}
205+
return UserContext.current().getCaller().getDomainId();
198206
}
199207

200-
@Override
201208
public int getDefaultPortStart() {
202209
return privatePort.intValue();
203210
}
204211

205-
@Override
206212
public int getDefaultPortEnd() {
207213
return privatePort.intValue();
208214
}
209215

210216
@Override
211217
public long getEntityOwnerId() {
212218
return getAccountId();
213-
}
214-
}
219+
}
220+
221+
public String getAccountName() {
222+
return accountName;
223+
}
224+
225+
public Long getZoneId() {
226+
return zoneId;
227+
}
228+
229+
public void setPublicIpId(Long publicIpId) {
230+
this.publicIpId = publicIpId;
231+
}
232+
233+
@Override
234+
public String getEventType() {
235+
return EventTypes.EVENT_LOAD_BALANCER_CREATE;
236+
}
237+
238+
@Override
239+
public String getEventDescription() {
240+
return "creating load balancer: " + getName() + " account: " + getAccountName();
241+
242+
}
243+
244+
public String getXid() {
245+
/*FIXME*/
246+
return null;
247+
}
248+
249+
public void setSourceIpAddressId(Long ipId) {
250+
this.publicIpId = ipId;
251+
}
252+
253+
}

api/src/com/cloud/api/commands/DeleteLoadBalancerRuleCmd.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public String getSyncObjType() {
9999

100100
@Override
101101
public Long getSyncObjId() {
102-
return _lbService.findById(id).getNetworkId();
102+
LoadBalancer lb = _lbService.findById(id);
103+
if (lb == null) {
104+
return null;
105+
}
106+
return lb.getNetworkId();
103107
}
104108
}

api/src/com/cloud/api/commands/ListCapabilitiesCmd.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public void execute(){
4949
response.setSecurityGroupsEnabled((Boolean)capabilities.get("securityGroupsEnabled"));
5050
response.setCloudStackVersion((String)capabilities.get("cloudStackVersion"));
5151
response.setUserPublicTemplateEnabled((Boolean)capabilities.get("userPublicTemplateEnabled"));
52+
response.setSupportELB((String)capabilities.get("supportELB"));
5253
response.setObjectName("capability");
5354
response.setResponseName(getCommandName());
5455
this.setResponseObject(response);

api/src/com/cloud/api/commands/ListLoadBalancerRulesCmd.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,17 @@ public void execute() {
119119
response.setResponseName(getCommandName());
120120
this.setResponseObject(response);
121121
}
122+
123+
/*
124+
public ListLoadBalancerRulesCmd(String accountName, Long domainId, Long id, String loadBalancerRuleName, Long publicIpId, Long virtualMachineId, Long zoneId) {
125+
super();
126+
this.accountName = accountName;
127+
this.domainId = domainId;
128+
this.id = id;
129+
this.loadBalancerRuleName = loadBalancerRuleName;
130+
this.publicIpId = publicIpId;
131+
this.virtualMachineId = virtualMachineId;
132+
this.zoneId = zoneId;
133+
}
134+
*/
122135
}

api/src/com/cloud/api/commands/ListPublicIpAddressesCmd.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public class ListPublicIpAddressesCmd extends BaseListCmd {
6565

6666
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="lists all public IP addresses by Zone ID")
6767
private Long zoneId;
68+
69+
@Parameter(name=ApiConstants.FOR_LOAD_BALANCING, type=CommandType.BOOLEAN, description="list only ips used for load balancing")
70+
private Boolean forLoadBalancing;
6871

6972
/////////////////////////////////////////////////////
7073
/////////////////// Accessors ///////////////////////
@@ -128,5 +131,34 @@ public void execute(){
128131

129132
public AsyncJob.Type getInstanceType() {
130133
return AsyncJob.Type.IpAddress;
134+
}
135+
136+
137+
public Boolean isForLoadBalancing() {
138+
return forLoadBalancing;
139+
}
140+
141+
public Boolean getAllocatedOnly() {
142+
return allocatedOnly;
143+
}
144+
145+
public void setAllocatedOnly(Boolean allocatedOnly) {
146+
this.allocatedOnly = allocatedOnly;
147+
}
148+
149+
public Boolean getForVirtualNetwork() {
150+
return forVirtualNetwork;
151+
}
152+
153+
public void setForVirtualNetwork(Boolean forVirtualNetwork) {
154+
this.forVirtualNetwork = forVirtualNetwork;
155+
}
156+
157+
public Boolean getForLoadBalancing() {
158+
return forLoadBalancing;
159+
}
160+
161+
public void setForLoadBalancing(Boolean forLoadBalancing) {
162+
this.forLoadBalancing = forLoadBalancing;
131163
}
132164
}

api/src/com/cloud/api/response/CapabilitiesResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public class CapabilitiesResponse extends BaseResponse {
3030

3131
@SerializedName("userpublictemplateenabled") @Param(description="true if user and domain admins can set templates to be shared, false otherwise")
3232
private boolean userPublicTemplateEnabled;
33+
34+
35+
@SerializedName("supportELB") @Param(description="true if region supports elastic load balancer on basic zones")
36+
private String supportELB;
3337

3438
public boolean getSecurityGroupsEnabled() {
3539
return securityGroupsEnabled;
@@ -54,4 +58,12 @@ public boolean getUserPublicTemplateEnabled() {
5458
public void setUserPublicTemplateEnabled(boolean userPublicTemplateEnabled) {
5559
this.userPublicTemplateEnabled = userPublicTemplateEnabled;
5660
}
61+
62+
public void setSupportELB(String supportELB) {
63+
this.supportELB = supportELB;
64+
}
65+
66+
public String getSupportELB() {
67+
return supportELB;
68+
}
5769
}

api/src/com/cloud/network/Network.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public static class Provider {
9393
public static final Provider F5BigIp = new Provider("F5BigIp");
9494
public static final Provider ExternalDhcpServer = new Provider("ExternalDhcpServer");
9595
public static final Provider ExternalGateWay = new Provider("ExternalGateWay");
96+
public static final Provider ElasticLoadBalancerVm = new Provider("ElasticLoadBalancerVm");
97+
9698
public static final Provider None = new Provider("None");
9799

98100
private String name;

0 commit comments

Comments
 (0)