Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ryan Morgan
committed
Jul 7, 2009
1 parent
4269814
commit 3b57e19
Showing
6 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters