Skip to content
Permalink
Browse files

[JENKINS-47589] Better details of the database status for better trou…

…bleshooting (#106)

[JENKINS-47589] Better details of the database status for better troubleshooting
  • Loading branch information
Cyrille Le Clerc
Cyrille Le Clerc committed Oct 23, 2017
1 parent 6e52f01 commit 291aa5bafb3663547ee17a2b9c4b72f485733042
@@ -113,4 +113,9 @@ void recordGeneratedArtifact(@Nonnull String jobFullName, int buildNumber,
* Routine task to cleanup the database and reclaim disk space (if possible in the underlying database).
*/
void cleanup();

/**
* Human readable toString
*/
String toPrettyString();
}
@@ -484,4 +484,37 @@ protected synchronized void testDatabase() throws RuntimeSqlException {

return results;
}

@Override
public String toPrettyString() {
List<String> prettyStrings = new ArrayList<>();
try (Connection cnn = jdbcConnectionPool.getConnection()) {
prettyStrings.add("jdbc.url: " + cnn.getMetaData().getURL());
List<String> tables = Arrays.asList("MAVEN_ARTIFACT", "JENKINS_JOB", "JENKINS_BUILD", "MAVEN_DEPENDENCY", "GENERATED_MAVEN_ARTIFACT");
for (String table : tables) {
try (Statement stmt = cnn.createStatement()) {
try (ResultSet rst = stmt.executeQuery("SELECT count(*) FROM " + table)) {
if (rst.next()) {
int count = rst.getInt(1);
prettyStrings.add("Table " + table + ": " + count + " rows");
} else {
prettyStrings.add("Table " + table + ": #IllegalStateException 'select count(*)' didn't return any row#");
}
}
} catch (SQLException e) {
prettyStrings.add("Table " + table + ": "+ e);
LOGGER.log(Level.WARNING, "SQLException counting rows on " + table, e);
}
}
} catch (SQLException e) {
prettyStrings.add("SQLException getting a connection to " + jdbcConnectionPool + ": " + e);
LOGGER.log(Level.WARNING, "SQLException getting a connection to " + jdbcConnectionPool, e);
}

StringBuilder result = new StringBuilder("PipelineMavenPluginH2Dao ");
for (String prettyString : prettyStrings) {
result.append("\r\n\t" + prettyString);
}
return result.toString();
}
}
@@ -68,4 +68,9 @@ public void deleteBuild(String jobFullName, int buildNumber) {
public void cleanup() {

}

@Override
public String toPrettyString() {
return "PipelineMavenPluginNullDao";
}
}
@@ -27,6 +27,9 @@ THE SOFTWARE.
xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:section title="${%Pipeline Maven Configuration}">
<f:entry title="${%DAO}">
<pre><code>${instance.dao.toPrettyString()}</code></pre>
</f:entry>
<f:entry title="${%Trigger downstream upon result}" field="triggerDownstreamUponResult" >
<f:checkbox title="${%Success}" field="triggerDownstreamUponResultSuccess" default="true" />
<f:checkbox title="${%Unstable}" field="triggerDownstreamUponResultUnstable" />
@@ -38,6 +41,7 @@ THE SOFTWARE.
<f:repeatableHeteroProperty field="publisherOptions" targetType="org.jenkinsci.plugins.pipeline.maven.MavenPublisher"
addCaption="${%Add Publisher Options}" hasHeader="true" oneEach="true"/>
</f:entry>
</f:section>

</f:section>

</j:jelly>

0 comments on commit 291aa5b

Please sign in to comment.
You can’t perform that action at this time.