Skip to content

Commit 7796143

Browse files
authored
Merge pull request #365 from ablecloud-team/ablestack-diplo
diplo merge
2 parents 710aab3 + 2901187 commit 7796143

File tree

9 files changed

+330
-62
lines changed

9 files changed

+330
-62
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public class ImportBackupOfferingCmd extends BaseAsyncCmd {
6262
description = "the description of the backup offering")
6363
private String description;
6464

65+
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, required = true,
66+
description = "The backup provider name")
67+
private String provider;
68+
6569
@Parameter(name = ApiConstants.EXTERNAL_ID,
6670
type = CommandType.STRING,
6771
required = true,
@@ -88,6 +92,10 @@ public String getName() {
8892
return name;
8993
}
9094

95+
public String getProvider() {
96+
return provider;
97+
}
98+
9199
public String getExternalId() {
92100
return externalId;
93101
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public class ListBackupProviderOfferingsCmd extends BaseBackupListCmd {
5555
required = true, description = "The zone ID")
5656
private Long zoneId;
5757

58+
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, required = true,
59+
description = "The backup provider name")
60+
private String provider;
61+
5862
/////////////////////////////////////////////////////
5963
/////////////////// Accessors ///////////////////////
6064
/////////////////////////////////////////////////////
@@ -63,6 +67,10 @@ public Long getZoneId() {
6367
return zoneId;
6468
}
6569

70+
public String getProvider() {
71+
return provider;
72+
}
73+
6674
/////////////////////////////////////////////////////
6775
/////////////// API Implementation///////////////////
6876
/////////////////////////////////////////////////////
@@ -77,7 +85,7 @@ private void validateParameters() {
7785
public void execute() throws ResourceUnavailableException, ServerApiException, ConcurrentOperationException {
7886
validateParameters();
7987
try {
80-
final List<BackupOffering> backupOfferings = backupManager.listBackupProviderOfferings(getZoneId());
88+
final List<BackupOffering> backupOfferings = backupManager.listBackupProviderOfferings(getZoneId(), getProvider());
8189
setupResponseBackupOfferingsList(backupOfferings, backupOfferings.size());
8290
} catch (InvalidParameterValueException e) {
8391
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.api.command.admin.backup;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import javax.inject.Inject;
23+
24+
import org.apache.cloudstack.acl.RoleType;
25+
import org.apache.cloudstack.api.APICommand;
26+
import org.apache.cloudstack.api.ApiConstants;
27+
import org.apache.cloudstack.api.BaseCmd;
28+
import org.apache.cloudstack.api.Parameter;
29+
import org.apache.cloudstack.api.response.BackupProviderResponse;
30+
import org.apache.cloudstack.api.response.ListResponse;
31+
import org.apache.cloudstack.api.response.ZoneResponse;
32+
import org.apache.cloudstack.backup.BackupManager;
33+
import org.apache.cloudstack.backup.BackupProvider;
34+
35+
import com.cloud.user.Account;
36+
37+
@APICommand(name = "listBackupProvidersForZone",
38+
description = "Lists Backup and Recovery providers for zone",
39+
responseObject = BackupProviderResponse.class, since = "4.14.0",
40+
authorized = {RoleType.Admin})
41+
public class ListBackupProvidersForZoneCmd extends BaseCmd {
42+
43+
@Inject
44+
private BackupManager backupManager;
45+
46+
/////////////////////////////////////////////////////
47+
//////////////// API parameters /////////////////////
48+
/////////////////////////////////////////////////////
49+
50+
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the zone ID")
51+
private Long zoneId;
52+
53+
/////////////////////////////////////////////////////
54+
/////////////////// Accessors ///////////////////////
55+
/////////////////////////////////////////////////////
56+
57+
public Long getZoneId() {
58+
return zoneId;
59+
}
60+
61+
@Override
62+
public long getEntityOwnerId() {
63+
return Account.ACCOUNT_ID_SYSTEM;
64+
}
65+
66+
/////////////////////////////////////////////////////
67+
/////////////// API Implementation///////////////////
68+
/////////////////////////////////////////////////////
69+
70+
private void setupResponse(final List<BackupProvider> providers) {
71+
final ListResponse<BackupProviderResponse> response = new ListResponse<>();
72+
final List<BackupProviderResponse> responses = new ArrayList<>();
73+
for (final BackupProvider provider : providers) {
74+
if (provider == null) {
75+
continue;
76+
}
77+
final BackupProviderResponse backupProviderResponse = new BackupProviderResponse();
78+
backupProviderResponse.setName(provider.getName());
79+
backupProviderResponse.setDescription(provider.getDescription());
80+
backupProviderResponse.setObjectName("providers");
81+
responses.add(backupProviderResponse);
82+
}
83+
response.setResponses(responses);
84+
response.setResponseName(getCommandName());
85+
setResponseObject(response);
86+
}
87+
88+
@Override
89+
public void execute() {
90+
List<BackupProvider> providers = backupManager.listBackupProvidersForZone(getZoneId());
91+
setupResponse(providers);
92+
}
93+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
4444
ConfigKey<String> BackupProviderPlugin = new ConfigKey<>("Advanced", String.class,
4545
"backup.framework.provider.plugin",
4646
"dummy",
47-
"The backup and recovery provider plugin.", true, ConfigKey.Scope.Zone, BackupFrameworkEnabled.key());
47+
"The backup and recovery provider plugin (comma-separated). Example: dummy,nas,commvault", true, ConfigKey.Scope.Zone, BackupFrameworkEnabled.key());
4848

4949
ConfigKey<Long> BackupSyncPollingInterval = new ConfigKey<>("Advanced", Long.class,
5050
"backup.framework.sync.interval",
@@ -59,8 +59,9 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
5959
/**
6060
* List backup provider offerings
6161
* @param zoneId zone id
62+
* @param provider provider name
6263
*/
63-
List<BackupOffering> listBackupProviderOfferings(final Long zoneId);
64+
List<BackupOffering> listBackupProviderOfferings(final Long zoneId, final String provider);
6465

6566
/**
6667
* Add a new Backup and Recovery policy to CloudStack by mapping an existing external backup offering to a name and description

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,24 @@ public interface BackupService {
2828
*/
2929
List<BackupProvider> listBackupProviders();
3030

31+
/**
32+
* Lists backup and recovery provider plugins for zone
33+
* @param zoneId zone id
34+
* @return list of providers for zone
35+
*/
36+
List<BackupProvider> listBackupProvidersForZone(final Long zoneId);
37+
3138
/**
3239
* Find backup provider by zone ID
3340
* @param zoneId zone id
3441
* @return backup provider
3542
*/
3643
BackupProvider getBackupProvider(final Long zoneId);
44+
45+
/**
46+
* Find backup provider by offering ID
47+
* @param offeringId offering id
48+
* @return backup provider
49+
*/
50+
BackupProvider getBackupProviderForOffering(final Long offeringId);
3751
}

plugins/backup/commvault/src/main/java/org/apache/cloudstack/backup/CommvaultBackupProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ public boolean takeBackup(VirtualMachine vm) {
891891
BackupVO backup = new BackupVO();
892892
backup.setVmId(vm.getId());
893893
backup.setExternalId(externalId);
894-
backup.setType(type);
894+
backup.setType(type.toUpperCase());
895895
try {
896896
backup.setDate(formatterDateTime.parse(formattedString));
897897
} catch (ParseException e) {

0 commit comments

Comments
 (0)