Skip to content

Commit d3cad42

Browse files
committed
Merge release branch 4.18 to main
* 4.18: server: Initial new vpnuser state (#8268) UI: Removed redundant IP Address Column when create Port forwarding rules (#8275) UI: Removed ICMP input fields for protocol number from ACL List rules modal (#8253) server: check if there are active nics before network GC (#8204)
2 parents b0910fc + 7243946 commit d3cad42

File tree

7 files changed

+37
-23
lines changed

7 files changed

+37
-23
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ public void execute() {
125125
vpnResponse.setId(vpnUser.getUuid());
126126
vpnResponse.setUserName(vpnUser.getUsername());
127127
vpnResponse.setAccountName(account.getAccountName());
128+
// re-retrieve the vpnuser, as the call to `applyVpnUsers` might have changed the state
129+
vpnUser = _entityMgr.findById(VpnUser.class, getEntityId());
130+
vpnResponse.setState(vpnUser.getState().toString());
128131

129132
Domain domain = _entityMgr.findById(Domain.class, account.getDomainId());
130133
if (domain != null) {

api/src/main/java/org/apache/cloudstack/api/response/VpnUsersResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class VpnUsersResponse extends BaseResponse implements ControlledEntityRe
5757
private String projectName;
5858

5959
@SerializedName(ApiConstants.STATE)
60-
@Param(description = "the state of the Vpn User")
60+
@Param(description = "the state of the Vpn User, can be 'Add', 'Revoke' or 'Active'.")
6161
private String state;
6262

6363
public void setId(String id) {

engine/schema/src/main/java/com/cloud/vm/dao/NicDao.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public interface NicDao extends GenericDao<NicVO, Long> {
7979

8080
List<NicVO> listByNetworkIdTypeAndGatewayAndBroadcastUri(long networkId, VirtualMachine.Type vmType, String gateway, URI broadcastUri);
8181

82-
int countNicsForStartingVms(long networkId);
82+
int countNicsForNonStoppedVms(long networkId);
83+
84+
int countNicsForNonStoppedRunningVrs(long networkId);
8385

8486
NicVO getControlNicForVM(long vmId);
8587

engine/schema/src/main/java/com/cloud/vm/dao/NicDaoImpl.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
4444
private GenericSearchBuilder<NicVO, String> IpSearch;
4545
private SearchBuilder<NicVO> NonReleasedSearch;
4646
private GenericSearchBuilder<NicVO, Integer> deviceIdSearch;
47-
private GenericSearchBuilder<NicVO, Integer> CountByForStartingVms;
47+
private GenericSearchBuilder<NicVO, Integer> CountByForNonStoppedVms;
4848
private SearchBuilder<NicVO> PeerRouterSearch;
4949

5050
@Inject
@@ -91,14 +91,16 @@ protected void init() {
9191
deviceIdSearch.and("instance", deviceIdSearch.entity().getInstanceId(), Op.EQ);
9292
deviceIdSearch.done();
9393

94-
CountByForStartingVms = createSearchBuilder(Integer.class);
95-
CountByForStartingVms.select(null, Func.COUNT, CountByForStartingVms.entity().getId());
96-
CountByForStartingVms.and("networkId", CountByForStartingVms.entity().getNetworkId(), Op.EQ);
97-
CountByForStartingVms.and("removed", CountByForStartingVms.entity().getRemoved(), Op.NULL);
94+
CountByForNonStoppedVms = createSearchBuilder(Integer.class);
95+
CountByForNonStoppedVms.select(null, Func.COUNT, CountByForNonStoppedVms.entity().getId());
96+
CountByForNonStoppedVms.and("vmType", CountByForNonStoppedVms.entity().getVmType(), Op.EQ);
97+
CountByForNonStoppedVms.and("vmTypeNEQ", CountByForNonStoppedVms.entity().getVmType(), Op.NEQ);
98+
CountByForNonStoppedVms.and("networkId", CountByForNonStoppedVms.entity().getNetworkId(), Op.EQ);
99+
CountByForNonStoppedVms.and("removed", CountByForNonStoppedVms.entity().getRemoved(), Op.NULL);
98100
SearchBuilder<VMInstanceVO> join1 = _vmDao.createSearchBuilder();
99-
join1.and("state", join1.entity().getState(), Op.EQ);
100-
CountByForStartingVms.join("vm", join1, CountByForStartingVms.entity().getInstanceId(), join1.entity().getId(), JoinBuilder.JoinType.INNER);
101-
CountByForStartingVms.done();
101+
join1.and("state", join1.entity().getState(), Op.IN);
102+
CountByForNonStoppedVms.join("vm", join1, CountByForNonStoppedVms.entity().getInstanceId(), join1.entity().getId(), JoinBuilder.JoinType.INNER);
103+
CountByForNonStoppedVms.done();
102104

103105
PeerRouterSearch = createSearchBuilder();
104106
PeerRouterSearch.and("instanceId", PeerRouterSearch.entity().getInstanceId(), Op.NEQ);
@@ -346,10 +348,21 @@ public List<NicVO> listPlaceholderNicsByNetworkIdAndVmType(long networkId, Virtu
346348
}
347349

348350
@Override
349-
public int countNicsForStartingVms(long networkId) {
350-
SearchCriteria<Integer> sc = CountByForStartingVms.create();
351+
public int countNicsForNonStoppedVms(long networkId) {
352+
SearchCriteria<Integer> sc = CountByForNonStoppedVms.create();
351353
sc.setParameters("networkId", networkId);
352-
sc.setJoinParameters("vm", "state", VirtualMachine.State.Starting);
354+
sc.setParameters("vmType", VirtualMachine.Type.User);
355+
sc.setJoinParameters("vm", "state", new Object[] {VirtualMachine.State.Starting, VirtualMachine.State.Running, VirtualMachine.State.Stopping, VirtualMachine.State.Migrating});
356+
List<Integer> results = customSearch(sc, null);
357+
return results.get(0);
358+
}
359+
360+
@Override
361+
public int countNicsForNonStoppedRunningVrs(long networkId) {
362+
SearchCriteria<Integer> sc = CountByForNonStoppedVms.create();
363+
sc.setParameters("networkId", networkId);
364+
sc.setParameters("vmTypeNEQ", VirtualMachine.Type.User);
365+
sc.setJoinParameters("vm", "state", new Object[] {VirtualMachine.State.Starting, VirtualMachine.State.Stopping, VirtualMachine.State.Migrating});
353366
List<Integer> results = customSearch(sc, null);
354367
return results.get(0);
355368
}

server/src/main/java/com/cloud/network/NetworkModelImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,10 +2559,11 @@ public boolean isNetworkReadyForGc(long networkId) {
25592559
return false;
25602560
}
25612561

2562-
//if the network has vms in Starting state (nics for those might not be allocated yet as Starting state also used when vm is being Created)
2563-
//don't GC
2564-
if (_nicDao.countNicsForStartingVms(networkId) > 0) {
2565-
s_logger.debug("Network id=" + networkId + " is not ready for GC as it has vms that are Starting at the moment");
2562+
// if the network has user vms in Starting/Stopping/Migrating/Running state, or VRs in Starting/Stopping/Migrating state, don't GC
2563+
// The active nics count (nics_count in op_networks table) might be wrong due to some reasons, should check the state of vms as well.
2564+
// (nics for Starting VMs might not be allocated yet as Starting state also used when vm is being Created)
2565+
if (_nicDao.countNicsForNonStoppedVms(networkId) > 0 || _nicDao.countNicsForNonStoppedRunningVrs(networkId) > 0) {
2566+
s_logger.debug("Network id=" + networkId + " is not ready for GC as it has vms that are not Stopped at the moment");
25662567
return false;
25672568
}
25682569

ui/src/views/network/AclListRulesTab.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
<a-input v-model:value="form.protocolnumber" />
212212
</a-form-item>
213213

214-
<div v-if="['icmp', 'protocolnumber'].includes(form.protocol)">
214+
<div v-if="form.protocol === 'icmp'">
215215
<a-form-item :label="$t('label.icmptype')" ref="icmptype" name="icmptype">
216216
<a-input v-model:value="form.icmptype" :placeholder="$t('icmp.type.desc')" />
217217
</a-form-item>

ui/src/views/network/PortForwarding.vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,6 @@ export default {
432432
title: this.$t('label.displayname'),
433433
dataIndex: 'displayname'
434434
},
435-
{
436-
title: this.$t('label.ip'),
437-
dataIndex: 'ip',
438-
width: 100
439-
},
440435
{
441436
title: this.$t('label.account'),
442437
dataIndex: 'account'

0 commit comments

Comments
 (0)