Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'hqapi-2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Morgan committed Feb 3, 2010
2 parents b47744b + e9dac39 commit a28f75e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Expand Up @@ -49,6 +49,9 @@ Changes in HQApi 3.0

Changes in HQApi 2.4

*) [HHQ-3709] Allow group syncing via command line arguments to include
child resources.

*) [HHQ-3664] Increase application update/create by not using Groovy's
Collection.minus() and pre-fetch the application inventory prior to the
session being marked read-write.
Expand Down
24 changes: 21 additions & 3 deletions src/org/hyperic/hq/hqapi1/tools/GroupCommand.java
Expand Up @@ -67,6 +67,7 @@ public class GroupCommand extends Command {
private static String OPT_REGEX = "regex";
private static String OPT_DELETEMISSING = "deleteMissing";
private static String OPT_DESC = "description";
private static String OPT_CHILDREN = "children";

private void printUsage() {
System.err.println("One of " + Arrays.toString(COMMANDS) + " required");
Expand Down Expand Up @@ -136,6 +137,8 @@ private void sync(String[] args) throws Exception {
p.accepts(OPT_COMPAT, "If specified, attempt to make the group compatible");
p.accepts(OPT_DESC, "If specified, set the description for the group").
withRequiredArg().ofType(String.class);
p.accepts(OPT_CHILDREN, "If specified, include child resources of the " +
"specified prototype and regex");

OptionSet options = getOptions(p, args);

Expand All @@ -159,6 +162,19 @@ private void sync(String[] args) throws Exception {
System.out.println("Successfully synced " + groups.size() + " groups.");
}

// Helper function to unroll a resource and it's children into a single list.
private List<Resource> getFlattenResources(List<Resource> resources) {
List<Resource> result = new ArrayList<Resource>();

for (Resource r : resources) {
result.add(r);
if (r.getResource().size() > 0) {
result.addAll(getFlattenResources(r.getResource()));
}
}
return result;
}

private void syncViaCommandLineArgs(OptionSet s) throws Exception
{
// Required args
Expand All @@ -169,6 +185,7 @@ private void syncViaCommandLineArgs(OptionSet s) throws Exception
String regex = (String)s.valueOf(OPT_REGEX);
boolean deleteMissing = s.has(OPT_DELETEMISSING);
boolean compatible = s.has(OPT_COMPAT);
boolean children = s.has(OPT_CHILDREN);

HQApi api = getApi(s);

Expand All @@ -179,7 +196,7 @@ private void syncViaCommandLineArgs(OptionSet s) throws Exception

// Query resources
ResourcesResponse resourceResponse = api.getResourceApi().
getResources(protoResponse.getResourcePrototype(), false, false);
getResources(protoResponse.getResourcePrototype(), false, children);
checkSuccess(resourceResponse);

List<Resource> resources = resourceResponse.getResource();
Expand Down Expand Up @@ -222,8 +239,9 @@ private void syncViaCommandLineArgs(OptionSet s) throws Exception
if (s.hasArgument(OPT_DESC)) {
group.setDescription((String)s.valueOf(OPT_DESC));
}

group.getResource().addAll(resources);

List<Resource> flattenedResources = getFlattenResources(resources);
group.getResource().addAll(flattenedResources);
List<Group> groups = new ArrayList<Group>();
groups.add(group);
GroupsResponse syncResponse = api.getGroupApi().syncGroups(groups);
Expand Down

0 comments on commit a28f75e

Please sign in to comment.