Skip to content

Commit b98a95b

Browse files
committed
Merge remote-tracking branch 'apache/main' into add-cleanupextraconfig-updatevm
2 parents e1772fe + 04b58ac commit b98a95b

File tree

103 files changed

+4108
-911
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+4108
-911
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ public class EventTypes {
503503
public static final String EVENT_S2S_VPN_CUSTOMER_GATEWAY_CREATE = "VPN.S2S.CUSTOMER.GATEWAY.CREATE";
504504
public static final String EVENT_S2S_VPN_CUSTOMER_GATEWAY_DELETE = "VPN.S2S.CUSTOMER.GATEWAY.DELETE";
505505
public static final String EVENT_S2S_VPN_CUSTOMER_GATEWAY_UPDATE = "VPN.S2S.CUSTOMER.GATEWAY.UPDATE";
506+
public static final String EVENT_S2S_VPN_GATEWAY_OBSOLETE_PARAMS = "VPN.S2S.GATEWAY.OBSOLETE.PARAMS";
506507
public static final String EVENT_S2S_VPN_CONNECTION_CREATE = "VPN.S2S.CONNECTION.CREATE";
507508
public static final String EVENT_S2S_VPN_CONNECTION_DELETE = "VPN.S2S.CONNECTION.DELETE";
508509
public static final String EVENT_S2S_VPN_CONNECTION_RESET = "VPN.S2S.CONNECTION.RESET";
@@ -1151,6 +1152,7 @@ public class EventTypes {
11511152
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_CREATE, Site2SiteCustomerGateway.class);
11521153
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_DELETE, Site2SiteCustomerGateway.class);
11531154
entityEventDetails.put(EVENT_S2S_VPN_CUSTOMER_GATEWAY_UPDATE, Site2SiteCustomerGateway.class);
1155+
entityEventDetails.put(EVENT_S2S_VPN_GATEWAY_OBSOLETE_PARAMS, Site2SiteCustomerGateway.class);
11541156
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_CREATE, Site2SiteVpnConnection.class);
11551157
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_DELETE, Site2SiteVpnConnection.class);
11561158
entityEventDetails.put(EVENT_S2S_VPN_CONNECTION_RESET, Site2SiteVpnConnection.class);

