Skip to content

Commit a0f35a1

Browse files
authored
Fixes issue with loading Capacity dashboard when mulitple backup providers configured (#12550)
1 parent 3d7d412 commit a0f35a1

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-6
lines changed

api/src/main/java/org/apache/cloudstack/backup/BackupManager.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.cloudstack.api.command.user.backup.ListBackupOfferingsCmd;
2727
import org.apache.cloudstack.api.command.user.backup.ListBackupsCmd;
2828
import org.apache.cloudstack.framework.config.ConfigKey;
29+
import org.apache.cloudstack.framework.config.ValidatedConfigKey;
2930
import org.apache.cloudstack.framework.config.Configurable;
3031

3132
import com.cloud.utils.Pair;
@@ -42,10 +43,11 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
4243
"false",
4344
"Is backup and recovery framework enabled.", false, ConfigKey.Scope.Zone);
4445

45-
ConfigKey<String> BackupProviderPlugin = new ConfigKey<>("Advanced", String.class,
46+
ConfigKey<String> BackupProviderPlugin = new ValidatedConfigKey<>("Advanced", String.class,
4647
"backup.framework.provider.plugin",
4748
"dummy",
48-
"The backup and recovery provider plugin.", true, ConfigKey.Scope.Zone, BackupFrameworkEnabled.key());
49+
"The backup and recovery provider plugin. Valid plugin values: dummy, veeam, networker and nas",
50+
true, ConfigKey.Scope.Zone, BackupFrameworkEnabled.key(), value -> validateBackupProviderConfig((String)value));
4951

5052
ConfigKey<Long> BackupSyncPollingInterval = new ConfigKey<>("Advanced", Long.class,
5153
"backup.framework.sync.interval",
@@ -148,4 +150,14 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
148150
boolean deleteBackup(final Long backupId, final Boolean forced);
149151

150152
BackupOffering updateBackupOffering(UpdateBackupOfferingCmd updateBackupOfferingCmd);
153+
154+
static void validateBackupProviderConfig(String value) {
155+
if (value != null && (value.contains(",") || value.trim().contains(" "))) {
156+
throw new IllegalArgumentException("Multiple backup provider plugins are not supported. Please provide a single plugin value.");
157+
}
158+
List<String> validPlugins = List.of("dummy", "veeam", "networker", "nas");
159+
if (value != null && !validPlugins.contains(value)) {
160+
throw new IllegalArgumentException("Invalid backup provider plugin: " + value + ". Valid plugin values are: " + String.join(", ", validPlugins));
161+
}
162+
}
151163
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.framework.config;
18+
19+
import java.util.function.Consumer;
20+
21+
public class ValidatedConfigKey<T> extends ConfigKey<T> {
22+
private final Consumer<T> validator;
23+
24+
public ValidatedConfigKey(String category, Class<T> type, String name, String defaultValue, String description, boolean dynamic, Scope scope, String parent, Consumer<T> validator) {
25+
super(category, type, name, defaultValue, description, dynamic, scope, parent);
26+
this.validator = validator;
27+
}
28+
29+
public Consumer<T> getValidator() {
30+
return validator;
31+
}
32+
33+
public void validateValue(String value) {
34+
if (validator != null) {
35+
validator.accept((T) value);
36+
}
37+
}
38+
}

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import org.apache.cloudstack.framework.config.ConfigDepot;
108108
import org.apache.cloudstack.framework.config.ConfigKey;
109109
import org.apache.cloudstack.framework.config.Configurable;
110+
import org.apache.cloudstack.framework.config.ValidatedConfigKey;
110111
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
111112
import org.apache.cloudstack.framework.config.dao.ConfigurationGroupDao;
112113
import org.apache.cloudstack.framework.config.dao.ConfigurationSubGroupDao;
@@ -716,6 +717,12 @@ public String updateConfiguration(final long userId, final String name, final St
716717
throw new InvalidParameterValueException(validationMsg);
717718
}
718719

720+
ConfigKey<?> configKey = _configDepot.get(name);
721+
if (configKey instanceof ValidatedConfigKey) {
722+
ValidatedConfigKey<?> validatedConfigKey = (ValidatedConfigKey<?>) configKey;
723+
validatedConfigKey.validateValue(value);
724+
}
725+
719726
// If scope of the parameter is given then it needs to be updated in the
720727
// corresponding details table,
721728
// if scope is mentioned as global or not mentioned then it is normal

server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,10 @@ public BackupProvider getBackupProvider(final String name) {
972972
if (StringUtils.isEmpty(name)) {
973973
throw new CloudRuntimeException("Invalid backup provider name provided");
974974
}
975-
if (!backupProvidersMap.containsKey(name)) {
976-
throw new CloudRuntimeException("Failed to find backup provider by the name: " + name);
977-
}
978-
return backupProvidersMap.get(name);
975+
if (!backupProvidersMap.containsKey(name)) {
976+
throw new CloudRuntimeException("Failed to find backup provider by the name: " + name);
977+
}
978+
return backupProvidersMap.get(name);
979979
}
980980

981981
@Override

0 commit comments

Comments
 (0)