Skip to content

Commit 01381f8

Browse files
committed
fix list apis
1 parent 0277e85 commit 01381f8

File tree

72 files changed

+2494
-2148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2494
-2148
lines changed

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import org.apache.cloudstack.gpu.GpuDevice;
3737
import org.apache.cloudstack.gpu.VgpuProfile;
3838
import org.apache.cloudstack.ha.HAConfig;
39+
import org.apache.cloudstack.kms.HSMProfile;
40+
import org.apache.cloudstack.kms.KMSKey;
3941
import org.apache.cloudstack.network.BgpPeer;
4042
import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap;
4143
import org.apache.cloudstack.quota.QuotaTariff;
@@ -274,12 +276,17 @@ public class EventTypes {
274276
// KMS (Key Management Service) events
275277
public static final String EVENT_KMS_KEY_WRAP = "KMS.KEY.WRAP";
276278
public static final String EVENT_KMS_KEY_UNWRAP = "KMS.KEY.UNWRAP";
277-
public static final String EVENT_KMS_KEK_CREATE = "KMS.KEK.CREATE";
278-
public static final String EVENT_KMS_KEK_ROTATE = "KMS.KEK.ROTATE";
279-
public static final String EVENT_KMS_KEK_DELETE = "KMS.KEK.DELETE";
280-
public static final String EVENT_KMS_HEALTH_CHECK = "KMS.HEALTH.CHECK";
279+
public static final String EVENT_KMS_KEY_CREATE = "KMS.KEY.CREATE";
280+
public static final String EVENT_KMS_KEY_UPDATE = "KMS.KEY.UPDATE";
281+
public static final String EVENT_KMS_KEY_ROTATE = "KMS.KEY.ROTATE";
282+
public static final String EVENT_KMS_KEY_DELETE = "KMS.KEY.DELETE";
281283
public static final String EVENT_VOLUME_MIGRATE_TO_KMS = "VOLUME.MIGRATE.TO.KMS";
282284

285+
// HSM Profile events
286+
public static final String EVENT_HSM_PROFILE_CREATE = "HSM.PROFILE.CREATE";
287+
public static final String EVENT_HSM_PROFILE_UPDATE = "HSM.PROFILE.UPDATE";
288+
public static final String EVENT_HSM_PROFILE_DELETE = "HSM.PROFILE.DELETE";
289+
283290
// Account events
284291
public static final String EVENT_ACCOUNT_ENABLE = "ACCOUNT.ENABLE";
285292
public static final String EVENT_ACCOUNT_DISABLE = "ACCOUNT.DISABLE";
@@ -1018,6 +1025,19 @@ public class EventTypes {
10181025
entityEventDetails.put(EVENT_VOLUME_RECOVER, Volume.class);
10191026
entityEventDetails.put(EVENT_VOLUME_CHANGE_DISK_OFFERING, Volume.class);
10201027

1028+
// KMS Key Events
1029+
entityEventDetails.put(EVENT_KMS_KEY_CREATE, KMSKey.class);
1030+
entityEventDetails.put(EVENT_KMS_KEY_UPDATE, KMSKey.class);
1031+
entityEventDetails.put(EVENT_KMS_KEY_UNWRAP, KMSKey.class);
1032+
entityEventDetails.put(EVENT_KMS_KEY_WRAP, KMSKey.class);
1033+
entityEventDetails.put(EVENT_KMS_KEY_DELETE, KMSKey.class);
1034+
entityEventDetails.put(EVENT_KMS_KEY_ROTATE, KMSKey.class);
1035+
1036+
// HSM Profile Events
1037+
entityEventDetails.put(EVENT_HSM_PROFILE_CREATE, HSMProfile.class);
1038+
entityEventDetails.put(EVENT_HSM_PROFILE_UPDATE, HSMProfile.class);
1039+
entityEventDetails.put(EVENT_HSM_PROFILE_DELETE, HSMProfile.class);
1040+
10211041
// Domains
10221042
entityEventDetails.put(EVENT_DOMAIN_CREATE, Domain.class);
10231043
entityEventDetails.put(EVENT_DOMAIN_DELETE, Domain.class);

api/src/main/java/org/apache/cloudstack/api/ApiCommandResourceType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ public enum ApiCommandResourceType {
9090
SharedFS(org.apache.cloudstack.storage.sharedfs.SharedFS.class),
9191
Extension(org.apache.cloudstack.extension.Extension.class),
9292
ExtensionCustomAction(org.apache.cloudstack.extension.ExtensionCustomAction.class),
93-
KmsKey(org.apache.cloudstack.kms.KMSKey.class);
93+
KmsKey(org.apache.cloudstack.kms.KMSKey.class),
94+
HsmProfile(org.apache.cloudstack.kms.HSMProfile.class);
9495

9596
private final Class<?> clazz;
9697

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ public class ApiConstants {
865865
public static final String HSM_PROFILE = "hsmprofile";
866866
public static final String HSM_PROFILE_ID = "hsmprofileid";
867867
public static final String PURPOSE = "purpose";
868+
public static final String KMS_KEY = "kmskey";
868869
public static final String KMS_KEY_ID = "kmskeyid";
869870
public static final String KMS_KEY_VERSION = "kmskeyversion";
870871
public static final String KEK_LABEL = "keklabel";

api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@
7373
import org.apache.cloudstack.api.response.IPAddressResponse;
7474
import org.apache.cloudstack.api.response.ImageStoreResponse;
7575
import org.apache.cloudstack.api.response.InstanceGroupResponse;
76-
import org.apache.cloudstack.api.response.KMSKeyResponse;
77-
import org.apache.cloudstack.kms.KMSKey;
7876
import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse;
7977
import org.apache.cloudstack.api.response.IpForwardingRuleResponse;
8078
import org.apache.cloudstack.api.response.IpQuarantineResponse;
@@ -279,7 +277,8 @@ public interface ResponseGenerator {
279277

280278
List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, UserVm... userVms);
281279

282-
List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, EnumSet<VMDetails> details, UserVm... userVms);
280+
List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, EnumSet<VMDetails> details,
281+
UserVm... userVms);
283282

284283
SystemVmResponse createSystemVmResponse(VirtualMachine systemVM);
285284

@@ -305,19 +304,22 @@ public interface ResponseGenerator {
305304

306305
LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer);
307306

308-
LBStickinessResponse createLBStickinessPolicyResponse(List<? extends StickinessPolicy> stickinessPolicies, LoadBalancer lb);
307+
LBStickinessResponse createLBStickinessPolicyResponse(List<? extends StickinessPolicy> stickinessPolicies,
308+
LoadBalancer lb);
309309

310310
LBStickinessResponse createLBStickinessPolicyResponse(StickinessPolicy stickinessPolicy, LoadBalancer lb);
311311

312-
LBHealthCheckResponse createLBHealthCheckPolicyResponse(List<? extends HealthCheckPolicy> healthcheckPolicies, LoadBalancer lb);
312+
LBHealthCheckResponse createLBHealthCheckPolicyResponse(List<? extends HealthCheckPolicy> healthcheckPolicies,
313+
LoadBalancer lb);
313314

314315
LBHealthCheckResponse createLBHealthCheckPolicyResponse(HealthCheckPolicy healthcheckPolicy, LoadBalancer lb);
315316

316317
PodResponse createPodResponse(Pod pod, Boolean showCapacities);
317318

318319
PodResponse createMinimalPodResponse(Pod pod);
319320

320-
ZoneResponse createZoneResponse(ResponseView view, DataCenter dataCenter, Boolean showCapacities, Boolean showResourceIcon);
321+
ZoneResponse createZoneResponse(ResponseView view, DataCenter dataCenter, Boolean showCapacities,
322+
Boolean showResourceIcon);
321323

322324
DataCenterGuestIpv6PrefixResponse createDataCenterGuestIpv6PrefixResponse(DataCenterGuestIpv6Prefix prefix);
323325

@@ -357,7 +359,8 @@ public interface ResponseGenerator {
357359

358360
List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long zoneId, boolean readyOnly);
359361

360-
List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long snapshotId, Long volumeId, boolean readyOnly);
362+
List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long snapshotId, Long volumeId,
363+
boolean readyOnly);
361364

362365
SecurityGroupResponse createSecurityGroupResponseFromSecurityGroupRule(List<? extends SecurityRule> securityRules);
363366

@@ -376,14 +379,15 @@ public interface ResponseGenerator {
376379
TemplateResponse createTemplateUpdateResponse(ResponseView view, VirtualMachineTemplate result);
377380

378381
List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachineTemplate result,
379-
Long zoneId, boolean readyOnly);
382+
Long zoneId, boolean readyOnly);
380383

381384
List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachineTemplate result,
382-
List<Long> zoneIds, boolean readyOnly);
385+
List<Long> zoneIds, boolean readyOnly);
383386

384387
List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format);
385388

386-
TemplatePermissionsResponse createTemplatePermissionsResponse(ResponseView view, List<String> accountNames, Long id);
389+
TemplatePermissionsResponse createTemplatePermissionsResponse(ResponseView view, List<String> accountNames,
390+
Long id);
387391

388392
AsyncJobResponse queryJobResult(QueryAsyncJobResultCmd cmd);
389393

@@ -397,7 +401,8 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
397401

398402
Long getSecurityGroupId(String groupName, long accountId);
399403

400-
List<TemplateResponse> createIsoResponses(ResponseView view, VirtualMachineTemplate iso, Long zoneId, boolean readyOnly);
404+
List<TemplateResponse> createIsoResponses(ResponseView view, VirtualMachineTemplate iso, Long zoneId,
405+
boolean readyOnly);
401406

402407
ProjectResponse createProjectResponse(Project project);
403408

@@ -498,13 +503,15 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
498503

499504
GuestOsMappingResponse createGuestOSMappingResponse(GuestOSHypervisor osHypervisor);
500505

501-
HypervisorGuestOsNamesResponse createHypervisorGuestOSNamesResponse(List<Pair<String, String>> hypervisorGuestOsNames);
506+
HypervisorGuestOsNamesResponse createHypervisorGuestOSNamesResponse(
507+
List<Pair<String, String>> hypervisorGuestOsNames);
502508

503509
SnapshotScheduleResponse createSnapshotScheduleResponse(SnapshotSchedule sched);
504510

505511
UsageRecordResponse createUsageResponse(Usage usageRecord);
506512

507-
UsageRecordResponse createUsageResponse(Usage usageRecord, Map<String, Set<ResourceTagResponse>> resourceTagResponseMap, boolean oldFormat);
513+
UsageRecordResponse createUsageResponse(Usage usageRecord,
514+
Map<String, Set<ResourceTagResponse>> resourceTagResponseMap, boolean oldFormat);
508515

509516
public Map<String, Set<ResourceTagResponse>> getUsageResourceTags();
510517

@@ -516,7 +523,8 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
516523

517524
public NicResponse createNicResponse(Nic result);
518525

519-
ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb, Map<Ip, UserVm> lbInstances);
526+
ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb,
527+
Map<Ip, UserVm> lbInstances);
520528

521529
AffinityGroupResponse createAffinityGroupResponse(AffinityGroup group);
522530

@@ -542,9 +550,12 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
542550

543551
ManagementServerResponse createManagementResponse(ManagementServerHost mgmt);
544552

545-
List<RouterHealthCheckResultResponse> createHealthCheckResponse(VirtualMachine router, List<RouterHealthCheckResult> healthCheckResults);
553+
List<RouterHealthCheckResultResponse> createHealthCheckResponse(VirtualMachine router,
554+
List<RouterHealthCheckResult> healthCheckResults);
546555

547-
RollingMaintenanceResponse createRollingMaintenanceResponse(Boolean success, String details, List<RollingMaintenanceManager.HostUpdated> hostsUpdated, List<RollingMaintenanceManager.HostSkipped> hostsSkipped);
556+
RollingMaintenanceResponse createRollingMaintenanceResponse(Boolean success, String details,
557+
List<RollingMaintenanceManager.HostUpdated> hostsUpdated,
558+
List<RollingMaintenanceManager.HostSkipped> hostsSkipped);
548559

549560
ResourceIconResponse createResourceIconResponse(ResourceIcon resourceIcon);
550561

@@ -554,11 +565,14 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
554565

555566
DirectDownloadCertificateResponse createDirectDownloadCertificateResponse(DirectDownloadCertificate certificate);
556567

557-
List<DirectDownloadCertificateHostStatusResponse> createDirectDownloadCertificateHostMapResponse(List<DirectDownloadCertificateHostMap> hostMappings);
568+
List<DirectDownloadCertificateHostStatusResponse> createDirectDownloadCertificateHostMapResponse(
569+
List<DirectDownloadCertificateHostMap> hostMappings);
558570

