CharlesQueiroz commented on code in PR #6899:
URL: https://github.com/apache/cloudstack/pull/6899#discussion_r1027320198
##########
engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java:
##########
@@ -1398,15 +1405,152 @@ private void
logBootModeParameters(Map<VirtualMachineProfile.Param, Object> para
}
}
+ /**
+ * Method to return the service offering by the given configuration.
+ *
+ * @param configName name of the config
+ * @return the service offering found or null if not found
+ */
+ public ServiceOffering getServiceOfferingByConfig(String configName) {
+ ServiceOffering defaultRouterOffering = null;
+ final String globalRouterOffering = configDao.getValue(configName);
+
+ if (globalRouterOffering != null) {
+ defaultRouterOffering =
_serviceOfferingDao.findByUuid(globalRouterOffering);
+ }
+
+ if (defaultRouterOffering == null) {
+ defaultRouterOffering =
_serviceOfferingDao.findByName(ServiceOffering.routerDefaultOffUniqueName);
+ }
+
+ return defaultRouterOffering;
+ }
+
+ /**
+ * Count VR resources for domain if global setting is true
+ * if value is "all" count all VR resources else get diff of
+ * current VR offering and default VR offering
+ *
+ * @param offering VR service offering
+ * @param defaultRouterOffering default VR service offering
+ * @param owner account
+ * @return a Pair of cpu and ram
+ */
+ private Pair<Long, Long> resolveCpuAndMemoryCount(ServiceOffering
offering, ServiceOffering defaultRouterOffering, Account owner) {
+ Integer cpuCount = 0;
+ Integer memoryCount = 0;
+ if
(COUNT_ALL_VR_RESOURCES.equalsIgnoreCase(ResourceCountRoutersType.valueIn(owner.getDomainId())))
{
+ cpuCount = offering.getCpu();
+ memoryCount = offering.getRamSize();
+ } else if
(COUNT_DELTA_VR_RESOURCES.equalsIgnoreCase(ResourceCountRoutersType.valueIn(owner.getDomainId())))
{
+ // Default offering value can be greater than current offering
value
+ if (offering.getCpu() >= defaultRouterOffering.getCpu()) {
+ cpuCount = offering.getCpu() - defaultRouterOffering.getCpu();
+ }
+ if (offering.getRamSize() >= defaultRouterOffering.getRamSize()) {
+ memoryCount = offering.getRamSize() -
defaultRouterOffering.getRamSize();
+ }
+ }
+
+ return Pair.of(cpuCount.longValue(), memoryCount.longValue());
+ }
+
+ private void validateResouceCount(Pair<Long, Long> cpuMemoryCount, Account
owner) {
+ final Long cpuCount = cpuMemoryCount.first();
+ final Long memoryCount = cpuMemoryCount.second();
+ try {
+ if (cpuCount > 0) {
+ _resourceLimitMgr.checkResourceLimit(owner, ResourceType.cpu,
cpuCount);
+ }
+ if (memoryCount > 0) {
+ _resourceLimitMgr.checkResourceLimit(owner,
ResourceType.memory, memoryCount);
+ }
+ } catch (ResourceAllocationException ex) {
+ throw new CloudRuntimeException("Unable to deploy/start routers
due to " + ex.getMessage());
+ }
+ }
+
+ /**
+ * Check if resource count can be allocated to account/domain
+ *
+ * @param cpuMemoryCount a Pair of cpu and ram
+ * @param owner the account
+ */
+ private void calculateResourceCount(Pair<Long, Long> cpuMemoryCount,
Account owner, boolean isIncrement) {
+ validateResouceCount(cpuMemoryCount, owner);
Review Comment:
done.
--
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]