Skip to content

Commit cdf6f4e

Browse files
committed
Big refactor and improvements
1 parent e9b160f commit cdf6f4e

File tree

62 files changed

+952
-1731
lines changed

Some content is hidden

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

62 files changed

+952
-1731
lines changed

api/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
<artifactId>cloud-framework-ca</artifactId>
5757
<version>${project.version}</version>
5858
</dependency>
59+
<dependency>
60+
<groupId>org.apache.cloudstack</groupId>
61+
<artifactId>cloud-framework-backup-and-recovery</artifactId>
62+
<version>${project.version}</version>
63+
</dependency>
5964
<dependency>
6065
<groupId>org.apache.commons</groupId>
6166
<artifactId>commons-lang3</artifactId>

api/src/main/java/com/cloud/host/Host.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public enum Type {
3333
Storage(false), Routing(false), SecondaryStorage(false), SecondaryStorageCmdExecutor(false), ConsoleProxy(true), ExternalFirewall(false), ExternalLoadBalancer(
3434
false), ExternalVirtualSwitchSupervisor(false), PxeServer(false), BaremetalPxe(false), BaremetalDhcp(false), TrafficMonitor(false), NetScalerControlCenter(false),
3535

36-
ExternalDhcp(false), SecondaryStorageVM(true), LocalSecondaryStorage(false), L2Networking(false), BackupRecovery(true);
36+
ExternalDhcp(false), SecondaryStorageVM(true), LocalSecondaryStorage(false), L2Networking(false);
3737
boolean _virtual;
3838

3939
private Type(boolean virtual) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,8 @@ public class ApiConstants {
720720
public static final String LDAP_DOMAIN = "ldapdomain";
721721

722722
// Backup and Recovery
723-
public static final String BACKUP_PROVIDER_ID = "backupproviderid";
724-
public static final String BACKUP_POLICY_ID = "backuppolicyid";
725-
public static final String BACKUP_POLICY_NAME = "backuppolicyname";
723+
public static final String BR_PROVIDER_ID = "providerid";
724+
public static final String BR_POLICY_ID = "policyid";
726725

727726
public enum HostDetails {
728727
all, capacity, events, stats, min;
Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1-
package org.apache.cloudstack.framework.backuprecovery.api;
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+
18+
package org.apache.cloudstack.api.command.admin.br.policy;
219

320
import com.cloud.exception.ConcurrentOperationException;
421
import com.cloud.exception.InsufficientCapacityException;
522
import com.cloud.exception.InvalidParameterValueException;
623
import com.cloud.exception.NetworkRuleConflictException;
7-
import com.cloud.exception.OperationTimedoutException;
824
import com.cloud.exception.ResourceAllocationException;
925
import com.cloud.exception.ResourceUnavailableException;
1026
import com.cloud.utils.exception.CloudRuntimeException;
@@ -16,40 +32,37 @@
1632
import org.apache.cloudstack.api.Parameter;
1733
import org.apache.cloudstack.api.ServerApiException;
1834
import org.apache.cloudstack.context.CallContext;
19-
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
20-
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse;
21-
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
22-
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
35+
import org.apache.cloudstack.br.BRManager;
36+
import org.apache.cloudstack.api.response.BRPolicyResponse;
37+
import org.apache.cloudstack.framework.br.BRPolicy;
2338

2439
import javax.inject.Inject;
2540

26-
@APICommand(name = AddBackupRecoveryPolicyCmd.APINAME,
41+
@APICommand(name = AddBRPolicyCmd.APINAME,
2742
description = "Adds a Backup policy",
28-
responseObject = BackupPolicyResponse.class, since = "4.12.0",
43+
responseObject = BRPolicyResponse.class, since = "4.12.0",
2944
authorized = {RoleType.Admin})
30-
public class AddBackupRecoveryPolicyCmd extends BaseCmd {
45+
public class AddBRPolicyCmd extends BaseCmd {
3146

32-
public static final String APINAME = "addBackupRecoveryPolicy";
47+
public static final String APINAME = "addBRPolicy";
3348

3449
@Inject
35-
BackupRecoveryManager backupRecoveryManager;
50+
BRManager brManager;
3651

3752
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the policy")
3853
private String policyName;
3954

40-
@Parameter(name = ApiConstants.BACKUP_POLICY_ID,
55+
@Parameter(name = ApiConstants.BR_POLICY_ID,
4156
type = CommandType.STRING,
42-
entityType = BackupRecoveryProviderResponse.class,
4357
required = true,
4458
description = "Backup Recovery Provider ID")
4559
private String policyId;
4660

47-
@Parameter(name = ApiConstants.BACKUP_PROVIDER_ID,
48-
type = BaseCmd.CommandType.UUID,
49-
entityType = BackupRecoveryProviderResponse.class,
61+
@Parameter(name = ApiConstants.BR_PROVIDER_ID,
62+
type = CommandType.STRING,
5063
required = true,
5164
description = "Backup Recovery Provider ID")
52-
private Long providerId;
65+
private String providerId;
5366

5467
public String getPolicyName() {
5568
return policyName;
@@ -59,17 +72,17 @@ public String getPolicyId() {
5972
return policyId;
6073
}
6174

62-
public Long getProviderId() {
75+
public String getProviderId() {
6376
return providerId;
6477
}
6578

6679
@Override
6780
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
6881
try {
69-
BackupPolicyVO policyVO = backupRecoveryManager.addBackupPolicy(this);
70-
if (policyVO != null) {
71-
BackupPolicyResponse response = backupRecoveryManager.createBackupPolicyResponse(policyVO);
72-
response.setObjectName("backuppolicy");
82+
BRPolicy policy = brManager.addBRPolicy(policyId, policyName, providerId);
83+
if (policy != null) {
84+
BRPolicyResponse response = brManager.createBackupPolicyResponse(policy);
85+
response.setObjectName("brpolicy");
7386
response.setResponseName(getCommandName());
7487
setResponseObject(response);
7588
} else {
@@ -79,14 +92,12 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
7992
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
8093
} catch (CloudRuntimeException e) {
8194
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
82-
} catch (OperationTimedoutException e) {
83-
e.printStackTrace();
8495
}
8596
}
8697

8798
@Override
8899
public String getCommandName() {
89-
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
100+
return APINAME.toLowerCase() + RESPONSE_SUFFIX;
90101
}
91102

92103
@Override
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.apache.cloudstack.framework.backuprecovery.api;
20+
package org.apache.cloudstack.api.command.admin.br.policy;
2121

2222
import com.cloud.exception.ConcurrentOperationException;
2323
import com.cloud.exception.InsufficientCapacityException;
@@ -33,33 +33,32 @@
3333
import org.apache.cloudstack.api.response.SuccessResponse;
3434
import org.apache.cloudstack.api.response.UserVmResponse;
3535
import org.apache.cloudstack.context.CallContext;
36-
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
37-
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
36+
import org.apache.cloudstack.br.BRManager;
37+
import org.apache.cloudstack.br.BRProviderDriver;
3838

3939
import javax.inject.Inject;
4040

41-
@APICommand(name = AssignBackupPolicyCmd.APINAME,
41+
@APICommand(name = AssignBRPolicyCmd.APINAME,
4242
description = "Assigns a VM to an existing backup policy",
4343
responseObject = SuccessResponse.class, since = "4.12.0")
44-
public class AssignBackupPolicyCmd extends BaseCmd {
44+
public class AssignBRPolicyCmd extends BaseCmd {
4545

46-
public static final String APINAME = "assignBackupPolicy";
46+
public static final String APINAME = "assignBRPolicy";
4747

4848
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
4949
type = CommandType.UUID,
5050
entityType = UserVmResponse.class,
5151
required = true,
5252
description = "id of the VM to be moved")
53-
private Long virtualMachineId;
53+
private String virtualMachineId;
5454

55-
@Parameter(name = ApiConstants.BACKUP_POLICY_ID,
55+
@Parameter(name = ApiConstants.BR_POLICY_ID,
5656
type = CommandType.STRING,
57-
entityType = BackupRecoveryProviderResponse.class,
5857
required = true,
5958
description = "Backup Recovery Provider ID")
6059
private String policyId;
6160

62-
public Long getVirtualMachineId() {
61+
public String getVirtualMachineId() {
6362
return virtualMachineId;
6463
}
6564

@@ -68,12 +67,13 @@ public String getPolicyId() {
6867
}
6968

7069
@Inject
71-
BackupRecoveryManager backupRecoveryManager;
70+
BRManager brManager;
7271

7372
@Override
7473
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
7574
try {
76-
boolean result = backupRecoveryManager.assignVMToBackupPolicy(this);
75+
BRProviderDriver provider = brManager.getBRProviderFromPolicy(getPolicyId());
76+
boolean result = provider.assignVMToBackupPolicy(getPolicyId(), getVirtualMachineId());
7777
if (result) {
7878
SuccessResponse response = new SuccessResponse(getCommandName());
7979
response.setResponseName(getCommandName());
@@ -82,13 +82,13 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
8282
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign VM to backup policy");
8383
}
8484
} catch (Exception e) {
85-
85+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
8686
}
8787
}
8888

8989
@Override
9090
public String getCommandName() {
91-
return AssignBackupPolicyCmd.APINAME + BaseCmd.RESPONSE_SUFFIX;
91+
return AssignBRPolicyCmd.APINAME + RESPONSE_SUFFIX;
9292
}
9393

9494
@Override
Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17-
package org.apache.cloudstack.framework.backuprecovery.api;
17+
package org.apache.cloudstack.api.command.admin.br.policy;
1818

1919
import com.cloud.exception.ConcurrentOperationException;
2020
import com.cloud.exception.InvalidParameterValueException;
@@ -23,56 +23,53 @@
2323
import org.apache.cloudstack.api.APICommand;
2424
import org.apache.cloudstack.api.ApiConstants;
2525
import org.apache.cloudstack.api.ApiErrorCode;
26-
import org.apache.cloudstack.api.BaseCmd;
2726
import org.apache.cloudstack.api.BaseListCmd;
2827
import org.apache.cloudstack.api.Parameter;
2928
import org.apache.cloudstack.api.ServerApiException;
3029
import org.apache.cloudstack.api.response.ListResponse;
31-
import org.apache.cloudstack.framework.backuprecovery.BackupRecoveryManager;
32-
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupPolicyResponse;
33-
import org.apache.cloudstack.framework.backuprecovery.api.response.BackupRecoveryProviderResponse;
34-
import org.apache.cloudstack.framework.backuprecovery.impl.BackupPolicyVO;
30+
import org.apache.cloudstack.br.BRManager;
31+
import org.apache.cloudstack.api.response.BRPolicyResponse;
32+
import org.apache.cloudstack.framework.br.BRPolicy;
3533
import org.apache.commons.collections.CollectionUtils;
3634

3735
import javax.inject.Inject;
3836
import java.util.ArrayList;
3937
import java.util.List;
4038

41-
@APICommand(name = ListBackupRecoveryPoliciesCmd.APINAME,
39+
@APICommand(name = ListBRPoliciesCmd.APINAME,
4240
description = "Lists mapped Backup policies",
43-
responseObject = BackupPolicyResponse.class, since = "4.12.0",
41+
responseObject = BRPolicyResponse.class, since = "4.12.0",
4442
authorized = {RoleType.Admin})
45-
public class ListBackupRecoveryPoliciesCmd extends BaseListCmd {
43+
public class ListBRPoliciesCmd extends BaseListCmd {
4644

47-
public static final String APINAME = "listBackupRecoveryPolicies";
45+
public static final String APINAME = "listBRPolicies";
4846

49-
@Parameter(name = ApiConstants.BACKUP_PROVIDER_ID,
50-
type = BaseCmd.CommandType.UUID,
51-
entityType = BackupRecoveryProviderResponse.class,
47+
@Parameter(name = ApiConstants.BR_PROVIDER_ID,
48+
type = CommandType.STRING,
5249
required = true,
5350
description = "Backup Recovery Provider ID")
54-
private Long providerId;
51+
private String providerId;
5552

56-
public long getProviderId() {
53+
public String getProviderId() {
5754
return providerId;
5855
}
5956

6057
@Inject
61-
BackupRecoveryManager backupRecoveryManager;
58+
BRManager brManager;
6259

6360
@Override
6461
public void execute() throws ServerApiException, ConcurrentOperationException {
6562
try {
66-
ListResponse<BackupPolicyResponse> response = new ListResponse<BackupPolicyResponse>();
67-
List<BackupPolicyResponse> responses = new ArrayList<>();
68-
List<BackupPolicyVO> policies = backupRecoveryManager.listBackupPolicies(this);
63+
ListResponse<BRPolicyResponse> response = new ListResponse<BRPolicyResponse>();
64+
List<BRPolicyResponse> responses = new ArrayList<>();
65+
List<BRPolicy> policies = brManager.listBRPolicies(providerId);
6966
if (CollectionUtils.isNotEmpty(policies)) {
70-
for (BackupPolicyVO policy : policies) {
71-
BackupPolicyResponse p = backupRecoveryManager.createBackupPolicyResponse(policy);
72-
responses.add(p);
67+
for (BRPolicy policy : policies) {
68+
responses.add(brManager.createBackupPolicyResponse(policy));
7369
}
7470
}
7571
response.setResponses(responses, responses.size());
72+
response.setObjectName("brpolicies");
7673
response.setResponseName(getCommandName());
7774
setResponseObject(response);
7875
} catch (InvalidParameterValueException e) {
@@ -83,7 +80,7 @@ public void execute() throws ServerApiException, ConcurrentOperationException {
8380
}
8481
@Override
8582
public String getCommandName() {
86-
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
83+
return APINAME.toLowerCase() + RESPONSE_SUFFIX;
8784
}
8885

8986
}

0 commit comments

Comments
 (0)