559-
DirectDownloadCertificateHostStatusResponse createDirectDownloadCertificateHostStatusResponse(DirectDownloadManager.HostCertificateStatus status);
571+
DirectDownloadCertificateHostStatusResponse createDirectDownloadCertificateHostStatusResponse(
572+
DirectDownloadManager.HostCertificateStatus status);
560573

561-
DirectDownloadCertificateHostStatusResponse createDirectDownloadCertificateProvisionResponse(Long certificateId, Long hostId, Pair<Boolean, String> result);
574+
DirectDownloadCertificateHostStatusResponse createDirectDownloadCertificateProvisionResponse(Long certificateId,
575+
Long hostId, Pair<Boolean, String> result);
562576

563577
FirewallResponse createIpv6FirewallRuleResponse(FirewallRule acl);
564578

@@ -585,6 +599,4 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
585599
GuiThemeResponse createGuiThemeResponse(GuiThemeJoin guiThemeJoin);
586600

587601
ConsoleSessionResponse createConsoleSessionResponse(ConsoleSession consoleSession, ResponseView responseView);
588-
589-
KMSKeyResponse createKMSKeyResponse(KMSKey kmsKey);
590602
}

api/src/main/java/org/apache/cloudstack/api/command/admin/kms/MigrateVolumesToKMSCmd.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.apache.cloudstack.api.command.admin.kms;
1818

1919
import com.cloud.dc.DataCenter;
20-
import com.cloud.user.Account;
2120
import org.apache.cloudstack.acl.RoleType;
2221
import org.apache.cloudstack.api.APICommand;
2322
import org.apache.cloudstack.api.ApiCommandResourceType;
@@ -29,11 +28,15 @@
2928
import org.apache.cloudstack.api.response.AsyncJobResponse;
3029
import org.apache.cloudstack.api.response.DomainResponse;
3130
import org.apache.cloudstack.api.response.KMSKeyResponse;
31+
import org.apache.cloudstack.api.response.VolumeResponse;
3232
import org.apache.cloudstack.api.response.ZoneResponse;
33+
import org.apache.cloudstack.context.CallContext;
3334
import org.apache.cloudstack.framework.kms.KMSException;
35+
import org.apache.cloudstack.kms.KMSKey;
3436
import org.apache.cloudstack.kms.KMSManager;
3537

3638
import javax.inject.Inject;
39+
import java.util.List;
3740

