Skip to content

Commit

Permalink
add additional state.apply convenience methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidd committed Sep 18, 2020
1 parent f14c2ff commit 587a5fd
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/main/java/com/suse/salt/netapi/calls/modules/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,53 @@ public static LocalCall<Object> showHighstate() {
new TypeToken<Object>(){});
}

/**
* Convenience method for state.apply for typical use.
* Set the "queue" parameter to true and do not pass a "test" parameter.
*
* @param mods state modules
* @param pillar pillar data
* @return LocalCall<Map<String, ApplyResult>> result
*/
public static LocalCall<Map<String, ApplyResult>> apply(List<String> mods, Optional<Map<String, Object>> pillar) {
return com.suse.salt.netapi.calls.modules.State.apply(mods, pillar, Optional.of(true), Optional.empty());
}

/**
* Method which accepts Class type and return result after parsing actual json to that particular class
* instead of ApplyResult
* @param mods state modules
* @param pillar pillar data
* @param queue add to the queue
* @param test if run in test mode
* @param returnType return type
* @param <R> R
* @return LocalCall<R> result
*/
public static <R> LocalCall<R> apply(List<String> mods, Optional<Map<String, Object>> pillar,
Optional<Boolean> queue, Optional<Boolean> test, Class<R> returnType) {
return apply(mods, pillar, queue, test, TypeToken.get(returnType));
}
/**
* Method which accepts TypeToken and return result after parsing actual json to that particular class
* instead of ApplyResult
* @param mods state modules
* @param pillar pillar data
* @param queue add to the queue
* @param test if run in test mode
* @param returnType return type
* @param <R> R
* @return LocalCall<R> result
*/
public static <R> LocalCall<R> apply(List<String> mods, Optional<Map<String, Object>> pillar,
Optional<Boolean> queue, Optional<Boolean> test,
TypeToken<R> returnType) {
Map<String, Object> kwargs = new LinkedHashMap<>();
kwargs.put("mods", mods);
pillar.ifPresent(p -> kwargs.put("pillar", p));
queue.ifPresent(q -> kwargs.put("queue", q));
test.ifPresent(t -> kwargs.put("test", t));
return new LocalCall<>("state.apply", Optional.empty(), Optional.of(kwargs), returnType);
}

}

0 comments on commit 587a5fd

Please sign in to comment.