Skip to content

Support additional target types - #226

Merged
lucidd merged 14 commits into
SUSE:masterfrom
amendlik:target-types
Jan 19, 2018
Merged

lucidd merged 14 commits into
SUSE:masterfrom
amendlik:target-types

Conversation

@amendlik

Copy link
Copy Markdown
Contributor

This PR addresses #103 by adding support for the following target types:

  • pcre
  • grain_pcre
  • pillar
  • pillar_exact
  • pillar_pcre
  • range
  • compound
  • ipcidr

It also adds support for special delimiters (other than :) in grain and pillar targets, and their variants.

@lucidd lucidd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey thanks for this Contribution. The PR looks good in general i just added some comments for things that could be simplified a bit.

*
* @param <T> The data type of the target class
*/
abstract class AbstractTarget<T> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractTarget seems to be similar to Target i think we could get rid of the interface and rename the AbstractTarget to Target.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each target type expresses its compatibility with the local client or ssh client with a declaration like this:

public class Glob extends AbstractTarget<String> implements Target<String>, SSHTarget<String>

I'm not sure that would continue to work if we change the interfaces to base classes. Can you suggest a solution?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. This does not seem that easy after all. I think its ok to leave it like that for now. 👍


protected final T target;

protected AbstractTarget(T target) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not also take the TargetType as parameter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! I'll change that.


protected final DictionaryTargetExpression expr;

public DictionaryTarget(DictionaryTargetExpression expr) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DictionaryTarget and DictionaryTargetExpression seems a bit much i wonder if we could just move all the functionality in DictionaryTarget.

@amendlik amendlik Jan 16, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what I had in 40efc77. I moved to DictionaryTargetExpression because I found I was duplicating a lot of code. You have 5 types that all take the same expression format, and each of them has 4 constructors. So I had 20 constructors that just called the base class constructor with the same arguments, and duplicated tests for all of these as well.

Is there a better way to solve that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a better way to solve that but at least those constructors won't have any logic in them so not much to get wrong. Its annoying to have this kind of boilerplate but i think its worth it if it improves usability of the API.

* Use {@link #Grains(DictionaryTargetExpression)} instead.
*/
@Deprecated
public Grains(String grain, String value) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a constructor like this is more convenient to use then having to create a DictionaryTargetExpression.

@renner

renner commented Jan 16, 2018

Copy link
Copy Markdown
Member

Hey @amendlik, thanks again for contributing! There is a checkstyle error that was introduced with your latest commit:

[ERROR] /home/travis/build/SUSE/salt-netapi-client/src/main/java/com/suse/salt/netapi/datatypes/target/Glob.java:13:43: ',' is not followed by whitespace. [WhitespaceAfter]

@amendlik

Copy link
Copy Markdown
Contributor Author

I've made all the requested changes.

@renner renner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @amendlik, your patch looks good to me! There is a couple of javadoc warnings though (see here, just scroll to the end of the build log), would you mind to fix those before we merge?

@renner renner added this to the Version 0.14.0 milestone Jan 19, 2018
@lucidd
lucidd merged commit 6b10964 into SUSE:master Jan 19, 2018
@lucidd

lucidd commented Jan 19, 2018

Copy link
Copy Markdown
Member

Hey thanks again for the contribution. I just merged your PR so it will be in the next release but until then you have to use a SNAPSHOT release if you want to work with your changes. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants