SadiJr commented on pull request #5901:
URL: https://github.com/apache/cloudstack/pull/5901#issuecomment-1032953373
@DaanHoogland a more complex explanation:
1. To work with volumes, ACS has a listener, called `VolumeStateListener`.
This listener has a method called `postStateTransitionEvent`, which can
generate a Usage Event in some transactional events. The transactional events
that can generate Usage Events can be found in `com.cloud.storage.Volume` class.
2. When creating a new volume (not attached to any VM), the API createVolume
is used. This API call method `allocVolume` of class `VolumeApiServiceImpl`
(which only alloc the volume in DB, without sending the createvolume cmd to
hypervisor, this command is only sended when the volume is attached to a VM),
and, this method calls the method `commitVolume`, which generates a
VOLUME.CREATE Usage Event.
3. So, when destroying a volume in `allocated` state, via API destroyVolume,
the method `destroyVolumeIfPossible` of class `VolumeApiServiceImpl` will be
called and, if the volume state isn't in the Set of volume states cannot be
destroyed (which isn't the case of `allocated` state), the method
`destroyVolume` of class `VolumeServiceImpl` is called.
4. In this method, the volume state has changed to `DestroyRequested` (and
then to `Destroy`) and then to `OperationSucceeded`.
4. When volume changes is state to `Destroy` with `OperationSucceeded`
event, the listener, in the `postStateTransitionEvent` method, generates a
VOLUME.DELETE Usage event.
5. But, in the normal execution, volumes in allocated state has only it
state changed to `DestroyRequested`, but no state change event of type
`OperationSucceeded` is used, which causes ACS, more specific the listener, to
not generate a DELETE Usage Event.
6. To fix this, there a lot of possibilities:
- Don't generate a CREATE Usage Event if volume is not allocated to any
VM;
- Remove the `allocated` state from `STATES_VOLUME_CANNOT_BE_DESTROYED`
Set;
- In the `destroyVolume` method, when volume is in `allocated` state,
make a transaction to `DestroyRequested` and, with success, make another
transaction to `OperationSucceeded`, to make listener generates a DELETE Usage
Event.
7. In this PR, I first used the second option, but, after a new review, I
chose to use the third
PS: I'm not sure I was clear in my answer. If you have any questions or
suggestions, just let me know :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]