JoaoJandre commented on code in PR #8475:
URL: https://github.com/apache/cloudstack/pull/8475#discussion_r1483061107
##########
server/src/main/java/com/cloud/server/ManagementServerImpl.java:
##########
@@ -5055,31 +5055,66 @@ public Pair<List<? extends HypervisorCapabilities>,
Integer> listHypervisorCapab
return new Pair<List<? extends HypervisorCapabilities>,
Integer>(result.first(), result.second());
}
+ protected HypervisorCapabilitiesVO
getHypervisorCapabilitiesForUpdate(final Long id, final String hypervisorStr,
final String hypervisorVersion) {
+ if (id == null && StringUtils.isAllEmpty(hypervisorStr,
hypervisorVersion)) {
+ throw new InvalidParameterValueException("Either ID or hypervisor
and hypervisor version must be specified");
+ }
+ if (id != null) {
+ if (!StringUtils.isAllBlank(hypervisorStr, hypervisorVersion)) {
+ throw new InvalidParameterValueException("ID can not be
specified together with hypervisor and hypervisor version");
+ }
+ HypervisorCapabilitiesVO hpvCapabilities =
_hypervisorCapabilitiesDao.findById(id, true);
+ if (hpvCapabilities == null) {
+ final InvalidParameterValueException ex = new
InvalidParameterValueException("unable to find the hypervisor capabilities for
specified id");
+ ex.addProxyObject(id.toString(), "Id");
+ throw ex;
+ }
+ return hpvCapabilities;
+ }
+ if (StringUtils.isAnyBlank(hypervisorStr, hypervisorVersion)) {
+ throw new InvalidParameterValueException("Hypervisor and
hypervisor version must be specified together");
+ }
+ HypervisorType hypervisorType = HypervisorType.getType(hypervisorStr);
+ if (hypervisorType == HypervisorType.None) {
+ throw new InvalidParameterValueException("Invalid hypervisor
specified");
+ }
+ HypervisorCapabilitiesVO hpvCapabilities =
_hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(hypervisorType,
hypervisorVersion);
+ if (hpvCapabilities == null) {
+ final InvalidParameterValueException ex = new
InvalidParameterValueException("Unable to find the hypervisor capabilities for
specified hypervisor and hypervisor version");
+ ex.addProxyObject(hypervisorStr, "hypervisor");
+ ex.addProxyObject(hypervisorVersion, "hypervisorVersion");
+ throw ex;
+ }
+ return hpvCapabilities;
+ }
+
@Override
public HypervisorCapabilities
updateHypervisorCapabilities(UpdateHypervisorCapabilitiesCmd cmd) {
final Long id = cmd.getId();
+ final String hypervisorStr = cmd.getHypervisor();
+ final String hypervisorVersion = cmd.getHypervisorVersion();
final Boolean securityGroupEnabled = cmd.getSecurityGroupEnabled();
final Long maxGuestsLimit = cmd.getMaxGuestsLimit();
final Integer maxDataVolumesLimit = cmd.getMaxDataVolumesLimit();
final Boolean storageMotionSupported = cmd.getStorageMotionSupported();
final Integer maxHostsPerClusterLimit =
cmd.getMaxHostsPerClusterLimit();
final Boolean vmSnapshotEnabled = cmd.getVmSnapshotEnabled();
- HypervisorCapabilitiesVO hpvCapabilities =
_hypervisorCapabilitiesDao.findById(id, true);
-
- if (hpvCapabilities == null) {
- final InvalidParameterValueException ex = new
InvalidParameterValueException("unable to find the hypervisor capabilities for
specified id");
- ex.addProxyObject(id.toString(), "Id");
- throw ex;
- }
+ HypervisorCapabilitiesVO hpvCapabilities =
getHypervisorCapabilitiesForUpdate(id, hypervisorStr, hypervisorVersion);
final boolean updateNeeded = securityGroupEnabled != null ||
maxGuestsLimit != null ||
maxDataVolumesLimit != null || storageMotionSupported != null
|| maxHostsPerClusterLimit != null ||
vmSnapshotEnabled != null;
if (!updateNeeded) {
return hpvCapabilities;
}
+ if (StringUtils.isNotBlank(hypervisorVersion) &&
!hpvCapabilities.getHypervisorVersion().equals(hypervisorVersion)) {
+ s_logger.debug(String.format("Hypervisor capabilities for
hypervisor: %s and version: %s does not exist, creating a copy from the parent
version: %s for update", hpvCapabilities.getHypervisorType(),
hypervisorVersion, hpvCapabilities.getHypervisorVersion()));
Review Comment:
```suggestion
logger.debug(String.format("Hypervisor capabilities for
hypervisor: %s and version: %s does not exist, creating a copy from the parent
version: %s for update", hpvCapabilities.getHypervisorType(),
hypervisorVersion, hpvCapabilities.getHypervisorVersion()));
```
--
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]