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

[STORM-3004] storm-elasticsearch-examples: fixed all checkstyle warnings #2596

Merged
merged 1 commit into from
Mar 28, 2018
Merged

[STORM-3004] storm-elasticsearch-examples: fixed all checkstyle warnings #2596

merged 1 commit into from
Mar 28, 2018

Conversation

krichter722
Copy link
Contributor

@krichter722 krichter722 commented Mar 19, 2018

I'd like to share my hands-on reflection on whether it makes sense to take over you checkstyle-config for some of my projects. The approx. 100 violations cost about 1,5h to fix which seems a realistic indicator for the time needed for similar fixes.

@srdo
Copy link
Contributor

srdo commented Mar 23, 2018

@krichter722 Thanks for the fixes. I'll review this as soon as I can. In the meantime, could you raise issues on https://issues.apache.org/jira to track your changes? It makes it easier for us to track which branches fixes have been applied to, and we use the JIRA issues to generate release notes. Please also rename the PR and commit to contain the JIRA issue number. Thanks :)

@krichter722 krichter722 changed the title storm-elasticsearch-examples: fixed all checkstyle warnings [STORM-3004] storm-elasticsearch-examples: fixed all checkstyle warnings Mar 24, 2018
Copy link
Contributor

@srdo srdo left a comment

Choose a reason for hiding this comment

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

Looks pretty good, left some comments. My only real concern is that I feel like some of the comments don't really help understand the code, because they're documenting e.g. field X with "The X", which seems redundant.

@@ -34,52 +39,128 @@
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Values;

public class EsIndexTopology {
/**
* Demonstrates an ElasticSearch Strom topology.
Copy link
Contributor

Choose a reason for hiding this comment

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

Strom -> Storm

public class EsIndexTopology {
/**
* Demonstrates an ElasticSearch Strom topology.
* @author unknown
Copy link
Contributor

Choose a reason for hiding this comment

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

We generally don't use @author in the javadoc, it's just noise since most files are worked on by more than one person. Could you remove it here and elsewhere?


/**
* The id of the used spout.
*/
static final String SPOUT_ID = "spout";
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 these should be private, that way checkstyle hopefully won't complain about missing comments.

};
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Is checkstyle requiring these comments? If not I'd rather we don't have them. Comments that are just "The $variable_name" are just noise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the current setup requires comments on almost everything. I agree that they almost no use. Therefore this PR is a good usability check for the current extremely strict checkstyle configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

I checked, and checkstyle passes fine for me without these comments. As far as I can tell, comments are required on public classes, public methods that don't override supertype methods, and public constructors/variables.

For example, this file works for me with only comments on the EsIndexTopology class and the main method. All the others can be removed without violating the checkstyle check.

Does this not work for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, you're right, I was using the checkstyle:check target which apparently uses a much stricter set of rules which might be even different from the one configured to run in the validate phase. I'll remove the noisy comments on private fields and methods.

}

/**
* Processes the next tuple.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: nextTuple makes the spout emit the next tuple, if any.

*/
public final class TridentEsTopology {
/**
* The default batch size. Necessary in order to avoid magic number
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I don't think you need to mention why the field is here. Won't checkstyle complain if someone replaces the field with a magic number again?

@Override
public Fields getOutputFields() {
return new Fields("source", "index", "type", "id");
}

/**
* Open the topology.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Opens the spout, not the topology

}
for (List<Object> list : batch) {
collector.emit(list);
}
}

/**
* Acknoledges the message with id {@code msgId}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Acknowledges

if (batch == null) {
batch = new ArrayList<List<Object>>();
if (index >= outputs.length && cycle) {
if (index >= outputs.length && isCycle()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Doesn't seem like there's any reason to use the getter rather than referring to the field?

* Get the maximum batch size.
* @return the maxBatchSize
*/
public int getMaxBatchSize() {
Copy link
Contributor

Choose a reason for hiding this comment

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

A little unsure why we need these getters and setters?

@krichter722
Copy link
Contributor Author

I agree with all your comments and removed the TridentEsTopology.get/setMaxBatchSize. The noisy comments are required (see comment above). Thanks for the review.

Copy link
Contributor

@srdo srdo left a comment

Choose a reason for hiding this comment

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

Looks good pending the last two comments, +1 after that.

@@ -1,3 +1,4 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

This change seems unnecessary.

System.out.println("**** RESENDING FAILED TUPLE");
this.collector.emit(this.pending.get(msgId), msgId);
}
}

/**
* Utility constructor.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation, that makes sense. Could you change the comment to e.g. "Prevent instantiation" or something similar, so people who run across this later will know why it's there?

@HeartSaVioR
Copy link
Contributor

@krichter722 kindly reminder.

@krichter722
Copy link
Contributor Author

Last comments incorporated.

@srdo
Copy link
Contributor

srdo commented Mar 28, 2018

+1, thanks for being patient. @krichter722 could you add the issue number to the commit message, I'll merge after that. I'd add it myself, but then the PR won't show as merged.

@asfgit asfgit merged commit eb72603 into apache:master Mar 28, 2018
@srdo
Copy link
Contributor

srdo commented Mar 28, 2018

@krichter722 Thanks, merged to master. I also added you to the contributors list in JIRA, so you should be able to assign tasks to yourself now.

@krichter722 krichter722 deleted the checkstyle-fix-es-examples branch May 12, 2018 21:20
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