https://issues.apache.org/jira/browse/CLOUDSTACK-2163
master, 4.2.0
In order for the admin to have better control over the first class objects in CS, admins needs to have the ability to add meta information to the objects and be able to expose/hide them from the end user. In addition admin should also be able to deploy the first class resources and have the capability to expose/hide them from the end user. These changes allow a service with higher functionality to manipulate objects managed by CS. For this I propose following changes to be introduced.
One of the use cases can be
Schema changes can be divided into two categories
vm_instance
user_vm_details
user_vm_view
volumes
volume_view
volume_details
networks
network_details
nics
nic_details
disk_offering_details
disk_offering
disk_offering view
CS APIs must be changed to allow for the above schema to be specified at the creation and update of the entities specified.
Regular user/domain admin can never request disabled resources via API.
Admin can do it by providing forDisplay=false flag in corresponding API request.
It works the following way:
DeployVM/UpdateVM/ - Add flag whether to display the VM to end user
CreateNetwork/UpdateNetwork - Add flag whether to display the network to end user
CreateDiskOffering - Add flag whether to display the disk offering to end user
CreateVolume - Add flag whether to display volume to the end user
Add new api's to add meta information for the resources.
UpdateVolume - Exposes the path component for other services to update
AddResourceDetail - Add details to resource
RemoveResourceDetail - Remove detail to resource
ListResourceDetails - lists details for a resource
Upgrade
For existing "resource" and "resource detail" tables the default value for the flag will be "true" so that they are displayed to the end user. This along with the new tables will be added to schema-410to420.sql
Since the display flag will be used by admin to control first class objects and hide them from the end user, following changes are made for calculating resource count
/** * Checks if a limit has been exceeded for an account if displayResource flag is on * * @param account * @param type * @param displayResource * @param count * @throws ResourceAllocationException */ void checkResourceLimit(Account account, ResourceType type, Boolean displayResource, long... count) throws ResourceAllocationException; /** * Increments the resource count if displayResource flag is on * * @param accountId * @param type * @param displayResource * @param delta */ void incrementResourceCount(long accountId, ResourceType type, Boolean displayResource, Long... delta); /** * Increments/Decrements the resource count depending on the displayResource flag is turned on or off respectively * * @param accountId * @param type * @param displayResource * @param delta */ void changeResourceCount(long accountId, ResourceType type, Boolean displayResource, Long... delta); /** * Decrements the resource count if displayResource flag is on * * @param accountId * @param type * @param displayResource * @param delta */ void decrementResourceCount(long accountId, ResourceType type, Boolean displayResource, Long... delta);
If the resources have display flag turned off we should not show the action events corresponding to actions happening on them.
Off course this should be done for end users only. For root admins all the events should be displayed. Technically following changes will be introduced.
Action events are put in at generic place at the entry of the commands and at their manager method interceptions. I have put in a generic function isDisplay() in BaseCmd.java (inherited by all APIs) and introduced a Displayable interface. So at the entry point of the commands this function will be invoked for each api to find out whether the corresponding action event needs to be logged with display=0. The method isDisplay() will check if the resource entity has the Displayable attribute and if it does then it check the display flag.
For method interceptors I will set the value of flag isDisplay in the CallContext so that while persisting action events these can be invoked.
Since the display flag will be used by admin to control first class objects and hide them from the end user, we shouldnt generate usage for the resources while the flag is off. In short, all the usage events are registered only when the flag is on.
Basic rules :-
TBD
2 Comments
Alena Prokharchyk
The feature doesn't actually provide an API for creating the copy of the resource in the DB. Is it a correct statement to make?
What feature does instead is:
provides an ability to mark certain resources as unavailable for display. The resources have to be created using regular cloudStack api prior to this point. And you leave it up to the third party resource (it will create a copy upon reading the msg of original resource creation published to the event bus)
Allows to set metadata for CS resources. Could you provide the samples of the metadata that customers would find useful?
Please let me know if my understanding is correct. Also it would be very helpful to have a simple use case described in the FS consisting of all the steps third party deployer needs to do in order to use the feature, including the APIs he would use. Something like:
the original resource is created. The event is published to the event bus
Third party reads the resource, creates a copy of the record in the DB for zone id=2
Third party calls the updateVm/updateVolume/updateNetwork API to update the display flag to be "false" for the resource copy
Alena Prokharchyk
Couple of questions on display flag implementation. I noticed that:
mysql> select id, name, display_vm from vm_instance where id=4;
--------------------------------------------------
id
name
display_vm
--------------------------------------------------
4
79aa2738-bf6d-43b3-ac8f-df961968d131
0
--------------------------------------------------
1 row in set (0.00 sec)
http://localhost:8096/?command=listVirtualMachines&id=79aa2738-bf6d-43b3-ac8f-df961968d131
<listvirtualmachinesresponse cloud-stack-version="4.2.0-SNAPSHOT">
<count>1</count>
<virtualmachine>
<id>79aa2738-bf6d-43b3-ac8f-df961968d131</id>
<name>79aa2738-bf6d-43b3-ac8f-df961968d131</name>
<account>admin</account>
Sounds like a buggy behavior to me