1639 Commits

Author SHA1 Message Date
Abhishek Kumar
97ddd17f94 fix related to 38d6c4e7e7d7535e08f1e45dad0f4e5fd1eb2239
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-09-13 17:40:20 +05:30
Abhishek Kumar
1d47e4d4ae engine-schema,server,plugins: list host IDs instead whole row where
applicable

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-09-13 16:19:43 +05:30
Abhishek Kumar
fe4ef05053 server,engine-schema: use single query to to list host capacities while
host capacity update

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-09-13 16:17:47 +05:30
Abhishek Kumar
98b27a409d engine-schema: fix get host type count searchcriteria
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-09-13 15:06:33 +05:30
Abhishek Kumar
38d6c4e7e7 optimize finding ready systemvm template for zone
Retrieving templates with inner join on host table was turning out to be
more expensive than finding distinct hypervisor types for a zone using
hsot table and then finding templates for those types

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-09-13 12:10:47 +05:30
Abhishek Kumar
a1ee64344d address host/cluster dao listall
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-09-12 17:23:44 +05:30
Abhishek Kumar
9e5c99ef9e fix tests from a78a2508e955fa8c08b62e56c3440ca58bad3e77
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-09-12 16:58:18 +05:30
Abhishek Kumar
a78a2508e9 server: refactor MS list retrieval for agent connect
During agent join and while changing configs - host and indirect.agent.lb.algorithm, optimize calling DB for zone's host list

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-09-12 16:00:17 +05:30
Abhishek Kumar
68bab20d24 VMInstanceDao.updatePowerState refactor
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-09-12 15:47:00 +05:30
Abhishek Kumar
8f6c657159 optimize scanStalledVms procedure
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-09-06 14:27:56 +05:30
Abhishek Kumar
4400e02a1b
framework/config,server: configkey caching (#472)
Added caching for ConfigKey value retrievals based on the Caffeine
in-memory caching library.
https://github.com/ben-manes/caffeine
Currently, expire time for a cache is 1 minute and each update of the
config key invalidates the cache.

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-09-03 15:53:08 +05:30
Abhishek Kumar
3f80cd3c66 optimize db list.size() cases
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
2024-08-27 13:06:25 +05:30
Abhishek Kumar
5e98405b38 Merge remote-tracking branch 'apple/apple-base418' into scalability-improvements 2024-07-22 16:12:19 +05:30
Suresh Kumar Anaparti
5c682677fc
Support resource name / displaytext with unicode / emoji chars, and SQL exception msg improvements (#460)
* Don't send sql exception/query from dao to upper layer, log it and send only the error message

* Updated charset to utf8mb4, for display_name column/user_vm table and job_result column/async_job table to support unicode chars & emojis

* Added API arg validator for RFC compliance domain name, to validate VM's host name

* Updated user resources name / display name column's charset to utf8mb4

* Check and update char set for affinity group name to utf8mb4, from the data migration in upgrade path

* Updated backup offering name column charset to utf8mb4

* Added unit tests for vm host/domain name validation

* Added smoke test to check resource name for vm, volume, service & disk offering, template, iso, account(first/lastname)

* Updated resource annotation charset to utf8mb4

* Updated some resources description charset to utf8mb4
2024-07-19 09:35:18 +05:30
Vishesh
8be18e587f
FR75 Enforce strict host tag checking (#421)
* Enforce strict host tag checking

* Add e2e tests

* Add more information to error log

* Fix e2e test

* Update global settings descrption

* fixup

* Fix e2e test teardown
2024-06-25 14:38:59 +05:30
Abhishek Kumar
8f88103a29
FR72 - api,server: purge expunged resources (#405)
This PR introduces the functionality of purging removed DB entries for CloudStack entities (currently only for VirtualMachine).
There would be three mechanisms for purging removed resources:
- Background task - CloudStack will run a background task which runs at a defined interval. Other parameters for this task can be controlled with new global settings.
- API - New API `purgeExpungedResources`. It will allow passing the following parameters - resourcetype, batchsize, startdate, enddate
- Config for service offering. Service offerings can be created with purgeresources parameter which would allow purging resources immediately on expunge.

Following new global settings have been added:
- `expunged.resources.purge.enabled`: Default: false. Whether to run a background task to purge the DB records of the expunged resources.
- `expunged.resources.purge.resources`: Default: (empty). A comma-separated list of resource types that will be considered by the background task to purge the DB records of the expunged resources. Currently only VirtualMachine is supported. An empty value will result in considering all resource types for purging.
- `expunged.resources.purge.interval`: Default: 86400. Interval (in seconds) for the background task to purge the DB records of the expunged resources.
- `expunged.resources.purge.delay`: Default: 300. Initial delay (in seconds) to start the background task to purge the DB records of the expunged resources task.
- `expunged.resources.purge.batch.size`: Default: 50. Batch size to be used during purging of the DB records of the expunged resources.
- `expunged.resources.purge.start.time`: Default: (empty). Start time to be used by the background task to purge the DB records of the expunged resources. Use format `yyyy-MM-dd` or `yyyy-MM-dd HH:mm:ss`.
- `expunged.resources.purge.keep.past.days`: Default: 30. The number of days in the past from the execution time of the background task to purge the DB records of the expunged resources for which the expunged resources must not be purged. To enable purging DB records of the expunged resource till the execution of the background task, set the value to zero.
- `expunged.resource.purge.job.delay`: Default: 180. Delay (in seconds) to execute the purging of the DB records of an expunged resource initiated by the configuration in the offering. Minimum value should be 180 seconds and if a lower value is set then the minimum value will be used.

Upstream PRs:
https://github.com/apache/cloudstack/pull/8999
https://github.com/apache/cloudstack-documentation/pull/397

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
Co-authored-by: Suresh Kumar Anaparti <suresh.anaparti@shapeblue.com>
2024-06-19 12:59:50 +05:30
Abhishek Kumar
256051af1d
server: fix resource reservation leakage (#456)
* server: fix resource reservation leakage

Fixes #453

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>

* refactor

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>

* Fix resource reservation leftover entries (#455)

* Resolve comments

* Address comments

---------

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
Co-authored-by: Vishesh <vishesh92@gmail.com>
2024-06-10 12:29:45 +05:30
Wei Zhou
e065c93c3f
Apple FR76: Implicit host tags (#427)
* Merge two HostTagVO and HostTagDaoImpl

* Apple FR76: dynamic host tags

* Revert "Apple FR76: dynamic host tags"

This reverts commit 01b93a873f167018c4fafd0744c0de07ae4de4ed.

* Apple FR76: Implicit host tags

* Apple FR76: address Abhishek's comments

* Apple FR76: move updateImplicitTags

* Apple FR76: add since to other two responses

* Update 8929: add unit test in LibvirtComputingResourceTest

* Update variable names

* Update FR76: add explicithosttags in response

* Update FR76 UI: Update explicit host tags

* Update 8929: remove host tags and change labels on UI

* Update: ui polish for host tags

* fix since in responses

* Update 8929: fix UI error if no host tags
2024-05-30 17:20:37 +05:30
Rohit Yadav
07097849d4 add more missing indexes to lower table scans
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-23 18:55:17 +05:30
Rohit Yadav
b03d1382e6 fix unit tests failures
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-23 10:23:32 +05:30
Rohit Yadav
2f0f0e9ebc engine/schema: call initDB before creating app context bean
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:39 +05:30
Rohit Yadav
3883dbe9a0 schema: force index on user_view_view
In env with large number of shared networks or ip addresses (10k+), this
causes millions of table scans in user_ip_address table. This causes
severe slowness in listVM APIs etc.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:39 +05:30
Rohit Yadav
f57f244863 schema: speed up network offering created table scans
Using function in view was causing too many scans, as many rows as
number of domains and zones. This reduces table scans where left joins
happen using sub-queries. The effect is seen in bit faster create
network API performance.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:39 +05:30
Rohit Yadav
c3867a941f more fixmes and todos
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:39 +05:30
Rohit Yadav
5603bf9c1a engine: optimise CPU and DB hotspot to return enabled hypervisors in the zone
This refactors a ResourceManager::listAvailHypervisorInZone method
that should return unique hypervisors for which existing hosts are Up
and processed. We can approximate this by assuming that those hosts
would have setup their hypervisor-specific systemvmtemplates. In a given
environment there wouldn't be thousands of systemvmtemplates, but can
have thousands of hosts. So, instead of scanning the entire cloud.host
table, we can make calculate guess by returning unique hypervisors of
systemvm templates which are ready. This method was used in
::processConnect() when an agent joins, to speed up its handling.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:39 +05:30
Rohit Yadav
8a320b807d engine/schema: cluster dao method query optimisation
Replace list.size() by doing getCount() instead.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:39 +05:30
Rohit Yadav
90afcf2f85 metrics: optimise code and query to get summed cpu sockets
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:38 +05:30
Rohit Yadav
076a712fbe schema: add indexes that save DB from too many scans
Speeds up several APIs, esp host and VM listing APIs and VM deployment

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:38 +05:30
Rohit Yadav
54accfdc0a schema: add missing index to reduce table scans
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:38 +05:30
Rohit Yadav
5750e56be5 server: improve DB optimisation, indexing and reduce table scans
In this example commit, we look at:
- Adding missing indexes to speed up queries
- Reduce table scans by optimising sql query and using indexes
- Optimising sql queries to remove duplicate rows (use of distinct)
- Reduce CPU and DB load by using jprofiler to optimise both sql query
  and CPU hotspots

server: reduce CPU and DB load caused by systemvm ::isZoneReady()
For this case, the sql query was fetching large number of table scans
only to determine if zone has any available pool+host to launch
systemvms. Accodingly the code and sql queries along with indexes
optimisations were used to lower both DB scans and mgmt server CPU load.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:38 +05:30
Rohit Yadav
807cd6a830 metrics: speed up list zones and cluster metrics APIs
Also add a flag to disable on-the-fly metrics computation when the
list metrics APIs for zones and clusters are called.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:38 +05:30
Rohit Yadav
5484d3c7e6 orchestartion: optimise vm list fetching excluding that reported
This optimises the sql query and iterator to simply return the VMs list
excluding those in the received report.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:38 +05:30
Rohit Yadav
c01aad6ba8 server: count hosts than get all hosts in capacity scans
This refactors hotspot code to fetch just the count of hosts than
all the host VOs for a zone, during capacity scans for systemvms.
This reduces CPU and DB load, in really large (10k+ hosts) env.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-05-22 20:22:38 +05:30
Vishesh
fd9325a86d
Speed up resource count calculation (#425)
* Speed up resource count calculation

* server: remove supportedOwner from Resource.ResourceType (#7416)

* Refactor resource count calculation

* Start transaction for updateCountByDeltaForIds

---------

Co-authored-by: GaOrtiga <49285692+GaOrtiga@users.noreply.github.com>
2024-04-17 14:21:07 +05:30
Vishesh
8d0915c4c9
Change iops on offering change (#416)
* Change IOPS on disk offering change

* Remove iops & bandwidth limits before copying template

* minor refactor

* Handle diskOfferingDetails

* Fixup
2024-04-11 16:59:57 +05:30
Marcus Sorensen
f896586925
Update version to 4.18.1.1 (#417)
* Update version to 4.18.1.1

* Update changelog

* Update changelog

* Update changelog

---------

Co-authored-by: Marcus Sorensen <mls@apple.com>
2024-04-08 09:27:57 -06:00
Rohit Yadav
0c23820c7c
Merge pull request #414 from shapeblue/security-backport418
Backport upstream security fixes to apple-base418
2024-04-03 19:58:28 +05:30
Wei Zhou
21a03ae4da upgrade: fix upgrade from 4.18.1.0 to 4.18.2.0-SNAPSHOT (#7959)
The uprgade from 4.18.1.0 to 4.18.2.0-SNAPSHOT failed with error

```
2023-09-12 16:12:19,003 INFO  [c.c.u.DatabaseUpgradeChecker] (main:null) (logid:) DB version = 4.18.1.0 Code Version = 4.18.2.0
2023-09-12 16:12:19,004 INFO  [c.c.u.DatabaseUpgradeChecker] (main:null) (logid:) Database upgrade must be performed from 4.18.1.0 to 4.18.2.0
2023-09-12 16:12:19,036 DEBUG [c.c.u.DatabaseUpgradeChecker] (main:null) (logid:) Running upgrade Upgrade41800to41810 to upgrade from 4.18.0.0-4.18.1.0 to 4.18.1.0
...
2023-09-12 16:12:19,041 DEBUG [c.c.u.d.ScriptRunner] (main:null) (logid:) -- Schema upgrade from 4.18.0.0 to 4.18.1.0
...
2023-09-12 16:12:21,602 DEBUG [c.c.u.d.DatabaseAccessObject] (main:null) (logid:) Statement: CREATE INDEX i_cluster_details__name on cluster_details (name)
2023-09-12 16:12:21,663 DEBUG [c.c.u.d.DatabaseAccessObject] (main:null) (logid:) Created index i_cluster_details__name
2023-09-12 16:12:21,673 DEBUG [c.c.u.d.T.Transaction] (main:null) (logid:) Rolling back the transaction: Time = 2632 Name =  Upgrade; called by -TransactionLegacy.rollback:888-TransactionLegacy.removeUpTo:831-TransactionLegacy.close:655-TransactionContextInterceptor.invoke:36-ReflectiveMethodInvocation.proceed:175-ExposeInvocationInterceptor.invoke:97-ReflectiveMethodInvocation.proceed:186-JdkDynamicAopProxy.invoke:215-$Proxy30.persist:-1-DatabaseUpgradeChecker.upgrade:319-DatabaseUpgradeChecker.check:403-CloudStackExtendedLifeCycle.checkIntegrity:64
```

It succeeded with this change.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
(cherry picked from commit a88a47989369af204ea6ee8a5fd190311f43c74c)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2024-04-03 15:50:56 +05:30
Vishesh
5137c196c2
HypervisorType as a class (#393)
* HypervisorType as a class

* Fixup

* fixup

* Add missing annotation

* Resolve comments

* Handle parallels typo
2024-04-02 17:35:16 +05:30
Marcus Sorensen
6a28cb33ff
update mysql dependency version (#394)
* update mysql dependency version

* Enable scrollTolerantForwardOnly property in the DB connection, to preserve the legacy behavior of Connector - tolerating backward and absolute cursor movements on result sets of type ResultSet.TYPE_FORWARD_ONLY

References:
https://dev.mysql.com/doc/relnotes/connector-j/en/news-8-0-24.html
https://dev.mysql.com/doc/connector-j/en/connector-j-connp-props-result-sets.html#cj-conn-prop_scrollTolerantForwardOnly

---------

Co-authored-by: Marcus Sorensen <mls@apple.com>
Co-authored-by: Suresh Kumar Anaparti <suresh.anaparti@shapeblue.com>
2024-03-21 18:08:53 +05:30
Vishesh
a1122d175e
Add missing indexes for vmstats (#391) 2024-03-21 14:04:50 +05:30
Vishesh
4c6c8216d5
Use join instead of views (#365)
* Use join instead of views for filtering volumes

* Use join instead of views for filtering events

* Use join instead of views for filtering accounts

* Use join instead of views for filtering domains

* Use join instead of views for filtering hosts

* Use join instead of views for filtering storage pools

* Use join instead of views for filtering service offerings

* Use join instead of views for filtering disk offerings

* Remove unused code

* Fix unit test

* Use disk_offering instead of disk_offering_view in service_offering_view

* Fixup

* Fix listing of diskoffering & serviceoffering

* Use constants instead of strings

* Make changes to prevent sql injection

* Remove commented code

* Prevent n+1 queries for template's response

* remove unused import

* refactor some code

* Add missing check for service offering's join with disk offering

* Fix n+1 queries for stoage pool metrics

* Remove n+1 queries from list accounts

* Remove unused imports

* remove todo

* Remove unused import

* Fixup query generation for nested joins

* Fixups

* Fix DB exception on ClientPreparedStatement

* events,alerts: Add missing indexes (#366)

* Fixup
2024-03-14 17:49:35 +05:30
Vishesh
ba3284bdc5
Fix resource count discrepancies (#376)
* Fix resource count discrepancies

* Fixup while removing vm

* Fix discrepancies when starting VMs

* Fixup tests

* Fixups

* Don't take lock when amount is negative
2024-03-13 18:22:34 +05:30
Abhishek Kumar
1510b44f03
backport: add more unit tests and fix related to #327 (#378)
Adds:

- Fix for volume limit checks for disk offerings with multiple tags - When a VM is deployed with multiple disks having offerings with multiple tags the resource limit check may falter as currently it tries to check based on individual diskoffering. With this, change if offering d1 and d2 for volumes v1 and v2 both have tag1, server will check volume limits for tag tag1 using the combined size of v1 and v2.
- Fix for template tag hosts in random host allocator - May affect use of template tag, service offering tags and random host allocator together. The current code for the random host allocator falters while trying to find the host allocation. This was found and fixed during the addition of the unit test here, https://github.com/shapeblue/cloudstack-apple/pull/378/files#diff-bbf9baea014e5cc1dfe9e7d13467c9857208cfe65e93883721d88a6f0452f912
- Unit tests for changes in api,server,ui: tagged resource limits #327
2024-03-01 17:22:14 +05:30
anniejili
2df750c2f4
Fixed query param for getDomainReservation. (#388)
Co-authored-by: Annie Li <ji_li@apple.com>
2024-02-28 08:10:16 -07:00
Vishesh
8b01c0aa62
Update VM's state if powerstate & state are not in sync (#368)
* Update VM's state if powerstate & state are not in sync

* Add unit tests

* some code improvements for instacne / power state check

* Update power state after vm stop confirmation (as power state 'PowerOn' is kept after vm stop and not updated later)

* Reset the power state update counter before migrate, to allow power state sync to proper state / host

* Do not consider transitional states (Starting, Stopping) to check power state sync

* set powerstate to off for all vm types

---------

Co-authored-by: Suresh Kumar Anaparti <suresh.anaparti@shapeblue.com>
2024-02-20 14:44:04 +05:30
Abhishek Kumar
6a9cdedda4
api,server,ui: tagged resource limits (#327)
Introduces the concept of tagged resource limits. Limits can be enforced on accounts and domains for the deployment of entities for a tagged resource. Current tagged resource limits can be used for the following resource types,

Host limits

    user_vm
    cpu
    memory

Storage limits

    volume
    primary_storage

Following global settings can used to specify tags for which limit needs to be enforced,

    Host: resource.limit.host.tags
    Storage: resource.limit.storage.tags

Option for specifying tagged resource limits and viewing tagged resource usage are made available in the UI.

Enhances use of templatetag for VM deployment and template creation

Adds option to list disk offering with suitability flag for a virtualmachine. A new parameter named virtualmachineid has been added to the listDiskOfferings API which when passed returns suitableforvirtualmachine param in the reponse.
2024-02-07 17:35:15 +05:30
Suresh Kumar Anaparti
b44710c8a9
Pass StoragePoolType object for poolType dao attribute - fixes conversion to DB column (#371) 2024-02-02 14:10:02 +05:30
Marcus Sorensen
40dd867198
Apple base418 storagepooltype as class (#351)
* StoragePoolType as a class

* Fix agent side StoragePoolType enum to class

* Handle StoragePoolType for StoragePoolJoinVO

* Since StoragePoolType is a class, it cannot be converted by @Enumerated annotation.
Implemented conveter class and logic to utilize @Convert annotation.

* Fix UserVMJoinVO for StoragePoolType

* fixed missing imports

* Since StoragePoolType is a class, it cannot be converted by @Enumerated annotation.
Implemented conveter class and logic to utilize @Convert annotation.

* Fixed equals for the enum.

* removed not needed try/catch for prepareAttribute

* Added license to the file.

* Implemented "supportsPhysicalDiskCopy" for storage adaptor. (#352)

Co-authored-by: mprokopchuk <mprokopchuk@apple.com>

* Add javadoc to StoragePoolType class

* Add unit test for StoragePoolType comparisons

* StoragePoolType "==" and ".equals()" fix.

* Fix for abstract storage adaptor set up issue

* review comments

---------

Co-authored-by: Marcus Sorensen <mls@apple.com>
Co-authored-by: mprokopchuk <mprokopchuk@apple.com>
Co-authored-by: mprokopchuk <mprokopchuk@gmail.com>
Co-authored-by: Suresh Kumar Anaparti <suresh.anaparti@shapeblue.com>
2024-01-25 14:58:44 +05:30
Suresh Kumar Anaparti
e704b6e492
Fix reorder/list pools when cluster details are not set (#358)
* Fix reorder/list pools when cluster details are not set

* minor code improvements

* added unit tests
2024-01-18 15:29:00 +05:30