Refactoring work, replaced Groovy xml and json w. jsoup and moshi.

This commit is contained in:
Mark Nellemann 2020-10-09 16:32:16 +02:00
parent 6a1742e72a
commit 3f71aabd4e
52 changed files with 505 additions and 468 deletions

View file

@ -18,6 +18,10 @@ repositories {
dependencies { dependencies {
implementation 'info.picocli:picocli:4.5.1' implementation 'info.picocli:picocli:4.5.1'
annotationProcessor 'info.picocli:picocli-codegen:4.5.1' annotationProcessor 'info.picocli:picocli-codegen:4.5.1'
// implementation 'com.thoughtworks.xstream:xstream:1.4.13'
// https://mvnrepository.com/artifact/org.jsoup/jsoup
implementation 'org.jsoup:jsoup:1.13.1'
implementation 'com.squareup.moshi:moshi:1.11.0'
implementation 'org.tomlj:tomlj:1.0.0' implementation 'org.tomlj:tomlj:1.0.0'
implementation 'org.codehaus.groovy:groovy-all:3.0.5' implementation 'org.codehaus.groovy:groovy-all:3.0.5'
implementation 'com.squareup.okhttp3:okhttp:4.8.0' implementation 'com.squareup.okhttp3:okhttp:4.8.0'
@ -25,6 +29,7 @@ dependencies {
implementation 'org.slf4j:slf4j-api:1.7.+' implementation 'org.slf4j:slf4j-api:1.7.+'
runtimeOnly 'ch.qos.logback:logback-classic:1.+' runtimeOnly 'ch.qos.logback:logback-classic:1.+'
testImplementation('org.spockframework:spock-core:2.0-M3-groovy-3.0') testImplementation('org.spockframework:spock-core:2.0-M3-groovy-3.0')
testImplementation("org.slf4j:slf4j-simple:1.7.+") testImplementation("org.slf4j:slf4j-simple:1.7.+")
testImplementation('com.squareup.okhttp3:mockwebserver:4.8.0') testImplementation('com.squareup.okhttp3:mockwebserver:4.8.0')

View file

@ -16,25 +16,21 @@
package biz.nellemann.hmci package biz.nellemann.hmci
import biz.nellemann.hmci.Configuration.HmcObject import biz.nellemann.hmci.Configuration.HmcObject
import com.squareup.moshi.Moshi
import groovy.transform.CompileDynamic import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j import groovy.util.logging.Slf4j
import groovy.xml.XmlSlurper import groovy.xml.XmlSlurper
import okhttp3.MediaType import okhttp3.*
import okhttp3.OkHttpClient import org.jsoup.Jsoup
import okhttp3.Request import org.jsoup.nodes.Document
import okhttp3.RequestBody import org.jsoup.nodes.Element
import okhttp3.Response import org.jsoup.select.Elements
import javax.net.ssl.HostnameVerifier import javax.net.ssl.*
import javax.net.ssl.SSLContext
import javax.net.ssl.SSLSession
import javax.net.ssl.SSLSocketFactory
import javax.net.ssl.TrustManager
import javax.net.ssl.X509TrustManager
import java.security.SecureRandom import java.security.SecureRandom
import java.security.cert.CertificateException import java.security.cert.CertificateException
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate
@Slf4j @Slf4j
@CompileStatic @CompileStatic
@ -154,11 +150,11 @@ class HmcClient {
* *
* @return * @return
*/ */
@CompileDynamic //@CompileDynamic
Map<String, ManagedSystem> getManagedSystems() { Map<String, ManagedSystem> getManagedSystems() {
URL url = new URL(String.format("%s/rest/api/uom/ManagedSystem", baseUrl)) URL url = new URL(String.format("%s/rest/api/uom/ManagedSystem", baseUrl))
Response response = getResponse(url) Response response = getResponse(url)
String responseBody = response.body.string() String responseBody = response.body().string()
Map<String,ManagedSystem> managedSystemsMap = new HashMap<String, ManagedSystem>() Map<String,ManagedSystem> managedSystemsMap = new HashMap<String, ManagedSystem>()
// Do not try to parse empty response // Do not try to parse empty response
@ -167,22 +163,24 @@ class HmcClient {
return managedSystemsMap return managedSystemsMap
} }
def feed = new XmlSlurper().parseText(responseBody) try {
feed?.entry?.each { entry -> Document doc = Jsoup.parse(responseBody);
entry.content.each { content -> Elements managedSystems = doc.select("ManagedSystem|ManagedSystem") // doc.select("img[src$=.png]");
content.ManagedSystem.each { system -> for(Element el : managedSystems) {
ManagedSystem managedSystem = new ManagedSystem( ManagedSystem system = new ManagedSystem(
hmcId, hmcId,
entry.id as String, el.select("Metadata > Atom > AtomID").text() as String,
system.SystemName as String, el.select("SystemName").text() as String,
system.MachineTypeModelAndSerialNumber?.MachineType as String, el.select("MachineTypeModelAndSerialNumber > MachineType").text() as String,
system.MachineTypeModelAndSerialNumber?.Model as String, el.select("MachineTypeModelAndSerialNumber > Model").text() as String,
system.MachineTypeModelAndSerialNumber?.SerialNumber as String el.select("MachineTypeModelAndSerialNumber > SerialNumber").text() as String,
) )
managedSystemsMap.put(managedSystem.id, managedSystem) managedSystemsMap.put(system.id, system)
log.debug("getManagedSystems() - Found system: " + managedSystem.toString()) log.info("getManagedSystems() - Found system: " + system.toString())
}
} }
} catch(Exception e) {
log.warn("getManagedSystems() - xml parse error", e);
} }
return managedSystemsMap return managedSystemsMap
@ -196,11 +194,11 @@ class HmcClient {
* @param UUID of managed system * @param UUID of managed system
* @return * @return
*/ */
@CompileDynamic //@CompileDynamic
Map<String, LogicalPartition> getLogicalPartitionsForManagedSystem(ManagedSystem system) { Map<String, LogicalPartition> getLogicalPartitionsForManagedSystem(ManagedSystem system) {
URL url = new URL(String.format("%s/rest/api/uom/ManagedSystem/%s/LogicalPartition", baseUrl, system.id)) URL url = new URL(String.format("%s/rest/api/uom/ManagedSystem/%s/LogicalPartition", baseUrl, system.id))
Response response = getResponse(url) Response response = getResponse(url)
String responseBody = response.body.string() String responseBody = response.body().string()
Map<String, LogicalPartition> partitionMap = new HashMap<String, LogicalPartition>() {} Map<String, LogicalPartition> partitionMap = new HashMap<String, LogicalPartition>() {}
// Do not try to parse empty response // Do not try to parse empty response
@ -209,22 +207,22 @@ class HmcClient {
return partitionMap return partitionMap
} }
def feed = new XmlSlurper().parseText(responseBody) try {
feed?.entry?.each { entry -> Document doc = Jsoup.parse(responseBody);
//log.debug("Entry") Elements logicalPartitions = doc.select("LogicalPartition|LogicalPartition") // doc.select("img[src$=.png]");
entry.content.each { content -> for(Element el : logicalPartitions) {
//log.debug("Content")
content.LogicalPartition.each { partition ->
LogicalPartition logicalPartition = new LogicalPartition( LogicalPartition logicalPartition = new LogicalPartition(
partition.PartitionUUID as String, el.select("PartitionUUID").text() as String,
partition.PartitionName as String, el.select("PartitionName").text() as String,
partition.PartitionType as String, el.select("PartitionType").text() as String,
system system
) )
partitionMap.put(logicalPartition.id, logicalPartition) partitionMap.put(logicalPartition.id, logicalPartition)
log.debug("getLogicalPartitionsForManagedSystem() - Found partition: " + logicalPartition.toString()) log.info("getLogicalPartitionsForManagedSystem() - Found partition: " + logicalPartition.toString())
}
} }
} catch(Exception e) {
log.warn("getLogicalPartitionsForManagedSystem() - xml parse error", e);
} }
return partitionMap return partitionMap
@ -237,12 +235,12 @@ class HmcClient {
* @param systemId * @param systemId
* @return * @return
*/ */
@CompileDynamic //@CompileDynamic
String getPcmDataForManagedSystem(ManagedSystem system) { String getPcmDataForManagedSystem(ManagedSystem system) {
log.debug("getPcmDataForManagedSystem() - " + system.id) log.debug("getPcmDataForManagedSystem() - " + system.id)
URL url = new URL(String.format("%s/rest/api/pcm/ManagedSystem/%s/ProcessedMetrics?NoOfSamples=1", baseUrl, system.id)) URL url = new URL(String.format("%s/rest/api/pcm/ManagedSystem/%s/ProcessedMetrics?NoOfSamples=1", baseUrl, system.id))
Response response = getResponse(url) Response response = getResponse(url)
String responseBody = response.body.string() String responseBody = response.body().string()
String jsonBody String jsonBody
// Do not try to parse empty response // Do not try to parse empty response
@ -251,13 +249,17 @@ class HmcClient {
return jsonBody return jsonBody
} }
// Parse XML and fetch JSON link try {
def feed = new XmlSlurper().parseText(responseBody) Document doc = Jsoup.parse(responseBody);
feed?.entry?.each { entry -> Element entry = doc.select("entry").first();
String link = entry.link["@href"] Element link = entry.select("link[href]").first();
if(entry.category["@term"] == "ManagedSystem") { if(link.attr("type") == "application/json") {
jsonBody = getResponseBody(new URL(link)) String href = (String) link.attr("href");
log.debug("getPcmDataForManagedSystem() - json url: " + href);
jsonBody = getResponseBody(new URL(href));
} }
} catch(Exception e) {
log.warn("getPcmDataForManagedSystem() - xml parse error", e);
} }
return jsonBody return jsonBody
@ -270,13 +272,13 @@ class HmcClient {
* @param partitionId * @param partitionId
* @return * @return
*/ */
@CompileDynamic //@CompileDynamic
String getPcmDataForLogicalPartition(LogicalPartition partition) { String getPcmDataForLogicalPartition(LogicalPartition partition) {
log.debug(String.format("getPcmDataForLogicalPartition() - %s @ %s", partition.id, partition.system.id)) log.debug(String.format("getPcmDataForLogicalPartition() - %s @ %s", partition.id, partition.system.id))
URL url = new URL(String.format("%s/rest/api/pcm/ManagedSystem/%s/LogicalPartition/%s/ProcessedMetrics?NoOfSamples=1", baseUrl, partition.system.id, partition.id)) 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) Response response = getResponse(url)
String responseBody = response.body.string() String responseBody = response.body().string()
String jsonBody String jsonBody
// Do not try to parse empty response // Do not try to parse empty response
@ -285,13 +287,17 @@ class HmcClient {
return jsonBody return jsonBody
} }
// Parse XML and fetch JSON link try {
def feed = new XmlSlurper().parseText(responseBody) Document doc = Jsoup.parse(responseBody);
feed?.entry?.each { entry -> Element entry = doc.select("entry").first();
String link = entry.link["@href"] Element link = entry.select("link[href]").first();
if(entry.category["@term"] == "LogicalPartition") { if(link.attr("type") == "application/json") {
jsonBody = getResponseBody(new URL(link)) String href = (String) link.attr("href");
log.debug("getPcmDataForLogicalPartition() - json url: " + href);
jsonBody = getResponseBody(new URL(href));
} }
} catch(Exception e) {
log.warn("getPcmDataForLogicalPartition() - xml parse error", e);
} }
return jsonBody return jsonBody

View file

@ -52,9 +52,9 @@ class LogicalPartition extends MetaSystem {
//map.put("tags", tagsMap) //map.put("tags", tagsMap)
log.debug("getAffinityScore() - tags: " + tagsMap.toString()) log.debug("getAffinityScore() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, Number> fieldsMap = [
affinityScore: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.affinityScore, affinityScore: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.affinityScore,
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
log.debug("getAffinityScore() - fields: " + fieldsMap.toString()) log.debug("getAffinityScore() - fields: " + fieldsMap.toString())
@ -77,10 +77,10 @@ class LogicalPartition extends MetaSystem {
//map.put("tags", tagsMap) //map.put("tags", tagsMap)
log.debug("getMemoryMetrics() - tags: " + tagsMap.toString()) log.debug("getMemoryMetrics() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, Number> fieldsMap = [
logicalMem: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.memory?.logicalMem?.first(), logicalMem: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.memory?.logicalMem?.first(),
backedPhysicalMem: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.memory?.backedPhysicalMem?.first(), backedPhysicalMem: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.memory?.backedPhysicalMem?.first(),
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
log.debug("getMemoryMetrics() - fields: " + fieldsMap.toString()) log.debug("getMemoryMetrics() - fields: " + fieldsMap.toString())
@ -103,7 +103,7 @@ class LogicalPartition extends MetaSystem {
//map.put("tags", tagsMap) //map.put("tags", tagsMap)
log.debug("getProcessorMetrics() - tags: " + tagsMap.toString()) log.debug("getProcessorMetrics() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, Number> fieldsMap = [
utilizedProcUnits: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.utilizedProcUnits?.first(), utilizedProcUnits: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.utilizedProcUnits?.first(),
maxVirtualProcessors: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.maxVirtualProcessors.first(), maxVirtualProcessors: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.maxVirtualProcessors.first(),
currentVirtualProcessors: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.currentVirtualProcessors.first(), currentVirtualProcessors: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.currentVirtualProcessors.first(),
@ -115,7 +115,7 @@ class LogicalPartition extends MetaSystem {
utilizedUncappedProcUnits: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.utilizedUncappedProcUnits?.first(), utilizedUncappedProcUnits: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.utilizedUncappedProcUnits?.first(),
timePerInstructionExecution: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.timeSpentWaitingForDispatch?.first(), timePerInstructionExecution: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.timeSpentWaitingForDispatch?.first(),
timeSpentWaitingForDispatch: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.timePerInstructionExecution?.first(), timeSpentWaitingForDispatch: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.timePerInstructionExecution?.first(),
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
log.debug("getProcessorMetrics() - fields: " + fieldsMap.toString()) log.debug("getProcessorMetrics() - fields: " + fieldsMap.toString())
@ -143,12 +143,12 @@ class LogicalPartition extends MetaSystem {
//map.put("tags", tagsMap) //map.put("tags", tagsMap)
log.debug("getVirtualEthernetAdapterMetrics() - tags: " + tagsMap.toString()) log.debug("getVirtualEthernetAdapterMetrics() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, Number> fieldsMap = [
receivedPhysicalBytes: it.receivedPhysicalBytes.first(), receivedPhysicalBytes: it.receivedPhysicalBytes.first(),
sentPhysicalBytes: it.sentPhysicalBytes.first(), sentPhysicalBytes: it.sentPhysicalBytes.first(),
receivedBytes: it.receivedBytes.first(), receivedBytes: it.receivedBytes.first(),
sentBytes: it.sentBytes.first(), sentBytes: it.sentBytes.first(),
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
log.debug("getVirtualEthernetAdapterMetrics() - fields: " + fieldsMap.toString()) log.debug("getVirtualEthernetAdapterMetrics() - fields: " + fieldsMap.toString())
@ -177,11 +177,11 @@ class LogicalPartition extends MetaSystem {
//map.put("tags", tagsMap) //map.put("tags", tagsMap)
log.debug("getVirtualFiberChannelAdaptersMetrics() - tags: " + tagsMap.toString()) log.debug("getVirtualFiberChannelAdaptersMetrics() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, Number> fieldsMap = [
transmittedBytes: it.transmittedBytes.first(), transmittedBytes: it.transmittedBytes.first(),
writeBytes: it.writeBytes.first(), writeBytes: it.writeBytes.first(),
readBytes: it.readBytes.first(), readBytes: it.readBytes.first(),
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
log.debug("getVirtualFiberChannelAdaptersMetrics() - fields: " + fieldsMap.toString()) log.debug("getVirtualFiberChannelAdaptersMetrics() - fields: " + fieldsMap.toString())

View file

@ -58,12 +58,12 @@ class ManagedSystem extends MetaSystem {
//map.put("tags", tagsMap) //map.put("tags", tagsMap)
log.debug("getMemoryMetrics() - tags: " + tagsMap.toString()) log.debug("getMemoryMetrics() - tags: " + tagsMap.toString())
Map<String, BigDecimal> fieldsMap = [ Map<String, Number> fieldsMap = [
"totalMem": metrics.systemUtil?.utilSamples?.first()?.serverUtil?.memory?.totalMem?.first(), "totalMem": metrics.systemUtil?.utilSamples?.first()?.serverUtil?.memory?.totalMem?.first(),
"availableMem": metrics.systemUtil?.utilSamples?.first()?.serverUtil?.memory?.availableMem?.first(), "availableMem": metrics.systemUtil?.utilSamples?.first()?.serverUtil?.memory?.availableMem?.first(),
"configurableMem": metrics.systemUtil?.utilSamples?.first()?.serverUtil?.memory?.configurableMem?.first(), "configurableMem": metrics.systemUtil?.utilSamples?.first()?.serverUtil?.memory?.configurableMem?.first(),
"assignedMemToLpars": metrics.systemUtil?.utilSamples?.first()?.serverUtil?.memory?.assignedMemToLpars?.first(), "assignedMemToLpars": metrics.systemUtil?.utilSamples?.first()?.serverUtil?.memory?.assignedMemToLpars?.first(),
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
log.debug("getMemoryMetrics() - fields: " + fieldsMap.toString()) log.debug("getMemoryMetrics() - fields: " + fieldsMap.toString())
@ -88,12 +88,12 @@ class ManagedSystem extends MetaSystem {
//measurement.tags = tagsMap; //measurement.tags = tagsMap;
log.debug("getProcessorMetrics() - tags: " + tagsMap.toString()) log.debug("getProcessorMetrics() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, Number> fieldsMap = [
availableProcUnits: metrics.systemUtil?.utilSamples?.first()?.serverUtil?.processor?.totalProcUnits?.first(), availableProcUnits: metrics.systemUtil?.utilSamples?.first()?.serverUtil?.processor?.totalProcUnits?.first(),
utilizedProcUnits: metrics.systemUtil?.utilSamples?.first()?.serverUtil?.processor?.utilizedProcUnits?.first(), utilizedProcUnits: metrics.systemUtil?.utilSamples?.first()?.serverUtil?.processor?.utilizedProcUnits?.first(),
availableProcUnits: metrics.systemUtil?.utilSamples?.first()?.serverUtil?.processor?.availableProcUnits?.first(), availableProcUnits: metrics.systemUtil?.utilSamples?.first()?.serverUtil?.processor?.availableProcUnits?.first(),
configurableProcUnits: metrics.systemUtil?.utilSamples?.first()?.serverUtil?.processor?.configurableProcUnits?.first(), configurableProcUnits: metrics.systemUtil?.utilSamples?.first()?.serverUtil?.processor?.configurableProcUnits?.first(),
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
//measurement.fields = fieldsMap; //measurement.fields = fieldsMap;
log.debug("getProcessorMetrics() - fields: " + fieldsMap.toString()) log.debug("getProcessorMetrics() - fields: " + fieldsMap.toString())
@ -119,10 +119,10 @@ class ManagedSystem extends MetaSystem {
//map.put("tags", tagsMap) //map.put("tags", tagsMap)
log.debug("getSharedProcessorPools() - tags: " + tagsMap.toString()) log.debug("getSharedProcessorPools() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, Number> fieldsMap = [
assignedProcUnits: it.assignedProcUnits.first(), assignedProcUnits: it.assignedProcUnits.first(),
availableProcUnits: it.availableProcUnits.first(), availableProcUnits: it.availableProcUnits.first(),
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
log.debug("getSharedProcessorPools() - fields: " + fieldsMap.toString()) log.debug("getSharedProcessorPools() - fields: " + fieldsMap.toString())
@ -152,11 +152,11 @@ class ManagedSystem extends MetaSystem {
measurement.tags = tagsMap; measurement.tags = tagsMap;
log.debug("getSystemSharedAdapters() - tags: " + tagsMap.toString()) log.debug("getSystemSharedAdapters() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, Number> fieldsMap = [
sentBytes: it.sentBytes.first(), sentBytes: it.sentBytes.first(),
receivedBytes: it.receivedBytes.first(), receivedBytes: it.receivedBytes.first(),
transferredBytes: it.transferredBytes.first(), transferredBytes: it.transferredBytes.first(),
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
measurement.fields = fieldsMap; measurement.fields = fieldsMap;
log.debug("getSystemSharedAdapters() - fields: " + fieldsMap.toString()) log.debug("getSystemSharedAdapters() - fields: " + fieldsMap.toString())
@ -190,11 +190,11 @@ class ManagedSystem extends MetaSystem {
measurement.tags = tagsMap; measurement.tags = tagsMap;
log.debug("getSystemFiberChannelAdapters() - tags: " + tagsMap.toString()) log.debug("getSystemFiberChannelAdapters() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, Number> fieldsMap = [
writeBytes: it.writeBytes.first(), writeBytes: it.writeBytes.first(),
readBytes: it.readBytes.first(), readBytes: it.readBytes.first(),
transmittedBytes: it.transmittedBytes.first(), transmittedBytes: it.transmittedBytes.first(),
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
measurement.fields = fieldsMap; measurement.fields = fieldsMap;
log.debug("getSystemFiberChannelAdapters() - fields: " + fieldsMap.toString()) log.debug("getSystemFiberChannelAdapters() - fields: " + fieldsMap.toString())
@ -225,11 +225,11 @@ class ManagedSystem extends MetaSystem {
measurement.tags = tagsMap; measurement.tags = tagsMap;
log.debug("getSystemGenericPhysicalAdapters() - tags: " + tagsMap.toString()) log.debug("getSystemGenericPhysicalAdapters() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, Number> fieldsMap = [
writeBytes: it.writeBytes.first(), writeBytes: it.writeBytes.first(),
readBytes: it.readBytes.first(), readBytes: it.readBytes.first(),
transmittedBytes: it.transmittedBytes.first(), transmittedBytes: it.transmittedBytes.first(),
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
measurement.fields = fieldsMap; measurement.fields = fieldsMap;
log.debug("getSystemGenericPhysicalAdapters() - fields: " + fieldsMap.toString()) log.debug("getSystemGenericPhysicalAdapters() - fields: " + fieldsMap.toString())
@ -260,11 +260,11 @@ class ManagedSystem extends MetaSystem {
measurement.tags = tagsMap; measurement.tags = tagsMap;
log.debug("getSystemGenericVirtualAdapters() - tags: " + tagsMap.toString()) log.debug("getSystemGenericVirtualAdapters() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, Number> fieldsMap = [
writeBytes: it.writeBytes.first(), writeBytes: it.writeBytes.first(),
readBytes: it.readBytes.first(), readBytes: it.readBytes.first(),
transmittedBytes: it.transmittedBytes.first(), transmittedBytes: it.transmittedBytes.first(),
] ] as HashMap<String, Number>
//map.put("fields", fieldsMap) //map.put("fields", fieldsMap)
measurement.fields = fieldsMap; measurement.fields = fieldsMap;
log.debug("getSystemGenericVirtualAdapters() - fields: " + fieldsMap.toString()) log.debug("getSystemGenericVirtualAdapters() - fields: " + fieldsMap.toString())

View file

@ -16,8 +16,10 @@
package biz.nellemann.hmci package biz.nellemann.hmci
import biz.nellemann.hmci.pcm.PcmData import biz.nellemann.hmci.pcm.PcmData
import groovy.json.JsonSlurper import com.squareup.moshi.FromJson
import groovy.transform.CompileDynamic import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.ToJson
import groovy.transform.CompileStatic import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j import groovy.util.logging.Slf4j
@ -29,15 +31,35 @@ import java.time.format.DateTimeParseException
@CompileStatic @CompileStatic
abstract class MetaSystem { abstract class MetaSystem {
private final Moshi moshi;
private final JsonAdapter<PcmData> jsonAdapter;
protected PcmData metrics protected PcmData metrics
@CompileDynamic MetaSystem() {
void processMetrics(String json) { try {
Map pcmMap = new JsonSlurper().parseText(json) as Map moshi = new Moshi.Builder().add(new NumberAdapter()).add(new BigDecimalAdapter())build();
metrics = new PcmData(pcmMap) jsonAdapter = moshi.adapter(PcmData.class);
} catch(Exception e) {
log.warn("MetaSystem() error", e)
throw new ExceptionInInitializerError(e);
}
} }
@CompileDynamic //@CompileDynamic
void processMetrics(String json) {
try {
metrics = jsonAdapter.fromJson(json);
} catch(Exception e) {
log.warn("processMetrics() error", e)
}
//Map pcmMap = new JsonSlurper().parseText(json) as Map
//metrics = new PcmData(pcmMap)
}
//@CompileDynamic
Instant getTimestamp() { Instant getTimestamp() {
String timestamp = metrics.systemUtil.utilSamples.first().sampleInfo.timeStamp String timestamp = metrics.systemUtil.utilSamples.first().sampleInfo.timeStamp
@ -54,4 +76,32 @@ abstract class MetaSystem {
return instant ?: Instant.now() return instant ?: Instant.now()
} }
class BigDecimalAdapter {
@FromJson
BigDecimal fromJson(String string) {
return new BigDecimal(string);
}
@ToJson
String toJson(BigDecimal value) {
return value.toString();
}
}
class NumberAdapter {
@FromJson
Number fromJson(String string) {
return new Double(string);
}
@ToJson
String toJson(Number value) {
return value.toString();
}
}
} }

View file

@ -1,19 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class FiberChannelAdapter {
String id
String wwpn
String physicalLocation
Integer numOfPorts
List<BigDecimal> numOfReads
List<BigDecimal> numOfWrites
List<BigDecimal> readBytes
List<BigDecimal> writeBytes
List<BigDecimal> runningSpeed
List<BigDecimal> transmittedBytes
}

View file

@ -1,18 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class GenericAdapter {
String id
String type
String physicalLocation
List<BigDecimal> receivedPackets
List<BigDecimal> sentPackets
List<BigDecimal> droppedPackets
List<BigDecimal> sentBytes
List<BigDecimal> receivedBytes
List<BigDecimal> transferredBytes
}

View file

@ -1,17 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class GenericPhysicalAdapters {
String id
String type
String physicalLocation
List<BigDecimal> numOfReads
List<BigDecimal> numOfWrites
List<BigDecimal> readBytes
List<BigDecimal> writeBytes
List<BigDecimal> transmittedBytes
}

View file

@ -1,18 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class GenericVirtualAdapter {
String id
String type
Integer viosId
String physicalLocation
List<BigDecimal> numOfReads
List<BigDecimal> numOfWrites
List<BigDecimal> readBytes
List<BigDecimal> writeBytes
List<BigDecimal> transmittedBytes
}

View file

@ -1,11 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class LparMemory {
List<BigDecimal> logicalMem
List<BigDecimal> backedPhysicalMem
}

View file

@ -1,23 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class LparProcessor {
Integer poolId
Integer weight
String mode
List<BigDecimal> maxVirtualProcessors
List<BigDecimal> currentVirtualProcessors
List<BigDecimal> maxProcUnits
List<BigDecimal> entitledProcUnits
List<BigDecimal> utilizedProcUnits
List<BigDecimal> utilizedCappedProcUnits
List<BigDecimal> utilizedUncappedProcUnits
List<BigDecimal> idleProcUnits
List<BigDecimal> donatedProcUnits
List<BigDecimal> timeSpentWaitingForDispatch
List<BigDecimal> timePerInstructionExecution
}

View file

@ -1,21 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class LparUtil {
Integer id
String uuid
String name
String state
String type
String osType
Integer affinityScore
LparMemory memory
LparProcessor processor
Network network
Storage storage
}

View file

@ -1,10 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class Network {
List<GenericAdapter> genericAdapters
List<SharedAdapter> sharedAdapters
List<VirtualEthernetAdapter> virtualEthernetAdapters
}

View file

@ -1,10 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class PcmData {
SystemUtil systemUtil
}

View file

@ -1,14 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class PhysicalProcessorPool {
List<BigDecimal> assignedProcUnits
List<BigDecimal> utilizedProcUnits
List<BigDecimal> availableProcUnits
List<BigDecimal> configuredProcUnits
List<BigDecimal> borrowedProcUnits
}

View file

@ -1,11 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class SampleInfo {
String timeStamp
Integer status
}

View file

@ -1,13 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class ServerMemory {
List<BigDecimal> totalMem
List<BigDecimal> availableMem
List<BigDecimal> configurableMem
List<BigDecimal> assignedMemToLpars
}

View file

@ -1,13 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class ServerProcessor {
List<BigDecimal> totalProcUnits
List<BigDecimal> utilizedProcUnits
List<BigDecimal> availableProcUnits
List<BigDecimal> configurableProcUnits
}

View file

@ -1,13 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class ServerUtil {
ServerProcessor processor
ServerMemory memory
PhysicalProcessorPool physicalProcessorPool
List<SharedProcessorPool> sharedProcessorPool
}

View file

@ -1,19 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class SharedAdapter {
String id
String type
String physicalLocation
List<BigDecimal> receivedPackets
List<BigDecimal> sentPackets
List<BigDecimal> droppedPackets
List<BigDecimal> sentBytes
List<BigDecimal> receivedBytes
List<BigDecimal> transferredBytes
List<String> bridgedAdapters
}

View file

@ -1,16 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class SharedProcessorPool {
String id
String name
List<BigDecimal> assignedProcUnits
List<BigDecimal> utilizedProcUnits
List<BigDecimal> availableProcUnits
List<BigDecimal> configuredProcUnits
List<BigDecimal> borrowedProcUnits
}

View file

@ -1,14 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class Storage {
List<String> clientLpars
List<GenericPhysicalAdapters> genericPhysicalAdapters
List<GenericVirtualAdapter> genericVirtualAdapters
List<FiberChannelAdapter> fiberChannelAdapters
List<VirtualFiberChannelAdapter> virtualFiberChannelAdapters
}

View file

@ -1,11 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class SystemUtil {
UtilInfo utilInfo
List<UtilSample> utilSamples
}

View file

@ -1,18 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class UtilInfo {
String version
String metricType
Integer frequency
String startTimeStamp
String endTimeStamp
String mtms
String name
String uuid
List<String> metricArrayOrder
}

View file

@ -1,14 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class UtilSample {
String sampleType
SampleInfo sampleInfo
ServerUtil serverUtil
List<ViosUtil> viosUtil
List<LparUtil> lparsUtil
}

View file

@ -1,24 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class ViosUtil {
String id
String uuid
String name
String state
Integer affinityScore
Memory memory
LparProcessor processor
Network network
Storage storage
class Memory {
List<BigDecimal> assignedMem
List<BigDecimal> utilizedMem
}
}

View file

@ -1,27 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class VirtualEthernetAdapter {
String physicalLocation
Integer vlanId
Integer vswitchId
Boolean isPortVlanId
Integer viosId
String sharedEthernetAdapterId
List<BigDecimal> receivedPackets
List<BigDecimal> sentPackets
List<BigDecimal> droppedPackets
List<BigDecimal> sentBytes
List<BigDecimal> receivedBytes
List<BigDecimal> receivedPhysicalPackets
List<BigDecimal> sentPhysicalPackets
List<BigDecimal> droppedPhysicalPackets
List<BigDecimal> sentPhysicalBytes
List<BigDecimal> receivedPhysicalBytes
List<BigDecimal> transferredBytes
List<BigDecimal> transferredPhysicalBytes
}

View file

@ -1,20 +0,0 @@
package biz.nellemann.hmci.pcm
import groovy.transform.ToString
@ToString
class VirtualFiberChannelAdapter {
String wwpn
String wwpn2
String physicalLocation
String physicalPortWWPN
Integer viosId
List<BigDecimal> numOfReads
List<BigDecimal> numOfWrites
List<BigDecimal> readBytes
List<BigDecimal> writeBytes
List<BigDecimal> runningSpeed
List<BigDecimal> transmittedBytes
}

View file

@ -0,0 +1,18 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class FiberChannelAdapter {
String id;
String wwpn;
String physicalLocation;
Integer numOfPorts;
List<Number> numOfReads;
List<Number> numOfWrites;
List<Number> readBytes;
List<Number> writeBytes;
List<Number> runningSpeed;
List<Number> transmittedBytes;
}

View file

@ -0,0 +1,17 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class GenericAdapter {
String id;
String type;
String physicalLocation;
List<Number> receivedPackets;
List<Number> sentPackets;
List<Number> droppedPackets;
List<Number> sentBytes;
List<Number> receivedBytes;
List<Number> transferredBytes;
}

View file

@ -0,0 +1,16 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class GenericPhysicalAdapters {
String id;
String type;
String physicalLocation;
List<Number> numOfReads;
List<Number> numOfWrites;
List<Number> readBytes;
List<Number> writeBytes;
List<Number> transmittedBytes;
}

View file

@ -0,0 +1,17 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class GenericVirtualAdapter {
String id;
String type;
Integer viosId;
String physicalLocation;
List<Number> numOfReads;
List<Number> numOfWrites;
List<Number> readBytes;
List<Number> writeBytes;
List<Number> transmittedBytes;
}

View file

@ -0,0 +1,10 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class LparMemory {
List<Number> logicalMem;
List<Number> backedPhysicalMem;
}

View file

@ -0,0 +1,22 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class LparProcessor {
Integer poolId;
Integer weight;
String mode;
List<Number> maxVirtualProcessors;
List<Number> currentVirtualProcessors;
List<Number> maxProcUnits;
List<Number> entitledProcUnits;
List<Number> utilizedProcUnits;
List<Number> utilizedCappedProcUnits;
List<Number> utilizedUncappedProcUnits;
List<Number> idleProcUnits;
List<Number> donatedProcUnits;
List<Number> timeSpentWaitingForDispatch;
List<Number> timePerInstructionExecution;
}

View file

@ -0,0 +1,18 @@
package biz.nellemann.hmci.pcm;
public class LparUtil {
Integer id;
String uuid;
String name;
String state;
String type;
String osType;
Integer affinityScore;
LparMemory memory;
LparProcessor processor;
Network network;
Storage storage;
}

View file

@ -0,0 +1,11 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class Network {
List<GenericAdapter> genericAdapters;
List<SharedAdapter> sharedAdapters;
List<VirtualEthernetAdapter> virtualEthernetAdapters;
}

View file

@ -0,0 +1,7 @@
package biz.nellemann.hmci.pcm;
public class PcmData {
public SystemUtil systemUtil;
}

View file

@ -0,0 +1,13 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class PhysicalProcessorPool {
List<Number> assignedProcUnits;
List<Number> utilizedProcUnits;
List<Number> availableProcUnits;
List<Number> configuredProcUnits;
List<Number> borrowedProcUnits;
}

View file

@ -0,0 +1,8 @@
package biz.nellemann.hmci.pcm;
public class SampleInfo {
public String timeStamp;
Integer status;
}

View file

@ -0,0 +1,12 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class ServerMemory {
List<Number> totalMem;
List<Number> availableMem;
List<Number> configurableMem;
List<Number> assignedMemToLpars;
}

View file

@ -0,0 +1,12 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class ServerProcessor {
List<Number> totalProcUnits;
List<Number> utilizedProcUnits;
List<Number> availableProcUnits;
List<Number> configurableProcUnits;
}

View file

@ -0,0 +1,12 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class ServerUtil {
ServerProcessor processor;
ServerMemory memory;
PhysicalProcessorPool physicalProcessorPool;
List<SharedProcessorPool> sharedProcessorPool;
}

View file

@ -0,0 +1,18 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class SharedAdapter {
String id;
String type;
String physicalLocation;
List<Number> receivedPackets;
List<Number> sentPackets;
List<Number> droppedPackets;
List<Number> sentBytes;
List<Number> receivedBytes;
List<Number> transferredBytes;
List<String> bridgedAdapters;
}

View file

@ -0,0 +1,15 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class SharedProcessorPool {
String id;
String name;
List<Number> assignedProcUnits;
List<Number> utilizedProcUnits;
List<Number> availableProcUnits;
List<Number> configuredProcUnits;
List<Number> borrowedProcUnits;
}

View file

@ -0,0 +1,13 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class Storage {
List<String> clientLpars;
List<GenericPhysicalAdapters> genericPhysicalAdapters;
List<GenericVirtualAdapter> genericVirtualAdapters;
List<FiberChannelAdapter> fiberChannelAdapters;
List<VirtualFiberChannelAdapter> virtualFiberChannelAdapters;
}

View file

@ -0,0 +1,10 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class SystemUtil {
UtilInfo utilInfo;
public List<UtilSample> utilSamples;
}

View file

@ -0,0 +1,17 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class UtilInfo {
String version;
String metricType;
Integer frequency;
String startTimeStamp;
String endTimeStamp;
String mtms;
String name;
String uuid;
List<String> metricArrayOrder;
}

View file

@ -0,0 +1,13 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class UtilSample {
String sampleType;
public SampleInfo sampleInfo;
ServerUtil serverUtil;
List<ViosUtil> viosUtil;
List<LparUtil> lparsUtil;
}

View file

@ -0,0 +1,10 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class ViosMemory {
List<Number> assignedMem;
List<Number> utilizedMem;
}

View file

@ -0,0 +1,16 @@
package biz.nellemann.hmci.pcm;
public class ViosUtil {
String id;
String uuid;
String name;
String state;
Integer affinityScore;
ViosMemory memory;
LparProcessor processor;
Network network;
Storage storage;
}

View file

@ -0,0 +1,26 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class VirtualEthernetAdapter {
String physicalLocation;
Integer vlanId;
Integer vswitchId;
Boolean isPortVlanId;
Integer viosId;
String sharedEthernetAdapterId;
List<Number> receivedPackets;
List<Number> sentPackets;
List<Number> droppedPackets;
List<Number> sentBytes;
List<Number> receivedBytes;
List<Number> receivedPhysicalPackets;
List<Number> sentPhysicalPackets;
List<Number> droppedPhysicalPackets;
List<Number> sentPhysicalBytes;
List<Number> receivedPhysicalBytes;
List<Number> transferredBytes;
List<Number> transferredPhysicalBytes;
}

View file

@ -0,0 +1,19 @@
package biz.nellemann.hmci.pcm;
import java.util.List;
public class VirtualFiberChannelAdapter {
String wwpn;
String wwpn2;
String physicalLocation;
String physicalPortWWPN;
Integer viosId;
List<Number> numOfReads;
List<Number> numOfWrites;
List<Number> readBytes;
List<Number> writeBytes;
List<Number> runningSpeed;
List<Number> transmittedBytes;
}