Skip to content

Commit c087de4

Browse files
committed
Merge branch '4.19'
2 parents 046870e + 2e4dd69 commit c087de4

File tree

4 files changed

+98
-63
lines changed

4 files changed

+98
-63
lines changed

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

+63-51
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

+2-2
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);

ui/src/views/compute/EditVM.vue

+29-6
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
}"
8585
:options="groups.opts" />
8686
</a-form-item>
87-
<a-form-item>
87+
<a-form-item v-if="userDataEnabled">
8888
<template #label>
8989
<tooltip-label :title="$t('label.userdata')" :tooltip="apiParams.userdata.description"/>
9090
</template>
@@ -150,6 +150,7 @@ export default {
150150
return {
151151
serviceOffering: {},
152152
template: {},
153+
userDataEnabled: false,
153154
securityGroupsEnabled: false,
154155
dynamicScalingVmConfig: false,
155156
loading: false,
@@ -297,15 +298,37 @@ export default {
297298
return decodedData.toString('utf-8')
298299
},
299300
fetchUserData () {
300-
const params = {
301-
id: this.resource.id,
302-
userdata: true
301+
let networkId
302+
this.resource.nic.forEach(nic => {
303+
if (nic.isdefault) {
304+
networkId = nic.networkid
305+
}
306+
})
307+
if (!networkId) {
308+
return
309+
}
310+
const listNetworkParams = {
311+
id: networkId,
312+
listall: true
303313
}
314+
api(`listNetworks`, listNetworkParams).then(json => {
315+
json.listnetworksresponse.network[0].service.forEach(service => {
316+
if (service.name === 'UserData') {
317+
this.userDataEnabled = true
304318
305-
api('listVirtualMachines', params).then(json => {
306-
this.form.userdata = this.decodeUserData(json.listvirtualmachinesresponse.virtualmachine[0].userdata || '')
319+
const listVmParams = {
320+
id: this.resource.id,
321+
userdata: true,
322+
listall: true
323+
}
324+
api('listVirtualMachines', listVmParams).then(json => {
325+
this.form.userdata = atob(json.listvirtualmachinesresponse.virtualmachine[0].userdata || '')
326+
})
327+
}
328+
})
307329
})
308330
},
331+
309332
handleSubmit () {
310333
this.formRef.value.validate().then(() => {
311334
const values = toRaw(this.form)

ui/src/views/network/VpcTab.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -800,12 +800,12 @@ export default {
800800
801801
this.formRef.value.validate().then(() => {
802802
const values = toRaw(this.form)
803-
804-
api('createVpnConnection', {
805-
s2svpngatewayid: this.vpnGateways[0].id,
803+
const params = {
804+
s2svpngatewayid: this.vpnGateways[0] ? this.vpnGateways[0].id : null,
806805
s2scustomergatewayid: values.vpncustomergateway,
807806
passive: values.passive ? values.passive : false
808-
}).then(response => {
807+
}
808+
api('createVpnConnection', params).then(response => {
809809
this.$pollJob({
810810
jobId: response.createvpnconnectionresponse.jobid,
811811
title: this.$t('label.vpn.connection'),

0 commit comments

Comments
 (0)