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
Check availability of Jenkins #434
Changes from 2 commits
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 |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.ConnectException; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
@@ -58,6 +59,8 @@ public final class DownloadUtils { | |
|
||
private static final Logger logger = LoggerFactory.getLogger(DownloadUtils.class); | ||
|
||
private static final String JENKINS_URL = "http://jenkins.terasology.org"; | ||
private static final int JENKINS_TIMEOUT = 3000; // milliseconds | ||
private static final String JENKINS_JOB_URL = "http://jenkins.terasology.org/job/"; | ||
private static final String LAST_STABLE_BUILD = "/lastStableBuild"; | ||
private static final String LAST_SUCCESSFUL_BUILD = "/lastSuccessfulBuild"; | ||
|
@@ -188,6 +191,25 @@ public static URL createUrlJenkins(String jobName, int buildNumber, String subPa | |
return new URL(urlBuilder.toString()); | ||
} | ||
|
||
public static boolean isJenkinsAvailable() { | ||
logger.trace("Checking Jenkins availability..."); | ||
try { | ||
HttpURLConnection conn = (HttpURLConnection) new URL(JENKINS_URL).openConnection(); | ||
try (AutoCloseable ac = conn::disconnect) { | ||
conn.setConnectTimeout(JENKINS_TIMEOUT); | ||
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { | ||
logger.trace("Jenkins is available at {}", JENKINS_URL); | ||
return true; | ||
} else { | ||
throw new ConnectException(); | ||
} | ||
} | ||
} catch (Exception e) { | ||
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. Please try to catch the most specific type of exception you can, e.g., For instance, a |
||
logger.warn("Could not connect to Jenkins at {}", JENKINS_URL); | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Get the build number of the last stable build on the Jenkins server. | ||
* <p> | ||
|
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.
3 seconds might be a bit too small, but let's keep it for now - we can still adjust this value later.