Skip to content

Commit a83734f

Browse files
committed
Merge remote-tracking branch 'upstream/main' into apik
2 parents 113c700 + d6181d5 commit a83734f

File tree

8 files changed

+112
-77
lines changed

8 files changed

+112
-77
lines changed

debian/control

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Section: libs
33
Priority: extra
44
Maintainer: Wido den Hollander <[email protected]>
55
Build-Depends: debhelper (>= 9), openjdk-17-jdk | java17-sdk | java17-jdk | zulu-17 | openjdk-11-jdk | java11-sdk | java11-jdk | zulu-11, genisoimage,
6-
python-mysql.connector | python3-mysql.connector, maven (>= 3) | maven3,
6+
python-mysql.connector | python3-mysql.connector | mysql-connector-python-py3, maven (>= 3) | maven3,
77
python (>= 2.7) | python2 (>= 2.7), python3 (>= 3), python-setuptools, python3-setuptools,
88
nodejs (>= 12), lsb-release, dh-systemd | debhelper (>= 13)
99
Standards-Version: 3.8.1
@@ -17,7 +17,7 @@ Description: A common package which contains files which are shared by several C
1717

1818
Package: cloudstack-management
1919
Architecture: all
20-
Depends: ${python3:Depends}, openjdk-17-jre-headless | java17-runtime-headless | java17-runtime | zulu-17, cloudstack-common (= ${source:Version}), net-tools, sudo, python3-mysql.connector, augeas-tools, mysql-client | mariadb-client, adduser, bzip2, ipmitool, file, gawk, iproute2, qemu-utils, rng-tools, python3-dnspython, lsb-release, init-system-helpers (>= 1.14~), python3-setuptools
20+
Depends: ${python3:Depends}, openjdk-17-jre-headless | java17-runtime-headless | java17-runtime | zulu-17, cloudstack-common (= ${source:Version}), net-tools, sudo, python3-mysql.connector | mysql-connector-python-py3, augeas-tools, mysql-client | mariadb-client, adduser, bzip2, ipmitool, file, gawk, iproute2, qemu-utils, rng-tools, python3-dnspython, lsb-release, init-system-helpers (>= 1.14~), python3-setuptools
2121
Conflicts: cloud-server, cloud-client, cloud-client-ui
2222
Description: CloudStack server library
2323
The CloudStack management server

server/src/main/java/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
import javax.inject.Inject;
2424
import javax.naming.ConfigurationException;
2525

26-
import org.apache.cloudstack.annotation.AnnotationService;
27-
import org.apache.cloudstack.annotation.dao.AnnotationDao;
26+
import org.apache.commons.collections.CollectionUtils;
2827
import org.springframework.stereotype.Component;
2928

29+
import org.apache.cloudstack.annotation.AnnotationService;
30+
import org.apache.cloudstack.annotation.dao.AnnotationDao;
3031
import org.apache.cloudstack.api.command.user.vpn.CreateVpnConnectionCmd;
3132
import org.apache.cloudstack.api.command.user.vpn.CreateVpnCustomerGatewayCmd;
3233
import org.apache.cloudstack.api.command.user.vpn.CreateVpnGatewayCmd;
@@ -45,7 +46,6 @@
4546
import com.cloud.event.ActionEvent;
4647
import com.cloud.event.EventTypes;
4748
import com.cloud.exception.InvalidParameterValueException;
48-
import com.cloud.exception.NetworkRuleConflictException;
4949
import com.cloud.exception.PermissionDeniedException;
5050
import com.cloud.exception.ResourceUnavailableException;
5151
import com.cloud.network.Site2SiteCustomerGateway;
@@ -106,7 +106,6 @@ public class Site2SiteVpnManagerImpl extends ManagerBase implements Site2SiteVpn
106106
@Inject
107107
private AnnotationDao annotationDao;
108108

109-
String _name;
110109
int _connLimit;
111110
int _subnetsLimit;
112111

