Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2fc49eb
b&r: phase1 all commits melded
yadvr Jun 29, 2018
b62eacb
B&R: Phase 2 commits melded
yadvr Jul 2, 2018
8833ddd
phase2: fix build/dependency issues with winrm
yadvr Aug 16, 2018
660cfa7
Improvements and refactors
nvazquez Aug 23, 2018
240ff82
make API args consistent with arg/types
yadvr Aug 23, 2018
2fe6c44
bugfix: allow listing of vmbackups of removed VMs
yadvr Aug 24, 2018
bceb29f
Bugfixes: import destroyed VM, check if VM is stopped only for existi…
nvazquez Aug 27, 2018
0bf0fbf
Other round of bugfixes
nvazquez Aug 28, 2018
4c1afcf
fix NPE in case usage metrics updation got a removed vmbackup
yadvr Aug 27, 2018
820b445
implemented access/privilege checks based on the access on the VM
yadvr Aug 28, 2018
5c2a460
don't allow reimport of imported policy and don't allow non-root user…
yadvr Aug 28, 2018
f33ab55
Fix CE298
nvazquez Aug 29, 2018
506e8ec
CE-302: restoring a root disk to another VM from a backup shouldnot add
yadvr Aug 29, 2018
49f0f29
CE300 etc: do access check for vmbackup's VM and allow restoring of a…
yadvr Aug 29, 2018
8723698
CE-304: usage type/id should be of the VM
yadvr Aug 29, 2018
8a70f23
better job deletion logic
yadvr Aug 29, 2018
3361ea0
CE-305: don't allow backup policy deletion if vmbackups use it
yadvr Aug 29, 2018
3abc3b8
Fix CE-303
nvazquez Aug 29, 2018
c76c290
Fix CE-298
nvazquez Aug 29, 2018
7da1799
detect volume including removed, for target VM don't search removed VM
yadvr Aug 30, 2018
c5142ca
Add error cause on exception
nvazquez Aug 31, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
B&R: Phase 2 commits melded
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
  • Loading branch information
yadvr committed Aug 22, 2018
commit b62eacba37ad3a966d77049a971b9334a036a971
30 changes: 15 additions & 15 deletions api/src/main/java/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.cloudstack.acl.Role;
import org.apache.cloudstack.acl.RolePermission;
import org.apache.cloudstack.annotation.Annotation;
import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.ha.HAConfig;
import org.apache.cloudstack.usage.Usage;

import com.cloud.dc.DataCenter;
import com.cloud.dc.Pod;
import com.cloud.dc.StorageNetworkIpRange;
Expand Down Expand Up @@ -69,12 +76,6 @@
import com.cloud.vm.Nic;
import com.cloud.vm.NicSecondaryIp;
import com.cloud.vm.VirtualMachine;
import org.apache.cloudstack.acl.Role;
import org.apache.cloudstack.acl.RolePermission;
import org.apache.cloudstack.annotation.Annotation;
import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.ha.HAConfig;
import org.apache.cloudstack.usage.Usage;

public class EventTypes {

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

// VM VMBackup and Recovery events
public static final String EVENT_VM_BACKUP_IMPORT_POLICY = "VMBACKUP.IMPORT.POLICY";
public static final String EVENT_VM_BACKUP_CREATE = "VMBACKUP.CREATE";
public static final String EVENT_VM_BACKUP_START = "VMBACKUP.START";
public static final String EVENT_VM_BACKUP_RESTORE = "VMBACKUP.RESTORE";
public static final String EVENT_VM_BACKUP_DELETE = "VMBACKUP.DELETE";
public static final String EVENT_VM_BACKUP_RESTORE_VOLUME_TO_VM = "VMBACKUP.RESTORE.VOLUME.TO.VM";

// external network device events
public static final String EVENT_EXTERNAL_NVP_CONTROLLER_ADD = "PHYSICAL.NVPCONTROLLER.ADD";
public static final String EVENT_EXTERNAL_NVP_CONTROLLER_DELETE = "PHYSICAL.NVPCONTROLLER.DELETE";
Expand Down Expand Up @@ -584,15 +593,6 @@ public class EventTypes {
public static final String EVENT_TEMPLATE_DIRECT_DOWNLOAD_FAILURE = "TEMPLATE.DIRECT.DOWNLOAD.FAILURE";
public static final String EVENT_ISO_DIRECT_DOWNLOAD_FAILURE = "ISO.DIRECT.DOWNLOAD.FAILURE";

// Backup and Recovery events
public static final String EVENT_ADD_VM_TO_BACKUP_POLICY = "ADD.VM.TO.BACKUP.POLICY";
public static final String EVENT_REMOVE_VM_FROM_BACKUP_POLICY = "REMOVE.VM.FROM.BACKUP.POLICY";
public static final String EVENT_IMPORT_BACKUP_POLICY = "IMPORT.BACKUP.POLICY";
public static final String EVENT_CREATE_VM_BACKUP = "CREATE.VM.BACKUP";
public static final String EVENT_DELETE_VM_BACKUP = "DELETE.VM.BACKUP";
public static final String EVENT_RESTORE_VM_FROM_BACKUP = "RESTORE.VM.FROM.BACKUP";
public static final String EVENT_RESTORE_VOLUME_FROM_BACKUP_AND_ATTACH_TO_VM = "RESTORE.VOLUME.FROM.BACKUP.AND.ATTACH.TO.VM";

static {

// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
Expand Down
7 changes: 7 additions & 0 deletions api/src/main/java/com/cloud/hypervisor/HypervisorGuru.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;

import org.apache.cloudstack.backup.VMBackup;
import org.apache.cloudstack.framework.config.ConfigKey;

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

Map<String, String> getClusterSettings(long vmId);

VirtualMachine importVirtualMachine(long zoneId, long domainId, long accountId, long userId,
String vmInternalName, VMBackup backup) throws Exception;

boolean attachRestoredVolumeToVirtualMachine(long zoneId, String location, VMBackup.VolumeInfo volumeInfo,
VirtualMachine vm, long poolId) throws Exception;
}
1 change: 1 addition & 0 deletions api/src/main/java/com/cloud/server/ResourceTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum ResourceObjectType {
NetworkACL(true, true),
StaticRoute(true, false),
VMSnapshot(true, false),
VMBackup(true, false),
RemoteAccessVpn(true, true),
Zone(false, true),
ServiceOffering(false, true),
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public class ApiConstants {
public static final String RESOURCE_TYPE = "resourcetype";
public static final String RESOURCE_TYPE_NAME = "resourcetypename";
public static final String RESPONSE = "response";
public static final String RESTORE_POINT_ID = "restorepointid";
public static final String REVERTABLE = "revertable";
public static final String REGISTERED = "registered";
public static final String QUERY_FILTER = "queryfilter";
Expand Down Expand Up @@ -615,6 +616,7 @@ public class ApiConstants {
public static final String EXCLUSIVE_GSLB_PROVIDER = "isexclusivegslbprovider";
public static final String GSLB_PROVIDER_PUBLIC_IP = "gslbproviderpublicip";
public static final String GSLB_PROVIDER_PRIVATE_IP = "gslbproviderprivateip";
public static final String VM_BACKUP_ID = "vmbackupid";
public static final String VM_SNAPSHOT_DESCRIPTION = "description";
public static final String VM_SNAPSHOT_DISPLAYNAME = "name";
public static final String VM_SNAPSHOT_ID = "vmsnapshotid";
Expand Down
43 changes: 23 additions & 20 deletions api/src/main/java/org/apache/cloudstack/api/BaseBackupListCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@

package org.apache.cloudstack.api;

import java.util.ArrayList;
import java.util.List;

import org.apache.cloudstack.api.response.BackupPolicyResponse;
import org.apache.cloudstack.api.response.BackupPolicyVMMapResponse;
import org.apache.cloudstack.api.response.BackupResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.backup.BackupPolicyVMMap;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.backup.Backup;
import org.apache.cloudstack.api.response.VMBackupResponse;
import org.apache.cloudstack.api.response.VMBackupRestorePointResponse;
import org.apache.cloudstack.backup.BackupPolicy;

import java.util.ArrayList;
import java.util.List;
import org.apache.cloudstack.backup.VMBackup;
import org.apache.cloudstack.context.CallContext;

public abstract class BaseBackupListCmd extends BaseListCmd {

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

protected void setupResponseBackupList(final List<Backup> backups) {
final ListResponse<BackupResponse> response = new ListResponse<>();
final List<BackupResponse> responses = new ArrayList<>();
for (Backup backup : backups) {
protected void setupResponseBackupList(final List<VMBackup> backups) {
final ListResponse<VMBackupResponse> response = new ListResponse<>();
final List<VMBackupResponse> responses = new ArrayList<>();
for (VMBackup backup : backups) {
if (backup == null) {
continue;
}
BackupResponse backupResponse = _responseGenerator.createBackupResponse(backup);
VMBackupResponse backupResponse = _responseGenerator.createBackupResponse(backup);
responses.add(backupResponse);
}
response.setResponses(responses);
response.setResponseName(getCommandName());
setResponseObject(response);
}

protected void setupResponseBackupPolicyVMMappings(final List<BackupPolicyVMMap> mappings) {
final ListResponse<BackupPolicyVMMapResponse> response = new ListResponse<>();
final List<BackupPolicyVMMapResponse> responses = new ArrayList<>();
for (BackupPolicyVMMap map : mappings) {
if (map == null) {
protected void setupResponseRestorePointsList(final List<VMBackup.RestorePoint> restorePoints) {
final ListResponse<VMBackupRestorePointResponse> response = new ListResponse<>();
final List<VMBackupRestorePointResponse> responses = new ArrayList<>();
for (VMBackup.RestorePoint rp : restorePoints) {
if (rp == null) {
continue;
}
BackupPolicyVMMapResponse resp = _responseGenerator.createBackupPolicyVMMappingResponse(map);
responses.add(resp);
VMBackupRestorePointResponse rpResponse = new VMBackupRestorePointResponse();
rpResponse.setId(rp.getId());
rpResponse.setCreated(rp.getCreated());
rpResponse.setType(rp.getType());
rpResponse.setObjectName("vmbackuprestorepoint");
responses.add(rpResponse);
}
response.setResponses(responses);
response.setResponseName(getCommandName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
import org.apache.cloudstack.api.response.BackupPolicyResponse;
import org.apache.cloudstack.api.response.BackupPolicyVMMapResponse;
import org.apache.cloudstack.api.response.BackupResponse;
import org.apache.cloudstack.api.response.CapacityResponse;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ConditionResponse;
Expand Down Expand Up @@ -111,6 +109,7 @@
import org.apache.cloudstack.api.response.UsageRecordResponse;
import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VMBackupResponse;
import org.apache.cloudstack.api.response.VMSnapshotResponse;
import org.apache.cloudstack.api.response.VirtualRouterProviderResponse;
import org.apache.cloudstack.api.response.VlanIpRangeResponse;
Expand All @@ -120,9 +119,8 @@
import org.apache.cloudstack.api.response.VpnUsersResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.backup.BackupPolicy;
import org.apache.cloudstack.backup.BackupPolicyVMMap;
import org.apache.cloudstack.backup.VMBackup;
import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.backup.Backup;
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
import org.apache.cloudstack.region.PortableIp;
import org.apache.cloudstack.region.PortableIpRange;
Expand Down Expand Up @@ -469,9 +467,7 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine

SSHKeyPairResponse createSSHKeyPairResponse(SSHKeyPair sshkeyPair, boolean privatekey);

BackupResponse createBackupResponse(Backup backup);
VMBackupResponse createBackupResponse(VMBackup backup);

BackupPolicyResponse createBackupPolicyResponse(BackupPolicy policy);

BackupPolicyVMMapResponse createBackupPolicyVMMappingResponse(BackupPolicyVMMap map);
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public long getEntityOwnerId() {

@Override
public String getEventType() {
return EventTypes.EVENT_IMPORT_BACKUP_POLICY;
return EventTypes.EVENT_VM_BACKUP_IMPORT_POLICY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.api.command.admin.vm;

import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.hypervisor.Hypervisor;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.backup.BackupManager;
import org.apache.cloudstack.context.CallContext;

import javax.inject.Inject;

@APICommand(name = ImportVMCmdByAdmin.APINAME,
description = "Import VM",
responseObject = SuccessResponse.class,
since = "4.12.0",
authorized = {RoleType.Admin})
public class ImportVMCmdByAdmin extends BaseAsyncCmd {
public static final String APINAME = "importVM";

@Inject
BackupManager backupManager;

@Parameter(name = ApiConstants.NAME,
type = CommandType.STRING,
required = true,
description = "VM Internal name")
private String vmInternalName;

@Parameter(name = ApiConstants.ZONE_ID, type = BaseCmd.CommandType.UUID, entityType = ZoneResponse.class,
description = "The zone ID", required = true)
private Long zoneId;

@Override
public String getEventType() {
return "IMPORT.VM";
}

@Override
public String getEventDescription() {
return "Importing VM";
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
long accountId = CallContext.current().getCallingAccountId();
long userId = CallContext.current().getCallingUserId();
long domainId = CallContext.current().getCallingAccount().getDomainId();
boolean result = backupManager.importVM(zoneId, domainId, accountId, userId, vmInternalName,
Hypervisor.HypervisorType.VMware, null);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to import VM");
}
}

@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}

public String getVmInternalName() {
return vmInternalName;
}

public Long getZoneId() {
return zoneId;
}
}
Loading