Merge branch '4.20' into 4.22

This commit is contained in:
Daan Hoogland 2026-02-09 13:05:08 +01:00
commit 7324ef45d4
4 changed files with 63 additions and 6 deletions

View File

@ -32,6 +32,7 @@ import org.apache.cloudstack.api.command.user.backup.ListBackupScheduleCmd;
import org.apache.cloudstack.api.command.user.backup.ListBackupsCmd;
import org.apache.cloudstack.api.response.BackupResponse;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.ValidatedConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import com.cloud.exception.ResourceUnavailableException;
@ -53,10 +54,11 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
"false",
"Is backup and recovery framework enabled.", false, ConfigKey.Scope.Zone);
ConfigKey<String> BackupProviderPlugin = new ConfigKey<>("Advanced", String.class,
ConfigKey<String> BackupProviderPlugin = new ValidatedConfigKey<>("Advanced", String.class,
"backup.framework.provider.plugin",
"dummy",
"The backup and recovery provider plugin. Valid plugin values: dummy, veeam, networker and nas", true, ConfigKey.Scope.Zone, BackupFrameworkEnabled.key());
"The backup and recovery provider plugin. Valid plugin values: dummy, veeam, networker and nas",
true, ConfigKey.Scope.Zone, BackupFrameworkEnabled.key(), value -> validateBackupProviderConfig((String)value));
ConfigKey<Long> BackupSyncPollingInterval = new ConfigKey<>("Advanced", Long.class,
"backup.framework.sync.interval",
@ -247,4 +249,14 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
Capacity getBackupStorageUsedStats(Long zoneId);
void checkAndRemoveBackupOfferingBeforeExpunge(VirtualMachine vm);
static void validateBackupProviderConfig(String value) {
if (value != null && (value.contains(",") || value.trim().contains(" "))) {
throw new IllegalArgumentException("Multiple backup provider plugins are not supported. Please provide a single plugin value.");
}
List<String> validPlugins = List.of("dummy", "veeam", "networker", "nas");
if (value != null && !validPlugins.contains(value)) {
throw new IllegalArgumentException("Invalid backup provider plugin: " + value + ". Valid plugin values are: " + String.join(", ", validPlugins));
}
}
}

View File

@ -0,0 +1,38 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.framework.config;
import java.util.function.Consumer;
public class ValidatedConfigKey<T> extends ConfigKey<T> {
private final Consumer<T> validator;
public ValidatedConfigKey(String category, Class<T> type, String name, String defaultValue, String description, boolean dynamic, Scope scope, String parent, Consumer<T> validator) {
super(category, type, name, defaultValue, description, dynamic, scope, parent);
this.validator = validator;
}
public Consumer<T> getValidator() {
return validator;
}
public void validateValue(String value) {
if (validator != null) {
validator.accept((T) value);
}
}
}

View File

@ -102,6 +102,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.framework.config.ConfigDepot;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.ValidatedConfigKey;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.dao.ConfigurationGroupDao;
import org.apache.cloudstack.framework.config.dao.ConfigurationSubGroupDao;
@ -761,6 +762,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException(validationMsg);
}
ConfigKey<?> configKey = _configDepot.get(name);
if (configKey instanceof ValidatedConfigKey) {
ValidatedConfigKey<?> validatedConfigKey = (ValidatedConfigKey<?>) configKey;
validatedConfigKey.validateValue(value);
}
// If scope of the parameter is given then it needs to be updated in the
// corresponding details table,
// if scope is mentioned as global or not mentioned then it is normal

View File

@ -1650,10 +1650,10 @@ public class BackupManagerImpl extends ManagerBase implements BackupManager {
if (StringUtils.isEmpty(name)) {
throw new CloudRuntimeException("Invalid backup provider name provided");
}
if (!backupProvidersMap.containsKey(name)) {
throw new CloudRuntimeException("Failed to find backup provider by the name: " + name);
}
return backupProvidersMap.get(name);
if (!backupProvidersMap.containsKey(name)) {
throw new CloudRuntimeException("Failed to find backup provider by the name: " + name);
}
return backupProvidersMap.get(name);
}
@Override