Skip to content

NIFI-9967: Added FlowSerializationStrategy to determine which flow formats (XML,JSON) to save#6001

Closed
mattyb149 wants to merge 2 commits intoapache:mainfrom
mattyb149:NIFI-9967
Closed

NIFI-9967: Added FlowSerializationStrategy to determine which flow formats (XML,JSON) to save#6001
mattyb149 wants to merge 2 commits intoapache:mainfrom
mattyb149:NIFI-9967

Conversation

@mattyb149
Copy link
Contributor

Description of PR

Adds a FlowSerializationStrategy enum to determine whether to save the flow in XML and/or JSON formats. NiFi saves both, MiNiFi saves only the XML version (as this is what is overwritten by config.yml)

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically main)?

  • Is your initial contribution a single, squashed commit? Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not squash or use --force when pushing to allow for clean monitoring of changes.

For code changes:

  • Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
  • Have you written or updated unit tests to verify your changes?
  • Have you verified that the full build is successful on JDK 8?
  • Have you verified that the full build is successful on JDK 11?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
  • If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
  • If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check GitHub Actions CI for build issues and submit an update to your PR as soon as possible.

Copy link
Contributor

@simonbence simonbence left a comment

Choose a reason for hiding this comment

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

Some minimal remarks, otherwise it looks good to me.

package org.apache.nifi.controller;

public enum FlowSerializationStrategy {
WRITE_XML,
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor suggestion: according to the WRITE_XML_AND_JSON value and the usage, we do not plan to use this like having a set of possible strategies, but always using only a single value. As of this, I would suggest to name the values like WRITE_XML_ONLY, and WRITE_JSON_ONLY.


saveJson(controller, archive);
saveXml(controller, archive);
if (serializationStrategy == FlowSerializationStrategy.WRITE_JSON || serializationStrategy == FlowSerializationStrategy.WRITE_XML_AND_JSON) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be useful to encapsulate the decision logic within the enum. The FlowSerializationStrategy could have a writesJSON and a writesXML methods with boolean return values. By this, the condition would change simply to serializationStrategy.writesJSON() and serializationStrategy.writesXML() accordingly.


return new StandardFlowService(controller, nifiProperties, senderListener, encryptor, true, coordinator, revisionManager, authorizer);
return new StandardFlowService(controller, nifiProperties, senderListener, encryptor, true, coordinator, revisionManager, authorizer,
FlowSerializationStrategy.WRITE_XML_AND_JSON);
Copy link
Contributor

Choose a reason for hiding this comment

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

Due to simmerty and having the same responsibilities for standalone and clustered methods, I would add an argument for this as well. As I found, it is callled only in the StandardFlowServiceFactoryBean, and the used enum might be specified there (like in case of standalone)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only NiFi itself runs in clustered mode, the reason we have an extra argument in the standalone instance is for MiNiFi, which needs WRITE_XML_ONLY and calls getStandaloneInstance() directly (not via Spring)

Copy link
Contributor

@bejancsaba bejancsaba left a comment

Choose a reason for hiding this comment

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

+1 from me I just had a minor enum structuring related proposal. Thanks for the change, the issue came up at our current minifi c2 work as well.

*/
package org.apache.nifi.controller;

public enum FlowSerializationStrategy {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is just syntactical but maybe better to read (but this could be really subjective), what do you think about:

public enum FlowSerializationStrategy {
    WRITE_XML_ONLY(false, true),
    WRITE_JSON_ONLY(true, false),
    WRITE_XML_AND_JSON(true, true);

    private final boolean writesJson;
    private final boolean writesXml;

    FlowSerializationStrategy(boolean writesJson, boolean writesXml) {
        this.writesJson = writesJson;
        this.writesXml = writesXml;
    }

    public boolean writesJson() {
        return writesJson;
    }

    public boolean writesXml() {
        return writesXml;
    }
}

Copy link
Contributor

@kevdoran kevdoran left a comment

Choose a reason for hiding this comment

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

I don't have any objection to this, and it is a small change that fixes key functionality, so overall I'm a +1.

That said, I hope that eventually we can move minifi to using our VersionedFlowSnapshot JSON format everywhere (in C2, in place of config.yml, in place of flow/xml.gz) which I feel will simplify a lot of the codebase in places where we have to deal with different formats.

@kevdoran kevdoran closed this in bd1e033 May 16, 2022
asfgit pushed a commit that referenced this pull request May 20, 2022
…rmats (XML,JSON) to save

This closes #6001.

Signed-off-by: Kevin Doran <kdoran@apache.org>
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.

4 participants