|
16 | 16 | // under the License. |
17 | 17 | package org.apache.cloudstack.api.command.admin.backup; |
18 | 18 |
|
| 19 | +import javax.inject.Inject; |
| 20 | + |
19 | 21 | import org.apache.cloudstack.acl.RoleType; |
20 | 22 | import org.apache.cloudstack.api.APICommand; |
21 | 23 | import org.apache.cloudstack.api.ApiConstants; |
22 | 24 | import org.apache.cloudstack.api.ApiErrorCode; |
| 25 | +import org.apache.cloudstack.api.BaseAsyncCmd; |
| 26 | +import org.apache.cloudstack.api.BaseCmd; |
23 | 27 | import org.apache.cloudstack.api.Parameter; |
24 | 28 | import org.apache.cloudstack.api.ServerApiException; |
25 | 29 | import org.apache.cloudstack.api.response.BackupOfferingResponse; |
| 30 | +import org.apache.cloudstack.api.response.ZoneResponse; |
| 31 | +import org.apache.cloudstack.backup.BackupManager; |
26 | 32 | import org.apache.cloudstack.backup.BackupOffering; |
| 33 | +import org.apache.cloudstack.context.CallContext; |
27 | 34 |
|
28 | 35 | import com.cloud.event.EventTypes; |
29 | 36 | import com.cloud.exception.ConcurrentOperationException; |
|
35 | 42 | import com.cloud.utils.exception.CloudRuntimeException; |
36 | 43 |
|
37 | 44 | @APICommand(name = "cloneBackupOffering", |
38 | | - description = "Clones an existing backup offering with updated values. " + |
39 | | - "All parameters are copied from the source offering unless explicitly overridden.", |
40 | | - responseObject = BackupOfferingResponse.class, |
41 | | - since = "4.23.0", |
| 45 | + description = "Clones a backup offering from an existing offering", |
| 46 | + responseObject = BackupOfferingResponse.class, since = "4.14.0", |
42 | 47 | authorized = {RoleType.Admin}) |
43 | | -public class CloneBackupOfferingCmd extends ImportBackupOfferingCmd { |
| 48 | +public class CloneBackupOfferingCmd extends BaseAsyncCmd { |
| 49 | + |
| 50 | + @Inject |
| 51 | + protected BackupManager backupManager; |
44 | 52 |
|
45 | 53 | ///////////////////////////////////////////////////// |
46 | 54 | //////////////// API parameters ///////////////////// |
47 | | - ///////////////////////////////////////////////////// |
| 55 | + //////////////////////////////////////////////////// |
| 56 | + |
| 57 | + @Parameter(name = ApiConstants.SOURCE_OFFERING_ID, type = BaseCmd.CommandType.UUID, |
| 58 | + required = true, description = "The ID of the source backup offering to clone from") |
| 59 | + private Long sourceOfferingId; |
| 60 | + |
| 61 | + @Parameter(name = ApiConstants.NAME, type = BaseCmd.CommandType.STRING, required = false, |
| 62 | + description = "The name of the cloned offering") |
| 63 | + private String name; |
| 64 | + |
| 65 | + @Parameter(name = ApiConstants.DESCRIPTION, type = BaseCmd.CommandType.STRING, required = false, |
| 66 | + description = "The description of the cloned offering") |
| 67 | + private String description; |
48 | 68 |
|
49 | | - @Parameter(name = ApiConstants.ID, |
50 | | - type = CommandType.UUID, |
51 | | - entityType = BackupOfferingResponse.class, |
52 | | - required = true, |
53 | | - description = "The ID of the backup offering to clone") |
54 | | - private Long id; |
| 69 | + @Parameter(name = ApiConstants.EXTERNAL_ID, type = BaseCmd.CommandType.STRING, required = false, |
| 70 | + description = "The backup offering ID (from backup provider side)") |
| 71 | + private String externalId; |
| 72 | + |
| 73 | + @Parameter(name = ApiConstants.ZONE_ID, type = BaseCmd.CommandType.UUID, entityType = ZoneResponse.class, |
| 74 | + description = "The zone ID", required = false) |
| 75 | + private Long zoneId; |
| 76 | + |
| 77 | + @Parameter(name = ApiConstants.ALLOW_USER_DRIVEN_BACKUPS, type = BaseCmd.CommandType.BOOLEAN, |
| 78 | + description = "Whether users are allowed to create adhoc backups and backup schedules", required = false) |
| 79 | + private Boolean userDrivenBackups; |
55 | 80 |
|
56 | 81 | ///////////////////////////////////////////////////// |
57 | 82 | /////////////////// Accessors /////////////////////// |
58 | 83 | ///////////////////////////////////////////////////// |
59 | 84 |
|
60 | | - public Long getId() { |
61 | | - return id; |
| 85 | + public Long getSourceOfferingId() { |
| 86 | + return sourceOfferingId; |
62 | 87 | } |
63 | 88 |
|
| 89 | + public String getName() { |
| 90 | + return name; |
| 91 | + } |
| 92 | + |
| 93 | + public String getExternalId() { |
| 94 | + return externalId; |
| 95 | + } |
| 96 | + |
| 97 | + public Long getZoneId() { |
| 98 | + return zoneId; |
| 99 | + } |
| 100 | + |
| 101 | + public String getDescription() { |
| 102 | + return description; |
| 103 | + } |
| 104 | + |
| 105 | + public Boolean getUserDrivenBackups() { |
| 106 | + return userDrivenBackups; |
| 107 | + } |
64 | 108 |
|
65 | 109 | ///////////////////////////////////////////////////// |
66 | 110 | /////////////// API Implementation/////////////////// |
67 | 111 | ///////////////////////////////////////////////////// |
68 | 112 |
|
69 | 113 | @Override |
70 | | - public void execute() throws ResourceUnavailableException, InsufficientCapacityException, |
71 | | - ServerApiException, ConcurrentOperationException, ResourceAllocationException, |
72 | | - NetworkRuleConflictException { |
| 114 | + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { |
73 | 115 | try { |
74 | | - BackupOffering clonedOffering = backupManager.cloneBackupOffering(this); |
75 | | - if (clonedOffering != null) { |
76 | | - BackupOfferingResponse response = _responseGenerator.createBackupOfferingResponse(clonedOffering); |
77 | | - response.setResponseName(getCommandName()); |
78 | | - setResponseObject(response); |
79 | | - } else { |
80 | | - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to clone backup offering"); |
| 116 | + BackupOffering policy = backupManager.cloneBackupOffering(this); |
| 117 | + if (policy == null) { |
| 118 | + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to clone a backup offering"); |
81 | 119 | } |
| 120 | + BackupOfferingResponse response = _responseGenerator.createBackupOfferingResponse(policy); |
| 121 | + response.setResponseName(getCommandName()); |
| 122 | + setResponseObject(response); |
82 | 123 | } catch (InvalidParameterValueException e) { |
83 | 124 | throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); |
84 | 125 | } catch (CloudRuntimeException e) { |
85 | 126 | throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); |
86 | 127 | } |
87 | 128 | } |
88 | 129 |
|
| 130 | + @Override |
| 131 | + public long getEntityOwnerId() { |
| 132 | + return CallContext.current().getCallingAccount().getId(); |
| 133 | + } |
| 134 | + |
89 | 135 | @Override |
90 | 136 | public String getEventType() { |
91 | 137 | return EventTypes.EVENT_VM_BACKUP_CLONE_OFFERING; |
92 | 138 | } |
93 | 139 |
|
94 | 140 | @Override |
95 | 141 | public String getEventDescription() { |
96 | | - return "Cloning backup offering from ID: " + id + " to new offering: " + getName(); |
| 142 | + return "Cloning backup offering: " + name + " from source offering: " + (sourceOfferingId == null ? "" : sourceOfferingId.toString()); |
97 | 143 | } |
98 | 144 | } |
99 | | - |
|
0 commit comments