Avoid HMC sessions timeouts. #2

Merged
nellemann merged 4 commits from sessiontimeouts into main 2023-11-13 13:16:46 +00:00
9 changed files with 92 additions and 59 deletions
Showing only changes of commit a24b03f4ad - Show all commits

View file

@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## 1.4.5 - 2023-11-13
- Adjust timeout to not have lingering sessions on HMC
- Update 3rd party dependencies
## 1.4.4 - 2023-05-20 ## 1.4.4 - 2023-05-20
- Support for InfluxDB v2, now requires InfluxDB 1.8 or later - Support for InfluxDB v2, now requires InfluxDB 1.8 or later
- Increase influx writer buffer limit - Increase influx writer buffer limit

View file

@ -4,7 +4,7 @@ plugins {
id 'groovy' id 'groovy'
id 'application' id 'application'
id "net.nemerosa.versioning" version "2.15.1" id "net.nemerosa.versioning" version "2.15.1"
id "com.netflix.nebula.ospackage" version "11.4.0" id "com.netflix.nebula.ospackage" version "11.5.0"
id "com.github.johnrengelman.shadow" version "7.1.2" id "com.github.johnrengelman.shadow" version "7.1.2"
} }
@ -17,10 +17,10 @@ group = projectGroup
version = projectVersion version = projectVersion
dependencies { dependencies {
annotationProcessor 'info.picocli:picocli-codegen:4.7.4' annotationProcessor 'info.picocli:picocli-codegen:4.7.5'
implementation 'info.picocli:picocli:4.7.4' implementation 'info.picocli:picocli:4.7.5'
implementation 'org.slf4j:slf4j-api:2.0.7' implementation 'org.slf4j:slf4j-api:2.0.9'
implementation 'org.slf4j:slf4j-simple:2.0.7' implementation 'org.slf4j:slf4j-simple:2.0.9'
implementation 'com.squareup.okhttp3:okhttp:4.11.0' // Also used by InfluxDB Client implementation 'com.squareup.okhttp3:okhttp:4.11.0' // Also used by InfluxDB Client
implementation 'com.influxdb:influxdb-client-java:6.10.0' implementation 'com.influxdb:influxdb-client-java:6.10.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2' implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'

View file

@ -15,17 +15,19 @@
*/ */
package biz.nellemann.hmci; package biz.nellemann.hmci;
import biz.nellemann.hmci.dto.toml.Configuration;
import com.fasterxml.jackson.dataformat.toml.TomlMapper;
import picocli.CommandLine;
import picocli.CommandLine.Option;
import picocli.CommandLine.Command;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import com.fasterxml.jackson.dataformat.toml.TomlMapper;
import biz.nellemann.hmci.dto.toml.Configuration;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
@Command(name = "hmci", @Command(name = "hmci",
mixinStandardHelpOptions = true, mixinStandardHelpOptions = true,
versionProvider = biz.nellemann.hmci.VersionProvider.class, versionProvider = biz.nellemann.hmci.VersionProvider.class,
@ -90,7 +92,7 @@ public class Application implements Callable<Integer> {
} }
influxClient.logoff(); influxClient.logoff();
} catch (Exception e) { } catch (IOException | InterruptedException e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
return 1; return 1;
} }

View file

@ -15,20 +15,21 @@
*/ */
package biz.nellemann.hmci; package biz.nellemann.hmci;
import biz.nellemann.hmci.dto.toml.InfluxConfiguration; import static java.lang.Thread.sleep;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.influxdb.client.InfluxDBClient; import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory; import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.WriteApi; import com.influxdb.client.WriteApi;
import com.influxdb.client.WriteOptions; import com.influxdb.client.WriteOptions;
import com.influxdb.client.write.Point;
import com.influxdb.client.domain.WritePrecision; import com.influxdb.client.domain.WritePrecision;
import org.slf4j.Logger; import com.influxdb.client.write.Point;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import biz.nellemann.hmci.dto.toml.InfluxConfiguration;
import java.util.List;
import static java.lang.Thread.sleep;
public final class InfluxClient { public final class InfluxClient {

View file

@ -15,21 +15,25 @@
*/ */
package biz.nellemann.hmci; package biz.nellemann.hmci;
import java.io.IOException;
import static java.lang.Thread.sleep;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import biz.nellemann.hmci.dto.toml.HmcConfiguration; import biz.nellemann.hmci.dto.toml.HmcConfiguration;
import biz.nellemann.hmci.dto.xml.Link; import biz.nellemann.hmci.dto.xml.Link;
import biz.nellemann.hmci.dto.xml.ManagementConsoleEntry; import biz.nellemann.hmci.dto.xml.ManagementConsoleEntry;
import biz.nellemann.hmci.dto.xml.XmlFeed; import biz.nellemann.hmci.dto.xml.XmlFeed;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import static java.lang.Thread.sleep;
class ManagementConsole implements Runnable { class ManagementConsole implements Runnable {
@ -170,7 +174,7 @@ class ManagementConsole implements Runnable {
} }
} }
} catch (Exception e) { } catch (IOException e) {
log.warn("discover() - error: {}", e.getMessage()); log.warn("discover() - error: {}", e.getMessage());
} }

