-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Externalize kvm agent storage timeout configuration #4585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DaanHoogland
merged 16 commits into
apache:main
from
GutoVeronezi:externalize-kvm-agent-storage-timeout-configuration
Jul 19, 2021
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
79a7aac
Externalize KVM Agent storage's timeout configuration
0351eca
Refactored KVHAMonitor nested thread and changed some logs
f9bfb55
It has been added the timeout's config in the agent.properties file
c221230
Rename classes
abd447a
Rename var and remove comment
debb3e9
Fix typo with word "heartbeat"
89792f8
Extract multiple methods call to variables
0c1b1a2
Add unit tests to file handler
17f2b79
Increase info about the property
001e74e
Create inner class Property
7d62d24
Rename method getProperty to getPropertyValue
695da42
Remove copyright
GutoVeronezi 353ff5e
Remove copyright
GutoVeronezi c80ff53
Extract code to createHeartBeatCommand
c3c8680
Merge branch 'externalize-kvm-agent-storage-timeout-configuration' of…
11d8225
Change method access from protected to private
GutoVeronezi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
agent/src/main/java/com/cloud/agent/properties/AgentProperty.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright 2021 The Apache Software Foundation. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.cloud.agent.properties; | ||
|
|
||
| /** | ||
| * Class of constant agent's properties available to configure on | ||
| * "agent.properties". | ||
| *<br><br> | ||
| * Not all available agent properties are defined here, but we should work to | ||
| * migrate them on demand to this class. | ||
| * | ||
| * @param <T> type of the default value. | ||
| */ | ||
| public class AgentProperty<T>{ | ||
|
|
||
| /** | ||
| * Heartbeat update timeout. <br> | ||
| * Data type: int. <br> | ||
| * Default value: 60000 (ms). | ||
| */ | ||
| public static final AgentProperty<Integer> HEARTBEAT_UPDATE_TIMEOUT = new AgentProperty<Integer>("hearbeat.update.timeout", 60000); | ||
|
|
||
| private final String name; | ||
| private final T defaultValue; | ||
|
|
||
| private AgentProperty(String name, T value) { | ||
| this.name = name; | ||
| this.defaultValue = value; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public T getDefaultValue() { | ||
| return defaultValue; | ||
| } | ||
|
|
||
| } |
66 changes: 66 additions & 0 deletions
66
agent/src/main/java/com/cloud/agent/properties/AgentPropertyFile.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Copyright 2021 The Apache Software Foundation. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.cloud.agent.properties; | ||
|
|
||
| import com.cloud.utils.PropertiesUtil; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import org.apache.cloudstack.utils.security.KeyStoreUtils; | ||
| import org.apache.commons.beanutils.ConvertUtils; | ||
| import org.apache.commons.beanutils.converters.IntegerConverter; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.log4j.Logger; | ||
|
|
||
| /** | ||
| * This class provides a facility to read the agent's properties file and get | ||
| * its properties, according to the {@link AgentProperty} properties constants. | ||
| * | ||
| */ | ||
| public class AgentPropertyFile { | ||
|
|
||
| private static final Logger logger = Logger.getLogger(AgentPropertyFile.class); | ||
|
|
||
| /** | ||
| * This method reads the property in the agent.properties file. | ||
| * | ||
| * @param property the property to retrieve. | ||
| * @return The value of the property. If the property is not available, the | ||
| * default defined value will be used. | ||
| */ | ||
| public static <T> T getProperty(AgentProperty<T> property) { | ||
| final T defaultValue = property.getDefaultValue(); | ||
| File agentPropertiesFile = PropertiesUtil.findConfigFile(KeyStoreUtils.AGENT_PROPSFILE); | ||
|
|
||
| if (agentPropertiesFile != null) { | ||
| try { | ||
| String configValue = PropertiesUtil.loadFromFile(agentPropertiesFile).getProperty(property.getName()); | ||
| if (StringUtils.isNotBlank(configValue)) { | ||
| ConvertUtils.register(new IntegerConverter(defaultValue), Integer.class); | ||
| return (T)ConvertUtils.convert(configValue, defaultValue.getClass()); | ||
| } else { | ||
| logger.debug(String.format("Property [%s] has empty or null value. Using default value [%s].", property.getName(), property.getDefaultValue())); | ||
| } | ||
| } catch (IOException ex) { | ||
| logger.debug(String.format("Failed to get property [%s]. Using default value [%s].", property.getName(), property.getDefaultValue()), ex); | ||
| } | ||
| } else { | ||
| logger.debug(String.format("File [%s] was not found, we will use default defined values. Property [%s]: [%s].", KeyStoreUtils.AGENT_PROPSFILE, property.getName(), property.getDefaultValue())); | ||
| } | ||
|
|
||
| return defaultValue; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.