Permalink
Browse files

Merged latest master

  • Loading branch information...
2 parents 821f8a0 + 878ee67 commit 39ec1520e18082b6ce47412492d630c414701131 Jennifer Hickey committed Jul 7, 2010
View
45 hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/ServerConfigSet_test.java
@@ -36,21 +36,18 @@ public void testSetSingleConfig() throws Exception {
ServerConfigResponse configResponse = sApi.getConfig();
hqAssertSuccess(configResponse);
- List<ServerConfig> configs = configResponse.getServerConfig();
- for (ServerConfig config : configs) {
- if (config.getKey().equals("HQ_ALERTS_ENABLED")) {
- config.setValue("false");
- }
- }
+ ServerConfig c = new ServerConfig();
+ c.setKey("HQ_ALERTS_ENABLED");
+ c.setValue("false");
- StatusResponse response = sApi.setConfig(configs);
+ StatusResponse response = sApi.setConfig(c);
hqAssertSuccess(response);
// Validate update of HQ_ALERTS_ENABLED
configResponse = sApi.getConfig();
hqAssertSuccess(configResponse);
- configs = configResponse.getServerConfig();
+ List<ServerConfig> configs = configResponse.getServerConfig();
for (ServerConfig config : configs) {
if (config.getKey().equals("HQ_ALERTS_ENABLED")) {
assertTrue("HQ_ALERTS_ENABLED was not false",
@@ -63,14 +60,44 @@ public void testSetSingleConfig() throws Exception {
hqAssertSuccess(response);
}
+ public void testSetUnknownConfig() throws Exception {
+
+ ServerConfigApi sApi = getApi().getServerConfigApi();
+
+ ServerConfigResponse configResponse = sApi.getConfig();
+ hqAssertSuccess(configResponse);
+
+ ServerConfig c = new ServerConfig();
+ c.setKey("HQ_UNKNOWN_CONFIG");
+ c.setValue("false");
+
+ StatusResponse response = sApi.setConfig(c);
+ hqAssertFailureInvalidParameters(response);
+ }
+
+ public void testSetRestrictedConfig() throws Exception {
+
+ ServerConfigApi sApi = getApi().getServerConfigApi();
+
+ ServerConfigResponse configResponse = sApi.getConfig();
+ hqAssertSuccess(configResponse);
+
+ ServerConfig c = new ServerConfig();
+ c.setKey("CAM_GUIDE_ENABLED");
+ c.setValue("false");
+
+ StatusResponse response = sApi.setConfig(c);
+ hqAssertFailureOperationDenied(response);
+ }
+
public void testSetConfigEmpty() throws Exception {
ServerConfigApi sApi = getApi().getServerConfigApi();
List<ServerConfig> configs = new ArrayList<ServerConfig>();
StatusResponse response = sApi.setConfig(configs);
- // All configs required
+ // At least one config parameter required
hqAssertFailureInvalidParameters(response);
}
View
28 hqapi1-plugin/src/main/groovy/app/ResourceController.groovy
@@ -579,10 +579,6 @@ class ResourceController extends ApiController {
return config.size() == 0;
}
- private generateVSpherePlatformName(name, fqdn) {
- return name + " (" + fqdn + ")"
- }
-
private syncResource(xmlResource, parent) {
def id = xmlResource.'@id'?.toInteger()
@@ -645,19 +641,6 @@ class ResourceController extends ApiController {
def fqdn = xmlResource['ResourceInfo'].find { it.'@key' == PROP_FQDN }
if (fqdn) {
resource = resourceHelper.find('byFqdn':fqdn.'@value')
-
- // Automatically rename vSphere platforms to ensure uniqueness
- if (!resource && prototype.isVSpherePlatformPrototype()) {
- // check to see if the platform name is already used
- def anotherPlatformWithSameName = resourceHelper.find('platform':name)
-
- if (anotherPlatformWithSameName) {
- // rename platform using this convention: name (fqdn)
- def uniqueName = generateVSpherePlatformName(name, fqdn.'@value')
- name = uniqueName
- config.name = uniqueName
- }
- }
} else {
resource = resourceHelper.find('platform':name)
}
@@ -675,17 +658,6 @@ class ResourceController extends ApiController {
config.put(PROP_FQDN, fqdn.'@value')
}
- // Automatically rename vSphere platforms to ensure uniqueness
- if (prototype.isVSpherePlatformPrototype()) {
- def uniqueName = generateVSpherePlatformName(name, fqdn.'@value')
- if (resource.name.equals(uniqueName)) {
- // platform was previously automatically renamed,
- // so keep using that name
- name = uniqueName
- config.name = uniqueName
- }
- }
-
// Add agent info
def xmlAgent = xmlResource['Agent']
if (xmlAgent) {
View
50 hqapi1-plugin/src/main/groovy/app/ServerconfigController.groovy
@@ -6,7 +6,22 @@ import org.hyperic.hq.hqapi1.ErrorCode
class ServerconfigController extends ApiController {
+
private _serverMan = Bootstrap.getBean(ServerConfigManager.class)
+
+
+ private _hiddenProps = ['CAM_SCHEMA_VERSION', 'CAM_SERVER_VERSION',
+ 'CAM_JAAS_PROVIDER', 'CAM_LDAP_NAMING_FACTORY_INITIAL',
+ 'CAM_HELP_USER', 'CAM_HELP_PASSWORD',
+ 'CAM_MULTICAST_ADDRESS', 'CAM_MULTICAST_PORT',
+ 'CAM_SYSLOG_ACTIONS_ENABLED', 'CAM_GUIDE_ENABLED',
+ 'CAM_RT_COLLECT_IP_ADDRS', 'AGENT_BUNDLE_REPOSITORY_DIR',
+ 'CAM_DATA_PURGE_1H', 'CAM_DATA_PURGE_6H',
+ 'CAM_DATA_PURGE_1D', 'RT_DATA_PURGE',
+ 'BATCH_AGGREGATE_BATCHSIZE', 'BATCH_AGGREGATE_QUEUE',
+ 'BATCH_AGGREGATE_WORKERS', 'DATA_STORE_ALL',
+ 'REPORT_STATS_SIZE', 'HQ-GUID']
+
def getConfig(params) {
@@ -20,7 +35,10 @@ class ServerconfigController extends ApiController {
} else {
out << getSuccessXML()
for (key in props.keySet().sort {a, b -> a <=> b}) {
- ServerConfig(key: key, value: props.getProperty(key))
+ // Filter out non-UI server configs
+ if (!_hiddenProps.contains(key)) {
+ ServerConfig(key: key, value: props.getProperty(key))
+ }
}
}
}
@@ -36,14 +54,38 @@ class ServerconfigController extends ApiController {
"User " + user.name + " is not superuser")
} else {
- Properties props = new Properties()
+ Properties props = _serverMan.config
+ def update = false
def postData = new XmlParser().parseText(getPostData())
+
+ // replace current server config props with new values
for (xmlConfig in postData['ServerConfig']) {
- props.put(xmlConfig.'@key', xmlConfig.'@value')
+ def key = xmlConfig.'@key'
+ if (props.containsKey(key)) {
+ if (_hiddenProps.contains(key)) {
+ failureXml = getFailureXML(ErrorCode.OPERATION_DENIED,
+ "Cannot update configuration parameter " + key)
+ break
+ } else {
+ props.put(key, xmlConfig.'@value')
+ update = true
+ }
+ } else {
+ failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS,
+ "Unknown configuration parameter " + key)
+ break
+ }
}
try {
- _serverMan.setConfig(user, props)
+ if (!failureXml) {
+ if (update) {
+ _serverMan.setConfig(user, props)
+ } else {
+ failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS,
+ "No configuration parameters updated")
+ }
+ }
} catch (Exception e) {
failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS,
e.getMessage())
View
18 hqapi1/src/main/java/org/hyperic/hq/hqapi1/ServerConfigApi.java
@@ -6,6 +6,7 @@
import org.hyperic.hq.hqapi1.types.StatusResponse;
import java.io.IOException;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -32,8 +33,21 @@ public ServerConfigResponse getConfig() throws IOException {
}
/**
- * Set the HQ server configuration. The List of ServerConfig's must include
- * all configurations returned from #getConfig.
+ * Set the HQ server configuration.
+ *
+ * @param config A ServerConfig object.
+ *
+ * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if
+ * the server configuration was updated sucessfully.
+ *
+ * @throws IOException If a network error occurs while making the request.
+ */
+ public StatusResponse setConfig(ServerConfig config) throws IOException {
+ return setConfig(Collections.singletonList(config));
+ }
+
+ /**
+ * Set the HQ server configuration.
*
* @param configs An array of ServerConfig objects.
*
View
24 hqapi1/src/main/java/org/hyperic/hq/hqapi1/tools/ServerConfigCommand.java
@@ -133,24 +133,12 @@ private void setParameter(String[] args) throws Exception {
String key = (String)getRequired(options, OPT_KEY);
String value = (String)getRequired(options, OPT_VALUE);
- ServerConfigResponse response = configApi.getConfig();
- checkSuccess(response);
+ ServerConfig config = new ServerConfig();
+ config.setKey(key);
+ config.setValue(value);
- List<ServerConfig> config = response.getServerConfig();
- boolean found = false;
- for (ServerConfig c : config) {
- if (c.getKey().equals(key)) {
- c.setValue(value);
- found = true;
- }
- }
-
- if (!found) {
- System.err.print("Unknown configuration parameter " + key);
- } else {
- StatusResponse setResponse = configApi.setConfig(config);
- checkSuccess(setResponse);
- System.out.println("Successfully updated HQ configuration.");
- }
+ StatusResponse setResponse = configApi.setConfig(config);
+ checkSuccess(setResponse);
+ System.out.println("Successfully updated HQ configuration.");
}
}

0 comments on commit 39ec152

Please sign in to comment.