Skip to content

Commit 9641e1d

Browse files
author
Alena Prokharchyk
committed
External UUID control support for NetworkACLList/LoadBalancer/ApplicationLoadBalancer
1 parent 3cfa5fb commit 9641e1d

12 files changed

Lines changed: 253 additions & 6 deletions

File tree

api/src/com/cloud/event/EventTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ public class EventTypes {
365365
public static final String EVENT_NETWORK_ACL_CREATE = "NETWORK.ACL.CREATE";
366366
public static final String EVENT_NETWORK_ACL_DELETE = "NETWORK.ACL.DELETE";
367367
public static final String EVENT_NETWORK_ACL_REPLACE = "NETWORK.ACL.REPLACE";
368+
public static final String EVENT_NETWORK_ACL_UPDATE = "NETWORK.ACL.UPDATE";
368369
public static final String EVENT_NETWORK_ACL_ITEM_CREATE = "NETWORK.ACL.ITEM.CREATE";
369370
public static final String EVENT_NETWORK_ACL_ITEM_UPDATE = "NETWORK.ACL.ITEM.UPDATE";
370371
public static final String EVENT_NETWORK_ACL_ITEM_DELETE = "NETWORK.ACL.ITEM.DELETE";

api/src/com/cloud/network/vpc/NetworkACLService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,6 @@ NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourc
130130
*/
131131
boolean replaceNetworkACLonPrivateGw(long aclId, long privateGatewayId) throws ResourceUnavailableException;
132132

133+
NetworkACL updateNetworkACL(Long id, String customId);
134+
133135
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.user.loadbalancer;
18+
19+
import org.apache.cloudstack.api.APICommand;
20+
import org.apache.cloudstack.api.ApiConstants;
21+
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
22+
import org.apache.cloudstack.api.Parameter;
23+
import org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse;
24+
import org.apache.cloudstack.api.response.FirewallRuleResponse;
25+
import org.apache.cloudstack.context.CallContext;
26+
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
27+
import org.apache.log4j.Logger;
28+
29+
import com.cloud.event.EventTypes;
30+
import com.cloud.exception.InvalidParameterValueException;
31+
32+
@APICommand(name = "updateLoadBalancer", description = "Updates a Load Balancer", responseObject = ApplicationLoadBalancerResponse.class, since = "4.4.0")
33+
public class UpdateApplicationLoadBalancerCmd extends BaseAsyncCustomIdCmd {
34+
public static final Logger s_logger = Logger.getLogger(UpdateApplicationLoadBalancerCmd.class.getName());
35+
36+
private static final String s_name = "updateloadbalancerresponse";
37+
38+
/////////////////////////////////////////////////////
39+
//////////////// API parameters /////////////////////
40+
/////////////////////////////////////////////////////
41+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, required = true, description = "the ID of the Load Balancer")
42+
private Long id;
43+
44+
/////////////////////////////////////////////////////
45+
/////////////////// Accessors ///////////////////////
46+
/////////////////////////////////////////////////////
47+
@Override
48+
public String getCommandName() {
49+
return s_name;
50+
}
51+
52+
public Long getId() {
53+
return id;
54+
}
55+
56+
@Override
57+
public long getEntityOwnerId() {
58+
ApplicationLoadBalancerRule lb = _entityMgr.findById(ApplicationLoadBalancerRule.class, getId());
59+
if (lb != null) {
60+
return lb.getAccountId();
61+
} else {
62+
throw new InvalidParameterValueException("Can't find load balancer by id specified");
63+
}
64+
}
65+
66+
@Override
67+
public String getEventType() {
68+
return EventTypes.EVENT_LOAD_BALANCER_UPDATE;
69+
}
70+
71+
@Override
72+
public String getEventDescription() {
73+
return "updating load balancer: " + getId();
74+
}
75+
76+
77+
/////////////////////////////////////////////////////
78+
/////////////// API Implementation///////////////////
79+
/////////////////////////////////////////////////////
80+
@Override
81+
public void execute() {
82+
CallContext.current().setEventDetails("Load balancer Id: " + getId());
83+
ApplicationLoadBalancerRule rule = _appLbService.deleteApplicationLoadBalancer(getId(), this.getCustomId());
84+
ApplicationLoadBalancerResponse lbResponse = _responseGenerator.createLoadBalancerContainerReponse(rule, _lbService.getLbInstances(getId()));
85+
setResponseObject(lbResponse);
86+
lbResponse.setResponseName(getCommandName());
87+
}
88+
89+
@Override
90+
public void checkUuid() {
91+
if (this.getCustomId() != null) {
92+
_uuidMgr.checkUuid(this.getCustomId(), ApplicationLoadBalancerRule.class);
93+
}
94+
}
95+
}

