Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Refactor duplicated code in SubmitterMain and SchedulerConfig #1599

Merged
merged 1 commit into from
Dec 8, 2016

Conversation

mycFelix
Copy link
Contributor

@mycFelix mycFelix commented Dec 8, 2016

As #1597 mentioned, the duplicated code is found in SubmitterMain and SchedulerConfig.

This PR is trying to fix it and the changes are following:

  • add an new method String getPkgType(String topologyBinaryFile) in FileUtils
  • invoke getPkgType method in SubmitterMain
  • invoke getPkgType method in SchedulerConfig

@objmagic
Copy link
Contributor

objmagic commented Dec 8, 2016

👍

@objmagic objmagic merged commit bc5f873 into apache:master Dec 8, 2016
@objmagic objmagic changed the title Remove duplicated code in SubmitterMain and SchedulerConfig Refactor duplicated code in SubmitterMain and SchedulerConfig Dec 8, 2016
@objmagic objmagic added this to the 0.15.0 milestone Dec 8, 2016
@@ -123,4 +123,17 @@ public static boolean isOriginalPackagePex(String packageFilename) {
public static String getBaseName(String file) {
return new File(file).getName();
}

public static String getPkgType(String topologyBinaryFile) {
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 removal of dup code!

Could you also please change to not abbreviate pkg (e.g., packageType and getPackageType).

Also instead of returning strings, better to use an enum, maybe as an inner enum in FileUtils:

enum PackageType {
  PEX,
  JAR,
  TAR
}

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for merging this too fast. I'll do this.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, returning enum might not be what we want, since we need to put value as string into config. See: https://github.com/twitter/heron/pull/1599/files#diff-1043de1ec8f8e4c0194d4e6035e654cfL80

Copy link
Contributor

Choose a reason for hiding this comment

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

Config.put takes an object as it's value, so we could put enum values in and add a getter that returns it. We did this with ByteAmount for example:

https://github.com/twitter/heron/blob/master/heron/spi/src/java/com/twitter/heron/spi/common/Config.java#L79

Then we refactor all consumers to use the enum.

The only catch is that if we add the helper to Config, then the enum needs to live somewhere central like in spi. This might not be a bad thing though. It's much better to have a strong set of package types than to pass strings around...

Copy link
Contributor

Choose a reason for hiding this comment

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

where do you think is appropriate to put this? I am really bad at finding an appropriate class to add code😔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@objmagic - hi, Is there anything I could do? The method name which @billonahill mentioned is better . However, I don't think adding an new enum class is a good idea. Perhaps we could add new static constants in FileUtils instead of handling string variable explicitly, for example

private static final String PEX = "pex";

Copy link
Contributor

@objmagic objmagic Dec 9, 2016

Choose a reason for hiding this comment

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

@mycFelix any reason why using enum is not a good idea?

Copy link
Contributor Author

@mycFelix mycFelix Dec 9, 2016

Choose a reason for hiding this comment

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

@objmagic - Cause String pkgType is used for Config's value. Just in my opion, this scene is applicable to the principle of Occam's razor -- If not necessary, do not increase the entity

Copy link
Contributor

Choose a reason for hiding this comment

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

Config supports objects and we should favor type safety where ever possible. Doing so will make code easier to maintain and less prone to bugs than by passing string values around.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mycFelix imo Bill has better arguments. I will submit a PR to use enum.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants