From 5d4f481837439ca4ea47dc38bdfcff3ef9d0d88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?= Date: Thu, 3 Mar 2022 09:46:15 +0000 Subject: [PATCH 01/10] Use stdout as error message in case not stderr for SaltSSHError --- .../salt/netapi/parser/ResultSSHResultTypeAdapterFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/suse/salt/netapi/parser/ResultSSHResultTypeAdapterFactory.java b/src/main/java/com/suse/salt/netapi/parser/ResultSSHResultTypeAdapterFactory.java index 4d6fd83c1..84c055dbd 100644 --- a/src/main/java/com/suse/salt/netapi/parser/ResultSSHResultTypeAdapterFactory.java +++ b/src/main/java/com/suse/salt/netapi/parser/ResultSSHResultTypeAdapterFactory.java @@ -85,7 +85,7 @@ public Result> read(JsonReader in) throws IOException { .flatMap(SaltErrorUtils::deriveError) .orElse( new SaltSSHError(result.getRetcode(), - result.getStderr().orElse("")) + result.getStderr().orElse(result.getStdout().orElse(""))) ) ); } else { From 39f16e56b8ea4634d4c1265a5632f0284d08ba22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?= Date: Thu, 3 Mar 2022 16:38:04 +0000 Subject: [PATCH 02/10] Add both stderr and stdout to SaltSSHError message --- .../salt/netapi/parser/ResultSSHResultTypeAdapterFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/suse/salt/netapi/parser/ResultSSHResultTypeAdapterFactory.java b/src/main/java/com/suse/salt/netapi/parser/ResultSSHResultTypeAdapterFactory.java index 84c055dbd..669f961b8 100644 --- a/src/main/java/com/suse/salt/netapi/parser/ResultSSHResultTypeAdapterFactory.java +++ b/src/main/java/com/suse/salt/netapi/parser/ResultSSHResultTypeAdapterFactory.java @@ -85,7 +85,8 @@ public Result> read(JsonReader in) throws IOException { .flatMap(SaltErrorUtils::deriveError) .orElse( new SaltSSHError(result.getRetcode(), - result.getStderr().orElse(result.getStdout().orElse(""))) + "stderr: \"" + result.getStderr().orElse("") + + "\", stdout: \"" + result.getStdout().orElse("") + "\"") ) ); } else { From d7b92db5333b14ebcfffa7df6f335fdc7359e239 Mon Sep 17 00:00:00 2001 From: Kevin Walter Date: Mon, 28 Mar 2022 14:11:52 +0200 Subject: [PATCH 03/10] handle array of names and null --- .../com/suse/salt/netapi/results/StateApplyResult.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/suse/salt/netapi/results/StateApplyResult.java b/src/main/java/com/suse/salt/netapi/results/StateApplyResult.java index cac1181d6..4d9cbf770 100644 --- a/src/main/java/com/suse/salt/netapi/results/StateApplyResult.java +++ b/src/main/java/com/suse/salt/netapi/results/StateApplyResult.java @@ -1,6 +1,9 @@ package com.suse.salt.netapi.results; import com.google.gson.annotations.SerializedName; +import com.suse.salt.netapi.utils.Xor; + +import java.util.Optional; /** * Result structure as returned by state.apply to be parsed from event data. @@ -10,7 +13,7 @@ public class StateApplyResult { private String comment; - private String name; + private Optional> name = Optional.empty(); @SerializedName("start_time") private String startTime; private boolean result; @@ -23,7 +26,7 @@ public String getComment() { return comment; } - public String getName() { + public Optional> getName() { return name; } From aa4d8c8bccfc104a05e7ca6bc471cf1353ab2b55 Mon Sep 17 00:00:00 2001 From: Kevin Walter Date: Wed, 20 Apr 2022 16:35:52 +0200 Subject: [PATCH 04/10] Update version to 0.20.0 in pom.xml and README.md --- README.md | 4 ++-- pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 330da70ec..7f133e70d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # salt-netapi-client -Java bindings for the [Salt API](http://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#module-salt.netapi.rest_cherrypy.app), please have a look at the Javadoc for [v0.19.0](http://suse.github.io/salt-netapi-client/docs/v0.19.0) or [master](http://suse.github.io/salt-netapi-client/docs/master). +Java bindings for the [Salt API](http://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#module-salt.netapi.rest_cherrypy.app), please have a look at the Javadoc for [v0.20.0](http://suse.github.io/salt-netapi-client/docs/v0.20.0) or [master](http://suse.github.io/salt-netapi-client/docs/master). ## How to use it @@ -13,7 +13,7 @@ Add the following dependency to the `pom.xml` file of your project: com.suse.salt salt-netapi-client - 0.19.0 + 0.20.0 ``` diff --git a/pom.xml b/pom.xml index c7306a307..2c4653527 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.suse.salt salt-netapi-client jar - 0.20.0-SNAPSHOT + 0.20.0 salt-netapi-client https://github.com/SUSE/salt-netapi-client Java bindings for the Salt API From 6f8c8a4388bc619c006f0f5549e3392794a8492b Mon Sep 17 00:00:00 2001 From: Johannes Hahn Date: Tue, 26 Apr 2022 17:34:33 +0200 Subject: [PATCH 05/10] Update the version to 0.21.0-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2c4653527..834102829 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.suse.salt salt-netapi-client jar - 0.20.0 + 0.21.0-SNAPSHOT salt-netapi-client https://github.com/SUSE/salt-netapi-client Java bindings for the Salt API From e976f55a3f33770b6880552647e68452353230dc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 20 May 2022 20:48:16 +0000 Subject: [PATCH 06/10] Bump gson from 2.8.2 to 2.8.9 Bumps [gson](https://github.com/google/gson) from 2.8.2 to 2.8.9. - [Release notes](https://github.com/google/gson/releases) - [Changelog](https://github.com/google/gson/blob/master/CHANGELOG.md) - [Commits](https://github.com/google/gson/compare/gson-parent-2.8.2...gson-parent-2.8.9) --- updated-dependencies: - dependency-name: com.google.code.gson:gson dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 834102829..e87b2e448 100644 --- a/pom.xml +++ b/pom.xml @@ -131,7 +131,7 @@ com.google.code.gson gson - 2.8.2 + 2.8.9 org.apache.httpcomponents From 1dd4821cf63193206d61e13f719a7b6f55e77a62 Mon Sep 17 00:00:00 2001 From: Welder Luz Date: Wed, 14 Dec 2022 06:57:38 -0300 Subject: [PATCH 07/10] Add transactional_update module --- .../calls/modules/TransactionalUpdate.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/com/suse/salt/netapi/calls/modules/TransactionalUpdate.java diff --git a/src/main/java/com/suse/salt/netapi/calls/modules/TransactionalUpdate.java b/src/main/java/com/suse/salt/netapi/calls/modules/TransactionalUpdate.java new file mode 100644 index 000000000..e72ded76b --- /dev/null +++ b/src/main/java/com/suse/salt/netapi/calls/modules/TransactionalUpdate.java @@ -0,0 +1,22 @@ +package com.suse.salt.netapi.calls.modules; + +import com.suse.salt.netapi.calls.LocalCall; + +import com.google.gson.reflect.TypeToken; + +import java.util.Optional; + +/** + * salt.modules.transactional_update + * + * https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.transactional_update.html + */ +public class TransactionalUpdate { + private TransactionalUpdate() { } + + public static LocalCall reboot() { + return new LocalCall<>("transactional_update.reboot", Optional.empty(), Optional.empty(), + new TypeToken() { + }); + } +} From 6423a4718892b48ff4437c35b752778c5e544862 Mon Sep 17 00:00:00 2001 From: Welder Luz Date: Wed, 11 Jan 2023 10:23:45 -0300 Subject: [PATCH 08/10] Improve logging when creating salt exception --- .../client/impl/HttpAsyncClientImpl.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/suse/salt/netapi/client/impl/HttpAsyncClientImpl.java b/src/main/java/com/suse/salt/netapi/client/impl/HttpAsyncClientImpl.java index 76b5ce8e1..bef279014 100644 --- a/src/main/java/com/suse/salt/netapi/client/impl/HttpAsyncClientImpl.java +++ b/src/main/java/com/suse/salt/netapi/client/impl/HttpAsyncClientImpl.java @@ -15,10 +15,14 @@ import org.apache.http.entity.StringEntity; import org.apache.http.nio.client.HttpAsyncClient; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.URI; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; +import java.util.stream.Collectors; /** * AsyncHttpClient implemented with Apache's HttpAsyncClient. @@ -118,7 +122,7 @@ public void completed(HttpResponse response) { future.completeExceptionally(e); } } else { - future.completeExceptionally(createSaltException(statusCode)); + future.completeExceptionally(createSaltException(response)); } } @@ -132,16 +136,27 @@ public void cancelled() { } /** - * Create the appropriate exception for the given HTTP status code. + * Create the appropriate exception for the given HTTP response. * - * @param statusCode HTTP status code + * @param response HTTP response * @return {@link SaltException} instance */ - private SaltException createSaltException(int statusCode) { + private SaltException createSaltException(HttpResponse response) { + int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_UNAUTHORIZED) { return new SaltUserUnauthorizedException( "Salt user does not have sufficient permissions"); } - return new SaltException("Response code: " + statusCode); + else { + String content = ""; + try { + content = new BufferedReader(new InputStreamReader(response.getEntity().getContent())) + .lines().parallel().collect(Collectors.joining("\n")); + } + catch (IOException e) { + // error trying to get the response body, nothing to do... + } + return new SaltException("Response code: " + statusCode + ". Response body:\n" + content); + } } } From 1130432f83585cfef6b32d214dac52eafea13dd6 Mon Sep 17 00:00:00 2001 From: Johannes Hahn Date: Thu, 12 Jan 2023 14:47:27 +0100 Subject: [PATCH 09/10] Update version to 0.21.0 --- README.md | 4 ++-- pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7f133e70d..08bc94ea2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # salt-netapi-client -Java bindings for the [Salt API](http://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#module-salt.netapi.rest_cherrypy.app), please have a look at the Javadoc for [v0.20.0](http://suse.github.io/salt-netapi-client/docs/v0.20.0) or [master](http://suse.github.io/salt-netapi-client/docs/master). +Java bindings for the [Salt API](http://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#module-salt.netapi.rest_cherrypy.app), please have a look at the Javadoc for [v0.21.0](http://suse.github.io/salt-netapi-client/docs/v0.21.0) or [master](http://suse.github.io/salt-netapi-client/docs/master). ## How to use it @@ -13,7 +13,7 @@ Add the following dependency to the `pom.xml` file of your project: com.suse.salt salt-netapi-client - 0.20.0 + 0.21.0 ``` diff --git a/pom.xml b/pom.xml index e87b2e448..0c062e246 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.suse.salt salt-netapi-client jar - 0.21.0-SNAPSHOT + 0.21.0 salt-netapi-client https://github.com/SUSE/salt-netapi-client Java bindings for the Salt API From d3b19b2c75af9282aceb012b65df446a2271bdf2 Mon Sep 17 00:00:00 2001 From: Johannes Hahn Date: Thu, 12 Jan 2023 17:31:10 +0100 Subject: [PATCH 10/10] Update version to 0.22.0-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0c062e246..a11ed2fd6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.suse.salt salt-netapi-client jar - 0.21.0 + 0.22.0-SNAPSHOT salt-netapi-client https://github.com/SUSE/salt-netapi-client Java bindings for the Salt API