diff --git a/api/resources/META-INF/cloudstack/api-config/module.properties b/api/resources/META-INF/cloudstack/api-config/module.properties new file mode 100644 index 00000000000..3b2a85d2743 --- /dev/null +++ b/api/resources/META-INF/cloudstack/api-config/module.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +name=api-config +parent=core diff --git a/api/resources/META-INF/cloudstack/api-config/spring-api-config-context.xml b/api/resources/META-INF/cloudstack/api-config/spring-api-config-context.xml new file mode 100644 index 00000000000..2cd12663072 --- /dev/null +++ b/api/resources/META-INF/cloudstack/api-config/spring-api-config-context.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/api/src/org/apache/cloudstack/config/ApiServiceConfiguration.java b/api/src/org/apache/cloudstack/config/ApiServiceConfiguration.java index f8f6d022daf..edf5a21b673 100644 --- a/api/src/org/apache/cloudstack/config/ApiServiceConfiguration.java +++ b/api/src/org/apache/cloudstack/config/ApiServiceConfiguration.java @@ -16,9 +16,12 @@ // under the License. package org.apache.cloudstack.config; +import javax.ejb.Local; + import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; +@Local(value = {ApiServiceConfiguration.class}) public class ApiServiceConfiguration implements Configurable { public static final ConfigKey ManagementHostIPAdr = new ConfigKey("Advanced", String.class, "host", "localhost", "The ip address of management server", true); public static final ConfigKey ApiServletPath = new ConfigKey("Advanced", String.class, "api.servlet.endpoint", "http://localhost:8080/client/api?", @@ -31,7 +34,7 @@ public class ApiServiceConfiguration implements Configurable { @Override public ConfigKey[] getConfigKeys() { - return new ConfigKey[] {ManagementHostIPAdr}; + return new ConfigKey[] {ManagementHostIPAdr, ApiServletPath}; } } diff --git a/framework/cluster/src/com/cloud/cluster/ClusterManager.java b/framework/cluster/src/com/cloud/cluster/ClusterManager.java index f59e63cc52c..ffdf3663f7b 100644 --- a/framework/cluster/src/com/cloud/cluster/ClusterManager.java +++ b/framework/cluster/src/com/cloud/cluster/ClusterManager.java @@ -26,7 +26,6 @@ public interface ClusterManager extends Manager { "Interval to check for the heart beat between management server nodes", false); final ConfigKey HeartbeatThreshold = new ConfigKey(Integer.class, "cluster.heartbeat.threshold", "management-server", "150000", "Threshold before self-fence the management server", true); - final ConfigKey ManagementHostIPAdr = new ConfigKey("Advanced", String.class, "host", "localhost", "The ip address of management server", true); void OnReceiveClusterServicePdu(ClusterServicePdu pdu); diff --git a/framework/cluster/src/com/cloud/cluster/ClusterManagerImpl.java b/framework/cluster/src/com/cloud/cluster/ClusterManagerImpl.java index ca0b031a5c2..622aa62f073 100644 --- a/framework/cluster/src/com/cloud/cluster/ClusterManagerImpl.java +++ b/framework/cluster/src/com/cloud/cluster/ClusterManagerImpl.java @@ -1099,7 +1099,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C @Override public ConfigKey[] getConfigKeys() { - return new ConfigKey[] {HeartbeatInterval, HeartbeatThreshold, ManagementHostIPAdr}; + return new ConfigKey[] {HeartbeatInterval, HeartbeatThreshold}; } private boolean pingManagementNode(ManagementServerHostVO mshost) { diff --git a/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java b/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java index 50e9d898a50..1ed37ab9969 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/ConfigDepot.java @@ -29,4 +29,6 @@ public interface ConfigDepot { Set> getConfigListByScope(String scope); void set(ConfigKey key, T value); + + void createOrUpdateConfigObject(String componentName, ConfigKey key, String value); } diff --git a/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java b/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java index 929b299be7c..c1ab6b89101 100644 --- a/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java +++ b/framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java @@ -27,15 +27,14 @@ import java.util.Set; import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.commons.lang.ObjectUtils; -import org.apache.log4j.Logger; - import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigDepotAdmin; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.ScopedConfigStorage; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; +import org.apache.commons.lang.ObjectUtils; +import org.apache.log4j.Logger; import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; @@ -116,23 +115,8 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { } _allKeys.put(key.key(), new Pair>(configurable.getConfigComponentName(), key)); - ConfigurationVO vo = _configDao.findById(key.key()); - if (vo == null) { - vo = new ConfigurationVO(configurable.getConfigComponentName(), key); - vo.setUpdated(date); - _configDao.persist(vo); - } else { - if (vo.isDynamic() != key.isDynamic() || !ObjectUtils.equals(vo.getDescription(), key.description()) || - !ObjectUtils.equals(vo.getDefaultValue(), key.defaultValue()) || - !ObjectUtils.equals(vo.getScope(), key.scope().toString())) { - vo.setDynamic(key.isDynamic()); - vo.setDescription(key.description()); - vo.setDefaultValue(key.defaultValue()); - vo.setScope(key.scope().toString()); - vo.setUpdated(date); - _configDao.persist(vo); - } - } + createOrupdateConfigObject(date, configurable.getConfigComponentName(), key, null); + if ((key.scope() != null) && (key.scope() != ConfigKey.Scope.Global)) { Set> currentConfigs = _scopeLevelConfigsMap.get(key.scope()); currentConfigs.add(key); @@ -142,6 +126,28 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { _configured.add(configurable); } + private void createOrupdateConfigObject(Date date, String componentName, ConfigKey key, String value) { + ConfigurationVO vo = _configDao.findById(key.key()); + if (vo == null) { + vo = new ConfigurationVO(componentName, key); + vo.setUpdated(date); + if (value != null) { + vo.setValue(value); + } + _configDao.persist(vo); + } else { + if (vo.isDynamic() != key.isDynamic() || !ObjectUtils.equals(vo.getDescription(), key.description()) || !ObjectUtils.equals(vo.getDefaultValue(), key.defaultValue()) + || !ObjectUtils.equals(vo.getScope(), key.scope().toString())) { + vo.setDynamic(key.isDynamic()); + vo.setDescription(key.description()); + vo.setDefaultValue(key.defaultValue()); + vo.setScope(key.scope().toString()); + vo.setUpdated(date); + _configDao.persist(vo); + } + } + } + @Override public void populateConfiguration(Configurable configurable) { populateConfiguration(new Date(), configurable); @@ -193,4 +199,10 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { public void set(ConfigKey key, T value) { _configDao.update(key.key(), value.toString()); } + + @Override + public void createOrUpdateConfigObject(String componentName, ConfigKey key, String value) { + createOrupdateConfigObject(new Date(), componentName, key, value); + + } } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index b8786b8d56b..cbf3728de80 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -152,6 +152,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio @Inject protected ConfigurationManager _configMgr; + public ConfigurationServerImpl() { setRunLevel(ComponentLifecycle.RUN_LEVEL_FRAMEWORK_BOOTSTRAP); } @@ -247,7 +248,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio } if (needUpdateHostIp) { - _configDao.update(ApiServiceConfiguration.ManagementHostIPAdr.key(), ApiServiceConfiguration.ManagementHostIPAdr.category(), hostIpAdr); + _configDepot.createOrUpdateConfigObject(ApiServiceConfiguration.class.getSimpleName(), ApiServiceConfiguration.ManagementHostIPAdr, hostIpAdr); s_logger.debug("ConfigurationServer saved \"" + hostIpAdr + "\" as host."); } }