Skip to content

Commit 6ba0af5

Browse files
committed
fix list apis
1 parent 529fd9d commit 6ba0af5

File tree

72 files changed

+2493
-2099
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

+2493
-2099
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";
@@ -1024,6 +1031,19 @@ public class EventTypes {
10241031
entityEventDetails.put(EVENT_VOLUME_RECOVER, Volume.class);
10251032
entityEventDetails.put(EVENT_VOLUME_CHANGE_DISK_OFFERING, Volume.class);
10261033

1034+
// KMS Key Events
1035+
entityEventDetails.put(EVENT_KMS_KEY_CREATE, KMSKey.class);
1036+
entityEventDetails.put(EVENT_KMS_KEY_UPDATE, KMSKey.class);
1037+
entityEventDetails.put(EVENT_KMS_KEY_UNWRAP, KMSKey.class);
1038+
entityEventDetails.put(EVENT_KMS_KEY_WRAP, KMSKey.class);
1039+
entityEventDetails.put(EVENT_KMS_KEY_DELETE, KMSKey.class);
1040+
entityEventDetails.put(EVENT_KMS_KEY_ROTATE, KMSKey.class);
1041+
1042+
// HSM Profile Events
1043+
entityEventDetails.put(EVENT_HSM_PROFILE_CREATE, HSMProfile.class);
1044+
entityEventDetails.put(EVENT_HSM_PROFILE_UPDATE, HSMProfile.class);
1045+
entityEventDetails.put(EVENT_HSM_PROFILE_DELETE, HSMProfile.class);
1046+
10271047
// Domains
10281048
entityEventDetails.put(EVENT_DOMAIN_CREATE, Domain.class);
10291049
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
@@ -870,6 +870,7 @@ public class ApiConstants {
870870
public static final String HSM_PROFILE = "hsmprofile";
871871
public static final String HSM_PROFILE_ID = "hsmprofileid";
872872
public static final String PURPOSE = "purpose";
873+
public static final String KMS_KEY = "kmskey";
873874
public static final String KMS_KEY_ID = "kmskeyid";
874875
public static final String KMS_KEY_VERSION = "kmskeyversion";
875876
public static final String KEK_LABEL = "keklabel";

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

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Set;
2424

2525
import org.apache.cloudstack.api.response.ConsoleSessionResponse;
26+
import org.apache.cloudstack.api.response.KMSKeyResponse;
2627
import org.apache.cloudstack.consoleproxy.ConsoleSession;
2728
import org.apache.cloudstack.acl.apikeypair.ApiKeyPair;
2829
import org.apache.cloudstack.acl.apikeypair.ApiKeyPairPermission;
@@ -76,8 +77,6 @@
7677
import org.apache.cloudstack.api.response.IPAddressResponse;
7778
import org.apache.cloudstack.api.response.ImageStoreResponse;
7879
import org.apache.cloudstack.api.response.InstanceGroupResponse;
79-
import org.apache.cloudstack.api.response.KMSKeyResponse;
80-
import org.apache.cloudstack.kms.KMSKey;
8180
import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse;
8281
import org.apache.cloudstack.api.response.IpForwardingRuleResponse;
8382
import org.apache.cloudstack.api.response.IpQuarantineResponse;
@@ -158,6 +157,7 @@
158157
import org.apache.cloudstack.direct.download.DirectDownloadCertificateHostMap;
159158
import org.apache.cloudstack.direct.download.DirectDownloadManager;
160159
import org.apache.cloudstack.gui.theme.GuiThemeJoin;
160+
import org.apache.cloudstack.kms.KMSKey;
161161
import org.apache.cloudstack.management.ManagementServerHost;
162162
import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule;
163163
import org.apache.cloudstack.region.PortableIp;
@@ -283,7 +283,8 @@ public interface ResponseGenerator {
283283

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

286-
List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, EnumSet<VMDetails> details, UserVm... userVms);
286+
List<UserVmResponse> createUserVmResponse(ResponseView view, String objectName, EnumSet<VMDetails> details,
287+
UserVm... userVms);
287288

288289
SystemVmResponse createSystemVmResponse(VirtualMachine systemVM);
289290

@@ -309,19 +310,22 @@ public interface ResponseGenerator {
309310

310311
LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer);
311312

312-
LBStickinessResponse createLBStickinessPolicyResponse(List<? extends StickinessPolicy> stickinessPolicies, LoadBalancer lb);
313+
LBStickinessResponse createLBStickinessPolicyResponse(List<? extends StickinessPolicy> stickinessPolicies,
314+
LoadBalancer lb);
313315

314316
LBStickinessResponse createLBStickinessPolicyResponse(StickinessPolicy stickinessPolicy, LoadBalancer lb);
315317

316-
LBHealthCheckResponse createLBHealthCheckPolicyResponse(List<? extends HealthCheckPolicy> healthcheckPolicies, LoadBalancer lb);
318+
LBHealthCheckResponse createLBHealthCheckPolicyResponse(List<? extends HealthCheckPolicy> healthcheckPolicies,
319+
LoadBalancer lb);
317320

318321
LBHealthCheckResponse createLBHealthCheckPolicyResponse(HealthCheckPolicy healthcheckPolicy, LoadBalancer lb);
319322

320323
PodResponse createPodResponse(Pod pod, Boolean showCapacities);
321324

322325
PodResponse createMinimalPodResponse(Pod pod);
323326

324-
ZoneResponse createZoneResponse(ResponseView view, DataCenter dataCenter, Boolean showCapacities, Boolean showResourceIcon);
327+
ZoneResponse createZoneResponse(ResponseView view, DataCenter dataCenter, Boolean showCapacities,
328+
Boolean showResourceIcon);
325329

326330
DataCenterGuestIpv6PrefixResponse createDataCenterGuestIpv6PrefixResponse(DataCenterGuestIpv6Prefix prefix);
327331

@@ -361,7 +365,8 @@ public interface ResponseGenerator {
361365

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

364-
List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long snapshotId, Long volumeId, boolean readyOnly);
368+
List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long snapshotId, Long volumeId,
369+
boolean readyOnly);
365370

366371
SecurityGroupResponse createSecurityGroupResponseFromSecurityGroupRule(List<? extends SecurityRule> securityRules);
367372

@@ -380,14 +385,15 @@ public interface ResponseGenerator {
380385
TemplateResponse createTemplateUpdateResponse(ResponseView view, VirtualMachineTemplate result);
381386

382387
List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachineTemplate result,
383-
Long zoneId, boolean readyOnly);
388+
Long zoneId, boolean readyOnly);
384389

