Skip to content

Commit 7f97040

Browse files
yadvrnvazquez
authored andcommitted
B&R: Phase 2 commits melded
1 parent cfea35c commit 7f97040

File tree

79 files changed

+3473
-1618
lines changed

Some content is hidden

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

79 files changed

+3473
-1618
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22+
import org.apache.cloudstack.acl.Role;
23+
import org.apache.cloudstack.acl.RolePermission;
24+
import org.apache.cloudstack.annotation.Annotation;
25+
import org.apache.cloudstack.config.Configuration;
26+
import org.apache.cloudstack.ha.HAConfig;
27+
import org.apache.cloudstack.usage.Usage;
28+
2229
import com.cloud.dc.DataCenter;
2330
import com.cloud.dc.Pod;
2431
import com.cloud.dc.StorageNetworkIpRange;
@@ -69,12 +76,6 @@
6976
import com.cloud.vm.Nic;
7077
import com.cloud.vm.NicSecondaryIp;
7178
import com.cloud.vm.VirtualMachine;
72-
import org.apache.cloudstack.acl.Role;
73-
import org.apache.cloudstack.acl.RolePermission;
74-
import org.apache.cloudstack.annotation.Annotation;
75-
import org.apache.cloudstack.config.Configuration;
76-
import org.apache.cloudstack.ha.HAConfig;
77-
import org.apache.cloudstack.usage.Usage;
7879

