users = createTestUsers(1);
44 | User unprivUser = users.get(0);
45 | AlertApi apiUnpriv = getApi(unprivUser.getName(), TESTUSER_PASSWORD).getAlertApi();
46 |
47 | StatusResponse deleteResponse = apiUnpriv.delete(a.getId());
48 | hqAssertFailurePermissionDenied(deleteResponse);
49 |
50 | // TODO: Valididate alert was deleted? Will require a getById API.
51 |
52 | // Cleanup
53 | deleteAlertDefinitionByAlert(a);
54 | deleteTestUsers(users);
55 | }
56 |
57 | public void testDeleteInvalidAlert() throws Exception {
58 |
59 | AlertApi api = getAlertApi();
60 |
61 | StatusResponse response = api.delete(Integer.MAX_VALUE);
62 | hqAssertFailureObjectNotFound(response);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/hqapi1-plugin/src/main/resources/views/api/index.gsp:
--------------------------------------------------------------------------------
1 |
4 |
5 | <%
6 | def version = plugin.descriptor.get('plugin.version')
7 | def clientPackageName = "hqapi1-client-" + version
8 | def clientPackageTgz = clientPackageName + ".tar.gz"
9 | def clientPackageZip = clientPackageName + ".zip"
10 | def clientPackageTgzUrl = "/" + urlFor(asset:clientPackageTgz)
11 | def clientPackageZipUrl = "/" + urlFor(asset:clientPackageZip)
12 | %>
13 |
14 | Hyperic HQ API Version ${version}
15 |
16 | This page provides resources and documentation for the Hyperic HQ API.
17 |
18 | Client Download
19 |
27 |
28 | Requires a Java JRE 1.5 or newer
29 |
30 | Quick Help
31 |
32 | HQ Api provides a java client with a command line wrapper. To utilize HQ Api please download the
33 | client package above and extract it to your local filesystem. It is not required to install HQ Api
34 | on the Hyperic server.
35 |
36 |
Once downloaded it is recommended to setup a ~/.hq/client.properties or conf/client.properties file
37 | to contain the Hyperic server connection properties. Example contents of this file are
38 |
39 |
40 | host=localhost
41 | port=7080
42 | user=hqadmin
43 | password=hqadmin
44 |
45 |
46 | Current method statistics
47 |
48 |
49 |
50 |
51 | | Method | Total Calls | Min Time | Max Time | Total Time |
52 |
53 | <%
54 | stats.each { k, v ->
55 | %>
56 |
57 | | ${k} | ${v.calls} | ${v.minTime} | ${v.maxTime} | ${v.totalTime} |
58 |
59 | <%
60 | }
61 | %>
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/hqapi1-client/src/main/assembly/assembly.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | tar.gz
5 | zip
6 |
7 |
8 |
9 |
10 | src/main/resources
11 | /
12 |
13 | **/*.sh
14 |
15 | 0644
16 | 0755
17 |
18 |
19 | src/main/resources
20 | /
21 |
22 | **/*.sh
23 |
24 | 0755
25 | 0755
26 |
27 |
28 | ../hqapi1/src/main
29 | /
30 |
31 | **/*.xsd
32 | **/*.wadl
33 |
34 | 0644
35 | 0755
36 |
37 |
38 |
39 |
40 |
41 | false
42 | /
43 | false
44 |
45 | *:javadoc
46 |
47 | 0644
48 | 0755
49 |
50 |
51 | false
52 | /javadoc
53 | false
54 | true
55 |
56 |
57 | **/META-INF/**
58 | **/resources/**
59 |
60 |
61 |
62 | *:javadoc
63 |
64 | 0644
65 | 0755
66 |
67 |
68 |
69 | false
70 | /lib
71 |
72 | org.hyperic.hq.hqapi:*
73 |
74 | 0644
75 | 0755
76 |
77 |
78 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/AgentGetAgents_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.AgentApi;
31 | import org.hyperic.hq.hqapi1.types.Agent;
32 | import org.hyperic.hq.hqapi1.types.AgentsResponse;
33 |
34 | import java.util.List;
35 |
36 | public class AgentGetAgents_test extends HQApiTestBase {
37 |
38 | public AgentGetAgents_test(String name) {
39 | super(name);
40 | }
41 |
42 | public void testGetAllAgents() throws Exception {
43 |
44 | AgentApi api = getApi().getAgentApi();
45 |
46 | AgentsResponse response = api.getAgents();
47 | hqAssertSuccess(response);
48 |
49 | List agents = response.getAgent();
50 | if (agents.size() == 0) {
51 | getLog().warn("Agent listing returned 0 results. Test results " +
52 | "may not be accurate.");
53 | }
54 |
55 | for (Agent a : agents) {
56 | assertTrue(a.getAddress().length() > 0);
57 | assertTrue(a.getPort() > 0 || a.getPort() == -1);
58 | assertTrue(a.getVersion().length() > 0);
59 | assertTrue(a.getId() > 0);
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/AgentTransferPlugin_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2010], VMware, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.AgentApi;
31 | import org.hyperic.hq.hqapi1.types.Agent;
32 | import org.hyperic.hq.hqapi1.types.StatusResponse;
33 |
34 | public class AgentTransferPlugin_test extends HQApiTestBase {
35 |
36 | public AgentTransferPlugin_test(String name) {
37 | super(name);
38 | }
39 |
40 | public void testInvalidAgent() throws Exception {
41 |
42 | AgentApi api = getApi().getAgentApi();
43 |
44 | Agent a = new Agent();
45 | a.setId(Integer.MAX_VALUE);
46 | StatusResponse response = api.transferPlugin(a, "system-plugin.jar");
47 | hqAssertFailureObjectNotFound(response);
48 | }
49 |
50 | public void testInvalidPlugin() throws Exception {
51 |
52 | AgentApi api = getApi().getAgentApi();
53 |
54 | Agent a = getRunningAgent();
55 | StatusResponse response = api.transferPlugin(a, "foo-plugin.jar");
56 | hqAssertFailureInvalidParameters(response);
57 | }
58 |
59 | // Cannot really test a valid plugin as the agent restart would cause
60 | // other tests to fail.. maybe a transfer/sleep/ping?
61 | }
62 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/UserTestBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.UserApi;
31 | import org.hyperic.hq.hqapi1.types.User;
32 | import org.hyperic.hq.hqapi1.types.UserResponse;
33 | import org.hyperic.hq.hqapi1.types.UsersResponse;
34 |
35 | import java.util.ArrayList;
36 | import java.util.List;
37 | import java.util.Random;
38 |
39 | public abstract class UserTestBase extends HQApiTestBase {
40 |
41 | public UserTestBase(String name) {
42 | super(name);
43 | }
44 |
45 | UserApi getUserApi() {
46 | return getApi().getUserApi();
47 | }
48 |
49 | UserApi getUserApi(String user, String password) {
50 | return getApi(user, password).getUserApi();
51 | }
52 |
53 | /**
54 | * Clean up test users after each test run.
55 | */
56 | public void tearDown() throws Exception {
57 |
58 | UserApi api = getUserApi();
59 | UsersResponse response = api.getUsers();
60 |
61 | for (User u : response.getUser()) {
62 | if (u.getName().startsWith(TESTUSER_NAME_PREFIX)) {
63 | api.deleteUser(u.getId());
64 | }
65 | }
66 |
67 | super.tearDown();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/hqapi1-tools/src/main/java/tools/PasswordField.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Adapted from Sun's password masking exaples:
3 | * http://java.sun.com/developer/technicalArticles/Security/pwordmask/
4 | */
5 | package org.hyperic.hq.hqapi1.tools;
6 |
7 | import java.io.InputStream;
8 | import java.io.IOException;
9 | import java.io.PushbackInputStream;
10 | import java.util.Arrays;
11 |
12 | /**
13 | * This class prompts the user for a password and attempts to mask input with "*"
14 | */
15 | public class PasswordField {
16 |
17 | /**
18 | *@param in stream to be used (e.g. System.in)
19 | *@param prompt The prompt to display to the user.
20 | *@return The password as entered by the user.
21 | */
22 | public static char[] getPassword(InputStream in, String prompt) throws IOException {
23 | MaskingThread maskingthread = new MaskingThread(prompt);
24 | Thread thread = new Thread(maskingthread);
25 | thread.start();
26 |
27 | char[] lineBuffer;
28 | char[] buf;
29 |
30 | buf = lineBuffer = new char[128];
31 |
32 | int room = buf.length;
33 | int offset = 0;
34 | int c;
35 |
36 | loop: while (true) {
37 | switch (c = in.read()) {
38 | case -1:
39 | case '\n':
40 | break loop;
41 |
42 | case '\r':
43 | int c2 = in.read();
44 | if ((c2 != '\n') && (c2 != -1)) {
45 | if (!(in instanceof PushbackInputStream)) {
46 | in = new PushbackInputStream(in);
47 | }
48 | ((PushbackInputStream)in).unread(c2);
49 | } else {
50 | break loop;
51 | }
52 |
53 | default:
54 | if (--room < 0) {
55 | buf = new char[offset + 128];
56 | room = buf.length - offset - 1;
57 | System.arraycopy(lineBuffer, 0, buf, 0, offset);
58 | Arrays.fill(lineBuffer, ' ');
59 | lineBuffer = buf;
60 | }
61 | buf[offset++] = (char) c;
62 | break;
63 | }
64 | }
65 | maskingthread.stopMasking();
66 | if (offset == 0) {
67 | return null;
68 | }
69 | char[] ret = new char[offset];
70 | System.arraycopy(buf, 0, ret, 0, offset);
71 | Arrays.fill(buf, ' ');
72 | return ret;
73 | }
74 | }
75 |
76 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/WADLAlertDefinition_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.wadl.*;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public class WADLAlertDefinition_test extends WADLTestBase {
9 |
10 | public void testListDefinitions() throws Exception {
11 | HttpLocalhost8080HquHqapi1.AlertdefinitionListDefinitionsHqu adList =
12 | new HttpLocalhost8080HquHqapi1.AlertdefinitionListDefinitionsHqu();
13 |
14 | AlertDefinitionsResponse response = adList.getAsAlertDefinitionsResponse();
15 | hqAssertSuccess(response);
16 | }
17 |
18 | public void testListDefinitionsByResources() throws Exception {
19 | HttpLocalhost8080HquHqapi1.AlertdefinitionListDefinitionsByResourcesHqu adList =
20 | new HttpLocalhost8080HquHqapi1.AlertdefinitionListDefinitionsByResourcesHqu();
21 | List resources = new ArrayList();
22 | ResourcesRequest request = new ResourcesRequest();
23 | request.getResource().addAll(resources);
24 | AlertDefinitionsResponse response = adList.postApplicationXmlAsAlertDefinitionsResponse(request);
25 | hqAssertSuccess(response);
26 | }
27 |
28 | public void testListTypeDefinitions() throws Exception {
29 | HttpLocalhost8080HquHqapi1.AlertdefinitionListTypeDefinitionsHqu adTypeList =
30 | new HttpLocalhost8080HquHqapi1.AlertdefinitionListTypeDefinitionsHqu();
31 |
32 | AlertDefinitionsResponse response = adTypeList.getAsAlertDefinitionsResponse();
33 | hqAssertSuccess(response);
34 | }
35 |
36 | public void testDelete() throws Exception {
37 | HttpLocalhost8080HquHqapi1.AlertdefinitionDeleteHqu adDelete =
38 | new HttpLocalhost8080HquHqapi1.AlertdefinitionDeleteHqu();
39 |
40 | StatusResponse response = adDelete.getAsStatusResponse(Integer.MAX_VALUE);
41 | hqAssertFailure(response); // Won't exist.
42 | }
43 |
44 | public void testSync() throws Exception {
45 | HttpLocalhost8080HquHqapi1.AlertdefinitionSyncHqu adSync =
46 | new HttpLocalhost8080HquHqapi1.AlertdefinitionSyncHqu();
47 | AlertDefinitionsRequest request = new AlertDefinitionsRequest();
48 |
49 | AlertDefinitionsResponse response = adSync.postApplicationXmlAsAlertDefinitionsResponse(request);
50 | hqAssertSuccess(response);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/AlertDefinitionGetByResources_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.AlertDefinitionApi;
4 | import org.hyperic.hq.hqapi1.HQApi;
5 | import org.hyperic.hq.hqapi1.ResourceApi;
6 | import org.hyperic.hq.hqapi1.types.AlertDefinitionsResponse;
7 | import org.hyperic.hq.hqapi1.types.Resource;
8 | import org.hyperic.hq.hqapi1.types.ResourcePrototypeResponse;
9 | import org.hyperic.hq.hqapi1.types.ResourcesResponse;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | public class AlertDefinitionGetByResources_test extends AlertDefinitionTestBase {
15 |
16 | public AlertDefinitionGetByResources_test(String name) {
17 | super(name);
18 | }
19 |
20 | public void testFindAlertDefinitions() throws Exception {
21 |
22 | HQApi api = getApi();
23 | ResourceApi rApi = api.getResourceApi();
24 | AlertDefinitionApi dApi = api.getAlertDefinitionApi();
25 |
26 | ResourcePrototypeResponse protoResponse =
27 | rApi.getResourcePrototype("CPU");
28 | hqAssertSuccess(protoResponse);
29 |
30 | ResourcesResponse resourcesResponse =
31 | rApi.getResources(protoResponse.getResourcePrototype(),
32 | false, false);
33 | hqAssertSuccess(resourcesResponse);
34 |
35 | AlertDefinitionsResponse response =
36 | dApi.getAlertDefinitions(resourcesResponse.getResource());
37 | hqAssertSuccess(response);
38 | }
39 |
40 | public void testFindAlertDefinitionsEmptyList() throws Exception {
41 |
42 | HQApi api = getApi();
43 | AlertDefinitionApi dApi = api.getAlertDefinitionApi();
44 |
45 | List resources = new ArrayList();
46 |
47 | AlertDefinitionsResponse response = dApi.getAlertDefinitions(resources);
48 | hqAssertSuccess(response);
49 | }
50 |
51 | public void testFindAlertDefinitionsInvalidResource() throws Exception {
52 |
53 | HQApi api = getApi();
54 | AlertDefinitionApi dApi = api.getAlertDefinitionApi();
55 |
56 | List resources = new ArrayList();
57 | Resource r = new Resource();
58 | r.setId(Integer.MAX_VALUE);
59 | r.setName("Invalid resource");
60 | resources.add(r);
61 |
62 | AlertDefinitionsResponse response =
63 | dApi.getAlertDefinitions(resources);
64 | hqAssertFailureObjectNotFound(response);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/WADLTestBase.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import junit.framework.TestCase;
4 |
5 | import org.hyperic.hq.hqapi1.wadl.*;
6 |
7 | import java.io.File;
8 | import java.io.FileInputStream;
9 | import java.io.IOException;
10 | import java.net.Authenticator;
11 | import java.net.PasswordAuthentication;
12 | import java.util.Properties;
13 |
14 | public abstract class WADLTestBase extends TestCase {
15 |
16 | private Properties getClientProperties() {
17 | Properties props = new Properties();
18 |
19 | String home = System.getProperty("user.home");
20 | File hq = new File(home, ".hq");
21 | File clientProperties = new File(hq, "client.properties");
22 |
23 | if (clientProperties.exists()) {
24 | FileInputStream fis = null;
25 | props = new Properties();
26 | try {
27 | fis = new FileInputStream(clientProperties);
28 | props.load(fis);
29 | } catch (IOException e) {
30 | return props;
31 | } finally {
32 | try {
33 | if (fis != null) {
34 | fis.close();
35 | }
36 | } catch (IOException ioe) {
37 | // Ignore
38 | }
39 | }
40 | }
41 | return props;
42 | }
43 |
44 | public void setUp() throws Exception {
45 | Properties props = getClientProperties();
46 |
47 | final String username = props.getProperty("user", "hqadmin");
48 | final String password = props.getProperty("password", "hqadmin");
49 |
50 | Authenticator.setDefault(new Authenticator() {
51 | protected PasswordAuthentication getPasswordAuthentication() {
52 | return new PasswordAuthentication (username, password.toCharArray());
53 | }
54 | });
55 | }
56 |
57 | // Assert SUCCESS
58 |
59 | void hqAssertSuccess(Response response) {
60 | String error = (response.getError() != null) ?
61 | response.getError().getReasonText() : "";
62 | assertEquals(error, ResponseStatus.SUCCESS, response.getStatus());
63 | }
64 |
65 | // Assert FAILURE
66 | void hqAssertFailure(Response response) {
67 | String error = (response.getError() != null) ?
68 | response.getError().getReasonText() : "";
69 | assertEquals(error, ResponseStatus.FAILURE, response.getStatus());
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/hqapi1/src/main/java/org/hyperic/hq/hqapi1/ServerConfigApi.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1;
2 |
3 | import org.hyperic.hq.hqapi1.types.ServerConfigResponse;
4 | import org.hyperic.hq.hqapi1.types.ServerConfig;
5 | import org.hyperic.hq.hqapi1.types.ServerConfigRequest;
6 | import org.hyperic.hq.hqapi1.types.StatusResponse;
7 |
8 | import java.io.IOException;
9 | import java.util.Collections;
10 | import java.util.HashMap;
11 | import java.util.List;
12 |
13 | /**
14 | * The Hyperic HQ Server Configuration API.
15 | */
16 | public class ServerConfigApi extends BaseApi {
17 |
18 | ServerConfigApi(HQConnection conn) {
19 | super(conn);
20 | }
21 |
22 | /**
23 | * Get the HQ server configuration.
24 | *
25 | * @return On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
26 | * a List of {@link org.hyperic.hq.hqapi1.types.ServerConfig}s.
27 | *
28 | * @throws IOException If a network error occurs while making the request.
29 | */
30 | public ServerConfigResponse getConfig() throws IOException {
31 | return doGet("serverconfig/getConfig.hqu", new HashMap(),
32 | new XmlResponseHandler(ServerConfigResponse.class));
33 | }
34 |
35 | /**
36 | * Set the HQ server configuration.
37 | *
38 | * @param config A ServerConfig object.
39 | *
40 | * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if
41 | * the server configuration was updated sucessfully.
42 | *
43 | * @throws IOException If a network error occurs while making the request.
44 | */
45 | public StatusResponse setConfig(ServerConfig config) throws IOException {
46 | return setConfig(Collections.singletonList(config));
47 | }
48 |
49 | /**
50 | * Set the HQ server configuration.
51 | *
52 | * @param configs An array of ServerConfig objects.
53 | *
54 | * @return {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS} if
55 | * the server configuration was updated sucessfully.
56 | *
57 | * @throws IOException If a network error occurs while making the request.
58 | */
59 | public StatusResponse setConfig(List configs) throws IOException {
60 | ServerConfigRequest request = new ServerConfigRequest();
61 | request.getServerConfig().addAll(configs);
62 | return doPost("serverConfig/setConfig.hqu", request,
63 | new XmlResponseHandler(StatusResponse.class));
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/WADLControl_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.wadl.*;
31 |
32 | public class WADLControl_test extends WADLTestBase {
33 |
34 | public void testActions() throws Exception {
35 | HttpLocalhost8080HquHqapi1.ControlActionsHqu actions =
36 | new HttpLocalhost8080HquHqapi1.ControlActionsHqu();
37 |
38 | ControlActionResponse response =
39 | actions.getAsControlActionResponse(Integer.MAX_VALUE);
40 | hqAssertFailure(response); // Id won't exist
41 | }
42 |
43 | public void testHistory() throws Exception {
44 | HttpLocalhost8080HquHqapi1.ControlHistoryHqu history =
45 | new HttpLocalhost8080HquHqapi1.ControlHistoryHqu();
46 |
47 | ControlHistoryResponse response =
48 | history.getAsControlHistoryResponse(Integer.MAX_VALUE);
49 | hqAssertFailure(response); // Id won't exist
50 | }
51 |
52 | public void testExecute() throws Exception {
53 | HttpLocalhost8080HquHqapi1.ControlExecuteHqu execute =
54 | new HttpLocalhost8080HquHqapi1.ControlExecuteHqu();
55 |
56 | StatusResponse response =
57 | execute.getAsStatusResponse(Integer.MAX_VALUE, "none",
58 | null);
59 | hqAssertFailure(response); // Id won't exist
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/SpinBarrier.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 |
4 |
5 | /**
6 | * Utility that continuosly evaluates a specified condition at specified retry
7 | * intervals, until either the condition is true or the specified timeout is
8 | * reached. This utility can be used, for example, by test classes that need to
9 | * verify the completion of some asynchronous task. It is expected that most
10 | * instrumentation tests will use this class to verify that performance monitors
11 | * have been asynchronously updated
12 | *
13 | * @author Jennifer Hickey
14 | *
15 | */
16 | public class SpinBarrier {
17 | private long timeout = 120000l;
18 | private long retryInterval = 250l;
19 | private final SpinBarrierCondition condition;
20 |
21 | /**
22 | * Constructor that uses the default timeout and retry interval
23 | *
24 | * @param condition
25 | * The condition to evaluate
26 | */
27 | public SpinBarrier(SpinBarrierCondition condition) {
28 | this.condition = condition;
29 | }
30 |
31 | /**
32 | *
33 | * @param timeout
34 | * The amount of time, in milliseconds, to continue evaluating
35 | * the condition if it has not been met
36 | * @param retryInterval
37 | * The amount of time to wait between evaluations of the
38 | * condition
39 | * @param condition
40 | * The condition to evaluate
41 | */
42 | public SpinBarrier(long timeout, long retryInterval, SpinBarrierCondition condition) {
43 | this.timeout = timeout;
44 | this.retryInterval = retryInterval;
45 | this.condition = condition;
46 | }
47 |
48 | /**
49 | * Evaluates a specified condition at specified retry intervals, until
50 | * either the condition is true or the specified timeout is reached
51 | *
52 | * @return true if the condition evaluated to true before the timeout was
53 | * reached
54 | */
55 | public boolean waitFor() {
56 | final long startTime = System.currentTimeMillis();
57 | boolean conditionMet = false;
58 | while (!(conditionMet) && (System.currentTimeMillis() < (startTime + timeout))) {
59 | conditionMet = condition.evaluate();
60 | if (conditionMet) {
61 | continue;
62 | }
63 | try {
64 | Thread.sleep(retryInterval);
65 | } catch (InterruptedException e) {
66 | // Ignore
67 | }
68 | }
69 | return conditionMet;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/UserGetUser_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.UserApi;
31 | import org.hyperic.hq.hqapi1.types.UserResponse;
32 |
33 | public class UserGetUser_test extends UserTestBase {
34 |
35 | public UserGetUser_test(String name) {
36 | super(name);
37 | }
38 |
39 | public void testGetUserValid() throws Exception {
40 | UserApi api = getUserApi();
41 | UserResponse response = api.getUser("hqadmin");
42 |
43 | hqAssertSuccess(response);
44 | assertEquals("HQ", response.getUser().getFirstName());
45 | assertEquals("Administrator", response.getUser().getLastName());
46 | }
47 |
48 | public void testGetUserInvalid() throws Exception {
49 | UserApi api = getUserApi();
50 | UserResponse response = api.getUser("unknownUser");
51 |
52 | hqAssertFailureObjectNotFound(response);
53 | }
54 |
55 | public void testGetUserById() throws Exception {
56 | UserApi api = getUserApi();
57 | UserResponse response = api.getUser(1);
58 |
59 | hqAssertSuccess(response);
60 | assertEquals("HQ", response.getUser().getFirstName());
61 | assertEquals("Administrator", response.getUser().getLastName());
62 | }
63 |
64 | public void testGetUserByIdInvalid() throws Exception {
65 | UserApi api = getUserApi();
66 | UserResponse response = api.getUser(Integer.MAX_VALUE);
67 |
68 | hqAssertFailureObjectNotFound(response);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/WADLMetricData_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.wadl.*;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | public class WADLMetricData_test extends WADLTestBase {
9 |
10 | public void testGet() throws Exception {
11 | HttpLocalhost8080HquHqapi1.MetricDataGetHqu get = new HttpLocalhost8080HquHqapi1.MetricDataGetHqu();
12 |
13 | MetricDataResponse response =
14 | get.getAsMetricDataResponse(Integer.MAX_VALUE,
15 | 0l, System.currentTimeMillis());
16 | hqAssertFailure(response);
17 | }
18 |
19 | public void testGetLast() throws Exception {
20 | HttpLocalhost8080HquHqapi1.MetricDataGetLastHqu last = new HttpLocalhost8080HquHqapi1.MetricDataGetLastHqu();
21 |
22 | LastMetricDataResponse response =
23 | last.getAsLastMetricDataResponse(Integer.MAX_VALUE);
24 | hqAssertFailure(response);
25 | }
26 |
27 | public void testGetMulti() throws Exception {
28 | HttpLocalhost8080HquHqapi1.MetricDataGetMultiHqu multi = new HttpLocalhost8080HquHqapi1.MetricDataGetMultiHqu();
29 |
30 | List ids = new ArrayList();
31 | ids.add(0);
32 | ids.add(2);
33 | MetricsDataResponse response =
34 | multi.getAsMetricsDataResponse(ids, 0l,
35 | System.currentTimeMillis());
36 | hqAssertFailure(response);
37 |
38 | }
39 |
40 | public void testGetMultiLast() throws Exception {
41 | HttpLocalhost8080HquHqapi1.MetricDataGetMultiLastHqu multiLast =
42 | new HttpLocalhost8080HquHqapi1.MetricDataGetMultiLastHqu();
43 |
44 | List ids = new ArrayList();
45 | ids.add(0);
46 | ids.add(2);
47 |
48 | LastMetricsDataResponse response =
49 | multiLast.getAsLastMetricsDataResponse(ids);
50 | hqAssertFailure(response);
51 | }
52 |
53 | public void testPut() throws Exception {
54 | HttpLocalhost8080HquHqapi1.MetricDataPutHqu put = new HttpLocalhost8080HquHqapi1.MetricDataPutHqu();
55 |
56 | List dps = new ArrayList();
57 | DataPoint dp = new DataPoint();
58 | dp.setTimestamp(System.currentTimeMillis());
59 | dp.setValue(0);
60 | dps.add(dp);
61 |
62 | DataPointsRequest request = new DataPointsRequest();
63 | request.setMetricId(Integer.MAX_VALUE);
64 | request.getDataPoint().addAll(dps);
65 |
66 | StatusResponse response = put.postApplicationXmlAsStatusResponse(request);
67 | hqAssertFailure(response);
68 | }
69 | }
70 |
71 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/MetricDataGet_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.MetricDataApi;
4 | import org.hyperic.hq.hqapi1.MetricApi;
5 | import org.hyperic.hq.hqapi1.types.MetricsResponse;
6 | import org.hyperic.hq.hqapi1.types.Resource;
7 | import org.hyperic.hq.hqapi1.types.Metric;
8 | import org.hyperic.hq.hqapi1.types.MetricDataResponse;
9 |
10 | public class MetricDataGet_test extends MetricDataTestBase {
11 |
12 | public MetricDataGet_test(String name) {
13 | super(name);
14 | }
15 |
16 | public void testValidGet() throws Exception {
17 |
18 | MetricApi api = getApi().getMetricApi();
19 | MetricDataApi dataApi = getApi().getMetricDataApi();
20 |
21 | Resource platform = getLocalPlatformResource(false, false);
22 | MetricsResponse metricsResponse = api.getMetrics(platform, true);
23 | hqAssertSuccess(metricsResponse);
24 | assertTrue("No metrics found for " + platform.getName(),
25 | metricsResponse.getMetric().size() > 0);
26 |
27 | Metric m = metricsResponse.getMetric().get(0);
28 |
29 | long end = System.currentTimeMillis();
30 | long start = end - (8 * 60 * 60 * 1000);
31 | MetricDataResponse dataResponse = dataApi.getData(m, start, end);
32 | hqAssertSuccess(dataResponse);
33 |
34 | validateMetricData(dataResponse.getMetricData());
35 | }
36 |
37 | public void testGetInvalidMetricId() throws Exception {
38 |
39 | MetricDataApi dataApi = getApi().getMetricDataApi();
40 |
41 | Metric m = new Metric();
42 | m.setId(Integer.MAX_VALUE);
43 |
44 | long end = System.currentTimeMillis();
45 | long start = end - (8 * 60 * 60 * 1000);
46 | MetricDataResponse dataResponse = dataApi.getData(m, start, end);
47 | hqAssertFailureObjectNotFound(dataResponse);
48 | }
49 |
50 | public void testGetInvalidRange() throws Exception {
51 |
52 | MetricApi api = getApi().getMetricApi();
53 | MetricDataApi dataApi = getApi().getMetricDataApi();
54 |
55 | Resource platform = getLocalPlatformResource(false, false);
56 | MetricsResponse metricsResponse = api.getMetrics(platform, true);
57 | hqAssertSuccess(metricsResponse);
58 | assertTrue("No metrics found for " + platform.getName(),
59 | metricsResponse.getMetric().size() > 0);
60 |
61 | Metric m = metricsResponse.getMetric().get(0);
62 |
63 | long end = System.currentTimeMillis();
64 | long start = end - (8 * 60 * 60 * 1000);
65 | MetricDataResponse dataResponse = dataApi.getData(m, end, start);
66 | hqAssertFailureInvalidParameters(dataResponse);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/UserDelete_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.UserApi;
31 | import org.hyperic.hq.hqapi1.types.StatusResponse;
32 | import org.hyperic.hq.hqapi1.types.User;
33 | import org.hyperic.hq.hqapi1.types.UserResponse;
34 |
35 | public class UserDelete_test extends UserTestBase {
36 |
37 | public UserDelete_test(String name) {
38 | super(name);
39 | }
40 |
41 | public void testCreateDelete() throws Exception {
42 |
43 | UserApi api = getUserApi();
44 |
45 | User user = generateTestUser();
46 |
47 | // Create the user
48 | UserResponse createResponse = api.createUser(user, TESTUSER_PASSWORD);
49 | hqAssertSuccess(createResponse);
50 |
51 | // Assert the new user exists
52 | UserResponse getResponse = api.getUser(user.getName());
53 | hqAssertSuccess(getResponse);
54 |
55 | // Delete the user that was just created.
56 | StatusResponse deleteResponse =
57 | api.deleteUser(getResponse.getUser().getId());
58 | hqAssertSuccess(deleteResponse);
59 |
60 | // Assert that user is no longer available
61 | UserResponse getResponse2 = api.getUser(user.getName());
62 | hqAssertFailureObjectNotFound(getResponse2);
63 |
64 | // Assert a second delete of this user results in failure
65 | StatusResponse deleteResponse2 =
66 | api.deleteUser(getResponse.getUser().getId());
67 | hqAssertFailureObjectNotFound(deleteResponse2);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/hqapi1/src/main/java/org/hyperic/hq/hqapi1/BaseApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1;
29 |
30 | import java.io.IOException;
31 | import java.util.Map;
32 |
33 | abstract class BaseApi {
34 | private static final String BASE_URI = "/hqu/hqapi1/";
35 |
36 | private final HQConnection _conn;
37 |
38 | BaseApi(HQConnection conn) {
39 | _conn = conn;
40 | }
41 |
42 | /**
43 | * Issue a GET for the specified controller/action.
44 | *
45 | * @param action The name of the controller/action to GET from. This is
46 | * appended on to the BASE_URI and results in a path like
47 | * '/hqu/hqapi1/user/listUsers.hqu'
48 | * @param params A map parameters to pass to the action. Each HTTP
49 | * parameter may have multiple values.
50 | */
51 | T doGet(String action, Map params,
52 | ResponseHandler responseHandler)
53 | throws IOException
54 | {
55 | return _conn.doGet(BASE_URI + action, params, responseHandler);
56 | }
57 |
58 | /**
59 | * Issue a POST for the specified controller/action.
60 | *
61 | * @param action The name of the controller/action to POST to. This is
62 | * tacked on to the BASE_URI and results in a path
63 | * like: '/hqu/hqapi1/user/syncUsers.hqu'
64 | * ex: 'resource/syncResources.hqu'
65 | */
66 | T doPost(String action, Object o, ResponseHandler responseHandler)
67 | throws IOException
68 | {
69 | return _conn.doPost(BASE_URI + action, o, responseHandler);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/EscalationTestBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.EscalationApi;
31 | import org.hyperic.hq.hqapi1.types.Escalation;
32 | import org.hyperic.hq.hqapi1.types.StatusResponse;
33 |
34 | import java.io.IOException;
35 | import java.util.List;
36 | import java.util.Random;
37 |
38 | public abstract class EscalationTestBase extends HQApiTestBase {
39 |
40 | public EscalationTestBase(String name) {
41 | super(name);
42 | }
43 |
44 | protected EscalationApi getEscalationApi() {
45 | return getApi().getEscalationApi();
46 | }
47 |
48 | protected Escalation generateEscalation() {
49 | Random r = new Random();
50 | Escalation e = new Escalation();
51 | e.setName("Api Test Escalation" + r.nextInt());
52 | e.setDescription("Api Test Description");
53 | e.setMaxPauseTime(600000);
54 | e.setNotifyAll(true);
55 | e.setPauseAllowed(true);
56 |
57 | return e;
58 | }
59 |
60 | protected void cleanup(Escalation e) throws IOException {
61 | EscalationApi api = getEscalationApi();
62 | StatusResponse response = api.deleteEscalation(e.getId());
63 | hqAssertSuccess(response);
64 | }
65 |
66 | protected void cleanup(List escalations) throws Exception {
67 | EscalationApi api = getEscalationApi();
68 |
69 | for (Escalation e : escalations) {
70 | StatusResponse response = api.deleteEscalation(e.getId());
71 | hqAssertSuccess(response);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/GroupDelete_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.GroupApi;
31 | import org.hyperic.hq.hqapi1.types.Group;
32 | import org.hyperic.hq.hqapi1.types.GroupResponse;
33 | import org.hyperic.hq.hqapi1.types.StatusResponse;
34 |
35 | public class GroupDelete_test extends GroupTestBase {
36 |
37 | public GroupDelete_test(String name) {
38 | super(name);
39 | }
40 |
41 | public void testDeleteInvalidId() throws Exception {
42 | GroupApi api = getApi().getGroupApi();
43 |
44 | StatusResponse resp = api.deleteGroup(Integer.MAX_VALUE);
45 | hqAssertFailureObjectNotFound(resp);
46 | }
47 |
48 | public void testDelete() throws Exception {
49 |
50 | GroupApi groupApi = getApi().getGroupApi();
51 |
52 | Group g = generateTestGroup();
53 |
54 | GroupResponse response = groupApi.createGroup(g);
55 | hqAssertSuccess(response);
56 |
57 | GroupResponse groupResponse = groupApi.getGroup(g.getName());
58 | hqAssertSuccess(groupResponse);
59 |
60 | Group createdGroup = groupResponse.getGroup();
61 | validateGroup(groupResponse.getGroup());
62 |
63 | StatusResponse deleteResponse = groupApi.deleteGroup(createdGroup.getId());
64 | hqAssertSuccess(deleteResponse);
65 | }
66 |
67 | public void testDeleteSystemGroup() throws Exception {
68 |
69 | GroupApi groupApi = getApi().getGroupApi();
70 |
71 | StatusResponse deleteResponse = groupApi.deleteGroup(0);
72 | hqAssertFailureNotSupported(deleteResponse);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/InvalidLogin_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.UserApi;
31 | import org.hyperic.hq.hqapi1.types.UsersResponse;
32 |
33 | public class InvalidLogin_test extends HQApiTestBase {
34 |
35 | public InvalidLogin_test(String name) {
36 | super(name);
37 | }
38 |
39 | public void testInvalidLogin() throws Exception {
40 |
41 | UserApi api = getApi("invalidUser", "invalidPassword").getUserApi();
42 | UsersResponse response = api.getUsers();
43 |
44 | hqAssertFailureLoginFailure(response);
45 | }
46 |
47 | public void testNullUsername() throws Exception {
48 |
49 | UserApi api = getApi(null, "invalidPassword").getUserApi();
50 | UsersResponse response = api.getUsers();
51 |
52 | hqAssertFailureLoginFailure(response);
53 | }
54 |
55 | public void testNullPassword() throws Exception {
56 |
57 | UserApi api = getApi("invalidUser", null).getUserApi();
58 | UsersResponse response = api.getUsers();
59 |
60 | hqAssertFailureLoginFailure(response);
61 | }
62 |
63 | public void testEmptyUsername() throws Exception {
64 |
65 | UserApi api = getApi("", "invalidPassword").getUserApi();
66 | UsersResponse response = api.getUsers();
67 |
68 | hqAssertFailureLoginFailure(response);
69 | }
70 |
71 | public void testEmptyPassword() throws Exception {
72 |
73 | UserApi api = getApi("hqadmin", "").getUserApi();
74 | UsersResponse response = api.getUsers();
75 |
76 | hqAssertFailureLoginFailure(response);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/hqapi1-tools/src/main/java/tools/OptionParserFactory.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2009 SpringSource Inc. All Rights Reserved. */
2 | package org.hyperic.hq.hqapi1.tools;
3 |
4 | import java.util.Arrays;
5 |
6 | import org.springframework.beans.factory.FactoryBean;
7 |
8 | import joptsimple.OptionParser;
9 |
10 | /**
11 | * Factory responsible for generating {@link OptionParser}s and initializing
12 | * with command line options accepted by all commands (i.e. connection
13 | * parameters and help)
14 | *
15 | * @author Jennifer Hickey
16 | *
17 | */
18 | public class OptionParserFactory implements FactoryBean {
19 | static final String OPT_HOST = "host";
20 | static final String OPT_PORT = "port";
21 | static final String OPT_PORT_SSL = "portSSL";
22 | static final String OPT_PORT_DEFAULTED = "portDefaulted";
23 | static final String OPT_USER = "user";
24 | static final String OPT_PASS = "password";
25 | static final String OPT_ENCRYPTEDPASSWORD = "encryptedPassword";
26 | static final String OPT_ENCRYPTIONKEY = "encryptionKey";
27 | static final String[] OPT_SECURE = {"s", "secure"};
28 | public static final String[] OPT_HELP = {"h","help"};
29 | public static final String SYSTEM_PROP_PREFIX = "scripting.client.";
30 | static final String OPT_FILE = "file";
31 | static final String OPT_PROPERTIES = "properties";
32 |
33 | public OptionParser getObject() throws Exception {
34 |
35 | OptionParser parser = new OptionParser();
36 |
37 | parser.accepts(OPT_HOST, "The HQ server host").
38 | withRequiredArg().ofType(String.class);
39 | parser.accepts(OPT_PORT, "The HQ server port. Defaults to 7080").
40 | withOptionalArg().ofType(Integer.class);
41 | parser.accepts(OPT_USER, "The user to connect as").
42 | withRequiredArg().ofType(String.class);
43 | parser.accepts(OPT_PASS, "The password for the given user").
44 | withRequiredArg().ofType(String.class);
45 |
46 | parser.acceptsAll(Arrays.asList(OPT_SECURE), "Connect using SSL");
47 | parser.acceptsAll(Arrays.asList(OPT_HELP), "Show this message");
48 | parser.accepts(OPT_FILE, "If specified, use the given file for " +
49 | "commands that take XML input. If " +
50 | "not specified, stdin will be used.").
51 | withRequiredArg().ofType(String.class);
52 |
53 | parser.accepts(OPT_PROPERTIES, "Specify the file to read for connection " +
54 | "properties. Defaults to ~/.hq/client.properties")
55 | .withRequiredArg().ofType(String.class);
56 |
57 | return parser;
58 | }
59 |
60 | public Class getObjectType() {
61 | return OptionParser.class;
62 | }
63 |
64 | public boolean isSingleton() {
65 | return false;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/ResourceMove_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.ResourceApi;
31 | import org.hyperic.hq.hqapi1.types.StatusResponse;
32 | import org.hyperic.hq.hqapi1.types.Resource;
33 |
34 | import java.util.List;
35 |
36 | public class ResourceMove_test extends ResourceTestBase {
37 |
38 | public ResourceMove_test(String name) {
39 | super(name);
40 | }
41 |
42 | public void testResourceMoveInvalidResources() throws Exception {
43 |
44 | ResourceApi api = getApi().getResourceApi();
45 |
46 | Resource target = new Resource();
47 | target.setId(Integer.MAX_VALUE);
48 |
49 | Resource destination = new Resource();
50 | destination.setId(Integer.MAX_VALUE);
51 |
52 | StatusResponse response = api.moveResource(target, destination);
53 | hqAssertFailureObjectNotFound(response);
54 |
55 | }
56 |
57 | public void testResourceMoveIncompatibleResources() throws Exception {
58 |
59 | ResourceApi api = getApi().getResourceApi();
60 | Resource platform = getLocalPlatformResource(false, true);
61 |
62 | List servers = platform.getResource();
63 |
64 | assertTrue("More than 2 servers not found for platform " + platform.getName(),
65 | servers.size() >= 2);
66 |
67 | Resource r1 = servers.get(0);
68 | Resource r2 = servers.get(1);
69 |
70 | // Attempt move of one server into another
71 |
72 | StatusResponse response = api.moveResource(r1, r2);
73 | hqAssertFailureInvalidParameters(response);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/ResourceGetPrototype_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.ResourceApi;
31 | import org.hyperic.hq.hqapi1.types.ResourcePrototype;
32 | import org.hyperic.hq.hqapi1.types.ResourcePrototypeResponse;
33 |
34 | public class ResourceGetPrototype_test extends HQApiTestBase {
35 |
36 | public ResourceGetPrototype_test(String name) {
37 | super(name);
38 | }
39 |
40 | public void testGetValidResourcePrototype() throws Exception {
41 |
42 | ResourceApi api = getApi().getResourceApi();
43 |
44 | final String TYPE = "Linux";
45 | ResourcePrototypeResponse response = api.getResourcePrototype(TYPE);
46 | hqAssertSuccess(response);
47 |
48 | ResourcePrototype type = response.getResourcePrototype();
49 | assertNotNull("Requested prototype " + TYPE + " was null", type);
50 | assertTrue("Requested prototype id " + type.getId() + " invalid",
51 | type.getId() > 10000);
52 | assertEquals(TYPE, type.getName());
53 | }
54 |
55 | public void testGetInvalidResourcePrototype() throws Exception {
56 |
57 | ResourceApi api = getApi().getResourceApi();
58 |
59 | final String TYPE = "Some unknown type";
60 | ResourcePrototypeResponse response = api.getResourcePrototype(TYPE);
61 | hqAssertFailureObjectNotFound(response);
62 | }
63 |
64 | public void testGetNullPrototype() throws Exception {
65 |
66 | ResourceApi api = getApi().getResourceApi();
67 |
68 | ResourcePrototypeResponse response = api.getResourcePrototype(null);
69 | hqAssertFailureInvalidParameters(response);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/SNMPv3InformTestBase.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.HQApi;
4 | import org.hyperic.hq.hqapi1.EscalationActionBuilder;
5 | import org.hyperic.hq.hqapi1.ServerConfigApi;
6 | import org.hyperic.hq.hqapi1.types.Alert;
7 | import org.hyperic.hq.hqapi1.types.AlertActionLog;
8 | import org.hyperic.hq.hqapi1.types.AlertDefinition;
9 | import org.hyperic.hq.hqapi1.types.AlertsResponse;
10 | import org.hyperic.hq.hqapi1.types.Escalation;
11 | import org.hyperic.hq.hqapi1.types.EscalationAction;
12 | import org.hyperic.hq.hqapi1.types.ServerConfigResponse;
13 | import org.hyperic.hq.hqapi1.types.StatusResponse;
14 | import org.hyperic.hq.hqapi1.types.ServerConfig;
15 | import org.hyperic.hq.hqapi1.types.Resource;
16 |
17 | import java.io.IOException;
18 | import java.util.ArrayList;
19 | import java.util.Collections;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 |
24 | public class SNMPv3InformTestBase extends SNMPTestBase {
25 |
26 | public SNMPv3InformTestBase(String name) {
27 | super(name);
28 | }
29 |
30 | public String getProtocolVersion() {
31 | return "3";
32 | }
33 |
34 | /**
35 | * Validate alert action logs
36 | */
37 | public void validateAlertActionLogs(String user,
38 | List actionLogs) {
39 |
40 | assertTrue("At least one alert action log is needed",
41 | !actionLogs.isEmpty());
42 |
43 | String logDetail = actionLogs.get(0).getDetail();
44 | System.out.println(logDetail);
45 |
46 | if (user.length() == 0) {
47 | // empty string user means a "no security name" test case
48 | assertTrue("The HQ server settings should have no SNMP Security Name",
49 | logDetail.indexOf("Security Name required") > -1);
50 | } else if (user.equals(INVALID_SECURITY_NAME)) {
51 | assertTrue("The HQ server settings should have an invalid SNMP Security Name",
52 | logDetail.indexOf("Unknown user name") > -1);
53 | } else {
54 | // non-empty string user means a "valid security name" test case
55 | // and the value should be a valid user who can send INFORM notifications
56 | assertTrue("INFORM notification was not sent",
57 | logDetail.indexOf("INFORM sent") > -1);
58 |
59 | // validate variable bindings
60 | assertTrue("sysUpTime is missing",
61 | logDetail.indexOf("1.3.6.1.2.1.1.3") > 0);
62 |
63 | assertTrue("snmpTrapOID is missing",
64 | logDetail.indexOf("1.3.6.1.6.3.1.1.4.1") > 0);
65 |
66 | // TODO: Need to validate user defined variable bindings
67 |
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/MetricDataGetLast_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.MetricApi;
4 | import org.hyperic.hq.hqapi1.MetricDataApi;
5 | import org.hyperic.hq.hqapi1.types.Resource;
6 | import org.hyperic.hq.hqapi1.types.MetricsResponse;
7 | import org.hyperic.hq.hqapi1.types.Metric;
8 | import org.hyperic.hq.hqapi1.types.LastMetricDataResponse;
9 |
10 | import java.util.List;
11 | import java.util.Iterator;
12 |
13 | public class MetricDataGetLast_test extends MetricDataTestBase {
14 |
15 | public MetricDataGetLast_test(String name) {
16 | super(name);
17 | }
18 |
19 | public void testValidGet() throws Exception {
20 | MetricApi api = getApi().getMetricApi();
21 | MetricDataApi dataApi = getApi().getMetricDataApi();
22 |
23 | Resource platform = getLocalPlatformResource(false, false);
24 | MetricsResponse metricsResponse = api.getMetrics(platform, true);
25 | hqAssertSuccess(metricsResponse);
26 | assertTrue("No metrics found for " + platform.getName(),
27 | metricsResponse.getMetric().size() > 0);
28 |
29 | Metric m = metricsResponse.getMetric().get(0);
30 |
31 | LastMetricDataResponse dataResponse = dataApi.getData(m);
32 | hqAssertSuccess(dataResponse);
33 |
34 | validateLastMetricData(dataResponse.getLastMetricData());
35 | }
36 |
37 | public void testGetInvalidMetricId() throws Exception {
38 | MetricDataApi dataApi = getApi().getMetricDataApi();
39 | Metric m = new Metric();
40 | m.setId(Integer.MAX_VALUE);
41 | LastMetricDataResponse dataResponse = dataApi.getData(m);
42 | hqAssertFailureObjectNotFound(dataResponse);
43 | }
44 |
45 | public void testGetLastNoData() throws Exception {
46 |
47 | MetricApi api = getApi().getMetricApi();
48 | MetricDataApi dataApi = getApi().getMetricDataApi();
49 |
50 | Resource platform = getLocalPlatformResource(false, false);
51 | MetricsResponse metricsResponse = api.getMetrics(platform, false);
52 | hqAssertSuccess(metricsResponse);
53 | assertTrue("No metrics found for " + platform.getName(),
54 | metricsResponse.getMetric().size() > 0);
55 |
56 | Metric metric = null;
57 | for (Metric m : metricsResponse.getMetric()) {
58 | if (!m.isEnabled()) {
59 | metric = m;
60 | }
61 | }
62 |
63 | assertNotNull("No disabled metric could be found", metric);
64 |
65 | LastMetricDataResponse dataResponse = dataApi.getData(metric);
66 | hqAssertSuccess(dataResponse);
67 | // TODO: What is the correct behavior of the API if the last data point
68 | // could not be found? Return an error for simply null?
69 | assertNull("Metric datapoint not null",
70 | dataResponse.getLastMetricData().getDataPoint());
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/EscalationGetEscalation_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.EscalationApi;
31 | import org.hyperic.hq.hqapi1.EscalationActionBuilder;
32 | import org.hyperic.hq.hqapi1.types.Escalation;
33 | import org.hyperic.hq.hqapi1.types.EscalationResponse;
34 |
35 | public class EscalationGetEscalation_test extends EscalationTestBase {
36 |
37 | public EscalationGetEscalation_test(String name) {
38 | super(name);
39 | }
40 |
41 | public void testGetEscalationById() throws Exception {
42 |
43 | EscalationApi escApi = getEscalationApi();
44 |
45 | Escalation e = generateEscalation();
46 | e.getAction().add(EscalationActionBuilder.createNoOpAction(1000));
47 |
48 | EscalationResponse response = escApi.createEscalation(e);
49 | hqAssertSuccess(response);
50 |
51 | // Look up escalation by id
52 | response = escApi.getEscalation(response.getEscalation().getId());
53 | hqAssertSuccess(response);
54 |
55 | // Cleanup
56 | cleanup(response.getEscalation());
57 | }
58 |
59 | public void testGetEscalationByName() throws Exception {
60 |
61 | EscalationApi escApi = getEscalationApi();
62 |
63 | Escalation e = generateEscalation();
64 | e.getAction().add(EscalationActionBuilder.createNoOpAction(1000));
65 |
66 | EscalationResponse response = escApi.createEscalation(e);
67 | hqAssertSuccess(response);
68 |
69 | // Look up escalation by id
70 | response = escApi.getEscalation(response.getEscalation().getName());
71 | hqAssertSuccess(response);
72 |
73 | // Cleanup
74 | cleanup(response.getEscalation());
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/AgentPing_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.AgentApi;
31 | import org.hyperic.hq.hqapi1.UserApi;
32 | import org.hyperic.hq.hqapi1.types.Agent;
33 | import org.hyperic.hq.hqapi1.types.PingAgentResponse;
34 | import org.hyperic.hq.hqapi1.types.User;
35 | import org.hyperic.hq.hqapi1.types.UserResponse;
36 |
37 | public class AgentPing_test extends UserTestBase {
38 |
39 | public AgentPing_test(String name) {
40 | super(name);
41 | }
42 |
43 | public void testPingInvalidAgent() throws Exception {
44 |
45 | AgentApi api = getApi().getAgentApi();
46 |
47 | Agent a = new Agent();
48 | a.setId(Integer.MAX_VALUE);
49 | PingAgentResponse response = api.pingAgent(a);
50 | hqAssertFailureObjectNotFound(response);
51 | }
52 |
53 | public void testPingValidAgent() throws Exception {
54 |
55 | AgentApi api = getApi().getAgentApi();
56 |
57 | Agent a = getRunningAgent();
58 |
59 | PingAgentResponse response = api.pingAgent(a);
60 | hqAssertSuccess(response);
61 | }
62 |
63 | public void testPingValidAgentUserNoPermission() throws Exception {
64 |
65 | UserApi userApi = getUserApi();
66 |
67 | User user = generateTestUser();
68 |
69 | UserResponse createResponse = userApi.createUser(user, TESTUSER_PASSWORD);
70 | hqAssertSuccess(createResponse);
71 |
72 | // reconnect as the new user
73 | AgentApi agentApi = getApi(user.getName(), TESTUSER_PASSWORD).getAgentApi();
74 |
75 | Agent a = getRunningAgent();
76 |
77 | PingAgentResponse pingResponse = agentApi.pingAgent(a);
78 | hqAssertFailurePermissionDenied(pingResponse);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/ResourceEdgeDelete_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import java.util.List;
31 |
32 | import org.hyperic.hq.hqapi1.ResourceEdgeApi;
33 | import org.hyperic.hq.hqapi1.types.Resource;
34 | import org.hyperic.hq.hqapi1.types.ResourcesResponse;
35 | import org.hyperic.hq.hqapi1.types.StatusResponse;
36 |
37 | public class ResourceEdgeDelete_test extends ResourceTestBase {
38 |
39 | public ResourceEdgeDelete_test(String name) {
40 | super(name);
41 | }
42 |
43 | public void testDeleteInvalidId() throws Exception {
44 | ResourceEdgeApi api = getApi().getResourceEdgeApi();
45 | StatusResponse response = api.deleteResourceEdges("network", Integer.MAX_VALUE);
46 | hqAssertFailureObjectNotFound(response);
47 | }
48 |
49 | public void testDeleteInvalidRelation() throws Exception {
50 | ResourceEdgeApi api = getApi().getResourceEdgeApi();
51 | StatusResponse response = api.deleteResourceEdges("invalid", Integer.MAX_VALUE);
52 | hqAssertFailureInvalidParameters(response);
53 | }
54 |
55 | public void testDelete() throws Exception {
56 | ResourceEdgeApi api = getApi().getResourceEdgeApi();
57 |
58 | // get top-level resources not associated with a network hierarchy
59 | ResourcesResponse resourcesResponse = api.getParentResourcesByRelation("network", null, null, false);
60 | List resources = resourcesResponse.getResource();
61 |
62 | if (!resources.isEmpty()) {
63 | // test delete using a top-level resource not associated with a network hierarchy
64 | Resource r = (Resource) resources.get(0);
65 | StatusResponse response = api.deleteResourceEdges("network", r.getId());
66 | hqAssertSuccess(response);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/ResourceListPrototypes_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.ResourceApi;
31 | import org.hyperic.hq.hqapi1.types.ResourcePrototype;
32 | import org.hyperic.hq.hqapi1.types.ResourcePrototypesResponse;
33 |
34 | public class ResourceListPrototypes_test extends HQApiTestBase {
35 |
36 | public ResourceListPrototypes_test(String name) {
37 | super(name);
38 | }
39 |
40 | public void testListAllPrototypes() throws Exception {
41 | ResourceApi api = getApi().getResourceApi();
42 |
43 | ResourcePrototypesResponse resp = api.getAllResourcePrototypes();
44 |
45 | hqAssertSuccess(resp);
46 | assertTrue(resp.getResourcePrototype().size() != 0);
47 |
48 | for (ResourcePrototype pt : resp.getResourcePrototype()) {
49 | assertTrue(pt.getId() > 0);
50 | assertTrue(pt.getName() != null && pt.getName().length() > 0);
51 | }
52 | }
53 |
54 | public void testListPrototypes() throws Exception {
55 | ResourceApi api = getApi().getResourceApi();
56 |
57 | ResourcePrototypesResponse allResponse = api.getAllResourcePrototypes();
58 | hqAssertSuccess(allResponse);
59 |
60 | ResourcePrototypesResponse response = api.getResourcePrototypes();
61 | hqAssertSuccess(response);
62 |
63 | assertTrue("All prototypes not greater than existing prototypes " +
64 | "all=" + allResponse.getResourcePrototype().size() +
65 | " existing=" + response.getResourcePrototype().size(),
66 | allResponse.getResourcePrototype().size() >
67 | response.getResourcePrototype().size());
68 |
69 | assertTrue("Existing prototypes not > 1",
70 | response.getResourcePrototype().size() > 1);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/hqapi1/src/main/java/org/hyperic/hq/hqapi1/XmlUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1;
29 |
30 | import javax.xml.bind.JAXBContext;
31 | import javax.xml.bind.JAXBException;
32 | import javax.xml.bind.Marshaller;
33 | import javax.xml.bind.Unmarshaller;
34 | import javax.xml.bind.helpers.DefaultValidationEventHandler;
35 | import java.io.InputStream;
36 | import java.io.OutputStream;
37 | import java.util.HashMap;
38 | import java.util.Map;
39 |
40 | /**
41 | * Utility class to convert Java objects to XML and vice versa.
42 | */
43 | public class XmlUtil {
44 |
45 | private static Map _ctxMap =
46 | new HashMap();
47 |
48 | private static synchronized JAXBContext getCachedContext(String pkg) throws JAXBException {
49 | JAXBContext ctx = _ctxMap.get(pkg);
50 | if (ctx == null) {
51 | ctx = JAXBContext.newInstance(pkg);
52 | _ctxMap.put(pkg, ctx);
53 | }
54 | return ctx;
55 | }
56 |
57 | public static T deserialize(Class res, InputStream is)
58 | throws JAXBException
59 | {
60 | String pkg = res.getPackage().getName();
61 | JAXBContext jc = getCachedContext(pkg);
62 | Unmarshaller u = jc.createUnmarshaller();
63 | u.setEventHandler(new DefaultValidationEventHandler());
64 | return res.cast(u.unmarshal(is));
65 | }
66 |
67 | public static void serialize(Object o, OutputStream os, Boolean format)
68 | throws JAXBException
69 | {
70 | String pkg = o.getClass().getPackage().getName();
71 | JAXBContext jc = getCachedContext(pkg);
72 | Marshaller m = jc.createMarshaller();
73 | m.setEventHandler(new DefaultValidationEventHandler());
74 | m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, format);
75 | m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
76 | m.marshal(o, os);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/SNMPv1Trap_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.HQApi;
4 | import org.hyperic.hq.hqapi1.EscalationActionBuilder;
5 | import org.hyperic.hq.hqapi1.ServerConfigApi;
6 | import org.hyperic.hq.hqapi1.types.Alert;
7 | import org.hyperic.hq.hqapi1.types.AlertActionLog;
8 | import org.hyperic.hq.hqapi1.types.AlertDefinition;
9 | import org.hyperic.hq.hqapi1.types.AlertsResponse;
10 | import org.hyperic.hq.hqapi1.types.Escalation;
11 | import org.hyperic.hq.hqapi1.types.EscalationAction;
12 | import org.hyperic.hq.hqapi1.types.ServerConfigResponse;
13 | import org.hyperic.hq.hqapi1.types.StatusResponse;
14 | import org.hyperic.hq.hqapi1.types.ServerConfig;
15 | import org.hyperic.hq.hqapi1.types.Resource;
16 |
17 | import java.io.IOException;
18 | import java.util.ArrayList;
19 | import java.util.Collections;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 |
24 | public class SNMPv1Trap_test extends SNMPTestBase {
25 |
26 | public SNMPv1Trap_test(String name) {
27 | super(name);
28 | }
29 |
30 | public String getProtocolVersion() {
31 | return "1";
32 | }
33 |
34 | // TODO: ResourceType Alert Definitions
35 |
36 | public void testSendVarbinds() throws Exception {
37 | testSendNotification(
38 | getProtocolVersion(),
39 | "v1 Trap",
40 | getCommunity(),
41 | getVariableBindings());
42 | }
43 |
44 | public void testSendVarBindsInvalidCommunity() throws Exception {
45 | testSendNotification(
46 | getProtocolVersion(),
47 | "v1 Trap",
48 | INVALID_COMMUNITY,
49 | getVariableBindings());
50 | }
51 |
52 | public void testSendNoVarbinds() throws Exception {
53 | testSendNotification(
54 | getProtocolVersion(),
55 | "v1 Trap",
56 | getCommunity(),
57 | "");
58 | }
59 |
60 | public void testSendNoVarbindsInvalidCommunity() throws Exception {
61 | testSendNotification(
62 | getProtocolVersion(),
63 | "v1 Trap",
64 | INVALID_COMMUNITY,
65 | "");
66 | }
67 |
68 | public void testSendInvalidVarbinds() throws Exception {
69 | testSendNotification(
70 | getProtocolVersion(),
71 | "v1 Trap",
72 | getCommunity(),
73 | INVALID_VARIABLE_BINDINGS);
74 | }
75 |
76 | /**
77 | * Validate alert action logs
78 | */
79 | public void validateAlertActionLogs(String user,
80 | List actionLogs) {
81 |
82 | assertTrue("At least one alert action log is needed",
83 | !actionLogs.isEmpty());
84 |
85 | String logDetail = actionLogs.get(0).getDetail();
86 | System.out.println(logDetail);
87 |
88 | assertTrue("TRAP notification was not sent",
89 | logDetail.indexOf("V1TRAP sent successfully") > -1);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/ApplicationTestBase.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.types.Application;
4 | import org.hyperic.hq.hqapi1.types.ApplicationResponse;
5 | import org.hyperic.hq.hqapi1.types.Resource;
6 | import org.hyperic.hq.hqapi1.ApplicationApi;
7 |
8 | import java.util.Random;
9 | import java.util.List;
10 |
11 | public abstract class ApplicationTestBase extends HQApiTestBase {
12 |
13 | static final String UPDATE_PREFIX = "UPDATED-";
14 |
15 | protected static final String APP_NAME = "Test Application";
16 | protected static final String APP_LOCATION = "SFO";
17 | protected static final String APP_DESC = "Test Application Description";
18 | protected static final String APP_ENG_CONTACT = "415-555-5555";
19 | protected static final String APP_BIZ_CONTACT = "212-555-5555";
20 | protected static final String APP_OPS_CONTACT = "510-555-5555";
21 |
22 | static final String GROUP_NAME = "API Test Group";
23 | static final String GROUP_LOCATION = "API Test Group Location";
24 | static final String GROUP_DESCRIPTION = "API Test Group Description";
25 |
26 | public ApplicationTestBase(String name) {
27 | super(name);
28 | }
29 |
30 | protected Application generateTestApplication()
31 | throws Exception {
32 |
33 | Random r = new Random();
34 | Application a = new Application();
35 |
36 | String name = APP_NAME + r.nextInt();
37 | a.setName(name);
38 | a.setLocation(APP_LOCATION);
39 | a.setDescription(APP_DESC);
40 | a.setEngContact(APP_ENG_CONTACT);
41 | a.setBizContact(APP_BIZ_CONTACT);
42 | a.setOpsContact(APP_OPS_CONTACT);
43 |
44 | return a;
45 | }
46 |
47 | /**
48 | * Create an Application with no groups or services associated.
49 | *
50 | * @param services A list of Resources to add to the Application or null
51 | * if no Resources should be added.
52 | * Groups should be added.
53 | * @return The created Application
54 | * @throws Exception If an error occurs.
55 | */
56 | protected Application createTestApplication(List services)
57 | throws Exception
58 | {
59 | ApplicationApi api = getApi().getApplicationApi();
60 | Application a = generateTestApplication();
61 |
62 | if (services != null) {
63 | a.getResource().addAll(services);
64 | }
65 |
66 | ApplicationResponse response = api.createApplication(a);
67 | hqAssertSuccess(response);
68 |
69 | Application createdApp = response.getApplication();
70 |
71 | assertNotNull("Application id was null!", createdApp.getId());
72 | assertEquals(createdApp.getName(), a.getName());
73 | assertEquals(createdApp.getLocation(), APP_LOCATION);
74 | assertEquals(createdApp.getDescription(), APP_DESC);
75 | assertEquals(createdApp.getEngContact(), APP_ENG_CONTACT);
76 | assertEquals(createdApp.getBizContact(), APP_BIZ_CONTACT);
77 | assertEquals(createdApp.getOpsContact(), APP_OPS_CONTACT);
78 |
79 | return response.getApplication();
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/hqapi1-plugin/src/main/groovy/app/AutodiscoveryController.groovy:
--------------------------------------------------------------------------------
1 |
2 | import org.hyperic.hq.hqapi1.ErrorCode;
3 |
4 | class AutodiscoveryController extends ApiController {
5 |
6 | private Closure getAIPlatformXML(p) {
7 | { doc ->
8 | AIPlatform(id : p.id,
9 | name : p.name,
10 | fqdn : p.fqdn) {
11 | p.getAIServerValues().each { s ->
12 | AIServer(id : s.id,
13 | name : s.name)
14 | }
15 | }
16 | }
17 | }
18 |
19 | def getQueue(params) {
20 | def failureXml
21 | def list
22 | try {
23 | list = autodiscoveryHelper.getQueue()
24 | } catch (Exception e) {
25 | log.error("UnexpectedError: " + e.getMessage(), e);
26 | failureXml = getFailureXML(ErrorCode.UNEXPECTED_ERROR)
27 | }
28 |
29 | renderXml() {
30 | out << QueueResponse() {
31 | if (failureXml) {
32 | out << failureXml
33 | } else {
34 | out << getSuccessXML()
35 | for (platform in list.sort {a, b -> a.name <=> b.name}) {
36 | out << getAIPlatformXML(platform)
37 | }
38 | }
39 | }
40 | }
41 | }
42 |
43 | def approve(params) {
44 | def id = params.getOne('id')?.toInteger()
45 | def serverId = params.getOne('serverId')?.toInteger()
46 |
47 | def failureXml
48 | if (id) {
49 | try {
50 | def plat = autodiscoveryHelper.findById(id)
51 | if (!plat) {
52 | failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
53 | "Platform " + id + " not found")
54 | } else {
55 | autodiscoveryHelper.approve(plat)
56 | }
57 | } catch (Exception e) {
58 | log.error("UnexpectedError: " + e.getMessage(), e);
59 | failureXml = getFailureXML(ErrorCode.UNEXPECTED_ERROR)
60 | }
61 | } else if (serverId) {
62 | try {
63 | def server = autodiscoveryHelper.findServerById(serverId)
64 | if (!server) {
65 | failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
66 | "Server " + serverId + " not found")
67 | } else {
68 | autodiscoveryHelper.approve(server)
69 | }
70 | } catch (Exception e) {
71 | log.error("UnexpectedError: " + e.getMessage(), e);
72 | failureXml = getFailureXML(ErrorCode.UNEXPECTED_ERROR)
73 | }
74 | } else {
75 | failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS)
76 | }
77 |
78 | renderXml() {
79 | out << StatusResponse() {
80 | if (failureXml) {
81 | out << failureXml
82 | } else {
83 | out << getSuccessXML()
84 | }
85 | }
86 | }
87 | }
88 | }
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/SNMPv3InformAuthPriv_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.HQApi;
4 | import org.hyperic.hq.hqapi1.EscalationActionBuilder;
5 | import org.hyperic.hq.hqapi1.ServerConfigApi;
6 | import org.hyperic.hq.hqapi1.types.Alert;
7 | import org.hyperic.hq.hqapi1.types.AlertActionLog;
8 | import org.hyperic.hq.hqapi1.types.AlertDefinition;
9 | import org.hyperic.hq.hqapi1.types.AlertsResponse;
10 | import org.hyperic.hq.hqapi1.types.Escalation;
11 | import org.hyperic.hq.hqapi1.types.EscalationAction;
12 | import org.hyperic.hq.hqapi1.types.ServerConfigResponse;
13 | import org.hyperic.hq.hqapi1.types.StatusResponse;
14 | import org.hyperic.hq.hqapi1.types.ServerConfig;
15 | import org.hyperic.hq.hqapi1.types.Resource;
16 |
17 | import java.io.IOException;
18 | import java.util.ArrayList;
19 | import java.util.Collections;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 |
24 | public class SNMPv3InformAuthPriv_test extends SNMPv3InformTestBase {
25 |
26 | public SNMPv3InformAuthPriv_test(String name) {
27 | super(name);
28 | }
29 |
30 | // TODO: ResourceType Alert Definitions
31 |
32 | public void testSendVarbinds() throws Exception {
33 | testSendNotification(
34 | getProtocolVersion(),
35 | "Inform",
36 | getSecurityName(),
37 | true, true,
38 | getVariableBindings());
39 | }
40 |
41 | public void testSendVarBindsNoUser() throws Exception {
42 | testSendNotification(
43 | getProtocolVersion(),
44 | "Inform",
45 | "",
46 | true, true,
47 | getVariableBindings());
48 | }
49 |
50 | public void testSendVarBindsInvalidUser() throws Exception {
51 | testSendNotification(
52 | getProtocolVersion(),
53 | "Inform",
54 | INVALID_SECURITY_NAME,
55 | true, true,
56 | getVariableBindings());
57 | }
58 |
59 | public void testSendNoVarbinds() throws Exception {
60 | testSendNotification(
61 | getProtocolVersion(),
62 | "Inform",
63 | getSecurityName(),
64 | true, true,
65 | "");
66 | }
67 |
68 | public void testSendNoVarbindsNoUser() throws Exception {
69 | testSendNotification(
70 | getProtocolVersion(),
71 | "Inform",
72 | "",
73 | true, true,
74 | "");
75 | }
76 |
77 | public void testSendNoVarbindsInvalidUser() throws Exception {
78 | testSendNotification(
79 | getProtocolVersion(),
80 | "Inform",
81 | INVALID_SECURITY_NAME,
82 | true, true,
83 | "");
84 | }
85 |
86 | public void testSendInvalidVarbinds() throws Exception {
87 | testSendNotification(
88 | getProtocolVersion(),
89 | "Inform",
90 | getSecurityName(),
91 | true, true,
92 | INVALID_VARIABLE_BINDINGS);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/SNMPv3InformAuthNoPriv_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.HQApi;
4 | import org.hyperic.hq.hqapi1.EscalationActionBuilder;
5 | import org.hyperic.hq.hqapi1.ServerConfigApi;
6 | import org.hyperic.hq.hqapi1.types.Alert;
7 | import org.hyperic.hq.hqapi1.types.AlertActionLog;
8 | import org.hyperic.hq.hqapi1.types.AlertDefinition;
9 | import org.hyperic.hq.hqapi1.types.AlertsResponse;
10 | import org.hyperic.hq.hqapi1.types.Escalation;
11 | import org.hyperic.hq.hqapi1.types.EscalationAction;
12 | import org.hyperic.hq.hqapi1.types.ServerConfigResponse;
13 | import org.hyperic.hq.hqapi1.types.StatusResponse;
14 | import org.hyperic.hq.hqapi1.types.ServerConfig;
15 | import org.hyperic.hq.hqapi1.types.Resource;
16 |
17 | import java.io.IOException;
18 | import java.util.ArrayList;
19 | import java.util.Collections;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 |
24 | public class SNMPv3InformAuthNoPriv_test extends SNMPv3InformTestBase {
25 |
26 | public SNMPv3InformAuthNoPriv_test(String name) {
27 | super(name);
28 | }
29 |
30 | // TODO: ResourceType Alert Definitions
31 |
32 | public void testSendVarbinds() throws Exception {
33 | testSendNotification(
34 | getProtocolVersion(),
35 | "Inform",
36 | getSecurityName(),
37 | true, false,
38 | getVariableBindings());
39 | }
40 |
41 | public void testSendVarBindsNoUser() throws Exception {
42 | testSendNotification(
43 | getProtocolVersion(),
44 | "Inform",
45 | "",
46 | true, false,
47 | getVariableBindings());
48 | }
49 |
50 | public void testSendVarBindsInvalidUser() throws Exception {
51 | testSendNotification(
52 | getProtocolVersion(),
53 | "Inform",
54 | INVALID_SECURITY_NAME,
55 | true, false,
56 | getVariableBindings());
57 | }
58 |
59 | public void testSendNoVarbinds() throws Exception {
60 | testSendNotification(
61 | getProtocolVersion(),
62 | "Inform",
63 | getSecurityName(),
64 | true, false,
65 | "");
66 | }
67 |
68 | public void testSendNoVarbindsNoUser() throws Exception {
69 | testSendNotification(
70 | getProtocolVersion(),
71 | "Inform",
72 | "",
73 | true, false,
74 | "");
75 | }
76 |
77 | public void testSendNoVarbindsInvalidUser() throws Exception {
78 | testSendNotification(
79 | getProtocolVersion(),
80 | "Inform",
81 | INVALID_SECURITY_NAME,
82 | true, false,
83 | "");
84 | }
85 |
86 | public void testSendInvalidVarbinds() throws Exception {
87 | testSendNotification(
88 | getProtocolVersion(),
89 | "Inform",
90 | getSecurityName(),
91 | true, false,
92 | INVALID_VARIABLE_BINDINGS);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/SNMPv3InformNoAuthNoPriv_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.HQApi;
4 | import org.hyperic.hq.hqapi1.EscalationActionBuilder;
5 | import org.hyperic.hq.hqapi1.ServerConfigApi;
6 | import org.hyperic.hq.hqapi1.types.Alert;
7 | import org.hyperic.hq.hqapi1.types.AlertActionLog;
8 | import org.hyperic.hq.hqapi1.types.AlertDefinition;
9 | import org.hyperic.hq.hqapi1.types.AlertsResponse;
10 | import org.hyperic.hq.hqapi1.types.Escalation;
11 | import org.hyperic.hq.hqapi1.types.EscalationAction;
12 | import org.hyperic.hq.hqapi1.types.ServerConfigResponse;
13 | import org.hyperic.hq.hqapi1.types.StatusResponse;
14 | import org.hyperic.hq.hqapi1.types.ServerConfig;
15 | import org.hyperic.hq.hqapi1.types.Resource;
16 |
17 | import java.io.IOException;
18 | import java.util.ArrayList;
19 | import java.util.Collections;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 |
24 | public class SNMPv3InformNoAuthNoPriv_test extends SNMPv3InformTestBase {
25 |
26 | public SNMPv3InformNoAuthNoPriv_test(String name) {
27 | super(name);
28 | }
29 |
30 | // TODO: ResourceType Alert Definitions
31 |
32 | public void testSendVarbinds() throws Exception {
33 | testSendNotification(
34 | getProtocolVersion(),
35 | "Inform",
36 | getSecurityName(),
37 | false, false,
38 | getVariableBindings());
39 | }
40 |
41 | public void testSendVarBindsNoUser() throws Exception {
42 | testSendNotification(
43 | getProtocolVersion(),
44 | "Inform",
45 | "",
46 | false, false,
47 | getVariableBindings());
48 | }
49 |
50 | public void testSendVarBindsInvalidUser() throws Exception {
51 | testSendNotification(
52 | getProtocolVersion(),
53 | "Inform",
54 | INVALID_SECURITY_NAME,
55 | false, false,
56 | getVariableBindings());
57 | }
58 |
59 | public void testSendNoVarbinds() throws Exception {
60 | testSendNotification(
61 | getProtocolVersion(),
62 | "Inform",
63 | getSecurityName(),
64 | false, false,
65 | "");
66 | }
67 |
68 | public void testSendNoVarbindsNoUser() throws Exception {
69 | testSendNotification(
70 | getProtocolVersion(),
71 | "Inform",
72 | "",
73 | false, false,
74 | "");
75 | }
76 |
77 | public void testSendNoVarbindsInvalidUser() throws Exception {
78 | testSendNotification(
79 | getProtocolVersion(),
80 | "Inform",
81 | INVALID_SECURITY_NAME,
82 | false, false,
83 | "");
84 | }
85 |
86 | public void testSendInvalidVarbinds() throws Exception {
87 | testSendNotification(
88 | getProtocolVersion(),
89 | "Inform",
90 | getSecurityName(),
91 | false, false,
92 | INVALID_VARIABLE_BINDINGS);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/RoleDelete_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.RoleApi;
31 | import org.hyperic.hq.hqapi1.UserApi;
32 | import org.hyperic.hq.hqapi1.types.Role;
33 | import org.hyperic.hq.hqapi1.types.RoleResponse;
34 | import org.hyperic.hq.hqapi1.types.StatusResponse;
35 | import org.hyperic.hq.hqapi1.types.User;
36 |
37 | public class RoleDelete_test extends RoleTestBase {
38 |
39 | public RoleDelete_test(String name) {
40 | super(name);
41 | }
42 |
43 | public void testDelete() throws Exception {
44 |
45 | RoleApi api = getRoleApi();
46 | Role r = generateTestRole();
47 |
48 | RoleResponse createResponse = api.createRole(r);
49 | hqAssertSuccess(createResponse);
50 |
51 | Role role = createResponse.getRole();
52 | StatusResponse deleteResponse = api.deleteRole(role.getId());
53 | hqAssertSuccess(deleteResponse);
54 |
55 | RoleResponse getResponse = api.getRole(role.getId());
56 | hqAssertFailureObjectNotFound(getResponse);
57 | }
58 |
59 | public void testDeleteNonExistantRole() throws Exception {
60 |
61 | RoleApi api = getRoleApi();
62 |
63 | StatusResponse response = api.deleteRole(Integer.MAX_VALUE);
64 | hqAssertFailureObjectNotFound(response);
65 | }
66 |
67 | public void testDeleteNoPermission() throws Exception {
68 |
69 | RoleApi api = getRoleApi();
70 | Role r = generateTestRole();
71 |
72 | RoleResponse createResponse = api.createRole(r);
73 | hqAssertSuccess(createResponse);
74 |
75 | //Create an underprivileged user
76 | UserApi userapi = getUserApi();
77 |
78 | User user = generateTestUser();
79 |
80 | userapi.createUser(user, TESTUSER_PASSWORD);
81 |
82 | RoleApi roleapi = getRoleApi(user.getName(), TESTUSER_PASSWORD);
83 | Role role = createResponse.getRole();
84 | StatusResponse deleteResponse = roleapi.deleteRole(role.getId());
85 | hqAssertFailurePermissionDenied(deleteResponse);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/AlertDefinitionGetTypeBased_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.AlertDefinitionApi;
31 | import org.hyperic.hq.hqapi1.types.AlertDefinitionsResponse;
32 | import org.hyperic.hq.hqapi1.types.AlertDefinition;
33 |
34 | public class AlertDefinitionGetTypeBased_test extends AlertDefinitionTestBase {
35 |
36 | public AlertDefinitionGetTypeBased_test(String name) {
37 | super(name);
38 | }
39 |
40 | public void testGetTypeDefinitionsWithIds() throws Exception {
41 |
42 | AlertDefinitionApi api = getApi().getAlertDefinitionApi();
43 |
44 | AlertDefinitionsResponse response = api.getTypeAlertDefinitions(false);
45 | hqAssertSuccess(response);
46 |
47 | for (AlertDefinition d : response.getAlertDefinition()) {
48 | validateTypeDefinition(d);
49 | }
50 | }
51 |
52 | public void testGetTypeDefinitionsWithoutIds() throws Exception {
53 |
54 | AlertDefinitionApi api = getApi().getAlertDefinitionApi();
55 |
56 | AlertDefinitionsResponse response = api.getTypeAlertDefinitions(true);
57 | hqAssertSuccess(response);
58 |
59 | for (AlertDefinition d : response.getAlertDefinition()) {
60 | assertNotNull("Alert definition name is null",
61 | d.getName());
62 | assertTrue("Invalid frequency " + d.getFrequency(),
63 | d.getFrequency() >= 0 && d.getFrequency() <= 4);
64 | assertTrue("Invalid priority " + d.getPriority(),
65 | d.getPriority() >= 1 & d.getPriority() <= 3);
66 | // Type alerts have parent == 0
67 | assertTrue("Invalid parent id " + d.getParent() +
68 | " for type definition " + d.getName(),
69 | d.getParent() == 0);
70 | assertTrue("No ResourcePrototype found for type based alert",
71 | d.getResourcePrototype() != null);
72 | // Should not have ids
73 | assertNull("Alert id is not null", d.getId());
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/RoleGetRole_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.RoleApi;
31 | import org.hyperic.hq.hqapi1.types.Role;
32 | import org.hyperic.hq.hqapi1.types.RoleResponse;
33 |
34 | public class RoleGetRole_test extends RoleTestBase {
35 |
36 | public RoleGetRole_test(String name) {
37 | super(name);
38 | }
39 |
40 | public void testGetRoleByName() throws Exception {
41 |
42 | RoleApi api = getRoleApi();
43 |
44 | RoleResponse response = api.getRole(GUEST_ROLENAME);
45 | hqAssertSuccess(response);
46 |
47 | Role r = response.getRole();
48 | assertEquals(2, r.getId().intValue());
49 | assertTrue("Guest role has no user",
50 | r.getUser().size() >= 1);
51 | }
52 |
53 | public void testGetRoleNameInvalid() throws Exception {
54 |
55 | RoleApi api = getRoleApi();
56 |
57 | RoleResponse response = api.getRole("Non-existant Role Name");
58 | hqAssertFailureObjectNotFound(response);
59 | }
60 |
61 | public void testGetRoleId() throws Exception {
62 |
63 | RoleApi api = getRoleApi();
64 |
65 | RoleResponse response = api.getRole(2);
66 | hqAssertSuccess(response);
67 |
68 | Role r = response.getRole();
69 | assertEquals(GUEST_ROLENAME, r.getName());
70 | }
71 |
72 | public void testGetRoleIdInvalid() throws Exception {
73 |
74 | RoleApi api = getRoleApi();
75 |
76 | RoleResponse response = api.getRole(Integer.MAX_VALUE);
77 | hqAssertFailureObjectNotFound(response);
78 | }
79 |
80 | public void testGetSystemRole() throws Exception {
81 | // System roles may not be modified
82 | // Exception Super User Role
83 |
84 | RoleApi api = getRoleApi();
85 |
86 | RoleResponse response = api.getRole(1);
87 | hqAssertFailureNotSupported(response);
88 |
89 | response = api.getRole(0);
90 | hqAssertSuccess(response);
91 | Role r = response.getRole();
92 | assertEquals(SUPER_USER_ROLENAME, r.getName());
93 |
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | org.hyperic.hq.hqapi
8 | parent
9 | 6.0.1
10 |
11 |
12 | hqapi1-integration-tests
13 | pom
14 | Hyperic HQAPI Integration Tests
15 |
16 |
17 |
18 | org.hyperic.hq.hqapi
19 | hqapi1
20 | ${project.version}
21 |
22 |
23 | junit
24 | junit
25 | test
26 |
27 |
28 |
29 |
30 | src/test/java
31 |
32 |
33 | org.apache.maven.plugins
34 | maven-compiler-plugin
35 |
36 |
37 |
38 | testCompile
39 |
40 |
41 |
42 |
43 |
44 | org.apache.maven.plugins
45 | maven-surefire-plugin
46 |
47 |
48 | **/*_test.java
49 |
50 |
51 | **/SSL_test.java
52 | **/SNMP*_test.java
53 |
54 |
55 |
56 |
57 | integration-test
58 |
59 | test
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | snmp
70 |
71 |
72 |
73 | org.apache.maven.plugins
74 | maven-surefire-plugin
75 |
76 |
77 | **/SNMP*_test.java
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | ${log}
86 | ${address}
87 | ${oid}
88 | ${variable-bindings}
89 | ${community}
90 | ${security-name}
91 | ${auth-protocol}
92 | ${auth-passphrase}
93 | ${priv-protocol}
94 | ${priv-passphrase}
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/hqapi1/src/main/java/org/hyperic/hq/hqapi1/ErrorCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008-2010], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1;
29 |
30 | public enum ErrorCode {
31 | /**
32 | * The given username and password could not be validated.
33 | */
34 | LOGIN_FAILURE("LoginFailure",
35 | "The given username and password could not be validated"),
36 | /**
37 | * The requested object could not be found.
38 | */
39 | OBJECT_NOT_FOUND("ObjectNotFound",
40 | "The requested object could not be found"),
41 | /**
42 | * The given object already exists.
43 | */
44 | OBJECT_EXISTS("ObjectExists",
45 | "The given object already exists"),
46 | /**
47 | * The given parameters are incorrect.
48 | */
49 | INVALID_PARAMETERS("InvalidParameters",
50 | "The given parameters are incorrect"),
51 | /**
52 | * An unexpected error occurred.
53 | */
54 | UNEXPECTED_ERROR("UnexpectedError",
55 | "An unexpected error occurred"),
56 | /**
57 | * The current user does not have permission for this operation.
58 | */
59 | PERMISSION_DENIED("PermissionDenied",
60 | "The current user does not have permission for this operation"),
61 |
62 | /**
63 | * The requested operation was denied.
64 | */
65 | OPERATION_DENIED("OperationDenied",
66 | "The request operation was denied"),
67 | /**
68 | * The requested API is not implemented.
69 | */
70 | NOT_IMPLEMENTED("NotImplemented",
71 | "The requested API is not available"),
72 |
73 | /**
74 | * Operation not supported.
75 | */
76 | NOT_SUPPORTED("NotSupported",
77 | "The requested operation is not supported");
78 |
79 | private final String _errorCode;
80 | private final String _reasonText;
81 |
82 | ErrorCode(String errorCode, String reasonText) {
83 | _errorCode = errorCode;
84 | _reasonText = reasonText;
85 | }
86 |
87 | public String getErrorCode() {
88 | return _errorCode;
89 | }
90 |
91 | public String getReasonText() {
92 | return _reasonText;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/hqapi1-tools/src/main/java/tools/EventCommand.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.tools;
2 |
3 | import joptsimple.OptionParser;
4 | import joptsimple.OptionSet;
5 |
6 | import java.util.Arrays;
7 |
8 | import org.hyperic.hq.hqapi1.HQApi;
9 | import org.hyperic.hq.hqapi1.XmlUtil;
10 | import org.hyperic.hq.hqapi1.EventApi;
11 | import org.hyperic.hq.hqapi1.ResourceApi;
12 | import org.hyperic.hq.hqapi1.types.ResourceResponse;
13 | import org.hyperic.hq.hqapi1.types.EventsResponse;
14 | import org.springframework.stereotype.Component;
15 | @Component
16 | public class EventCommand extends AbstractCommand {
17 |
18 | private static String CMD_LIST = "list";
19 |
20 | private static String[] COMMANDS = { CMD_LIST };
21 |
22 | private static final String OPT_RESOURCE_ID = "resourceId";
23 | private static final String OPT_HOURS = "hours";
24 |
25 | private void printUsage() {
26 | System.err.println("One of " + Arrays.toString(COMMANDS) + " required");
27 | }
28 |
29 | public String getName() {
30 | return "event";
31 | }
32 |
33 | public int handleCommand(String[] args) throws Exception {
34 | if (args.length == 0) {
35 | printUsage();
36 | return 1;
37 | }
38 |
39 | if (args[0].equals(CMD_LIST)) {
40 | list(trim(args));
41 | } else {
42 | printUsage();
43 | return 1;
44 | }
45 | return 0;
46 | }
47 |
48 | private void list(String[] args) throws Exception {
49 |
50 | OptionParser p = getOptionParser();
51 |
52 | p.accepts(OPT_RESOURCE_ID, "If specified, only return events for the" +
53 | "given Resource id").
54 | withRequiredArg().ofType(Integer.class);
55 | p.accepts(OPT_HOURS, "The number of hours of data to query. Defaults to 8")
56 | .withRequiredArg().ofType(Integer.class);
57 |
58 | OptionSet options = getOptions(p, args);
59 |
60 | HQApi api = getApi(options);
61 | EventApi eventApi = api.getEventApi();
62 | ResourceApi resourceApi = api.getResourceApi();
63 |
64 | final long MS_IN_HOUR = 60l * 60l * 1000l;
65 | final long end = System.currentTimeMillis();
66 | long start;
67 | if (options.has(OPT_HOURS)) {
68 | int hours = (Integer)options.valueOf(OPT_HOURS);
69 | start = end - (hours * MS_IN_HOUR);
70 | } else {
71 | start = end - (8 * MS_IN_HOUR);
72 | }
73 |
74 | EventsResponse response;
75 | if (options.has(OPT_RESOURCE_ID)) {
76 | Integer id = (Integer)options.valueOf(OPT_RESOURCE_ID);
77 |
78 | ResourceResponse resourceResponse =
79 | resourceApi.getResource(id, false, false);
80 | checkSuccess(resourceResponse);
81 |
82 | response = eventApi.findEvents(resourceResponse.getResource(),
83 | start, end);
84 | } else {
85 | response = eventApi.findEvents(start, end,
86 | EventApi.EventType.ANY,
87 | EventApi.EventStatus.ANY,
88 | Integer.MAX_VALUE);
89 | }
90 |
91 | checkSuccess(response);
92 | XmlUtil.serialize(response, System.out, Boolean.TRUE);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/GroupControlAction_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.ControlApi;
31 | import org.hyperic.hq.hqapi1.HQApi;
32 | import org.hyperic.hq.hqapi1.types.ControlActionResponse;
33 | import org.hyperic.hq.hqapi1.types.Group;
34 | import org.hyperic.hq.hqapi1.types.User;
35 |
36 | import java.util.List;
37 |
38 | public class GroupControlAction_test extends ControlTestBase {
39 |
40 | public GroupControlAction_test(String name) {
41 | super(name);
42 | }
43 |
44 | public void testControlActionInvalidGroup() throws Exception {
45 | ControlApi api = getApi().getControlApi();
46 |
47 | Group g = new Group();
48 | g.setResourceId(Integer.MAX_VALUE);
49 |
50 | ControlActionResponse response = api.getActions(g);
51 | hqAssertFailureObjectNotFound(response);
52 | }
53 |
54 | public void testControlActionValidGroup() throws Exception {
55 | HQApi api = getApi();
56 |
57 | Group controlGroup = createControllableGroup(api);
58 |
59 | ControlApi cApi = api.getControlApi();
60 | ControlActionResponse response = cApi.getActions(controlGroup);
61 | hqAssertSuccess(response);
62 |
63 | assertTrue("Should have found 1 control action for group " +
64 | controlGroup.getName(), response.getAction().size() == 1);
65 |
66 | assertEquals("run", response.getAction().get(0));
67 |
68 | cleanupControllableGroup(api, controlGroup);
69 | }
70 |
71 | public void testControlActionNoPermission() throws Exception {
72 | HQApi api = getApi();
73 |
74 | Group controlGroup = createControllableGroup(api);
75 | List users = createTestUsers(1);
76 | User user = users.get(0);
77 |
78 | HQApi apiUnpriv = getApi(user.getName(), TESTUSER_PASSWORD);
79 | ControlApi cApiUnpriv = apiUnpriv.getControlApi();
80 |
81 | ControlActionResponse response = cApiUnpriv.getActions(controlGroup);
82 | hqAssertFailurePermissionDenied(response);
83 |
84 | deleteTestUsers(users);
85 | cleanupControllableGroup(api, controlGroup);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/ControlExecute_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008-2010], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.ControlApi;
31 | import org.hyperic.hq.hqapi1.HQApi;
32 | import org.hyperic.hq.hqapi1.types.Resource;
33 | import org.hyperic.hq.hqapi1.types.StatusResponse;
34 | import org.hyperic.hq.hqapi1.types.User;
35 |
36 | import java.util.List;
37 |
38 | public class ControlExecute_test extends ControlTestBase {
39 |
40 | public ControlExecute_test(String name) {
41 | super(name);
42 | }
43 |
44 | public void testExecuteInvalidResource() throws Exception {
45 | ControlApi api = getApi().getControlApi();
46 |
47 | Resource r = new Resource();
48 | r.setId(Integer.MAX_VALUE);
49 |
50 | StatusResponse response = api.executeAction(r, "none", new String[] {});
51 | hqAssertFailureObjectNotFound(response);
52 | }
53 |
54 | public void testExecuteValidResource() throws Exception {
55 | HQApi api = getApi();
56 | ControlApi cApi = getApi().getControlApi();
57 |
58 | Resource controllableResource = createControllableResource(api);
59 |
60 | String[] arguments = new String[0];
61 | StatusResponse executeResponse = cApi.executeAction(controllableResource,
62 | "run", arguments);
63 | hqAssertSuccess(executeResponse);
64 |
65 | cleanupResource(api, controllableResource);
66 | }
67 |
68 | public void testExecuteNoPermission() throws Exception {
69 | HQApi api = getApi();
70 | Resource controllableResource = createControllableResource(api);
71 |
72 | List users = createTestUsers(1);
73 | User user = users.get(0);
74 |
75 | HQApi apiUnpriv = getApi(user.getName(), TESTUSER_PASSWORD);
76 | ControlApi cApiUnpriv = apiUnpriv.getControlApi();
77 |
78 | StatusResponse executeResponse = cApiUnpriv.executeAction(controllableResource,
79 | "run", new String[0]);
80 | hqAssertFailurePermissionDenied(executeResponse);
81 |
82 | deleteTestUsers(users);
83 | cleanupResource(api, controllableResource);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/WADLResource_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.wadl.*;
4 |
5 | public class WADLResource_test extends WADLTestBase {
6 |
7 | public void testResourceFindGet() throws Exception {
8 | HttpLocalhost8080HquHqapi1.ResourceFindHqu resourceFind = new HttpLocalhost8080HquHqapi1.ResourceFindHqu();
9 | HttpLocalhost8080HquHqapi1.ResourceGetHqu resourceGet = new HttpLocalhost8080HquHqapi1.ResourceGetHqu();
10 |
11 | ResourcesResponse response =
12 | resourceFind.getAsResourcesResponse(null, "CPU", null, false, false);
13 | hqAssertSuccess(response);
14 | assertTrue("No resources found", response.getResource().size() > 0);
15 |
16 | Resource r = response.getResource().get(0);
17 | ResourceResponse getResponse = resourceGet.getAsResourceResponse(r.getId(),
18 | null,
19 | false,
20 | false);
21 | hqAssertSuccess(getResponse);
22 | assertTrue("Resource names do not match",
23 | r.getName().equals(getResponse.getResource().getName()));
24 | }
25 |
26 | public void testCreatePlatform() throws Exception {
27 | HttpLocalhost8080HquHqapi1.ResourceCreatePlatformHqu createPlatform =
28 | new HttpLocalhost8080HquHqapi1.ResourceCreatePlatformHqu();
29 | HttpLocalhost8080HquHqapi1.ResourceDeleteHqu deleteResource =
30 | new HttpLocalhost8080HquHqapi1.ResourceDeleteHqu();
31 | }
32 |
33 | public void testCreateResource() throws Exception {
34 | HttpLocalhost8080HquHqapi1.ResourceCreateResourceHqu createResource =
35 | new HttpLocalhost8080HquHqapi1.ResourceCreateResourceHqu();
36 | HttpLocalhost8080HquHqapi1.ResourceDeleteHqu deleteResource =
37 | new HttpLocalhost8080HquHqapi1.ResourceDeleteHqu();
38 | HttpLocalhost8080HquHqapi1.ResourceSyncHqu syncResource = new HttpLocalhost8080HquHqapi1.ResourceSyncHqu();
39 | }
40 |
41 | public void testGetResourcePrototypes() throws Exception {
42 | HttpLocalhost8080HquHqapi1.ResourceGetResourcePrototypesHqu resourceGetPrototypes =
43 | new HttpLocalhost8080HquHqapi1.ResourceGetResourcePrototypesHqu();
44 |
45 | ResourcePrototypesResponse response =
46 | resourceGetPrototypes.getAsResourcePrototypesResponse();
47 | hqAssertSuccess(response);
48 | assertTrue("No ResourcePrototypes found",
49 | response.getResourcePrototype().size() > 0);
50 |
51 | response = resourceGetPrototypes.getAsResourcePrototypesResponse(true);
52 | hqAssertSuccess(response);
53 | assertTrue("No ResourcePrototypes found",
54 | response.getResourcePrototype().size() > 0);
55 | }
56 |
57 | public void testGetResourcePrototype() throws Exception {
58 | HttpLocalhost8080HquHqapi1.ResourceGetResourcePrototypeHqu resourceGetPrototype =
59 | new HttpLocalhost8080HquHqapi1.ResourceGetResourcePrototypeHqu();
60 |
61 | ResourcePrototypeResponse response =
62 | resourceGetPrototype.getAsResourcePrototypeResponse("CPU");
63 | hqAssertSuccess(response);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/AgentGet_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.AgentApi;
31 | import org.hyperic.hq.hqapi1.types.Agent;
32 | import org.hyperic.hq.hqapi1.types.AgentResponse;
33 |
34 | public class AgentGet_test extends HQApiTestBase {
35 |
36 | public AgentGet_test(String name) {
37 | super(name);
38 | }
39 |
40 | private void validateAgent(Agent a) {
41 | assertTrue(a.getAddress().length() > 0);
42 | assertTrue(a.getPort() > 0 || a.getPort() == -1);
43 | assertTrue(a.getVersion().length() > 0);
44 | assertTrue(a.getId() > 0);
45 | }
46 |
47 | public void testGetAgentInvalid() throws Exception {
48 |
49 | AgentApi api = getApi().getAgentApi();
50 |
51 | AgentResponse response = api.getAgent("invalid.hyperic.com", 2144);
52 | hqAssertFailureObjectNotFound(response);
53 | }
54 |
55 | public void testGetAgentValid() throws Exception {
56 |
57 | Agent agent = getRunningAgent();
58 |
59 | AgentApi api = getApi().getAgentApi();
60 |
61 | AgentResponse response = api.getAgent(agent.getAddress(),
62 | agent.getPort());
63 | hqAssertSuccess(response);
64 |
65 | Agent a = response.getAgent();
66 | validateAgent(a);
67 | }
68 |
69 | public void testGetAgentById() throws Exception {
70 |
71 | Agent agent = getRunningAgent();
72 |
73 | AgentApi api = getApi().getAgentApi();
74 |
75 | AgentResponse response = api.getAgent(agent.getId());
76 | hqAssertSuccess(response);
77 |
78 | Agent a = response.getAgent();
79 | validateAgent(a);
80 | }
81 |
82 | public void testGetAgentByInvalidId() throws Exception {
83 |
84 | AgentApi api = getApi().getAgentApi();
85 |
86 | AgentResponse response = api.getAgent(Integer.MAX_VALUE);
87 | hqAssertFailureObjectNotFound(response);
88 | }
89 |
90 | public void testGetAgentByInvalidToken() throws Exception {
91 |
92 | AgentApi api = getApi().getAgentApi();
93 |
94 | AgentResponse response = api.getAgent("someInvalidAgentToken");
95 | hqAssertFailureObjectNotFound(response);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/hqapi1/src/main/java/org/hyperic/hq/hqapi1/Connection.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.util.Map;
6 |
7 | public interface Connection {
8 |
9 | T doGet(String path, Map params, File targetFile, ResponseHandler responseHandler)
10 | throws IOException;
11 |
12 | /**
13 | * Issue a GET against the API.
14 | *
15 | * @param path
16 | * The web service endpoint.
17 | * @param params
18 | * A Map of key value pairs that are converted into query
19 | * arguments.
20 | * @param responseHandler
21 | * The @{link ResponseHandler} that will process this response.
22 | * @return The response object from the operation. This response will be of
23 | * the type given in the resultClass argument.
24 | * @throws IOException
25 | * If a network error occurs during the request.
26 | */
27 | T doGet(String path, Map params, ResponseHandler responseHandler)
28 | throws IOException;
29 |
30 | /**
31 | * Issue a POST against the API.
32 | *
33 | * @param path
34 | * The web service endpoint
35 | * @param params
36 | * A Map of key value pairs that are converted into query
37 | * arguments.
38 | * @param responseHandler
39 | * The @{link ResponseHandler} that will process this response.
40 | * @return The response object from the operation. This response will be of
41 | * the type given in the resultClass argument.
42 | * @throws IOException
43 | * If a network error occurs during the request.
44 | */
45 | T doPost(String path, Map params, ResponseHandler responseHandler)
46 | throws IOException;
47 |
48 | /**
49 | * Issue a POST against the API.
50 | *
51 | * @param path
52 | * The web service endpoint
53 | * @param params
54 | * A Map of key value pairs that are added to the post data
55 | * @param file
56 | * The file to post
57 | * @param responseHandler
58 | * The @{link ResponseHandler} that will process this response.
59 | * @return The response object from the operation. This response will be of
60 | * the type given in the resultClass argument.
61 | * @throws IOException
62 | * If a network error occurs during the request.
63 | */
64 | T doPost(String path, Map params, File file,
65 | ResponseHandler responseHandler) throws IOException;
66 |
67 | /**
68 | * Issue a POST against the API.
69 | *
70 | * @param path
71 | * The web service endpoint
72 | * @param o
73 | * The object to POST. This object will be serialized into XML
74 | * prior to being sent.
75 | * @param responseHandler
76 | * The @{link ResponseHandler} that will process this response.
77 | * @return The response object from the operation. This response will be of
78 | * the type given in the resultClass argument.
79 | * @throws IOException
80 | * If a network error occurs during the request.
81 | */
82 | T doPost(String path, Object o, ResponseHandler responseHandler)
83 | throws IOException;
84 | }
85 |
--------------------------------------------------------------------------------
/hqapi1-tools/src/main/java/tools/GroovyShellCommand.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2011], VMWare, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.tools;
29 |
30 | import joptsimple.OptionParser;
31 | import joptsimple.OptionSet;
32 | import org.hyperic.hq.hqapi1.HQApi;
33 | import org.hyperic.hq.hqapi1.XmlUtil;
34 | import org.springframework.stereotype.Component;
35 |
36 | import java.io.IOException;
37 | import java.io.InputStream;
38 | import java.util.Arrays;
39 | import java.util.List;
40 |
41 | import groovy.lang.GroovyClassLoader;
42 | import groovy.lang.GroovyObject;
43 |
44 | @Component
45 | public class GroovyShellCommand extends AbstractCommand {
46 |
47 | private static String CMD_RUN = "run";
48 |
49 | private static String[] COMMANDS = { CMD_RUN };
50 |
51 | private void printUsage() {
52 | System.err.println("One of " + Arrays.toString(COMMANDS) + " required");
53 | }
54 |
55 | public String getName() {
56 | return "groovyshell";
57 | }
58 |
59 | public int handleCommand(String[] args) throws Exception {
60 | if (args.length == 0) {
61 | printUsage();
62 | return 1;
63 | }
64 |
65 | if (args[0].equals(CMD_RUN)) {
66 | run(trim(args));
67 | } else {
68 | printUsage();
69 | return 1;
70 | }
71 | return 0;
72 | }
73 |
74 | private void run(String[] args) throws Exception {
75 | OptionParser p = getOptionParser();
76 | OptionSet options = getOptions(p, args);
77 | InputStream is = null;
78 |
79 | try {
80 | is = getInputStream(options);
81 | } catch (IOException e) {
82 | printUsage();
83 | System.exit(-1);
84 | }
85 |
86 | ClassLoader parent = getClass().getClassLoader();
87 | GroovyClassLoader loader = new GroovyClassLoader(parent);
88 | Class groovyClass = loader.parseClass(is);
89 |
90 | // let's call some method on an instance
91 | GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
92 | groovyObject.setProperty("api", getApi(options)); // pass the api to the script
93 | groovyObject.invokeMethod("run", args);
94 | }
95 |
96 | public HQApi getApi() {
97 | return hqApi;
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/MetricDataGetMulti_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.MetricApi;
4 | import org.hyperic.hq.hqapi1.MetricDataApi;
5 | import org.hyperic.hq.hqapi1.types.Resource;
6 | import org.hyperic.hq.hqapi1.types.MetricsResponse;
7 | import org.hyperic.hq.hqapi1.types.MetricsDataResponse;
8 | import org.hyperic.hq.hqapi1.types.MetricData;
9 | import org.hyperic.hq.hqapi1.types.Metric;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | public class MetricDataGetMulti_test extends MetricDataTestBase {
15 |
16 | public MetricDataGetMulti_test(String name) {
17 | super(name);
18 | }
19 |
20 | public void testValidGet() throws Exception {
21 |
22 | MetricApi api = getApi().getMetricApi();
23 | MetricDataApi dataApi = getApi().getMetricDataApi();
24 |
25 | Resource platform = getLocalPlatformResource(false, false);
26 | MetricsResponse metricsResponse = api.getMetrics(platform, true);
27 | hqAssertSuccess(metricsResponse);
28 | assertTrue("No metrics found for " + platform.getName(),
29 | metricsResponse.getMetric().size() > 0);
30 |
31 | long end = System.currentTimeMillis();
32 | long start = end - (8 * 60 * 60 * 1000);
33 | MetricsDataResponse dataResponse = dataApi.getData(metricsResponse.getMetric(),
34 | start, end);
35 | hqAssertSuccess(dataResponse);
36 |
37 | for (MetricData metricData : dataResponse.getMetricData()) {
38 | validateMetricData(metricData);
39 | }
40 | }
41 |
42 | public void testGetInvalidMetricId() throws Exception {
43 |
44 | MetricDataApi dataApi = getApi().getMetricDataApi();
45 |
46 | long end = System.currentTimeMillis();
47 | long start = end - (8 * 60 * 60 * 1000);
48 |
49 | List metrics = new ArrayList();
50 | Metric m = new Metric();
51 | m.setId(Integer.MAX_VALUE);
52 | metrics.add(m);
53 |
54 | MetricsDataResponse dataResponse = dataApi.getData(metrics, start, end);
55 | hqAssertFailureObjectNotFound(dataResponse);
56 | }
57 |
58 | public void testGetEmptyMetricList() throws Exception {
59 |
60 | MetricDataApi dataApi = getApi().getMetricDataApi();
61 |
62 | long end = System.currentTimeMillis();
63 | long start = end - (8 * 60 * 60 * 1000);
64 |
65 | List metrics = new ArrayList();
66 |
67 | MetricsDataResponse dataResponse = dataApi.getData(metrics, start, end);
68 | hqAssertFailureInvalidParameters(dataResponse);
69 | }
70 |
71 | public void testGetInvalidRange() throws Exception {
72 |
73 | MetricApi api = getApi().getMetricApi();
74 | MetricDataApi dataApi = getApi().getMetricDataApi();
75 |
76 | Resource platform = getLocalPlatformResource(false, false);
77 | MetricsResponse metricsResponse = api.getMetrics(platform, true);
78 | hqAssertSuccess(metricsResponse);
79 | assertTrue("No metrics found for " + platform.getName(),
80 | metricsResponse.getMetric().size() > 0);
81 |
82 | long end = System.currentTimeMillis();
83 | long start = end - (8 * 60 * 60 * 1000);
84 | MetricsDataResponse dataResponse = dataApi.getData(metricsResponse.getMetric(),
85 | end, start);
86 | hqAssertFailureInvalidParameters(dataResponse);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/RoleTestBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.RoleApi;
31 | import org.hyperic.hq.hqapi1.UserApi;
32 | import org.hyperic.hq.hqapi1.types.Operation;
33 | import org.hyperic.hq.hqapi1.types.Role;
34 | import org.hyperic.hq.hqapi1.types.RolesResponse;
35 |
36 | import java.util.ArrayList;
37 | import java.util.List;
38 | import java.util.Random;
39 |
40 | public abstract class RoleTestBase extends HQApiTestBase {
41 |
42 | static final String GUEST_ROLENAME = "Guest Role";
43 | static final String SUPER_USER_ROLENAME = "Super User Role";
44 |
45 | // Collections of Operations for test purposes.
46 | static final List VIEW_OPS;
47 | static final List MODIFY_OPS;
48 |
49 | static {
50 | VIEW_OPS = new ArrayList();
51 | VIEW_OPS.add(Operation.VIEW_APPLICATION);
52 | VIEW_OPS.add(Operation.VIEW_PLATFORM);
53 | VIEW_OPS.add(Operation.VIEW_RESOURCE_GROUP);
54 | VIEW_OPS.add(Operation.VIEW_ROLE);
55 | VIEW_OPS.add(Operation.VIEW_SERVER);
56 | VIEW_OPS.add(Operation.VIEW_SERVICE);
57 | VIEW_OPS.add(Operation.VIEW_SUBJECT);
58 |
59 | MODIFY_OPS = new ArrayList();
60 | MODIFY_OPS.add(Operation.MODIFY_APPLICATION);
61 | MODIFY_OPS.add(Operation.MODIFY_ESCALATION);
62 | MODIFY_OPS.add(Operation.MODIFY_PLATFORM);
63 | MODIFY_OPS.add(Operation.MODIFY_RESOURCE_GROUP);
64 | MODIFY_OPS.add(Operation.MODIFY_RESOURCE_TYPE);
65 | MODIFY_OPS.add(Operation.MODIFY_ROLE);
66 | MODIFY_OPS.add(Operation.MODIFY_SERVER);
67 | MODIFY_OPS.add(Operation.MODIFY_SERVICE);
68 | MODIFY_OPS.add(Operation.MODIFY_SUBJECT);
69 | }
70 |
71 | public RoleTestBase(String name) {
72 | super(name);
73 | }
74 |
75 | public RoleApi getRoleApi() {
76 | return getApi().getRoleApi();
77 | }
78 |
79 | public UserApi getUserApi() {
80 | return getApi().getUserApi();
81 | }
82 |
83 | public RoleApi getRoleApi(String name, String password){
84 | return getApi(name, password).getRoleApi();
85 | }
86 |
87 | /**
88 | * Clean up test roles after each test run.
89 | */
90 | public void tearDown() throws Exception {
91 |
92 | cleanupRoles();
93 |
94 | super.tearDown();
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/UserCopy_test.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * NOTE: This copyright does *not* cover user programs that use HQ
4 | * program services by normal system calls through the application
5 | * program interfaces provided as part of the Hyperic Plug-in Development
6 | * Kit or the Hyperic Client Development Kit - this is merely considered
7 | * normal use of the program, and does *not* fall under the heading of
8 | * "derived work".
9 | *
10 | * Copyright (C) [2008, 2009], Hyperic, Inc.
11 | * This file is part of HQ.
12 | *
13 | * HQ is free software; you can redistribute it and/or modify
14 | * it under the terms version 2 of the GNU General Public License as
15 | * published by the Free Software Foundation. This program is distributed
16 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
17 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 | * PARTICULAR PURPOSE. See the GNU General Public License for more
19 | * details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with this program; if not, write to the Free Software
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 | * USA.
25 | *
26 | */
27 |
28 | package org.hyperic.hq.hqapi1.test;
29 |
30 | import org.hyperic.hq.hqapi1.UserApi;
31 | import org.hyperic.hq.hqapi1.types.ResponseStatus;
32 | import org.hyperic.hq.hqapi1.types.StatusResponse;
33 | import org.hyperic.hq.hqapi1.types.User;
34 | import org.hyperic.hq.hqapi1.types.UserResponse;
35 | import org.hyperic.hq.hqapi1.types.UsersRequest;
36 | import org.hyperic.hq.hqapi1.types.UsersResponse;
37 |
38 | import java.util.List;
39 |
40 | public class UserCopy_test extends UserTestBase {
41 |
42 | public UserCopy_test(String name) {
43 | super(name);
44 | }
45 |
46 | /**
47 | * This test will create a user then deletes the same user and re-create the user
48 | * using the same User object that had created initially and test the user login.
49 | */
50 | public void testCopy() throws Exception {
51 |
52 | UserApi api = getUserApi();
53 |
54 | User user = generateTestUser();
55 |
56 | //create the new user
57 | UserResponse createResponse = api.createUser(user, TESTUSER_PASSWORD);
58 | assertEquals(ResponseStatus.SUCCESS, createResponse.getStatus());
59 |
60 | // Assert the new user exists
61 | UserResponse getResponse = api.getUser(user.getName());
62 | hqAssertSuccess(getResponse);
63 |
64 | // store the user that was just created before deleting
65 | User createdUser = getResponse.getUser();
66 |
67 | // Delete the user that was just created.
68 | StatusResponse deleteResponse = api.deleteUser(createdUser.getId());
69 | hqAssertSuccess(deleteResponse);
70 |
71 | // Assert that user is no longer available
72 | UserResponse getResponse2 = api.getUser(createdUser.getId());
73 | hqAssertFailureObjectNotFound(getResponse2);
74 |
75 | // create the user using the existing user object
76 | UsersRequest syncRequest = new UsersRequest();
77 | List users = syncRequest.getUser();
78 | users.add(createdUser);
79 | StatusResponse syncResponse = api.syncUsers(users);
80 | assertEquals(ResponseStatus.SUCCESS, syncResponse.getStatus());
81 |
82 | // test login
83 | UserApi api2 = getUserApi(user.getName(), TESTUSER_PASSWORD);
84 | UsersResponse getResponse3 = api2.getUsers();
85 | hqAssertSuccess(getResponse3);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/hqapi1-integration-tests/src/test/java/org/hyperic/hq/hqapi1/test/SNMPv2cInform_test.java:
--------------------------------------------------------------------------------
1 | package org.hyperic.hq.hqapi1.test;
2 |
3 | import org.hyperic.hq.hqapi1.HQApi;
4 | import org.hyperic.hq.hqapi1.EscalationActionBuilder;
5 | import org.hyperic.hq.hqapi1.ServerConfigApi;
6 | import org.hyperic.hq.hqapi1.types.Alert;
7 | import org.hyperic.hq.hqapi1.types.AlertActionLog;
8 | import org.hyperic.hq.hqapi1.types.AlertDefinition;
9 | import org.hyperic.hq.hqapi1.types.AlertsResponse;
10 | import org.hyperic.hq.hqapi1.types.Escalation;
11 | import org.hyperic.hq.hqapi1.types.EscalationAction;
12 | import org.hyperic.hq.hqapi1.types.ServerConfigResponse;
13 | import org.hyperic.hq.hqapi1.types.StatusResponse;
14 | import org.hyperic.hq.hqapi1.types.ServerConfig;
15 | import org.hyperic.hq.hqapi1.types.Resource;
16 |
17 | import java.io.IOException;
18 | import java.util.ArrayList;
19 | import java.util.Collections;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 |
24 | public class SNMPv2cInform_test extends SNMPTestBase {
25 |
26 | public SNMPv2cInform_test(String name) {
27 | super(name);
28 | }
29 |
30 | public String getProtocolVersion() {
31 | return "2c";
32 | }
33 |
34 | // TODO: ResourceType Alert Definitions
35 |
36 | public void testSendVarbinds() throws Exception {
37 | testSendNotification(
38 | getProtocolVersion(),
39 | "Inform",
40 | getCommunity(),
41 | getVariableBindings());
42 | }
43 |
44 | public void testSendVarBindsInvalidCommunity() throws Exception {
45 | testSendNotification(
46 | getProtocolVersion(),
47 | "Inform",
48 | INVALID_COMMUNITY,
49 | getVariableBindings());
50 | }
51 |
52 | public void testSendNoVarbinds() throws Exception {
53 | testSendNotification(
54 | getProtocolVersion(),
55 | "Inform",
56 | getCommunity(),
57 | "");
58 | }
59 |
60 | public void testSendNoVarbindsInvalidCommunity() throws Exception {
61 | testSendNotification(
62 | getProtocolVersion(),
63 | "Inform",
64 | INVALID_COMMUNITY,
65 | "");
66 | }
67 |
68 | public void testSendInvalidVarbinds() throws Exception {
69 | testSendNotification(
70 | getProtocolVersion(),
71 | "Inform",
72 | getCommunity(),
73 | INVALID_VARIABLE_BINDINGS);
74 | }
75 |
76 | /**
77 | * Validate alert action logs
78 | */
79 | public void validateAlertActionLogs(String user,
80 | List actionLogs) {
81 |
82 | assertTrue("At least one alert escalation log is needed",
83 | !actionLogs.isEmpty());
84 |
85 | String logDetail = actionLogs.get(0).getDetail();
86 | System.out.println(logDetail);
87 |
88 | assertTrue("INFORM notification was not sent",
89 | logDetail.indexOf("INFORM sent") > -1);
90 |
91 | // validate variable bindings
92 | assertTrue("sysUpTime is missing",
93 | logDetail.indexOf("1.3.6.1.2.1.1.3") > 0);
94 |
95 | assertTrue("snmpTrapOID is missing",
96 | logDetail.indexOf("1.3.6.1.6.3.1.1.4.1") > 0);
97 |
98 | // TODO: Need to validate user defined variable bindings
99 |
100 | }
101 | }
102 |
--------------------------------------------------------------------------------