Skip to content

Commit 49cd4fa

Browse files
author
Alex Huang
committed
Connected config gathering to CloudStack
1 parent 90cfca0 commit 49cd4fa

13 files changed

Lines changed: 166 additions & 31 deletions

File tree

api/src/org/apache/cloudstack/config/Configuration.java

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,69 @@
1616
// under the License.
1717
package org.apache.cloudstack.config;
1818

19+
import java.util.Date;
20+
21+
/**
22+
* Configuration represents one global configuration parameter for CloudStack.
23+
* Its scope should indicate whether this parameter can be set at different
24+
* organization levels in CloudStack.
25+
*
26+
*/
1927
public interface Configuration {
2028

21-
public String getCategory();
29+
/**
30+
* @return Category of the parameter.
31+
*/
32+
String getCategory();
33+
34+
/**
35+
* @return Server instance that uses this parameter.
36+
*/
37+
String getInstance();
38+
39+
/**
40+
* @return Component that introduced this parameter.
41+
*/
42+
String getComponent();
43+
44+
/**
45+
* @return Name of the parameter.
46+
*/
47+
String getName();
2248

23-
public String getInstance();
49+
/**
50+
* @return Value set by the administrator. Defaults to the defaultValue.
51+
*/
52+
String getValue();
2453

25-
public String getComponent();
54+
/**
55+
* @return Description of the value and the range of the value.
56+
*/
57+
String getDescription();
2658

27-
public String getName();
59+
/**
60+
* @return Default value for this parameter. Cannot be null.
61+
*/
62+
String getDefaultValue();
2863

29-
public String getValue();
64+
/**
65+
* @return Scope for the parameter. Null indicates that this parameter is
66+
* always global. A non-null value indicates that this parameter can be
67+
* set at a certain organization level.
68+
*/
69+
String getScope();
3070

31-
public String getDescription();
71+
/**
72+
* @return can the configuration parameter be changed without restarting the server.
73+
*/
74+
boolean isDynamic();
3275

76+
/**
77+
* @return The date this VO was updated by the components. Note that this is not
78+
* a date for when an administrator updates the value. This is when the system
79+
* updated this value. By searching on this field gives you all the config
80+
* parameters that have changed in an upgrade. Null value indicates that this
81+
* parameter is no longer used and can be deleted.
82+
*/
83+
Date getUpdated();
3384
}

framework/cluster/src/com/cloud/cluster/ClusterManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,9 +1028,9 @@ public boolean stop() {
10281028
}
10291029

10301030
protected final ConfigKey<Integer> HeartBeatInterval = new ConfigKey<Integer>(Integer.class, "cluster.heartbeat.interval", "management-server",
1031-
"1500", "Interval to check for the heart beat between management server nodes", false, "Seconds");
1031+
"1500", "Interval to check for the heart beat between management server nodes", false);
10321032
protected final ConfigKey<Integer> HeartBeatThreshold = new ConfigKey<Integer>(Integer.class, "cluster.heartbeat.threshold", "management-server",
1033-
"150000", "Threshold before self-fence the management server", true, "Seconds");
1033+
"150000", "Threshold before self-fence the management server", true);
10341034

10351035
@Override
10361036
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {

framework/cluster/src/com/cloud/cluster/ClusterServiceServletAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public boolean stop() {
126126
}
127127

128128
private final ConfigKey<Integer> ClusterMessageTimeOut = new ConfigKey<Integer>(Integer.class, "cluster.message.timeout.seconds", "Advance", "300",
129-
"Time (in seconds) to wait before a inter-management server message post times out.", true, "Seconds");
129+
"Time (in seconds) to wait before a inter-management server message post times out.", true);
130130