7980
public class EventTypes {
8081

@@ -469,6 +470,14 @@ public class EventTypes {
469470
public static final String EVENT_VM_SNAPSHOT_OFF_PRIMARY = "VMSNAPSHOT.OFF_PRIMARY";
470471
public static final String EVENT_VM_SNAPSHOT_REVERT = "VMSNAPSHOT.REVERTTO";
471472

473+
// VM VMBackup and Recovery events
474+
public static final String EVENT_VM_BACKUP_IMPORT_POLICY = "VMBACKUP.IMPORT.POLICY";
475+
public static final String EVENT_VM_BACKUP_CREATE = "VMBACKUP.CREATE";
476+
public static final String EVENT_VM_BACKUP_START = "VMBACKUP.START";
477+
public static final String EVENT_VM_BACKUP_RESTORE = "VMBACKUP.RESTORE";
478+
public static final String EVENT_VM_BACKUP_DELETE = "VMBACKUP.DELETE";
479+
public static final String EVENT_VM_BACKUP_RESTORE_VOLUME_TO_VM = "VMBACKUP.RESTORE.VOLUME.TO.VM";
480+
472481
// external network device events
473482
public static final String EVENT_EXTERNAL_NVP_CONTROLLER_ADD = "PHYSICAL.NVPCONTROLLER.ADD";
474483
public static final String EVENT_EXTERNAL_NVP_CONTROLLER_DELETE = "PHYSICAL.NVPCONTROLLER.DELETE";
@@ -584,15 +593,6 @@ public class EventTypes {
584593
public static final String EVENT_TEMPLATE_DIRECT_DOWNLOAD_FAILURE = "TEMPLATE.DIRECT.DOWNLOAD.FAILURE";
585594
public static final String EVENT_ISO_DIRECT_DOWNLOAD_FAILURE = "ISO.DIRECT.DOWNLOAD.FAILURE";
586595

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-
596596
static {
597597

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

api/src/main/java/com/cloud/hypervisor/HypervisorGuru.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.List;
2020
import java.util.Map;
2121

22+
import org.apache.cloudstack.backup.VMBackup;
2223
import org.apache.cloudstack.framework.config.ConfigKey;
2324

2425
import com.cloud.agent.api.Command;
@@ -84,4 +85,10 @@ public interface HypervisorGuru extends Adapter {
8485
List<Command> finalizeExpungeVolumes(VirtualMachine vm);
8586

8687
Map<String, String> getClusterSettings(long vmId);
88+
89+
VirtualMachine importVirtualMachine(long zoneId, long domainId, long accountId, long userId,
90+
String vmInternalName, VMBackup backup) throws Exception;
91+
92+
boolean attachRestoredVolumeToVirtualMachine(long zoneId, String location, VMBackup.VolumeInfo volumeInfo,
93+
VirtualMachine vm, long poolId) throws Exception;
8794
}

api/src/main/java/com/cloud/server/ResourceTag.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public enum ResourceObjectType {
4343
NetworkACL(true, true),
4444
StaticRoute(true, false),
4545
VMSnapshot(true, false),
46+
VMBackup(true, false),
4647
RemoteAccessVpn(true, true),
4748
Zone(false, true),
4849
ServiceOffering(false, true),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ public class ApiConstants {
253253
public static final String RESOURCE_TYPE = "resourcetype";
254254
public static final String RESOURCE_TYPE_NAME = "resourcetypename";
255255
public static final String RESPONSE = "response";
256+
public static final String RESTORE_POINT_ID = "restorepointid";
256257
public static final String REVERTABLE = "revertable";
257258
public static final String REGISTERED = "registered";
258259
public static final String QUERY_FILTER = "queryfilter";
@@ -613,6 +614,7 @@ public class ApiConstants {
613614
public static final String EXCLUSIVE_GSLB_PROVIDER = "isexclusivegslbprovider";
614615
public static final String GSLB_PROVIDER_PUBLIC_IP = "gslbproviderpublicip";
615616
public static final String GSLB_PROVIDER_PRIVATE_IP = "gslbproviderprivateip";
617+
public static final String VM_BACKUP_ID = "vmbackupid";
616618
public static final String VM_SNAPSHOT_DESCRIPTION = "description";
617619
public static final String VM_SNAPSHOT_DISPLAYNAME = "name";
618620
public static final String VM_SNAPSHOT_ID = "vmsnapshotid";

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

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717

1818
package org.apache.cloudstack.api;
1919

20+
import java.util.ArrayList;
21+
import java.util.List;
22+
2023
import org.apache.cloudstack.api.response.BackupPolicyResponse;
21-
import org.apache.cloudstack.api.response.BackupPolicyVMMapResponse;
22-
import org.apache.cloudstack.api.response.BackupResponse;
2324
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;
25+
import org.apache.cloudstack.api.response.VMBackupResponse;
26+
import org.apache.cloudstack.api.response.VMBackupRestorePointResponse;
2727
import org.apache.cloudstack.backup.BackupPolicy;
28-
29-
import java.util.ArrayList;
30-
import java.util.List;
28+
import org.apache.cloudstack.backup.VMBackup;
29+
import org.apache.cloudstack.context.CallContext;
3130

3231
public abstract class BaseBackupListCmd extends BaseListCmd {
3332

@@ -46,30 +45,34 @@ protected void setupResponseBackupPolicyList(final List<BackupPolicy> policies)
4645
setResponseObject(response);
4746
}
4847

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) {
48+
protected void setupResponseBackupList(final List<VMBackup> backups) {
49+
final ListResponse<VMBackupResponse> response = new ListResponse<>();
50+
final List<VMBackupResponse> responses = new ArrayList<>();
51+
for (VMBackup backup : backups) {
5352
if (backup == null) {
5453
continue;
5554
}
56-
BackupResponse backupResponse = _responseGenerator.createBackupResponse(backup);
55+
VMBackupResponse backupResponse = _responseGenerator.createBackupResponse(backup);
5756
responses.add(backupResponse);
5857
}
5958
response.setResponses(responses);
6059
response.setResponseName(getCommandName());
6160
setResponseObject(response);
6261
}
6362

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) {
63+
protected void setupResponseRestorePointsList(final List<VMBackup.RestorePoint> restorePoints) {
64+
final ListResponse<VMBackupRestorePointResponse> response = new ListResponse<>();
65+
final List<VMBackupRestorePointResponse> responses = new ArrayList<>();
66+
for (VMBackup.RestorePoint rp : restorePoints) {
67+
if (rp == null) {
6968
continue;
7069
}
71-
BackupPolicyVMMapResponse resp = _responseGenerator.createBackupPolicyVMMappingResponse(map);
72-
responses.add(resp);
70+
VMBackupRestorePointResponse rpResponse = new VMBackupRestorePointResponse();
71+
rpResponse.setId(rp.getId());
72+
rpResponse.setCreated(rp.getCreated());
73+
rpResponse.setType(rp.getType());
74+
rpResponse.setObjectName("vmbackuprestorepoint");
75+
responses.add(rpResponse);
7376
}
7477
response.setResponses(responses);
7578
response.setResponseName(getCommandName());

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
3636
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
3737
import org.apache.cloudstack.api.response.BackupPolicyResponse;
38-
import org.apache.cloudstack.api.response.BackupPolicyVMMapResponse;
39-
import org.apache.cloudstack.api.response.BackupResponse;
4038
import org.apache.cloudstack.api.response.CapacityResponse;
4139
import org.apache.cloudstack.api.response.ClusterResponse;
4240
import org.apache.cloudstack.api.response.ConditionResponse;
@@ -111,6 +109,7 @@
111109
import org.apache.cloudstack.api.response.UsageRecordResponse;
112110
import org.apache.cloudstack.api.response.UserResponse;
113111
import org.apache.cloudstack.api.response.UserVmResponse;
112+
import org.apache.cloudstack.api.response.VMBackupResponse;
114113
import org.apache.cloudstack.api.response.VMSnapshotResponse;
115114
import org.apache.cloudstack.api.response.VirtualRouterProviderResponse;
116115
import org.apache.cloudstack.api.response.VlanIpRangeResponse;
@@ -120,9 +119,8 @@
120119
import org.apache.cloudstack.api.response.VpnUsersResponse;
121120
import org.apache.cloudstack.api.response.ZoneResponse;
122121
import org.apache.cloudstack.backup.BackupPolicy;
123-
import org.apache.cloudstack.backup.BackupPolicyVMMap;
122+
import org.apache.cloudstack.backup.VMBackup;
124123
import org.apache.cloudstack.config.Configuration;
125-
import org.apache.cloudstack.backup.Backup;
126124
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
127125
import org.apache.cloudstack.region.PortableIp;
128126
import org.apache.cloudstack.region.PortableIpRange;
@@ -469,9 +467,7 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
469467

470468
SSHKeyPairResponse createSSHKeyPairResponse(SSHKeyPair sshkeyPair, boolean privatekey);
471469

472-
BackupResponse createBackupResponse(Backup backup);
470+
VMBackupResponse createBackupResponse(VMBackup backup);
473471

474472
BackupPolicyResponse createBackupPolicyResponse(BackupPolicy policy);
475-
476-
BackupPolicyVMMapResponse createBackupPolicyVMMappingResponse(BackupPolicyVMMap map);
477473
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public long getEntityOwnerId() {
127127

128128
@Override
129129
public String getEventType() {
130-
return EventTypes.EVENT_IMPORT_BACKUP_POLICY;
130+
return EventTypes.EVENT_VM_BACKUP_IMPORT_POLICY;
131131
}
132132

133133
@Override
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.vm;
18+
19+
import com.cloud.exception.ConcurrentOperationException;
20+
import com.cloud.exception.InsufficientCapacityException;
21+
import com.cloud.exception.NetworkRuleConflictException;
22+
import com.cloud.exception.ResourceAllocationException;
23+
import com.cloud.exception.ResourceUnavailableException;
24+
import com.cloud.hypervisor.Hypervisor;
25+
import org.apache.cloudstack.acl.RoleType;
26+
import org.apache.cloudstack.api.APICommand;
27+
import org.apache.cloudstack.api.ApiConstants;
28+
import org.apache.cloudstack.api.ApiErrorCode;
29+
import org.apache.cloudstack.api.BaseAsyncCmd;
30+
import org.apache.cloudstack.api.BaseCmd;
31+
import org.apache.cloudstack.api.Parameter;
32+
import org.apache.cloudstack.api.ServerApiException;
33+
import org.apache.cloudstack.api.response.SuccessResponse;
34+
import org.apache.cloudstack.api.response.ZoneResponse;
35+
import org.apache.cloudstack.backup.BackupManager;
36+
import org.apache.cloudstack.context.CallContext;
37+
38+
import javax.inject.Inject;
39+
40+
@APICommand(name = ImportVMCmdByAdmin.APINAME,
41+
description = "Import VM",
42+
responseObject = SuccessResponse.class,
43+
since = "4.12.0",
44+
authorized = {RoleType.Admin})
45+
public class ImportVMCmdByAdmin extends BaseAsyncCmd {
46+
public static final String APINAME = "importVM";
47+
48+
@Inject
49+
BackupManager backupManager;
50+
51+
@Parameter(name = ApiConstants.NAME,
52+
type = CommandType.STRING,
53+
required = true,
54+
description = "VM Internal name")
55+
private String vmInternalName;
56+
57+
@Parameter(name = ApiConstants.ZONE_ID, type = BaseCmd.CommandType.UUID, entityType = ZoneResponse.class,
58+
description = "The zone ID", required = true)
59+
private Long zoneId;
60+
61+
@Override
62+
public String getEventType() {
63+
return "IMPORT.VM";
64+
}
65+
66+
@Override
67+
public String getEventDescription() {
68+
return "Importing VM";
69+
}
70+
71+
@Override
72+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
73+
long accountId = CallContext.current().getCallingAccountId();
74+
long userId = CallContext.current().getCallingUserId();
75+
long domainId = CallContext.current().getCallingAccount().getDomainId();
76+
boolean result = backupManager.importVM(zoneId, domainId, accountId, userId, vmInternalName,
77+
Hypervisor.HypervisorType.VMware, null);
78+
if (result) {
79+
SuccessResponse response = new SuccessResponse(getCommandName());
80+
setResponseObject(response);
81+
} else {
82+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to import VM");
83+
}
84+
}
85+
86+
@Override
87+
public String getCommandName() {
88+
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
89+
}
90+
91+
@Override
92+
public long getEntityOwnerId() {
93+
return CallContext.current().getCallingAccount().getId();
94+
}
95+
96+
public String getVmInternalName() {
97+
return vmInternalName;
98+
}
99+
100+
public Long getZoneId() {
101+
return zoneId;
102+
}
103+
}

0 commit comments

Comments
 (0)