385390
List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachineTemplate result,
386-
List<Long> zoneIds, boolean readyOnly);
391+
List<Long> zoneIds, boolean readyOnly);
387392

388393
List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format);
389394

390-
TemplatePermissionsResponse createTemplatePermissionsResponse(ResponseView view, List<String> accountNames, Long id);
395+
TemplatePermissionsResponse createTemplatePermissionsResponse(ResponseView view, List<String> accountNames,
396+
Long id);
391397

392398
AsyncJobResponse queryJobResult(QueryAsyncJobResultCmd cmd);
393399

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

402408
Long getSecurityGroupId(String groupName, long accountId);
403409

404-
List<TemplateResponse> createIsoResponses(ResponseView view, VirtualMachineTemplate iso, Long zoneId, boolean readyOnly);
410+
List<TemplateResponse> createIsoResponses(ResponseView view, VirtualMachineTemplate iso, Long zoneId,
411+
boolean readyOnly);
405412

406413
ProjectResponse createProjectResponse(Project project);
407414

@@ -502,13 +509,15 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
502509

503510
GuestOsMappingResponse createGuestOSMappingResponse(GuestOSHypervisor osHypervisor);
504511

505-
HypervisorGuestOsNamesResponse createHypervisorGuestOSNamesResponse(List<Pair<String, String>> hypervisorGuestOsNames);
512+
HypervisorGuestOsNamesResponse createHypervisorGuestOSNamesResponse(
513+
List<Pair<String, String>> hypervisorGuestOsNames);
506514

