Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3212 from oleg-nenashev/bug/JENKINS-48761-remotin…
…g-API [JENKINS-48761] - Restore binary compatibility with agents running old Remoting versions
- Loading branch information
Showing
11 changed files
with
363 additions
and
8 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
core/src/filter/resources/jenkins/slaves/remoting-info.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Remoting version, which is embedded into the core | ||
# This version MAY differ from what is really classloaded (see the "Pluggable Core Components", JENKINS-41196) | ||
remoting.embedded.version=${remoting.version} | ||
|
||
# Minimum Remoting version on external agents which is supported by the core | ||
remoting.minimum.supported.version=${remoting.minimum.supported.version} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
core/src/main/java/jenkins/slaves/RemotingVersionInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2018, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package jenkins.slaves; | ||
|
||
import hudson.util.VersionNumber; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
// TODO: Make the API public (JENKINS-48766) | ||
/** | ||
* Provides information about Remoting versions used within the core. | ||
* @author Oleg Nenashev | ||
*/ | ||
@Restricted(NoExternalUse.class) | ||
public class RemotingVersionInfo { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(RemotingVersionInfo.class.getName()); | ||
private static final String RESOURCE_NAME="remoting-info.properties"; | ||
|
||
@CheckForNull | ||
private static VersionNumber EMBEDDED_VERSION; | ||
|
||
@CheckForNull | ||
private static VersionNumber MINIMUM_SUPPORTED_VERSION; | ||
|
||
private RemotingVersionInfo() {} | ||
|
||
static { | ||
Properties props = new Properties(); | ||
try (InputStream is = RemotingVersionInfo.class.getResourceAsStream(RESOURCE_NAME)) { | ||
if(is!=null) { | ||
props.load(is); | ||
} | ||
} catch (IOException e) { | ||
LOGGER.log(Level.WARNING, "Failed to load Remoting Info from " + RESOURCE_NAME, e); | ||
} | ||
|
||
EMBEDDED_VERSION = tryExtractVersion(props, "remoting.embedded.version"); | ||
MINIMUM_SUPPORTED_VERSION = tryExtractVersion(props, "remoting.minimum.supported.version"); | ||
} | ||
|
||
@CheckForNull | ||
private static VersionNumber tryExtractVersion(@Nonnull Properties props, @Nonnull String propertyName) { | ||
String prop = props.getProperty(propertyName); | ||
if (prop == null) { | ||
LOGGER.log(Level.FINE, "Property {0} is not defined in {1}", new Object[] {propertyName, RESOURCE_NAME}); | ||
return null; | ||
} | ||
|
||
if(prop.contains("${")) { // Due to whatever reason, Maven does not nullify them | ||
LOGGER.log(Level.WARNING, "Property {0} in {1} has unresolved variable(s). Raw value: {2}", | ||
new Object[] {propertyName, RESOURCE_NAME, prop}); | ||
return null; | ||
} | ||
|
||
try { | ||
return new VersionNumber(prop); | ||
} catch (RuntimeException ex) { | ||
LOGGER.log(Level.WARNING, String.format("Failed to parse version for for property %s in %s. Raw Value: %s", | ||
propertyName, RESOURCE_NAME, prop), ex); | ||
return null; | ||
} | ||
} | ||
|
||
@CheckForNull | ||
public static VersionNumber getEmbeddedVersion() { | ||
return EMBEDDED_VERSION; | ||
} | ||
|
||
@CheckForNull | ||
public static VersionNumber getMinimumSupportedVersion() { | ||
return MINIMUM_SUPPORTED_VERSION; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
core/src/test/java/jenkins/slaves/RemotingVersionInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2018, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package jenkins.slaves; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* Tests for {@link RemotingVersionInfo}. | ||
*/ | ||
public class RemotingVersionInfoTest { | ||
|
||
@Test | ||
public void shouldLoadEmbeddedVersionByDefault() { | ||
assertThat("Remoting Embedded version is not defined", | ||
RemotingVersionInfo.getEmbeddedVersion(), notNullValue()); | ||
} | ||
|
||
@Test | ||
public void shouldLoadMinimumSupportedVersionByDefault() { | ||
assertThat("Remoting Minimum supported version is not defined", | ||
RemotingVersionInfo.getMinimumSupportedVersion(), notNullValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.