Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2fc49eb
b&r: phase1 all commits melded
rohityadavcloud Jun 29, 2018
b62eacb
B&R: Phase 2 commits melded
rohityadavcloud Jul 2, 2018
8833ddd
phase2: fix build/dependency issues with winrm
rohityadavcloud Aug 16, 2018
660cfa7
Improvements and refactors
nvazquez Aug 23, 2018
240ff82
make API args consistent with arg/types
rohityadavcloud Aug 23, 2018
2fe6c44
bugfix: allow listing of vmbackups of removed VMs
rohityadavcloud 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
rohityadavcloud Aug 27, 2018
820b445
implemented access/privilege checks based on the access on the VM
rohityadavcloud Aug 28, 2018
5c2a460
don't allow reimport of imported policy and don't allow non-root user…
rohityadavcloud 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
rohityadavcloud Aug 29, 2018
49f0f29
CE300 etc: do access check for vmbackup's VM and allow restoring of a…
rohityadavcloud Aug 29, 2018
8723698
CE-304: usage type/id should be of the VM
rohityadavcloud Aug 29, 2018
8a70f23
better job deletion logic
rohityadavcloud Aug 29, 2018
3361ea0
CE-305: don't allow backup policy deletion if vmbackups use it
rohityadavcloud 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
rohityadavcloud 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
21 changes: 15 additions & 6 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
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, VMBackup backup) 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
4 changes: 4 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 @@ -121,6 +121,7 @@ public class ApiConstants {
public static final String EXTRA_DHCP_OPTION_NAME = "extradhcpoptionname";
public static final String EXTRA_DHCP_OPTION_CODE = "extradhcpoptioncode";
public static final String EXTRA_DHCP_OPTION_VALUE = "extradhcpvalue";
public static final String EXTERNAL = "external";
public static final String FENCE = "fence";
public static final String FETCH_LATEST = "fetchlatest";
public static final String FIRSTNAME = "firstname";
Expand Down Expand Up @@ -253,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 @@ -336,6 +338,7 @@ public class ApiConstants {
public static final String VNET = "vnet";
public static final String IS_VOLATILE = "isvolatile";
public static final String VOLUME_ID = "volumeid";
public static final String VOLUMES = "volumes";
public static final String ZONE_ID = "zoneid";
public static final String ZONE_NAME = "zonename";
public static final String NETWORK_TYPE = "networktype";
Expand Down Expand Up @@ -613,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
86 changes: 86 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/BaseBackupListCmd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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;

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

import org.apache.cloudstack.api.response.BackupPolicyResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.VMBackupResponse;
import org.apache.cloudstack.api.response.VMBackupRestorePointResponse;
import org.apache.cloudstack.backup.BackupPolicy;
import org.apache.cloudstack.backup.VMBackup;
import org.apache.cloudstack.context.CallContext;

public abstract class BaseBackupListCmd extends BaseListCmd {

protected void setupResponseBackupPolicyList(final List<BackupPolicy> policies) {
final ListResponse<BackupPolicyResponse> response = new ListResponse<>();
final List<BackupPolicyResponse> responses = new ArrayList<>();
for (final BackupPolicy policy : policies) {
if (policy == null) {
continue;
}
BackupPolicyResponse backupPolicyResponse = _responseGenerator.createBackupPolicyResponse(policy);
responses.add(backupPolicyResponse);
}
response.setResponses(responses);
response.setResponseName(getCommandName());
setResponseObject(response);
}

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;
}
VMBackupResponse backupResponse = _responseGenerator.createBackupResponse(backup);
responses.add(backupResponse);
}
response.setResponses(responses);
response.setResponseName(getCommandName());
setResponseObject(response);
}

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;
}
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());
setResponseObject(response);
}

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.cloudstack.api.response.AutoScalePolicyResponse;
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.CapacityResponse;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ConditionResponse;
Expand Down Expand Up @@ -108,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 @@ -116,6 +118,8 @@
import org.apache.cloudstack.api.response.VpcResponse;
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.VMBackup;
import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
import org.apache.cloudstack.region.PortableIp;
Expand Down Expand Up @@ -462,4 +466,8 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
ListResponse<UpgradeRouterTemplateResponse> createUpgradeRouterTemplateResponse(List<Long> jobIds);

SSHKeyPairResponse createSSHKeyPairResponse(SSHKeyPair sshkeyPair, boolean privatekey);

VMBackupResponse createBackupResponse(VMBackup backup);

BackupPolicyResponse createBackupPolicyResponse(BackupPolicy policy);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// 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.backup;

import javax.inject.Inject;

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.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.BackupPolicyResponse;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.backup.BackupManager;
import org.apache.cloudstack.context.CallContext;

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;

@APICommand(name = DeleteBackupPolicyCmd.APINAME,
description = "Deletes a backup policy",
responseObject = SuccessResponse.class, since = "4.12.0",
authorized = {RoleType.Admin})
public class DeleteBackupPolicyCmd extends BaseCmd {
public static final String APINAME = "deleteBackupPolicy";

@Inject
private BackupManager backupManager;

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
////////////////////////////////////////////////////

@Parameter(name = ApiConstants.ID,
type = CommandType.UUID,
entityType = BackupPolicyResponse.class,
required = true,
description = "The backup policy internal ID")
private Long id;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////

public Long getId() {
return id;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
if (backupManager.deleteBackupPolicy(getId())) {
SuccessResponse response = new SuccessResponse(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to remove backup policy: " + getId());
}
}

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

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