Action Events are logged for API cmds in API implementation at the corresponding manager layer.
Action Events are stored in event table. ListEvents Api lists the Action Events. These events are generated at the manager layer using @ActionEvent annotation. EventType and description are mentioned as part of the annotation.
There are four states for action events.
Sample annotation:
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_CREATE, eventDescription = "creating volume", create = true)
2. Scheduled : Logged only for async cmds. For any async command, Scheuled event is logged after it is queued (ApiServer.queueCommand). No annotation required, Scheduled event is automatically logged for all async commands
3. Started : Logged when an async command starts execution. @ActionEvent annotation has to be used with async flag set to true. Started event will be logged before the method gets executed.
Sample annotation:
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_CREATE, eventDescription = "creating volume", async = true)
4. Completed : Logged for all cmds with @ActionEvent annotation. Completed event is logged after the method execution is completed. On failure, Completed event is logged with Error level. Exception has to be thrown to indicate any failure. No exception will be assumed as success.
A cmd which involves creation of an entity and is an async commmand will have all four event states. All async cmds will have Scheduled, Started, Completed state. Sync commands will have only Completed state events.
Any additional details to the event description can be set in the UserContext.
e.g.: UserContext.current().setEventDetails("Vm Id: "+getId());
Complete list of events is available in api/src/com/cloud/event/EventTypes.java.
Sample entries in event tables:
mysql> select * from event;
+---------------------------------------------------------------------------------------------------------------------------------------+-----------+
| id | type | state | description | user_id | account_id | created | level | start_id | parameters |
+---------------------------------------------------------------------------------------------------------------------------------------+-----------+
| 2 | VOLUME.CREATE | Created | Successfully created entity for creating volume. Volume Id: 3 | 2 | 2 | 2011-05-04 10:56:25 | INFO | 0 | NULL |
| 3 | VOLUME.CREATE | Scheduled | Scheduled async job for creating volume: vol1 | 2 | 2 | 2011-05-04 10:56:25 | INFO | 2 | NULL |
| 4 | VOLUME.CREATE | Started | Starting job for creating volume. Volume Id: 3 | 2 | 2 | 2011-05-04 10:56:25 | INFO | 2 | NULL |
| 5 | VOLUME.CREATE | Completed | Successfully completed creating volume. Volume Id: 3 | 2 | 2 | 2011-05-04 10:56:25 | INFO | 2 | NULL |
+---------------------------------------------------------------------------------------------------------------------------------------+-----------+
Usage is not impacted by Action Events. Seperate Usage Events are used for Usage
cloudstack-oss/api/src/com/cloud/api/commands/CreateVolumeCmd.java
Annotation for Created Event:
com.cloud.storage.StorageManagerImpl.allocVolume(CreateVolumeCmd)
@Override
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_CREATE, eventDescription = "creating volume", create = true)
public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationException
Annotation for Started and Completed Events:
com.cloud.storage.StorageManagerImpl.createVolume(CreateVolumeCmd)
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_CREATE, eventDescription = "creating volume", async = true)
public VolumeVO createVolume(CreateVolumeCmd cmd) {
cloudstack-oss/api/src/com/cloud/api/commands/StartVMCmd.java
Annotation for Started and Completed Events:
com.cloud.vm.UserVmManagerImpl.startVirtualMachine(StartVMCmd)
@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_START, eventDescription = "starting Vm", async = true)
public UserVm startVirtualMachine(StartVMCmd cmd)
cloudstack-oss/api/src/com/cloud/api/commands/CreateUserCmd.java
Annotation for Completed Event:
com.cloud.user.AccountManagerImpl.createUser(CreateUserCmd)
@Override
@ActionEvent(eventType = EventTypes.EVENT_USER_CREATE, eventDescription = "creating User")
public UserVO createUser(CreateUserCmd cmd)