weizhouapache commented on code in PR #7170:
URL: https://github.com/apache/cloudstack/pull/7170#discussion_r1099851181
##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -1249,6 +1250,52 @@ public AgentHandler(final Task.Type type, final Link
link, final byte[] data) {
super(type, link, data);
}
+ private void processHostHealthCheckResult(Boolean
hostHealthCheckResult, long hostId) {
+ if (hostHealthCheckResult == null) {
+ return;
+ }
+ HostVO host = _hostDao.findById(hostId);
+ if (host == null) {
+ s_logger.error(String.format("Unable to find host with ID:
%s", hostId));
+ return;
+ }
+ if
(!BooleanUtils.toBoolean(EnableKVMAutoEnableDisable.valueIn(host.getClusterId())))
{
+ s_logger.debug(String.format("%s is disabled for the cluster
%s, cannot process the health check result " +
+ "received for the host %s",
EnableKVMAutoEnableDisable.key(), host.getClusterId(), host.getName()));
+ return;
+ }
+
+ String allocationState = hostHealthCheckResult ? "Enable" :
"Disable";
Review Comment:
can define a enum ?
##########
server/src/main/java/com/cloud/resource/ResourceManagerImpl.java:
##########
@@ -1774,73 +1780,142 @@ public boolean checkAndMaintain(final long hostId) {
return hostInMaintenance;
}
+ private ResourceState.Event
getResourceEventFromAllocationStateString(String allocationState) {
+ final ResourceState.Event resourceEvent =
ResourceState.Event.toEvent(allocationState);
+ if (resourceEvent != ResourceState.Event.Enable && resourceEvent !=
ResourceState.Event.Disable) {
+ throw new InvalidParameterValueException(String.format("Invalid
allocation state: %s, " +
+ "only Enable/Disable are allowed", allocationState));
+ }
+ return resourceEvent;
+ }
+
+ private void handleAutoEnableDisableKVMHost(boolean
autoEnableDisableKVMSetting,
+ boolean
isUpdateFromHostHealthCheck,
+ HostVO host, DetailVO
hostDetail,
+ ResourceState.Event
resourceEvent) {
+ if (autoEnableDisableKVMSetting) {
+ if (!isUpdateFromHostHealthCheck && hostDetail != null &&
+ !Boolean.parseBoolean(hostDetail.getValue()) &&
resourceEvent == ResourceState.Event.Enable) {
+ hostDetail.setValue(Boolean.TRUE.toString());
+ _hostDetailsDao.update(hostDetail.getId(), hostDetail);
+ } else if (!isUpdateFromHostHealthCheck && hostDetail != null &&
+ Boolean.parseBoolean(hostDetail.getValue()) &&
resourceEvent == ResourceState.Event.Disable) {
+ s_logger.info(String.format("The setting %s is enabled but the
host %s is manually set into %s state," +
+ "ignoring future auto enabling of the host
based on health check results",
+ AgentManager.EnableKVMAutoEnableDisable.key(),
host.getName(), resourceEvent));
+ hostDetail.setValue(Boolean.FALSE.toString());
+ _hostDetailsDao.update(hostDetail.getId(), hostDetail);
+ } else if (isUpdateFromHostHealthCheck && hostDetail == null) {
+ hostDetail = new DetailVO(host.getId(),
ApiConstants.AUTO_ENABLE_KVM_HOST, Boolean.TRUE.toString());
+ _hostDetailsDao.persist(hostDetail);
+ }
+ }
+ }
+ private boolean updateHostAllocationState(HostVO host, String
allocationState,
+ boolean
isUpdateFromHostHealthCheck) throws NoTransitionException {
+ boolean autoEnableDisableKVMSetting =
AgentManager.EnableKVMAutoEnableDisable.valueIn(host.getClusterId()) &&
+ host.getHypervisorType() == HypervisorType.KVM;
+ ResourceState.Event resourceEvent =
getResourceEventFromAllocationStateString(allocationState);
+ DetailVO hostDetail = _hostDetailsDao.findDetail(host.getId(),
ApiConstants.AUTO_ENABLE_KVM_HOST);
+
+ if ((host.getResourceState() == ResourceState.Enabled && resourceEvent
== ResourceState.Event.Enable) ||
+ (host.getResourceState() == ResourceState.Disabled &&
resourceEvent == ResourceState.Event.Disable)) {
+ s_logger.info(String.format("The host %s is already on the
allocated state", host.getName()));
+ return false;
+ }
+
+ if (autoEnableDisableKVMSetting && isUpdateFromHostHealthCheck &&
hostDetail != null &&
Review Comment:
can you extract as a method ?
--
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]