131131
private void init() throws ConfigurationException {
132132
if(_mshostDao != null)

framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@
2222
*/
2323
public interface ConfigDepot {
2424
<T> ConfigValue<T> get(ConfigKey<T> key);
25+
26+
<T> ScopedConfigValue<T> getScopedValue(ConfigKey<T> key);
2527
}

framework/config/src/org/apache/cloudstack/framework/config/ConfigDepotAdmin.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
*
2424
*/
2525
public interface ConfigDepotAdmin {
26+
/**
27+
* Create configurations if there are new config parameters.
28+
* Update configurations if the parameter settings have been changed.
29+
* All configurations that have been updated/created will have the same timestamp in the updated field.
30+
* All previous configurations that should be obsolete will have a null updated field.
31+
* @see Configuration
32+
*/
2633
void populateConfigurations();
2734

2835
List<String> getComponentsInDepot();

framework/config/src/org/apache/cloudstack/framework/config/ConfigDepotImpl.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,25 @@
2727
import com.cloud.utils.db.EntityManager;
2828

2929
/**
30-
* DepotImpl implements the ConfigDepot interface
30+
* ConfigDepotImpl implements the ConfigDepot and ConfigDepotAdmin interface.
31+
* Its functionalities include:
32+
* - Control how dynamic config values are cached and refreshed.
33+
* - Control how scoped config values are stored.
34+
* - Gather all of the Configurable interfaces and insert their config
35+
* variables into the config table.
36+
* - Hide the data source where configs are stored and retrieved.
37+
*
38+
* When dealing with this class, we must be very careful on cluster situations.
39+
*
40+
* TODO:
41+
* - Move the rest of the changes to the config table to here.
42+
* - Implement ScopedConfigValue
43+
* - Move the code to set scoped configuration values to here.
44+
* - Add the code to mark the rows in configuration table without
45+
* the corresponding keys to be null.
46+
* - Move all of the configurations to using ConfigDepot
47+
* - Completely eliminate Config.java
48+
* - Figure out the correct categories.
3149
*
3250
*/
3351
class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin {
@@ -48,6 +66,13 @@ public <T> ConfigValue<T> get(ConfigKey<T> config) {
4866
return new ConfigValue<T>(_entityMgr, config);
4967
}
5068

69+
@Override
70+
public <T> ScopedConfigValue<T> getScopedValue(ConfigKey<T> config) {
71+
assert (config.scope() != null) : "Did you notice the configuration you're trying to retrieve is not scoped?";
72+
return new ScopedConfigValue<T>(_entityMgr, config);
73+
}
74+
75+
5176
@Override
5277
public void populateConfigurations() {
5378
Date date = new Date();
@@ -70,8 +95,6 @@ public void populateConfigurations() {
7095
}
7196
}
7297
}
73-
74-
// TODO: Missing code to remove the updated field if the a configurationVO's name cannot be found any more.
7598
}
7699
}
77100

framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
// under the License.
1717
package org.apache.cloudstack.framework.config;
1818

19+
import com.cloud.org.Grouping;
20+
1921
/**
2022
* ConfigKey supplants the original Config.java. It is just a class
2123
* declaration where others can declare their config variables.
2224
*
23-
* TODO: This class should be moved to a framework project where the gathering
24-
* of these configuration keys should be done by a config server. I
25-
* don't have time yet to do this. Ask me about it if you want to work
26-
* in this area. Right now, we'll just work with the actual names.
2725
*/
2826
public class ConfigKey<T> {
2927

@@ -49,7 +47,7 @@ public String description() {
4947
return _description;
5048
}
5149

52-
public String scope() {
50+
public Class<? extends Grouping> scope() {
5351
return _scope;
5452
}
5553

@@ -66,11 +64,11 @@ public String toString() {
6664
private final String _name;
6765
private final String _defaultValue;
6866
private final String _description;
69-
private final String _scope; // Parameter can be at different levels (Zone/cluster/pool/account), by default every parameter is at global
67+
private final Class<? extends Grouping> _scope; // Parameter can be at different levels (Zone/cluster/pool/account), by default every parameter is at global
7068
private final boolean _isDynamic;
7169

7270
public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic,
73-
String scope) {
71+
Class<? extends Grouping> scope) {
7472
_category = category;
7573
_type = type;
7674
_name = name;

framework/config/src/org/apache/cloudstack/framework/config/Configurable.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
// under the License.
1717
package org.apache.cloudstack.framework.config;
1818

19+
/**
20+
* Configurable can be implemented by components to insert their own
21+
* configuration keys.
22+
*
23+
* CloudStack will gather all of these configurations at startup and insert
24+
* them into the configuration table.
25+
*
26+
*/
1927
public interface Configurable {
2028

2129
String getConfigComponentName();

framework/config/src/org/apache/cloudstack/framework/config/ConfigurationVO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public ConfigurationVO(String component, ConfigKey<?> key) {
8080
this(key.category(), "DEFAULT", component, key.key(), key.defaultValue(), key.description());
8181
defaultValue = key.defaultValue();
8282
dynamic = key.isDynamic();
83-
scope = key.scope();
83+
scope = key.scope().getName();
8484
}
8585

8686
@Override
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.framework.config;
18+
19+
import com.cloud.dc.DataCenter;
20+
import com.cloud.dc.Pod;
21+
import com.cloud.org.Cluster;
22+
import com.cloud.org.Grouping;
23+
import com.cloud.utils.db.EntityManager;
24+
25+
public class ScopedConfigValue<T> extends ConfigValue<T> {
26+
public T getValueForScope(long scopeId) {
27+
// TODO: In order to complete this the details for zone, pod, cluster
28+
// needs to have interfaces. Then you can use the EntityManager to
29+
// retrieve those information.
30+
Class<? extends Grouping> scope = _config.scope();
31+
if (scope == DataCenter.class) {
32+
} else if (scope == Pod.class) {
33+
34+
} else if (scope == Cluster.class) {
35+
36+
}
37+
return null;
38+
}
39+
40+
protected ScopedConfigValue(EntityManager entityMgr, ConfigKey<T> key) {
41+
super(entityMgr, key);
42+
}
43+
}

0 commit comments

Comments
 (0)