507515
SnapshotScheduleResponse createSnapshotScheduleResponse(SnapshotSchedule sched);
508516

509517
UsageRecordResponse createUsageResponse(Usage usageRecord);
510518

511-
UsageRecordResponse createUsageResponse(Usage usageRecord, Map<String, Set<ResourceTagResponse>> resourceTagResponseMap, boolean oldFormat);
519+
UsageRecordResponse createUsageResponse(Usage usageRecord,
520+
Map<String, Set<ResourceTagResponse>> resourceTagResponseMap, boolean oldFormat);
512521

513522
public Map<String, Set<ResourceTagResponse>> getUsageResourceTags();
514523

@@ -520,7 +529,8 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
520529

521530
public NicResponse createNicResponse(Nic result);
522531

523-
ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb, Map<Ip, UserVm> lbInstances);
532+
ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb,
533+
Map<Ip, UserVm> lbInstances);
524534

525535
AffinityGroupResponse createAffinityGroupResponse(AffinityGroup group);
526536

@@ -546,9 +556,12 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
546556

547557
ManagementServerResponse createManagementResponse(ManagementServerHost mgmt);
548558

549-
List<RouterHealthCheckResultResponse> createHealthCheckResponse(VirtualMachine router, List<RouterHealthCheckResult> healthCheckResults);
559+
List<RouterHealthCheckResultResponse> createHealthCheckResponse(VirtualMachine router,
560+
List<RouterHealthCheckResult> healthCheckResults);
550561

551-
RollingMaintenanceResponse createRollingMaintenanceResponse(Boolean success, String details, List<RollingMaintenanceManager.HostUpdated> hostsUpdated, List<RollingMaintenanceManager.HostSkipped> hostsSkipped);
562+
RollingMaintenanceResponse createRollingMaintenanceResponse(Boolean success, String details,
563+
List<RollingMaintenanceManager.HostUpdated> hostsUpdated,
564+
List<RollingMaintenanceManager.HostSkipped> hostsSkipped);
552565

553566
ResourceIconResponse createResourceIconResponse(ResourceIcon resourceIcon);
554567

@@ -558,11 +571,14 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
558571

559572
DirectDownloadCertificateResponse createDirectDownloadCertificateResponse(DirectDownloadCertificate certificate);
560573

561-
List<DirectDownloadCertificateHostStatusResponse> createDirectDownloadCertificateHostMapResponse(List<DirectDownloadCertificateHostMap> hostMappings);
574+
List<DirectDownloadCertificateHostStatusResponse> createDirectDownloadCertificateHostMapResponse(
575+
List<DirectDownloadCertificateHostMap> hostMappings);
562576

563-
DirectDownloadCertificateHostStatusResponse createDirectDownloadCertificateHostStatusResponse(DirectDownloadManager.HostCertificateStatus status);
577+
DirectDownloadCertificateHostStatusResponse createDirectDownloadCertificateHostStatusResponse(
578+
DirectDownloadManager.HostCertificateStatus status);
564579

565-
DirectDownloadCertificateHostStatusResponse createDirectDownloadCertificateProvisionResponse(Long certificateId, Long hostId, Pair<Boolean, String> result);
580+
DirectDownloadCertificateHostStatusResponse createDirectDownloadCertificateProvisionResponse(Long certificateId,
581+
Long hostId, Pair<Boolean, String> result);
566582

567583
FirewallResponse createIpv6FirewallRuleResponse(FirewallRule acl);
568584

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

0 commit comments

Comments
 (0)