@@ -253,35 +252,23 @@ public Site2SiteCustomerGateway createCustomerGateway(CreateVpnCustomerGatewayCm
253252

254253
@Override
255254
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_CREATE, eventDescription = "creating s2s vpn connection", create = true)
256-
public Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) throws NetworkRuleConflictException {
255+
public Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) {
257256
Account caller = CallContext.current().getCallingAccount();
258257
Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
259258

260259
//Verify that caller can perform actions in behalf of vpc owner
261260
_accountMgr.checkAccess(caller, null, false, owner);
262261

263262
Long customerGatewayId = cmd.getCustomerGatewayId();
264-
Site2SiteCustomerGateway customerGateway = _customerGatewayDao.findById(customerGatewayId);
265-
if (customerGateway == null) {
266-
throw new InvalidParameterValueException("Unable to found specified Site to Site VPN customer gateway " + customerGatewayId + " !");
267-
}
268-
_accountMgr.checkAccess(caller, null, false, customerGateway);
263+
Site2SiteCustomerGateway customerGateway = getAndValidateSite2SiteCustomerGateway(customerGatewayId, caller);
269264

270265
Long vpnGatewayId = cmd.getVpnGatewayId();
271-
Site2SiteVpnGateway vpnGateway = _vpnGatewayDao.findById(vpnGatewayId);
272-
if (vpnGateway == null) {
273-
throw new InvalidParameterValueException("Unable to found specified Site to Site VPN gateway " + vpnGatewayId + " !");
274-
}
275-
_accountMgr.checkAccess(caller, null, false, vpnGateway);
266+
Site2SiteVpnGateway vpnGateway = getAndValidateSite2SiteVpnGateway(vpnGatewayId, caller);
276267

277-
if (customerGateway.getAccountId() != vpnGateway.getAccountId() || customerGateway.getDomainId() != vpnGateway.getDomainId()) {
278-
throw new InvalidParameterValueException("VPN connection can only be esitablished between same account's VPN gateway and customer gateway!");
279-
}
268+
validateVpnConnectionOfTheRightAccount(customerGateway, vpnGateway);
269+
validateVpnConnectionDoesntExist(vpnGatewayId, customerGatewayId);
270+
validatePrerequisiteVpnGateway(vpnGateway);
280271

281-
if (_vpnConnectionDao.findByVpnGatewayIdAndCustomerGatewayId(vpnGatewayId, customerGatewayId) != null) {
282-
throw new InvalidParameterValueException("The vpn connection with customer gateway id " + customerGatewayId + " and vpn gateway id " + vpnGatewayId +
283-
" already existed!");
284-
}
285272
String[] cidrList = customerGateway.getGuestCidrList().split(",");
286273

287274
// Remote sub nets cannot overlap VPC's sub net
@@ -324,13 +311,51 @@ public Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) th
324311
return conn;
325312
}
326313

