Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 committed Oct 23, 2017
1 parent 6e52f01 commit 291aa5b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
Expand Up @@ -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();
}
Expand Up @@ -484,4 +484,37 @@ public List<Map<String, String>> getGeneratedArtifacts(@Nonnull String jobFullNa

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();
}
}
Expand Up @@ -68,4 +68,9 @@ public List<String> listDownstreamJobs(@Nonnull String jobFullName, int buildNum
public void cleanup() {

}

@Override
public String toPrettyString() {
return "PipelineMavenPluginNullDao";
}
}
Expand Up @@ -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" />
Expand All @@ -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.