3841
@APICommand(name = "migrateVolumesToKMS",
3942
description = "Migrates passphrase-based volumes to KMS (admin only)",
@@ -48,12 +51,7 @@ public class MigrateVolumesToKMSCmd extends BaseAsyncCmd {
4851
@Inject
4952
private KMSManager kmsManager;
5053

51-
/////////////////////////////////////////////////////
52-
//////////////// API parameters /////////////////////
53-
/////////////////////////////////////////////////////
54-
5554
@Parameter(name = ApiConstants.ZONE_ID,
56-
required = true,
5755
type = CommandType.UUID,
5856
entityType = ZoneResponse.class,
5957
description = "Zone ID")
@@ -70,17 +68,20 @@ public class MigrateVolumesToKMSCmd extends BaseAsyncCmd {
7068
description = "Domain ID")
7169
private Long domainId;
7270

73-
@Parameter(name = ApiConstants.ID,
71+
@Parameter(name = ApiConstants.VOLUME_IDS,
72+
type = CommandType.LIST,
73+
collectionType = CommandType.UUID,
74+
entityType = VolumeResponse.class,
75+
description = "List of volume IDs to migrate")
76+
private List<Long> volumeIds;
77+
78+
@Parameter(name = ApiConstants.KMS_KEY_ID,
7479
required = true,
7580
type = CommandType.UUID,
7681
entityType = KMSKeyResponse.class,
7782
description = "KMS Key ID to use for migrating volumes")
7883
private Long kmsKeyId;
7984

80-
/////////////////////////////////////////////////////
81-
/////////////////// Accessors ///////////////////////
82-
/////////////////////////////////////////////////////
83-
8485
public Long getZoneId() {
8586
return zoneId;
8687
}
@@ -93,14 +94,14 @@ public Long getDomainId() {
9394
return domainId;
9495
}
9596

97+
public List<Long> getVolumeIds() {
98+
return volumeIds;
99+
}
100+
96101
public Long getKmsKeyId() {
97102
return kmsKeyId;
98103
}
99104

100-
/////////////////////////////////////////////////////
101-
/////////////// API Implementation///////////////////
102-
/////////////////////////////////////////////////////
103-
104105
@Override
105106
public void execute() {
106107
try {
@@ -118,7 +119,11 @@ public String getCommandName() {
118119

119120
@Override
120121
public long getEntityOwnerId() {
121-
return Account.ACCOUNT_ID_SYSTEM;
122+
KMSKey key = _entityMgr.findById(KMSKey.class, kmsKeyId);
123+
if (key != null) {
124+
return key.getAccountId();
125+
}
126+
return CallContext.current().getCallingAccount().getId();
122127
}
123128

124129
@Override

api/src/main/java/org/apache/cloudstack/api/command/user/kms/CreateKMSKeyCmd.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.apache.cloudstack.api.command.user.kms;
2121

2222
import com.cloud.exception.ResourceAllocationException;
23-
import com.cloud.user.Account;
2423
import org.apache.cloudstack.acl.RoleType;
2524
import org.apache.cloudstack.api.APICommand;
2625
import org.apache.cloudstack.api.ApiCommandResourceType;
@@ -33,6 +32,7 @@
3332
import org.apache.cloudstack.api.response.DomainResponse;
3433
import org.apache.cloudstack.api.response.HSMProfileResponse;
3534
import org.apache.cloudstack.api.response.KMSKeyResponse;
35+
import org.apache.cloudstack.api.response.ProjectResponse;
3636
import org.apache.cloudstack.api.response.ZoneResponse;
3737
import org.apache.cloudstack.context.CallContext;
3838
import org.apache.cloudstack.framework.kms.KMSException;
@@ -64,9 +64,8 @@ public class CreateKMSKeyCmd extends BaseCmd implements UserCmd {
6464
private String description;
6565

6666
@Parameter(name = ApiConstants.PURPOSE,
67-
required = true,
6867
type = CommandType.STRING,
69-
description = "Purpose of the key: volume, tls")
68+
description = "Purpose of the key: volume, tls. (default: volume)")
7069
private String purpose;
7170

7271
@Parameter(name = ApiConstants.ZONE_ID,
@@ -87,6 +86,12 @@ public class CreateKMSKeyCmd extends BaseCmd implements UserCmd {
8786
description = "Domain ID (for creating keys for child accounts - requires domain admin or admin)")
8887
private Long domainId;
8988

89+
@Parameter(name = ApiConstants.PROJECT_ID,
90+
type = CommandType.UUID,
91+
entityType = ProjectResponse.class,
92+
description = "ID of the project to create the KMS key for")
93+
private Long projectId;
94+
9095
@Parameter(name = ApiConstants.KEY_BITS,
9196
type = CommandType.INTEGER,
9297
description = "Key size in bits: 128, 192, or 256 (default: 256)")
@@ -108,7 +113,7 @@ public String getDescription() {
108113
}
109114

110115
public String getPurpose() {
111-
return purpose;
116+
return purpose == null ? "volume" : purpose;
112117
}
113118

114119
public Long getZoneId() {
@@ -123,8 +128,12 @@ public Long getDomainId() {
123128
return domainId;
124129
}
125130

131+
public Long getProjectId() {
132+
return projectId;
133+
}
134+
126135
public Integer getKeyBits() {
127-
return keyBits != null ? keyBits : 256; // Default to 256 bits
136+
return keyBits != null ? keyBits : 256;
128137
}
129138

130139
public Long getHsmProfileId() {
@@ -145,11 +154,11 @@ public void execute() throws ResourceAllocationException {
145154

146155
@Override
147156
public long getEntityOwnerId() {
148-
Account caller = CallContext.current().getCallingAccount();
149-
if (accountName != null || domainId != null) {
150-
return _accountService.finalyzeAccountId(accountName, domainId, null, true);
157+
Long accountId = _accountService.finalizeAccountId(accountName, domainId, projectId, true);
158+
if (accountId != null) {
159+
return accountId;
151160
}
152-
return caller.getId();
161+
return CallContext.current().getCallingAccount().getId();
153162
}
154163

155164
@Override

0 commit comments

Comments
 (0)