Skip to content

Commit

Permalink
Begin ServerConfigApi.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Morgan committed Jul 7, 2009
1 parent 4269814 commit 3b57e19
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 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()
}
}
}
}
11 changes: 11 additions & 0 deletions src/org/hyperic/hq/hqapi1/HQApi.java
Expand Up @@ -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.
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
}
50 changes: 50 additions & 0 deletions 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<String, String[]>(),
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<ServerConfig> configs) throws IOException {
ServerConfigRequest request = new ServerConfigRequest();
request.getServerConfig().addAll(configs);
return doPost("serverConfig/setConfig.hqu", request, StatusResponse.class);
}
}
57 changes: 57 additions & 0 deletions 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);
}
}
23 changes: 23 additions & 0 deletions 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);
}
}
31 changes: 31 additions & 0 deletions xsd/HQApi1.xsd
Expand Up @@ -865,4 +865,35 @@
</xs:complexType>
</xs:element>

<!-- Server Config objects -->

<xs:complexType name="ServerConfig">
<xs:attribute name="value" type="xs:string" use="required"/>
<xs:attribute name="key" type="xs:string" use="required"/>
</xs:complexType>

<!-- Server Config Response objects -->

<xs:element name="ServerConfigResponse">
<xs:complexType>
<xs:complexContent>
<xs:extension base="Response">
<xs:sequence>
<xs:element name="ServerConfig" type="ServerConfig" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>

<!-- Server Config Request objects -->

<xs:element name="ServerConfigRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="ServerConfig" maxOccurs="unbounded" type="ServerConfig"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

0 comments on commit 3b57e19

Please sign in to comment.