Add missing HA config keys (#3737)

* Add missing HA config keys
* Change time value to seconds
* Change Integer to Long
* Using ConfigKey defaultValue
* Do some code refactoring
* Simplify code
This commit is contained in:
mdominka 2019-12-17 15:24:53 +01:00 committed by Sven Vogel
parent 2e8c069dd2
commit 16527f1eb0
2 changed files with 72 additions and 35 deletions

View File

@ -16,18 +16,34 @@
// under the License.
package com.cloud.ha;
import java.util.List;
import com.cloud.deploy.DeploymentPlanner;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.utils.component.Manager;
import com.cloud.vm.VMInstanceVO;
import org.apache.cloudstack.framework.config.ConfigKey;
import java.util.List;
/**
* HighAvailabilityManager checks to make sure the VMs are running fine.
*/
public interface HighAvailabilityManager extends Manager {
ConfigKey<Long> TimeBetweenCleanup = new ConfigKey<>("Advanced", Long.class,
"time.between.cleanup", "86400", "Time in seconds to wait before the cleanup thread runs.",
false, null);
ConfigKey<Integer> MaxRetries = new ConfigKey<>("Advanced", Integer.class, "max.retries",
"5", "Number of times to retry start.", false, null);
ConfigKey<Long> TimeToSleep = new ConfigKey<>("Advanced", Long.class, "time.to.sleep",
"60", "Time in seconds to sleep if no work items are found.", false, null);
ConfigKey<Long> TimeBetweenFailures = new ConfigKey<>("Advanced", Long.class,
"time.between.failures", "3600", "Time in seconds before try to cleanup all the VMs"
+ " which are registered for the HA event that were successful and are now ready to be purged.", false, null);
public enum WorkType {
Migration, // Migrating VMs off of a host.
Stop, // Stops a VM for storage pool migration purposes. This should be obsolete now.

View File

@ -16,29 +16,9 @@
// under the License.
package com.cloud.ha;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.managed.context.ManagedContext;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import com.cloud.agent.AgentManager;
import com.cloud.alert.AlertManager;
import com.cloud.cluster.ClusterManagerListener;
import org.apache.cloudstack.management.ManagementServerHost;
import com.cloud.configuration.Config;
import com.cloud.dc.ClusterDetailsDao;
import com.cloud.dc.DataCenterVO;
@ -78,6 +58,27 @@ import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.VMInstanceDao;
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.managed.context.ManagedContext;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
import org.apache.cloudstack.management.ManagementServerHost;
import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
/**
* HighAvailabilityManagerImpl coordinates the HA process. VMs are registered with the HA Manager for HA. The request is stored
@ -101,7 +102,13 @@ import com.cloud.vm.dao.VMInstanceDao;
* ha.retry.wait | time to wait before retrying the work item | seconds | 120 || || stop.retry.wait | time to wait
* before retrying the stop | seconds | 120 || * }
**/
public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvailabilityManager, ClusterManagerListener {
public class HighAvailabilityManagerImpl extends ManagerBase implements Configurable, HighAvailabilityManager, ClusterManagerListener {
private static final int SECONDS_TO_MILLISECONDS_FACTOR = 1000;
private static final int STOP_RETRY_INTERVAL_SECONDS = 600;
private static final int RESTART_RETRY_INTERVAL_SECONDS = 600;
private static final int INVESTIGATE_RETRY_INTERVAL_SECONDS = 60;
private static final int MIGRATE_RETRY_INTERVAL_SECONDS = 120;
protected static final Logger s_logger = Logger.getLogger(HighAvailabilityManagerImpl.class);
WorkerThread[] _workers;
@ -844,29 +851,25 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
value = params.get("force.ha");
_forceHA = Boolean.parseBoolean(value);
value = params.get("time.to.sleep");
_timeToSleep = (long)NumbersUtil.parseInt(value, 60) * 1000;
_timeToSleep = TimeToSleep.value() * SECONDS_TO_MILLISECONDS_FACTOR;
value = params.get("max.retries");
_maxRetries = NumbersUtil.parseInt(value, 5);
_maxRetries = MaxRetries.value();
value = params.get("time.between.failures");
_timeBetweenFailures = NumbersUtil.parseLong(value, 3600) * 1000;
_timeBetweenFailures = TimeBetweenFailures.value() * SECONDS_TO_MILLISECONDS_FACTOR;
value = params.get("time.between.cleanup");
_timeBetweenCleanups = NumbersUtil.parseLong(value, 3600 * 24);
_timeBetweenCleanups = TimeBetweenCleanup.value();
value = params.get("stop.retry.interval");
_stopRetryInterval = NumbersUtil.parseInt(value, 10 * 60);
_stopRetryInterval = NumbersUtil.parseInt(value, STOP_RETRY_INTERVAL_SECONDS);
value = params.get("restart.retry.interval");
_restartRetryInterval = NumbersUtil.parseInt(value, 10 * 60);
_restartRetryInterval = NumbersUtil.parseInt(value, RESTART_RETRY_INTERVAL_SECONDS);
value = params.get("investigate.retry.interval");
_investigateRetryInterval = NumbersUtil.parseInt(value, 1 * 60);
_investigateRetryInterval = NumbersUtil.parseInt(value, INVESTIGATE_RETRY_INTERVAL_SECONDS);
value = params.get("migrate.retry.interval");
_migrateRetryInterval = NumbersUtil.parseInt(value, 2 * 60);
_migrateRetryInterval = NumbersUtil.parseInt(value, MIGRATE_RETRY_INTERVAL_SECONDS);
_instance = params.get("instance");
if (_instance == null) {
@ -1004,4 +1007,22 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai
List<HaWorkVO> haWorks = _haDao.listPendingHaWorkForVm(vmId);
return haWorks.size() > 0;
}
/**
* @return The name of the component that provided this configuration
* variable. This value is saved in the database so someone can easily
* identify who provides this variable.
**/
@Override
public String getConfigComponentName() {
return HighAvailabilityManager.class.getSimpleName();
}
/**
* @return The list of config keys provided by this configuable.
*/
@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey[] {TimeBetweenCleanup, MaxRetries, TimeToSleep, TimeBetweenFailures};
}
}