Skip to content

Commit 0b3b3f1

Browse files
b&r: phase1 all commits melded
Signed-off-by: Rohit Yadav <[email protected]>
1 parent 1d05fea commit 0b3b3f1

File tree

77 files changed

+6073
-3
lines changed

Some content is hidden

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

77 files changed

+6073
-3
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,15 @@ public class EventTypes {
584584
public static final String EVENT_TEMPLATE_DIRECT_DOWNLOAD_FAILURE = "TEMPLATE.DIRECT.DOWNLOAD.FAILURE";
585585
public static final String EVENT_ISO_DIRECT_DOWNLOAD_FAILURE = "ISO.DIRECT.DOWNLOAD.FAILURE";
586586

587+
// Backup and Recovery events
588+
public static final String EVENT_ADD_VM_TO_BACKUP_POLICY = "ADD.VM.TO.BACKUP.POLICY";
589+
public static final String EVENT_REMOVE_VM_FROM_BACKUP_POLICY = "REMOVE.VM.FROM.BACKUP.POLICY";
590+
public static final String EVENT_IMPORT_BACKUP_POLICY = "IMPORT.BACKUP.POLICY";
591+
public static final String EVENT_CREATE_VM_BACKUP = "CREATE.VM.BACKUP";
592+
public static final String EVENT_DELETE_VM_BACKUP = "DELETE.VM.BACKUP";
593+
public static final String EVENT_RESTORE_VM_FROM_BACKUP = "RESTORE.VM.FROM.BACKUP";
594+
public static final String EVENT_RESTORE_VOLUME_FROM_BACKUP_AND_ATTACH_TO_VM = "RESTORE.VOLUME.FROM.BACKUP.AND.ATTACH.TO.VM";
595+
587596
static {
588597

589598
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public class ApiConstants {
121121
public static final String EXTRA_DHCP_OPTION_NAME = "extradhcpoptionname";
122122
public static final String EXTRA_DHCP_OPTION_CODE = "extradhcpoptioncode";
123123
public static final String EXTRA_DHCP_OPTION_VALUE = "extradhcpvalue";
124+
public static final String EXTERNAL = "external";
124125
public static final String FENCE = "fence";
125126
public static final String FETCH_LATEST = "fetchlatest";
126127
public static final String FIRSTNAME = "firstname";
@@ -335,6 +336,7 @@ public class ApiConstants {
335336
public static final String VNET = "vnet";
336337
public static final String IS_VOLATILE = "isvolatile";
337338
public static final String VOLUME_ID = "volumeid";
339+
public static final String VOLUME_IDS = "volumeids";
338340
public static final String ZONE_ID = "zoneid";
339341
public static final String ZONE_NAME = "zonename";
340342
public static final String NETWORK_TYPE = "networktype";
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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;
19+
20+
import org.apache.cloudstack.api.response.BackupPolicyResponse;
21+
import org.apache.cloudstack.api.response.BackupPolicyVMMapResponse;
22+
import org.apache.cloudstack.api.response.BackupResponse;
23+
import org.apache.cloudstack.api.response.ListResponse;
24+
import org.apache.cloudstack.backup.BackupPolicyVMMap;
25+
import org.apache.cloudstack.context.CallContext;
26+
import org.apache.cloudstack.backup.Backup;
27+
import org.apache.cloudstack.backup.BackupPolicy;
28+
29+
import java.util.ArrayList;
30+
import java.util.List;
31+
32+
public abstract class BaseBackupListCmd extends BaseListCmd {
33+
34+
protected void setupResponseBackupPolicyList(final List<BackupPolicy> policies) {
35+
final ListResponse<BackupPolicyResponse> response = new ListResponse<>();
36+
final List<BackupPolicyResponse> responses = new ArrayList<>();
37+
for (final BackupPolicy policy : policies) {
38+
if (policy == null) {
39+
continue;
40+
}
41+
BackupPolicyResponse backupPolicyResponse = _responseGenerator.createBackupPolicyResponse(policy);
42+
responses.add(backupPolicyResponse);
43+
}
44+
response.setResponses(responses);
45+
response.setResponseName(getCommandName());
46+
setResponseObject(response);
47+
}
48+
49+
protected void setupResponseBackupList(final List<Backup> backups) {
50+
final ListResponse<BackupResponse> response = new ListResponse<>();
51+
final List<BackupResponse> responses = new ArrayList<>();
52+
for (Backup backup : backups) {
53+
if (backup == null) {
54+
continue;
55+
}
56+
BackupResponse backupResponse = _responseGenerator.createBackupResponse(backup);
57+
responses.add(backupResponse);
58+
}
59+
response.setResponses(responses);
60+
response.setResponseName(getCommandName());
61+
setResponseObject(response);
62+
}
63+
64+
protected void setupResponseBackupPolicyVMMappings(final List<BackupPolicyVMMap> mappings) {
65+
final ListResponse<BackupPolicyVMMapResponse> response = new ListResponse<>();
66+
final List<BackupPolicyVMMapResponse> responses = new ArrayList<>();
67+
for (BackupPolicyVMMap map : mappings) {
68+
if (map == null) {
69+
continue;
70+
}
71+
BackupPolicyVMMapResponse resp = _responseGenerator.createBackupPolicyVMMappingResponse(map);
72+
responses.add(resp);
73+
}
74+
response.setResponses(responses);
75+
response.setResponseName(getCommandName());
76+
setResponseObject(response);
77+
}
78+
79+
@Override
80+
public long getEntityOwnerId() {
81+
return CallContext.current().getCallingAccount().getId();
82+
}
83+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
import org.apache.cloudstack.api.response.AutoScalePolicyResponse;
3535
import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
3636
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
37+
import org.apache.cloudstack.api.response.BackupPolicyResponse;
38+
import org.apache.cloudstack.api.response.BackupPolicyVMMapResponse;
39+
import org.apache.cloudstack.api.response.BackupResponse;
3740
import org.apache.cloudstack.api.response.CapacityResponse;
3841
import org.apache.cloudstack.api.response.ClusterResponse;
3942
import org.apache.cloudstack.api.response.ConditionResponse;
@@ -116,7 +119,10 @@
116119
import org.apache.cloudstack.api.response.VpcResponse;
117120
import org.apache.cloudstack.api.response.VpnUsersResponse;
118121
import org.apache.cloudstack.api.response.ZoneResponse;
122+
import org.apache.cloudstack.backup.BackupPolicy;
123+
import org.apache.cloudstack.backup.BackupPolicyVMMap;
119124
import org.apache.cloudstack.config.Configuration;
125+
import org.apache.cloudstack.backup.Backup;
120126
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
121127
import org.apache.cloudstack.region.PortableIp;
122128
import org.apache.cloudstack.region.PortableIpRange;
@@ -462,4 +468,10 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
462468
ListResponse<UpgradeRouterTemplateResponse> createUpgradeRouterTemplateResponse(List<Long> jobIds);
463469

464470
SSHKeyPairResponse createSSHKeyPairResponse(SSHKeyPair sshkeyPair, boolean privatekey);
471+
472+
BackupResponse createBackupResponse(Backup backup);
473+
474+
BackupPolicyResponse createBackupPolicyResponse(BackupPolicy policy);
475+
476+
BackupPolicyVMMapResponse createBackupPolicyVMMappingResponse(BackupPolicyVMMap map);
465477
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.backup;
19+
20+
import javax.inject.Inject;
21+
22+
import org.apache.cloudstack.acl.RoleType;
23+
import org.apache.cloudstack.api.APICommand;
24+
import org.apache.cloudstack.api.ApiConstants;
25+
import org.apache.cloudstack.api.ApiErrorCode;
26+
import org.apache.cloudstack.api.BaseCmd;
27+
import org.apache.cloudstack.api.Parameter;
28+
import org.apache.cloudstack.api.ServerApiException;
29+
import org.apache.cloudstack.api.response.BackupPolicyResponse;
30+
import org.apache.cloudstack.api.response.SuccessResponse;
31+
import org.apache.cloudstack.backup.BackupManager;
32+
import org.apache.cloudstack.context.CallContext;
33+
34+
import com.cloud.exception.ConcurrentOperationException;
35+
import com.cloud.exception.InsufficientCapacityException;
36+
import com.cloud.exception.NetworkRuleConflictException;
37+
import com.cloud.exception.ResourceAllocationException;
38+
import com.cloud.exception.ResourceUnavailableException;
39+
40+
@APICommand(name = DeleteBackupPolicyCmd.APINAME,
41+
description = "Deletes a backup policy",
42+
responseObject = SuccessResponse.class, since = "4.12.0",
43+
authorized = {RoleType.Admin})
44+
public class DeleteBackupPolicyCmd extends BaseCmd {
45+
public static final String APINAME = "deleteBackupPolicy";
46+
47+
@Inject
48+
private BackupManager backupManager;
49+
50+
/////////////////////////////////////////////////////
51+
//////////////// API parameters /////////////////////
52+
////////////////////////////////////////////////////
53+
54+
@Parameter(name = ApiConstants.ID,
55+
type = CommandType.UUID,
56+
entityType = BackupPolicyResponse.class,
57+
required = true,
58+
description = "The backup policy internal ID")
59+
private Long id;
60+
61+
/////////////////////////////////////////////////////
62+
/////////////////// Accessors ///////////////////////
63+
/////////////////////////////////////////////////////
64+
65+
public Long getId() {
66+
return id;
67+
}
68+
69+
/////////////////////////////////////////////////////
70+
/////////////// API Implementation///////////////////
71+
/////////////////////////////////////////////////////
72+
73+
@Override
74+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
75+
if (backupManager.deleteBackupPolicy(getId())) {
76+
SuccessResponse response = new SuccessResponse(getCommandName());
77+
setResponseObject(response);
78+
} else {
79+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to remove backup policy: " + getId());
80+
}
81+
}
82+
83+
@Override
84+
public String getCommandName() {
85+
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
86+
}
87+
88+
@Override
89+
public long getEntityOwnerId() {
90+
return CallContext.current().getCallingAccount().getId();
91+
}
92+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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 javax.inject.Inject;
20+
21+
import com.cloud.event.EventTypes;
22+
import org.apache.cloudstack.acl.RoleType;
23+
import org.apache.cloudstack.api.APICommand;
24+
import org.apache.cloudstack.api.ApiConstants;
25+
import org.apache.cloudstack.api.ApiErrorCode;
26+
import org.apache.cloudstack.api.BaseAsyncCmd;
27+
import org.apache.cloudstack.api.BaseCmd;
28+
import org.apache.cloudstack.api.Parameter;
29+
import org.apache.cloudstack.api.ServerApiException;
30+
import org.apache.cloudstack.api.response.BackupPolicyResponse;
31+
import org.apache.cloudstack.api.response.ZoneResponse;
32+
import org.apache.cloudstack.backup.BackupManager;
33+
import org.apache.cloudstack.context.CallContext;
34+
import org.apache.cloudstack.backup.BackupPolicy;
35+
36+
import com.cloud.exception.ConcurrentOperationException;
37+
import com.cloud.exception.InsufficientCapacityException;
38+
import com.cloud.exception.InvalidParameterValueException;
39+
import com.cloud.exception.NetworkRuleConflictException;
40+
import com.cloud.exception.ResourceAllocationException;
41+
import com.cloud.exception.ResourceUnavailableException;
42+
import com.cloud.utils.exception.CloudRuntimeException;
43+
44+
@APICommand(name = ImportBackupPolicyCmd.APINAME,
45+
description = "Imports a backup policy from the backup provider",
46+
responseObject = BackupPolicyResponse.class, since = "4.12.0",
47+
authorized = {RoleType.Admin})
48+
public class ImportBackupPolicyCmd extends BaseAsyncCmd {
49+
public static final String APINAME = "importBackupPolicy";
50+
51+
@Inject
52+
private BackupManager backupManager;
53+
54+
/////////////////////////////////////////////////////
55+
//////////////// API parameters /////////////////////
56+
////////////////////////////////////////////////////
57+
58+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true,
59+
description = "the name of the backup policy")
60+
private String policyName;
61+
62+
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, required = true,
63+
description = "the description of the backup policy")
64+
private String description;
65+
66+
@Parameter(name = ApiConstants.EXTERNAL_ID,
67+
type = CommandType.STRING,
68+
required = true,
69+
description = "The backup policy ID (on backup provider side)")
70+
private String policyExternalId;
71+
72+
@Parameter(name = ApiConstants.ZONE_ID, type = BaseCmd.CommandType.UUID, entityType = ZoneResponse.class,
73+
description = "The zone ID", required = true)
74+
private Long zoneId;
75+
76+
/////////////////////////////////////////////////////
77+
/////////////////// Accessors ///////////////////////
78+
/////////////////////////////////////////////////////
79+
80+
public String getPolicyName() {
81+
return policyName;
82+
}
83+
84+
public String getPolicyExternalId() {
85+
return policyExternalId;
86+
}
87+
88+
public Long getZoneId() {
89+
return zoneId;
90+
}
91+
92+
public String getDescription() {
93+
return description;
94+
}
95+
96+
/////////////////////////////////////////////////////
97+
/////////////// API Implementation///////////////////
98+
/////////////////////////////////////////////////////
99+
100+
@Override
101+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
102+
try {
103+
BackupPolicy policy = backupManager.importBackupPolicy(getZoneId(), getPolicyExternalId(), getPolicyName(), getDescription());
104+
if (policy != null) {
105+
BackupPolicyResponse response = _responseGenerator.createBackupPolicyResponse(policy);
106+
response.setResponseName(getCommandName());
107+
setResponseObject(response);
108+
} else {
109+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add a Backup policy");
110+
}
111+
} catch (InvalidParameterValueException e) {
112+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
113+
} catch (CloudRuntimeException e) {
114+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
115+
}
116+
}
117+
118+
@Override
119+
public String getCommandName() {
120+
return APINAME.toLowerCase() + RESPONSE_SUFFIX;
121+
}
122+
123+
@Override
124+
public long getEntityOwnerId() {
125+
return CallContext.current().getCallingAccount().getId();
126+
}
127+
128+
@Override
129+
public String getEventType() {
130+
return EventTypes.EVENT_IMPORT_BACKUP_POLICY;
131+
}
132+
133+
@Override
134+
public String getEventDescription() {
135+
return "Importing backup policy: " + policyName + " (externalId=" + policyExternalId + ") on zone " + zoneId ;
136+
}
137+
}

0 commit comments

Comments
 (0)