View file

@ -1,17 +1,8 @@
package biz.nellemann.hmci; package biz.nellemann.hmci;
import biz.nellemann.hmci.dto.xml.LogonResponse; import java.io.IOException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper; import java.net.MalformedURLException;
import okhttp3.*; import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.*;
import java.net.*;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
@ -21,6 +12,23 @@ import java.time.temporal.ChronoUnit;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import biz.nellemann.hmci.dto.xml.LogonResponse;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class RestClient { public class RestClient {
private final static Logger log = LoggerFactory.getLogger(RestClient.class); private final static Logger log = LoggerFactory.getLogger(RestClient.class);
@ -173,6 +181,7 @@ public class RestClient {
* Return a Response from the HMC * Return a Response from the HMC
* @param url to get Response from * @param url to get Response from
* @return Response body string * @return Response body string
* @throws IOException
*/ */
public synchronized String getRequest(URL url) throws IOException { public synchronized String getRequest(URL url) throws IOException {
@ -234,6 +243,10 @@ public class RestClient {
/** /**
* Send a POST request with a payload (can be null) to the HMC * Send a POST request with a payload (can be null) to the HMC
* @param url
* @param payload
* @return Response body string
* @throws IOException
*/ */
public synchronized String postRequest(URL url, String payload) throws IOException { public synchronized String postRequest(URL url, String payload) throws IOException {

View file

@ -1,14 +1,20 @@
package biz.nellemann.hmci; package biz.nellemann.hmci;
import biz.nellemann.hmci.dto.xml.Link;
import biz.nellemann.hmci.dto.xml.XmlFeed;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import biz.nellemann.hmci.dto.xml.Link;
import biz.nellemann.hmci.dto.xml.XmlFeed;
class SystemEnergy extends Resource { class SystemEnergy extends Resource {

View file

@ -15,12 +15,12 @@
*/ */
package biz.nellemann.hmci; package biz.nellemann.hmci;
import picocli.CommandLine;
import java.io.IOException; import java.io.IOException;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import picocli.CommandLine;
class VersionProvider implements CommandLine.IVersionProvider { class VersionProvider implements CommandLine.IVersionProvider {
@Override @Override

View file

@ -1,13 +1,16 @@
package biz.nellemann.hmci; package biz.nellemann.hmci;
import biz.nellemann.hmci.dto.xml.VirtualIOServerEntry; import java.io.IOException;
import biz.nellemann.hmci.dto.xml.XmlEntry; import java.net.URI;
import com.fasterxml.jackson.dataformat.xml.XmlMapper; import java.net.URISyntaxException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.net.URI; import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import java.net.URISyntaxException;
import biz.nellemann.hmci.dto.xml.VirtualIOServerEntry;
import biz.nellemann.hmci.dto.xml.XmlEntry;
public class VirtualIOServer { public class VirtualIOServer {
private final static Logger log = LoggerFactory.getLogger(VirtualIOServer.class); private final static Logger log = LoggerFactory.getLogger(VirtualIOServer.class);
@ -58,7 +61,7 @@ public class VirtualIOServer {
throw new UnsupportedOperationException("Failed to deserialize VirtualIOServer"); throw new UnsupportedOperationException("Failed to deserialize VirtualIOServer");
} }
} catch (Exception e) { } catch (IOException e) {
log.error("discover() - error: {}", e.getMessage()); log.error("discover() - error: {}", e.getMessage());
} }
} }