Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix merge conflicts.

  • Loading branch information...
commit fa97b002d140914e8bb53dfe99becb14964c8cfe 2 parents 0c5b495 + 47084a5
Ryan Morgan authored
View
11 ChangeLog
@@ -90,6 +90,17 @@ Changes in HQApi 3.0
*) [HHQ-3144] Add ServerConfigApi to allow manipulation of HQ server config
settings.
+Changes in HQApi 2.6
+
+ *) [HHQ-4151] Add new API to ResourceApi to find a platform Resource
+ based on the passed resource id. Extended support for this into the
+ CLI using the --parentPlatform flag to resource list.
+
+ *) [HHQ-4150] Make --count optional when listing alerts via the CLI.
+
+ *) [HHQ-4145] Add --addRole, --removeRole, and --clearRoles options to
+ command line group syncing. These can only be used with --name.
+
Changes in HQApi 2.5
*) [HHQ-4133] Perform permission checking on ResourceApi.
View
12 hqu/hqapi1/app/ResourceController.groovy
@@ -359,12 +359,13 @@ class ResourceController extends ApiController {
def id = params.getOne("id")?.toInteger()
def platformName = params.getOne("platformName")
def fqdn = params.getOne("fqdn")
+ def platformId = params.getOne("platformId")?.toInteger()
boolean children = params.getOne("children", "false").toBoolean()
boolean verbose = params.getOne("verbose", "false").toBoolean()
def resource = null
def failureXml
- if (!id && !platformName && !fqdn) {
+ if (!id && !platformName && !fqdn && !platformId) {
failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS)
} else {
try {
@@ -375,6 +376,15 @@ class ResourceController extends ApiController {
"Resource id=" + id +
" not found")
}
+ } else if (platformId) {
+ def wantedResource = getResource(platformId)
+ if (!wantedResource) {
+ failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND,
+ "Resource id=" + platformId +
+ " not found")
+ } else {
+ resource = wantedResource.platform
+ }
} else if (platformName) {
resource = resourceHelper.find('platform': platformName)
if (!resource) {
View
29 src/org/hyperic/hq/hqapi1/ResourceApi.java
@@ -325,7 +325,34 @@ public ResourceResponse getPlatformResourceByFqdn(String fqdn, boolean verbose,
return doGet("resource/get.hqu", params,
new XmlResponseHandler<ResourceResponse>(ResourceResponse.class));
}
-
+
+ /**
+ * Get the platform {@link Resource} for the given resource id.
+ *
+ * @param id The resource id to query.
+ * @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 getPlatformResource(int id, boolean verbose,
+ boolean children)
+ throws IOException
+ {
+ Map<String, String[]> params = new HashMap<String, String[]>();
+ params.put("platformId", new String[] { Integer.toString(id) });
+ 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
63 src/org/hyperic/hq/hqapi1/test/ResourceGet_test.java
@@ -239,4 +239,67 @@ public void testGetResourceByNameUnauthorized() throws Exception {
deleteTestUsers(users);
}
+
+ public void testGetPlatformResourceByPlatform() throws Exception {
+
+ ResourceApi api = getApi().getResourceApi();
+ Resource localPlatform = getLocalPlatformResource(false, false);
+
+ ResourceResponse response = api.getPlatformResource(localPlatform.getId(), false, false);
+ hqAssertSuccess(response);
+
+ assertEquals("Platform ids not equal", localPlatform.getId(),
+ response.getResource().getId());
+ }
+
+ public void testGetPlatformResourceByServer() throws Exception {
+
+ ResourceApi api = getApi().getResourceApi();
+ Resource localPlatform = getLocalPlatformResource(false, true);
+
+ List<Resource> servers = localPlatform.getResource();
+ assertTrue("No servers found for " + localPlatform.getName(),
+ servers.size() > 0);
+
+ Resource server = servers.get(0);
+
+ ResourceResponse response = api.getPlatformResource(server.getId(), false, false);
+ hqAssertSuccess(response);
+
+ assertEquals("Platform ids not equal", localPlatform.getId(),
+ response.getResource().getId());
+ }
+
+ public void testGetPlatformResourceByService() throws Exception {
+
+ ResourceApi api = getApi().getResourceApi();
+ Resource localPlatform = getLocalPlatformResource(false, true);
+
+ List<Resource> servers = localPlatform.getResource();
+ assertTrue("No servers found for " + localPlatform.getName(),
+ servers.size() > 0);
+ Resource service = null;
+ for (Resource server : servers) {
+ if (server.getResource().size() > 0) {
+ service = server.getResource().get(0);
+ break;
+ }
+ }
+
+ assertNotNull("Unable to find a service for platform " + localPlatform.getName(),
+ service);
+
+ ResourceResponse response = api.getPlatformResource(service.getId(), false, false);
+ hqAssertSuccess(response);
+
+ assertEquals("Platform ids not equal", localPlatform.getId(),
+ response.getResource().getId());
+ }
+
+ public void testGetPlatformResourceInvalidId() throws Exception {
+ ResourceApi api = getApi().getResourceApi();
+
+ ResourceResponse response = api.getPlatformResource(Integer.MAX_VALUE, false, false);
+ hqAssertFailureObjectNotFound(response);
+ }
}
View
10 src/org/hyperic/hq/hqapi1/tools/AlertCommand.java
@@ -106,7 +106,7 @@ private void list(String[] args) throws Exception {
withRequiredArg().ofType(Long.class);
p.accepts(OPT_END, "If specified, the end time in epoch-millis.").
withRequiredArg().ofType(Long.class);
- p.accepts(OPT_COUNT, "The maximum number of alerts to return.")
+ p.accepts(OPT_COUNT, "If specified, the maximum number of alerts to return.")
.withRequiredArg().ofType(Integer.class);
p.acceptsAll(Arrays.asList(OPT_INESC),
"If specified, only return alerts which are in " +
@@ -134,8 +134,12 @@ private void list(String[] args) throws Exception {
end = System.currentTimeMillis();
}
- // --count is required
- Integer count = (Integer)getRequired(options, OPT_COUNT);
+ Integer count;
+ if (options.has(OPT_COUNT)) {
+ count = (Integer)getRequired(options, OPT_COUNT);
+ } else {
+ count = Integer.MAX_VALUE;
+ }
Boolean inEsc = options.has(OPT_INESC[0]);
Boolean notFixed = options.has(OPT_NOTFIXED[0]);
View
66 src/org/hyperic/hq/hqapi1/tools/GroupCommand.java
@@ -34,6 +34,8 @@
import org.hyperic.hq.hqapi1.XmlUtil;
import org.hyperic.hq.hqapi1.types.Group;
import org.hyperic.hq.hqapi1.types.GroupsResponse;
+import org.hyperic.hq.hqapi1.types.Role;
+import org.hyperic.hq.hqapi1.types.RoleResponse;
import org.hyperic.hq.hqapi1.types.StatusResponse;
import org.hyperic.hq.hqapi1.types.GroupResponse;
import org.hyperic.hq.hqapi1.types.ResponseStatus;
@@ -76,6 +78,9 @@
private static String OPT_DESC = "description";
private static String OPT_CHILDREN = "children";
private static String OPT_DELETE = "delete";
+ private static String OPT_ADDROLE = "addRole";
+ private static String OPT_REMOVEROLE = "removeRole";
+ private static String OPT_CLEARROLES = "clearRoles";
private void printUsage() {
System.err.println("One of " + Arrays.toString(COMMANDS) + " required");
@@ -175,8 +180,16 @@ private void sync(String[] args) throws Exception {
withRequiredArg().ofType(String.class);
p.accepts(OPT_CHILDREN, "If specified, include child resources of the " +
"specified prototype and regex");
- p.accepts(OPT_DELETE, "If specifed, remove the specified resources from " +
+ p.accepts(OPT_DELETE, "If specified, remove the specified resources from " +
"the given group");
+ p.accepts(OPT_ADDROLE, "If specified, add the given role to this group. " +
+ "This option can only be used with --" + OPT_NAME).
+ withRequiredArg().ofType(String.class);
+ p.accepts(OPT_REMOVEROLE, "If specified, remove the given role from this group. " +
+ "This option can only be used with --" + OPT_NAME).
+ withRequiredArg().ofType(String.class);
+ p.accepts(OPT_CLEARROLES, "If specified, remove all roles from this group. " +
+ "This option can only be used with --" + OPT_NAME);
OptionSet options = getOptions(p, args);
@@ -214,6 +227,48 @@ private void sync(String[] args) throws Exception {
return result;
}
+ private void syncRoles(HQApi api, OptionSet s) throws Exception
+ {
+ // Required arguments
+ String name = (String)getRequired(s, OPT_NAME);
+
+ // Check for existing group
+ GroupResponse groupResponse = api.getGroupApi().getGroup(name);
+ checkSuccess(groupResponse);
+ Group group = groupResponse.getGroup();
+ String msg;
+
+ if (s.has(OPT_CLEARROLES)) {
+ System.out.println(name + ": Clearing " + group.getRole().size() + " roles");
+ group.getRole().clear();
+ } else if (s.has(OPT_ADDROLE)) {
+ String roleName = (String)s.valueOf(OPT_ADDROLE);
+ RoleResponse roleResponse = api.getRoleApi().getRole(roleName);
+ checkSuccess(roleResponse);
+ group.getRole().add(roleResponse.getRole());
+ System.out.println(name + ": Adding role " + roleResponse.getRole().getName());
+ } else if (s.has(OPT_REMOVEROLE)) {
+ String roleName = (String)s.valueOf(OPT_REMOVEROLE);
+ RoleResponse roleResponse = api.getRoleApi().getRole(roleName);
+ checkSuccess(roleResponse);
+ for (Iterator it = group.getRole().iterator(); it.hasNext();) {
+ Role r = (Role)it.next();
+ if (r.getName().equals(roleResponse.getRole().getName())) {
+ it.remove();
+ }
+ }
+ System.out.println(name + ": Removing role " + roleResponse.getRole().getName());
+ } else {
+ throw new IllegalArgumentException("Invalid role options");
+ }
+
+ GroupResponse response = api.getGroupApi().updateGroup(group);
+ checkSuccess(response);
+ String roleText = response.getGroup().getRole().size() == 1 ? "role" : "roles";
+ System.out.println(name + ": Success (now contains " + response.getGroup().getRole().size() +
+ " " + roleText + ")");
+ }
+
private void syncViaCommandLineArgs(OptionSet s) throws Exception
{
// Required args
@@ -231,8 +286,13 @@ private void syncViaCommandLineArgs(OptionSet s) throws Exception
HQApi api = getApi(s);
- Map<Integer,Resource> resources = new HashMap<Integer,Resource>();
+ // Command line role syncing is handled separately
+ if (s.has(OPT_CLEARROLES) || s.has(OPT_ADDROLE) || s.has(OPT_REMOVEROLE)) {
+ syncRoles(api, s);
+ return;
+ }
+ Map<Integer,Resource> resources = new HashMap<Integer,Resource>();
if (prototype != null && platform != null) {
System.err.println("Only one of " + OPT_PROTOTYPE + " or " +
OPT_PLATFORM + " is allowed.");
@@ -336,7 +396,7 @@ private void syncViaCommandLineArgs(OptionSet s) throws Exception
}
}
} else {
- // TODO: could be more efficent here, server side will prune dups
+ // TODO: could be more efficient here, server side will prune dups
group.getResource().addAll(flattenedResources.values());
}
View
11 src/org/hyperic/hq/hqapi1/tools/ResourceCommand.java
@@ -80,6 +80,7 @@
private static String OPT_AGENT_ID = "agentId";
private static String OPT_BATCH_SIZE = "batchSize";
private static String OPT_TO = "to";
+ private static String OPT_PARENT_PLATFORM = "parentPlatform";
private void printUsage() {
System.err.println("One of " + Arrays.toString(COMMANDS) + " required");
@@ -133,6 +134,8 @@ private void list(String[] args) throws Exception {
p.accepts(OPT_VERBOSE, "Include resource configuration and properties");
p.accepts(OPT_CHILDREN, "Include child resources");
+ p.accepts(OPT_PARENT_PLATFORM, "Return the parent platform Resource. " +
+ "Can only be used with --" + OPT_ID);
OptionSet options = getOptions(p, args);
@@ -181,7 +184,13 @@ private void list(String[] args) throws Exception {
resources.getResource().add(resource.getResource());
} else if (options.has(OPT_ID)) {
Integer id = (Integer)options.valueOf(OPT_ID);
- ResourceResponse resource = resourceApi.getResource(id, verbose, children);
+ ResourceResponse resource;
+ if (options.has(OPT_PARENT_PLATFORM)) {
+ resource = resourceApi.getPlatformResource(id, verbose, children);
+ } else {
+ resource = resourceApi.getResource(id, verbose, children);
+ }
+
checkSuccess(resource);
resources = new ResourcesResponse();

0 comments on commit fa97b00

Please sign in to comment.
Something went wrong with that request. Please try again.