Fix issue with empty xml resulting in parse errors.
Improve version information.
This commit is contained in:
parent
c1c894d64e
commit
c5bde9c2f6
|
@ -17,7 +17,7 @@ pipelines:
|
|||
- gradle
|
||||
name: Build and Release
|
||||
script:
|
||||
- ./gradlew clean build shadowJar startShadowScripts buildRpm buildDeb
|
||||
- ./gradlew clean versionTxt build shadowJar startShadowScripts buildRpm buildDeb
|
||||
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/libs/*-all.jar ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done
|
||||
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/distributions/*.rpm ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done
|
||||
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/distributions/*.deb ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done
|
||||
|
|
21
build.gradle
21
build.gradle
|
@ -9,6 +9,7 @@ plugins {
|
|||
id 'jacoco'
|
||||
|
||||
id "com.github.johnrengelman.shadow" version "6.0.0"
|
||||
id "net.nemerosa.versioning" version "2.14.0"
|
||||
id "nebula.ospackage" version "8.4.1"
|
||||
}
|
||||
|
||||
|
@ -97,3 +98,23 @@ jacocoTestCoverageVerification {
|
|||
}
|
||||
}
|
||||
check.dependsOn jacocoTestCoverageVerification
|
||||
|
||||
|
||||
processResources.dependsOn.add("versionFile")
|
||||
versionFile {
|
||||
// Path to the file to be written
|
||||
file = new File(project.buildDir, 'resources/main/version.properties')
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
'Built-By' : System.properties['user.name'],
|
||||
'Build-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ").toString(),
|
||||
'Build-Revision' : versioning.info.commit,
|
||||
'Created-By' : "Gradle ${gradle.gradleVersion}",
|
||||
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
|
||||
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
id = hmci
|
||||
group = biz.nellemann.hmci
|
||||
version = 1.0.8
|
||||
|
|
|
@ -160,20 +160,33 @@ class App implements Runnable {
|
|||
}
|
||||
|
||||
|
||||
static String getVersion() {
|
||||
URL url = getClass().getResource("/version.properties");
|
||||
if (url == null) {
|
||||
return "No version.txt file found in the classpath."
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.load(url.openStream());
|
||||
return properties.getProperty("VERSION_GRADLE") + "-" + properties.getProperty("VERSION_BUILD")
|
||||
}
|
||||
|
||||
|
||||
static void main(String... args) {
|
||||
|
||||
def cli = new CliBuilder(name: "hmci")
|
||||
cli.h(longOpt: 'help', 'display usage')
|
||||
cli.v(longOpt: 'version', 'display version')
|
||||
cli.c(longOpt: 'config', args: 1, required: true, defaultValue: '/etc/hmci.groovy', 'configuration file')
|
||||
cli.h(longOpt: 'help', usageHelp: true, 'display usage information')
|
||||
cli.v(longOpt: 'version', versionHelp: true, 'display version information')
|
||||
cli.c(longOpt: 'config', args: 1, required: true, paramLabel: "FILE", defaultValue: '/etc/hmci.groovy', 'configuration file')
|
||||
|
||||
OptionAccessor options = cli.parse(args)
|
||||
if (options.h) cli.usage()
|
||||
if (options.h) {
|
||||
cli.usage()
|
||||
return
|
||||
}
|
||||
|
||||
if(options.v) {
|
||||
// TODO - how to display correct version or build number ?
|
||||
println("See https://bitbucket.org/mnellemann/hmci for more information.")
|
||||
System.exit(0)
|
||||
println("Version " + getVersion())
|
||||
return
|
||||
}
|
||||
|
||||
ConfigObject configuration
|
||||
|
@ -194,7 +207,6 @@ class App implements Runnable {
|
|||
}
|
||||
|
||||
new App(configuration)
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ class HmcClient {
|
|||
private final String password
|
||||
private final Boolean unsafe
|
||||
|
||||
protected Integer responseErrors = 0
|
||||
protected String authToken
|
||||
private final OkHttpClient client
|
||||
|
||||
|
@ -151,6 +152,7 @@ class HmcClient {
|
|||
|
||||
// Do not try to parse empty response
|
||||
if(responseBody.empty || responseBody.size() < 1) {
|
||||
responseErrors++
|
||||
return managedSystemsMap
|
||||
}
|
||||
|
||||
|
@ -191,6 +193,7 @@ class HmcClient {
|
|||
|
||||
// Do not try to parse empty response
|
||||
if(responseBody.empty || responseBody.size() < 1) {
|
||||
responseErrors++
|
||||
return partitionMap
|
||||
}
|
||||
|
||||
|
@ -227,9 +230,14 @@ class HmcClient {
|
|||
URL url = new URL(String.format("%s/rest/api/pcm/ManagedSystem/%s/ProcessedMetrics?NoOfSamples=1", baseUrl, system.id))
|
||||
Response response = getResponse(url)
|
||||
String responseBody = response.body.string()
|
||||
|
||||
String jsonBody
|
||||
|
||||
// Do not try to parse empty response
|
||||
if(responseBody.empty || responseBody.size() < 1) {
|
||||
responseErrors++
|
||||
return jsonBody
|
||||
}
|
||||
|
||||
// Parse XML and fetch JSON link
|
||||
def feed = new XmlSlurper().parseText(responseBody)
|
||||
feed?.entry?.each { entry ->
|
||||
|
@ -255,10 +263,14 @@ class HmcClient {
|
|||
URL url = new URL(String.format("%s/rest/api/pcm/ManagedSystem/%s/LogicalPartition/%s/ProcessedMetrics?NoOfSamples=1", baseUrl, partition.system.id, partition.id))
|
||||
Response response = getResponse(url)
|
||||
String responseBody = response.body.string()
|
||||
|
||||
//log.debug(responseBody)
|
||||
String jsonBody
|
||||
|
||||
// Do not try to parse empty response
|
||||
if(responseBody.empty || responseBody.size() < 1) {
|
||||
responseErrors++
|
||||
return jsonBody
|
||||
}
|
||||
|
||||
// Parse XML and fetch JSON link
|
||||
def feed = new XmlSlurper().parseText(responseBody)
|
||||
feed?.entry?.each { entry ->
|
||||
|
@ -295,6 +307,12 @@ class HmcClient {
|
|||
*/
|
||||
private Response getResponse(URL url, Integer retry = 0) {
|
||||
|
||||
if(responseErrors > 2) {
|
||||
responseErrors = 0
|
||||
login(true)
|
||||
return getResponse(url, retry++)
|
||||
}
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
|
||||
|
|
1
src/main/resources/.gitignore
vendored
Normal file
1
src/main/resources/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
version.properties
|
Loading…
Reference in a new issue