314+
private Site2SiteCustomerGateway getAndValidateSite2SiteCustomerGateway(Long customerGatewayId, Account caller) {
315+
Site2SiteCustomerGateway customerGateway = _customerGatewayDao.findById(customerGatewayId);
316+
if (customerGateway == null) {
317+
throw new InvalidParameterValueException(String.format("Unable to find specified Site to Site VPN customer gateway %s !", customerGatewayId));
318+
}
319+
_accountMgr.checkAccess(caller, null, false, customerGateway);
320+
return customerGateway;
321+
}
322+
323+
private Site2SiteVpnGateway getAndValidateSite2SiteVpnGateway(Long vpnGatewayId, Account caller) {
324+
Site2SiteVpnGateway vpnGateway = _vpnGatewayDao.findById(vpnGatewayId);
325+
if (vpnGateway == null) {
326+
throw new InvalidParameterValueException(String.format("Unable to find specified Site to Site VPN gateway %s !", vpnGatewayId));
327+
}
328+
_accountMgr.checkAccess(caller, null, false, vpnGateway);
329+
return vpnGateway;
330+
}
331+
332+
private void validateVpnConnectionOfTheRightAccount(Site2SiteCustomerGateway customerGateway, Site2SiteVpnGateway vpnGateway) {
333+
if (customerGateway.getAccountId() != vpnGateway.getAccountId() || customerGateway.getDomainId() != vpnGateway.getDomainId()) {
334+
throw new InvalidParameterValueException("VPN connection can only be established between same account's VPN gateway and customer gateway!");
335+
}
336+
}
337+
338+
private void validateVpnConnectionDoesntExist(Long vpnGatewayId, Long customerGatewayId) {
339+
if (_vpnConnectionDao.findByVpnGatewayIdAndCustomerGatewayId(vpnGatewayId, customerGatewayId) != null) {
340+
throw new InvalidParameterValueException("The vpn connection with customer gateway id " + customerGatewayId + " and vpn gateway id " + vpnGatewayId +
341+
" already existed!");
342+
}
343+
}
344+
345+
private void validatePrerequisiteVpnGateway(Site2SiteVpnGateway vpnGateway) {
346+
// check if gateway has been defined on the VPC
347+
if (_vpnGatewayDao.findByVpcId(vpnGateway.getVpcId()) == null) {
348+
throw new InvalidParameterValueException("we can not create a VPN connection for a VPC that does not have a VPN gateway defined");
349+
}
350+
}
351+
327352
@Override
328353
@DB
329354
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_CREATE, eventDescription = "starting s2s vpn connection", async = true)
330355
public Site2SiteVpnConnection startVpnConnection(long id) throws ResourceUnavailableException {
331356
Site2SiteVpnConnectionVO conn = _vpnConnectionDao.acquireInLockTable(id);
332357
if (conn == null) {
333-
throw new CloudRuntimeException("Unable to acquire lock on " + conn);
358+
throw new CloudRuntimeException("Unable to acquire lock for starting of VPN connection with ID " + id);
334359
}
335360
try {
336361
if (conn.getState() != State.Pending && conn.getState() != State.Disconnected) {
@@ -380,19 +405,15 @@ public boolean deleteCustomerGateway(DeleteVpnCustomerGatewayCmd cmd) {
380405
Account caller = CallContext.current().getCallingAccount();
381406

382407
Long id = cmd.getId();
383-
Site2SiteCustomerGateway customerGateway = _customerGatewayDao.findById(id);
384-
if (customerGateway == null) {
385-
throw new InvalidParameterValueException("Fail to find customer gateway with " + id + " !");
386-
}
387-
_accountMgr.checkAccess(caller, null, false, customerGateway);
408+
Site2SiteCustomerGateway customerGateway = getAndValidateSite2SiteCustomerGateway(id, caller);
388409

389410
return doDeleteCustomerGateway(customerGateway);
390411
}
391412

392413
protected boolean doDeleteCustomerGateway(Site2SiteCustomerGateway gw) {
393414
long id = gw.getId();
394415
List<Site2SiteVpnConnectionVO> vpnConnections = _vpnConnectionDao.listByCustomerGatewayId(id);
395-
if (vpnConnections != null && vpnConnections.size() != 0) {
416+
if (!CollectionUtils.isEmpty(vpnConnections)) {
396417
throw new InvalidParameterValueException("Unable to delete VPN customer gateway with id " + id + " because there is still related VPN connections!");
397418
}
398419
annotationDao.removeByEntityType(AnnotationService.EntityType.VPN_CUSTOMER_GATEWAY.name(), gw.getUuid());
@@ -402,7 +423,7 @@ protected boolean doDeleteCustomerGateway(Site2SiteCustomerGateway gw) {
402423

403424
protected void doDeleteVpnGateway(Site2SiteVpnGateway gw) {
404425
List<Site2SiteVpnConnectionVO> conns = _vpnConnectionDao.listByVpnGatewayId(gw.getId());
405-
if (conns != null && conns.size() != 0) {
426+
if (!CollectionUtils.isEmpty(conns)) {
406427
throw new InvalidParameterValueException("Unable to delete VPN gateway " + gw.getId() + " because there is still related VPN connections!");
407428
}
408429
_vpnGatewayDao.remove(gw.getId());
@@ -415,12 +436,7 @@ public boolean deleteVpnGateway(DeleteVpnGatewayCmd cmd) {
415436
Account caller = CallContext.current().getCallingAccount();
416437

417438
Long id = cmd.getId();
418-
Site2SiteVpnGateway vpnGateway = _vpnGatewayDao.findById(id);
419-
if (vpnGateway == null) {
420-
throw new InvalidParameterValueException("Fail to find vpn gateway with " + id + " !");
421-
}
422-
423-
_accountMgr.checkAccess(caller, null, false, vpnGateway);
439+
Site2SiteVpnGateway vpnGateway = getAndValidateSite2SiteVpnGateway(id, caller);
424440

425441
doDeleteVpnGateway(vpnGateway);
426442
return true;
@@ -576,7 +592,7 @@ public boolean deleteVpnConnection(DeleteVpnConnectionCmd cmd) throws ResourceUn
576592
private void stopVpnConnection(Long id) throws ResourceUnavailableException {
577593
Site2SiteVpnConnectionVO conn = _vpnConnectionDao.acquireInLockTable(id);
578594
if (conn == null) {
579-
throw new CloudRuntimeException("Unable to acquire lock on " + conn);
595+
throw new CloudRuntimeException("Unable to acquire lock for stopping of VPN connection with ID " + id);
580596
}
581597
try {
582598
if (conn.getState() == State.Pending) {
@@ -637,10 +653,9 @@ public Pair<List<? extends Site2SiteCustomerGateway>, Integer> searchForCustomer
637653
String keyword = cmd.getKeyword();
638654

639655
Account caller = CallContext.current().getCallingAccount();
640-
List<Long> permittedAccounts = new ArrayList<Long>();
656+
List<Long> permittedAccounts = new ArrayList<>();
641657

642-
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
643-
ListProjectResourcesCriteria>(domainId, isRecursive, null);
658+
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
644659
_accountMgr.buildACLSearchParameters(caller, id, accountName, cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false);
645660
domainId = domainIdRecursiveListProject.first();
646661
isRecursive = domainIdRecursiveListProject.second();
@@ -665,7 +680,7 @@ public Pair<List<? extends Site2SiteCustomerGateway>, Integer> searchForCustomer
665680
}
666681

667682
Pair<List<Site2SiteCustomerGatewayVO>, Integer> result = _customerGatewayDao.searchAndCount(sc, searchFilter);
668-
return new Pair<List<? extends Site2SiteCustomerGateway>, Integer>(result.first(), result.second());
683+
return new Pair<>(result.first(), result.second());
669684
}
670685

671686
@Override
@@ -682,10 +697,9 @@ public Pair<List<? extends Site2SiteVpnGateway>, Integer> searchForVpnGateways(L
682697
long pageSizeVal = cmd.getPageSizeVal();
683698

684699
Account caller = CallContext.current().getCallingAccount();
685-
List<Long> permittedAccounts = new ArrayList<Long>();
700+
List<Long> permittedAccounts = new ArrayList<>();
686701

687-
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
688-
ListProjectResourcesCriteria>(domainId, isRecursive, null);
702+
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
689703
_accountMgr.buildACLSearchParameters(caller, id, accountName, cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false);
690704
domainId = domainIdRecursiveListProject.first();
691705
isRecursive = domainIdRecursiveListProject.second();
@@ -715,7 +729,7 @@ public Pair<List<? extends Site2SiteVpnGateway>, Integer> searchForVpnGateways(L
715729
}
716730

717731
Pair<List<Site2SiteVpnGatewayVO>, Integer> result = _vpnGatewayDao.searchAndCount(sc, searchFilter);
718-
return new Pair<List<? extends Site2SiteVpnGateway>, Integer>(result.first(), result.second());
732+
return new Pair<>(result.first(), result.second());
719733
}
720734

721735
@Override
@@ -732,10 +746,9 @@ public Pair<List<? extends Site2SiteVpnConnection>, Integer> searchForVpnConnect
732746
long pageSizeVal = cmd.getPageSizeVal();
733747

734748
Account caller = CallContext.current().getCallingAccount();
735-
List<Long> permittedAccounts = new ArrayList<Long>();
749+
List<Long> permittedAccounts = new ArrayList<>();
736750

737-
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean,
738-
ListProjectResourcesCriteria>(domainId, isRecursive, null);
751+
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
739752
_accountMgr.buildACLSearchParameters(caller, id, accountName, cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false);
740753
domainId = domainIdRecursiveListProject.first();
741754
isRecursive = domainIdRecursiveListProject.second();
@@ -769,7 +782,7 @@ public Pair<List<? extends Site2SiteVpnConnection>, Integer> searchForVpnConnect
769782
}
770783

771784
Pair<List<Site2SiteVpnConnectionVO>, Integer> result = _vpnConnectionDao.searchAndCount(sc, searchFilter);
772-
return new Pair<List<? extends Site2SiteVpnConnection>, Integer>(result.first(), result.second());
785+
return new Pair<>(result.first(), result.second());
773786
}
774787

775788
@Override
@@ -816,7 +829,7 @@ public void markDisconnectVpnConnByVpc(long vpcId) {
816829

817830
@Override
818831
public List<Site2SiteVpnConnectionVO> getConnectionsForRouter(DomainRouterVO router) {
819-
List<Site2SiteVpnConnectionVO> conns = new ArrayList<Site2SiteVpnConnectionVO>();
832+
List<Site2SiteVpnConnectionVO> conns = new ArrayList<>();
820833
// One router for one VPC
821834
Long vpcId = router.getVpcId();
822835
if (router.getVpcId() == null) {
@@ -829,7 +842,6 @@ public List<Site2SiteVpnConnectionVO> getConnectionsForRouter(DomainRouterVO rou
829842
@Override
830843
public boolean deleteCustomerGatewayByAccount(long accountId) {
831844
boolean result = true;
832-
;
833845
List<Site2SiteCustomerGatewayVO> gws = _customerGatewayDao.listByAccountId(accountId);
834846
for (Site2SiteCustomerGatewayVO gw : gws) {
835847
result = result & doDeleteCustomerGateway(gw);

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4859,7 +4859,7 @@ public Pair<List<? extends UserData>, Integer> listUserDatas(final ListUserDataC
48594859

48604860
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
48614861
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
4862-
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
4862+
sb.and("keyword", sb.entity().getName(), SearchCriteria.Op.LIKE);
48634863
final SearchCriteria<UserDataVO> sc = sb.create();
48644864
_accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
48654865

@@ -4872,7 +4872,7 @@ public Pair<List<? extends UserData>, Integer> listUserDatas(final ListUserDataC
48724872
}
48734873

48744874
if (keyword != null) {
4875-
sc.setParameters("name", "%" + keyword + "%");
4875+
sc.setParameters("keyword", "%" + keyword + "%");
48764876
}
48774877

48784878
final Pair<List<UserDataVO>, Integer> result = userDataDao.searchAndCount(sc, searchFilter);

test/integration/smoke/test_usage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(self):
9595
"iso": {
9696
"displaytext": "Test ISO",
9797
"name": "Test ISO",
98-
"url": "http://people.apache.org/~tsp/dummy.iso",
98+
"url": "http://download.cloudstack.org/testing/marvin/dummy.iso",
9999
# Source URL where ISO is located
100100
"isextractable": True,
101101
"isfeatured": True,

ui/public/locales/pt_BR.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,8 +1482,8 @@
14821482
"label.setting": "Configura\u00e7\u00e3o",
14831483
"label.settings": "Configura\u00e7\u00f5es",
14841484
"label.setup": "Configura\u00e7\u00e3o",
1485-
"label.shared": "Compatilhado",
1486-
"label.sharedexecutable": "Compatilhado",
1485+
"label.shared": "Compartilhado",
1486+
"label.sharedexecutable": "Compartilhado",
14871487
"label.sharedmountpoint": "SharedMountPoint",
14881488
"label.sharedrouterip": "Endere\u00e7os IPv4 para o roteador dentro da rede compartilhada",
14891489
"label.sharedrouteripv6": "Endere\u00e7os IPv6 para o roteador dentro da rede compartilhada",

0 commit comments

Comments
 (0)