-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement Match module functions #116
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.suse.saltstack.netapi.calls.modules; | ||
|
||
import com.google.gson.reflect.TypeToken; | ||
import com.suse.saltstack.netapi.calls.LocalCall; | ||
|
||
import java.util.Arrays; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* salt.modules.match | ||
*/ | ||
public class Match { | ||
|
||
public static LocalCall<Boolean> compound(String tgt, Optional<String> minionId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not make sense to document the module functions since they are already documented on the salt side. The variable names are borrowed from the documentation page as well to keep it consistent. The only thing that may vary is the types if we can provide something saner on the java side. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes sense to have a simple javadoc, what will popup in the IDE, so everyone can see it while programming. I don't know what means "tgt". Inability to write "target"? That Goofy Thing? Tyrese, Ginuwine and Tank R&B singers?.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if we provide documentation it would be mostly copied from the salt docs and would not be precise since our library may work with different versions of the module which could have slightly different but documented behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably don't need to document it so much as in Salt, but at least you could say in one sentence what it is, what is return and what are params. I bet your IDE cries for it and checkstyle hates you for this. 😉 |
||
LinkedHashMap<String, Object> args = new LinkedHashMap<>(); | ||
args.put("tgt", tgt); | ||
minionId.ifPresent(id -> args.put("minion_id", id)); | ||
return new LocalCall<>("match.compound", Optional.empty(), | ||
Optional.of(args), new TypeToken<Boolean>(){}); | ||
} | ||
|
||
public static LocalCall<Boolean> compound(String tgt) { | ||
return compound(tgt, Optional.empty()); | ||
} | ||
|
||
public static LocalCall<Boolean> glob(String tgt, Optional<String> minionId) { | ||
LinkedHashMap<String, Object> args = new LinkedHashMap<>(); | ||
args.put("tgt", tgt); | ||
minionId.ifPresent(id -> args.put("minion_id", id)); | ||
return new LocalCall<>("match.glob", Optional.empty(), | ||
Optional.of(args), new TypeToken<Boolean>(){}); | ||
} | ||
|
||
public static LocalCall<Boolean> glob(String tgt) { | ||
return glob(tgt, Optional.empty()); | ||
} | ||
|
||
public static LocalCall<Boolean> grain(String tgt, Optional<String> delimiter) { | ||
LinkedHashMap<String, Object> args = new LinkedHashMap<>(); | ||
args.put("tgt", tgt); | ||
delimiter.ifPresent(d -> args.put("delimiter", d)); | ||
return new LocalCall<>("match.grain", Optional.empty(), | ||
Optional.of(args), new TypeToken<Boolean>(){}); | ||
} | ||
|
||
public static LocalCall<Boolean> list(List<String> tgt, Optional<String> minionId) { | ||
LinkedHashMap<String, Object> args = new LinkedHashMap<>(); | ||
args.put("tgt", tgt.stream().collect(Collectors.joining(","))); | ||
minionId.ifPresent(id -> args.put("minion_id", id)); | ||
return new LocalCall<>("match.list", Optional.empty(), | ||
Optional.of(args), new TypeToken<Boolean>(){}); | ||
} | ||
|
||
public static LocalCall<Boolean> list(String... tgt) { | ||
return list(Arrays.asList(tgt), Optional.empty()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, @renner suggests to have at least have a documentation for the whole class with the URL link to it. Maybe Johannes will write more here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will open a separate issue to track the documentation of the modules where we also can discuss what to do. In any case adding documentation should be done in a separate PR that covers all modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening the issue, @lucidd! From my perspective there is no need to add javadoc for the
Match
module class within this patch, especially I wouldn't want to copy it from the salt documentation for the reasons mentioned in #117. For now let's just do it as the other module classes we already have, i.e. keep it as it is.