api/src/main/java/com/cloud/network/NetworkModel.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ public interface NetworkModel {
125125
*/
126126
String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException;
127127

128+
String getUniqueMacAddress(long macAddress, long networkId, long datacenterId) throws InsufficientAddressCapacityException;
129+
130+
boolean isMACUnique(String mac, long networkId);
131+
128132
PublicIpAddress getPublicIpAddress(long ipAddressId);
129133

130134
List<? extends Vlan> listPodVlans(long podId);
@@ -364,4 +368,8 @@ List<String[]> generateVmData(String userData, String userDataDetails, String se
364368

365369
boolean checkSecurityGroupSupportForNetwork(Account account, DataCenter zone, List<Long> networkIds,
366370
List<Long> securityGroupsIds);
371+
372+
default long getMacIdentifier(Long dataCenterId) {
373+
return 0;
374+
}
367375
}

api/src/main/java/com/cloud/user/AccountService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.cloud.offering.NetworkOffering;
3737
import com.cloud.offering.ServiceOffering;
3838
import org.apache.cloudstack.auth.UserTwoFactorAuthenticator;
39+
import org.apache.cloudstack.backup.BackupOffering;
3940

4041
public interface AccountService {
4142

@@ -115,6 +116,8 @@ User createUser(String userName, String password, String firstName, String lastN
115116

116117
void checkAccess(Account account, VpcOffering vof, DataCenter zone) throws PermissionDeniedException;
117118

119+
void checkAccess(Account account, BackupOffering bof) throws PermissionDeniedException;
120+
118121
void checkAccess(User user, ControlledEntity entity);
119122

120123
void checkAccess(Account account, AccessType accessType, boolean sameOwner, String apiName, ControlledEntity... entities) throws PermissionDeniedException;

api/src/main/java/org/apache/cloudstack/acl/SecurityChecker.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.cloud.user.User;
2828
import com.cloud.utils.component.Adapter;
2929

30+
import org.apache.cloudstack.backup.BackupOffering;
31+
3032
/**
3133
* SecurityChecker checks the ownership and access control to objects within
3234
*/
@@ -145,4 +147,6 @@ boolean checkAccess(Account caller, AccessType accessType, String action, Contro
145147
boolean checkAccess(Account account, NetworkOffering nof, DataCenter zone) throws PermissionDeniedException;
146148

147149
boolean checkAccess(Account account, VpcOffering vof, DataCenter zone) throws PermissionDeniedException;
150+
151+
boolean checkAccess(Account account, BackupOffering bof) throws PermissionDeniedException;
148152
}

api/src/main/java/org/apache/cloudstack/alert/AlertService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ private AlertType(short type, String name, boolean isDefault) {
7474
public static final AlertType ALERT_TYPE_VR_PUBLIC_IFACE_MTU = new AlertType((short)32, "ALERT.VR.PUBLIC.IFACE.MTU", true);
7575
public static final AlertType ALERT_TYPE_VR_PRIVATE_IFACE_MTU = new AlertType((short)32, "ALERT.VR.PRIVATE.IFACE.MTU", true);
7676
public static final AlertType ALERT_TYPE_EXTENSION_PATH_NOT_READY = new AlertType((short)33, "ALERT.TYPE.EXTENSION.PATH.NOT.READY", true);
77+
public static final AlertType ALERT_TYPE_VPN_GATEWAY_OBSOLETE_PARAMETERS = new AlertType((short)34, "ALERT.S2S.VPN.GATEWAY.OBSOLETE.PARAMETERS", true);
7778
public static final AlertType ALERT_TYPE_BACKUP_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_BACKUP_STORAGE, "ALERT.STORAGE.BACKUP", true);
7879
public static final AlertType ALERT_TYPE_OBJECT_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_OBJECT_STORAGE, "ALERT.STORAGE.OBJECT", true);
7980

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,10 @@ public class ApiConstants {
13651365

13661366
public static final String RECURSIVE_DOMAINS = "recursivedomains";
13671367

1368+
public static final String VPN_CUSTOMER_GATEWAY_PARAMETERS = "vpncustomergatewayparameters";
1369+
public static final String OBSOLETE_PARAMETERS = "obsoleteparameters";
1370+
public static final String EXCLUDED_PARAMETERS = "excludedparameters";
1371+
13681372
/**
13691373
* This enum specifies IO Drivers, each option controls specific policies on I/O.
13701374
* Qemu guests support "threads" and "native" options Since 0.8.8 ; "io_uring" is supported Since 6.3.0 (QEMU 5.0).

api/src/main/java/org/apache/cloudstack/api/BaseBackupListCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.apache.cloudstack.backup.BackupOffering;
2626
import org.apache.cloudstack.context.CallContext;
2727

28-
public abstract class BaseBackupListCmd extends BaseListCmd {
28+
public abstract class BaseBackupListCmd extends BaseListAccountResourcesCmd {
2929

3030
protected void setupResponseBackupOfferingsList(final List<BackupOffering> offerings, final Integer count) {
3131
final ListResponse<BackupOfferingResponse> response = new ListResponse<>();

api/src/main/java/org/apache/cloudstack/api/command/admin/backup/ImportBackupOfferingCmd.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.Parameter;
2828
import org.apache.cloudstack.api.ServerApiException;
2929
import org.apache.cloudstack.api.response.BackupOfferingResponse;
30+
import org.apache.cloudstack.api.response.DomainResponse;
3031
import org.apache.cloudstack.api.response.ZoneResponse;
3132
import org.apache.cloudstack.backup.BackupManager;
3233
import org.apache.cloudstack.backup.BackupOffering;
@@ -40,6 +41,11 @@
4041
import com.cloud.exception.ResourceAllocationException;
4142
import com.cloud.exception.ResourceUnavailableException;
4243
import com.cloud.utils.exception.CloudRuntimeException;
44+
import org.apache.commons.collections.CollectionUtils;
45+
46+
import java.util.LinkedHashSet;
47+
import java.util.List;
48+
import java.util.Set;
4349

4450
@APICommand(name = "importBackupOffering",
4551
description = "Imports a backup offering using a backup provider",
@@ -76,6 +82,13 @@ public class ImportBackupOfferingCmd extends BaseAsyncCmd {
7682
description = "Whether users are allowed to create adhoc backups and backup schedules", required = true)
7783
private Boolean userDrivenBackups;
7884

85+
@Parameter(name = ApiConstants.DOMAIN_ID,
86+
type = CommandType.LIST,
87+
collectionType = CommandType.UUID,
88+
entityType = DomainResponse.class,
89+
description = "the ID of the containing domain(s), null for public offerings")
90+
private List<Long> domainIds;
91+
7992
/////////////////////////////////////////////////////
8093
/////////////////// Accessors ///////////////////////
8194
/////////////////////////////////////////////////////
@@ -100,6 +113,15 @@ public Boolean getUserDrivenBackups() {
100113
return userDrivenBackups == null ? false : userDrivenBackups;
101114
}
102115

116+
public List<Long> getDomainIds() {
117+
if (CollectionUtils.isNotEmpty(domainIds)) {
118+
Set<Long> set = new LinkedHashSet<>(domainIds);
119+
domainIds.clear();
120+
domainIds.addAll(set);
121+
}
122+
return domainIds;
123+
}
124+
103125
/////////////////////////////////////////////////////
104126
/////////////// API Implementation///////////////////
105127
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,24 @@
2525
import org.apache.cloudstack.api.BaseCmd;
2626
import org.apache.cloudstack.api.Parameter;
2727
import org.apache.cloudstack.api.ServerApiException;
28+
import org.apache.cloudstack.api.command.offering.DomainAndZoneIdResolver;
2829
import org.apache.cloudstack.api.response.BackupOfferingResponse;
2930
import org.apache.cloudstack.backup.BackupManager;
3031
import org.apache.cloudstack.backup.BackupOffering;
3132
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
33+
import org.apache.commons.collections.CollectionUtils;
3234
import org.apache.commons.lang3.StringUtils;
3335

3436
import com.cloud.exception.InvalidParameterValueException;
3537
import com.cloud.user.Account;
3638
import com.cloud.utils.exception.CloudRuntimeException;
3739

40+
import java.util.List;
41+
import java.util.function.LongFunction;
42+
3843
@APICommand(name = "updateBackupOffering", description = "Updates a backup offering.", responseObject = BackupOfferingResponse.class,
3944
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.16.0")
40-
public class UpdateBackupOfferingCmd extends BaseCmd {
45+
public class UpdateBackupOfferingCmd extends BaseCmd implements DomainAndZoneIdResolver {
4146

4247
@Inject
4348
private BackupManager backupManager;
@@ -57,6 +62,13 @@ public class UpdateBackupOfferingCmd extends BaseCmd {
5762
@Parameter(name = ApiConstants.ALLOW_USER_DRIVEN_BACKUPS, type = CommandType.BOOLEAN, description = "Whether to allow user driven backups or not")
5863
private Boolean allowUserDrivenBackups;
5964

65+
@Parameter(name = ApiConstants.DOMAIN_ID,
66+
type = CommandType.STRING,
67+
description = "the ID of the containing domain(s) as comma separated string, public for public offerings",
68+
since = "4.23.0",
69+
length = 4096)
70+
private String domainIds;
71+
6072
/////////////////////////////////////////////////////
6173
/////////////////// Accessors ///////////////////////
6274
/////////////////////////////////////////////////////
@@ -82,7 +94,7 @@ public Boolean getAllowUserDrivenBackups() {
8294
@Override
8395
public void execute() {
8496
try {
85-
if (StringUtils.isAllEmpty(getName(), getDescription()) && getAllowUserDrivenBackups() == null) {
97+
if (StringUtils.isAllEmpty(getName(), getDescription()) && getAllowUserDrivenBackups() == null && CollectionUtils.isEmpty(getDomainIds())) {
8698
throw new InvalidParameterValueException(String.format("Can't update Backup Offering [id: %s] because there are no parameters to be updated, at least one of the",
8799
"following should be informed: name, description or allowUserDrivenBackups.", id));
88100
}
@@ -103,6 +115,18 @@ public void execute() {
103115
}
104116
}
105117

118+
public List<Long> getDomainIds() {
119+
// backupManager may be null in unit tests where the command is spied without injection.
120+
// Avoid creating a method reference to a null receiver which causes NPE. When backupManager
121+
// is null, pass null as the defaultDomainsProvider so resolveDomainIds will simply return
122+
// an empty list or parse the explicit domainIds string.
123+
LongFunction<List<Long>> defaultDomainsProvider = null;
124+
if (backupManager != null) {
125+
defaultDomainsProvider = backupManager::getBackupOfferingDomains;
126+
}
127+
return resolveDomainIds(domainIds, id, defaultDomainsProvider, "backup offering");
128+
}
129+
106130
@Override
107131
public long getEntityOwnerId() {
108132
return Account.ACCOUNT_ID_SYSTEM;

api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.network;
1818

19-
import java.util.ArrayList;
2019
import java.util.List;
2120

2221
import org.apache.cloudstack.api.APICommand;
@@ -26,18 +25,16 @@
2625
import org.apache.cloudstack.api.BaseCmd;
2726
import org.apache.cloudstack.api.Parameter;
2827
import org.apache.cloudstack.api.ServerApiException;
28+
import org.apache.cloudstack.api.command.offering.DomainAndZoneIdResolver;
2929
import org.apache.cloudstack.api.response.NetworkOfferingResponse;
30-
import org.apache.commons.lang3.StringUtils;
3130

32-
import com.cloud.dc.DataCenter;
33-
import com.cloud.domain.Domain;
34-
import com.cloud.exception.InvalidParameterValueException;
31+
3532
import com.cloud.offering.NetworkOffering;
3633
import com.cloud.user.Account;
3734

3835
@APICommand(name = "updateNetworkOffering", description = "Updates a network offering.", responseObject = NetworkOfferingResponse.class,
3936
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
40-
public class UpdateNetworkOfferingCmd extends BaseCmd {
37+
public class UpdateNetworkOfferingCmd extends BaseCmd implements DomainAndZoneIdResolver {
4138

4239
/////////////////////////////////////////////////////
4340
//////////////// API parameters /////////////////////
@@ -129,63 +126,11 @@ public String getTags() {
129126
}
130127

131128
public List<Long> getDomainIds() {
132-
List<Long> validDomainIds = new ArrayList<>();
133-
if (StringUtils.isNotEmpty(domainIds)) {
134-
if (domainIds.contains(",")) {
135-
String[] domains = domainIds.split(",");
136-
for (String domain : domains) {
137-
Domain validDomain = _entityMgr.findByUuid(Domain.class, domain.trim());
138-
if (validDomain != null) {
139-
validDomainIds.add(validDomain.getId());
140-
} else {
141-
throw new InvalidParameterValueException("Failed to create network offering because invalid domain has been specified.");
142-
}
143-
}
144-
} else {
145-
domainIds = domainIds.trim();
146-
if (!domainIds.matches("public")) {
147-
Domain validDomain = _entityMgr.findByUuid(Domain.class, domainIds.trim());
148-
if (validDomain != null) {
149-
validDomainIds.add(validDomain.getId());
150-
} else {
151-
throw new InvalidParameterValueException("Failed to create network offering because invalid domain has been specified.");
152-
}
153-
}
154-
}
155-
} else {
156-
validDomainIds.addAll(_configService.getNetworkOfferingDomains(id));
157-
}
158-
return validDomainIds;
129+
return resolveDomainIds(domainIds, id, _configService::getNetworkOfferingDomains, "network offering");
159130
}
160131

161132
public List<Long> getZoneIds() {
162-
List<Long> validZoneIds = new ArrayList<>();
163-
if (StringUtils.isNotEmpty(zoneIds)) {
164-
if (zoneIds.contains(",")) {
165-
String[] zones = zoneIds.split(",");
166-
for (String zone : zones) {
167-
DataCenter validZone = _entityMgr.findByUuid(DataCenter.class, zone.trim());
168-
if (validZone != null) {
169-
validZoneIds.add(validZone.getId());
170-
} else {
171-
throw new InvalidParameterValueException("Failed to create network offering because invalid zone has been specified.");
172-
}
173-
}
174-
} else {
175-
zoneIds = zoneIds.trim();
176-
if (!zoneIds.matches("all")) {
177-
DataCenter validZone = _entityMgr.findByUuid(DataCenter.class, zoneIds.trim());
178-
if (validZone != null) {
179-
validZoneIds.add(validZone.getId());
180-
} else {
181-
throw new InvalidParameterValueException("Failed to create network offering because invalid zone has been specified.");
182-
}
183-
}
184-
}
185-
} else {
186-
validZoneIds.addAll(_configService.getNetworkOfferingZones(id));
187-
}
188-
return validZoneIds;
133+
return resolveZoneIds(zoneIds, id, _configService::getNetworkOfferingZones, "network offering");
189134
}
190135

191136
/////////////////////////////////////////////////////

0 commit comments

Comments
 (0)