Skip to content
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

Add ConfigRecognizer API #16958

Merged
merged 3 commits into from Jun 26, 2020

Conversation

blazember
Copy link
Contributor

@blazember blazember commented May 5, 2020

This commit introduces the ConfigRecognition API that is meant to
recognize if a provided declarative configuration is recognized by the
rules defined in a given implementation. The main use case for this
implementation is to recognize member, client and failover client XML
and YAML configurations just by looking into the content of the
configuration, without building any actual configuration.

Along with the API the following three implementations are added:

  • MemberConfigRecognizer for recognizing member XML and YAML
    configurations
  • ClientConfigRecognizer for recognizing client XML and YAML
    configurations
  • ClientFailoverConfigRecognizer for recognizing failover client XML and
    YAML configurations

All the three are extensible with custom recognizers so that even those
configurations can be recognized that would otherwise remain
unrecognized with the built-in set of recognizers that recognizes XML
and YAML configurations by checking the root node in the provided
configuration.

The API recognizes configuration provided in InputStreams only, while
the ConfigBuilder implementations can be built from files defined by
their location and URLs too. The reason for lacking the support for
these two options is that both are easy to convert to InputStreams and
that handling errors caused by non-existing resources, missing
privileges etc should be handled outside of this API with potentially
having more contextual information.

The built-in implementations honor parse errors with unrecognized
configuration. The reason is that the provided InputStream can be tested
both for XML and YAML configuration and at least one is expected to
lead to parse errors.

Implements #16866

This commit introduces the ConfigRecognition API that is meant to
recognize if a provided declarative configuration is recognized by the
rules defined in a given implementation. The main use case for this
implementation is to recognize member, client and failover client XML
and YAML configurations just by looking into the content of the
configuration, without building any actual configuration.

Along with the API the following three implementations are added:
- MemberConfigRecognizer for recognizing member XML and YAML
configurations
- ClientConfigRecognizer for recognizing client XML and YAML
configurations
- ClientFailoverConfigRecognizer for recognizing failover client XML and
YAML configurations

All the three are extensible with custom recognizers so that even those
configurations can be recognized that would otherwise remain
unrecognized with the built-in set of recognizers that recognizes XML
and YAML configurations by checking the root node in the provided
configuration.

The API recognizes configuration provided in InputStreams only, while
the ConfigBuilder implementations can be built from files defined by
their location and URLs too. The reason for lacking the support for
these two options is that both are easy to convert to InputStreams and
that handling errors caused by non-existing resources, missing
privileges etc should be handled outside of this API with potentially
having more contextual information.

The built-in implementations honour parse errors with unrecognized
configuration. The reason is that the provided InputStream can be tested
both for XML and YAML configuration and at least one is expected to
lead to parse errors.

Implements hazelcast#16866
@blazember blazember changed the title Config type distinction API Add ConfigRecognizer API May 11, 2020
@blazember blazember marked this pull request as ready for review May 12, 2020 08:13
@blazember blazember requested a review from a team as a code owner May 12, 2020 08:13
@hazelcast hazelcast deleted a comment May 12, 2020
@mmedenjak mmedenjak added the Source: Internal PR or issue was opened by an employee label May 12, 2020
boolean recognized = false;
for (ConfigRecognizer recognizer : recognizers) {
configStream.reset();
recognized = recognized || recognizer.isRecognized(configStream);
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: can we exit early if it was recognized?

Copy link
Contributor

@mmedenjak mmedenjak left a comment

Choose a reason for hiding this comment

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

Looks really nice 💯

@mmedenjak mmedenjak merged commit 7d63cfd into hazelcast:master Jun 26, 2020
@blazember blazember deleted the 4.1/config/distinction-api branch June 26, 2020 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants