Skip to content

Commit 8065ee4

Browse files
author
Alena Prokharchyk
committed
External UUID control support for VPC and NetworkACLItemp
1 parent 7cd0ad3 commit 8065ee4

11 files changed

Lines changed: 60 additions & 31 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ public interface NetworkACLService {
114114
* @param sourcePortEnd
115115
* @param icmpCode
116116
* @param icmpType
117+
* @param newUUID TODO
117118
* @return
118119
* @throws ResourceUnavailableException
119120
*/
120121
NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, Integer number,
121-
Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType) throws ResourceUnavailableException;
122+
Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String newUUID) throws ResourceUnavailableException;
122123

123124
/**
124125
* Associates ACL with specified Network

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName
6666
* @param vpcId
6767
* @param vpcName
6868
* @param displayText
69+
* @param customId TODO
6970
* @return
7071
*/
71-
public Vpc updateVpc(long vpcId, String vpcName, String displayText);
72+
public Vpc updateVpc(long vpcId, String vpcName, String displayText, String customId);
7273

7374
/**
7475
* Lists VPC(s) based on the parameters passed to the method call

api/src/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,23 @@
1818

1919
import java.util.List;
2020

21-
import org.apache.log4j.Logger;
22-
2321
import org.apache.cloudstack.api.APICommand;
2422
import org.apache.cloudstack.api.ApiConstants;
2523
import org.apache.cloudstack.api.ApiErrorCode;
26-
import org.apache.cloudstack.api.BaseAsyncCmd;
24+
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
2725
import org.apache.cloudstack.api.Parameter;
2826
import org.apache.cloudstack.api.ServerApiException;
2927
import org.apache.cloudstack.api.response.NetworkACLItemResponse;
3028
import org.apache.cloudstack.context.CallContext;
29+
import org.apache.log4j.Logger;
3130

3231
import com.cloud.event.EventTypes;
3332
import com.cloud.exception.ResourceUnavailableException;
3433
import com.cloud.network.vpc.NetworkACLItem;
3534
import com.cloud.user.Account;
3635

3736
@APICommand(name = "updateNetworkACLItem", description = "Updates ACL Item with specified Id", responseObject = NetworkACLItemResponse.class)
38-
public class UpdateNetworkACLItemCmd extends BaseAsyncCmd {
37+
public class UpdateNetworkACLItemCmd extends BaseAsyncCustomIdCmd {
3938
public static final Logger s_logger = Logger.getLogger(UpdateNetworkACLItemCmd.class.getName());
4039

4140
private static final String s_name = "createnetworkaclresponse";
@@ -165,7 +164,7 @@ public void execute() throws ResourceUnavailableException {
165164
CallContext.current().setEventDetails("Rule Id: " + getId());
166165
NetworkACLItem aclItem =
167166
_networkACLService.updateNetworkACLItem(getId(), getProtocol(), getSourceCidrList(), getTrafficType(), getAction(), getNumber(), getSourcePortStart(),
168-
getSourcePortEnd(), getIcmpCode(), getIcmpType());
167+
getSourcePortEnd(), getIcmpCode(), getIcmpType(), this.getCustomId());
169168
if (aclItem == null) {
170169
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network ACL Item");
171170
}
@@ -174,4 +173,11 @@ public void execute() throws ResourceUnavailableException {
174173
aclResponse.setResponseName(getCommandName());
175174
}
176175

176+
@Override
177+
public void checkUuid(String id, Class<?> cls) {
178+
if (this.getCustomId() != null) {
179+
_uuidMgr.checkUuid(this.getCustomId(), NetworkACLItem.class);
180+
}
181+
}
182+
177183
}

api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.vpc;
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.VpcResponse;
27+
import org.apache.log4j.Logger;
2828

2929
import com.cloud.event.EventTypes;
3030
import com.cloud.network.vpc.Vpc;
3131
import com.cloud.user.Account;
3232

3333
@APICommand(name = "updateVPC", description = "Updates a VPC", responseObject = VpcResponse.class)
34-
public class UpdateVPCCmd extends BaseAsyncCmd {
34+
public class UpdateVPCCmd extends BaseAsyncCustomIdCmd {
3535
public static final Logger s_logger = Logger.getLogger(UpdateVPCCmd.class.getName());
3636
private static final String Name = "updatevpcresponse";
3737

@@ -84,7 +84,7 @@ public long getEntityOwnerId() {
8484

8585
@Override
8686
public void execute() {
87-
Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText());
87+
Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText(), this.getCustomId());
8888
if (result != null) {
8989
VpcResponse response = _responseGenerator.createVpcResponse(result);
9090
response.setResponseName(getCommandName());
@@ -113,4 +113,11 @@ public String getSyncObjType() {
113113
public Long getSyncObjId() {
114114
return getId();
115115
}
116+
117+
@Override
118+
public void checkUuid(String id, Class<?> cls) {
119+
if (this.getCustomId() != null) {
120+
_uuidMgr.checkUuid(this.getCustomId(), Vpc.class);
121+
}
122+
}
116123
}

engine/components-api/src/com/cloud/network/vpc/NetworkACLManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,12 @@ NetworkACLItem createNetworkACLItem(Integer sourcePortStart, Integer sourcePortE
130130
* @param sourcePortEnd
131131
* @param icmpCode
132132
* @param icmpType
133+
* @param customId TODO
133134
* @return
134135
* @throws ResourceUnavailableException
135136
*/
136137
NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, Integer number,
137-
Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType) throws ResourceUnavailableException;
138+
Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String customId) throws ResourceUnavailableException;
138139

139140
/**
140141
* Associates acl with a network and applies the ACLItems

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,8 @@ public void setNumber(int number) {
241241
public void setAction(Action action) {
242242
this.action = action;
243243
}
244+
245+
public void setUuid(String uuid) {
246+
this.uuid = uuid;
247+
}
244248
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@Entity
3232
@Table(name = "vpc")
3333
public class VpcVO implements Vpc {
34+
3435
@Id
3536
@Column(name = "id")
3637
long id;
@@ -177,4 +178,8 @@ public void setRestartRequired(boolean restartRequired) {
177178
public boolean isRestartRequired() {
178179
return restartRequired;
179180
}
181+
182+
public void setUuid(String uuid) {
183+
this.uuid = uuid;
184+
}
180185
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
import javax.ejb.Local;
2323
import javax.inject.Inject;
2424

25-
import org.apache.log4j.Logger;
26-
2725
import org.apache.cloudstack.context.CallContext;
26+
import org.apache.log4j.Logger;
2827

2928
import com.cloud.configuration.ConfigurationManager;
3029
import com.cloud.event.ActionEvent;
@@ -399,7 +398,7 @@ public boolean applyACLToNetwork(long networkId) throws ResourceUnavailableExcep
399398

400399
@Override
401400
public NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action,
402-
Integer number, Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType) throws ResourceUnavailableException {
401+
Integer number, Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String customId) throws ResourceUnavailableException {
403402
NetworkACLItemVO aclItem = _networkACLItemDao.findById(id);
404403
aclItem.setState(State.Add);
405404

@@ -443,6 +442,10 @@ public NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String
443442
aclItem.setIcmpType(icmpType);
444443
}
445444

445+
if (customId != null) {
446+
aclItem.setUuid(customId);
447+
}
448+
446449
if (_networkACLItemDao.update(id, aclItem)) {
447450
if (applyNetworkACL(aclItem.getAclId())) {
448451
return aclItem;

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@
2323
import javax.ejb.Local;
2424
import javax.inject.Inject;
2525

26-
import com.cloud.network.vpc.dao.VpcDao;
27-
import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd;
28-
import org.apache.commons.lang.StringUtils;
29-
import org.apache.log4j.Logger;
30-
import org.springframework.stereotype.Component;
31-
3226
import org.apache.cloudstack.api.ApiErrorCode;
3327
import org.apache.cloudstack.api.ServerApiException;
3428
import org.apache.cloudstack.api.command.user.network.CreateNetworkACLCmd;
29+
import org.apache.cloudstack.api.command.user.network.ListNetworkACLListsCmd;
3530
import org.apache.cloudstack.api.command.user.network.ListNetworkACLsCmd;
3631
import org.apache.cloudstack.context.CallContext;
32+
import org.apache.commons.lang.StringUtils;
33+
import org.apache.log4j.Logger;
34+
import org.springframework.stereotype.Component;
3735

3836
import com.cloud.exception.InvalidParameterValueException;
3937
import com.cloud.exception.ResourceUnavailableException;
@@ -43,6 +41,7 @@
4341
import com.cloud.network.dao.NetworkDao;
4442
import com.cloud.network.dao.NetworkVO;
4543
import com.cloud.network.vpc.dao.NetworkACLDao;
44+
import com.cloud.network.vpc.dao.VpcDao;
4645
import com.cloud.network.vpc.dao.VpcGatewayDao;
4746
import com.cloud.projects.Project.ListProjectResourcesCriteria;
4847
import com.cloud.server.ResourceTag.ResourceObjectType;
@@ -606,7 +605,7 @@ public boolean revokeNetworkACLItem(long ruleId) {
606605

607606
@Override
608607
public NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String> sourceCidrList, NetworkACLItem.TrafficType trafficType, String action,
609-
Integer number, Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType) throws ResourceUnavailableException {
608+
Integer number, Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String newUUID) throws ResourceUnavailableException {
610609
NetworkACLItemVO aclItem = _networkACLItemDao.findById(id);
611610
if (aclItem == null) {
612611
throw new InvalidParameterValueException("Unable to find ACL Item cannot be found");
@@ -635,7 +634,7 @@ public NetworkACLItem updateNetworkACLItem(Long id, String protocol, List<String
635634
validateNetworkACLItem((sourcePortStart == null) ? aclItem.getSourcePortStart() : sourcePortStart, (sourcePortEnd == null) ? aclItem.getSourcePortEnd()
636635
: sourcePortEnd, sourceCidrList, protocol, icmpCode, (icmpType == null) ? aclItem.getIcmpType() : icmpType, action, number);
637636

638-
return _networkAclMgr.updateNetworkACLItem(id, protocol, sourceCidrList, trafficType, action, number, sourcePortStart, sourcePortEnd, icmpCode, icmpType);
637+
return _networkAclMgr.updateNetworkACLItem(id, protocol, sourceCidrList, trafficType, action, number, sourcePortStart, sourcePortEnd, icmpCode, icmpType, newUUID);
639638
}
640639

641640
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import javax.inject.Inject;
3333
import javax.naming.ConfigurationException;
3434

35-
import org.apache.log4j.Logger;
36-
3735
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
3836
import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd;
3937
import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
@@ -42,6 +40,7 @@
4240
import org.apache.cloudstack.framework.config.ConfigDepot;
4341
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
4442
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
43+
import org.apache.log4j.Logger;
4544

4645
import com.cloud.configuration.Config;
4746
import com.cloud.configuration.ConfigurationManager;
@@ -770,7 +769,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
770769

771770
@Override
772771
@ActionEvent(eventType = EventTypes.EVENT_VPC_UPDATE, eventDescription = "updating vpc")
773-
public Vpc updateVpc(long vpcId, String vpcName, String displayText) {
772+
public Vpc updateVpc(long vpcId, String vpcName, String displayText, String customId) {
774773
CallContext.current().setEventDetails(" Id: " + vpcId);
775774
Account caller = CallContext.current().getCallingAccount();
776775

@@ -792,6 +791,10 @@ public Vpc updateVpc(long vpcId, String vpcName, String displayText) {
792791
vpc.setDisplayText(displayText);
793792
}
794793

794+
if (customId != null) {
795+
vpc.setUuid(customId);
796+
}
797+
795798
if (_vpcDao.update(vpcId, vpc)) {
796799
s_logger.debug("Updated VPC id=" + vpcId);
797800
return _vpcDao.findById(vpcId);

0 commit comments

Comments
 (0)