-
Notifications
You must be signed in to change notification settings - Fork 104
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
Stop hard-coding underscore in clone names #93
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,9 @@ public class vSphereCloudSlaveTemplate implements Describable<vSphereCloudSlaveT | |
protected static final SchemeRequirement HTTP_SCHEME = new SchemeRequirement("http"); | ||
protected static final SchemeRequirement HTTPS_SCHEME = new SchemeRequirement("https"); | ||
|
||
private final String cloneNamePrefix; | ||
private int configVersion; | ||
private static final int CURRENT_CONFIG_VERSION = 1; | ||
private String cloneNamePrefix; // almost final | ||
private final String masterImageName; | ||
private Boolean useSnapshot; // almost final | ||
private final String snapshotName; | ||
|
@@ -148,6 +150,7 @@ public vSphereCloudSlaveTemplate(final String cloneNamePrefix, | |
final RetentionStrategy<?> retentionStrategy, | ||
final List<? extends NodeProperty<?>> nodeProperties, | ||
final List<? extends VSphereGuestInfoProperty> guestInfoProperties) { | ||
this.configVersion = CURRENT_CONFIG_VERSION; | ||
this.cloneNamePrefix = cloneNamePrefix; | ||
this.masterImageName = masterImageName; | ||
this.snapshotName = snapshotName; | ||
|
@@ -349,6 +352,38 @@ protected Object readResolve() { | |
LOGGER.log(Level.CONFIG, " - Failed to reconfigure strategy", ex); | ||
} | ||
} | ||
// Earlier versions of the code may have stored configuration in a | ||
// different way but in the same kind of fields, so we need an explicit | ||
// versioning to know how to mutate the data. | ||
if( configVersion<=0) { | ||
LOGGER.log(Level.CONFIG, | ||
"{0} loaded old configuration that had hard-coded underscore at the end of the cloneNamePrefix.", | ||
this); | ||
// In version one, the underscore was removed from the code so we | ||
// have to put it in the data (the user is then free to change it to | ||
// something else if they want to). | ||
this.cloneNamePrefix = this.cloneNamePrefix + "_"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no guarantees.
In an ideal world, we'd have some sort of "post deserialization fix-up" at the cloud level that ensured that, within the vSphereCloud, the prefix was non-null, non-empty and unique for each template, but I'm not 100% sure where that code would have to go / get-called-from in order to make it work in all situations. |
||
configVersion = 1; | ||
} | ||
// Note: Subsequent changes dependent on configVersion should go above | ||
// this line. | ||
if (configVersion < CURRENT_CONFIG_VERSION) { | ||
throw new IllegalStateException("Internal error: configVersion==" + configVersion | ||
+ " at end of readResolve method, but the current config version should be " | ||
+ CURRENT_CONFIG_VERSION | ||
+ ". Either CURRENT_CONFIG_VERSION is incorrect or the readResolve method is not setting configVersion when it upgrades the data."); | ||
} | ||
if( configVersion > CURRENT_CONFIG_VERSION ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: paren spacing |
||
LOGGER.log(Level.WARNING, | ||
"{0} was defined by a later version of the plugin " | ||
+ "(one that saved with configVersion={1}, whereas this version of the plugin is expecting {2}). " | ||
+ "The code may not function as expected.", | ||
new Object[]{ | ||
this, | ||
configVersion, | ||
CURRENT_CONFIG_VERSION | ||
}); | ||
} | ||
return this; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<div> | ||
Controls the name by which the virtual machine will be known to vSphere. | ||
The plug-in will append an underscore and a unique ID to this prefix in order to generate unique names.<p> | ||
The plug-in will append a unique ID to this prefix in order to generate unique names.<p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HTML nit (maybe applies throughout) -- do this
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I'm not much of a fan of putting formatting/layout elements at the start/end of lines that contain content. I prefer to keep layout and content on their own lines. e.g. <p>
stuff
</p>
<p>
more stuff
</p> However, I did try wrapping the first line of text (line 2 in the file) in I suspect that the HTML generated by Jenkins to wrap the help text was designed more for "simple text" than HTML containing lots of layout formatting. I suspect that it was designed to make things "look right" if they start and end with no vertical whitespace. I'm not an HTML expert, so I did ...also (a brief google later), doing I'm open to ideas but unless we can settle on something that's both "good HTML practice" and also "looks correct when rendered" then I think it may be best to leave that code as-is. |
||
Note: You must ensure that no virtual machines (other than those created by this template) have names starting with this prefix. | ||
</p> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: inconsistent parens (looks like this project generally goes for the standard-ish
if (...) {
with space after the if and space after the close paren.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm quite happy with nit-picking comments; I'll sort those out - I dislike messy/inconsistent code too.