diff --git a/hqu/hqapi1/app/ServerconfigController.groovy b/hqu/hqapi1/app/ServerconfigController.groovy new file mode 100644 index 00000000..6914fb3e --- /dev/null +++ b/hqu/hqapi1/app/ServerconfigController.groovy @@ -0,0 +1,37 @@ +import org.hyperic.hq.common.server.session.ServerConfigManagerEJBImpl as SMan +import org.hyperic.hq.hqapi1.ErrorCode + +class ServerconfigController extends ApiController { + + private _serverMan = SMan.one + + def getConfig(params) { + + def props = _serverMan.config + + renderXml() { + ServerConfigResponse() { + if (!user.isSuperUser()) { + out << getFailureXML(ErrorCode.PERMISSION_DENIED, + "User " + user.name + " is not superuser") + } else { + out << getSuccessXML() + props.each { k, v -> + ServerConfig(key: k, value: v) + } + } + } + } + } + + def setConfig(params) { + + // TODO: Implement + + renderXml() { + StatusResponse() { + out << getSuccessXML() + } + } + } +} \ No newline at end of file diff --git a/src/org/hyperic/hq/hqapi1/HQApi.java b/src/org/hyperic/hq/hqapi1/HQApi.java index 476b94df..d421579e 100644 --- a/src/org/hyperic/hq/hqapi1/HQApi.java +++ b/src/org/hyperic/hq/hqapi1/HQApi.java @@ -45,6 +45,7 @@ public class HQApi { private final AlertDefinitionApi _alertDefinitionApi; private final MaintenanceApi _maintenanceApi; private final ResourceEdgeApi _resourceEdgeApi; + private final ServerConfigApi _serverConfigApi; /** * @param host The hostname of the HQ Server to connect to. @@ -68,6 +69,7 @@ public HQApi(String host, int port, boolean isSecure, String user, _alertDefinitionApi = new AlertDefinitionApi(connection); _maintenanceApi = new MaintenanceApi(connection); _resourceEdgeApi = new ResourceEdgeApi(connection); + _serverConfigApi = new ServerConfigApi(connection); } /** @@ -169,4 +171,13 @@ public MaintenanceApi getMaintenanceApi() { public ResourceEdgeApi getResourceEdgeApi() { return _resourceEdgeApi; } + + /** + * Manipulate HQ server configuration settings + * + * @return The API for modifying HQ server settings + */ + public ServerConfigApi getServerConfigApi() { + return _serverConfigApi; + } } diff --git a/src/org/hyperic/hq/hqapi1/ServerConfigApi.java b/src/org/hyperic/hq/hqapi1/ServerConfigApi.java new file mode 100644 index 00000000..dc3ac741 --- /dev/null +++ b/src/org/hyperic/hq/hqapi1/ServerConfigApi.java @@ -0,0 +1,50 @@ +package org.hyperic.hq.hqapi1; + +import org.hyperic.hq.hqapi1.types.ServerConfigResponse; +import org.hyperic.hq.hqapi1.types.ServerConfig; +import org.hyperic.hq.hqapi1.types.ServerConfigRequest; +import org.hyperic.hq.hqapi1.types.StatusResponse; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; + +/** + * The Hyperic HQ Server Configuration API. + */ +public class ServerConfigApi extends BaseApi { + + ServerConfigApi(HQConnection conn) { + super(conn); + } + + /** + * Get the HQ server configuration. + * + * @return On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS}, + * a List of {@link org.hyperic.hq.hqapi1.types.ServerConfig}s. + * + * @throws IOException If a network error occurs while making the request. + */ + public ServerConfigResponse getConfig() throws IOException { + return doGet("serverconfig/getConfig.hqu", new HashMap(), + ServerConfigResponse.class); + } + + /** + * Set the HQ server configuration. The List of ServerConfig's must include + * all configurations returned from #getConfig. + * + * @param configs An array of ServerConfig objects. + * + * @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(List configs) throws IOException { + ServerConfigRequest request = new ServerConfigRequest(); + request.getServerConfig().addAll(configs); + return doPost("serverConfig/setConfig.hqu", request, StatusResponse.class); + } +} diff --git a/src/org/hyperic/hq/hqapi1/test/ServerConfigGet_test.java b/src/org/hyperic/hq/hqapi1/test/ServerConfigGet_test.java new file mode 100644 index 00000000..581cc215 --- /dev/null +++ b/src/org/hyperic/hq/hqapi1/test/ServerConfigGet_test.java @@ -0,0 +1,57 @@ +package org.hyperic.hq.hqapi1.test; + +import org.hyperic.hq.hqapi1.ServerConfigApi; +import org.hyperic.hq.hqapi1.HQApi; +import org.hyperic.hq.hqapi1.UserApi; +import org.hyperic.hq.hqapi1.types.ServerConfigResponse; +import org.hyperic.hq.hqapi1.types.User; +import org.hyperic.hq.hqapi1.types.StatusResponse; +import org.hyperic.hq.hqapi1.types.UserResponse; + +import java.util.Random; + +public class ServerConfigGet_test extends HQApiTestBase { + + public ServerConfigGet_test(String name) { + super(name); + } + + public void testGetConfig() throws Exception { + + ServerConfigApi sApi = getApi().getServerConfigApi(); + + ServerConfigResponse response = sApi.getConfig(); + hqAssertSuccess(response); + assertTrue("No server configuration settings found", + response.getServerConfig().size() > 0); + } + + public void testGetConfigInvalidUser() throws Exception { + + HQApi api = getApi(); + UserApi uApi = api.getUserApi(); + + Random r = new Random(); + + User user = new User(); + user.setName("test" + r.nextInt()); + user.setFirstName("Get Server Config"); + user.setLastName("Test User"); + user.setEmailAddress("testuser@springsource.com"); + user.setActive(true); + + UserResponse userCreateResponse = + uApi.createUser(user, "test"); // Create test user w/o Admin + hqAssertSuccess(userCreateResponse); + + ServerConfigApi sApi = getApi(user.getName(), "test").getServerConfigApi(); + + ServerConfigResponse response = sApi.getConfig(); + hqAssertFailurePermissionDenied(response); + + // Cleanup + StatusResponse deleteResponse = + uApi.deleteUser(userCreateResponse.getUser().getId()); + hqAssertSuccess(deleteResponse); + } +} diff --git a/src/org/hyperic/hq/hqapi1/test/ServerConfigSet_test.java b/src/org/hyperic/hq/hqapi1/test/ServerConfigSet_test.java new file mode 100644 index 00000000..14962bd1 --- /dev/null +++ b/src/org/hyperic/hq/hqapi1/test/ServerConfigSet_test.java @@ -0,0 +1,23 @@ +package org.hyperic.hq.hqapi1.test; + +import org.hyperic.hq.hqapi1.ServerConfigApi; +import org.hyperic.hq.hqapi1.types.ServerConfigResponse; +import org.hyperic.hq.hqapi1.types.StatusResponse; + +public class ServerConfigSet_test extends HQApiTestBase { + + public ServerConfigSet_test(String name) { + super(name); + } + + public void testSetConfig() throws Exception { + + ServerConfigApi sApi = getApi().getServerConfigApi(); + + ServerConfigResponse configResponse = sApi.getConfig(); + hqAssertSuccess(configResponse); + + StatusResponse response = sApi.setConfig(configResponse.getServerConfig()); + hqAssertSuccess(response); + } +} diff --git a/xsd/HQApi1.xsd b/xsd/HQApi1.xsd index 46713cf0..3c0a49ff 100644 --- a/xsd/HQApi1.xsd +++ b/xsd/HQApi1.xsd @@ -865,4 +865,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +