Skip to content

Commit 523805c

Browse files
authored
schema,server,api: events improvement (apache#5997)
* schema,server,api: events improvement Add resource ID and resource type to event. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * wip Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * refactor resourcetype association with API class Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * add resource anme to the response Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * changes Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * test Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * more tests Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * new line Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * add resource test Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * changes Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * smoke test for events resource Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * changes Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * ui improvements Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * refactor Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * api,ui: add support for listing events for a resource Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * since key Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * tests and permission changes Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * missing test Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * events for domain Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * improvements Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * add missing license Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * ui: fix js console errors Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * sort enumeration Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix event resource for vpc Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * feedback changes Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix order Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * events with parent resource Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * missing UI labels Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * donot call cmd resource methods before dispatch Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * add restore vm to procedure Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * add missing imports Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * resource details for more events Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * add test for changes Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * more test, license fix Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * wrong merge fix Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * fix for more event types Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 3f7b879 commit 523805c

File tree

325 files changed

+4424
-1037
lines changed

Some content is hidden

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

325 files changed

+4424
-1037
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@
3333
String eventType();
3434

3535
String eventDescription();
36+
37+
long resourceId() default -1;
38+
39+
String resourceType() default "";
3640
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public enum State {
3333

3434
String getDescription();
3535

36+
Long getResourceId();
37+
38+
String getResourceType();
39+
3640
Date getCreateDate();
3741

3842
long getUserId();

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.cloudstack.acl.Role;
2323
import org.apache.cloudstack.acl.RolePermission;
24+
import org.apache.cloudstack.affinity.AffinityGroup;
2425
import org.apache.cloudstack.annotation.Annotation;
2526
import org.apache.cloudstack.api.response.ClusterResponse;
2627
import org.apache.cloudstack.api.response.HostResponse;
@@ -63,6 +64,7 @@
6364
import com.cloud.network.vpc.PrivateGateway;
6465
import com.cloud.network.vpc.StaticRoute;
6566
import com.cloud.network.vpc.Vpc;
67+
import com.cloud.network.vpc.VpcOffering;
6668
import com.cloud.offering.DiskOffering;
6769
import com.cloud.offering.NetworkOffering;
6870
import com.cloud.offering.ServiceOffering;
@@ -972,9 +974,9 @@ public class EventTypes {
972974
entityEventDetails.put(EVENT_VPC_RESTART, Vpc.class);
973975

974976
// VPC offerings
975-
entityEventDetails.put(EVENT_VPC_OFFERING_CREATE, Vpc.class);
976-
entityEventDetails.put(EVENT_VPC_OFFERING_UPDATE, Vpc.class);
977-
entityEventDetails.put(EVENT_VPC_OFFERING_DELETE, Vpc.class);
977+
entityEventDetails.put(EVENT_VPC_OFFERING_CREATE, VpcOffering.class);
978+
entityEventDetails.put(EVENT_VPC_OFFERING_UPDATE, VpcOffering.class);
979+
entityEventDetails.put(EVENT_VPC_OFFERING_DELETE, VpcOffering.class);
978980

979981
// Private gateway
980982
entityEventDetails.put(EVENT_PRIVATE_GATEWAY_CREATE, PrivateGateway.class);
@@ -1014,6 +1016,11 @@ public class EventTypes {
10141016
entityEventDetails.put(EVENT_GUEST_VLAN_RANGE_DEDICATE, GuestVlan.class);
10151017
entityEventDetails.put(EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE, GuestVlan.class);
10161018

1019+
entityEventDetails.put(EVENT_AFFINITY_GROUP_CREATE, AffinityGroup.class);
1020+
entityEventDetails.put(EVENT_AFFINITY_GROUP_DELETE, AffinityGroup.class);
1021+
entityEventDetails.put(EVENT_AFFINITY_GROUP_ASSIGN, AffinityGroup.class);
1022+
entityEventDetails.put(EVENT_AFFINITY_GROUP_REMOVE, AffinityGroup.class);
1023+
10171024
// OpenDaylight
10181025
entityEventDetails.put(EVENT_EXTERNAL_OPENDAYLIGHT_ADD_CONTROLLER, "OpenDaylightController");
10191026
entityEventDetails.put(EVENT_EXTERNAL_OPENDAYLIGHT_DELETE_CONTROLLER, "OpenDaylightController");

api/src/main/java/com/cloud/network/vpn/Site2SiteVpnService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public interface Site2SiteVpnService {
4646

4747
Site2SiteVpnGateway getVpnGateway(Long vpnGatewayId);
4848

49+
Site2SiteCustomerGateway getCustomerGateway(Long customerGatewayId);
50+
4951
Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) throws NetworkRuleConflictException;
5052

5153
boolean deleteCustomerGateway(DeleteVpnCustomerGatewayCmd deleteVpnCustomerGatewayCmd);

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

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import org.apache.cloudstack.region.PortableIp;
23+
import org.apache.commons.collections.CollectionUtils;
24+
import org.apache.commons.lang3.EnumUtils;
25+
import org.apache.commons.lang3.StringUtils;
26+
27+
public enum ApiCommandResourceType {
28+
None(null),
29+
VirtualMachine(com.cloud.vm.VirtualMachine.class),
30+
DomainRouter(com.cloud.network.router.VirtualRouter.class),
31+
Volume(com.cloud.storage.Volume.class),
32+
ConsoleProxy(com.cloud.vm.VirtualMachine.class),
33+
Snapshot(com.cloud.storage.Snapshot.class),
34+
Backup(org.apache.cloudstack.backup.Backup.class),
35+
Template(com.cloud.template.VirtualMachineTemplate.class),
36+
Iso(com.cloud.template.VirtualMachineTemplate.class),
37+
SystemVm(com.cloud.vm.VirtualMachine.class),
38+
Host(com.cloud.host.Host.class),
39+
StoragePool(com.cloud.storage.StoragePool.class),
40+
ImageStore(com.cloud.storage.ImageStore.class),
41+
IpAddress(com.cloud.network.IpAddress.class),
42+
PortableIpAddress(PortableIp.class),
43+
SecurityGroup(com.cloud.network.security.SecurityGroup.class),
44+
PhysicalNetwork(com.cloud.network.PhysicalNetwork.class),
45+
TrafficType(com.cloud.network.PhysicalNetworkTrafficType.class),
46+
PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider.class),
47+
FirewallRule(com.cloud.network.rules.FirewallRule.class),
48+
Account(com.cloud.user.Account.class),
49+
User(com.cloud.user.User.class),
50+
PrivateGateway(com.cloud.network.vpc.PrivateGateway.class),
51+
StaticRoute(com.cloud.network.vpc.StaticRoute.class),
52+
Counter(com.cloud.network.as.Counter.class),
53+
Condition(com.cloud.network.as.Condition.class),
54+
AutoScalePolicy(com.cloud.network.as.AutoScalePolicy.class),
55+
AutoScaleVmProfile(com.cloud.network.as.AutoScaleVmProfile.class),
56+
AutoScaleVmGroup(com.cloud.network.as.AutoScaleVmGroup.class),
57+
GlobalLoadBalancerRule(com.cloud.region.ha.GlobalLoadBalancerRule.class),
58+
LoadBalancerRule(com.cloud.network.lb.LoadBalancingRule.class),
59+
AffinityGroup(org.apache.cloudstack.affinity.AffinityGroup.class),
60+
InternalLbVm(com.cloud.network.router.VirtualRouter.class),
61+
DedicatedGuestVlanRange(com.cloud.network.GuestVlan.class),
62+
GuestOs(com.cloud.storage.GuestOS.class),
63+
GuestOsMapping(com.cloud.storage.GuestOSHypervisor.class),
64+
Network(com.cloud.network.Network.class),
65+
NetworkAcl(com.cloud.network.vpc.NetworkACL.class),
66+
NetworkAclItem(com.cloud.network.vpc.NetworkACLItem.class),
67+
Project(com.cloud.projects.Project.class),
68+
Domain(com.cloud.domain.Domain.class),
69+
DiskOffering(com.cloud.offering.DiskOffering.class),
70+
ServiceOffering(com.cloud.offering.ServiceOffering.class),
71+
NetworkOffering(com.cloud.offering.NetworkOffering.class),
72+
VpcOffering(com.cloud.network.vpc.VpcOffering.class),
73+
BackupOffering(org.apache.cloudstack.backup.BackupOffering.class),
74+
Zone(com.cloud.dc.DataCenter.class),
75+
Vpc(com.cloud.network.vpc.Vpc.class),
76+
Cluster(com.cloud.org.Cluster.class),
77+
Pod(com.cloud.dc.Pod.class),
78+
VmSnapshot(com.cloud.vm.snapshot.VMSnapshot.class),
79+
Role(org.apache.cloudstack.acl.Role.class),
80+
VpnCustomerGateway(com.cloud.network.Site2SiteCustomerGateway.class);
81+
82+
private final Class<?> clazz;
83+
84+
private ApiCommandResourceType(Class<?> clazz) {
85+
this.clazz = clazz;
86+
}
87+
88+
public Class<?> getAssociatedClass() {
89+
return this.clazz;
90+
}
91+
92+
public static List<ApiCommandResourceType> valuesFromAssociatedClass(Class<?> clazz) {
93+
List<ApiCommandResourceType> types = new ArrayList<>();
94+
for (ApiCommandResourceType type : ApiCommandResourceType.values()) {
95+
if (type.getAssociatedClass() == clazz) {
96+
types.add(type);
97+
}
98+
}
99+
return types;
100+
}
101+
102+
public static ApiCommandResourceType valueFromAssociatedClass(Class<?> clazz) {
103+
List<ApiCommandResourceType> types = valuesFromAssociatedClass(clazz);
104+
return CollectionUtils.isEmpty(types) ? null : types.get(0);
105+
}
106+
107+
@Override
108+
public String toString() {
109+
return this.name();
110+
}
111+
112+
public static ApiCommandResourceType fromString(String value) {
113+
if (StringUtils.isNotEmpty(value) && EnumUtils.isValidEnum(ApiCommandResourceType.class, value)) {
114+
return valueOf(value);
115+
}
116+
return null;
117+
}
118+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public class ApiConstants {
335335
public static final String RECONNECT = "reconnect";
336336
public static final String RECOVER = "recover";
337337
public static final String REQUIRES_HVM = "requireshvm";
338+
public static final String RESOURCE_NAME = "resourcename";
338339
public static final String RESOURCE_TYPE = "resourcetype";
339340
public static final String RESOURCE_TYPE_NAME = "resourcetypename";
340341
public static final String RESPONSE = "response";

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,6 @@ public void setStartEventId(Long startEventId) {
7474
this.startEventId = startEventId;
7575
}
7676

77-
/**
78-
* Async commands that want to be tracked as part of the listXXX commands need to
79-
* provide implementations of the two following methods, getInstanceId() and getInstanceType()
80-
*
81-
* getObjectId() should return the id of the object the async command is executing on
82-
* getObjectType() should return a type from the AsyncJob.Type enumeration
83-
*/
84-
public Long getInstanceId() {
85-
return null;
86-
}
87-
88-
public ApiCommandJobType getInstanceType() {
89-
return ApiCommandJobType.None;
90-
}
91-
9277
public String getSyncObjType() {
9378
return null;
9479
}

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929

3030
import javax.inject.Inject;
3131

32-
import com.cloud.server.ManagementService;
33-
import com.cloud.server.ResourceIconManager;
34-
import com.cloud.server.ResourceManagerUtil;
35-
import com.cloud.server.ResourceMetaDataService;
36-
import com.cloud.server.TaggedResourceService;
3732
import org.apache.cloudstack.acl.ProjectRoleService;
3833
import org.apache.cloudstack.acl.RoleService;
3934
import org.apache.cloudstack.acl.RoleType;
@@ -72,6 +67,11 @@
7267
import com.cloud.network.vpn.Site2SiteVpnService;
7368
import com.cloud.projects.ProjectService;
7469
import com.cloud.resource.ResourceService;
70+
import com.cloud.server.ManagementService;
71+
import com.cloud.server.ResourceIconManager;
72+
import com.cloud.server.ResourceManagerUtil;
73+
import com.cloud.server.ResourceMetaDataService;
74+
import com.cloud.server.TaggedResourceService;
7575
import com.cloud.storage.DataStoreProviderApiService;
7676
import com.cloud.storage.StorageService;
7777
import com.cloud.storage.VolumeApiService;
@@ -430,4 +430,21 @@ private Object getEntityVO(Class entityType, Object entityId){
430430
return null;
431431
}
432432

433+
/**
434+
* Commands that generate action events associated to a resource and
435+
* async commands that want to be tracked as part of the listXXX commands
436+
* need to provide implementations of the two following methods,
437+
* getApiResourceId() and getApiResourceType()
438+
*
439+
* getApiResourceId() should return the id of the object the async command is executing on
440+
* getApiResourceType() should return a type from the ApiCommandResourceType enumeration
441+
*/
442+
public Long getApiResourceId() {
443+
return null;
444+
}
445+
446+
public ApiCommandResourceType getApiResourceType() {
447+
return ApiCommandResourceType.None;
448+
}
449+
433450
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ public Long getStartIndex() {
117117
return startIndex;
118118
}
119119

120-
@Override
121-
public ApiCommandJobType getInstanceType() {
122-
return ApiCommandJobType.None;
123-
}
124-
125120
@Override
126121
public void validateSpecificParameters(final Map<String, String> params){
127122
super.validateSpecificParameters(params);

0 commit comments

Comments
 (0)