Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
ccec1bc
feature: VM Backup and Recovery
yadvr Nov 19, 2019
6e8778b
remove id req.
yadvr Nov 19, 2019
b75f35e
apidoc: fix section name
yadvr Nov 19, 2019
21509bd
don't allow duplicates by name in the same zone
yadvr Nov 20, 2019
3edec49
implement the asyncjob based scheduler design in db
yadvr Nov 20, 2019
6646353
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Nov 21, 2019
f1b957b
fix missing methods
yadvr Nov 21, 2019
cff613d
schedule apis
yadvr Nov 21, 2019
9f6a2e6
more apis, backend support and refactorings
yadvr Nov 21, 2019
4e1cf0d
add assignment/removal APIs
yadvr Nov 21, 2019
5a0bdb1
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Nov 25, 2019
97b7b69
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Nov 28, 2019
e536282
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Nov 30, 2019
a2e6452
list api pagination and searching etc.
yadvr Nov 30, 2019
50c44a6
api layer changes and refactorings
yadvr Nov 30, 2019
33d580d
minor fixes
yadvr Dec 1, 2019
73f3d58
fix deletion corner cases
yadvr Dec 1, 2019
25b658c
handle case of force vm removal from offering to delete job/backups f…
yadvr Dec 1, 2019
8308241
backup scheduled crud apis
yadvr Dec 1, 2019
63b41d2
apidocs comments
yadvr Dec 1, 2019
aebb61a
major refactorings per new spec updates
yadvr Dec 5, 2019
57d6c1f
more refactorings
yadvr Dec 5, 2019
ad5d882
more refactorings
yadvr Dec 5, 2019
8c7d42f
api and schema refactorings, end to end
yadvr Dec 5, 2019
a57ae37
cleanup: remove unused class
yadvr Dec 5, 2019
8b0fa1b
fix both metrics and backup sync in the thread
yadvr Dec 5, 2019
b66e8d7
misc fixes
yadvr Dec 5, 2019
00c87b8
fixes
yadvr Dec 5, 2019
4746d05
fix bugz
yadvr Dec 5, 2019
0d3934e
more fixes
yadvr Dec 5, 2019
cf9cbfc
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Dec 6, 2019
0c2ec55
refactorings and fixes
yadvr Dec 7, 2019
14330ab
missing declr.
yadvr Dec 7, 2019
a2a5436
minor fixes
yadvr Dec 7, 2019
2c8095b
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Dec 7, 2019
0dbf44a
implement backup schedule execution logic using timer and locks
yadvr Dec 8, 2019
47c255b
return backupoffering name/id in list VMs api for UI
yadvr Dec 8, 2019
6eee0eb
offerings fixes
yadvr Dec 8, 2019
1a866b9
ui fixes
yadvr Dec 8, 2019
cd5f983
fixes
yadvr Dec 8, 2019
a6cf24c
rename to id instead of backupid for consistency
yadvr Dec 8, 2019
65f2d25
fix GC logic for veeam
yadvr Dec 8, 2019
a355c33
minor fix
yadvr Dec 9, 2019
5003d24
minor fixes from self review
yadvr Dec 9, 2019
e3c500a
vmware: fix issue, find including removed for volume of an expunged VM
yadvr Dec 9, 2019
7bb19a1
bugfix - restore expunged vm case wip
yadvr Dec 9, 2019
4bbf1e5
fixes
yadvr Dec 9, 2019
b6a2db1
fixes fixes fixes
yadvr Dec 9, 2019
50deb58
handle many edge cases around VM restoration of an expunged VM
yadvr Dec 10, 2019
c8e368c
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Dec 10, 2019
8e1fe3a
add ui button/forms
yadvr Dec 10, 2019
b776650
backup schedule ui finish testing+fixes
yadvr Dec 10, 2019
8f0c511
more edge case fixes
yadvr Dec 10, 2019
cc2055e
allow granularity if user-driven backups (adhoc+scheduled) are allowed
yadvr Dec 11, 2019
f32d5b1
fix edge case when veeam job+backups are removed but not synced
yadvr Dec 11, 2019
c20fe2c
fix build issue
yadvr Dec 11, 2019
b014532
use row-lock based VM instance updation
yadvr Dec 11, 2019
81e85ce
fix usage record generation, track backup offering in helper table
yadvr Dec 11, 2019
7f6577e
fixes
yadvr Dec 11, 2019
4e2be13
test+travis
yadvr Dec 11, 2019
48122fa
meorefixes
yadvr Dec 11, 2019
b3bb5cd
ffffixes
yadvr Dec 11, 2019
a4ccfea
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Dec 11, 2019
b56149f
fix setting enable/revert, to make it pass on travis
yadvr Dec 13, 2019
dd50888
address review comments
yadvr Dec 20, 2019
5833cf1
fix build
yadvr Dec 20, 2019
71142ad
build fix
yadvr Dec 20, 2019
5220899
Merge branch 'master' into bckuprecframework
yadvr Jan 14, 2020
7677eab
Merge branch 'master' into bckuprecframework
yadvr Jan 28, 2020
3cca470
Merge branch 'master' into bckuprecframework
yadvr Jan 30, 2020
d538e0b
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Feb 5, 2020
bc4b125
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Feb 7, 2020
a1e20a5
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Feb 7, 2020
1722125
fix merge conflict issue
yadvr Feb 7, 2020
7e78da1
make veeam password secure
yadvr Feb 7, 2020
03c9104
fix schema issue in B&R
yadvr Feb 7, 2020
4d9fa83
fix issue of VM assignment failure, instead ask users to remove assig…
yadvr Feb 7, 2020
a22efef
handle any exception
yadvr Feb 7, 2020
efc425f
Merge branch 'master' into bckuprecframework
yadvr Feb 8, 2020
2453d73
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Feb 12, 2020
fa8e78f
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Feb 13, 2020
5b6d8de
veeam fix auth issue per latest 9.x version
yadvr Feb 13, 2020
12d71c4
fix unit test fail
yadvr Feb 13, 2020
eb65700
check session id in the constructor which calls authenticate(); fail …
yadvr Feb 13, 2020
c71d281
fix auth issue
yadvr Feb 17, 2020
099e18d
add log statement
yadvr Feb 17, 2020
72ab892
fixes
yadvr Feb 18, 2020
b9cec97
fix assignment
yadvr Feb 18, 2020
0e134f2
enable disabled cloned job
yadvr Feb 18, 2020
f0d1860
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Feb 19, 2020
5e7e3d7
sync without in a transaction, DB updates are not inter-dependent
yadvr Feb 19, 2020
f54a473
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Feb 20, 2020
c5c54af
run restore VM operations in background and poll until completion
yadvr Feb 20, 2020
066a439
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Feb 24, 2020
008fdd1
ui: tell users that only backup has started, not created
yadvr Feb 24, 2020
4f20f76
backup: don't allow backup offering attach for vms not in running, st…
yadvr Feb 24, 2020
9047577
dummy: fix dummy B&R test smoketest
yadvr Feb 24, 2020
7e24faf
veeam: fix potential NPE on no backend jobs
yadvr Feb 25, 2020
15ddbc7
veeam: only discover/list consistent restore points (not corrupt or t…
yadvr Feb 26, 2020
9b0afed
make pipe explicit, guard within parenthesis
yadvr Feb 26, 2020
a461606
Merge remote-tracking branch 'origin/master' into bckuprecframework
yadvr Feb 26, 2020
b850ba7
escape powershell pipe character
yadvr Feb 26, 2020
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ env:
smoke/test_affinity_groups
smoke/test_affinity_groups_projects
smoke/test_async_job
smoke/test_backup_recovery_dummy
smoke/test_create_list_domain_account_project
smoke/test_create_network
smoke/test_deploy_vgpu_enabled_vm
Expand Down
11 changes: 11 additions & 0 deletions api/src/main/java/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,17 @@ 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";

// Backup and Recovery events
public static final String EVENT_VM_BACKUP_IMPORT_OFFERING = "BACKUP.IMPORT.OFFERING";
public static final String EVENT_VM_BACKUP_OFFERING_ASSIGN = "BACKUP.OFFERING.ASSIGN";
public static final String EVENT_VM_BACKUP_OFFERING_REMOVE = "BACKUP.OFFERING.REMOVE";
public static final String EVENT_VM_BACKUP_CREATE = "BACKUP.CREATE";
public static final String EVENT_VM_BACKUP_RESTORE = "BACKUP.RESTORE";
public static final String EVENT_VM_BACKUP_DELETE = "BACKUP.DELETE";
public static final String EVENT_VM_BACKUP_RESTORE_VOLUME_TO_VM = "BACKUP.RESTORE.VOLUME.TO.VM";
public static final String EVENT_VM_BACKUP_SCHEDULE_CONFIGURE = "BACKUP.SCHEDULE.CONFIGURE";
public static final String EVENT_VM_BACKUP_SCHEDULE_DELETE = "BACKUP.SCHEDULE.DELETE";

// 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
8 changes: 7 additions & 1 deletion api/src/main/java/com/cloud/hypervisor/HypervisorGuru.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
import java.util.List;
import java.util.Map;

import com.cloud.storage.StoragePool;
import org.apache.cloudstack.backup.Backup;
import org.apache.cloudstack.framework.config.ConfigKey;

import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.StoragePool;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Adapter;
import com.cloud.vm.NicProfile;
Expand Down Expand Up @@ -86,6 +87,11 @@ public interface HypervisorGuru extends Adapter {

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

VirtualMachine importVirtualMachineFromBackup(long zoneId, long domainId, long accountId, long userId,
String vmInternalName, Backup backup) throws Exception;

boolean attachRestoredVolumeToVirtualMachine(long zoneId, String location, Backup.VolumeInfo volumeInfo,
VirtualMachine vm, long poolId, Backup backup) throws Exception;
/**
* Will generate commands to migrate a vm to a pool. For now this will only work for stopped VMs on Vmware.
*
Expand Down
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 @@ -29,6 +29,7 @@ public enum ResourceObjectType {
ISO(true, false),
Volume(true, true),
Snapshot(true, false),
Backup(true, false),
Network(true, true),
Nic(false, true),
LoadBalancer(true, true),
Expand Down
23 changes: 16 additions & 7 deletions api/src/main/java/com/cloud/vm/VirtualMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@
// under the License.
package com.cloud.vm;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.api.Displayable;
import org.apache.cloudstack.backup.Backup;
import org.apache.cloudstack.kernel.Partition;

import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.fsm.StateMachine2;
import com.cloud.utils.fsm.StateMachine2.Transition;
import com.cloud.utils.fsm.StateMachine2.Transition.Impact;
import com.cloud.utils.fsm.StateObject;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.api.Displayable;
import org.apache.cloudstack.kernel.Partition;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
* VirtualMachine describes the properties held by a virtual machine
Expand Down Expand Up @@ -319,6 +322,12 @@ public boolean isUsedBySystem() {

Long getDiskOfferingId();

Long getBackupOfferingId();

String getBackupExternalId();

List<Backup.VolumeInfo> getBackupVolumeList();

Type getType();

HypervisorType getHypervisorType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum ApiCommandJobType {
Volume,
ConsoleProxy,
Snapshot,
Backup,
Template,
Iso,
SystemVm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class ApiConstants {
public static final String APPLIED = "applied";
public static final String LIST_LB_VMIPS = "lbvmips";
public static final String AVAILABLE = "available";
public static final String BACKUP_ID = "backupid";
public static final String BACKUP_OFFERING_NAME = "backupofferingname";
public static final String BACKUP_OFFERING_ID = "backupofferingid";
public static final String BITS = "bits";
public static final String BOOTABLE = "bootable";
public static final String BIND_DN = "binddn";
Expand Down Expand Up @@ -144,6 +147,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 @@ -366,6 +370,7 @@ public class ApiConstants {
public static final String VALUE = "value";
public static final String VIRTUAL_MACHINE_ID = "virtualmachineid";
public static final String VIRTUAL_MACHINE_IDS = "virtualmachineids";
public static final String VIRTUAL_MACHINE_NAME = "virtualmachinename";
public static final String VIRTUAL_MACHINE_ID_IP = "vmidipmap";
public static final String VIRTUAL_MACHINE_COUNT = "virtualmachinecount";
public static final String USAGE_ID = "usageid";
Expand All @@ -385,6 +390,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 = "zone";
public static final String ZONE_ID = "zoneid";
public static final String ZONE_NAME = "zonename";
Expand Down Expand Up @@ -531,6 +537,7 @@ public class ApiConstants {
public static final String REQUIRED = "required";
public static final String RESTART_REQUIRED = "restartrequired";
public static final String ALLOW_USER_CREATE_PROJECTS = "allowusercreateprojects";
public static final String ALLOW_USER_DRIVEN_BACKUPS = "allowuserdrivenbackups";
public static final String CONSERVE_MODE = "conservemode";
public static final String TRAFFIC_TYPE_IMPLEMENTOR = "traffictypeimplementor";
public static final String KEYWORD = "keyword";
Expand Down Expand Up @@ -780,7 +787,7 @@ public enum HostDetails {
}

public enum VMDetails {
all, group, nics, stats, secgrp, tmpl, servoff, diskoff, iso, volume, min, affgrp;
all, group, nics, stats, secgrp, tmpl, servoff, diskoff, backoff, iso, volume, min, affgrp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spello? back-up versus -off? Or act of aggression ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha :), to keep it abbreviated, like servoff, diskoff etc.

}

public enum DomainDetails {
Expand Down
49 changes: 49 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,49 @@
// 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.BackupOfferingResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.backup.BackupOffering;
import org.apache.cloudstack.context.CallContext;

public abstract class BaseBackupListCmd extends BaseListCmd {

protected void setupResponseBackupOfferingsList(final List<BackupOffering> offerings, final Integer count) {
final ListResponse<BackupOfferingResponse> response = new ListResponse<>();
final List<BackupOfferingResponse> responses = new ArrayList<>();
for (final BackupOffering offering : offerings) {
if (offering == null) {
continue;
}
BackupOfferingResponse backupOfferingResponse = _responseGenerator.createBackupOfferingResponse(offering);
responses.add(backupOfferingResponse);
}
response.setResponses(responses, count);
response.setResponseName(getCommandName());
setResponseObject(response);
}

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}
}
16 changes: 14 additions & 2 deletions api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.Map;
import java.util.Set;

import org.apache.cloudstack.api.response.RouterHealthCheckResultResponse;
import org.apache.cloudstack.management.ManagementServerHost;
import org.apache.cloudstack.affinity.AffinityGroup;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
Expand All @@ -36,6 +34,8 @@
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.BackupOfferingResponse;
import org.apache.cloudstack.api.response.BackupScheduleResponse;
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 @@ -88,6 +88,7 @@
import org.apache.cloudstack.api.response.ResourceCountResponse;
import org.apache.cloudstack.api.response.ResourceLimitResponse;
import org.apache.cloudstack.api.response.ResourceTagResponse;
import org.apache.cloudstack.api.response.RouterHealthCheckResultResponse;
import org.apache.cloudstack.api.response.SSHKeyPairResponse;
import org.apache.cloudstack.api.response.SecurityGroupResponse;
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
Expand All @@ -111,6 +112,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.BackupResponse;
import org.apache.cloudstack.api.response.VMSnapshotResponse;
import org.apache.cloudstack.api.response.VirtualRouterProviderResponse;
import org.apache.cloudstack.api.response.VlanIpRangeResponse;
Expand All @@ -119,7 +121,11 @@
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.BackupOffering;
import org.apache.cloudstack.backup.Backup;
import org.apache.cloudstack.backup.BackupSchedule;
import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.management.ManagementServerHost;
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
import org.apache.cloudstack.region.PortableIp;
import org.apache.cloudstack.region.PortableIpRange;
Expand Down Expand Up @@ -467,6 +473,12 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine

SSHKeyPairResponse createSSHKeyPairResponse(SSHKeyPair sshkeyPair, boolean privatekey);

BackupResponse createBackupResponse(Backup backup);

BackupScheduleResponse createBackupScheduleResponse(BackupSchedule backup);

BackupOfferingResponse createBackupOfferingResponse(BackupOffering policy);

ManagementServerResponse createManagementResponse(ManagementServerHost mgmt);

List<RouterHealthCheckResultResponse> createHealthCheckResponse(VirtualMachine router, List<RouterHealthCheckResult> healthCheckResults);
Expand Down
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.BackupOfferingResponse;
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 = DeleteBackupOfferingCmd.APINAME,
description = "Deletes a backup offering",
responseObject = SuccessResponse.class, since = "4.14.0",
authorized = {RoleType.Admin})
public class DeleteBackupOfferingCmd extends BaseCmd {
public static final String APINAME = "deleteBackupOffering";

@Inject
private BackupManager backupManager;

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

@Parameter(name = ApiConstants.ID,
type = CommandType.UUID,
entityType = BackupOfferingResponse.class,
required = true,
description = "ID of the backup offering")
private Long id;

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

public Long getId() {
return id;
}

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

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

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

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