api/src/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.loadbalancer;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import org.apache.cloudstack.api.APICommand;
2220
import org.apache.cloudstack.api.ApiConstants;
2321
import org.apache.cloudstack.api.ApiErrorCode;
2422
import org.apache.cloudstack.api.BaseAsyncCmd;
23+
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
2524
import org.apache.cloudstack.api.Parameter;
2625
import org.apache.cloudstack.api.ServerApiException;
2726
import org.apache.cloudstack.api.response.FirewallRuleResponse;
2827
import org.apache.cloudstack.api.response.LoadBalancerResponse;
2928
import org.apache.cloudstack.context.CallContext;
29+
import org.apache.log4j.Logger;
3030

3131
import com.cloud.event.EventTypes;
3232
import com.cloud.exception.InvalidParameterValueException;
3333
import com.cloud.network.rules.LoadBalancer;
3434
import com.cloud.user.Account;
3535

3636
@APICommand(name = "updateLoadBalancerRule", description = "Updates load balancer", responseObject = LoadBalancerResponse.class)
37-
public class UpdateLoadBalancerRuleCmd extends BaseAsyncCmd {
37+
public class UpdateLoadBalancerRuleCmd extends BaseAsyncCustomIdCmd {
3838
public static final Logger s_logger = Logger.getLogger(UpdateLoadBalancerRuleCmd.class.getName());
3939
private static final String s_name = "updateloadbalancerruleresponse";
4040

@@ -132,4 +132,11 @@ public Long getSyncObjId() {
132132
}
133133
return lb.getNetworkId();
134134
}
135+
136+
@Override
137+
public void checkUuid() {
138+
if (this.getCustomId() != null) {
139+
_uuidMgr.checkUuid(this.getCustomId(), LoadBalancer.class);
140+
}
141+
}
135142
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.user.network;
18+
19+
import org.apache.cloudstack.api.APICommand;
20+
import org.apache.cloudstack.api.ApiConstants;
21+
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
22+
import org.apache.cloudstack.api.Parameter;
23+
import org.apache.cloudstack.api.response.NetworkACLResponse;
24+
import org.apache.cloudstack.api.response.SuccessResponse;
25+
import org.apache.cloudstack.context.CallContext;
26+
import org.apache.log4j.Logger;
27+
28+
import com.cloud.event.EventTypes;
29+
import com.cloud.exception.ResourceUnavailableException;
30+
import com.cloud.network.vpc.NetworkACL;
31+
import com.cloud.user.Account;
32+
33+
@APICommand(name = "updateNetworkACLList", description = "Updates Network ACL list", responseObject = SuccessResponse.class, since = "4.4")
34+
public class UpdateNetworkACLListCmd extends BaseAsyncCustomIdCmd {
35+
public static final Logger s_logger = Logger.getLogger(UpdateNetworkACLListCmd.class.getName());
36+
private static final String s_name = "updatenetworkacllistresponse";
37+
38+
/////////////////////////////////////////////////////
39+
//////////////// API parameters /////////////////////
40+
/////////////////////////////////////////////////////
41+
42+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = NetworkACLResponse.class, required = true, description = "the ID of the network ACL")
43+
private Long id;
44+
45+
/////////////////////////////////////////////////////
46+
/////////////////// Accessors ///////////////////////
47+
/////////////////////////////////////////////////////
48+
49+
public Long getId() {
50+
return id;
51+
}
52+
53+
/////////////////////////////////////////////////////
54+
/////////////// API Implementation///////////////////
55+
/////////////////////////////////////////////////////
56+
@Override
57+
public String getCommandName() {
58+
return s_name;
59+
}
60+
61+
@Override
62+
public String getEventType() {
63+
return EventTypes.EVENT_NETWORK_ACL_UPDATE;
64+
}
65+
66+
@Override
67+
public String getEventDescription() {
68+
return ("Updating network acl list id=" + id);
69+
}
70+
71+
@Override
72+
public long getEntityOwnerId() {
73+
Account caller = CallContext.current().getCallingAccount();
74+
return caller.getAccountId();
75+
}
76+
77+
@Override
78+
public void execute() throws ResourceUnavailableException {
79+
NetworkACL acl = _networkACLService.updateNetworkACL(id, this.getCustomId());
80+
NetworkACLResponse aclResponse = _responseGenerator.createNetworkACLResponse(acl);
81+
setResponseObject(aclResponse);
82+
aclResponse.setResponseName(getCommandName());
83+
}
84+
85+
@Override
86+
public void checkUuid() {
87+
if (this.getCustomId() != null) {
88+
_uuidMgr.checkUuid(this.getCustomId(), NetworkACL.class);
89+
}
90+
}
91+
}

