More refactoring work, cleanup and improvements.

This commit is contained in:
Mark Nellemann 2020-10-12 10:15:53 +02:00
parent b005376941
commit 3474ee1790
19 changed files with 111 additions and 110 deletions

View File

@ -72,7 +72,7 @@ ospackage {
buildRpm { buildRpm {
dependsOn startShadowScripts dependsOn startShadowScripts
os = LINUX os = "LINUX"
} }
buildDeb { buildDeb {

View File

@ -1,3 +1,3 @@
id = hmci id = hmci
group = biz.nellemann.hmci group = biz.nellemann.hmci
version = 1.0.10 version = 0.2.1

View File

@ -26,18 +26,17 @@ public class Configuration {
Path source = Paths.get(configurationFile); Path source = Paths.get(configurationFile);
TomlParseResult result = Toml.parse(source); TomlParseResult result = Toml.parse(source);
result.errors().forEach(error -> System.err.println(error.toString())); result.errors().forEach(error -> System.err.println(error.toString()));
//System.out.println(result.toJson());
if(result.contains("refresh")) { if(result.contains("refresh")) {
refresh = result.getLong("refresh"); refresh = result.getLong("refresh");
} else { } else {
refresh = 15l; refresh = 15L;
} }
if(result.contains("rescan")) { if(result.contains("rescan")) {
rescan = result.getLong("rescan"); rescan = result.getLong("rescan");
} else { } else {
rescan = 60l; rescan = 60L;
} }
hmc = getHmc(result); hmc = getHmc(result);
@ -52,6 +51,9 @@ public class Configuration {
if(result.contains("hmc") && result.isTable("hmc")) { if(result.contains("hmc") && result.isTable("hmc")) {
TomlTable hmcTable = result.getTable("hmc"); TomlTable hmcTable = result.getTable("hmc");
if(hmcTable == null) {
return list;
}
for(String key : hmcTable.keySet()) { for(String key : hmcTable.keySet()) {
HmcObject c = new HmcObject(); HmcObject c = new HmcObject();
@ -119,17 +121,30 @@ public class Configuration {
String password = ""; String password = "";
String database = "hmci"; String database = "hmci";
private boolean isValid = false; private boolean validated = false;
InfluxObject() { }
InfluxObject(String url, String username, String password, String database) {
this.url = url;
this.username = username;
this.password = password;
this.database = database;
}
Boolean isValid() { Boolean isValid() {
return isValid(); return validated;
} }
// TODO: Fixme // TODO: Fixme
void validate() { void validate() {
isValid = true; validated = true;
} }
@Override
public String toString() {
return url;
}
} }
@ -141,15 +156,25 @@ public class Configuration {
String password; String password;
Boolean unsafe = false; Boolean unsafe = false;
private boolean isValid = false; private boolean validated = false;
HmcObject() { }
HmcObject(String url, String username, String password, Boolean unsafe) {
this.url = url;
this.username = username;
this.password = password;
this.unsafe = unsafe;
}
Boolean isValid() { Boolean isValid() {
return isValid(); return validated;
} }
// TODO: Fixme // TODO: Fixme
void validate() { void validate() {
isValid = true; validated = true;
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com> * Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
@ -44,7 +45,6 @@ class HmcClient {
private final String baseUrl; private final String baseUrl;
private final String username; private final String username;
private final String password; private final String password;
private final Boolean unsafe;
protected Integer responseErrors = 0; protected Integer responseErrors = 0;
protected String authToken; protected String authToken;
@ -57,7 +57,7 @@ class HmcClient {
this.baseUrl = configHmc.url; this.baseUrl = configHmc.url;
this.username = configHmc.username; this.username = configHmc.username;
this.password = configHmc.password; this.password = configHmc.password;
this.unsafe = configHmc.unsafe; Boolean unsafe = configHmc.unsafe;
if(unsafe) { if(unsafe) {
this.client = getUnsafeOkHttpClient(); this.client = getUnsafeOkHttpClient();
@ -70,7 +70,6 @@ class HmcClient {
/** /**
* Logon to the HMC and get an authentication token for further requests. * Logon to the HMC and get an authentication token for further requests.
* @throws Exception
*/ */
void login() throws Exception { void login() throws Exception {
this.login(false); this.login(false);
@ -80,7 +79,6 @@ class HmcClient {
/** /**
* Logon to the HMC and get an authentication token for further requests. * Logon to the HMC and get an authentication token for further requests.
* @param force * @param force
* @throws Exception
*/ */
void login(Boolean force) throws Exception { void login(Boolean force) throws Exception {
@ -97,8 +95,9 @@ class HmcClient {
payload.append("<Password>").append(password).append("</Password>"); payload.append("<Password>").append(password).append("</Password>");
payload.append("</LogonRequest>"); payload.append("</LogonRequest>");
URL url = new URL(String.format("%s/rest/api/web/Logon", baseUrl)); try {
Request request = new Request.Builder() URL url = new URL(String.format("%s/rest/api/web/Logon", baseUrl));
Request request = new Request.Builder()
.url(url) .url(url)
//.addHeader("Content-Type", "application/vnd.ibm.powervm.web+xml; type=LogonRequest") //.addHeader("Content-Type", "application/vnd.ibm.powervm.web+xml; type=LogonRequest")
.addHeader("Accept", "application/vnd.ibm.powervm.web+xml; type=LogonResponse") .addHeader("Accept", "application/vnd.ibm.powervm.web+xml; type=LogonResponse")
@ -106,21 +105,23 @@ class HmcClient {
.put(RequestBody.create(payload.toString(), MEDIA_TYPE_IBM_XML_LOGIN)) .put(RequestBody.create(payload.toString(), MEDIA_TYPE_IBM_XML_LOGIN))
.build(); .build();
try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
// Get response body and parse // Get response body and parse
String responseBody = response.body().string(); String responseBody = Objects.requireNonNull(response.body()).string();
response.body().close(); Objects.requireNonNull(response.body()).close();
Document doc = Jsoup.parse(responseBody); Document doc = Jsoup.parse(responseBody);
authToken = doc.select("X-API-Session").text(); authToken = doc.select("X-API-Session").text();
log.debug("login() - Auth Token: " + authToken); log.debug("login() - Auth Token: " + authToken);
} catch (MalformedURLException e) {
log.error("login() - url error", e);
throw new Exception(new Throwable("Login URL Error: " + e.getMessage()));
} catch(Exception e) { } catch(Exception e) {
log.error(e.getMessage()); log.error("login() - general error", e);
throw new Exception(e); throw new Exception(new Throwable("Login General Error: " + e.getMessage()));
} }
} }
@ -157,14 +158,14 @@ class HmcClient {
/** /**
* Return Map of ManagedSystems seen by this HMC * Return Map of ManagedSystems seen by this HMC
* *
* @return * @return Map of system-id and ManagedSystem
*/ */
Map<String, ManagedSystem> getManagedSystems() throws Exception { Map<String, ManagedSystem> getManagedSystems() throws Exception {
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 = Objects.requireNonNull(response.body()).string(); String responseBody = Objects.requireNonNull(response.body()).string();
Map<String,ManagedSystem> managedSystemsMap = new HashMap<String, ManagedSystem>(); Map<String,ManagedSystem> managedSystemsMap = new HashMap<>();
// Do not try to parse empty response // Do not try to parse empty response
if(responseBody.isEmpty() || responseBody.length() <= 1) { if(responseBody.isEmpty() || responseBody.length() <= 1) {
@ -185,7 +186,7 @@ class HmcClient {
el.select("MachineTypeModelAndSerialNumber > SerialNumber").text() el.select("MachineTypeModelAndSerialNumber > SerialNumber").text()
); );
managedSystemsMap.put(system.id, system); managedSystemsMap.put(system.id, system);
log.info("getManagedSystems() - Found system: " + system.toString()); log.debug("getManagedSystems() - Found system: " + system.toString());
} }
} catch(Exception e) { } catch(Exception e) {
@ -199,8 +200,8 @@ class HmcClient {
/** /**
* Return Map of LogicalPartitions seen by a ManagedSystem on this HMC * Return Map of LogicalPartitions seen by a ManagedSystem on this HMC
* @param system * @param system a valid ManagedSystem
* @return * @return Map of partition-id and LogicalPartition
*/ */
Map<String, LogicalPartition> getLogicalPartitionsForManagedSystem(ManagedSystem system) throws Exception { Map<String, LogicalPartition> getLogicalPartitionsForManagedSystem(ManagedSystem system) throws Exception {
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));
@ -225,7 +226,7 @@ class HmcClient {
system system
); );
partitionMap.put(logicalPartition.id, logicalPartition); partitionMap.put(logicalPartition.id, logicalPartition);
log.info("getLogicalPartitionsForManagedSystem() - Found partition: " + logicalPartition.toString()); log.debug("getLogicalPartitionsForManagedSystem() - Found partition: " + logicalPartition.toString());
} }
} catch(Exception e) { } catch(Exception e) {
@ -239,8 +240,8 @@ class HmcClient {
/** /**
* Parse XML feed to get PCM Data in JSON format * Parse XML feed to get PCM Data in JSON format
* @param system * @param system a valid ManagedSystem
* @return * @return JSON string with PCM data for this ManagedSystem
*/ */
String getPcmDataForManagedSystem(ManagedSystem system) throws Exception { String getPcmDataForManagedSystem(ManagedSystem system) throws Exception {
@ -254,7 +255,7 @@ class HmcClient {
if(responseBody.isEmpty() || responseBody.length() <= 1) { if(responseBody.isEmpty() || responseBody.length() <= 1) {
responseErrors++; responseErrors++;
log.warn("getPcmDataForManagedSystem() - empty response"); log.warn("getPcmDataForManagedSystem() - empty response");
return jsonBody; return null;
} }
try { try {
@ -278,8 +279,8 @@ class HmcClient {
/** /**
* Parse XML feed to get PCM Data in JSON format * Parse XML feed to get PCM Data in JSON format
* @param partition * @param partition a valid LogicalPartition
* @return * @return JSON string with PCM data for this LogicalPartition
*/ */
String getPcmDataForLogicalPartition(LogicalPartition partition) throws Exception { String getPcmDataForLogicalPartition(LogicalPartition partition) throws Exception {
@ -293,7 +294,7 @@ class HmcClient {
if(responseBody.isEmpty() || responseBody.length() <= 1) { if(responseBody.isEmpty() || responseBody.length() <= 1) {
responseErrors++; responseErrors++;
log.warn("getPcmDataForLogicalPartition() - empty response"); log.warn("getPcmDataForLogicalPartition() - empty response");
return jsonBody; return null;
} }
try { try {
@ -310,19 +311,6 @@ class HmcClient {
} catch(Exception e) { } catch(Exception e) {
log.warn("getPcmDataForLogicalPartition() - xml parse error", e); log.warn("getPcmDataForLogicalPartition() - xml parse error", e);
} }
/*
try {
Document doc = Jsoup.parse(responseBody);
Element entry = doc.select("entry").first();
Element link = entry.select("link[href]").first();
if(link.attr("type") == "application/json") {
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;
} }
@ -331,8 +319,8 @@ class HmcClient {
/** /**
* Return body text from a HTTP response from the HMC * Return body text from a HTTP response from the HMC
* *
* @param url * @param url URL to get response body as String
* @return * @return String with http reponse body
*/ */
protected String getResponseBody(URL url) throws Exception { protected String getResponseBody(URL url) throws Exception {
Response response = getResponse(url); Response response = getResponse(url);
@ -344,8 +332,8 @@ class HmcClient {
/** /**
* Return a Response from the HMC * Return a Response from the HMC
* @param url * @param url to get Response from
* @return * @return Response object
*/ */
private Response getResponse(URL url) throws Exception { private Response getResponse(URL url) throws Exception {
return getResponse(url, 0); return getResponse(url, 0);
@ -354,9 +342,9 @@ class HmcClient {
/** /**
* Return a Response from the HMC * Return a Response from the HMC
* @param url * @param url to get Response from
* @param retry * @param retry number of retries for this call
* @return * @return Response object
*/ */
private Response getResponse(URL url, Integer retry) throws Exception { private Response getResponse(URL url, Integer retry) throws Exception {
@ -377,7 +365,7 @@ class HmcClient {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
if (!response.isSuccessful()) { if (!response.isSuccessful()) {
response.body().close(); Objects.requireNonNull(response.body()).close();
if(response.code() == 401) { if(response.code() == 401) {
login(true); login(true);
@ -391,7 +379,7 @@ class HmcClient {
log.error("getResponse() - Unexpected response: " + response.code()); log.error("getResponse() - Unexpected response: " + response.code());
throw new IOException("getResponse() - Unexpected response: " + response.code()); throw new IOException("getResponse() - Unexpected response: " + response.code());
}; }
return response; return response;
} }
@ -432,15 +420,9 @@ class HmcClient {
OkHttpClient.Builder builder = new OkHttpClient.Builder(); OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]); builder.sslSocketFactory(sslSocketFactory, (X509TrustManager)trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() { builder.hostnameVerifier((hostname, session) -> true);
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
OkHttpClient okHttpClient = builder.build(); return builder.build();
return okHttpClient;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -1,4 +1,4 @@
/** /*
* Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com> * Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,4 +1,4 @@
/** /*
* Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com> * Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -20,6 +20,9 @@ import org.slf4j.LoggerFactory;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import static java.lang.Thread.*;
class Insights { class Insights {
@ -28,9 +31,9 @@ class Insights {
final Configuration configuration; final Configuration configuration;
InfluxClient influxClient; InfluxClient influxClient;
Map<String, HmcClient> hmcClients = new HashMap<>(); final Map<String, HmcClient> hmcClients = new HashMap<>();
Map<String,ManagedSystem> systems = new HashMap<String, ManagedSystem>(); final Map<String,ManagedSystem> systems = new HashMap<>();
Map<String, LogicalPartition> partitions = new HashMap<String, LogicalPartition>(); final Map<String, LogicalPartition> partitions = new HashMap<>();
Insights(Configuration configuration) { Insights(Configuration configuration) {
@ -52,7 +55,6 @@ class Insights {
configuration.hmc.forEach( configHmc -> { configuration.hmc.forEach( configHmc -> {
if(hmcClients != null && !hmcClients.containsKey(configHmc.name)) { if(hmcClients != null && !hmcClients.containsKey(configHmc.name)) {
log.debug("Adding HMC: " + configHmc.toString());
HmcClient hmcClient = new HmcClient(configHmc); HmcClient hmcClient = new HmcClient(configHmc);
hmcClients.put(configHmc.name, hmcClient); hmcClients.put(configHmc.name, hmcClient);
} }
@ -82,7 +84,6 @@ class Insights {
} catch(Exception e) { } catch(Exception e) {
log.error("discover() - " + hmcId + " error: " + e.getMessage()); log.error("discover() - " + hmcId + " error: " + e.getMessage());
//hmcClients.remove(hmcId);
} }
}); });
@ -102,7 +103,6 @@ class Insights {
tmpJsonString = hmcClient.getPcmDataForManagedSystem(system); tmpJsonString = hmcClient.getPcmDataForManagedSystem(system);
} catch (Exception e) { } catch (Exception e) {
log.error("getMetricsForSystems()", e); log.error("getMetricsForSystems()", e);
//e.printStackTrace();
} }
if(tmpJsonString != null && !tmpJsonString.isEmpty()) { if(tmpJsonString != null && !tmpJsonString.isEmpty()) {
@ -128,7 +128,7 @@ class Insights {
try { try {
tmpJsonString2 = hmcClient.getPcmDataForLogicalPartition(partition); tmpJsonString2 = hmcClient.getPcmDataForLogicalPartition(partition);
} catch (Exception e) { } catch (Exception e) {
log.error("getMetricsForPartitions()", e); log.error("getMetricsForPartitions() - getPcmDataForLogicalPartition", e);
} }
if(tmpJsonString2 != null && !tmpJsonString2.isEmpty()) { if(tmpJsonString2 != null && !tmpJsonString2.isEmpty()) {
partition.processMetrics(tmpJsonString2); partition.processMetrics(tmpJsonString2);
@ -160,8 +160,12 @@ class Insights {
log.debug("run()"); log.debug("run()");
int executions = 0; int executions = 0;
AtomicBoolean keepRunning = new AtomicBoolean(true);
while(true) { Thread shutdownHook = new Thread(() -> keepRunning.set(false));
Runtime.getRuntime().addShutdownHook(shutdownHook);
do {
try { try {
getMetricsForSystems(); getMetricsForSystems();
@ -172,17 +176,18 @@ class Insights {
influxClient.writeBatchPoints(); influxClient.writeBatchPoints();
// Refresh HMC's // Refresh HMC's
if(executions > configuration.rescan) { if (executions > configuration.rescan) {
executions = 0; executions = 0;
discover(); discover();
} }
} catch(Exception e) { } catch (Exception e) {
log.error("run()", e.getMessage()); log.error("run()", e);
} }
executions++; executions++;
Thread.sleep(configuration.refresh * 1000); sleep(configuration.refresh * 1000);
}
} while (keepRunning.get());
} }

View File

@ -1,4 +1,4 @@
/** /*
* Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com> * Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -27,10 +27,10 @@ class LogicalPartition extends MetaSystem {
private final static Logger log = LoggerFactory.getLogger(LogicalPartition.class); private final static Logger log = LoggerFactory.getLogger(LogicalPartition.class);
public String id; public final String id;
public String name; public final String name;
public String type; public final String type;
public ManagedSystem system; public final ManagedSystem system;
LogicalPartition(String id, String name, String type, ManagedSystem system) { LogicalPartition(String id, String name, String type, ManagedSystem system) {

View File

@ -32,6 +32,7 @@ public class Main implements Callable<Integer> {
private final static Logger log = LoggerFactory.getLogger(Main.class); private final static Logger log = LoggerFactory.getLogger(Main.class);
@SuppressWarnings("FieldMayBeFinal")
@CommandLine.Option(names = { "-c", "--conf" }, description = "Configuration file [default: '/etc/hmci.toml'].") @CommandLine.Option(names = { "-c", "--conf" }, description = "Configuration file [default: '/etc/hmci.toml'].")
private String configurationFile = "/etc/hmci.toml"; private String configurationFile = "/etc/hmci.toml";

View File

@ -1,4 +1,4 @@
/** /*
* Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com> * Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -99,7 +99,7 @@ class ManagedSystem extends MetaSystem {
HashMap<String, Number> fieldsMap = new HashMap<String, Number>() { HashMap<String, Number> fieldsMap = new HashMap<String, Number>() {
{ {
put("availableProcUnits", metrics.systemUtil.sample.serverUtil.processor.totalProcUnits); put("totalProcUnits", metrics.systemUtil.sample.serverUtil.processor.totalProcUnits);
put("utilizedProcUnits", metrics.systemUtil.sample.serverUtil.processor.utilizedProcUnits); put("utilizedProcUnits", metrics.systemUtil.sample.serverUtil.processor.utilizedProcUnits);
put("availableProcUnits", metrics.systemUtil.sample.serverUtil.processor.availableProcUnits); put("availableProcUnits", metrics.systemUtil.sample.serverUtil.processor.availableProcUnits);
put("configurableProcUnits", metrics.systemUtil.sample.serverUtil.processor.configurableProcUnits); put("configurableProcUnits", metrics.systemUtil.sample.serverUtil.processor.configurableProcUnits);

View File

@ -1,4 +1,4 @@
/** /*
* Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com> * Copyright 2020 Mark Nellemann <mark.nellemann@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -2,8 +2,6 @@ package biz.nellemann.hmci.pcm;
import com.serjltt.moshi.adapters.FirstElement; import com.serjltt.moshi.adapters.FirstElement;
import java.util.List;
public class FiberChannelAdapter { public class FiberChannelAdapter {
public String id; public String id;

View File

@ -2,8 +2,6 @@ package biz.nellemann.hmci.pcm;
import com.serjltt.moshi.adapters.FirstElement; import com.serjltt.moshi.adapters.FirstElement;
import java.util.List;
public class GenericPhysicalAdapters { public class GenericPhysicalAdapters {
public String id; public String id;

View File

@ -2,8 +2,6 @@ package biz.nellemann.hmci.pcm;
import com.serjltt.moshi.adapters.FirstElement; import com.serjltt.moshi.adapters.FirstElement;
import java.util.List;
public class LparProcessor { public class LparProcessor {
public Integer poolId; public Integer poolId;

View File

@ -1,9 +1,6 @@
package biz.nellemann.hmci.pcm; package biz.nellemann.hmci.pcm;
import com.serjltt.moshi.adapters.FirstElement; import com.serjltt.moshi.adapters.FirstElement;
import com.squareup.moshi.Json;
import java.util.List;
public class ServerMemory { public class ServerMemory {

View File

@ -2,7 +2,6 @@ package biz.nellemann.hmci.pcm;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
public class Storage { public class Storage {

View File

@ -2,8 +2,6 @@ package biz.nellemann.hmci.pcm;
import com.serjltt.moshi.adapters.FirstElement; import com.serjltt.moshi.adapters.FirstElement;
import java.util.List;
public class VirtualEthernetAdapter { public class VirtualEthernetAdapter {
public String physicalLocation; public String physicalLocation;

View File

@ -10,7 +10,7 @@ class ConfigurationTest extends Specification {
void "test parsing"() { void "test parsing"() {
when: when:
Configuration conf = new Configuration(testConfigurationFile); Configuration conf = new Configuration(testConfigurationFile)
then: then:
conf != null conf != null
@ -20,7 +20,7 @@ class ConfigurationTest extends Specification {
void "test lookup influx"() { void "test lookup influx"() {
when: when:
Configuration conf = new Configuration(testConfigurationFile); Configuration conf = new Configuration(testConfigurationFile)
then: then:
conf != null conf != null

View File

@ -7,11 +7,11 @@ import spock.lang.Specification
class HmcClientTest extends Specification { class HmcClientTest extends Specification {
HmcClient hmc HmcClient hmc
MockWebServer mockServer = new MockWebServer(); MockWebServer mockServer = new MockWebServer()
def setup() { def setup() {
mockServer.start(); mockServer.start()
Configuration.HmcObject configHmc = new Configuration.HmcObject() Configuration.HmcObject configHmc = new Configuration.HmcObject()
configHmc.name = "site1" configHmc.name = "site1"
configHmc.url = mockServer.url("/").toString() configHmc.url = mockServer.url("/").toString()
@ -29,7 +29,7 @@ class HmcClientTest extends Specification {
void "test against empty xml"() { void "test against empty xml"() {
setup: setup:
def testXml = "" def testXml = ""
mockServer.enqueue(new MockResponse().setBody(testXml)); mockServer.enqueue(new MockResponse().setBody(testXml))
when: when:
Map<String, ManagedSystem> systems = hmc.getManagedSystems() Map<String, ManagedSystem> systems = hmc.getManagedSystems()
@ -43,7 +43,7 @@ class HmcClientTest extends Specification {
setup: setup:
def testFile = new File(getClass().getResource('/managed-systems.xml').toURI()) def testFile = new File(getClass().getResource('/managed-systems.xml').toURI())
def testXml = testFile.getText('UTF-8') def testXml = testFile.getText('UTF-8')
mockServer.enqueue(new MockResponse().setBody(testXml)); mockServer.enqueue(new MockResponse().setBody(testXml))
when: when:
Map<String, ManagedSystem> systems = hmc.getManagedSystems() Map<String, ManagedSystem> systems = hmc.getManagedSystems()
@ -58,7 +58,7 @@ class HmcClientTest extends Specification {
setup: setup:
def testFile = new File(getClass().getResource('/logical-partitions.xml').toURI()) def testFile = new File(getClass().getResource('/logical-partitions.xml').toURI())
def testXml = testFile.getText('UTF-8') def testXml = testFile.getText('UTF-8')
mockServer.enqueue(new MockResponse().setBody(testXml)); mockServer.enqueue(new MockResponse().setBody(testXml))
when: when:
ManagedSystem system = new ManagedSystem("site1", "e09834d1-c930-3883-bdad-405d8e26e166", "Test Name","Test Type", "Test Model", "Test S/N") ManagedSystem system = new ManagedSystem("site1", "e09834d1-c930-3883-bdad-405d8e26e166", "Test Name","Test Type", "Test Model", "Test S/N")
@ -75,7 +75,7 @@ class HmcClientTest extends Specification {
setup: setup:
def testFile = new File(getClass().getResource('/pcm-data-managed-system.json').toURI()) def testFile = new File(getClass().getResource('/pcm-data-managed-system.json').toURI())
def testJson = testFile.getText('UTF-8') def testJson = testFile.getText('UTF-8')
mockServer.enqueue(new MockResponse().setBody(testJson)); mockServer.enqueue(new MockResponse().setBody(testJson))
when: when:
String jsonString = hmc.getResponseBody(new URL(mockServer.url("/rest/api/pcm/ProcessedMetrics/ManagedSystem_e09834d1-c930-3883-bdad-405d8e26e166_20200807T122600+0200_20200807T122600+0200_30.json") as String)) String jsonString = hmc.getResponseBody(new URL(mockServer.url("/rest/api/pcm/ProcessedMetrics/ManagedSystem_e09834d1-c930-3883-bdad-405d8e26e166_20200807T122600+0200_20200807T122600+0200_30.json") as String))
@ -89,7 +89,7 @@ class HmcClientTest extends Specification {
setup: setup:
def testFile = new File(getClass().getResource('/pcm-data-logical-partition.json').toURI()) def testFile = new File(getClass().getResource('/pcm-data-logical-partition.json').toURI())
def testJson = testFile.getText('UTF-8') def testJson = testFile.getText('UTF-8')
mockServer.enqueue(new MockResponse().setBody(testJson)); mockServer.enqueue(new MockResponse().setBody(testJson))
when: when:
String jsonString = hmc.getResponseBody(new URL(mockServer.url("/rest/api/pcm/ProcessedMetrics/LogicalPartition_2DE05DB6-8AD5-448F-8327-0F488D287E82_20200807T123730+0200_20200807T123730+0200_30.json") as String)) String jsonString = hmc.getResponseBody(new URL(mockServer.url("/rest/api/pcm/ProcessedMetrics/LogicalPartition_2DE05DB6-8AD5-448F-8327-0F488D287E82_20200807T123730+0200_20200807T123730+0200_30.json") as String))

View File

@ -9,7 +9,7 @@ class InfluxClientTest extends Specification {
InfluxClient influxClient InfluxClient influxClient
def setup() { def setup() {
influxClient = new InfluxClient("http://localhost:8086", "root", "", "hmci") influxClient = new InfluxClient(new Configuration.InfluxObject("http://localhost:8086", "root", "", "hmci"))
influxClient.login() influxClient.login()
} }