Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get resource by fqdn.

  • Loading branch information...
commit e2d22dd39c9486afc8aa29f408e516bd1a853224 1 parent 29d9848
pnguyen authored
View
21 hqu/hqapi1/app/ResourceController.groovy
@@ -358,12 +358,13 @@ class ResourceController extends ApiController {
def get(params) {
def id = params.getOne("id")?.toInteger()
def platformName = params.getOne("platformName")
+ def fqdn = params.getOne("fqdn")
boolean children = params.getOne("children", "false").toBoolean()
boolean verbose = params.getOne("verbose", "false").toBoolean()
def resource = null
def failureXml
- if (!id && !platformName) {
+ if (!id && !platformName && !fqdn) {
failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS)
} else {
if (id) {
@@ -380,6 +381,17 @@ class ResourceController extends ApiController {
"Platform '" + platformName +
"' not found")
}
+ } else if (fqdn) {
+ try {
+ resource = resourceHelper.find('byFqdn':fqdn)
+ if (!resource) {
+ failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
+ "Platform fqdn='" + fqdn +
+ "' not found")
+ }
+ } catch (PermissionException pe) {
+ failureXml = getFailureXML(ErrorCode.PERMISSION_DENIED)
+ }
}
}
@@ -611,7 +623,12 @@ class ResourceController extends ApiController {
}
} else {
// Assume platform
- resource = resourceHelper.find('platform':name)
+ def fqdn = xmlResource['ResourceInfo'].find { it.'@key' == PROP_FQDN }
+ if (fqdn) {
+ resource = resourceHelper.find('byFqdn':fqdn.'@value')
+ } else {
+ resource = resourceHelper.find('platform':name)
+ }
}
}
View
29 src/org/hyperic/hq/hqapi1/ResourceApi.java
@@ -7,7 +7,7 @@
* normal use of the program, and does *not* fall under the heading of
* "derived work".
*
- * Copyright (C) [2008, 2009], Hyperic, Inc.
+ * Copyright (C) [2008-2010], Hyperic, Inc.
* This file is part of HQ.
*
* HQ is free software; you can redistribute it and/or modify
@@ -300,6 +300,33 @@ public ResourceResponse getPlatformResource(String name, boolean verbose,
}
/**
+ * Get a {@link Resource} by it's platform fqdn.
+ *
+ * @param fqdn The platform fqdn to look up.
+ * @param verbose Flag to indicate whether {@link org.hyperic.hq.hqapi1.types.ResourceConfig}
+ * and {@link org.hyperic.hq.hqapi1.types.ResourceProperty} information will
+ * be included.
+ * @param children Flag to control whether child resources of this resource
+ * will be included.
+ * @return On {@link org.hyperic.hq.hqapi1.types.ResponseStatus#SUCCESS},
+ * the Resource is returned via
+ * {@link org.hyperic.hq.hqapi1.types.ResourceResponse#getResource()}.
+ *
+ * @throws java.io.IOException If a network error occurs while making the request.
+ */
+ public ResourceResponse getPlatformResourceByFqdn(String fqdn, boolean verbose,
+ boolean children)
+ throws IOException
+ {
+ Map<String, String[]> params = new HashMap<String, String[]>();
+ params.put("fqdn", new String[] { fqdn });
+ params.put("verbose", new String[] { Boolean.toString(verbose) });
+ params.put("children", new String[] { Boolean.toString(children)});
+ return doGet("resource/get.hqu", params,
+ new XmlResponseHandler<ResourceResponse>(ResourceResponse.class));
+ }
+
+ /**
* Find the platform {@link Resource}s serviced by the given
* {@link org.hyperic.hq.hqapi1.types.Agent}.
*
View
61 src/org/hyperic/hq/hqapi1/test/ResourceGet_test.java
@@ -7,7 +7,7 @@
* normal use of the program, and does *not* fall under the heading of
* "derived work".
*
- * Copyright (C) [2008, 2009], Hyperic, Inc.
+ * Copyright (C) [2008-2010], Hyperic, Inc.
* This file is part of HQ.
*
* HQ is free software; you can redistribute it and/or modify
@@ -27,9 +27,14 @@
package org.hyperic.hq.hqapi1.test;
+import java.util.List;
+
+import org.hyperic.hq.hqapi1.HQApi;
import org.hyperic.hq.hqapi1.ResourceApi;
import org.hyperic.hq.hqapi1.types.Resource;
+import org.hyperic.hq.hqapi1.types.ResourceInfo;
import org.hyperic.hq.hqapi1.types.ResourceResponse;
+import org.hyperic.hq.hqapi1.types.User;
public class ResourceGet_test extends ResourceTestBase {
@@ -150,4 +155,58 @@ public void testGetInvalidPlatformResource() throws Exception {
false, false);
hqAssertFailureObjectNotFound(getResponse);
}
+
+ public void testGetPlatformResourceByFqdn() throws Exception {
+
+ Resource r = getLocalPlatformResource(false, false);
+
+ String fqdn = getFqdn(r);
+ assertNotNull("Platform has no fqdn", fqdn);
+
+ ResourceResponse getResponse =
+ getApi().getResourceApi().getPlatformResourceByFqdn(fqdn, false, false);
+
+ hqAssertSuccess(getResponse);
+ Resource resource = getResponse.getResource();
+ validateResource(resource);
+ }
+
+ public void testGetPlatformResourceByFqdnNoPermission() throws Exception {
+
+ Resource r = getLocalPlatformResource(false, false);
+
+ String fqdn = getFqdn(r);
+ assertNotNull("Platform has no fqdn", fqdn);
+
+ List<User> users = createTestUsers(1);
+ User user = users.get(0);
+ HQApi apiUnpriv = getApi(user.getName(), TESTUSER_PASSWORD);
+
+ ResourceResponse getResponse =
+ apiUnpriv.getResourceApi().getPlatformResourceByFqdn(fqdn, false, false);
+
+ hqAssertFailurePermissionDenied(getResponse);
+
+ deleteTestUsers(users);
+ }
+
+ public void testGetInvalidPlatformResourceByFqdn() throws Exception {
+
+ ResourceApi api = getApi().getResourceApi();
+
+ ResourceResponse getResponse = api.getPlatformResourceByFqdn("Invalid platform fqdn",
+ false, false);
+ hqAssertFailureObjectNotFound(getResponse);
+ }
+
+ private String getFqdn(Resource r) {
+ String fqdn = null;
+ for (ResourceInfo ri : r.getResourceInfo()) {
+ if ("fqdn".equals(ri.getKey())) {
+ fqdn = ri.getValue();
+ break;
+ }
+ }
+ return fqdn;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.