Skip to content

Commit db8fb3b

Browse files
committed
make fields non mandatory for clone offerings APIs
1 parent 3787aaa commit db8fb3b

File tree

8 files changed

+578
-508
lines changed

8 files changed

+578
-508
lines changed

api/src/main/java/com/cloud/configuration/ConfigurationService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
import org.apache.cloudstack.api.command.admin.network.CloneNetworkOfferingCmd;
2828
import org.apache.cloudstack.api.command.admin.network.CreateGuestNetworkIpv6PrefixCmd;
2929
import org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
30-
import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
3130
import org.apache.cloudstack.api.command.admin.network.DeleteGuestNetworkIpv6PrefixCmd;
3231
import org.apache.cloudstack.api.command.admin.network.DeleteManagementNetworkIpRangeCmd;
3332
import org.apache.cloudstack.api.command.admin.network.DeleteNetworkOfferingCmd;
3433
import org.apache.cloudstack.api.command.admin.network.ListGuestNetworkIpv6PrefixesCmd;
34+
import org.apache.cloudstack.api.command.admin.network.NetworkOfferingBaseCmd;
3535
import org.apache.cloudstack.api.command.admin.network.UpdateNetworkOfferingCmd;
3636
import org.apache.cloudstack.api.command.admin.network.UpdatePodManagementNetworkIpRangeCmd;
3737
import org.apache.cloudstack.api.command.admin.offering.CloneDiskOfferingCmd;
@@ -312,7 +312,7 @@ Vlan updateVlanAndPublicIpRange(UpdateVlanIpRangeCmd cmd) throws ConcurrentOpera
312312

313313
boolean releasePublicIpRange(ReleasePublicIpRangeCmd cmd);
314314

315-
NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd);
315+
NetworkOffering createNetworkOffering(NetworkOfferingBaseCmd cmd);
316316

317317
NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd);
318318

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

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.backup;
1818

19+
import javax.inject.Inject;
20+
1921
import org.apache.cloudstack.acl.RoleType;
2022
import org.apache.cloudstack.api.APICommand;
2123
import org.apache.cloudstack.api.ApiConstants;
2224
import org.apache.cloudstack.api.ApiErrorCode;
25+
import org.apache.cloudstack.api.BaseAsyncCmd;
26+
import org.apache.cloudstack.api.BaseCmd;
2327
import org.apache.cloudstack.api.Parameter;
2428
import org.apache.cloudstack.api.ServerApiException;
2529
import org.apache.cloudstack.api.response.BackupOfferingResponse;
30+
import org.apache.cloudstack.api.response.ZoneResponse;
31+
import org.apache.cloudstack.backup.BackupManager;
2632
import org.apache.cloudstack.backup.BackupOffering;
33+
import org.apache.cloudstack.context.CallContext;
2734

2835
import com.cloud.event.EventTypes;
2936
import com.cloud.exception.ConcurrentOperationException;
@@ -35,65 +42,103 @@
3542
import com.cloud.utils.exception.CloudRuntimeException;
3643

3744
@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",
4247
authorized = {RoleType.Admin})
43-
public class CloneBackupOfferingCmd extends ImportBackupOfferingCmd {
48+
public class CloneBackupOfferingCmd extends BaseAsyncCmd {
49+
50+
@Inject
51+
protected BackupManager backupManager;
4452

4553
/////////////////////////////////////////////////////
4654
//////////////// 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;
4868

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;
5580

5681
/////////////////////////////////////////////////////
5782
/////////////////// Accessors ///////////////////////
5883
/////////////////////////////////////////////////////
5984

60-
public Long getId() {
61-
return id;
85+
public Long getSourceOfferingId() {
86+
return sourceOfferingId;
6287
}
6388

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+
}
64108

65109
/////////////////////////////////////////////////////
66110
/////////////// API Implementation///////////////////
67111
/////////////////////////////////////////////////////
68112

69113
@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 {
73115
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");
81119
}
120+
BackupOfferingResponse response = _responseGenerator.createBackupOfferingResponse(policy);
121+
response.setResponseName(getCommandName());
122+
setResponseObject(response);
82123
} catch (InvalidParameterValueException e) {
83124
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
84125
} catch (CloudRuntimeException e) {
85126
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
86127
}
87128
}
88129

130+
@Override
131+
public long getEntityOwnerId() {
132+
return CallContext.current().getCallingAccount().getId();
133+
}
134+
89135
@Override
90136
public String getEventType() {
91137
return EventTypes.EVENT_VM_BACKUP_CLONE_OFFERING;
92138
}
93139

94140
@Override
95141
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());
97143
}
98144
}
99-

api/src/main/java/org/apache/cloudstack/api/command/admin/network/CloneNetworkOfferingCmd.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
requestHasSensitiveInfo = false,
3636
responseHasSensitiveInfo = false,
3737
since = "4.23.0")
38-
public class CloneNetworkOfferingCmd extends CreateNetworkOfferingCmd {
38+
public class CloneNetworkOfferingCmd extends NetworkOfferingBaseCmd {
3939

4040
/////////////////////////////////////////////////////
4141
//////////////// API parameters /////////////////////
@@ -62,6 +62,14 @@ public class CloneNetworkOfferingCmd extends CreateNetworkOfferingCmd {
6262
"If specified along with 'supportedservices', this parameter is ignored.")
6363
private List<String> dropServices;
6464

65+
@Parameter(name = ApiConstants.TRAFFIC_TYPE,
66+
type = CommandType.STRING,
67+
description = "The traffic type for the network offering. Supported type in current release is GUEST only")
68+
private String traffictype;
69+
70+
@Parameter(name = ApiConstants.GUEST_IP_TYPE, type = CommandType.STRING, description = "Guest type of the network offering: Shared or Isolated")
71+
private String guestIptype;
72+
6573

6674
/////////////////////////////////////////////////////
6775
/////////////////// Accessors ///////////////////////
@@ -79,22 +87,12 @@ public List<String> getDropServices() {
7987
return dropServices;
8088
}
8189

82-
/**
83-
* Override to provide placeholder values that will be replaced with source offering values.
84-
* This allows API validation to pass even though these are marked as required in the parent class.
85-
*/
86-
@Override
8790
public String getGuestIpType() {
88-
String value = super.getGuestIpType();
89-
// Return placeholder if not provided - will be overwritten from source offering
90-
return value != null ? value : "Isolated";
91+
return guestIptype;
9192
}
9293

93-
@Override
9494
public String getTraffictype() {
95-
String value = super.getTraffictype();
96-
// Return placeholder if not provided - will be overwritten from source offering
97-
return value != null ? value : "Guest";
95+
return traffictype;
9896
}
9997

10098
/////////////////////////////////////////////////////

0 commit comments

Comments
 (0)