api/src/org/apache/cloudstack/network/lb/ApplicationLoadBalancerService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ ApplicationLoadBalancerRule createApplicationLoadBalancer(String name, String de
3939

4040
ApplicationLoadBalancerRule getApplicationLoadBalancer(long ruleId);
4141

42+
ApplicationLoadBalancerRule deleteApplicationLoadBalancer(Long id, String customId);
43+
4244
}

client/tomcatconf/commands.properties.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ createNetworkACLList=15
471471
deleteNetworkACLList=15
472472
replaceNetworkACLList=15
473473
listNetworkACLLists=15
474+
updateNetworkACLList=15
474475

475476

476477
#### Static route commands
@@ -653,6 +654,7 @@ removedeleteUcsManager=1
653654
createLoadBalancer=15
654655
listLoadBalancers=15
655656
deleteLoadBalancer=15
657+
updateLoadBalancer=15
656658

657659
#Internal Load Balancer Element commands
658660
configureInternalLoadBalancerElement=7

engine/schema/src/com/cloud/network/vpc/NetworkACLVO.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,7 @@ public String getName() {
8282
return name;
8383
}
8484

85+
public void setUuid(String uuid) {
86+
this.uuid = uuid;
87+
}
8588
}

server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,7 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
18881888
String algorithm = cmd.getAlgorithm();
18891889
LoadBalancerVO lb = _lbDao.findById(lbRuleId);
18901890
LoadBalancerVO lbBackup = _lbDao.findById(lbRuleId);
1891+
String customId = cmd.getCustomId();
18911892

18921893
if (lb == null) {
18931894
throw new InvalidParameterValueException("Unable to find lb rule by id=" + lbRuleId);
@@ -1908,6 +1909,10 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
19081909
lb.setAlgorithm(algorithm);
19091910
}
19101911

1912+
if (customId != null) {
1913+
lb.setUuid(customId);
1914+
}
1915+
19111916
boolean success = _lbDao.update(lbRuleId, lb);
19121917

19131918
// If algorithm is changed, have to reapply the lb config

server/src/com/cloud/network/vpc/NetworkACLServiceImpl.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.apache.log4j.Logger;
3434
import org.springframework.stereotype.Component;
3535

36+
import com.cloud.event.ActionEvent;
37+
import com.cloud.event.EventTypes;
3638
import com.cloud.exception.InvalidParameterValueException;
3739
import com.cloud.exception.ResourceUnavailableException;
3840
import com.cloud.network.Network;
@@ -637,4 +639,20 @@ public NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String
637639
return _networkAclMgr.updateNetworkACLItem(id, protocol, sourceCidrList, trafficType, action, number, sourcePortStart, sourcePortEnd, icmpCode, icmpType, newUUID);
638640
}
639641

642+
@Override
643+
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_ACL_UPDATE, eventDescription = "updating network acl", async = true)
644+
public NetworkACL updateNetworkACL(Long id, String customId) {
645+
NetworkACLVO acl = _networkACLDao.findById(id);
646+
Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId());
647+
Account caller = CallContext.current().getCallingAccount();
648+
_accountMgr.checkAccess(caller, null, true, vpc);
649+
650+
if (customId != null) {
651+
acl.setUuid(customId);
652+
}
653+
654+
_networkACLDao.update(id, acl);
655+
return _networkACLDao.findById(id);
656+
}
657+
640658
}

0 commit comments

Comments
 (0)