From 29a53a98e31ac74f4eca7a7fee6ff391f465d5f4 Mon Sep 17 00:00:00 2001 From: k-wall Date: Fri, 26 Jun 2020 09:07:23 +0100 Subject: [PATCH 01/18] Add #4825 to changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b5c449dee5..108ba954463 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ * #4730: Enhance brokered address space's address controller (agent) to populate address plan status * #4753: Resizing broker volumes broken on OpenShift 4 * #4823: Update snakeyaml/hibernate validation dependencies to latest micro releases. +* #4825: Bump Jackson 2.10.0 -> 2.10.4 ## 0.31.4 * #4704: [OpenShift 3.11] Console returns 500 internal error when configured with custom certificate From 0974f8d6e276bb4fcd90ff3707c321aed52a7f0a Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 26 Jun 2020 10:24:51 +0200 Subject: [PATCH 02/18] Update pom.xml snapshot versions to 1.0-SNAPSHOT --- address-space-controller/pom.xml | 2 +- agent/pom.xml | 2 +- amqp-utils/pom.xml | 2 +- api-common/pom.xml | 2 +- api-model-annotator/pom.xml | 2 +- api-model/pom.xml | 2 +- broker-plugin/amqp-connector/pom.xml | 2 +- broker-plugin/broker-cli/pom.xml | 2 +- broker-plugin/plugin/pom.xml | 2 +- broker-plugin/pom.xml | 2 +- broker-plugin/sasl-delegation/pom.xml | 2 +- broker-plugin/tcnative/pom.xml | 2 +- bundle/pom.xml | 2 +- console/console-init/pom.xml | 2 +- console/console-server/pom.xml | 2 +- console/pom.xml | 2 +- controller-manager/pom.xml | 2 +- discovery-lib/pom.xml | 2 +- documentation/pom.xml | 2 +- iot/images/iot-adapters/pom.xml | 2 +- iot/images/iot-device-registry/pom.xml | 2 +- iot/iot-application-base/pom.xml | 2 +- iot/iot-auth-service/pom.xml | 2 +- iot/iot-device-connection-infinispan/pom.xml | 2 +- iot/iot-device-registry-base/pom.xml | 2 +- iot/iot-device-registry-infinispan/pom.xml | 2 +- iot/iot-device-registry-jdbc/pom.xml | 2 +- iot/iot-http-adapter/pom.xml | 2 +- iot/iot-infinispan-base/pom.xml | 2 +- iot/iot-jdbc-base/pom.xml | 2 +- iot/iot-lorawan-adapter/pom.xml | 2 +- iot/iot-mqtt-adapter/pom.xml | 2 +- iot/iot-proxy-configurator/pom.xml | 2 +- iot/iot-service-base/pom.xml | 2 +- iot/iot-sigfox-adapter/pom.xml | 2 +- iot/iot-tenant-cleaner/pom.xml | 2 +- iot/iot-tenant-service/pom.xml | 2 +- iot/iot-utils/pom.xml | 2 +- iot/pom.xml | 2 +- k8s-api-testutil/pom.xml | 2 +- k8s-api/pom.xml | 2 +- keycloak-plugin/pom.xml | 2 +- keycloak-plugin/sasl-plugin/pom.xml | 2 +- keycloak-user-api/pom.xml | 2 +- metrics-api/pom.xml | 2 +- mqtt-gateway/pom.xml | 2 +- mqtt-lwt/pom.xml | 2 +- none-authservice/pom.xml | 2 +- olm-manifest/pom.xml | 2 +- pom.properties | 4 ++-- pom.xml | 2 +- service-broker/pom.xml | 2 +- standard-controller/pom.xml | 2 +- systemtests/pom.xml | 2 +- templates/pom.xml | 2 +- topic-forwarder/pom.xml | 2 +- 56 files changed, 57 insertions(+), 57 deletions(-) diff --git a/address-space-controller/pom.xml b/address-space-controller/pom.xml index c71f947fd31..b7eb6f69e46 100644 --- a/address-space-controller/pom.xml +++ b/address-space-controller/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 address-space-controller diff --git a/agent/pom.xml b/agent/pom.xml index 9f2ac137cb8..7377451f694 100644 --- a/agent/pom.xml +++ b/agent/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 io.enmasse diff --git a/amqp-utils/pom.xml b/amqp-utils/pom.xml index 0a365109638..185a8096e5a 100644 --- a/amqp-utils/pom.xml +++ b/amqp-utils/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 amqp-utils diff --git a/api-common/pom.xml b/api-common/pom.xml index b1e7677e781..4d9be30e87d 100644 --- a/api-common/pom.xml +++ b/api-common/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 api-common diff --git a/api-model-annotator/pom.xml b/api-model-annotator/pom.xml index 157e5f543e2..7f1fc1aa6d2 100644 --- a/api-model-annotator/pom.xml +++ b/api-model-annotator/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 api-model-annotator diff --git a/api-model/pom.xml b/api-model/pom.xml index 42adb616d47..03627f552ec 100644 --- a/api-model/pom.xml +++ b/api-model/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 api-model diff --git a/broker-plugin/amqp-connector/pom.xml b/broker-plugin/amqp-connector/pom.xml index 0337027327c..aaa04e34ea4 100644 --- a/broker-plugin/amqp-connector/pom.xml +++ b/broker-plugin/amqp-connector/pom.xml @@ -4,7 +4,7 @@ io.enmasse broker-plugin - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 amqp-connector diff --git a/broker-plugin/broker-cli/pom.xml b/broker-plugin/broker-cli/pom.xml index bbfaa4139e6..eb7c2e225db 100644 --- a/broker-plugin/broker-cli/pom.xml +++ b/broker-plugin/broker-cli/pom.xml @@ -5,7 +5,7 @@ io.enmasse broker-plugin - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 broker-cli diff --git a/broker-plugin/plugin/pom.xml b/broker-plugin/plugin/pom.xml index 52091f824ba..a7a505fe5cb 100644 --- a/broker-plugin/plugin/pom.xml +++ b/broker-plugin/plugin/pom.xml @@ -4,7 +4,7 @@ io.enmasse broker-plugin - 0.32-SNAPSHOT + 1.0-SNAPSHOT pom 4.0.0 diff --git a/broker-plugin/pom.xml b/broker-plugin/pom.xml index f755836909f..8c5b2c688f2 100644 --- a/broker-plugin/pom.xml +++ b/broker-plugin/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT pom 4.0.0 diff --git a/broker-plugin/sasl-delegation/pom.xml b/broker-plugin/sasl-delegation/pom.xml index 18d2c7dd3c2..5705d973b9d 100644 --- a/broker-plugin/sasl-delegation/pom.xml +++ b/broker-plugin/sasl-delegation/pom.xml @@ -4,7 +4,7 @@ io.enmasse broker-plugin - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 sasl-delegation diff --git a/broker-plugin/tcnative/pom.xml b/broker-plugin/tcnative/pom.xml index 5b17b8685cd..8836053531f 100644 --- a/broker-plugin/tcnative/pom.xml +++ b/broker-plugin/tcnative/pom.xml @@ -4,7 +4,7 @@ io.enmasse broker-plugin - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 tcnative diff --git a/bundle/pom.xml b/bundle/pom.xml index 1f845e5bb83..f28582d5d61 100644 --- a/bundle/pom.xml +++ b/bundle/pom.xml @@ -5,7 +5,7 @@ enmasse io.enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT pom EnMasse Bundles diff --git a/console/console-init/pom.xml b/console/console-init/pom.xml index a7f5e5eceb4..85538679e00 100644 --- a/console/console-init/pom.xml +++ b/console/console-init/pom.xml @@ -5,7 +5,7 @@ io.enmasse console - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 io.enmasse diff --git a/console/console-server/pom.xml b/console/console-server/pom.xml index 6ee2f7c80fe..1c41b1f9fe3 100644 --- a/console/console-server/pom.xml +++ b/console/console-server/pom.xml @@ -4,7 +4,7 @@ io.enmasse console - 0.32-SNAPSHOT + 1.0-SNAPSHOT pom 4.0.0 diff --git a/console/pom.xml b/console/pom.xml index f53462f6171..379192c5654 100644 --- a/console/pom.xml +++ b/console/pom.xml @@ -5,7 +5,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 io.enmasse diff --git a/controller-manager/pom.xml b/controller-manager/pom.xml index 62bdb167a18..a2cb9ca0eaf 100644 --- a/controller-manager/pom.xml +++ b/controller-manager/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT pom 4.0.0 diff --git a/discovery-lib/pom.xml b/discovery-lib/pom.xml index 60ba254ec0f..60e15994dd8 100644 --- a/discovery-lib/pom.xml +++ b/discovery-lib/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 discovery-lib diff --git a/documentation/pom.xml b/documentation/pom.xml index ba20763d237..e931bb1dd00 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -5,7 +5,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 documentation diff --git a/iot/images/iot-adapters/pom.xml b/iot/images/iot-adapters/pom.xml index f53adbc85a5..fb350238334 100644 --- a/iot/images/iot-adapters/pom.xml +++ b/iot/images/iot-adapters/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../../ diff --git a/iot/images/iot-device-registry/pom.xml b/iot/images/iot-device-registry/pom.xml index 8ce64f8273d..087ed43c1d7 100644 --- a/iot/images/iot-device-registry/pom.xml +++ b/iot/images/iot-device-registry/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../../ diff --git a/iot/iot-application-base/pom.xml b/iot/iot-application-base/pom.xml index e726106e4af..6d77f1c35e2 100644 --- a/iot/iot-application-base/pom.xml +++ b/iot/iot-application-base/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot - 0.32-SNAPSHOT + 1.0-SNAPSHOT iot-application-base diff --git a/iot/iot-auth-service/pom.xml b/iot/iot-auth-service/pom.xml index 167f4e3ff47..7a1fdb26209 100644 --- a/iot/iot-auth-service/pom.xml +++ b/iot/iot-auth-service/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot-application-base - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../iot-application-base diff --git a/iot/iot-device-connection-infinispan/pom.xml b/iot/iot-device-connection-infinispan/pom.xml index 96293592c94..ffd013750d3 100644 --- a/iot/iot-device-connection-infinispan/pom.xml +++ b/iot/iot-device-connection-infinispan/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot-application-base - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../iot-application-base diff --git a/iot/iot-device-registry-base/pom.xml b/iot/iot-device-registry-base/pom.xml index 0dba3a71ab4..96d22b2580b 100644 --- a/iot/iot-device-registry-base/pom.xml +++ b/iot/iot-device-registry-base/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot - 0.32-SNAPSHOT + 1.0-SNAPSHOT iot-device-registry-base diff --git a/iot/iot-device-registry-infinispan/pom.xml b/iot/iot-device-registry-infinispan/pom.xml index 63be9dc268c..68f76b18750 100644 --- a/iot/iot-device-registry-infinispan/pom.xml +++ b/iot/iot-device-registry-infinispan/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot-application-base - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../iot-application-base diff --git a/iot/iot-device-registry-jdbc/pom.xml b/iot/iot-device-registry-jdbc/pom.xml index 4ebcf4916e5..d5e3e33943a 100644 --- a/iot/iot-device-registry-jdbc/pom.xml +++ b/iot/iot-device-registry-jdbc/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot-application-base - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../iot-application-base diff --git a/iot/iot-http-adapter/pom.xml b/iot/iot-http-adapter/pom.xml index 850f0558000..8e0c17ba3c3 100644 --- a/iot/iot-http-adapter/pom.xml +++ b/iot/iot-http-adapter/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot-application-base - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../iot-application-base diff --git a/iot/iot-infinispan-base/pom.xml b/iot/iot-infinispan-base/pom.xml index b034d947694..d81718ef78e 100644 --- a/iot/iot-infinispan-base/pom.xml +++ b/iot/iot-infinispan-base/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot - 0.32-SNAPSHOT + 1.0-SNAPSHOT iot-infinispan-base diff --git a/iot/iot-jdbc-base/pom.xml b/iot/iot-jdbc-base/pom.xml index c9c188464ec..fa5713ed71b 100644 --- a/iot/iot-jdbc-base/pom.xml +++ b/iot/iot-jdbc-base/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot - 0.32-SNAPSHOT + 1.0-SNAPSHOT iot-jdbc-base diff --git a/iot/iot-lorawan-adapter/pom.xml b/iot/iot-lorawan-adapter/pom.xml index 14ace593977..37af7e44a71 100644 --- a/iot/iot-lorawan-adapter/pom.xml +++ b/iot/iot-lorawan-adapter/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot-application-base - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../iot-application-base diff --git a/iot/iot-mqtt-adapter/pom.xml b/iot/iot-mqtt-adapter/pom.xml index 9d394c201f0..ebecf0c6e36 100644 --- a/iot/iot-mqtt-adapter/pom.xml +++ b/iot/iot-mqtt-adapter/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot-application-base - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../iot-application-base diff --git a/iot/iot-proxy-configurator/pom.xml b/iot/iot-proxy-configurator/pom.xml index 918fe3a2ec8..141c29f5d0f 100644 --- a/iot/iot-proxy-configurator/pom.xml +++ b/iot/iot-proxy-configurator/pom.xml @@ -4,7 +4,7 @@ io.enmasse iot-application-base - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../iot-application-base pom diff --git a/iot/iot-service-base/pom.xml b/iot/iot-service-base/pom.xml index 6f8f61ae32f..060137531cc 100644 --- a/iot/iot-service-base/pom.xml +++ b/iot/iot-service-base/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot - 0.32-SNAPSHOT + 1.0-SNAPSHOT iot-service-base diff --git a/iot/iot-sigfox-adapter/pom.xml b/iot/iot-sigfox-adapter/pom.xml index 697ab9e6f65..c03b9c75ce8 100644 --- a/iot/iot-sigfox-adapter/pom.xml +++ b/iot/iot-sigfox-adapter/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot-application-base - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../iot-application-base diff --git a/iot/iot-tenant-cleaner/pom.xml b/iot/iot-tenant-cleaner/pom.xml index 142a2bad873..945f3d2fdcc 100644 --- a/iot/iot-tenant-cleaner/pom.xml +++ b/iot/iot-tenant-cleaner/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot-application-base - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../iot-application-base diff --git a/iot/iot-tenant-service/pom.xml b/iot/iot-tenant-service/pom.xml index 18ad13ab336..cbd24ef243c 100644 --- a/iot/iot-tenant-service/pom.xml +++ b/iot/iot-tenant-service/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot-application-base - 0.32-SNAPSHOT + 1.0-SNAPSHOT ../iot-application-base diff --git a/iot/iot-utils/pom.xml b/iot/iot-utils/pom.xml index 39b573b4831..a72aceea52e 100644 --- a/iot/iot-utils/pom.xml +++ b/iot/iot-utils/pom.xml @@ -8,7 +8,7 @@ io.enmasse iot - 0.32-SNAPSHOT + 1.0-SNAPSHOT iot-utils diff --git a/iot/pom.xml b/iot/pom.xml index a28ef85ee86..ae39b1c2259 100644 --- a/iot/pom.xml +++ b/iot/pom.xml @@ -7,7 +7,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT iot pom diff --git a/k8s-api-testutil/pom.xml b/k8s-api-testutil/pom.xml index 6232b234d4f..ff64336abf9 100644 --- a/k8s-api-testutil/pom.xml +++ b/k8s-api-testutil/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 io.enmasse diff --git a/k8s-api/pom.xml b/k8s-api/pom.xml index e2298fae70a..da66b183872 100644 --- a/k8s-api/pom.xml +++ b/k8s-api/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 io.enmasse diff --git a/keycloak-plugin/pom.xml b/keycloak-plugin/pom.xml index ead60c7a3af..e4d55191eb5 100644 --- a/keycloak-plugin/pom.xml +++ b/keycloak-plugin/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT pom 4.0.0 diff --git a/keycloak-plugin/sasl-plugin/pom.xml b/keycloak-plugin/sasl-plugin/pom.xml index bbcff21b27c..e407518a1e6 100644 --- a/keycloak-plugin/sasl-plugin/pom.xml +++ b/keycloak-plugin/sasl-plugin/pom.xml @@ -4,7 +4,7 @@ io.enmasse keycloak - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 sasl-plugin diff --git a/keycloak-user-api/pom.xml b/keycloak-user-api/pom.xml index 5153b17df80..5ed4e2e07e5 100644 --- a/keycloak-user-api/pom.xml +++ b/keycloak-user-api/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 io.enmasse diff --git a/metrics-api/pom.xml b/metrics-api/pom.xml index c8d093c9e70..2d768054ea7 100644 --- a/metrics-api/pom.xml +++ b/metrics-api/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 io.enmasse diff --git a/mqtt-gateway/pom.xml b/mqtt-gateway/pom.xml index 39da5bff799..ecfb7096853 100644 --- a/mqtt-gateway/pom.xml +++ b/mqtt-gateway/pom.xml @@ -3,7 +3,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 mqtt-gateway diff --git a/mqtt-lwt/pom.xml b/mqtt-lwt/pom.xml index 6ceb7a686f3..c4fabeb00cd 100644 --- a/mqtt-lwt/pom.xml +++ b/mqtt-lwt/pom.xml @@ -3,7 +3,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 mqtt-lwt diff --git a/none-authservice/pom.xml b/none-authservice/pom.xml index cbafa230893..0df401f5f4b 100644 --- a/none-authservice/pom.xml +++ b/none-authservice/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 none-authservice diff --git a/olm-manifest/pom.xml b/olm-manifest/pom.xml index 22f4957660f..7886a189c6b 100644 --- a/olm-manifest/pom.xml +++ b/olm-manifest/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 olm-manifest diff --git a/pom.properties b/pom.properties index 0bea9593109..124a37e5129 100644 --- a/pom.properties +++ b/pom.properties @@ -22,6 +22,6 @@ olm.csv.logo.base64=PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3 olm.csv.logo.mediatype=image/svg+xml license.advice.text=EnMasse comprises the following components: olm.version=999.999.999 -release.version=0.32-SNAPSHOT -maven.version=0.32-SNAPSHOT +release.version=1.0-SNAPSHOT +maven.version=1.0-SNAPSHOT application.docs=https://enmasse.io/documentation/ diff --git a/pom.xml b/pom.xml index 9f45a7ceac0..83ccb472f77 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.enmasse enmasse pom - 0.32-SNAPSHOT + 1.0-SNAPSHOT EnMasse http://enmasse.io/ diff --git a/service-broker/pom.xml b/service-broker/pom.xml index 7590ba1c0cd..e7b2fecce41 100644 --- a/service-broker/pom.xml +++ b/service-broker/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 service-broker diff --git a/standard-controller/pom.xml b/standard-controller/pom.xml index 0dc4593c8bd..8e02bc43f52 100644 --- a/standard-controller/pom.xml +++ b/standard-controller/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 standard-controller diff --git a/systemtests/pom.xml b/systemtests/pom.xml index 8d30417eeb4..080f5952f34 100644 --- a/systemtests/pom.xml +++ b/systemtests/pom.xml @@ -5,7 +5,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 systemtests diff --git a/templates/pom.xml b/templates/pom.xml index 9c95c9e20a9..8527d254f78 100644 --- a/templates/pom.xml +++ b/templates/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT pom 4.0.0 diff --git a/topic-forwarder/pom.xml b/topic-forwarder/pom.xml index 14437a57157..1e11e4a68aa 100644 --- a/topic-forwarder/pom.xml +++ b/topic-forwarder/pom.xml @@ -4,7 +4,7 @@ io.enmasse enmasse - 0.32-SNAPSHOT + 1.0-SNAPSHOT 4.0.0 topic-forwarder From 69949457e1f6d181e27fbfd6cfe0e0f9b713c370 Mon Sep 17 00:00:00 2001 From: David Kornel Date: Fri, 26 Jun 2020 11:14:15 +0200 Subject: [PATCH 03/18] Upgrade surefire plugin and remove workarounds (#4787) * Upgrade surefire plugin and remove workarounds --- pom.xml | 17 +-- systemtests/pom.xml | 6 +- systemtests/scripts/build_pr_response.sh | 2 +- .../systemtest/bases/JUnitWorkaround.java | 120 ------------------ .../io/enmasse/systemtest/iot/IoTTests.java | 6 +- .../listener/JunitCallbackListener.java | 86 ++++++------- .../operator/OLMOperatorManager.java | 29 +++-- .../apps/SystemtestsKubernetesApps.java | 4 +- .../systemtest/bases/olm/OLMTestBase.java | 77 +++++------ .../systemtest/iot/CredentialsTest.java | 2 +- .../iot/DeviceCertificateManagerTest.java | 2 +- .../systemtest/iot/IoTTestSessionTest.java | 2 +- .../systemtest/iot/KeyStoreCreatorTest.java | 2 +- .../iot/isolated/project/ManagedTest.java | 2 +- .../shared/control/CommandAndControlTest.java | 2 +- .../systemtest/isolated/CommonTest.java | 2 - .../infra/standard/InfraTestStandard.java | 4 +- .../isolated/monitoring/MonitoringTest.java | 33 ++--- .../enmasse/systemtest/olm/OLMLinksTest.java | 4 +- .../scale/ScaleTestManagerTest.java | 3 +- 20 files changed, 119 insertions(+), 286 deletions(-) delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/JUnitWorkaround.java diff --git a/pom.xml b/pom.xml index 83ccb472f77..262d764751d 100644 --- a/pom.xml +++ b/pom.xml @@ -63,10 +63,9 @@ 2.21.0 25.0-jre 2.2 - 5.5.2 - 1.5.2 - 1.5.2 - 2.1.3 + 5.6.2 + 1.6.2 + 1.6.2 2.13.0 1.2.1 4.1.48.Final @@ -103,7 +102,7 @@ 3.8.0 3.1.1 3.1.0 - 3.0.0-M4 + 3.0.0-M5 3.5.1 2.9 3.3.0 @@ -640,12 +639,6 @@ ${junit.platform.launcher.version} - - io.github.artsok - rerunner-jupiter - ${rerunner-jupiter.version} - - org.mockito mockito-core @@ -909,6 +902,8 @@ maven-surefire-plugin true + 10 + true value true diff --git a/systemtests/pom.xml b/systemtests/pom.xml index 080f5952f34..b81c867b30b 100644 --- a/systemtests/pom.xml +++ b/systemtests/pom.xml @@ -103,11 +103,6 @@ junit-jupiter-params test - - io.github.artsok - rerunner-jupiter - test - org.seleniumhq.selenium selenium-java @@ -160,6 +155,7 @@ ${groups} ${excludeGroups} ${skip.tests} + 0 ${release.version} ${application.docs} diff --git a/systemtests/scripts/build_pr_response.sh b/systemtests/scripts/build_pr_response.sh index 4180f103f5c..4ad1fc519e4 100755 --- a/systemtests/scripts/build_pr_response.sh +++ b/systemtests/scripts/build_pr_response.sh @@ -39,7 +39,7 @@ fi SUMMARY="**TEST_PROFILE**: ${TEST_PROFILE}\n**TEST_CASE:** ${TEST_CASE}\n**TOTAL:** ${TEST_COUNT}\n**PASS:** $((TEST_COUNT - TEST_ALL_FAILED_COUNT - TEST_SKIPPED_COUNT))\n**FAIL:** ${TEST_ALL_FAILED_COUNT}\n**SKIP:** ${TEST_SKIPPED_COUNT}\n**BUILD_NUMBER:** ${BUILD_ID}\n**BUILD_ENV:** ${BUILD_ENV}\n" -FAILED_TESTS=$(find "${RESULTS_PATH}" -name 'TEST*.xml' -type f -print0 | xargs -0 sed -n "s#\(\)#\1#p" | awk -F '"' '{print "\\n- " $2 " in " $4}') +FAILED_TESTS=$(find "${RESULTS_PATH}" -name 'TEST*.xml' -type f -print0 | xargs -0 awk '//{ getline x; if (x ~ " - * TODO: Remove it after upgrade to surefire plugin 3.0.0-M5. - *

- * To use this you need to: - *

    - *
  • Add {@link JUnitWorkaround} as a JUnit extension. - *
- */ -public class JUnitWorkaround implements BeforeEachCallback, AfterAllCallback, LifecycleMethodExecutionExceptionHandler { - - private static final Logger logger = LoggerFactory.getLogger(JUnitWorkaround.class); - - private List exceptions; - - @Override - public void handleBeforeAllMethodExecutionException(final ExtensionContext context, final Throwable throwable) throws Throwable { - logger.info("Exception caught - recording"); - addBeforeAllException(throwable); - } - - /** - * Record an exception from a {@code @BeforeAll} method. - * - * @param e The exception to store. - */ - private void addBeforeAllException(final Throwable e) { - if (this.exceptions == null) { - this.exceptions = new LinkedList<>(); - } - this.exceptions.add(e); - } - - /** - * Fetch all stored exceptions. - * - * @return All exception that had been recorded. May be {@code null}. - */ - private List getBeforeAllExceptions() { - return this.exceptions; - } - - /** - * Clear all stored exceptions. - */ - private void clearBeforeAllExceptions() { - this.exceptions = null; - } - - /** - * Check if we have recorded "before all" exceptions. - *

- * As we use {@link #beforeEach(ExtensionContext)} this means that all tests covered by the wrapping - * {@link BeforeAll} call will fail. Which is reasonable as they did not get set up properly. - * - * @throws Throwable if there was any recorded exception. - */ - @Override - public void beforeEach(final ExtensionContext context) throws Exception { - - // check if we have recorded exceptions ... - - final List exceptions = getBeforeAllExceptions(); - if (exceptions == null || exceptions.isEmpty()) { - // ... all good - logger.info("No recorded @BeforeAll errors"); - return; - } - - logger.warn("There are @BeforeAll errors - count = {}", exceptions.size()); - - // build up exception - - Throwable first = null; - for (Throwable e : exceptions) { - if (first == null) { - first = e; - } else { - first.addSuppressed(e); - } - } - - // throw it - - if (first instanceof Exception) { - // normal exception - throw (Exception) first; - } else { - // assert*() calls throw AssertionError's - throw new Exception(first); - } - } - - @Override - public void afterAll(ExtensionContext context) throws Exception { - // we get called when we are closing up the BeforeAll calls - // now we can clear the collected exceptions and start fresh - clearBeforeAllExceptions(); - } - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java index 6fdd1e6485a..4d38a3dc98b 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java @@ -15,7 +15,6 @@ import io.enmasse.systemtest.IndicativeSentences; import io.enmasse.systemtest.bases.ITestSeparator; -import io.enmasse.systemtest.bases.JUnitWorkaround; import io.enmasse.systemtest.listener.JunitCallbackListener; import io.enmasse.systemtest.platform.Kubernetes; @@ -23,18 +22,17 @@ * Marker interface for IoT tests, which provision their own IoT infrastructure. */ @ExtendWith(JunitCallbackListener.class) -@ExtendWith(JUnitWorkaround.class) @DisplayNameGeneration(IndicativeSentences.class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) public interface IoTTests extends ITestSeparator { @BeforeAll - public static void deployDefaultCerts() throws Exception { + static void deployDefaultCerts() throws Exception { IoTTestSession.deployDefaultCerts(); } @BeforeAll - public static void createDeviceManager() throws Exception { + static void createDeviceManager() throws Exception { DeviceManagementApi.createManagementServiceAccount(); } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java b/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java index 84a5ae10175..6caf6b945c7 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java @@ -45,7 +45,6 @@ public class JunitCallbackListener implements TestExecutionExceptionHandler, Lif private final SharedIoTManager sharedIoTManager = SharedIoTManager.getInstance(); private final IsolatedIoTManager isolatedIoTManager = IsolatedIoTManager.getInstance(); private final EnmasseOperatorManager operatorManager = EnmasseOperatorManager.getInstance(); - private static Exception beforeAllException; //TODO remove it after upgrade to surefire plugin 3.0.0-M5 @Override public void beforeAll(ExtensionContext context) throws Exception { @@ -54,57 +53,51 @@ public void beforeAll(ExtensionContext context) throws Exception { testInfo.setCurrentTestClass(context); ResourceManager.getInstance().setClassResources(); KubeClusterManager.getInstance().setClassConfigurations(); - try { //TODO remove it after upgrade to surefire plugin 3.0.0-M5 - handleCallBackError("Callback before all", context, () -> { - if (testInfo.isUpgradeTest()) { - if (operatorManager.isEnmasseBundleDeployed()) { - operatorManager.deleteEnmasseBundle(); - } - LOGGER.info("Enmasse is not installed because next test is {}", context.getDisplayName()); - } else if (testInfo.isOLMTest()) { - LOGGER.info("Test is OLM"); - if (operatorManager.isEnmasseOlmDeployed()) { - operatorManager.deleteEnmasseOlm(); - } - if (operatorManager.isEnmasseBundleDeployed()) { - operatorManager.deleteEnmasseBundle(); - } - operatorManager.installEnmasseOlm(testInfo.getOLMInstallationType()); - } else if (env.installType() == EnmasseInstallType.OLM) { - if (!operatorManager.isEnmasseOlmDeployed()) { - operatorManager.installEnmasseOlm(); - } - if (!operatorManager.areExamplesApplied()) { - operatorManager.installExamplesBundleOlm(); - operatorManager.waitUntilOperatorReadyOlm(); - } - } else if (testInfo.isTestSharedInfra()) { - if (operatorManager.isEnmasseBundleDeployed()) { - operatorManager.deleteEnmasseBundle(); - } else if (operatorManager.isEnmasseOlmDeployed()) { - operatorManager.deleteEnmasseOlm(); - } - operatorManager.installEnmasseSharedInfraBundle(); - } else { - if (!operatorManager.isEnmasseBundleDeployed()) { - operatorManager.installEnmasseBundle(); - } - if (testInfo.isClassIoT()) { - operatorManager.installIoTOperator(); - } + handleCallBackError("Callback before all", context, () -> { + if (testInfo.isUpgradeTest()) { + if (operatorManager.isEnmasseBundleDeployed()) { + operatorManager.deleteEnmasseBundle(); } - }); - } catch (Exception ex) { - beforeAllException = ex; //TODO remove it after upgrade to surefire plugin 3.0.0-M5 - operatorManager.deleteEnmasseOlm(); - } + LOGGER.info("Enmasse is not installed because next test is {}", context.getDisplayName()); + } else if (testInfo.isOLMTest()) { + LOGGER.info("Test is OLM"); + if (operatorManager.isEnmasseOlmDeployed()) { + operatorManager.deleteEnmasseOlm(); + } + if (operatorManager.isEnmasseBundleDeployed()) { + operatorManager.deleteEnmasseBundle(); + } + operatorManager.installEnmasseOlm(testInfo.getOLMInstallationType()); + } else if (env.installType() == EnmasseInstallType.OLM) { + if (!operatorManager.isEnmasseOlmDeployed()) { + operatorManager.installEnmasseOlm(); + } + if (!operatorManager.areExamplesApplied()) { + operatorManager.installExamplesBundleOlm(); + operatorManager.waitUntilOperatorReadyOlm(); + } + } else if (testInfo.isTestSharedInfra()) { + if (operatorManager.isEnmasseBundleDeployed()) { + operatorManager.deleteEnmasseBundle(); + } else if (operatorManager.isEnmasseOlmDeployed()) { + operatorManager.deleteEnmasseOlm(); + } + operatorManager.installEnmasseSharedInfraBundle(); + } else { + if (!operatorManager.isEnmasseBundleDeployed()) { + operatorManager.installEnmasseBundle(); + } + if (testInfo.isClassIoT()) { + operatorManager.installIoTOperator(); + } + } + }); } @Override public void afterAll(ExtensionContext extensionContext) throws Exception { LOGGER.info("running - afterAll"); - beforeAllException = null; //TODO remove it after upgrade to surefire plugin 3.0.0-M5 handleCallBackError("Callback after all", extensionContext, () -> { if (!env.skipCleanup()) { ResourceManager.getInstance().deleteClassResources(); @@ -134,9 +127,6 @@ public void beforeEach(ExtensionContext context) throws Exception { ResourceManager.getInstance().setMethodResources(); KubeClusterManager.getInstance().setMethodConfigurations(); logPodsInInfraNamespace(); - if (beforeAllException != null) { - throw beforeAllException; - } } @Override diff --git a/systemtests/src/main/java/io/enmasse/systemtest/operator/OLMOperatorManager.java b/systemtests/src/main/java/io/enmasse/systemtest/operator/OLMOperatorManager.java index 7c50c2b39b8..e30fccffbd4 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/operator/OLMOperatorManager.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/operator/OLMOperatorManager.java @@ -11,6 +11,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; + import org.slf4j.Logger; import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; @@ -73,7 +74,7 @@ public void install(OLMInstallationType installation, String manifestsImage, Str if (installation == OLMInstallationType.SPECIFIC) { Path operatorGroupFile = Files.createTempFile("operatorgroup", ".yaml"); - String operatorGroup = Files.readString(Paths.get("custom-operator-registry", "operator-group.yaml")); + String operatorGroup = Files.readString(Paths.get(System.getProperty("user.dir"), "custom-operator-registry", "operator-group.yaml")); Files.writeString(operatorGroupFile, operatorGroup.replaceAll("\\$\\{OPERATOR_NAMESPACE}", namespace)); KubeCMDClient.applyFromFile(namespace, operatorGroupFile); } @@ -91,31 +92,31 @@ public void clean() throws Exception { public void applySubscription(String installationNamespace, String catalogSourceName, String catalogNamespace, String csvName, String operatorName, String operatorChannel) throws IOException { Path subscriptionFile = Files.createTempFile("subscription", ".yaml"); - String subscription = Files.readString(Paths.get("custom-operator-registry", "subscription.yaml")); + String subscription = Files.readString(Paths.get(System.getProperty("user.dir"), "custom-operator-registry", "subscription.yaml")); Files.writeString(subscriptionFile, subscription - .replaceAll("\\$\\{OPERATOR_NAME}", operatorName) - .replaceAll("\\$\\{OPERATOR_CHANNEL}", operatorChannel) - .replaceAll("\\$\\{OPERATOR_NAMESPACE}", installationNamespace) - .replaceAll("\\$\\{CATALOG_SOURCE_NAME}", catalogSourceName) - .replaceAll("\\$\\{CATALOG_NAMESPACE}", catalogNamespace) - .replaceAll("\\$\\{CSV}", csvName)); + .replaceAll("\\$\\{OPERATOR_NAME}", operatorName) + .replaceAll("\\$\\{OPERATOR_CHANNEL}", operatorChannel) + .replaceAll("\\$\\{OPERATOR_NAMESPACE}", installationNamespace) + .replaceAll("\\$\\{CATALOG_SOURCE_NAME}", catalogSourceName) + .replaceAll("\\$\\{CATALOG_NAMESPACE}", catalogNamespace) + .replaceAll("\\$\\{CSV}", csvName)); KubeCMDClient.applyFromFile(installationNamespace, subscriptionFile); } public void deployCatalogSource(String catalogSourceName, String catalogNamespace, String customRegistryImageToUse) throws IOException { Path catalogSourceFile = Files.createTempFile("catalogsource", ".yaml"); - String catalogSource = Files.readString(Paths.get("custom-operator-registry", "catalog-source.yaml")); + String catalogSource = Files.readString(Paths.get(System.getProperty("user.dir"), "custom-operator-registry", "catalog-source.yaml")); Files.writeString(catalogSourceFile, catalogSource - .replaceAll("\\$\\{CATALOG_SOURCE_NAME}", catalogSourceName) - .replaceAll("\\$\\{OPERATOR_NAMESPACE}", catalogNamespace) - .replaceAll("\\$\\{REGISTRY_IMAGE}", customRegistryImageToUse)); + .replaceAll("\\$\\{CATALOG_SOURCE_NAME}", catalogSourceName) + .replaceAll("\\$\\{OPERATOR_NAMESPACE}", catalogNamespace) + .replaceAll("\\$\\{REGISTRY_IMAGE}", customRegistryImageToUse)); KubeCMDClient.applyFromFile(catalogNamespace, catalogSourceFile); } public void buildPushCustomOperatorRegistry(String namespace, String manifestsImage) throws Exception { - String customRegistryImageToPush = clusterExternalImageRegistry+"/"+namespace+"/systemtests-operator-registry:latest"; + String customRegistryImageToPush = clusterExternalImageRegistry + "/" + namespace + "/systemtests-operator-registry:latest"; String olmManifestsImage = manifestsImage.replace(clusterInternalImageRegistry, clusterExternalImageRegistry); @@ -154,7 +155,7 @@ private boolean saysDoingNothing(String text) { } public String getCustomOperatorRegistryInternalImage(String namespace) { - return clusterInternalImageRegistry+"/"+namespace+"/systemtests-operator-registry:latest"; + return clusterInternalImageRegistry + "/" + namespace + "/systemtests-operator-registry:latest"; } public String getLatestStartingCsv() throws Exception { diff --git a/systemtests/src/main/java/io/enmasse/systemtest/platform/apps/SystemtestsKubernetesApps.java b/systemtests/src/main/java/io/enmasse/systemtest/platform/apps/SystemtestsKubernetesApps.java index 12bca650709..3c41c2a4fc9 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/platform/apps/SystemtestsKubernetesApps.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/platform/apps/SystemtestsKubernetesApps.java @@ -928,11 +928,11 @@ public static void buildOperatorRegistryImage(Kubernetes kubeClient, String olmM } catch (Exception ex) { return false; } - }, new TimeoutBudget(15, TimeUnit.SECONDS)); + }, new TimeoutBudget(60, TimeUnit.SECONDS)); kubeClient.waitPodUntilCondition(pod, p -> { String reason = containerReasonGetter.apply(p); return reason.equals("Completed") || reason.equals("Error"); - }, 3, TimeUnit.MINUTES); + }, 5, TimeUnit.MINUTES); Pod podRes = kubeClient.getPod(CONTAINER_BUILDS_PROJECT, pod.getMetadata().getName()); String reason = containerReasonGetter.apply(podRes); if (reason.equals("Error")) { diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/olm/OLMTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/olm/OLMTestBase.java index 2300d84d90d..d77f1ae052a 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/olm/OLMTestBase.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/bases/olm/OLMTestBase.java @@ -31,7 +31,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtensionContext; import org.slf4j.Logger; @@ -51,7 +50,6 @@ public abstract class OLMTestBase extends TestBase implements ITestIsolatedStandard { private static Logger log = CustomLogger.getLogger(); - private Exception ex = null; //TODO remove it after upgrade to surefire plugin 3.0.0-M5 private static final int CR_TIMEOUT_MILLIS = 30000; private List exampleResources = new ArrayList<>(); @@ -62,46 +60,36 @@ public abstract class OLMTestBase extends TestBase implements ITestIsolatedStand @BeforeAll void setupExampleResources() throws Exception { - try { //TODO remove it after upgrade to surefire plugin 3.0.0-M5 - ExecutionResultData result = KubeCMDClient.runOnCluster("get", "csv", "-n", getInstallationNamespace(), "-o", "json", "-l", "app=enmasse"); - JsonObject csvList = new JsonObject(result.getStdOut()); - JsonObject csv = csvList.getJsonArray("items").getJsonObject(0); - String almExamples = csv.getJsonObject("metadata").getJsonObject("annotations").getString("alm-examples"); - JsonArray examples = new JsonArray(almExamples); - exampleResources = examples.stream().map(o -> (JsonObject) o).collect(Collectors.toList()); + ExecutionResultData result = KubeCMDClient.runOnCluster("get", "csv", "-n", getInstallationNamespace(), "-o", "json", "-l", "app=enmasse"); + JsonObject csvList = new JsonObject(result.getStdOut()); + JsonObject csv = csvList.getJsonArray("items").getJsonObject(0); + String almExamples = csv.getJsonObject("metadata").getJsonObject("annotations").getString("alm-examples"); + JsonArray examples = new JsonArray(almExamples); + exampleResources = examples.stream().map(o -> (JsonObject) o).collect(Collectors.toList()); - Set infraKinds = Set.of("StandardInfraConfig", "BrokeredInfraConfig", "AddressPlan", "AddressSpacePlan", "AuthenticationService"); + Set infraKinds = Set.of("StandardInfraConfig", "BrokeredInfraConfig", "AddressPlan", "AddressSpacePlan", "AuthenticationService"); - for (JsonObject example : exampleResources) { - LOGGER.info("Example: {}", example); - String kind = example.getString("kind"); - if (kind.equals("AuthenticationService") && kubernetes.getCluster() instanceof CRCCluster) { - log.info("Creating standard-authservice with no persistence because of CRC cluster"); - AuthenticationService authService = AuthServiceUtils.createStandardAuthServiceObject("standard-authservice", false); - authService.getMetadata().setNamespace(getInstallationNamespace()); - kubernetes.getAuthenticationServiceClient(getInstallationNamespace()).create(authService); - } else if (infraKinds.contains(kind)) { - log.info("Creating {}", example.toString()); - createCR(getInstallationNamespace(), example); - } + for (JsonObject example : exampleResources) { + LOGGER.info("Example: {}", example); + String kind = example.getString("kind"); + if (kind.equals("AuthenticationService") && kubernetes.getCluster() instanceof CRCCluster) { + log.info("Creating standard-authservice with no persistence because of CRC cluster"); + AuthenticationService authService = AuthServiceUtils.createStandardAuthServiceObject("standard-authservice", false); + authService.getMetadata().setNamespace(getInstallationNamespace()); + kubernetes.getAuthenticationServiceClient(getInstallationNamespace()).create(authService); + } else if (infraKinds.contains(kind)) { + log.info("Creating {}", example.toString()); + createCR(getInstallationNamespace(), example); } - TestUtils.waitUntilDeployed(getInstallationNamespace()); - TestUtils.waitForPodReady("standard-authservice", getInstallationNamespace()); - TestUtils.waitForSchemaInSync("standard-small"); - var addressSpacePlanClient = kubernetes.getAddressSpacePlanClient(getInstallationNamespace()); - TestUtils.waitUntilCondition("AddressSpacePlan standard-small visible", - phase -> addressSpacePlanClient.withName("standard-small").get() != null, - new TimeoutBudget(2, TimeUnit.MINUTES)); - } catch (Exception exception){ //TODO remove it after upgrade to surefire plugin 3.0.0-M5 - ex = exception; } - } + TestUtils.waitUntilDeployed(getInstallationNamespace()); + TestUtils.waitForPodReady("standard-authservice", getInstallationNamespace()); + TestUtils.waitForSchemaInSync("standard-small"); + var addressSpacePlanClient = kubernetes.getAddressSpacePlanClient(getInstallationNamespace()); + TestUtils.waitUntilCondition("AddressSpacePlan standard-small visible", + phase -> addressSpacePlanClient.withName("standard-small").get() != null, + new TimeoutBudget(2, TimeUnit.MINUTES)); - @BeforeEach - void removeMe() throws Exception { //TODO remove it after upgrade to surefire plugin 3.0.0-M5 - if (ex != null) { - throw ex; - } } @AfterEach @@ -122,7 +110,6 @@ void deleteAddressSpace(ExtensionContext context) throws Exception { @AfterAll void teardownExampleResources() throws Exception { - ex = null; //TODO remove it after upgrade to surefire plugin 3.0.0-M5 if (!environment.skipCleanup()) { for (JsonObject example : exampleResources) { log.info("Deleting {}", example.toString()); @@ -143,20 +130,20 @@ protected void doTestExampleResourcesDifferentNamespaceThanOperator() throws Exc private void createdUserResources(String addressSpaceNamespace) throws Exception { JsonObject exampleAddressSpace = exampleResources.stream() - .filter(example -> example.getString("kind").equals("AddressSpace")) - .findFirst() - .orElseThrow(()-> new IllegalStateException("Example resources don't contain an address space")); + .filter(example -> example.getString("kind").equals("AddressSpace")) + .findFirst() + .orElseThrow(() -> new IllegalStateException("Example resources don't contain an address space")); log.info("Creating {}", exampleAddressSpace.getString("kind")); createCR(addressSpaceNamespace, exampleAddressSpace); var client = kubernetes.getAddressSpaceClient(addressSpaceNamespace); TestUtils.waitUntilCondition("Address space visible", - phase -> client.withName("myspace").get() != null,new TimeoutBudget(30, TimeUnit.SECONDS)); + phase -> client.withName("myspace").get() != null, new TimeoutBudget(30, TimeUnit.SECONDS)); resourcesManager.waitForAddressSpaceReady(client.withName("myspace").get()); - for(JsonObject example : exampleResources) { + for (JsonObject example : exampleResources) { String kind = example.getString("kind"); - if(kind.equals("Address") || kind.equals("MessagingUser")) { + if (kind.equals("Address") || kind.equals("MessagingUser")) { log.info("Creating {}", kind); createCR(addressSpaceNamespace, example); } @@ -191,7 +178,7 @@ private void createdUserResources(String addressSpaceNamespace) throws Exception private void createCR(String namespace, JsonObject cr) throws IOException { ExecutionResultData res = KubeCMDClient.createCR(namespace, cr.toString(), CR_TIMEOUT_MILLIS); - if(!res.getRetCode()) { + if (!res.getRetCode()) { Assertions.fail(res.getStdErr()); } } diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/CredentialsTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/CredentialsTest.java index c2303c03139..c64c24b3348 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/CredentialsTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/iot/CredentialsTest.java @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; @Tag(TestTag.FRAMEWORK) public class CredentialsTest { diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceCertificateManagerTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceCertificateManagerTest.java index f0376781fef..8c52eb2f6b1 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceCertificateManagerTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceCertificateManagerTest.java @@ -6,7 +6,7 @@ package io.enmasse.systemtest.iot; import static io.enmasse.systemtest.TestTag.FRAMEWORK; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.security.cert.X509Certificate; import java.time.Duration; diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/IoTTestSessionTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/IoTTestSessionTest.java index a3346e7db16..f5b600013c1 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/IoTTestSessionTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/iot/IoTTestSessionTest.java @@ -7,7 +7,7 @@ import static io.enmasse.systemtest.TestTag.FRAMEWORK; import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/KeyStoreCreatorTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/KeyStoreCreatorTest.java index 7cefd2e5f7c..60aae1db950 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/KeyStoreCreatorTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/iot/KeyStoreCreatorTest.java @@ -5,7 +5,7 @@ package io.enmasse.systemtest.iot; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.time.Duration; import java.time.Instant; diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/project/ManagedTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/project/ManagedTest.java index 5893410b771..eade350eb0e 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/project/ManagedTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/project/ManagedTest.java @@ -10,7 +10,7 @@ import static java.time.Duration.ofMinutes; import static java.time.Duration.ofSeconds; import static org.hamcrest.collection.IsEmptyIterable.emptyIterable; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.net.HttpURLConnection; import java.util.LinkedList; diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/shared/control/CommandAndControlTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/shared/control/CommandAndControlTest.java index a727845e731..8a16e5bd431 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/shared/control/CommandAndControlTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/iot/shared/control/CommandAndControlTest.java @@ -15,7 +15,7 @@ import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.hamcrest.core.IsNull.notNullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.net.HttpURLConnection; import java.nio.ByteBuffer; diff --git a/systemtests/src/test/java/io/enmasse/systemtest/isolated/CommonTest.java b/systemtests/src/test/java/io/enmasse/systemtest/isolated/CommonTest.java index 3fc69c6e27f..30a07badaf9 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/isolated/CommonTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/isolated/CommonTest.java @@ -45,7 +45,6 @@ import io.enmasse.systemtest.utils.PlanUtils; import io.enmasse.systemtest.utils.TestUtils; import io.fabric8.kubernetes.api.model.Pod; -import io.github.artsok.RepeatedIfExceptionsTest; import org.apache.qpid.proton.amqp.Binary; import org.apache.qpid.proton.amqp.messaging.AmqpValue; import org.apache.qpid.proton.amqp.messaging.Data; @@ -606,7 +605,6 @@ private AddressSpace getAddressSpaceBrokerOperableOnFullQueue(AddressPlan exampl @Tag(NON_PR) @DisplayName("testFullBrokerRemainsOperableBrokered") - @RepeatedIfExceptionsTest(repeats = 2, name = "") public void testFullBrokerRemainsOperableBrokered() throws Exception { BrokeredInfraConfig testInfra = new BrokeredInfraConfigBuilder() .withNewMetadata() diff --git a/systemtests/src/test/java/io/enmasse/systemtest/isolated/infra/standard/InfraTestStandard.java b/systemtests/src/test/java/io/enmasse/systemtest/isolated/infra/standard/InfraTestStandard.java index 1856bd27b2d..e4185786c5a 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/isolated/infra/standard/InfraTestStandard.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/isolated/infra/standard/InfraTestStandard.java @@ -56,8 +56,8 @@ import java.util.stream.Collectors; import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; class InfraTestStandard extends InfraTestBase implements ITestIsolatedStandard { diff --git a/systemtests/src/test/java/io/enmasse/systemtest/isolated/monitoring/MonitoringTest.java b/systemtests/src/test/java/io/enmasse/systemtest/isolated/monitoring/MonitoringTest.java index cb556591d31..c10a24283e8 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/isolated/monitoring/MonitoringTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/isolated/monitoring/MonitoringTest.java @@ -26,7 +26,9 @@ import io.enmasse.systemtest.operator.EnmasseOperatorManager; import io.enmasse.systemtest.platform.Kubernetes; import io.enmasse.systemtest.utils.AddressUtils; + import static io.enmasse.systemtest.condition.OpenShiftVersion.OCP4; + import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -44,37 +46,24 @@ @Tag(ACCEPTANCE) class MonitoringTest extends TestBase implements ITestIsolatedStandard { String testNamespace = "monitoring-test"; - private static Exception beforeAllException; //TODO remove it after upgrade to surefire plugin 3.0.0-M5 private MonitoringClient monitoring; @BeforeAll - void installMonitoring() { - try { //TODO remove it after upgrade to surefire plugin 3.0.0-M5 - EnmasseOperatorManager.getInstance().enableMonitoring(); - Endpoint metricsEndpoint; - if (Kubernetes.isOpenShiftCompatible(OCP4) && !Kubernetes.isCRC()) { - metricsEndpoint = Kubernetes.getInstance().getExternalEndpoint("thanos-querier", "openshift-monitoring"); - } else { - metricsEndpoint = Kubernetes.getInstance().getExternalEndpoint("prometheus-route", environment.getMonitoringNamespace()); - } - monitoring = new MonitoringClient(metricsEndpoint); - kubernetes.createNamespace(testNamespace); - } catch (Exception e) { - beforeAllException = e; - } - } - - @BeforeEach - void catchBeforeAllException() throws Exception { - if (beforeAllException != null) { - throw beforeAllException; + void installMonitoring() throws Exception { + EnmasseOperatorManager.getInstance().enableMonitoring(); + Endpoint metricsEndpoint; + if (Kubernetes.isOpenShiftCompatible(OCP4) && !Kubernetes.isCRC()) { + metricsEndpoint = Kubernetes.getInstance().getExternalEndpoint("thanos-querier", "openshift-monitoring"); + } else { + metricsEndpoint = Kubernetes.getInstance().getExternalEndpoint("prometheus-route", environment.getMonitoringNamespace()); } + monitoring = new MonitoringClient(metricsEndpoint); + kubernetes.createNamespace(testNamespace); } @AfterAll void uninstallMonitoring() throws Exception { - beforeAllException = null; //TODO remove it after upgrade to surefire plugin 3.0.0-M5 EnmasseOperatorManager.getInstance().removeIoT(); if (!Kubernetes.isOpenShiftCompatible(OCP4) || Kubernetes.isCRC()) { EnmasseOperatorManager.getInstance().deleteMonitoringOperator(); diff --git a/systemtests/src/test/java/io/enmasse/systemtest/olm/OLMLinksTest.java b/systemtests/src/test/java/io/enmasse/systemtest/olm/OLMLinksTest.java index a3e739cf434..60571faf505 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/olm/OLMLinksTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/olm/OLMLinksTest.java @@ -7,8 +7,8 @@ import static io.enmasse.systemtest.TestTag.ACCEPTANCE; import static io.enmasse.systemtest.TestTag.NON_PR; import static io.enmasse.systemtest.TestTag.OLM; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Duration; import java.util.List; diff --git a/systemtests/src/test/java/io/enmasse/systemtest/scale/ScaleTestManagerTest.java b/systemtests/src/test/java/io/enmasse/systemtest/scale/ScaleTestManagerTest.java index 7d82304fc96..2136d79c62e 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/scale/ScaleTestManagerTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/scale/ScaleTestManagerTest.java @@ -5,7 +5,7 @@ package io.enmasse.systemtest.scale; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.ArrayList; import java.util.Collections; @@ -13,7 +13,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.IntStream; -import org.HdrHistogram.DoubleHistogram; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; From d1ea283b8f9e4d3a216191cd6ea044060da10690 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 26 Jun 2020 11:46:19 +0200 Subject: [PATCH 04/18] Iot cert auth shared infra (#4790) * Add global internal listener for infra that accepts TLS client cert auth * Example on how to reconcile certificate and what information to use for iot adapters * Improve names --- pkg/controller/iotconfig/auth.go | 31 +++++++++ .../iotconfig/iotconfig_controller.go | 26 ++++++-- .../messaginginfra/router/controller.go | 65 +++++++++++++++---- .../messaginginfra/router/router_config.go | 13 ++++ 4 files changed, 117 insertions(+), 18 deletions(-) diff --git a/pkg/controller/iotconfig/auth.go b/pkg/controller/iotconfig/auth.go index 4fbee3fccf7..1892d890924 100644 --- a/pkg/controller/iotconfig/auth.go +++ b/pkg/controller/iotconfig/auth.go @@ -7,7 +7,11 @@ package iotconfig import ( "context" + "fmt" + iotv1alpha1 "github.com/enmasseproject/enmasse/pkg/apis/iot/v1alpha1" + "github.com/enmasseproject/enmasse/pkg/controller/messaginginfra" + "github.com/enmasseproject/enmasse/pkg/controller/messaginginfra/cert" "github.com/enmasseproject/enmasse/pkg/util" "github.com/enmasseproject/enmasse/pkg/util/cchange" "github.com/enmasseproject/enmasse/pkg/util/recon" @@ -80,6 +84,33 @@ func (r *ReconcileIoTConfig) processAdapterPskCredentials(ctx context.Context, c } +func (r *ReconcileIoTConfig) processAdapterInfraCert(ctx context.Context, config *iotv1alpha1.IoTConfig, configTracker *configTracker) (reconcile.Result, error) { + + rc := &recon.ReconcileContext{} + + // for all adapters + + infra, err := messaginginfra.LookupInfra(ctx, r.client, config.Namespace) + if err != nil { + return reconcile.Result{}, err + } + + // TODO: Set desired DNS names + _, err = r.certController.ReconcileCert(ctx, nil, infra, config, "iot-adapters") + if err != nil { + return reconcile.Result{}, err + } + + // TODO: Inject the following into adapter deployments + certSecretName := cert.GetCertSecretName(config.Name) + host := fmt.Sprintf("%s-cluster", infra.Name) + port := 55667 + log.Info("Reconcile adapter cert", "secret", certSecretName, "host", host, "port", port) + + return rc.Result() + +} + func (r *ReconcileIoTConfig) processAuthServicePskSecret(ctx context.Context, config *iotv1alpha1.IoTConfig, authServiceConfigCtx *cchange.ConfigChangeRecorder) error { return r.processSecret(ctx, nameAuthServicePskSecret, config, false, func(config *iotv1alpha1.IoTConfig, secret *corev1.Secret) error { diff --git a/pkg/controller/iotconfig/iotconfig_controller.go b/pkg/controller/iotconfig/iotconfig_controller.go index 601b254c6c9..be0c043c4b0 100644 --- a/pkg/controller/iotconfig/iotconfig_controller.go +++ b/pkg/controller/iotconfig/iotconfig_controller.go @@ -7,15 +7,19 @@ package iotconfig import ( "context" + "time" + + "github.com/enmasseproject/enmasse/pkg/controller/messaginginfra/cert" "github.com/enmasseproject/enmasse/pkg/util/iot" "github.com/enmasseproject/enmasse/pkg/util/loghandler" "github.com/pkg/errors" promv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1" - "k8s.io/client-go/tools/record" "reflect" + "k8s.io/client-go/tools/record" + "github.com/enmasseproject/enmasse/pkg/util/cchange" "github.com/enmasseproject/enmasse/pkg/util/install" @@ -30,7 +34,7 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" iotv1alpha1 "github.com/enmasseproject/enmasse/pkg/apis/iot/v1alpha1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -75,12 +79,14 @@ func Add(mgr manager.Manager) error { } func newReconciler(mgr manager.Manager, infraNamespace string, configName string) *ReconcileIoTConfig { + certController := cert.NewCertController(mgr.GetClient(), mgr.GetScheme(), 24*30*time.Hour, 24*time.Hour) return &ReconcileIoTConfig{ - client: mgr.GetClient(), - scheme: mgr.GetScheme(), - namespace: infraNamespace, - configName: configName, - recorder: mgr.GetEventRecorderFor(ControllerName), + client: mgr.GetClient(), + scheme: mgr.GetScheme(), + namespace: infraNamespace, + configName: configName, + recorder: mgr.GetEventRecorderFor(ControllerName), + certController: certController, } } @@ -154,6 +160,9 @@ type ReconcileIoTConfig struct { scheme *runtime.Scheme recorder record.EventRecorder + // Manages certificates for messaging infrastructure. + certController *cert.CertController + // The name of the configuration we are watching // we are watching only one config, in our own namespace configName string @@ -256,6 +265,9 @@ func (r *ReconcileIoTConfig) Reconcile(request reconcile.Request) (reconcile.Res rc.Process(func() (reconcile.Result, error) { return r.processAdapterPskCredentials(ctx, config, configTracker) }) + rc.Process(func() (reconcile.Result, error) { + return r.processAdapterInfraCert(ctx, config, configTracker) + }) // start normal reconcile diff --git a/pkg/controller/messaginginfra/router/controller.go b/pkg/controller/messaginginfra/router/controller.go index 52c5a860107..ab4589fd7e9 100644 --- a/pkg/controller/messaginginfra/router/controller.go +++ b/pkg/controller/messaginginfra/router/controller.go @@ -123,6 +123,8 @@ func (r *RouterController) ReconcileRouters(ctx context.Context, logger logr.Log certShaSum = certSha.Sum(certShaSum) routerCertSha := hex.EncodeToString(certShaSum[:]) + meshServiceName := fmt.Sprintf("%s", routerInfraName) + // Reconcile statefulset of the router statefulset := &appsv1.StatefulSet{ ObjectMeta: metav1.ObjectMeta{Namespace: infra.Namespace, Name: routerInfraName}, @@ -158,13 +160,21 @@ func (r *RouterController) ReconcileRouters(ctx context.Context, logger logr.Log install.ApplyEnvSimple(container, "QDROUTERD_CONF", "/etc/qpid-dispatch/config/qdrouterd.json") install.ApplyEnvSimple(container, "QDROUTERD_CONF_TYPE", "json") install.ApplyEnvSimple(container, "QDROUTERD_AUTO_MESH_DISCOVERY", "INFER") - install.ApplyEnvSimple(container, "QDROUTERD_AUTO_MESH_SERVICE_NAME", routerInfraName) + install.ApplyEnvSimple(container, "QDROUTERD_AUTO_MESH_SERVICE_NAME", meshServiceName) container.Ports = []corev1.ContainerPort{ { ContainerPort: 55672, Name: "inter-router", }, + { + ContainerPort: 55671, + Name: "operator", + }, + { + ContainerPort: 55667, + Name: "cluster", + }, { ContainerPort: 7777, Name: "management", @@ -214,7 +224,7 @@ func (r *RouterController) ReconcileRouters(ctx context.Context, logger logr.Log return err } statefulset.Spec.Template.Spec.Containers = containers - statefulset.Spec.ServiceName = routerInfraName + statefulset.Spec.ServiceName = meshServiceName install.ApplyConfigMapVolume(&statefulset.Spec.Template.Spec, "config", routerInfraName) install.ApplySecretVolume(&statefulset.Spec.Template.Spec, "certs", certSecretName) @@ -227,17 +237,17 @@ func (r *RouterController) ReconcileRouters(ctx context.Context, logger logr.Log } // Reconcile router service - service := &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{Namespace: infra.Namespace, Name: routerInfraName}, + meshService := &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{Namespace: infra.Namespace, Name: meshServiceName}, } - _, err = controllerutil.CreateOrUpdate(ctx, r.client, service, func() error { - if err := controllerutil.SetControllerReference(infra, service, r.scheme); err != nil { + _, err = controllerutil.CreateOrUpdate(ctx, r.client, meshService, func() error { + if err := controllerutil.SetControllerReference(infra, meshService, r.scheme); err != nil { return err } - install.ApplyServiceDefaults(service, "router", infra.Name) - service.Spec.ClusterIP = "None" - service.Spec.Selector = statefulset.Spec.Template.Labels - service.Spec.Ports = []corev1.ServicePort{ + install.ApplyServiceDefaults(meshService, "router", infra.Name) + meshService.Spec.ClusterIP = "None" + meshService.Spec.Selector = statefulset.Spec.Template.Labels + meshService.Spec.Ports = []corev1.ServicePort{ { Port: 55672, Protocol: corev1.ProtocolTCP, @@ -252,8 +262,41 @@ func (r *RouterController) ReconcileRouters(ctx context.Context, logger logr.Log return nil, err } + // Reconcile internal cluster router service + internalClusterServiceName := fmt.Sprintf("%s-cluster", routerInfraName) + internalClusterService := &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{Namespace: infra.Namespace, Name: internalClusterServiceName}, + } + _, err = controllerutil.CreateOrUpdate(ctx, r.client, internalClusterService, func() error { + if err := controllerutil.SetControllerReference(infra, internalClusterService, r.scheme); err != nil { + return err + } + install.ApplyServiceDefaults(internalClusterService, "router", infra.Name) + internalClusterService.Spec.Type = corev1.ServiceTypeClusterIP + internalClusterService.Spec.Selector = statefulset.Spec.Template.Labels + internalClusterService.Spec.Ports = []corev1.ServicePort{ + { + Port: 55667, + Protocol: corev1.ProtocolTCP, + TargetPort: intstr.FromString("cluster"), + Name: "cluster", + }, + } + + return nil + }) + if err != nil { + return nil, err + } + // Reconcile router certificate - _, err = r.certController.ReconcileCert(ctx, logger, infra, statefulset, fmt.Sprintf("%s", service.Name), fmt.Sprintf("%s.%s.svc", service.Name, service.Namespace), fmt.Sprintf("*.%s.%s.svc", service.Name, service.Namespace)) + _, err = r.certController.ReconcileCert(ctx, logger, infra, statefulset, + fmt.Sprintf("%s", meshService.Name), + fmt.Sprintf("%s.%s.svc", meshService.Name, meshService.Namespace), + fmt.Sprintf("*.%s.%s.svc", meshService.Name, meshService.Namespace), + fmt.Sprintf("%s", internalClusterService.Name), + fmt.Sprintf("%s.%s.svc", internalClusterService.Name, internalClusterService.Namespace), + fmt.Sprintf("*.%s.%s.svc", internalClusterService.Name, internalClusterService.Namespace)) if err != nil { return nil, err } diff --git a/pkg/controller/messaginginfra/router/router_config.go b/pkg/controller/messaginginfra/router/router_config.go index f84498ae4e5..fa825872e36 100644 --- a/pkg/controller/messaginginfra/router/router_config.go +++ b/pkg/controller/messaginginfra/router/router_config.go @@ -92,6 +92,19 @@ func generateConfig(router *v1beta2.MessagingInfrastructureSpecRouter) routerCon "httpRootDir": "invalid", }, }, + []interface{}{ + // Listener for cluster-internal components + "listener", + map[string]interface{}{ + "name": "cluster-internal", + "host": "0.0.0.0", + "port": 55667, + "requireSsl": true, + "saslMechanisms": "EXTERNAL", + "sslProfile": "infra_tls", + "authenticatePeer": true, + }, + }, }, } } From 280e3575f0157a5deb8382cce4f0c1cef7ff88aa Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Sat, 27 Jun 2020 23:13:44 +0200 Subject: [PATCH 05/18] Publish docs to tag --- .github/scripts/publish_docs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/publish_docs.sh b/.github/scripts/publish_docs.sh index 56bf7ffaa81..2a41de4298c 100755 --- a/.github/scripts/publish_docs.sh +++ b/.github/scripts/publish_docs.sh @@ -3,7 +3,7 @@ set -e DOCVERSION=master if [ "${RELEASE}" == "true" ]; then - DOCVERSION=${VERSION} + DOCVERSION=${TAG} fi echo "Publishing docs for version ${DOCVERSION}" From e84922b30538165d880fe9619e45a031902ffd3d Mon Sep 17 00:00:00 2001 From: Dejan Bosanac Date: Mon, 29 Jun 2020 11:06:17 +0200 Subject: [PATCH 06/18] Upgrade to Hono 1.3.0-M3 (#4419) --- .../autowire/AutowiredCredentialsAdapter.java | 36 ------ ...AutowiredCredentialsManagementAdapter.java | 37 ------ .../AutowiredDeviceManagementAdapter.java | 36 ------ .../AutowiredRegistrationAdapter.java | 37 ------ .../AbstractDeviceConnectionService.java | 7 +- .../KubernetesTenantInformationService.java | 1 - ...tractCredentialsManagementServiceTest.java | 96 -------------- iot/iot-device-registry-infinispan/pom.xml | 7 - .../iot/registry/infinispan/Application.java | 5 +- .../config/AmqpEndpointConfiguration.java | 13 ++ .../DeviceConnectionServiceConfiguration.java | 35 +++-- .../config/DeviceServiceConfiguration.java | 121 ++++++++++++++---- .../config/RestEndpointConfiguration.java | 12 ++ .../config/TenantServiceConfiguration.java | 46 ------- .../CredentialsManagementServiceImpl.java | 5 +- iot/iot-device-registry-jdbc/pom.xml | 7 - .../iot/registry/jdbc/Application.java | 3 +- .../config/AmqpEndpointConfiguration.java | 16 +++ .../DeviceConnectionServiceConfiguration.java | 27 ++-- .../config/DeviceServiceConfiguration.java | 119 +++++++++++++---- .../config/RestEndpointConfiguration.java | 15 +++ .../config/TenantServiceConfiguration.java | 46 ------- .../AutowiredDeviceConnectionAdapter.java | 35 ----- .../impl/DeviceConnectionServiceImpl.java | 9 +- .../CredentialsManagementServiceImpl.java | 4 +- .../io/enmasse/iot/tenant/Application.java | 2 +- .../config/AmqpEndpointConfiguration.java | 6 + .../tenant/config/ServiceConfiguration.java | 16 +++ .../iot/tenant/impl/TenantAmqpService.java | 2 - .../iot/tenant/impl/TenantServiceImpl.java | 4 - iot/pom.xml | 2 +- pom.xml | 14 ++ systemtests/pom.xml | 4 + .../iot/CredentialsRegistryClient.java | 12 +- .../systemtest/iot/IoTTestSession.java | 2 +- .../isolated/registry/DeviceRegistryTest.java | 6 +- 36 files changed, 351 insertions(+), 494 deletions(-) delete mode 100644 iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredCredentialsAdapter.java delete mode 100644 iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredCredentialsManagementAdapter.java delete mode 100644 iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredDeviceManagementAdapter.java delete mode 100644 iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredRegistrationAdapter.java delete mode 100644 iot/iot-device-registry-base/src/test/java/io/enmasse/iot/registry/device/AbstractCredentialsManagementServiceTest.java delete mode 100644 iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/TenantServiceConfiguration.java delete mode 100644 iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/TenantServiceConfiguration.java delete mode 100644 iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/devcon/impl/AutowiredDeviceConnectionAdapter.java diff --git a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredCredentialsAdapter.java b/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredCredentialsAdapter.java deleted file mode 100644 index 66f65e979af..00000000000 --- a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredCredentialsAdapter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.iot.registry.autowire; - -import org.eclipse.hono.service.credentials.CredentialsService; -import org.eclipse.hono.service.credentials.EventBusCredentialsAdapter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.stereotype.Component; - -/** - * A default event bus based service implementation of the {@link CredentialsService}. - *

- * This wires up the actual service instance with the mapping to the event bus implementation. It is intended to be used - * in a Spring Boot environment. - */ -@Component -@ConditionalOnBean(CredentialsService.class) -public final class AutowiredCredentialsAdapter extends EventBusCredentialsAdapter { - - private CredentialsService service; - - @Autowired - public void setService(final CredentialsService service) { - this.service = service; - } - - @Override - protected CredentialsService getService() { - return this.service; - } - -} diff --git a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredCredentialsManagementAdapter.java b/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredCredentialsManagementAdapter.java deleted file mode 100644 index dc464b434dc..00000000000 --- a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredCredentialsManagementAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.iot.registry.autowire; - -import org.eclipse.hono.service.management.credentials.CredentialsManagementService; -import org.eclipse.hono.service.management.credentials.EventBusCredentialsManagementAdapter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.stereotype.Component; - -/** - * A default event bus based service implementation of the {@link CredentialsManagementService}. - *

- * This wires up the actual service instance with the mapping to the event bus implementation. It is intended to be used - * in a Spring Boot environment. - */ -@Component -@ConditionalOnBean(CredentialsManagementService.class) -public final class AutowiredCredentialsManagementAdapter extends EventBusCredentialsManagementAdapter { - - private CredentialsManagementService service; - - @Autowired - public void setService(final CredentialsManagementService service) { - this.service = service; - } - - @Override - protected CredentialsManagementService getService() { - return this.service; - } - -} - diff --git a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredDeviceManagementAdapter.java b/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredDeviceManagementAdapter.java deleted file mode 100644 index da37f1c66ca..00000000000 --- a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredDeviceManagementAdapter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.iot.registry.autowire; - -import org.eclipse.hono.service.management.device.DeviceManagementService; -import org.eclipse.hono.service.management.device.EventBusDeviceManagementAdapter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.stereotype.Component; - -/** - * A default event bus based service implementation of the {@link DeviceManagementService}. - *

- * This wires up the actual service instance with the mapping to the event bus implementation. It is intended to be used - * in a Spring Boot environment. - */ -@Component -@ConditionalOnBean(DeviceManagementService.class) -public final class AutowiredDeviceManagementAdapter extends EventBusDeviceManagementAdapter { - - private DeviceManagementService service; - - @Autowired - public void setService(final DeviceManagementService service) { - this.service = service; - } - - @Override - protected DeviceManagementService getService() { - return this.service; - } - -} diff --git a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredRegistrationAdapter.java b/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredRegistrationAdapter.java deleted file mode 100644 index c839954b7f2..00000000000 --- a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/autowire/AutowiredRegistrationAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.iot.registry.autowire; - -import org.eclipse.hono.service.management.device.DeviceManagementService; -import org.eclipse.hono.service.registration.EventBusRegistrationAdapter; -import org.eclipse.hono.service.registration.RegistrationService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.stereotype.Component; - -/** - * A default event bus based service implementation of the {@link DeviceManagementService}. - *

- * This wires up the actual service instance with the mapping to the event bus implementation. It is intended to be used - * in a Spring Boot environment. - */ -@Component -@ConditionalOnBean(RegistrationService.class) -public final class AutowiredRegistrationAdapter extends EventBusRegistrationAdapter { - - private RegistrationService service; - - @Autowired - public void setService(final RegistrationService service) { - this.service = service; - } - - @Override - protected RegistrationService getService() { - return this.service; - } - -} diff --git a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/devcon/AbstractDeviceConnectionService.java b/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/devcon/AbstractDeviceConnectionService.java index 8fd99af22bf..f5352137a95 100644 --- a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/devcon/AbstractDeviceConnectionService.java +++ b/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/devcon/AbstractDeviceConnectionService.java @@ -5,6 +5,7 @@ package io.enmasse.iot.registry.devcon; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -24,7 +25,7 @@ public abstract class AbstractDeviceConnectionService implements DeviceConnectio protected abstract Future processGetLastKnownGatewayForDevice(final DeviceConnectionKey key, final Span span); - protected abstract Future processSetCommandHandlingAdapterInstance(final DeviceConnectionKey key, final String adapterInstanceId, final Span span); + protected abstract Future processSetCommandHandlingAdapterInstance(final DeviceConnectionKey key, final String adapterInstanceId, Duration lifespan, final Span span); protected abstract Future processGetCommandHandlingAdapterInstances(final DeviceConnectionKey key, final List viaGateways, final Span span); @@ -43,8 +44,8 @@ public Future setLastKnownGatewayForDevice(final String } @Override - public Future setCommandHandlingAdapterInstance(String tenantId, String deviceId, String adapterInstanceId, Span span) { - return processSetCommandHandlingAdapterInstance(DeviceConnectionKey.deviceConnectionKey(tenantId, deviceId), adapterInstanceId, span); + public Future setCommandHandlingAdapterInstance(String tenantId, String deviceId, String adapterInstanceId, Duration lifespan, Span span) { + return processSetCommandHandlingAdapterInstance(DeviceConnectionKey.deviceConnectionKey(tenantId, deviceId), adapterInstanceId, lifespan, span); } @Override diff --git a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/tenant/KubernetesTenantInformationService.java b/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/tenant/KubernetesTenantInformationService.java index c7ace5045fb..10250819846 100644 --- a/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/tenant/KubernetesTenantInformationService.java +++ b/iot/iot-device-registry-base/src/main/java/io/enmasse/iot/registry/tenant/KubernetesTenantInformationService.java @@ -30,7 +30,6 @@ import io.opentracing.Span; import io.vertx.core.Future; -@Component public class KubernetesTenantInformationService extends AbstractProjectBasedService implements TenantInformationService { private static final Logger log = LoggerFactory.getLogger(KubernetesTenantInformationService.class); diff --git a/iot/iot-device-registry-base/src/test/java/io/enmasse/iot/registry/device/AbstractCredentialsManagementServiceTest.java b/iot/iot-device-registry-base/src/test/java/io/enmasse/iot/registry/device/AbstractCredentialsManagementServiceTest.java deleted file mode 100644 index 6410838ae97..00000000000 --- a/iot/iot-device-registry-base/src/test/java/io/enmasse/iot/registry/device/AbstractCredentialsManagementServiceTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.iot.registry.device; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.IsNull.notNullValue; - -import java.net.HttpURLConnection; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import org.eclipse.hono.deviceregistry.service.credentials.AbstractCredentialsManagementService; -import org.eclipse.hono.deviceregistry.service.device.DeviceKey; -import org.eclipse.hono.service.management.OperationResult; -import org.eclipse.hono.service.management.credentials.CommonCredential; -import org.eclipse.hono.service.management.credentials.PasswordCredential; -import org.hamcrest.core.Is; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import io.enmasse.iot.registry.tenant.NoopTenantInformationService; -import io.opentracing.Span; -import io.opentracing.noop.NoopSpan; -import io.vertx.core.Future; -import io.vertx.core.Vertx; -import io.vertx.junit5.VertxExtension; -import io.vertx.junit5.VertxTestContext; - -/** - * Tests for {@link AbstractCredentialsManagementService}. - * - */ -@ExtendWith(VertxExtension.class) -public class AbstractCredentialsManagementServiceTest { - - private Vertx vertx; - private AbstractCredentialsManagementService service; - - @BeforeEach - public void setup() { - this.vertx = Vertx.factory.vertx(); - this.service = new AbstractCredentialsManagementService(this.vertx) { - - @Override - protected Future> processUpdateCredentials(DeviceKey key, Optional resourceVersion, List credentials, Span span) { - return Future.succeededFuture(); - } - - @Override - protected Future>> processReadCredentials(DeviceKey key, Span span) { - return Future.succeededFuture(); - } - }; - - this.service.setTenantInformationService(new NoopTenantInformationService()); - } - - @AfterEach - public void cleanup() { - vertx.close(); - } - - /** - * Test if the abstract implementation detects the invalid credential information. - *
- * This test checks if the {@link AbstractCredentialsManagementService} detects, and rejects an - * invalid credential set. For that the actual implementation of the service can simply return - * {@code null}. - * - * @throws Exception if something goes wrong. It should not. - */ - @Test - @Disabled("Update credentials throws exception instead of returning bad request") - public void testValidationFailure(final VertxTestContext ctx) throws Exception { - final PasswordCredential invalidCredentials = new PasswordCredential(); - final List credentials = Collections.singletonList(invalidCredentials); - - final Future> f = this.service.updateCredentials("foo", "bar", credentials, Optional.empty(), NoopSpan.INSTANCE) - .setHandler(ctx.succeeding(r -> { - ctx.verify(() -> { - assertThat(r, notNullValue()); - assertThat(r.isError(), Is.is(true)); - assertThat(r.getStatus(), Is.is(HttpURLConnection.HTTP_BAD_REQUEST)); - } - ); - })); - } - -} diff --git a/iot/iot-device-registry-infinispan/pom.xml b/iot/iot-device-registry-infinispan/pom.xml index 68f76b18750..2ff82f31454 100644 --- a/iot/iot-device-registry-infinispan/pom.xml +++ b/iot/iot-device-registry-infinispan/pom.xml @@ -86,13 +86,6 @@ vertx-junit5 test - - org.eclipse.hono - hono-service-base - tests - test-jar - test - org.infinispan diff --git a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/Application.java b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/Application.java index 80322abd163..539e3b0bedb 100644 --- a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/Application.java +++ b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/Application.java @@ -21,11 +21,8 @@ import io.vertx.core.Verticle; @ComponentScan("org.eclipse.hono.service.auth") -@ComponentScan("org.eclipse.hono.deviceregistry.service.deviceconnection") @ComponentScan("org.eclipse.hono.service.metric") -@ComponentScan("io.enmasse.iot.registry") -@ComponentScan("io.enmasse.iot.service.base") -@ComponentScan("io.enmasse.iot.infinispan") +@ComponentScan("io.enmasse.iot.registry.infinispan.config") @EnableAutoConfiguration public class Application extends AbstractBaseApplication { diff --git a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/AmqpEndpointConfiguration.java b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/AmqpEndpointConfiguration.java index 6c7fb7388ac..442cbe49804 100644 --- a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/AmqpEndpointConfiguration.java +++ b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/AmqpEndpointConfiguration.java @@ -11,7 +11,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; +import io.enmasse.iot.registry.server.DeviceRegistryAmqpServer; import io.enmasse.iot.utils.ConfigBase; @Configuration @@ -29,4 +31,15 @@ public ServiceConfigProperties amqpProperties() { return new ServiceConfigProperties(); } + /** + * Creates a new server for exposing the device registry's AMQP 1.0 based + * endpoints. + * + * @return The server. + */ + @Bean + public DeviceRegistryAmqpServer amqpServer() { + return new DeviceRegistryAmqpServer(); + } + } diff --git a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/DeviceConnectionServiceConfiguration.java b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/DeviceConnectionServiceConfiguration.java index d9d22b16f48..211ff18020c 100644 --- a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/DeviceConnectionServiceConfiguration.java +++ b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/DeviceConnectionServiceConfiguration.java @@ -5,37 +5,50 @@ package io.enmasse.iot.registry.infinispan.config; +import static io.enmasse.iot.registry.infinispan.Profiles.PROFILE_DEVICE_CONNECTION; +import static io.vertx.core.Vertx.vertx; + +import org.eclipse.hono.deviceregistry.service.deviceconnection.MapBasedDeviceConnectionService; import org.eclipse.hono.deviceregistry.service.deviceconnection.MapBasedDeviceConnectionsConfigProperties; -import org.eclipse.hono.service.deviceconnection.DeviceConnectionAmqpEndpoint; +import org.eclipse.hono.service.amqp.AmqpEndpoint; +import org.eclipse.hono.service.deviceconnection.DelegatingDeviceConnectionAmqpEndpoint; import org.eclipse.hono.service.deviceconnection.DeviceConnectionService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; - -import io.vertx.core.Vertx; +import org.springframework.context.annotation.Profile; @Configuration -//@Profile(PROFILE_DEVICE_CONNECTION) -//TODO - enable it again when https://github.com/EnMasseProject/enmasse/issues/4338 is implemented +@Profile(PROFILE_DEVICE_CONNECTION) public class DeviceConnectionServiceConfiguration { /** * Creates a new instance of an AMQP 1.0 protocol handler for Hono's Device Connection API. * + * @param service The service instance to delegate to. * @return The handler. */ - @Autowired @Bean @ConditionalOnBean(DeviceConnectionService.class) - public DeviceConnectionAmqpEndpoint deviceConnectionAmqpEndpoint(final Vertx vertx) { - return new DeviceConnectionAmqpEndpoint(vertx); + public AmqpEndpoint deviceConnectionAmqpEndpoint(final DeviceConnectionService service) { + return new DelegatingDeviceConnectionAmqpEndpoint(vertx(), service); } @Bean - //TODO - remove when https://github.com/EnMasseProject/enmasse/issues/4338 is implemented - public MapBasedDeviceConnectionsConfigProperties deviceConnectionsProperties() { + public MapBasedDeviceConnectionsConfigProperties deviceConnectionProperties() { return new MapBasedDeviceConnectionsConfigProperties(); } + /** + * Creates an instance of the file based service for managing device connection information. + * + * @return The service. + */ + @Bean + public DeviceConnectionService deviceConnectionService() { + final MapBasedDeviceConnectionService service = new MapBasedDeviceConnectionService(); + service.setConfig(deviceConnectionProperties()); + return service; + } + } diff --git a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/DeviceServiceConfiguration.java b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/DeviceServiceConfiguration.java index 35818d7aa47..c94064aa7b3 100644 --- a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/DeviceServiceConfiguration.java +++ b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/DeviceServiceConfiguration.java @@ -5,80 +5,143 @@ package io.enmasse.iot.registry.infinispan.config; +import io.enmasse.iot.infinispan.cache.DeviceManagementCacheProvider; +import io.enmasse.iot.infinispan.config.InfinispanProperties; import static io.enmasse.iot.registry.infinispan.Profiles.PROFILE_DEVICE_REGISTRY; +import io.enmasse.iot.registry.infinispan.device.impl.CredentialsManagementServiceImpl; +import io.enmasse.iot.registry.infinispan.device.impl.CredentialsServiceImpl; +import io.enmasse.iot.registry.infinispan.device.impl.DeviceManagementServiceImpl; +import io.enmasse.iot.registry.infinispan.device.impl.RegistrationServiceImpl; +import io.enmasse.iot.registry.tenant.KubernetesTenantInformationService; +import io.enmasse.iot.registry.util.DeviceRegistryTokenAuthHandler; +import io.enmasse.iot.registry.util.DeviceRegistryTokenAuthProvider; +import io.opentracing.Tracer; +import io.vertx.core.Vertx; +import static io.vertx.core.Vertx.vertx; +import io.vertx.ext.auth.AuthProvider; +import io.vertx.ext.web.handler.AuthHandler; import org.eclipse.hono.auth.HonoPasswordEncoder; import org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder; -import org.eclipse.hono.service.credentials.CredentialsAmqpEndpoint; +import org.eclipse.hono.deviceregistry.service.tenant.TenantInformationService; +import org.eclipse.hono.service.amqp.AmqpEndpoint; import org.eclipse.hono.service.credentials.CredentialsService; -import org.eclipse.hono.service.management.credentials.CredentialsManagementHttpEndpoint; +import org.eclipse.hono.service.credentials.DelegatingCredentialsAmqpEndpoint; +import org.eclipse.hono.service.http.HttpEndpoint; import org.eclipse.hono.service.management.credentials.CredentialsManagementService; -import org.eclipse.hono.service.management.device.DeviceManagementHttpEndpoint; +import org.eclipse.hono.service.management.credentials.DelegatingCredentialsManagementHttpEndpoint; +import org.eclipse.hono.service.management.device.DelegatingDeviceManagementHttpEndpoint; import org.eclipse.hono.service.management.device.DeviceManagementService; -import org.eclipse.hono.service.registration.RegistrationAmqpEndpoint; +import org.eclipse.hono.service.registration.DelegatingRegistrationAmqpEndpoint; import org.eclipse.hono.service.registration.RegistrationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; - -import io.enmasse.iot.registry.util.DeviceRegistryTokenAuthHandler; -import io.enmasse.iot.registry.util.DeviceRegistryTokenAuthProvider; -import io.opentracing.Tracer; -import io.vertx.core.Vertx; -import io.vertx.ext.auth.AuthProvider; -import io.vertx.ext.web.handler.AuthHandler; +import org.springframework.context.annotation.Scope; @Configuration +@Profile({PROFILE_DEVICE_REGISTRY}) public class DeviceServiceConfiguration { + @Bean + public DeviceManagementCacheProvider deviceManagementCacheProvider(final InfinispanProperties infinispanProperties) { + return new DeviceManagementCacheProvider(infinispanProperties); + } + + /** + * Exposes the Infinispan registration service as a Spring bean. + * + * @return The Infinispan registration service. + */ + @Bean + public RegistrationService registrationService(final DeviceManagementCacheProvider cacheProvider) { + return new RegistrationServiceImpl(cacheProvider); + } + + /** + * Exposes the Infinispan credentials service as a Spring bean. + * + * @return The Infinispan credentials service. + */ + @Bean + public CredentialsService credentialsService(final DeviceManagementCacheProvider cacheProvider, final DeviceServiceProperties properties) { + return new CredentialsServiceImpl(cacheProvider, properties); + } + + /** + * Exposes Infinispan device management service as a Spring bean + * + * @param cacheProvider The cache provider. + * @return The Infinispan device management service + */ + @Bean + public DeviceManagementService deviceManagementService(final DeviceManagementCacheProvider cacheProvider) { + return new DeviceManagementServiceImpl(cacheProvider); + } + + /** + * Exposes Infinispan credential management service as a Spring bean + * + * @param cacheProvider The cache provider. + * @return The Infinispan credential management service + */ + @Bean + public CredentialsManagementService credentialsManagementService(final Vertx vertx, HonoPasswordEncoder passwordEncoder, final DeviceManagementCacheProvider cacheProvider) { + return new CredentialsManagementServiceImpl(vertx, passwordEncoder, cacheProvider); + } + /** * Creates a new instance of an AMQP 1.0 protocol handler for Hono's Device Registration API. * + * @param service The service instance to delegate to. * @return The handler. */ - @Autowired @Bean @ConditionalOnBean(RegistrationService.class) - public RegistrationAmqpEndpoint registrationAmqpEndpoint(final Vertx vertx) { - return new RegistrationAmqpEndpoint(vertx); + public AmqpEndpoint registrationAmqpEndpoint(final RegistrationService service) { + return new DelegatingRegistrationAmqpEndpoint(vertx(), service); } /** * Creates a new instance of an AMQP 1.0 protocol handler for Hono's Credentials API. * + * @param service The service instance to delegate to. * @return The handler. */ - @Autowired @Bean @ConditionalOnBean(CredentialsService.class) - public CredentialsAmqpEndpoint credentialsAmqpEndpoint(final Vertx vertx) { - return new CredentialsAmqpEndpoint(vertx); + public AmqpEndpoint credentialsAmqpEndpoint(final CredentialsService service) { + return new DelegatingCredentialsAmqpEndpoint(vertx(), service); } /** - * Creates a new instance of an HTTP protocol handler for Hono's Device Registration API. + * Creates a new instance of an HTTP protocol handler for the devices resources + * of Hono's Device Registry Management API's. * + * @param vertx The vert.x instance to run on. + * @param service The service instance to delegate to. * @return The handler. */ - @Autowired @Bean @ConditionalOnBean(DeviceManagementService.class) - public DeviceManagementHttpEndpoint registrationHttpEndpoint(final Vertx vertx) { - return new DeviceManagementHttpEndpoint(vertx); + public HttpEndpoint deviceHttpEndpoint(final Vertx vertx, final DeviceManagementService service) { + return new DelegatingDeviceManagementHttpEndpoint(vertx, service); } /** - * Creates a new instance of an HTTP protocol handler for Hono's Credentials API. + * Creates a new instance of an HTTP protocol handler for the credentials resources + * of Hono's Device Registry Management API's. * + * @param vertx The vert.x instance to run on. + * @param service The service instance to delegate to. * @return The handler. */ - @Autowired @Bean @ConditionalOnBean(CredentialsManagementService.class) - public CredentialsManagementHttpEndpoint credentialsHttpEndpoint(final Vertx vertx) { - return new CredentialsManagementHttpEndpoint(vertx); + public HttpEndpoint credentialsHttpEndpoint(final Vertx vertx, final CredentialsManagementService service) { + return new DelegatingCredentialsManagementHttpEndpoint(vertx, service); } /** @@ -87,13 +150,11 @@ public CredentialsManagementHttpEndpoint credentialsHttpEndpoint(final Vertx ver * @return The handler. */ @Bean - @Autowired public AuthHandler authHandler(final Tracer tracer, final RestEndpointConfiguration restEndpointConfiguration) { return new DeviceRegistryTokenAuthHandler(tracer, authProvider(tracer, restEndpointConfiguration)); } @Bean - @Autowired public AuthProvider authProvider(final Tracer tracer, final RestEndpointConfiguration restEndpointConfiguration) { return new DeviceRegistryTokenAuthProvider(tracer, restEndpointConfiguration.getAuthTokenCacheExpiration()); } @@ -105,10 +166,14 @@ public AuthProvider authProvider(final Tracer tracer, final RestEndpointConfigur * @return The encoder. */ @Bean - @Autowired @Profile(PROFILE_DEVICE_REGISTRY) public HonoPasswordEncoder passwordEncoder(DeviceServiceProperties deviceServiceProperties) { return new SpringBasedHonoPasswordEncoder(deviceServiceProperties.getMaxBcryptIterations()); } + @Bean + public KubernetesTenantInformationService tenantInformationService() { + return new KubernetesTenantInformationService(); + } + } diff --git a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/RestEndpointConfiguration.java b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/RestEndpointConfiguration.java index 5919a62071a..38877ffe7b6 100644 --- a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/RestEndpointConfiguration.java +++ b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/RestEndpointConfiguration.java @@ -9,6 +9,7 @@ import java.time.temporal.ChronoUnit; import org.eclipse.hono.config.ServiceConfigProperties; +import org.eclipse.hono.deviceregistry.server.DeviceRegistryHttpServer; import org.eclipse.hono.util.Constants; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -47,4 +48,15 @@ public Duration getAuthTokenCacheExpiration() { public void setAuthTokenCacheExpiration(Duration authTokenCacheExpiration) { this.authTokenCacheExpiration = authTokenCacheExpiration; } + + /** + * Creates a new server for exposing the device registry's AMQP 1.0 based + * endpoints. + * + * @return The server. + */ + @Bean + public DeviceRegistryHttpServer httpServer() { + return new DeviceRegistryHttpServer(); + } } diff --git a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/TenantServiceConfiguration.java b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/TenantServiceConfiguration.java deleted file mode 100644 index 27938742e97..00000000000 --- a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/config/TenantServiceConfiguration.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.iot.registry.infinispan.config; - -import org.eclipse.hono.service.management.tenant.TenantManagementHttpEndpoint; -import org.eclipse.hono.service.management.tenant.TenantManagementService; -import org.eclipse.hono.service.tenant.TenantAmqpEndpoint; -import org.eclipse.hono.service.tenant.TenantService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.vertx.core.Vertx; - -@Configuration -public class TenantServiceConfiguration { - - /** - * Creates a new instance of an AMQP 1.0 protocol handler for Hono's Tenant API. - * - * @return The handler. - */ - @Bean - @ConditionalOnBean(TenantService.class) - @Autowired - public TenantAmqpEndpoint tenantAmqpEndpoint(final Vertx vertx) { - return new TenantAmqpEndpoint(vertx); - } - - /** - * Creates a new instance of an HTTP protocol handler for Hono's Tenant API. - * - * @return The handler. - */ - @Bean - @ConditionalOnBean(TenantManagementService.class) - @Autowired - public TenantManagementHttpEndpoint tenantHttpEndpoint(final Vertx vertx) { - return new TenantManagementHttpEndpoint(vertx); - } - -} diff --git a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/device/impl/CredentialsManagementServiceImpl.java b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/device/impl/CredentialsManagementServiceImpl.java index d58ec363f6c..0021b1b94a8 100644 --- a/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/device/impl/CredentialsManagementServiceImpl.java +++ b/iot/iot-device-registry-infinispan/src/main/java/io/enmasse/iot/registry/infinispan/device/impl/CredentialsManagementServiceImpl.java @@ -30,6 +30,7 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; +import org.eclipse.hono.auth.HonoPasswordEncoder; import org.eclipse.hono.client.ServiceInvocationException; import org.eclipse.hono.deviceregistry.service.credentials.AbstractCredentialsManagementService; import org.eclipse.hono.deviceregistry.service.device.DeviceKey; @@ -61,8 +62,8 @@ public class CredentialsManagementServiceImpl extends AbstractCredentialsManagem private final RemoteCache managementCache; @Autowired - public CredentialsManagementServiceImpl(final Vertx vertx, final DeviceManagementCacheProvider cacheProvider) { - super(vertx); + public CredentialsManagementServiceImpl(final Vertx vertx, HonoPasswordEncoder passwordEncoder, final DeviceManagementCacheProvider cacheProvider) { + super(vertx, passwordEncoder); this.managementCache = cacheProvider .getDeviceManagementCache() .orElseThrow(() -> new NoSuchElementException("Missing device management cache")); diff --git a/iot/iot-device-registry-jdbc/pom.xml b/iot/iot-device-registry-jdbc/pom.xml index d5e3e33943a..8842308e2a6 100644 --- a/iot/iot-device-registry-jdbc/pom.xml +++ b/iot/iot-device-registry-jdbc/pom.xml @@ -91,13 +91,6 @@ vertx-junit5 test - - org.eclipse.hono - hono-service-base - tests - test-jar - test - diff --git a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/Application.java b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/Application.java index 14965fcff3d..0d9506abdb7 100644 --- a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/Application.java +++ b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/Application.java @@ -22,8 +22,7 @@ @ComponentScan("org.eclipse.hono.service.auth") @ComponentScan("org.eclipse.hono.service.metric") -@ComponentScan("io.enmasse.iot.registry") -@ComponentScan("io.enmasse.iot.service.base") +@ComponentScan("io.enmasse.iot.registry.jdbc.config") @EnableAutoConfiguration public class Application extends AbstractBaseApplication { diff --git a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/AmqpEndpointConfiguration.java b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/AmqpEndpointConfiguration.java index 2d47c638841..1cd61fcd1e4 100644 --- a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/AmqpEndpointConfiguration.java +++ b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/AmqpEndpointConfiguration.java @@ -11,7 +11,11 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import static io.enmasse.iot.registry.jdbc.Profiles.PROFILE_DEVICE_CONNECTION; +import static io.enmasse.iot.registry.jdbc.Profiles.PROFILE_REGISTRY_ADAPTER; +import io.enmasse.iot.registry.server.DeviceRegistryAmqpServer; import io.enmasse.iot.utils.ConfigBase; @Configuration @@ -29,4 +33,16 @@ public ServiceConfigProperties amqpProperties() { return new ServiceConfigProperties(); } + /** + * Creates a new server for exposing the device registry's AMQP 1.0 based + * endpoints. + * + * @return The server. + */ + @Bean + @Profile({PROFILE_REGISTRY_ADAPTER, PROFILE_DEVICE_CONNECTION}) + public DeviceRegistryAmqpServer amqpServer() { + return new DeviceRegistryAmqpServer(); + } + } diff --git a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/DeviceConnectionServiceConfiguration.java b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/DeviceConnectionServiceConfiguration.java index e93d0b2ef4a..d5d938b0e51 100644 --- a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/DeviceConnectionServiceConfiguration.java +++ b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/DeviceConnectionServiceConfiguration.java @@ -5,33 +5,44 @@ package io.enmasse.iot.registry.jdbc.config; +import io.enmasse.iot.jdbc.store.devcon.Store; import static io.enmasse.iot.registry.jdbc.Profiles.PROFILE_DEVICE_CONNECTION; +import io.enmasse.iot.registry.jdbc.devcon.impl.DeviceConnectionServiceImpl; +import static io.vertx.core.Vertx.vertx; -import org.eclipse.hono.deviceregistry.service.deviceconnection.MapBasedDeviceConnectionsConfigProperties; -import org.eclipse.hono.service.deviceconnection.DeviceConnectionAmqpEndpoint; +import org.eclipse.hono.service.amqp.AmqpEndpoint; +import org.eclipse.hono.service.deviceconnection.DelegatingDeviceConnectionAmqpEndpoint; import org.eclipse.hono.service.deviceconnection.DeviceConnectionService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; -import io.vertx.core.Vertx; - @Configuration @Profile(PROFILE_DEVICE_CONNECTION) public class DeviceConnectionServiceConfiguration { + /** + * Creates and instance of the JDBC device connection service. + * + * @param store The device information store. + * @return The JDBC device connection service. + */ + @Bean + public DeviceConnectionService deviceConnectionService(Store store) { + return new DeviceConnectionServiceImpl(store); + } + /** * Creates a new instance of an AMQP 1.0 protocol handler for Hono's Device Connection API. * + * @param service The service instance to delegate to. * @return The handler. */ - @Autowired @Bean @ConditionalOnBean(DeviceConnectionService.class) - public DeviceConnectionAmqpEndpoint deviceConnectionAmqpEndpoint(final Vertx vertx) { - return new DeviceConnectionAmqpEndpoint(vertx); + public AmqpEndpoint deviceConnectionAmqpEndpoint(final DeviceConnectionService service) { + return new DelegatingDeviceConnectionAmqpEndpoint(vertx(), service); } } diff --git a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/DeviceServiceConfiguration.java b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/DeviceServiceConfiguration.java index 4de3c61acc1..63115153a44 100644 --- a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/DeviceServiceConfiguration.java +++ b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/DeviceServiceConfiguration.java @@ -5,18 +5,34 @@ package io.enmasse.iot.registry.jdbc.config; +import io.enmasse.iot.jdbc.store.device.AbstractDeviceAdapterStore; +import io.enmasse.iot.jdbc.store.device.AbstractDeviceManagementStore; import static io.enmasse.iot.registry.jdbc.Profiles.PROFILE_REGISTRY_ADAPTER; import static io.enmasse.iot.registry.jdbc.Profiles.PROFILE_REGISTRY_MANAGEMENT; +import io.enmasse.iot.registry.jdbc.device.impl.CredentialsManagementServiceImpl; +import io.enmasse.iot.registry.jdbc.device.impl.CredentialsServiceImpl; +import io.enmasse.iot.registry.jdbc.device.impl.DeviceManagementServiceImpl; +import io.enmasse.iot.registry.jdbc.device.impl.RegistrationServiceImpl; +import io.enmasse.iot.registry.tenant.KubernetesTenantInformationService; +import io.enmasse.iot.registry.util.DeviceRegistryTokenAuthHandler; +import io.enmasse.iot.registry.util.DeviceRegistryTokenAuthProvider; +import io.opentracing.Tracer; +import io.vertx.core.Vertx; +import static io.vertx.core.Vertx.vertx; +import io.vertx.ext.auth.AuthProvider; +import io.vertx.ext.web.handler.AuthHandler; import org.eclipse.hono.auth.HonoPasswordEncoder; import org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder; -import org.eclipse.hono.service.credentials.CredentialsAmqpEndpoint; +import org.eclipse.hono.service.amqp.AmqpEndpoint; import org.eclipse.hono.service.credentials.CredentialsService; -import org.eclipse.hono.service.management.credentials.CredentialsManagementHttpEndpoint; +import org.eclipse.hono.service.credentials.DelegatingCredentialsAmqpEndpoint; +import org.eclipse.hono.service.http.HttpEndpoint; import org.eclipse.hono.service.management.credentials.CredentialsManagementService; -import org.eclipse.hono.service.management.device.DeviceManagementHttpEndpoint; +import org.eclipse.hono.service.management.credentials.DelegatingCredentialsManagementHttpEndpoint; +import org.eclipse.hono.service.management.device.DelegatingDeviceManagementHttpEndpoint; import org.eclipse.hono.service.management.device.DeviceManagementService; -import org.eclipse.hono.service.registration.RegistrationAmqpEndpoint; +import org.eclipse.hono.service.registration.DelegatingRegistrationAmqpEndpoint; import org.eclipse.hono.service.registration.RegistrationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -24,63 +40,111 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; -import io.enmasse.iot.registry.util.DeviceRegistryTokenAuthHandler; -import io.enmasse.iot.registry.util.DeviceRegistryTokenAuthProvider; -import io.opentracing.Tracer; -import io.vertx.core.Vertx; -import io.vertx.ext.auth.AuthProvider; -import io.vertx.ext.web.handler.AuthHandler; - @Configuration @Profile({PROFILE_REGISTRY_ADAPTER, PROFILE_REGISTRY_MANAGEMENT}) public class DeviceServiceConfiguration { + /** + * Exposes the JDBC registration service as a Spring bean. + * + * @param store The JDBC store. + * @return The JDBC registration service. + */ + @Bean + @Profile(PROFILE_REGISTRY_ADAPTER) + public RegistrationService registrationService(AbstractDeviceAdapterStore store) { + return new RegistrationServiceImpl(store); + } + + /** + * Exposes the JDBC credentials service as a Spring bean. + * + * @param store The JDBC store. + * @return The JDBC credentials service. + */ + @Bean + @Profile(PROFILE_REGISTRY_ADAPTER) + public CredentialsService credentialsService(AbstractDeviceAdapterStore store) { + return new CredentialsServiceImpl(store); + } + + /** + * Exposes JDBC device management service as a Spring bean + * + * @param store The JDBC store. + * @param properties The service properties. + * @return The JDBC device management service + */ + @Bean + @Profile(PROFILE_REGISTRY_MANAGEMENT) + public DeviceManagementService deviceManagementService(final AbstractDeviceManagementStore store, final DeviceServiceProperties properties) { + return new DeviceManagementServiceImpl(store, properties); + } + + /** + * Exposes JDBC credential management service as a Spring bean + * + * @param vertx The Verx instance. + * @param store The JDBC store + * @param properties The service properties. + * @return The JDBC credential management service + */ + @Bean + @Profile(PROFILE_REGISTRY_MANAGEMENT) + public CredentialsManagementService credentialsManagementService(final Vertx vertx, HonoPasswordEncoder passwordEncoder, final AbstractDeviceManagementStore store, final DeviceServiceProperties properties) { + return new CredentialsManagementServiceImpl(vertx, passwordEncoder, store, properties); + } + /** * Creates a new instance of an AMQP 1.0 protocol handler for Hono's Device Registration API. * + * @param service The service instance to delegate to. * @return The handler. */ - @Autowired @Bean @ConditionalOnBean(RegistrationService.class) - public RegistrationAmqpEndpoint registrationAmqpEndpoint(final Vertx vertx) { - return new RegistrationAmqpEndpoint(vertx); + public AmqpEndpoint registrationAmqpEndpoint(final RegistrationService service) { + return new DelegatingRegistrationAmqpEndpoint(vertx(), service); } /** * Creates a new instance of an AMQP 1.0 protocol handler for Hono's Credentials API. * + * @param service The service instance to delegate to. * @return The handler. */ - @Autowired @Bean @ConditionalOnBean(CredentialsService.class) - public CredentialsAmqpEndpoint credentialsAmqpEndpoint(final Vertx vertx) { - return new CredentialsAmqpEndpoint(vertx); + public AmqpEndpoint credentialsAmqpEndpoint(final CredentialsService service) { + return new DelegatingCredentialsAmqpEndpoint(vertx(), service); } /** - * Creates a new instance of an HTTP protocol handler for Hono's Device Registration API. + * Creates a new instance of an HTTP protocol handler for the devices resources + * of Hono's Device Registry Management API's. * + * @param vertx The vert.x instance to run on. + * @param service The service instance to delegate to. * @return The handler. */ - @Autowired @Bean @ConditionalOnBean(DeviceManagementService.class) - public DeviceManagementHttpEndpoint registrationHttpEndpoint(final Vertx vertx) { - return new DeviceManagementHttpEndpoint(vertx); + public HttpEndpoint deviceHttpEndpoint(final Vertx vertx, final DeviceManagementService service) { + return new DelegatingDeviceManagementHttpEndpoint(vertx, service); } /** - * Creates a new instance of an HTTP protocol handler for Hono's Credentials API. + * Creates a new instance of an HTTP protocol handler for the credentials resources + * of Hono's Device Registry Management API's. * + * @param vertx The vert.x instance to run on. + * @param service The service instance to delegate to. * @return The handler. */ - @Autowired @Bean @ConditionalOnBean(CredentialsManagementService.class) - public CredentialsManagementHttpEndpoint credentialsHttpEndpoint(final Vertx vertx) { - return new CredentialsManagementHttpEndpoint(vertx); + public HttpEndpoint credentialsHttpEndpoint(final Vertx vertx, final CredentialsManagementService service) { + return new DelegatingCredentialsManagementHttpEndpoint(vertx, service); } /** @@ -113,4 +177,9 @@ public HonoPasswordEncoder passwordEncoder(final DeviceServiceProperties deviceS return new SpringBasedHonoPasswordEncoder(deviceServiceProperties.getMaxBcryptIterations()); } + @Bean + public KubernetesTenantInformationService tenantInformationService() { + return new KubernetesTenantInformationService(); + } + } diff --git a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/RestEndpointConfiguration.java b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/RestEndpointConfiguration.java index 517528ce8cd..409fac722e9 100644 --- a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/RestEndpointConfiguration.java +++ b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/RestEndpointConfiguration.java @@ -9,13 +9,16 @@ import java.time.temporal.ChronoUnit; import org.eclipse.hono.config.ServiceConfigProperties; +import org.eclipse.hono.deviceregistry.server.DeviceRegistryHttpServer; import org.eclipse.hono.util.Constants; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.convert.DurationUnit; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import static io.enmasse.iot.registry.jdbc.Profiles.PROFILE_REGISTRY_MANAGEMENT; import io.enmasse.iot.utils.ConfigBase; @Configuration @@ -47,4 +50,16 @@ public Duration getAuthTokenCacheExpiration() { public void setAuthTokenCacheExpiration(Duration authTokenCacheExpiration) { this.authTokenCacheExpiration = authTokenCacheExpiration; } + + /** + * Creates a new server for exposing the device registry's AMQP 1.0 based + * endpoints. + * + * @return The server. + */ + @Bean + @Profile(PROFILE_REGISTRY_MANAGEMENT) + public DeviceRegistryHttpServer httpServer() { + return new DeviceRegistryHttpServer(); + } } diff --git a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/TenantServiceConfiguration.java b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/TenantServiceConfiguration.java deleted file mode 100644 index eea47fbddf2..00000000000 --- a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/config/TenantServiceConfiguration.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.iot.registry.jdbc.config; - -import org.eclipse.hono.service.management.tenant.TenantManagementHttpEndpoint; -import org.eclipse.hono.service.management.tenant.TenantManagementService; -import org.eclipse.hono.service.tenant.TenantAmqpEndpoint; -import org.eclipse.hono.service.tenant.TenantService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.vertx.core.Vertx; - -@Configuration -public class TenantServiceConfiguration { - - /** - * Creates a new instance of an AMQP 1.0 protocol handler for Hono's Tenant API. - * - * @return The handler. - */ - @Autowired - @Bean - @ConditionalOnBean(TenantService.class) - public TenantAmqpEndpoint tenantAmqpEndpoint(final Vertx vertx) { - return new TenantAmqpEndpoint(vertx); - } - - /** - * Creates a new instance of an HTTP protocol handler for Hono's Tenant API. - * - * @return The handler. - */ - @Autowired - @Bean - @ConditionalOnBean(TenantManagementService.class) - public TenantManagementHttpEndpoint tenantHttpEndpoint(final Vertx vertx) { - return new TenantManagementHttpEndpoint(vertx); - } - -} diff --git a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/devcon/impl/AutowiredDeviceConnectionAdapter.java b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/devcon/impl/AutowiredDeviceConnectionAdapter.java deleted file mode 100644 index 713666f631b..00000000000 --- a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/devcon/impl/AutowiredDeviceConnectionAdapter.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.iot.registry.jdbc.devcon.impl; - -import org.eclipse.hono.service.deviceconnection.DeviceConnectionService; -import org.eclipse.hono.service.deviceconnection.EventBusDeviceConnectionAdapter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.stereotype.Component; - -/** - * A default event bus based service implementation of the {@link DeviceConnectionService}. - *

- * This wires up the actual service instance with the mapping to the event bus implementation. It is intended to be used - * in a Spring Boot environment. - */ -@Component -@ConditionalOnBean(DeviceConnectionService.class) -public final class AutowiredDeviceConnectionAdapter extends EventBusDeviceConnectionAdapter { - - private DeviceConnectionService service; - - @Autowired - public void setService(final DeviceConnectionService service) { - this.service = service; - } - - @Override - protected DeviceConnectionService getService() { - return this.service; - } - -} diff --git a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/devcon/impl/DeviceConnectionServiceImpl.java b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/devcon/impl/DeviceConnectionServiceImpl.java index d101a0dac9e..7ad0b22cab3 100644 --- a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/devcon/impl/DeviceConnectionServiceImpl.java +++ b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/devcon/impl/DeviceConnectionServiceImpl.java @@ -8,6 +8,7 @@ import static io.enmasse.iot.registry.jdbc.Profiles.PROFILE_DEVICE_CONNECTION; import java.net.HttpURLConnection; +import java.time.Duration; import java.util.List; import org.eclipse.hono.service.deviceconnection.DeviceConnectionService; @@ -27,14 +28,11 @@ /** * A {@link DeviceConnectionService} that use an JDBC as a backend service. */ -@Component -@Profile(PROFILE_DEVICE_CONNECTION) public class DeviceConnectionServiceImpl extends AbstractDeviceConnectionService { private Store store; - @Autowired - protected DeviceConnectionServiceImpl(final Store store) { + public DeviceConnectionServiceImpl(final Store store) { this.store = store; } @@ -65,7 +63,8 @@ protected Future processSetLastKnownGatewayForDevice(fin } @Override - protected Future processSetCommandHandlingAdapterInstance(DeviceConnectionKey key, String adapterInstanceId, Span span) { + protected Future processSetCommandHandlingAdapterInstance(DeviceConnectionKey key, String adapterInstanceId, Duration lifespan, Span span) { + //TODO handle lifespan return this.store .processSetCommandHandlingAdapterInstance(key, adapterInstanceId, span.context()) .map(r -> DeviceConnectionResult.from(HttpURLConnection.HTTP_NO_CONTENT)); diff --git a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/device/impl/CredentialsManagementServiceImpl.java b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/device/impl/CredentialsManagementServiceImpl.java index 02c02e44568..79b35eb0b84 100644 --- a/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/device/impl/CredentialsManagementServiceImpl.java +++ b/iot/iot-device-registry-jdbc/src/main/java/io/enmasse/iot/registry/jdbc/device/impl/CredentialsManagementServiceImpl.java @@ -39,8 +39,8 @@ public class CredentialsManagementServiceImpl extends AbstractCredentialsManagem private final Optional ttl; @Autowired - public CredentialsManagementServiceImpl(final Vertx vertx, final AbstractDeviceManagementStore store, final DeviceServiceProperties properties) { - super(vertx); + public CredentialsManagementServiceImpl(final Vertx vertx, HonoPasswordEncoder passwordEncoder, final AbstractDeviceManagementStore store, final DeviceServiceProperties properties) { + super(vertx, passwordEncoder); this.store = store; this.ttl = Optional.of(CacheDirective.maxAgeDirective(properties.getCredentialsTtl().toSeconds())); } diff --git a/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/Application.java b/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/Application.java index 5c2cf214ffd..8615a65db6f 100644 --- a/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/Application.java +++ b/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/Application.java @@ -21,7 +21,7 @@ import io.vertx.core.Promise; import io.vertx.core.Verticle; -@ComponentScan("io.enmasse.iot.tenant") +@ComponentScan("io.enmasse.iot.tenant.config") @ComponentScan("org.eclipse.hono.service.metric") @ComponentScan("org.eclipse.hono.deviceregistry.service.tenant") @EnableAutoConfiguration diff --git a/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/config/AmqpEndpointConfiguration.java b/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/config/AmqpEndpointConfiguration.java index d0ec8fed684..0c13cab76b4 100644 --- a/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/config/AmqpEndpointConfiguration.java +++ b/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/config/AmqpEndpointConfiguration.java @@ -12,6 +12,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import io.enmasse.iot.tenant.impl.TenantAmqpService; import io.enmasse.iot.utils.ConfigBase; @Configuration @@ -24,4 +25,9 @@ public ServiceConfigProperties amqpEndpointProperties() { return new ServiceConfigProperties(); } + @Bean + public TenantAmqpService amqpServer() { + return new TenantAmqpService(); + } + } diff --git a/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/config/ServiceConfiguration.java b/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/config/ServiceConfiguration.java index a74117cb316..7b9984c9143 100644 --- a/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/config/ServiceConfiguration.java +++ b/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/config/ServiceConfiguration.java @@ -5,12 +5,17 @@ package io.enmasse.iot.tenant.config; +import org.eclipse.hono.service.amqp.AmqpEndpoint; +import org.eclipse.hono.service.tenant.DelegatingTenantAmqpEndpoint; +import org.eclipse.hono.service.tenant.TenantService; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import io.enmasse.iot.tenant.impl.TenantServiceConfigProperties; +import io.enmasse.iot.tenant.impl.TenantServiceImpl; import io.enmasse.iot.utils.ConfigBase; +import static io.vertx.core.Vertx.vertx; @Configuration public class ServiceConfiguration { @@ -20,4 +25,15 @@ public class ServiceConfiguration { public TenantServiceConfigProperties tenantsProperties() { return new TenantServiceConfigProperties(); } + + @Bean + public AmqpEndpoint tenantAmqpEndpoint(final TenantService service) { + return new DelegatingTenantAmqpEndpoint(vertx(), service); + } + + @Bean + public TenantServiceImpl tenantService() { + return new TenantServiceImpl(); + } + } diff --git a/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/impl/TenantAmqpService.java b/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/impl/TenantAmqpService.java index 85d46621830..803b3775590 100644 --- a/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/impl/TenantAmqpService.java +++ b/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/impl/TenantAmqpService.java @@ -7,9 +7,7 @@ import org.eclipse.hono.config.ServiceConfigProperties; import org.eclipse.hono.service.amqp.AmqpServiceBase; -import org.springframework.stereotype.Component; -@Component public final class TenantAmqpService extends AmqpServiceBase { @Override diff --git a/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/impl/TenantServiceImpl.java b/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/impl/TenantServiceImpl.java index dddabfbbab7..a0925ccebe2 100644 --- a/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/impl/TenantServiceImpl.java +++ b/iot/iot-tenant-service/src/main/java/io/enmasse/iot/tenant/impl/TenantServiceImpl.java @@ -25,8 +25,6 @@ import org.eclipse.hono.util.TenantResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Service; import com.google.common.collect.ImmutableMap; @@ -36,8 +34,6 @@ import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; -@Service -@Qualifier("backend") public class TenantServiceImpl extends AbstractTenantService { private static final Logger logger = LoggerFactory.getLogger(TenantServiceImpl.class); diff --git a/iot/pom.xml b/iot/pom.xml index ae39b1c2259..c0ef122d53c 100644 --- a/iot/pom.xml +++ b/iot/pom.xml @@ -13,7 +13,7 @@ pom - 1.2.3 + 1.3.0-M3 9.4.16.Final 42.2.9 diff --git a/pom.xml b/pom.xml index 262d764751d..e69198d2017 100644 --- a/pom.xml +++ b/pom.xml @@ -144,6 +144,20 @@ templates + + + hono.snapshots + Eclipse Hono Development Snapshot Repository + https://repo.eclipse.org/content/repositories/hono-snapshots/ + + false + + + true + + + + diff --git a/systemtests/pom.xml b/systemtests/pom.xml index b81c867b30b..c1fb0680491 100644 --- a/systemtests/pom.xml +++ b/systemtests/pom.xml @@ -130,6 +130,10 @@ org.eclipse.hono hono-service-base + + org.eclipse.hono + hono-service-device-registry-base + org.hawkular.agent prometheus-scraper diff --git a/systemtests/src/main/java/io/enmasse/systemtest/iot/CredentialsRegistryClient.java b/systemtests/src/main/java/io/enmasse/systemtest/iot/CredentialsRegistryClient.java index b8a4dde9a10..24699e17099 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/iot/CredentialsRegistryClient.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/iot/CredentialsRegistryClient.java @@ -174,8 +174,7 @@ public static PasswordCredential createPlainPasswordCredentialsObject(final Stri // create credentials - var credentials = new PasswordCredential(); - credentials.setAuthId(authId); + var credentials = new PasswordCredential(authId); credentials.setSecrets(Collections.singletonList(secret)); return credentials; @@ -188,8 +187,7 @@ static PasswordCredential createCredentialsObject(final String authId, final Str // create credentials - var credentials = new PasswordCredential(); - credentials.setAuthId(authId); + var credentials = new PasswordCredential(authId); credentials.setSecrets(Collections.singletonList(secret)); return credentials; @@ -202,8 +200,7 @@ static PskCredential createPskCredentialsObject(final String authId, final byte[ // create credentials - var credentials = new PskCredential(); - credentials.setAuthId(authId); + var credentials = new PskCredential(authId); credentials.setSecrets(Collections.singletonList(secret)); return credentials; @@ -216,8 +213,7 @@ static X509CertificateCredential createX509CertificateCredentialsObject(final St // create credentials - var credentials = new X509CertificateCredential(); - credentials.setAuthId(authId); + var credentials = new X509CertificateCredential(authId); credentials.setSecrets(Collections.singletonList(secret)); return credentials; diff --git a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java index 04d746384d8..200f426c325 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java @@ -616,7 +616,7 @@ public void addCleanup(final ThrowingCallable cleanupTask) { if (log.isDebugEnabled()) { log.debug("Caught exception during deployment", e); } else { - log.info("Caught exception during deployment, running exception handler"); + log.info("Caught exception during deployment, running exception handler", e); } // first run exception handler diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/DeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/DeviceRegistryTest.java index 832a121b4fc..fd709d39543 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/DeviceRegistryTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/DeviceRegistryTest.java @@ -107,7 +107,7 @@ protected void doTestRegisterDevice() throws Exception { client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); final Device result = client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); assertNotNull(result); - assertDefaultEnabled(result.getEnabled()); + assertDefaultEnabled(result.isEnabled()); client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); @@ -124,7 +124,7 @@ protected void doTestDisableDevice() throws Exception { final Device result = client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); // as we set it explicitly, we expect the explicit value of "false" - assertEquals(Boolean.FALSE, result.getEnabled()); + assertEquals(Boolean.FALSE, result.isEnabled()); client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); @@ -375,7 +375,7 @@ protected void doRegisterMultipleDevices() throws Exception { for (final String deviceId : devices) { final Device result = client.getDeviceRegistration(tenantId, deviceId); assertNotNull(result); - assertDefaultEnabled(result.getEnabled()); + assertDefaultEnabled(result.isEnabled()); } for (final String deviceId : devices) { From f55c2fa8cde648cbefefe3f6eaeda5640eb0c449 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 29 Jun 2020 12:12:48 +0200 Subject: [PATCH 07/18] Run CI using kind (#4843) --- .github/scripts/build.sh | 16 +++------------- .github/scripts/setup_kind.sh | 26 ++++++++++++++++++++++++++ .github/workflows/master.yml | 4 ++-- .github/workflows/release.yml | 4 ++-- .github/workflows/smoke.yml | 4 ++-- Makefile | 6 +++--- 6 files changed, 38 insertions(+), 22 deletions(-) create mode 100755 .github/scripts/setup_kind.sh diff --git a/.github/scripts/build.sh b/.github/scripts/build.sh index 272a8327c35..b38a576ad9c 100755 --- a/.github/scripts/build.sh +++ b/.github/scripts/build.sh @@ -3,21 +3,11 @@ set -e echo "${VERSION}" -echo "Make" -make - -echo "Build" -make docker_build - if [[ -v PUSH_REGISTRY ]] then echo "Logging in to registry" docker login -u "${REGISTRY_USER}" -p "${REGISTRY_PASS}" "${DOCKER_REGISTRY}" - make TAG="${VERSION}" docker_tag docker_push + make TAG="${VERSION}" buildpush +else + make IMAGE_PULL_POLICY=IfNotPresent buildpushkind fi - -echo "Push to registry" -make -j 4 docker_tag docker_push - -echo "Generate templates" -make templates diff --git a/.github/scripts/setup_kind.sh b/.github/scripts/setup_kind.sh new file mode 100755 index 00000000000..15e8c4ea748 --- /dev/null +++ b/.github/scripts/setup_kind.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.8.1/kind-$(uname)-amd64" +chmod +x ./kind + +cat < Date: Mon, 29 Jun 2020 15:27:53 +0200 Subject: [PATCH 08/18] Adopt the new messaging infrastructure (#4484) * Adopt the new messaging infrastructure * Using `.spec.message` vs `.spec.phaseReason` --- documentation/design/iot/README.adoc | 138 ++++++++++++++++++++++++--- 1 file changed, 124 insertions(+), 14 deletions(-) diff --git a/documentation/design/iot/README.adoc b/documentation/design/iot/README.adoc index f6b496c5650..d9011808387 100644 --- a/documentation/design/iot/README.adoc +++ b/documentation/design/iot/README.adoc @@ -1,18 +1,82 @@ +:icons: font = IoT support +[.lead] This document describes how IoT is added into the EnMasse system. +NOTE: This is the updated version for EnMasse Core v1. + == Overview -EnMasse IoT support is an additional layer on top of the EnMasse system. It supports IoT -specific use cases and protocols, like "telemetry ingestion", "command & control", "MQTT", "HTTP", ... +EnMasse IoT support is an additional layer on top of the +EnMasse system. It supports IoT specific use cases and +protocols, like "telemetry ingestion", "command & control", +"MQTT", "HTTP", … This is implemented based on the Eclipse Hono project. +== IoT Config CRD + +[.lead] +An "IoT Config" is an IoT infrastructure which can serve multiple IoT tenants (IoTProject). + +An IoT Config: + +* Is part of the EnMasse infrastructure namespace. +* Is configured to bind to exactly one _messaging infrastructure_. +* Has the name `default`. +* Can currently only exist once in the cluster. ++ +NOTE: The goal is to lift this limitation in a future version and +allow for multiple IoT infrastructure instances. Each IoT infrastructure +pointing to exactly one messaging infrastructure. +* Serves all IoT projects assigned to the IoT infrastructure. ++ +This is an implicit assignment. An IoT project resides in a Kubernetes +namespace, which is assigned to a messaging tenant, which is assigned +to a messaging infrastructure. + +*Target persona:* IoT service admin + +*Proposal:* Change the name from `IoTConfig` to `IoTInfrastructure` +when we make allow for multiple IoT infrastructures. + +=== Hono services + +Each IoT infrastructure has a set of Hono services (protocol adapters, +device registry, …) which will be shared between all IoT projects, +assigned to this infrastructure. + +=== Protocol adapter addressing + +The protocol adapters will directly connect to the messaging +infrastructure, using an (to be defined) internal +authentication/authorization mechanism. + +For this to work, the protocol adapters must be able to prefix +the address resources with the _vhost_ prefix. The _vhost_ prefix +is the Kubernetes namespace. + +*Example:* Assuming an IoT project `iot1` in the namespace `ns1`. +The operator would request an address `telemetry/ns1.iot1` in the +namespace `ns1`. As the protocol adapters would connect to the +messaging infrastructure, they would prefix the address with the +namespace and would use the address `ns1/telemetry/ns1.iot1` instead. + +IMPORTANT: Currently we are using the QPID dispatch router sidecar to +split the single AMQP connection coming from Hono protocol adapters +into multiple connections for the different address spaces. This +sidecar setup would be removed. + +IMPORTANT: This requires an upstream change in Hono, so that we +have the ability to prefix the addresses in Hono with a custom +(tenant specific) prefix. + == IoT Project CRD -An "IoT project" is a logical entity which scopes a set of devices into a single, IoT specific, namespace. +[.lead] +An "IoT project" is a logical entity, which scopes a set of devices into a single, IoT specific, namespace. An IoT project: @@ -20,19 +84,65 @@ An IoT project: * Has a name which adheres to the requirements of `.metadata.name` * Translates into a Hono tenant name by: `.` * Can be described in a Kubernetes CRD -* Connects to one EnMasse standard address space -* Has its own set of addresses ("telemtry/", "event/", ...) inside that address space +* Connects implicitly to one EnMasse IoT infrastructure (IoTConfig) +* Manages its own set of addresses ("telemetry/", "event/", ...) +* Requires a _messaging tenant_ to be created first + +IMPORTANT: This will remove the three current _downstream strategies_ +and remain with only the _managed_ one. The "external" strategy can +be achieved by using _EnMasse connectors_. + +*Target persona:* IoT tenant + +=== Missing messaging tenant + +*Aspect:* Getting started + +If an IoT project gets created in a namespace which does not have +a _message tenant_ created, then the IoT project will: + +* Get the field `.status.phase` set to `Failed` +* Provide a helpful message in the field `.status.message` +* Get the condition `HasMessagingTenant` set to `false` + +As soon as the messaging tenant gets created, the project will +try to become ready automatically. + +The Web UI should alert the user that it is not possible to create +an IoT project without having a messaging tenant. It _may_ offer to +create a messaging tenant on the fly. + +=== IoT infrastructure assignment === + +As mentioned earlier, each IoT project is implicitly assigned to a +messaging infrastructure. And each IoT infrastructure is assigned +to exactly one messaging infrastructure. + +This may lead to a situation where an IoT projects gets created, +pointing to a messaging infrastructure, which has no IoT infrastructure +assigned. + +In this case the IoT project will: + +* Get the field `.status.phase` set to `Failed` +* Provide a helpful message in the field `.status.message` +* Get the condition `HasMessagingInfrastructure` set to `false` -IoT project know three modes of operation: +The controller will *not* automatically re-try to bring the IoT project +into a ready state. -* **External**: All messaging resources (address space, addresses, users) are provided by the user (external - to the IoT project). The configuration of the IoT project contains all necessary information. -* **Providd**: to be written -* **Managed**: The EnMasse system fully managed the messaging resources. +IMPORTANT: This scenario is more important in the first version, as we +currently only support *one* IoT infrastructure. It still is a valid +scenario once multiple IoT infrastructures are supported. -== Protocol adapters +== Getting started -The Hono protocol adapters are shared, infrastructure components, which will be re-used by all IoT projects. -Therefore the messages of each Hono tenant (EnMasse IoT project) will be proxies using the Qpid dispatcher router, -from the Hono protocol adapters, to the target messaging resources of the IoT project. +The minimum steps to get started are: +* Deploy EnMasse +* Create a messaging infrastructure +* Create an IoT infrastructure + ** Deploy PostgreSQL + ** Create a database schema +* Create a messaging tenant +* Create an IoT project From 1bafdfa5b7334bc5f38887e15b500322d483c6b5 Mon Sep 17 00:00:00 2001 From: David Kornel Date: Mon, 29 Jun 2020 16:11:31 +0200 Subject: [PATCH 09/18] Remove ununsed tests in enmasse 1.0 (#4844) * Remove ununsed tests in enmasse 1.0 --- .github/scripts/olm_test.sh | 4 +- .github/scripts/smoke_test.sh | 2 +- systemtests/pom.xml | 120 +- .../io/enmasse/systemtest/Environment.java | 14 +- .../java/io/enmasse/systemtest/TestTag.java | 3 +- .../enmasse/systemtest/bases/ITestBase.java | 44 - .../systemtest/bases/ITestBaseBrokered.java | 28 - .../systemtest/bases/ITestBaseStandard.java | 32 - .../systemtest/bases/iot/ITestIoTBase.java | 38 - .../bases/iot/ITestIoTIsolated.java | 45 - .../systemtest/bases/iot/ITestIoTShared.java | 60 - .../bases/isolated/ITestBaseIsolated.java | 32 - .../bases/isolated/ITestIsolatedBrokered.java | 28 - .../isolated/ITestIsolatedSharedInfra.java | 25 - .../bases/isolated/ITestIsolatedStandard.java | 26 - .../bases/shared/ITestBaseShared.java | 28 - .../bases/shared/ITestSharedBrokered.java | 26 - .../bases/shared/ITestSharedStandard.java | 28 - .../systemtest/clients/ClientUtils.java | 3 +- .../io/enmasse/systemtest/info/TestInfo.java | 4 - .../systemtest/iot/IoTTestSession.java | 13 +- .../io/enmasse/systemtest/iot/IoTTests.java | 3 +- .../listener/JunitCallbackListener.java | 111 +- .../listener/JunitExecutionListener.java | 11 +- .../manager/IsolatedIoTManager.java | 185 -- .../manager/IsolatedResourcesManager.java | 362 --- .../systemtest/manager/ResourceManager.java | 532 ----- .../systemtest/manager/SharedIoTManager.java | 163 -- .../manager/SharedResourceManager.java | 138 -- .../messaginginfra/ResourceManager.java | 3 - .../operator/EnmasseOperatorManager.java | 48 +- .../systemtest/platform/KubeCMDClient.java | 10 - .../systemtest/resources/CliOutputData.java | 6 +- .../enmasse/systemtest/utils/UserUtils.java | 8 - .../io/enmasse/systemtest/bases/TestBase.java | 351 +-- .../bases/authz/AuthorizationTestBase.java | 521 ----- .../bases/bridging/BridgingBase.java | 226 -- .../bases/clients/ClientTestBase.java | 591 ----- .../bases/clients/ClusterClientTestBase.java | 145 -- .../systemtest/bases/infra/InfraTestBase.java | 209 -- .../bases/mqtt/MqttPublishTestBase.java | 163 -- .../systemtest/bases/olm/OLMTestBase.java | 186 -- .../systemtest/bases/plans/PlansTestBase.java | 257 -- .../systemtest/bases/soak/SoakTestBase.java | 376 --- .../systemtest/bases/web/ConsoleTest.java | 2074 ----------------- .../bases/web/WebSocketBrowserTest.java | 41 - .../CliOutputDataTest.java | 3 +- .../systemtest/iot/CredentialsTest.java | 32 - .../iot/DeviceCertificateManagerTest.java | 52 - .../systemtest/iot/DeviceSupplier.java | 65 - .../systemtest/iot/IoTTestSessionTest.java | 82 - .../systemtest/iot/KeyStoreCreatorTest.java | 51 - .../systemtest/iot/MessageSendTesterTest.java | 62 - .../systemtest/iot/StandardIoTTests.java | 27 - .../iot/http/StandardIoTHttpTests.java | 199 -- .../isolated/AbstractMaxPayloadSizeTest.java | 144 -- .../iot/isolated/IoTProjectManagedTest.java | 421 ---- .../iot/isolated/MultipleProjectsTest.java | 227 -- .../iot/isolated/SimpleK8sDeployTest.java | 162 -- .../iot/isolated/http/HttpAdapterTest.java | 64 - .../iot/isolated/http/MaxPayloadSizeTest.java | 30 - .../iot/isolated/mqtt/MaxPayloadSizeTest.java | 35 - .../iot/isolated/mqtt/MqttAdapterTest.java | 68 - .../iot/isolated/project/ManagedTest.java | 210 -- .../isolated/registry/DeviceRegistryTest.java | 391 ---- .../registry/H2DeviceRegistryTest.java | 148 -- .../InfinispanDeviceRegistryTest.java | 108 - .../registry/MixedDeviceRegistryTest.java | 105 - .../PostgresTableDeviceRegistryTest.java | 95 - .../PostgresTableSplitDeviceRegistryTest.java | 96 - .../isolated/tls/ReloadCertificatesTest.java | 145 -- .../iot/isolated/tls/TlsVersionTest.java | 77 - .../iot/isolated/x509/StandardX509Cases.java | 97 - .../iot/isolated/x509/TrustAnchorTests.java | 114 - .../x509/X509EcAuthenticationTests.java | 67 - .../x509/X509RsaAuthenticationTests.java | 67 - .../iot/mqtt/StandardIoTMqttTests.java | 255 -- .../shared/control/CommandAndControlTest.java | 306 --- .../systemtest/isolated/CommonTest.java | 839 ------- .../systemtest/isolated/Credentials.java | 28 - .../isolated/PersistentMessagesTest.java | 231 -- .../isolated/api/ApiServerTest.java | 592 ----- .../isolated/api/AuthServiceTest.java | 548 ----- ...omResourceDefinitionAddressSpacesTest.java | 423 ---- ...CustomResourceDefinitionAddressesTest.java | 187 -- .../isolated/bridging/ConnectorsTest.java | 306 --- .../isolated/bridging/ForwardersTest.java | 370 --- .../isolated/brokered/SmokeTest.java | 211 -- .../catalog/ServiceCatalogWebTest.java | 366 --- .../isolated/certs/CertProviderTest.java | 215 -- .../infra/brokered/InfraTestBrokered.java | 240 -- .../infra/standard/InfraTestStandard.java | 539 ----- .../isolated/monitoring/MonitoringTest.java | 227 -- .../plans/brokered/PlansTestBrokered.java | 230 -- .../plans/standard/PlansTestStandard.java | 1308 ----------- .../policy/NetworkPolicyTestBrokered.java | 251 -- .../policy/NetworkPolicyTestStandard.java | 275 --- .../isolated/standard/AnycastTest.java | 180 -- .../isolated/standard/SmokeTest.java | 182 -- .../isolated/support/SupportToolingTest.java | 144 -- .../isolated/ttl/MessageTtlTest.java | 382 --- .../isolated/upgrade/UpgradeTest.java | 544 ----- .../isolated/web/ChromeConsoleTest.java | 131 -- .../isolated/web/FirefoxConsoleTest.java | 169 -- .../systemtest/olm/OLMDefaultTest.java | 43 - .../enmasse/systemtest/olm/OLMLinksTest.java | 96 - .../systemtest/olm/OLMSpecificTest.java | 43 - .../enmasse/systemtest/scale/ScaleTest.java | 675 ------ .../scale/ScaleTestManagerTest.java | 162 -- .../systemtest/shared/brokered/QueueTest.java | 345 --- .../systemtest/shared/brokered/TopicTest.java | 454 ---- .../shared/brokered/api/UserApiTest.java | 295 --- .../brokered/authz/AuthorizationTest.java | 37 - .../artemis/MsgPatternsInternalTest.java | 19 - .../clients/artemis/MsgPatternsTest.java | 54 - .../clients/mqtt/MsgPatternsInternalTest.java | 17 - .../openwire/MsgPatternsInternalTest.java | 20 - .../clients/openwire/MsgPatternsTest.java | 54 - .../proton/java/MsgPatternsInternalTest.java | 19 - .../clients/proton/java/MsgPatternsTest.java | 58 - .../python/MsgPatternsInternalTest.java | 19 - .../proton/python/MsgPatternsTest.java | 54 - .../clients/rhea/MsgPatternsInternalTest.java | 27 - .../clients/rhea/MsgPatternsTest.java | 66 - .../clients/stomp/MsgPatternsTest.java | 31 - .../shared/brokered/mqtt/PublishTest.java | 56 - .../brokered/web/ChromeConsoleTest.java | 61 - .../web/ChromeWebSocketBrowserTest.java | 55 - .../brokered/web/FirefoxConsoleTest.java | 196 -- .../web/FirefoxWebSocketBrowserTest.java | 51 - .../shared/standard/MulticastTest.java | 44 - .../systemtest/shared/standard/PlansTest.java | 74 - .../systemtest/shared/standard/QueueTest.java | 543 ----- .../systemtest/shared/standard/TopicTest.java | 713 ------ .../shared/standard/api/UserApiTest.java | 139 -- .../standard/authz/AuthorizationTest.java | 42 - .../proton/java/MsgPatternsInternalTest.java | 19 - .../clients/proton/java/MsgPatternsTest.java | 44 - .../python/MsgPatternsInternalTest.java | 19 - .../proton/python/MsgPatternsTest.java | 40 - .../clients/rhea/MsgPatternsInternalTest.java | 27 - .../clients/rhea/MsgPatternsTest.java | 52 - .../standard/web/ChromeConsoleTest.java | 235 -- .../web/ChromeWebSocketBrowserTest.java | 54 - .../standard/web/FirefoxConsoleTest.java | 360 --- .../web/FirefoxWebSocketBrowserTest.java | 48 - .../systemtest/sharedinfra/DefaultsTest.java | 12 +- .../sharedinfra/MessagingAddressPerfTest.java | 16 +- .../sharedinfra/MessagingAddressTest.java | 40 +- .../sharedinfra/MessagingEndpointTest.java | 39 +- .../MessagingInfrastructureTest.java | 36 +- .../sharedinfra/MessagingTenantTest.java | 14 +- .../systemtest/soak/BrokeredSoakTest.java | 75 - .../systemtest/soak/PlansSoakTest.java | 205 -- .../enmasse/systemtest/soak/RestartTest.java | 126 - .../systemtest/soak/StabilityTest.java | 131 -- .../systemtest/soak/StandardSoakTest.java | 75 - .../enmasse.io_messagingaddresses.yaml | 2 +- .../enmasse.io_messagingendpoints.yaml | 2 +- .../enmasse.io_messaginginfrastructures.yaml | 2 +- .../enmasse.io_messagingtenants.yaml | 2 +- 161 files changed, 150 insertions(+), 26533 deletions(-) delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBase.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseBrokered.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseStandard.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTBase.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTIsolated.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTShared.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestBaseIsolated.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedBrokered.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedSharedInfra.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedStandard.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestBaseShared.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedBrokered.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedStandard.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedIoTManager.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedResourcesManager.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/manager/ResourceManager.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/manager/SharedIoTManager.java delete mode 100644 systemtests/src/main/java/io/enmasse/systemtest/manager/SharedResourceManager.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/bases/authz/AuthorizationTestBase.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/bases/bridging/BridgingBase.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClientTestBase.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClusterClientTestBase.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/bases/infra/InfraTestBase.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/bases/mqtt/MqttPublishTestBase.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/bases/olm/OLMTestBase.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/bases/plans/PlansTestBase.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/bases/soak/SoakTestBase.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/bases/web/ConsoleTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/bases/web/WebSocketBrowserTest.java rename systemtests/src/test/java/io/enmasse/systemtest/{resources => framework}/CliOutputDataTest.java (98%) delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/CredentialsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceCertificateManagerTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceSupplier.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/IoTTestSessionTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/KeyStoreCreatorTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/MessageSendTesterTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/StandardIoTTests.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/http/StandardIoTHttpTests.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/AbstractMaxPayloadSizeTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/IoTProjectManagedTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/MultipleProjectsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/SimpleK8sDeployTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/HttpAdapterTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/MaxPayloadSizeTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MaxPayloadSizeTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MqttAdapterTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/project/ManagedTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/DeviceRegistryTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/H2DeviceRegistryTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/InfinispanDeviceRegistryTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/MixedDeviceRegistryTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableDeviceRegistryTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableSplitDeviceRegistryTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/ReloadCertificatesTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/TlsVersionTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/StandardX509Cases.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/TrustAnchorTests.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509EcAuthenticationTests.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509RsaAuthenticationTests.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/mqtt/StandardIoTMqttTests.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/iot/shared/control/CommandAndControlTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/CommonTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/Credentials.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/PersistentMessagesTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/api/ApiServerTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/api/AuthServiceTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/api/CustomResourceDefinitionAddressSpacesTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/api/CustomResourceDefinitionAddressesTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/bridging/ConnectorsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/bridging/ForwardersTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/brokered/SmokeTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/catalog/ServiceCatalogWebTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/certs/CertProviderTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/infra/brokered/InfraTestBrokered.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/infra/standard/InfraTestStandard.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/monitoring/MonitoringTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/plans/brokered/PlansTestBrokered.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/plans/standard/PlansTestStandard.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/policy/NetworkPolicyTestBrokered.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/policy/NetworkPolicyTestStandard.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/standard/AnycastTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/standard/SmokeTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/support/SupportToolingTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/ttl/MessageTtlTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/upgrade/UpgradeTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/web/ChromeConsoleTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/isolated/web/FirefoxConsoleTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/olm/OLMDefaultTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/olm/OLMLinksTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/olm/OLMSpecificTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/scale/ScaleTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/scale/ScaleTestManagerTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/QueueTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/TopicTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/api/UserApiTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/authz/AuthorizationTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/artemis/MsgPatternsInternalTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/artemis/MsgPatternsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/mqtt/MsgPatternsInternalTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/openwire/MsgPatternsInternalTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/openwire/MsgPatternsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/proton/java/MsgPatternsInternalTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/proton/java/MsgPatternsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/proton/python/MsgPatternsInternalTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/proton/python/MsgPatternsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/rhea/MsgPatternsInternalTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/rhea/MsgPatternsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/clients/stomp/MsgPatternsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/mqtt/PublishTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/web/ChromeConsoleTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/web/ChromeWebSocketBrowserTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/web/FirefoxConsoleTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/brokered/web/FirefoxWebSocketBrowserTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/MulticastTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/PlansTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/QueueTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/TopicTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/api/UserApiTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/authz/AuthorizationTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/clients/proton/java/MsgPatternsInternalTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/clients/proton/java/MsgPatternsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/clients/proton/python/MsgPatternsInternalTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/clients/proton/python/MsgPatternsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/clients/rhea/MsgPatternsInternalTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/clients/rhea/MsgPatternsTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/web/ChromeConsoleTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/web/ChromeWebSocketBrowserTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/web/FirefoxConsoleTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/shared/standard/web/FirefoxWebSocketBrowserTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/soak/BrokeredSoakTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/soak/PlansSoakTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/soak/RestartTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/soak/StabilityTest.java delete mode 100644 systemtests/src/test/java/io/enmasse/systemtest/soak/StandardSoakTest.java diff --git a/.github/scripts/olm_test.sh b/.github/scripts/olm_test.sh index bb1a56adfd9..9a564c1fe3e 100755 --- a/.github/scripts/olm_test.sh +++ b/.github/scripts/olm_test.sh @@ -6,5 +6,5 @@ export TEMPLATES=${PWD}/templates/build/enmasse-${TAG} export OCP4_EXTERNAL_IMAGE_REGISTRY=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' image-registry):5000 -echo "Running OLM tests" -time make TESTCASE=olm.** PROFILE=olm-pr systemtests +echo "OLM TESTS DISABLED" +#time make TESTCASE=olm.** PROFILE=olm-pr systemtests diff --git a/.github/scripts/smoke_test.sh b/.github/scripts/smoke_test.sh index 8a583477fff..13df107f1ca 100755 --- a/.github/scripts/smoke_test.sh +++ b/.github/scripts/smoke_test.sh @@ -5,4 +5,4 @@ TAG=${TAG:-latest} export TEMPLATES=${PWD}/templates/build/enmasse-${TAG} echo "Running smoke tests" -time make PROFILE=smoke systemtests \ No newline at end of file +time make PROFILE=systemtests systemtests \ No newline at end of file diff --git a/systemtests/pom.xml b/systemtests/pom.xml index c1fb0680491..67558af7a15 100644 --- a/systemtests/pom.xml +++ b/systemtests/pom.xml @@ -223,130 +223,14 @@ systemtests false - (shared-standard | shared-brokered | isolated | soak | shared-iot | isolated-iot | isolated-shared-infra) & !upgrade - - - - shared - - false - (shared-standard | shared-brokered) & !isolated & !smoke & !soak - & !shared-iot & !olm & !upgrade & !scale & !framework - - - - - isolated-shared-infra - - (isolated-shared-infra) & !soak & !shared-iot & !olm & !upgrade & !scale - false - - - - isolated - - (isolated | isolated-broker | isolated-standard) & !soak & !shared-iot & !olm & !upgrade & !scale & !framework - false + systemtests & !upgrade pr false - (shared-standard | shared-brokered | isolated) & !nonPR & !smoke & !soak - & !shared-iot & !olm & !upgrade & !scale & !framework - - - - - iot - - (isolated-iot | shared-iot) & !soak & !olm & !upgrade & !scale & !framework - false - - - - shared-iot - - shared-iot & !soak & !olm & !upgrade & !framework - false - - - - isolated-iot - - isolated-iot & !soak & !olm & !upgrade & !framework - false - - - - smoke-iot - - (shared-iot | isolated-iot) & smoke & !soak & !olm & !upgrade & !scale & !framework - false - - - - soak - - soak - false - - - - smoke - - smoke & !shared-iot & !isolated-iot & !soak & !olm & !upgrade & !scale & !framework - false - - - - upgrade - - upgrade & !soak & !olm & !scale & !framework - false - - - - olm - - olm - false - - - - olm-pr - - olm & !nonPR - false - - - - iot-release - - (shared-iot | isolated-iot) & !noneAuth & !smoke & !soak & !olm & !upgrade & !framework - false - - - - acceptance - - acceptance & !soak & !upgrade & !scale & !framework - false - - - - acceptance-no-iot - - acceptance & !soak & !upgrade & !shared-iot & !isolated-iot & !scale & !framework - false - - - - scale - - scale - false + systemtests & !upgrade diff --git a/systemtests/src/main/java/io/enmasse/systemtest/Environment.java b/systemtests/src/main/java/io/enmasse/systemtest/Environment.java index 85e91c87343..3bd188055b3 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/Environment.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/Environment.java @@ -102,10 +102,8 @@ public class Environment { private final String clusterInternalImageRegistry = getOrDefault(jsonEnv, OCP4_INTERNAL_IMAGE_REGISTRY, ""); //Default values - private final UserCredentials managementCredentials = new UserCredentials(null, null); - private final UserCredentials defaultCredentials = new UserCredentials(null, null); - private final UserCredentials sharedManagementCredentials = new UserCredentials("artemis-admin", "artemis-admin"); - private final UserCredentials sharedDefaultCredentials = new UserCredentials("test", "test"); + private final UserCredentials managementCredentials = new UserCredentials("artemis-admin", "artemis-admin"); + private final UserCredentials defaultCredentials = new UserCredentials("test", "test"); //Collectings properties private final String enmasseVersion = System.getProperty(ENMASSE_VERSION_SYSTEM_PROPERTY); @@ -267,14 +265,6 @@ public UserCredentials getDefaultCredentials() { return defaultCredentials; } - public UserCredentials getSharedManagementCredentials() { - return sharedManagementCredentials; - } - - public UserCredentials getSharedDefaultCredentials() { - return sharedDefaultCredentials; - } - public boolean isSkipSaveState() { return this.skipSaveState; } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/TestTag.java b/systemtests/src/main/java/io/enmasse/systemtest/TestTag.java index 84399162589..0f87d09772b 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/TestTag.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/TestTag.java @@ -14,9 +14,9 @@ * This class defines all the tags used in the test suite. */ public class TestTag { + public static final String SYSTEMTEST = "systemtests"; public static final String ISOLATED = "isolated"; public static final String ISOLATED_STANDARD = "isolated-standard"; - public static final String ISOLATED_SHARED_INFRA = "isolated-shared-infra"; public static final String ISOLATED_BROKER = "isolated-broker"; public static final String SHARED_STANDARD = "shared-standard"; public static final String SHARED_BROKERED = "shared-brokered"; @@ -32,5 +32,4 @@ public class TestTag { public static final String FRAMEWORK = "framework"; public static final Set SHARED_TAGS = new HashSet<>(Arrays.asList(SHARED_BROKERED, SHARED_STANDARD, SHARED_IOT)); public static final Set IOT_TAGS = new HashSet<>(Arrays.asList(SHARED_IOT, ISOLATED_IOT)); - public static final Set SHARED_INFRA_TAGS = new HashSet<>(Arrays.asList(ISOLATED_SHARED_INFRA)); } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBase.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBase.java deleted file mode 100644 index a5dad924b3c..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBase.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases; - -import io.enmasse.systemtest.clients.ClientUtils; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.manager.ResourceManager; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.platform.Kubernetes; - -import org.slf4j.Logger; - -public interface ITestBase { - ClientUtils clientUtils = new ClientUtils(); - Logger LOGGER = CustomLogger.getLogger(); - Kubernetes kubernetes = Kubernetes.getInstance(); - default ClientUtils getClientUtils() { - return clientUtils; - } - - default AddressSpaceType getAddressSpaceType() { - return null; - } - - default String getDefaultPlan(AddressType addressType) { - return null; - } - - default String getDefaultAddressSpacePlan() { - return null; - } - - default String getDefaultAddrSpaceIdentifier() { - return "default"; - } - - default ResourceManager getResourceManager() { - return null; - } - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseBrokered.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseBrokered.java deleted file mode 100644 index 3480956cb1f..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseBrokered.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases; - -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; - -public interface ITestBaseBrokered extends ITestBase { - - @Override - default AddressSpaceType getAddressSpaceType() { - return AddressSpaceType.BROKERED; - } - - @Override - default String getDefaultPlan(AddressType addressType) { - switch (addressType) { - case QUEUE: - return DestinationPlan.BROKERED_QUEUE; - case TOPIC: - return DestinationPlan.BROKERED_TOPIC; - } - return null; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseStandard.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseStandard.java deleted file mode 100644 index 07d7b1fe49a..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseStandard.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases; - -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; - -public interface ITestBaseStandard extends ITestBase { - - @Override - default AddressSpaceType getAddressSpaceType() { - return AddressSpaceType.STANDARD; - } - - @Override - default String getDefaultPlan(AddressType addressType) { - switch (addressType) { - case QUEUE: - return DestinationPlan.STANDARD_SMALL_QUEUE; - case TOPIC: - return DestinationPlan.STANDARD_SMALL_TOPIC; - case ANYCAST: - return DestinationPlan.STANDARD_SMALL_ANYCAST; - case MULTICAST: - return DestinationPlan.STANDARD_SMALL_MULTICAST; - } - return null; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTBase.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTBase.java deleted file mode 100644 index e27d19a441c..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTBase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.iot; - -import org.junit.jupiter.api.BeforeAll; - -import io.enmasse.systemtest.iot.DeviceManagementApi; -import io.enmasse.systemtest.iot.IoTTestSession; - -public interface ITestIoTBase { - String IOT_ADDRESS_EVENT = "event"; - String IOT_ADDRESS_TELEMETRY = "telemetry"; - String IOT_ADDRESS_CONTROL = "control"; - String IOT_ADDRESS_COMMAND = "command"; - String IOT_ADDRESS_COMMAND_RESPONSE = "command_response"; - - String[] IOT_ADDRESSES = new String[] { - IOT_ADDRESS_TELEMETRY, - IOT_ADDRESS_EVENT, - IOT_ADDRESS_CONTROL, - IOT_ADDRESS_COMMAND, - IOT_ADDRESS_COMMAND_RESPONSE, - }; - - String IOT_PROJECT_NAMESPACE = "iot-project-ns"; - - @BeforeAll - public static void deployDefaultCerts() throws Exception { - IoTTestSession.deployDefaultCerts(); - } - - @BeforeAll - public static void createDeviceManager() throws Exception { - DeviceManagementApi.createManagementServiceAccount(); - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTIsolated.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTIsolated.java deleted file mode 100644 index 35218089b2f..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTIsolated.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.iot; - -import org.junit.jupiter.api.Tag; - -import io.enmasse.systemtest.TestTag; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.manager.IsolatedIoTManager; -import io.enmasse.systemtest.manager.ResourceManager; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; - -@Tag(TestTag.ISOLATED_IOT) -public interface ITestIoTIsolated extends ITestIoTBase, ITestBase { - - IsolatedIoTManager isolatedIoTManager = IsolatedIoTManager.getInstance(); - - default AmqpClientFactory getAmqpClientFactory() { - return isolatedIoTManager.getAmqpClientFactory(); - } - - @Override - default ResourceManager getResourceManager() { - return isolatedIoTManager; - } - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.STANDARD_SMALL; - } - - @Override - default String getDefaultAddrSpaceIdentifier() { - return "standard"; - } - - @Override - default AddressSpaceType getAddressSpaceType() { - return AddressSpaceType.STANDARD; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTShared.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTShared.java deleted file mode 100644 index d61b7d450d0..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTShared.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.iot; - -import org.junit.jupiter.api.Tag; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.systemtest.TestTag; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.manager.ResourceManager; -import io.enmasse.systemtest.manager.SharedIoTManager; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; - -@Tag(TestTag.SHARED_IOT) -public interface ITestIoTShared extends ITestBase, ITestIoTBase { - - SharedIoTManager sharedIoTResourceManager = SharedIoTManager.getInstance(); - - default AddressSpace getSharedAddressSpace() { - return sharedIoTResourceManager.getSharedAddressSpace(); - } - - default AmqpClientFactory getAmqpClientFactory() { - return sharedIoTResourceManager.getAmqpClientFactory(); - } - - default IoTProject getSharedIoTProject() { - return sharedIoTResourceManager.getSharedIoTProject(); - } - - default IoTConfig getSharedIoTConfig() { - return sharedIoTResourceManager.getSharedIoTConfig(); - } - - @Override - default ResourceManager getResourceManager() { - return sharedIoTResourceManager; - } - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.STANDARD_SMALL; - } - - @Override - default String getDefaultAddrSpaceIdentifier() { - return "shared-iot"; - } - - @Override - default AddressSpaceType getAddressSpaceType() { - return AddressSpaceType.STANDARD; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestBaseIsolated.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestBaseIsolated.java deleted file mode 100644 index 4bdfa006f04..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestBaseIsolated.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.isolated; - -import static io.enmasse.systemtest.TestTag.ISOLATED; - -import java.util.List; - -import org.junit.jupiter.api.Tag; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.manager.IsolatedResourcesManager; -import io.enmasse.systemtest.manager.ResourceManager; - -@Tag(ISOLATED) -public interface ITestBaseIsolated extends ITestBase { - IsolatedResourcesManager isolatedResourcesManager = IsolatedResourcesManager.getInstance(); - List currentAddressSpaces = isolatedResourcesManager.getCurrentAddressSpaces(); - - default AmqpClientFactory getAmqpClientFactory() { - return isolatedResourcesManager.getAmqpClientFactory(); - } - - @Override - default ResourceManager getResourceManager() { - return isolatedResourcesManager; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedBrokered.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedBrokered.java deleted file mode 100644 index 9a44fad0b42..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedBrokered.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.isolated; - -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.bases.ITestBaseBrokered; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import org.junit.jupiter.api.Tag; - -import static io.enmasse.systemtest.TestTag.ISOLATED_BROKER; - - -@Tag(ISOLATED_BROKER) -public interface ITestIsolatedBrokered extends ITestBaseBrokered, ITestBaseIsolated, ITestBase { - - @Override - default AddressSpaceType getAddressSpaceType() { - return AddressSpaceType.BROKERED; - } - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.BROKERED; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedSharedInfra.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedSharedInfra.java deleted file mode 100644 index 926e5a5cf13..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedSharedInfra.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.isolated; - -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.manager.IsolatedResourcesManager; -import io.enmasse.systemtest.manager.ResourceManager; - - -public interface ITestIsolatedSharedInfra extends ITestBase { - - IsolatedResourcesManager isolatedResourcesManager = IsolatedResourcesManager.getInstance(); - - default AmqpClientFactory getAmqpClientFactory() { - return isolatedResourcesManager.getAmqpClientFactory(); - } - - @Override - default ResourceManager getResourceManager() { - return isolatedResourcesManager; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedStandard.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedStandard.java deleted file mode 100644 index 0f2fdfdf261..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedStandard.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.isolated; - -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.bases.ITestBaseStandard; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import org.junit.jupiter.api.Tag; - -import static io.enmasse.systemtest.TestTag.ISOLATED_STANDARD; - -@Tag(ISOLATED_STANDARD) -public interface ITestIsolatedStandard extends ITestBaseStandard, ITestBaseIsolated, ITestBase { - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.STANDARD_UNLIMITED; - } - - @Override - default String getDefaultAddrSpaceIdentifier() { - return "standard"; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestBaseShared.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestBaseShared.java deleted file mode 100644 index 3e4046c946c..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestBaseShared.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.shared; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.manager.ResourceManager; -import io.enmasse.systemtest.manager.SharedResourceManager; - -public interface ITestBaseShared extends ITestBase { - SharedResourceManager sharedResourceManager = SharedResourceManager.getInstance(); - - default AddressSpace getSharedAddressSpace() { - return sharedResourceManager.getSharedAddressSpace(); - } - - default AmqpClientFactory getAmqpClientFactory() { - return sharedResourceManager.getAmqpClientFactory(); - } - - @Override - default ResourceManager getResourceManager() { - return sharedResourceManager; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedBrokered.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedBrokered.java deleted file mode 100644 index 2697d47c13e..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedBrokered.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.shared; - -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.bases.ITestBaseBrokered; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import org.junit.jupiter.api.Tag; - -import static io.enmasse.systemtest.TestTag.SHARED_BROKERED; - -@Tag(SHARED_BROKERED) -public interface ITestSharedBrokered extends ITestBase, ITestBaseShared, ITestBaseBrokered { - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.BROKERED; - } - - @Override - default String getDefaultAddrSpaceIdentifier() { - return "brokered"; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedStandard.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedStandard.java deleted file mode 100644 index f2d4d9d72e4..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedStandard.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.shared; - -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.bases.ITestBaseStandard; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import org.junit.jupiter.api.Tag; - -import static io.enmasse.systemtest.TestTag.SHARED_STANDARD; - -@Tag(SHARED_STANDARD) -public interface ITestSharedStandard extends ITestBaseStandard, ITestBaseShared, ITestBase { - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.STANDARD_UNLIMITED; - } - - @Override - default String getDefaultAddrSpaceIdentifier() { - return "standard"; - } - - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/clients/ClientUtils.java b/systemtests/src/main/java/io/enmasse/systemtest/clients/ClientUtils.java index 6d461dc1da6..2895c261547 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/clients/ClientUtils.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/clients/ClientUtils.java @@ -13,13 +13,13 @@ import io.enmasse.systemtest.amqp.ReceiverStatus; import io.enmasse.systemtest.amqp.UnauthorizedAccessException; import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.manager.ResourceManager; import io.enmasse.systemtest.messagingclients.AbstractClient; import io.enmasse.systemtest.messagingclients.ClientArgument; import io.enmasse.systemtest.messagingclients.ExternalMessagingClient; import io.enmasse.systemtest.messagingclients.rhea.RheaClientConnector; import io.enmasse.systemtest.messagingclients.rhea.RheaClientReceiver; import io.enmasse.systemtest.messagingclients.rhea.RheaClientSender; +import io.enmasse.systemtest.messaginginfra.ResourceManager; import io.enmasse.systemtest.model.address.AddressType; import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; import io.enmasse.systemtest.utils.AddressSpaceUtils; @@ -33,7 +33,6 @@ import org.slf4j.Logger; import javax.security.sasl.AuthenticationException; - import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; diff --git a/systemtests/src/main/java/io/enmasse/systemtest/info/TestInfo.java b/systemtests/src/main/java/io/enmasse/systemtest/info/TestInfo.java index 993dcf2ae42..3c68720fdcb 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/info/TestInfo.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/info/TestInfo.java @@ -185,10 +185,6 @@ public boolean isTestShared() { return false; } - public boolean isTestSharedInfra() { - return currentTestClass.getTags().stream().anyMatch(TestTag.SHARED_INFRA_TAGS::contains); - } - public boolean isTestIoT() { for (String tag : currentTest.getTags()) { if (TestTag.IOT_TAGS.contains(tag)) { diff --git a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java index 200f426c325..cf4be27ebc1 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java @@ -5,8 +5,6 @@ package io.enmasse.systemtest.iot; -import static io.enmasse.systemtest.bases.iot.ITestIoTBase.IOT_ADDRESS_EVENT; -import static io.enmasse.systemtest.bases.iot.ITestIoTBase.IOT_ADDRESS_TELEMETRY; import static io.enmasse.systemtest.condition.OpenShiftVersion.OCP4; import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.MQTT; @@ -55,7 +53,6 @@ import io.enmasse.systemtest.UserCredentials; import io.enmasse.systemtest.amqp.AmqpClient; import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.iot.ITestIoTBase; import io.enmasse.systemtest.executor.Exec; import io.enmasse.systemtest.info.TestInfo; import io.enmasse.systemtest.iot.IoTTestSession.Builder.PreDeployProcessor; @@ -581,10 +578,10 @@ public void addCleanup(final ThrowingCallable cleanupTask) { .withAuthorization( Collections.singletonList(new UserAuthorizationBuilder() .withAddresses( - IOT_ADDRESS_TELEMETRY + "/" + tenantId, - IOT_ADDRESS_TELEMETRY + "/" + tenantId + "/*", - IOT_ADDRESS_EVENT + "/" + tenantId, - IOT_ADDRESS_EVENT + "/" + tenantId + "/*") + "telemetry" + "/" + tenantId, + "telemetry" + "/" + tenantId + "/*", + "event" + "/" + tenantId, + "event" + "/" + tenantId + "/*") .withOperations(Operation.recv) .build())) .endSpec() @@ -657,7 +654,7 @@ public static IoTTestSession.Builder create(final String namespace, final boolea var project = new IoTProjectBuilder( IoTUtils.getBasicIoTProjectObject( name, name, - ITestIoTBase.IOT_PROJECT_NAMESPACE, + "iot-project-ns", AddressSpacePlans.STANDARD_SMALL)); // done diff --git a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java index 4d38a3dc98b..edea94dc6cc 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java @@ -5,7 +5,6 @@ package io.enmasse.systemtest.iot; -import static io.enmasse.systemtest.bases.iot.ITestIoTBase.IOT_PROJECT_NAMESPACE; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -38,7 +37,7 @@ static void createDeviceManager() throws Exception { @BeforeEach default void createNamespace() { - Kubernetes.getInstance().createNamespace(IOT_PROJECT_NAMESPACE); + Kubernetes.getInstance().createNamespace("iot-project-ns"); } } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java b/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java index 6caf6b945c7..bbad09d7d59 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java @@ -4,31 +4,26 @@ */ package io.enmasse.systemtest.listener; -import org.junit.jupiter.api.extension.AfterAllCallback; -import org.junit.jupiter.api.extension.AfterEachCallback; -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.BeforeEachCallback; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.LifecycleMethodExecutionExceptionHandler; -import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; -import org.slf4j.Logger; - import io.enmasse.systemtest.EnmasseInstallType; import io.enmasse.systemtest.Environment; import io.enmasse.systemtest.bases.ThrowableRunner; import io.enmasse.systemtest.info.TestInfo; import io.enmasse.systemtest.logs.CustomLogger; import io.enmasse.systemtest.logs.GlobalLogCollector; -import io.enmasse.systemtest.manager.IsolatedIoTManager; -import io.enmasse.systemtest.manager.IsolatedResourcesManager; -import io.enmasse.systemtest.manager.SharedIoTManager; -import io.enmasse.systemtest.manager.SharedResourceManager; import io.enmasse.systemtest.messaginginfra.ResourceManager; import io.enmasse.systemtest.operator.EnmasseOperatorManager; import io.enmasse.systemtest.platform.KubeCMDClient; import io.enmasse.systemtest.platform.Kubernetes; import io.enmasse.systemtest.platform.cluster.KubeClusterManager; import io.enmasse.systemtest.utils.TestUtils; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.LifecycleMethodExecutionExceptionHandler; +import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; +import org.slf4j.Logger; /** * This class implements a variety of junit callbacks and orchestates the full lifecycle of the operator installation @@ -40,10 +35,6 @@ public class JunitCallbackListener implements TestExecutionExceptionHandler, Lif private static final Environment env = Environment.getInstance(); private final Kubernetes kubernetes = Kubernetes.getInstance(); private final TestInfo testInfo = TestInfo.getInstance(); - private final IsolatedResourcesManager isolatedResourcesManager = IsolatedResourcesManager.getInstance(); - private final SharedResourceManager sharedResourcesManager = SharedResourceManager.getInstance(); - private final SharedIoTManager sharedIoTManager = SharedIoTManager.getInstance(); - private final IsolatedIoTManager isolatedIoTManager = IsolatedIoTManager.getInstance(); private final EnmasseOperatorManager operatorManager = EnmasseOperatorManager.getInstance(); @Override @@ -54,43 +45,12 @@ public void beforeAll(ExtensionContext context) throws Exception { ResourceManager.getInstance().setClassResources(); KubeClusterManager.getInstance().setClassConfigurations(); handleCallBackError("Callback before all", context, () -> { - if (testInfo.isUpgradeTest()) { - if (operatorManager.isEnmasseBundleDeployed()) { - operatorManager.deleteEnmasseBundle(); - } - LOGGER.info("Enmasse is not installed because next test is {}", context.getDisplayName()); - } else if (testInfo.isOLMTest()) { - LOGGER.info("Test is OLM"); - if (operatorManager.isEnmasseOlmDeployed()) { - operatorManager.deleteEnmasseOlm(); - } - if (operatorManager.isEnmasseBundleDeployed()) { - operatorManager.deleteEnmasseBundle(); - } - operatorManager.installEnmasseOlm(testInfo.getOLMInstallationType()); - } else if (env.installType() == EnmasseInstallType.OLM) { - if (!operatorManager.isEnmasseOlmDeployed()) { - operatorManager.installEnmasseOlm(); - } - if (!operatorManager.areExamplesApplied()) { - operatorManager.installExamplesBundleOlm(); - operatorManager.waitUntilOperatorReadyOlm(); - } - } else if (testInfo.isTestSharedInfra()) { - if (operatorManager.isEnmasseBundleDeployed()) { - operatorManager.deleteEnmasseBundle(); - } else if (operatorManager.isEnmasseOlmDeployed()) { - operatorManager.deleteEnmasseOlm(); - } - operatorManager.installEnmasseSharedInfraBundle(); - } else { - if (!operatorManager.isEnmasseBundleDeployed()) { - operatorManager.installEnmasseBundle(); - } - if (testInfo.isClassIoT()) { - operatorManager.installIoTOperator(); - } + if (operatorManager.isEnmasseBundleDeployed()) { + operatorManager.deleteEnmasseBundle(); + } else if (operatorManager.isEnmasseOlmDeployed()) { + operatorManager.deleteEnmasseOlm(); } + operatorManager.installEnmasseBundle(); }); } @@ -105,15 +65,7 @@ public void afterAll(ExtensionContext extensionContext) throws Exception { } if (env.skipCleanup() || env.skipUninstall()) { LOGGER.info("Skip cleanup/uninstall is set, enmasse and iot operators won't be deleted"); - } else if (testInfo.isOLMTest()) { - LOGGER.info("Test is OLM"); - if (operatorManager.isEnmasseOlmDeployed()) { - operatorManager.deleteEnmasseOlm(); - } } else if (env.installType() == EnmasseInstallType.BUNDLE) { - if (testInfo.isEndOfIotTests()) { - operatorManager.removeIoT(); - } if (operatorManager.isEnmasseOlmDeployed()) { operatorManager.deleteEnmasseOlm(); } @@ -122,7 +74,7 @@ public void afterAll(ExtensionContext extensionContext) throws Exception { } @Override - public void beforeEach(ExtensionContext context) throws Exception { + public void beforeEach(ExtensionContext context) { testInfo.setCurrentTest(context); ResourceManager.getInstance().setMethodResources(); KubeClusterManager.getInstance().setMethodConfigurations(); @@ -135,44 +87,9 @@ public void afterEach(ExtensionContext extensionContext) throws Exception { LOGGER.info("Teardown section: "); ResourceManager.getInstance().deleteMethodResources(); KubeClusterManager.getInstance().restoreMethodConfigurations(); - if (testInfo.isTestShared()) { - tearDownSharedResources(); - } else if (testInfo.isTestIoT()) { - if (testInfo.needsIoTCleanup()) { - isolatedIoTManager.tearDown(testInfo.getActualTest()); - } - } else { - tearDownCommonResources(); - } }); } - private void tearDownCommonResources() throws Exception { - LOGGER.info("Admin resource manager teardown"); - isolatedResourcesManager.tearDown(testInfo.getActualTest()); - isolatedResourcesManager.unsetReuseAddressSpace(); - isolatedResourcesManager.deleteAddressspacesFromList(); - } - - private void tearDownSharedResources() throws Exception { - if (testInfo.isAddressSpaceDeleteable() || testInfo.getActualTest().getExecutionException().isPresent()) { - if (testInfo.isTestIoT()) { - if (testInfo.needsIoTCleanup()) { - LOGGER.info("Teardown shared IoT!"); - sharedIoTManager.tearDown(testInfo.getActualTest()); - } else { - LOGGER.info("Self-cleaning IoT test"); - sharedIoTManager.closeAmqpFactory(); - } - } else { - LOGGER.info("Teardown shared!"); - sharedResourcesManager.tearDown(testInfo.getActualTest()); - } - } else if (sharedResourcesManager.getSharedAddressSpace() != null) { - sharedResourcesManager.tearDownShared(); - } - } - @Override public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable { saveKubernetesState("Test execution", context, throwable); diff --git a/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitExecutionListener.java b/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitExecutionListener.java index 03c1a0b53c4..11984cd14e1 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitExecutionListener.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitExecutionListener.java @@ -4,22 +4,19 @@ */ package io.enmasse.systemtest.listener; -import org.junit.platform.launcher.TestExecutionListener; -import org.junit.platform.launcher.TestPlan; -import org.slf4j.Logger; - import io.enmasse.systemtest.Environment; import io.enmasse.systemtest.TestTag; import io.enmasse.systemtest.info.TestInfo; import io.enmasse.systemtest.logs.CustomLogger; import io.enmasse.systemtest.logs.GlobalLogCollector; -import io.enmasse.systemtest.manager.IsolatedResourcesManager; import io.enmasse.systemtest.operator.EnmasseOperatorManager; import io.enmasse.systemtest.platform.Kubernetes; import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; import io.enmasse.systemtest.time.TimeMeasuringSystem; -import io.enmasse.systemtest.utils.AddressSpaceUtils; import io.enmasse.systemtest.utils.IoTUtils; +import org.junit.platform.launcher.TestExecutionListener; +import org.junit.platform.launcher.TestPlan; +import org.slf4j.Logger; /** * Execution listener useful for safety cleanups of the test environment after test suite execution @@ -117,8 +114,6 @@ private void performCleanup() { kube.getAddressSpaceClient().inAnyNamespace().list().getItems().forEach((addrSpace) -> { LOGGER.info("address space '{}' will be removed", addrSpace); try { - AddressSpaceUtils.deleteAddressSpaceAndWait(addrSpace, logCollector); - IsolatedResourcesManager.getInstance().tearDown(TestInfo.getInstance().getActualTest()); } catch (Exception e) { LOGGER.warn("Cleanup failed or no clean is needed"); } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedIoTManager.java b/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedIoTManager.java deleted file mode 100644 index 23ea7ed430b..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedIoTManager.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.manager; - -import static io.enmasse.systemtest.bases.iot.ITestIoTBase.IOT_PROJECT_NAMESPACE; - -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.enmasse.systemtest.utils.ThrowingCallable; - -public class IsolatedIoTManager extends ResourceManager { - - private Logger LOGGER = CustomLogger.getLogger(); - protected AmqpClientFactory amqpClientFactory; - protected List ioTProjects; - protected List ioTConfigs; - private static IsolatedIoTManager instance = null; - private UserCredentials defaultCredentials = environment.getDefaultCredentials(); - - private IsolatedIoTManager() { - ioTProjects = new ArrayList<>(); - ioTConfigs = new ArrayList<>(); - } - - public static synchronized IsolatedIoTManager getInstance() { - if (instance == null) { - instance = new IsolatedIoTManager(); - } - return instance; - } - - public void initFactories(AddressSpace addressSpace) { - amqpClientFactory = new AmqpClientFactory(addressSpace, defaultCredentials); - } - - public void initFactories(IoTProject project) { - String addSpaceName = project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(); - this.initFactories(kubernetes.getAddressSpaceClient(project.getMetadata() - .getNamespace()).withName(addSpaceName).get()); - } - - @Override - public void setup() { - kubernetes.createNamespace(IOT_PROJECT_NAMESPACE); - } - - private static Throwable cleanup(ThrowingCallable callable, Throwable e) { - try { - callable.call(); - return e; - } catch (Throwable e1) { - if (e == null) { - return e1; - } else { - e.addSuppressed(e1); - return e; - } - } - } - - @Override - public void tearDown(ExtensionContext context) throws Exception { - - if (environment.skipCleanup()) { - - LOGGER.info("Skip cleanup is set, no cleanup process"); - - } else { - - // the next lines, using cleanup(...) prevent that the failure of - // one cleanup step prevents the next step from being executed. - // Also we must handle Throwables here, since some parts of the code - // call 'assert*', which throws a 'AssertionFailedError', which is - // is an 'Error' rather than an 'Exception'. - - Throwable e = null; - e = cleanup(() -> tearDownProjects(), e); - e = cleanup(() -> tearDownConfigs(), e); - if (context.getExecutionException().isPresent()) { - final Path path = TestUtils.getFailedTestLogsPath(context); - e = cleanup(() -> SystemtestsKubernetesApps.collectInfinispanServerLogs(path), e); - } - e = cleanup(() -> SystemtestsKubernetesApps.deleteInfinispanServer(), e); - e = cleanup(() -> SystemtestsKubernetesApps.deletePostgresqlServer(), e); - e = cleanup(() -> SystemtestsKubernetesApps.deleteH2Server(), e); - - if (e != null) { - LOGGER.error("Error tearing down IoT test: {}", e); - if (e instanceof Exception) { - throw (Exception) e; - } else { - throw new Exception(e); - } - } - - } - } - - private void tearDownProjects() throws Exception { - LOGGER.info("All IoTProjects will be removed"); - for (IoTProject project : ioTProjects) { - var iotProjectApiClient = kubernetes.getIoTProjectClient(project.getMetadata().getNamespace()); - if (iotProjectApiClient.withName(project.getMetadata().getName()).get() != null) { - IoTUtils.deleteIoTProjectAndWait(kubernetes, project); - } else { - LOGGER.info("IoTProject '{}' doesn't exists!", project.getMetadata().getName()); - } - } - ioTProjects.clear(); - } - - private void tearDownConfigs() throws Exception { - // delete configs - LOGGER.info("All IoTConfigs will be removed"); - var iotConfigApiClient = kubernetes.getIoTConfigClient(); - for (IoTConfig config : ioTConfigs) { - if (iotConfigApiClient.withName(config.getMetadata().getName()).get() != null) { - IoTUtils.deleteIoTConfigAndWait(kubernetes, config); - } else { - LOGGER.info("IoTConfig '{}' doesn't exists!", config.getMetadata().getName()); - } - } - ioTConfigs.clear(); - } - - @Override - public AmqpClientFactory getAmqpClientFactory() { - return amqpClientFactory; - } - - @Override - public void setAmqpClientFactory(AmqpClientFactory amqpClientFactory) { - this.amqpClientFactory = amqpClientFactory; - } - - public void createIoTProject(IoTProject project) throws Exception { - ioTProjects.add(project); - IoTUtils.createIoTProject(project); - initFactories(project); - } - - public void deleteIoTProject(IoTProject project) throws Exception { - IoTUtils.deleteIoTProjectAndWait(kubernetes, project); - ioTProjects.remove(project); - } - - public void createIoTConfig(IoTConfig ioTConfig) throws Exception { - ioTConfigs.add(ioTConfig); - IoTUtils.createIoTConfig(ioTConfig); - } - - public void deleteIoTConfig(IoTConfig ioTConfig) throws Exception { - IoTUtils.deleteIoTConfigAndWait(kubernetes, ioTConfig); - ioTConfigs.add(ioTConfig); - } - - public List getIoTProjects() { - return ioTProjects; - } - - public String getTenantId() { - return IoTUtils.getTenantId(ioTProjects.get(0)); - } - - public List getIoTConfigs() { - return ioTConfigs; - } - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedResourcesManager.java b/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedResourcesManager.java deleted file mode 100644 index f193013f345..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedResourcesManager.java +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.manager; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.admin.model.v1.AddressPlan; -import io.enmasse.admin.model.v1.AddressSpacePlan; -import io.enmasse.admin.model.v1.AuthenticationService; -import io.enmasse.admin.model.v1.BrokeredInfraConfig; -import io.enmasse.admin.model.v1.InfraConfig; -import io.enmasse.admin.model.v1.StandardInfraConfig; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.time.SystemtestsOperation; -import io.enmasse.systemtest.time.TimeMeasuringSystem; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.TestUtils; - -public class IsolatedResourcesManager extends ResourceManager { - - private static IsolatedResourcesManager managerInstance = null; - private static Logger LOGGER; - protected AmqpClientFactory amqpClientFactory; - boolean reuseAddressSpace = false; - private ArrayList addressPlans; - private ArrayList addressSpacePlans; - private ArrayList standardInfraConfigs; - private ArrayList brokeredInfraConfigs; - private ArrayList authServices; - private UserCredentials defaultCredentials = environment.getDefaultCredentials(); - - private IsolatedResourcesManager() { - LOGGER = CustomLogger.getLogger(); - addressPlans = new ArrayList<>(); - addressSpacePlans = new ArrayList<>(); - standardInfraConfigs = new ArrayList<>(); - brokeredInfraConfigs = new ArrayList<>(); - authServices = new ArrayList<>(); - currentAddressSpaces = new ArrayList<>(); - } - - //------------------------------------------------------------------------------------------------ - // Singleton handling - //------------------------------------------------------------------------------------------------ - - public List getCurrentAddressSpaces() { - return currentAddressSpaces; - } - - public static synchronized IsolatedResourcesManager getInstance() { - if (managerInstance == null) { - managerInstance = new IsolatedResourcesManager(); - } - return managerInstance; - } - - - public void initFactories(AddressSpace addressSpace) { - amqpClientFactory = new AmqpClientFactory(addressSpace, defaultCredentials); - } - - public void initFactories(AddressSpace addressSpace, UserCredentials userCredentials) throws Exception { - closeClientFactories(amqpClientFactory); - amqpClientFactory = new AmqpClientFactory(addressSpace, userCredentials); - } - - @Override - public void setup() { - if (currentAddressSpaces.isEmpty()) { - initFactories(null); - } else { - initFactories(currentAddressSpaces.get(0)); - } - } - - @Override - public void tearDown(ExtensionContext context) throws Exception { - LOGGER.info("Reuse addressspace: " + reuseAddressSpace); - LOGGER.info("Environment cleanup: " + environment.skipCleanup()); - - if (!environment.skipCleanup() && !reuseAddressSpace) { - for (AddressSpacePlan addressSpacePlan : addressSpacePlans) { - Kubernetes.getInstance().getAddressSpacePlanClient().withName(addressSpacePlan.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitUntilCondition("Delete addressspace plan", waitPhase -> Kubernetes.getInstance().getAddressSpacePlanClient().list().getItems().stream().noneMatch(plan -> plan.getMetadata().getName().equals(addressSpacePlan.getMetadata().getName())), - new TimeoutBudget(1, TimeUnit.MINUTES)); - LOGGER.info("AddressSpace plan {} deleted", addressSpacePlan.getMetadata().getName()); - } - addressSpacePlans.clear(); - - for (AddressPlan addressPlan : addressPlans) { - Kubernetes.getInstance().getAddressPlanClient().withName(addressPlan.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitUntilCondition("Delete address plan", waitPhase -> Kubernetes.getInstance().getAddressPlanClient().list().getItems().stream().noneMatch(plan -> plan.getMetadata().getName().equals(addressPlan.getMetadata().getName())), - new TimeoutBudget(1, TimeUnit.MINUTES)); - LOGGER.info("Address plan {} deleted", addressPlan.getMetadata().getName()); - } - addressPlans.clear(); - - for (StandardInfraConfig infraConfigDefinition : standardInfraConfigs) { - Kubernetes.getInstance().getStandardInfraConfigClient().withName(infraConfigDefinition.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitUntilCondition("Delete infraConfig plan", waitPhase -> Kubernetes.getInstance().getStandardInfraConfigClient().list().getItems().stream().noneMatch(plan -> plan.getMetadata().getName().equals(infraConfigDefinition.getMetadata().getName())), - new TimeoutBudget(1, TimeUnit.MINUTES)); - LOGGER.info("Standardinfraconfig {} deleted", infraConfigDefinition.getMetadata().getName()); - } - standardInfraConfigs.clear(); - - for (BrokeredInfraConfig infraConfigDefinition : brokeredInfraConfigs) { - Kubernetes.getInstance().getBrokeredInfraConfigClient().withName(infraConfigDefinition.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitUntilCondition("Delete infraConfig plan", waitPhase -> Kubernetes.getInstance().getBrokeredInfraConfigClient().list().getItems().stream().noneMatch(plan -> plan.getMetadata().getName().equals(infraConfigDefinition.getMetadata().getName())), - new TimeoutBudget(1, TimeUnit.MINUTES)); - LOGGER.info("Brokeredinfraconfig {} deleted", infraConfigDefinition.getMetadata().getName()); - } - brokeredInfraConfigs.clear(); - - for (AuthenticationService authService : authServices) { - Kubernetes.getInstance().getAuthenticationServiceClient().withName(authService.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitForNReplicas(0, false, authService.getMetadata().getNamespace(), Map.of("name", authService.getMetadata().getName()), Collections.emptyMap(), new TimeoutBudget(1, TimeUnit.MINUTES), 5000); - LOGGER.info("AuthService {} deleted", authService.getMetadata().getName()); - } - authServices.clear(); - - - closeClientFactories(amqpClientFactory); - amqpClientFactory = null; - } else { - LOGGER.warn("No custom resources are deleted, SKIP_CLEANUP is set"); - } - - } - - - //------------------------------------------------------------------------------------------------ - // Address plans - //------------------------------------------------------------------------------------------------ - - @Override - public void createAddressPlan(AddressPlan addressPlan) throws Exception { - addressPlans.add(addressPlan); - super.createAddressPlan(addressPlan); - } - - @Override - public void removeAddressPlan(AddressPlan addressPlan) throws Exception { - super.removeAddressPlan(addressPlan); - addressPlans.removeIf(addressPlanIter -> addressPlanIter.getMetadata().getName().equals(addressPlan.getMetadata().getName())); - } - - @Override - public void replaceAddressPlan(AddressPlan plan) throws InterruptedException { - super.replaceAddressPlan(plan); - } - - @Override - public AddressPlan getAddressPlan(String name) throws Exception { - return super.getAddressPlan(name); - } - - //------------------------------------------------------------------------------------------------ - // Address space plans - //------------------------------------------------------------------------------------------------ - - @Override - public void createAddressSpacePlan(AddressSpacePlan addressSpacePlan) throws Exception { - addressSpacePlans.add(addressSpacePlan); - super.createAddressSpacePlan(addressSpacePlan); - } - - @Override - public void createAddressSpacePlan(AddressSpacePlan addressSpacePlan, boolean wait) throws Exception { - addressSpacePlans.add(addressSpacePlan); - super.createAddressSpacePlan(addressSpacePlan, wait); - } - - @Override - public void removeAddressSpacePlan(AddressSpacePlan addressSpacePlan) throws Exception { - super.removeAddressSpacePlan(addressSpacePlan); - addressSpacePlans.removeIf(spacePlanIter -> spacePlanIter.getMetadata().getName().equals(addressSpacePlan.getMetadata().getName())); - } - - @Override - public AddressSpacePlan getAddressSpacePlan(String config) throws Exception { - return super.getAddressSpacePlan(config); - } - - //------------------------------------------------------------------------------------------------ - // Infra configs - //------------------------------------------------------------------------------------------------ - - @Override - public BrokeredInfraConfig getBrokeredInfraConfig(String name) throws Exception { - return Kubernetes.getInstance().getBrokeredInfraConfigClient().withName(name).get(); - } - - @Override - public StandardInfraConfig getStandardInfraConfig(String name) throws Exception { - return Kubernetes.getInstance().getStandardInfraConfigClient().withName(name).get(); - } - - @Override - public void createInfraConfig(StandardInfraConfig standardInfraConfig) { - standardInfraConfigs.add(standardInfraConfig); - super.createInfraConfig(standardInfraConfig); - } - - @Override - public void createInfraConfig(BrokeredInfraConfig brokeredInfraConfig) { - brokeredInfraConfigs.add(brokeredInfraConfig); - super.createInfraConfig(brokeredInfraConfig); - } - - public void createInfraConfig(InfraConfig infraConfigDefinition) throws Exception { - if (infraConfigDefinition instanceof StandardInfraConfig) { - standardInfraConfigs.add((StandardInfraConfig) infraConfigDefinition); - super.createInfraConfig((StandardInfraConfig) infraConfigDefinition); - } else { - brokeredInfraConfigs.add((BrokeredInfraConfig) infraConfigDefinition); - super.createInfraConfig((BrokeredInfraConfig) infraConfigDefinition); - } - } - - public void removeInfraConfig(InfraConfig infraConfigDefinition) throws Exception { - if (infraConfigDefinition instanceof StandardInfraConfig) { - super.removeInfraConfig((StandardInfraConfig) infraConfigDefinition); - standardInfraConfigs.removeIf(infraId -> infraId.getMetadata().getName().equals(infraConfigDefinition.getMetadata().getName())); - } else { - super.removeInfraConfig((BrokeredInfraConfig) infraConfigDefinition); - brokeredInfraConfigs.removeIf(infraId -> infraId.getMetadata().getName().equals(infraConfigDefinition.getMetadata().getName())); - } - } - - //------------------------------------------------------------------------------------------------ - // Authentication services - //------------------------------------------------------------------------------------------------ - - @Override - public void replaceAuthService(AuthenticationService authService) throws Exception { - replaceAuthService(authService, false); - } - - public void replaceAuthService(AuthenticationService authenticationService, boolean replaceExisting) throws Exception { - if (replaceExisting) { - super.replaceAuthService(authenticationService); - } else { - super.createAuthService(authenticationService); - authServices.add(authenticationService); - } - } - - @Override - public void createAuthService(AuthenticationService authenticationService) throws Exception { - authServices.add(authenticationService); - super.createAuthService(authenticationService); - } - - @Override - public void createAuthService(AuthenticationService authenticationService, boolean wait) throws Exception { - authServices.add(authenticationService); - super.createAuthService(authenticationService, wait); - } - - @Override - public void removeAuthService(AuthenticationService authService) throws Exception { - super.removeAuthService(authService); - authServices.removeIf(authserviceId -> authserviceId.getMetadata().getName().equals(authService.getMetadata().getName())); - } - - @Override - public void createAddressSpace(AddressSpace addressSpace) throws Exception { - createAddressSpace(addressSpace, true); - } - - @Override - public void createAddressSpace(AddressSpace addressSpace, boolean waitForReady) throws Exception { - if (!AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - currentAddressSpaces.add(addressSpace); - super.createAddressSpace(addressSpace, waitForReady); - } else { - if (waitForReady) { - super.waitForAddressSpaceReady(addressSpace); - } - } - } - - public void setReuseAddressSpace() { - reuseAddressSpace = true; - } - - public void unsetReuseAddressSpace() { - reuseAddressSpace = false; - } - - //================================================================================================ - //==================================== AddressSpace methods ====================================== - //================================================================================================ - - public void createAddressSpaceList(AddressSpace... addressSpaces) throws Exception { - String operationID = TimeMeasuringSystem.startOperation(SystemtestsOperation.CREATE_ADDRESS_SPACE); - ArrayList spaces = new ArrayList<>(); - for (AddressSpace addressSpace : addressSpaces) { - if (!AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - LOGGER.info("Address space '" + addressSpace + "' doesn't exist and will be created."); - spaces.add(addressSpace); - } else { - LOGGER.warn("Address space '" + addressSpace + "' already exists."); - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - currentAddressSpaces.add(addressSpace); - } - } - currentAddressSpaces.addAll(spaces); - super.createAddressSpaces(spaces, operationID); - } - - public void replaceAddressSpace(AddressSpace addressSpace) throws Exception { - replaceAddressSpace(addressSpace, true, null); - } - - public void deleteAddressspacesFromList() throws Exception { - if (environment.skipCleanup()) { - LOGGER.warn("No address space is deleted, SKIP_CLEANUP is set"); - } else { - LOGGER.info("All addressspaces will be removed"); - for (AddressSpace addressSpace : currentAddressSpaces) { - deleteAddressSpace(addressSpace); - } - currentAddressSpaces.clear(); - } - } - - @Override - public void addToAddressSpaces(AddressSpace addressSpace) { - this.currentAddressSpaces.add(addressSpace); - } - - @Override - public void deleteAddressSpaceCreatedBySC(AddressSpace addressSpace) throws Exception { - TestUtils.deleteAddressSpaceCreatedBySC(kubernetes, addressSpace, logCollector); - } - - @Override - public AmqpClientFactory getAmqpClientFactory() { - return amqpClientFactory; - } - - @Override - public void setAmqpClientFactory(AmqpClientFactory amqpClientFactory) { - this.amqpClientFactory = amqpClientFactory; - } - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/manager/ResourceManager.java b/systemtests/src/main/java/io/enmasse/systemtest/manager/ResourceManager.java deleted file mode 100644 index d1bb14d3e33..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/manager/ResourceManager.java +++ /dev/null @@ -1,532 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.manager; - -import static io.enmasse.systemtest.time.TimeoutBudget.ofDuration; -import static java.time.Duration.ofMinutes; - -import java.util.List; -import java.util.Objects; -import java.util.concurrent.TimeUnit; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.admin.model.v1.*; -import io.enmasse.config.AnnotationKeys; -import io.enmasse.systemtest.Environment; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.logs.GlobalLogCollector; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.time.SystemtestsOperation; -import io.enmasse.systemtest.time.TimeMeasuringSystem; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.enmasse.systemtest.utils.UserUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserAuthenticationType; -import io.enmasse.user.model.v1.UserBuilder; -import io.fabric8.kubernetes.api.model.Pod; - -public abstract class ResourceManager { - protected static final Environment environment = Environment.getInstance(); - protected static final Kubernetes kubernetes = Kubernetes.getInstance(); - protected static final GlobalLogCollector logCollector = new GlobalLogCollector(kubernetes, environment.testLogDir()); - private static Logger LOGGER = CustomLogger.getLogger(); - - protected String defaultAddSpaceIdentifier; - protected String addressSpaceType; - protected String addressSpacePlan; - protected List currentAddressSpaces; - - public void setDefaultAddSpaceIdentifier(String defaultAddSpaceIdentifier) { - this.defaultAddSpaceIdentifier = defaultAddSpaceIdentifier; - } - - public void setAddressSpaceType(String addressSpaceType) { - this.addressSpaceType = addressSpaceType; - } - - public void setAddressSpacePlan(String addressSpacePlan) { - this.addressSpacePlan = addressSpacePlan; - } - - public abstract void setup() throws Exception; - - public abstract void tearDown(ExtensionContext context) throws Exception; - - public abstract AmqpClientFactory getAmqpClientFactory(); - - public abstract void setAmqpClientFactory(AmqpClientFactory amqpClientFactory); - - public AddressSpace getSharedAddressSpace() { - return null; - } - - public void addToAddressSpaces(AddressSpace addressSpace) throws Exception { - throw new Exception("Not implemented in resource manager"); - } - - public void deleteAddressSpaceCreatedBySC(AddressSpace addressSpace) throws Exception { - throw new Exception("Not implemented in resource manager"); - } - - //------------------------------------------------------------------------------------------------ - // Client factories - //------------------------------------------------------------------------------------------------ - - public void closeClientFactories(AmqpClientFactory amqpClientFactory) throws Exception { - if (amqpClientFactory != null) { - amqpClientFactory.close(); - } - } - - //------------------------------------------------------------------------------------------------ - // Address plans - //------------------------------------------------------------------------------------------------ - - public void createAddressPlan(AddressPlan addressPlan) throws Exception { - LOGGER.info("Address plan {} will be created {}", addressPlan.getMetadata().getName(), addressPlan); - var client = Kubernetes.getInstance().getAddressPlanClient(); - client.create(addressPlan); - Thread.sleep(1000); - } - - public void replaceAddressPlan(AddressPlan addressPlan) throws InterruptedException { - LOGGER.info("Address plan {} will be replaced {}", addressPlan.getMetadata().getName(), addressPlan); - var client = Kubernetes.getInstance().getAddressPlanClient(); - client.createOrReplace(addressPlan); - Thread.sleep(1000); - } - - public void removeAddressPlan(AddressPlan addressPlan) throws Exception { - Kubernetes.getInstance().getAddressPlanClient().withName(addressPlan.getMetadata().getName()).cascading(true).delete(); - } - - public AddressPlan getAddressPlan(String name) throws Exception { - return Kubernetes.getInstance().getAddressPlanClient().withName(name).get(); - } - - //------------------------------------------------------------------------------------------------ - // Address space plans - //------------------------------------------------------------------------------------------------ - - public void createAddressSpacePlan(AddressSpacePlan addressSpacePlan) throws Exception { - createAddressSpacePlan(addressSpacePlan, true); - } - - public void createAddressSpacePlan(AddressSpacePlan addressSpacePlan, boolean wait) throws Exception { - LOGGER.info("AddressSpace plan {} will be created {}", addressSpacePlan.getMetadata().getName(), addressSpacePlan); - if (addressSpacePlan.getMetadata().getNamespace() == null || addressSpacePlan.getMetadata().getNamespace().equals("")) { - addressSpacePlan.getMetadata().setNamespace(Kubernetes.getInstance().getInfraNamespace()); - } - var client = Kubernetes.getInstance().getAddressSpacePlanClient(); - client.create(addressSpacePlan); - if (wait) { - TestUtils.waitForSchemaInSync(addressSpacePlan.getMetadata().getName()); - } - Thread.sleep(1000); - } - - public void removeAddressSpacePlan(AddressSpacePlan addressSpacePlan) throws Exception { - Kubernetes.getInstance().getAddressSpacePlanClient().withName(addressSpacePlan.getMetadata().getName()).cascading(true).delete(); - } - - public AddressSpacePlan getAddressSpacePlan(String config) throws Exception { - return Kubernetes.getInstance().getAddressSpacePlanClient().withName(config).get(); - } - - //------------------------------------------------------------------------------------------------ - // Infra configs - //------------------------------------------------------------------------------------------------ - - public BrokeredInfraConfig getBrokeredInfraConfig(String name) throws Exception { - return Kubernetes.getInstance().getBrokeredInfraConfigClient().withName(name).get(); - } - - public StandardInfraConfig getStandardInfraConfig(String name) throws Exception { - return Kubernetes.getInstance().getStandardInfraConfigClient().withName(name).get(); - } - - public void createInfraConfig(StandardInfraConfig standardInfraConfig) { - LOGGER.info("StandardInfraConfig {} will be created {}", standardInfraConfig.getMetadata().getName(), standardInfraConfig); - var client = Kubernetes.getInstance().getStandardInfraConfigClient(); - client.createOrReplace(standardInfraConfig); - } - - public void createInfraConfig(BrokeredInfraConfig brokeredInfraConfig) { - LOGGER.info("BrokeredInfraConfig {} will be created {}", brokeredInfraConfig.getMetadata().getName(), brokeredInfraConfig); - var client = Kubernetes.getInstance().getBrokeredInfraConfigClient(); - client.createOrReplace(brokeredInfraConfig); - } - - public void removeInfraConfig(StandardInfraConfig infraConfig) { - var client = Kubernetes.getInstance().getStandardInfraConfigClient(); - client.withName(infraConfig.getMetadata().getName()).cascading(true).delete(); - } - - public void removeInfraConfig(BrokeredInfraConfig infraConfig) { - var client = Kubernetes.getInstance().getBrokeredInfraConfigClient(); - client.withName(infraConfig.getMetadata().getName()).cascading(true).delete(); - } - - //------------------------------------------------------------------------------------------------ - // Authentication services - //------------------------------------------------------------------------------------------------ - - public AuthenticationService getAuthService(String name) { - return Kubernetes.getInstance().getAuthenticationServiceClient().withName(name).get(); - } - - public void createAuthService(AuthenticationService authenticationService) throws Exception { - createAuthService(authenticationService, true); - } - - public void createAuthService(AuthenticationService authenticationService, boolean wait) throws Exception { - var client = Kubernetes.getInstance().getAuthenticationServiceClient(); - LOGGER.info("AuthService {} will be created {}", authenticationService.getMetadata().getName(), authenticationService); - client.create(authenticationService); - if (wait) { - waitForAuthPods(authenticationService); - } - } - - - public void replaceAuthService(AuthenticationService authenticationService) throws Exception { - LOGGER.info("AuthService {} will be created {}", authenticationService.getMetadata().getName(), authenticationService); - var client = Kubernetes.getInstance().getAuthenticationServiceClient(); - client.createOrReplace(authenticationService); - waitForAuthPods(authenticationService); - } - - public void waitForAuthPods(AuthenticationService authenticationService) throws Exception { - String desiredPodName = authenticationService.getMetadata().getName(); - int expectedMatches = 1; - if (authenticationService.getSpec().getType().equals(AuthenticationServiceType.none) && - authenticationService.getSpec().getNone() != null && - authenticationService.getSpec().getNone().getReplicas() != null) { - expectedMatches = authenticationService.getSpec().getNone().getReplicas(); - } else if (authenticationService.getSpec().getType().equals(AuthenticationServiceType.standard) && - authenticationService.getSpec().getStandard() != null && - authenticationService.getSpec().getStandard().getReplicas() != null) { - expectedMatches = authenticationService.getSpec().getStandard().getReplicas(); - } - int finalExpectedMatches = expectedMatches; - TestUtils.waitUntilCondition("Auth service is deployed: " + desiredPodName, phase -> { - List pods = TestUtils.listReadyPods(Kubernetes.getInstance(), authenticationService.getMetadata().getNamespace()); - long matching = pods.stream().filter(pod -> - pod.getMetadata().getName().contains(desiredPodName)).count(); - if (matching != finalExpectedMatches) { - List podNames = pods.stream().map(p -> p.getMetadata().getName()).collect(Collectors.toList()); - LOGGER.info("Still awaiting pod with name : {}, matching : {}, current pods {}", - desiredPodName, matching, podNames); - } - - return matching == finalExpectedMatches; - }, - new TimeoutBudget(5, TimeUnit.MINUTES)); - } - - public void removeAuthService(AuthenticationService authService) throws Exception { - Kubernetes.getInstance().getAuthenticationServiceClient(authService.getMetadata().getNamespace()) - .withName(authService.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitUntilCondition("Auth service is deleted: " + authService.getMetadata().getName(), (phase) -> - TestUtils.listReadyPods(Kubernetes.getInstance(), authService.getMetadata().getNamespace()).stream().noneMatch(pod -> - pod.getMetadata().getName().contains(authService.getMetadata().getName())), - new TimeoutBudget(1, TimeUnit.MINUTES)); - } - - public void createAddressSpace(AddressSpace addressSpace) throws Exception { - createAddressSpace(addressSpace, true); - } - - public void createAddressSpace(AddressSpace addressSpace, boolean waitUntilReady) throws Exception { - String operationID = TimeMeasuringSystem.startOperation(SystemtestsOperation.CREATE_ADDRESS_SPACE); - if (!AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - LOGGER.info("Address space '{}' doesn't exist and will be created.", addressSpace); - kubernetes.getAddressSpaceClient(addressSpace.getMetadata().getNamespace()).createOrReplace(addressSpace); - if (waitUntilReady) { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - } - } else { - if (waitUntilReady) { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - } - LOGGER.info("Address space '" + addressSpace + "' already exists."); - } - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - TimeMeasuringSystem.stopOperation(operationID); - } - - public void createAddressSpace(AddressSpace... addressSpaces) throws Exception { - String operationID = TimeMeasuringSystem.startOperation(SystemtestsOperation.CREATE_ADDRESS_SPACE); - for (AddressSpace addressSpace : addressSpaces) { - if (!AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - LOGGER.info("Address space '{}' doesn't exist and will be created.", addressSpace); - kubernetes.getAddressSpaceClient(addressSpace.getMetadata().getNamespace()).createOrReplace(addressSpace); - } else { - LOGGER.info("Address space '" + addressSpace + "' already exists."); - } - } - for (AddressSpace addressSpace : addressSpaces) { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - } - TimeMeasuringSystem.stopOperation(operationID); - } - - public void waitForAddressSpaceReady(AddressSpace addressSpace) throws Exception { - LOGGER.info("Waiting for address space ready"); - String operationID = TimeMeasuringSystem.startOperation(SystemtestsOperation.CREATE_ADDRESS_SPACE); - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - TimeMeasuringSystem.stopOperation(operationID); - } - - //------------------------------------------------------------------------------------------------ - // Address space methods - //------------------------------------------------------------------------------------------------ - - public void deleteAddressSpace(AddressSpace addressSpace) throws Exception { - if (AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - AddressSpaceUtils.deleteAddressSpaceAndWait(addressSpace, logCollector); - } else { - LOGGER.info("Address space '" + addressSpace.getMetadata().getName() + "' doesn't exists!"); - } - } - - public void deleteAddressSpaceWithoutWait(AddressSpace addressSpace) throws Exception { - if (AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - AddressSpaceUtils.deleteAddressSpace(addressSpace, logCollector); - } else { - LOGGER.info("Address space '" + addressSpace.getMetadata().getName() + "' doesn't exists!"); - } - } - - protected void createAddressSpaces(List addressSpaces, String operationID) throws Exception { - addressSpaces.forEach(addressSpace -> - kubernetes.getAddressSpaceClient(addressSpace.getMetadata().getNamespace()).createOrReplace(addressSpace)); - for (AddressSpace addressSpace : addressSpaces) { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - } - TimeMeasuringSystem.stopOperation(operationID); - } - - public void replaceAddressSpace(AddressSpace addressSpace, boolean waitForConfigApplied, TimeoutBudget waitBudget) throws Exception { - String operationID = TimeMeasuringSystem.startOperation(SystemtestsOperation.UPDATE_ADDRESS_SPACE); - var client = kubernetes.getAddressSpaceClient(addressSpace.getMetadata().getNamespace()); - if (AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - LOGGER.info("Address space '{}' exists and will be updated.", addressSpace); - final AddressSpace current = client.withName(addressSpace.getMetadata().getName()).get(); - final String currentResourceVersion = current.getMetadata().getResourceVersion(); - final String currentConfig = current.getAnnotation(AnnotationKeys.APPLIED_CONFIGURATION); - client.createOrReplace(addressSpace); - Thread.sleep(10_000); - TestUtils.waitForChangedResourceVersion(ofDuration(ofMinutes(5)), addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName(), currentResourceVersion); - if (waitForConfigApplied) { - AddressSpaceUtils.waitForAddressSpaceConfigurationApplied(addressSpace, currentConfig); - } - if (waitBudget == null) { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - } else { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace, waitBudget); - } - - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - currentAddressSpaces.add(addressSpace); - } else { - LOGGER.info("Address space '{}' does not exists.", addressSpace.getMetadata().getName()); - } - LOGGER.info("Address space updated: {}", addressSpace); - TimeMeasuringSystem.stopOperation(operationID); - } - - public AddressSpace getAddressSpace(String namespace, String addressSpaceName) { - return kubernetes.getAddressSpaceClient(namespace).withName(addressSpaceName).get(); - } - - public AddressSpace getAddressSpace(String addressSpaceName) { - return kubernetes.getAddressSpaceClient().withName(addressSpaceName).get(); - } - - - //================================================================================================ - //====================================== Address methods ========================================= - //================================================================================================ - - public void deleteAddresses(Address... destinations) { - logCollector.collectRouterState("deleteAddresses"); - AddressUtils.delete(destinations); - } - - public void deleteAddresses(AddressSpace addressSpace) throws Exception { - LOGGER.info("Addresses in " + addressSpace.getMetadata().getName() + " will be deleted!"); - logCollector.collectRouterState("deleteAddresses"); - AddressUtils.delete(addressSpace); - } - - - public void appendAddresses(Address... destinations) throws Exception { - TimeoutBudget budget = new TimeoutBudget(15, TimeUnit.MINUTES); - appendAddresses(budget, destinations); - } - - public void appendAddresses(TimeoutBudget timeout, Address... destinations) throws Exception { - appendAddresses(true, timeout, destinations); - } - - public void appendAddresses(boolean wait, Address... destinations) throws Exception { - TimeoutBudget budget = new TimeoutBudget(15, TimeUnit.MINUTES); - appendAddresses(wait, budget, destinations); - } - - private void appendAddresses(boolean wait, TimeoutBudget timeout, Address... destinations) throws Exception { - AddressUtils.appendAddresses(timeout, wait, destinations); - } - - public void setAddresses(TimeoutBudget budget, Address... addresses) throws Exception { - logCollector.collectRouterState("setAddresses"); - AddressUtils.setAddresses(budget, true, addresses); - } - - public void setAddresses(boolean wait, Address... addresses) throws Exception { - logCollector.collectRouterState("setAddresses"); - AddressUtils.setAddresses(null, wait, addresses); - } - - public void setAddresses(Address... addresses) throws Exception { - setAddresses(new TimeoutBudget(15, TimeUnit.MINUTES), addresses); - } - - public void replaceAddress(Address destination) throws Exception { - AddressUtils.replaceAddress(destination, true, new TimeoutBudget(10, TimeUnit.MINUTES)); - } - - public Address getAddress(String namespace, Address destination) { - return kubernetes.getAddressClient().inNamespace(namespace).withName(destination.getMetadata().getName()).get(); - } - - //================================================================================================ - //======================================= User methods =========================================== - //================================================================================================ - - public User createOrUpdateUser(AddressSpace addressSpace, UserCredentials credentials) throws Exception { - return createOrUpdateUser(addressSpace, credentials, true); - } - - public User createOrUpdateUser(AddressSpace addressSpace, UserCredentials credentials, boolean wait) throws Exception { - Objects.requireNonNull(addressSpace); - Objects.requireNonNull(credentials); - User user = new UserBuilder() - .withNewMetadata() - .withName(addressSpace.getMetadata().getName() + "." + credentials.getUsername()) - .endMetadata() - .withNewSpec() - .withUsername(credentials.getUsername()) - .withNewAuthentication() - .withType(UserAuthenticationType.password) - .withNewPassword(UserUtils.passwordToBase64(credentials.getPassword())) - .endAuthentication() - .addNewAuthorization() - .withAddresses("*") - .addToOperations(Operation.send) - .addToOperations(Operation.recv) - .endAuthorization() - .addNewAuthorization() - .addToOperations(Operation.manage) - .endAuthorization() - .endSpec() - .build(); - return createOrUpdateUser(addressSpace, user, wait); - } - - public User createOrUpdateUser(AddressSpace addressSpace, User user) throws Exception { - return createOrUpdateUser(addressSpace, user, true); - } - - public User createOrUpdateUser(AddressSpace addressSpace, User user, boolean wait) throws Exception { - if (user.getMetadata().getName() == null || !user.getMetadata().getName().contains(addressSpace.getMetadata().getName())) { - user.getMetadata().setName(addressSpace.getMetadata().getName() + "." + user.getSpec().getUsername()); - } - if (user.getMetadata().getNamespace() == null) { - user.getMetadata().setNamespace(addressSpace.getMetadata().getNamespace()); - } - LOGGER.info("User {} in address space {} will be created/replaced", user, addressSpace.getMetadata().getName()); - User existing = kubernetes.getUserClient(user.getMetadata().getNamespace()).withName(user.getMetadata().getName()).get(); - if (existing != null) { - existing.setSpec(user.getSpec()); - user = existing; - } - kubernetes.getUserClient(user.getMetadata().getNamespace()).createOrReplace(user); - if (wait) { - return UserUtils.waitForUserActive(user, new TimeoutBudget(1, TimeUnit.MINUTES)); - } - return kubernetes.getUserClient(user.getMetadata().getNamespace()).withName(user.getMetadata().getName()).get(); - } - - public User createUserServiceAccount(AddressSpace addressSpace, UserCredentials cred) throws Exception { - LOGGER.info("ServiceAccount user {} in address space {} will be created", cred.getUsername(), addressSpace.getMetadata().getName()); - String serviceaccountName = kubernetes.createServiceAccount(cred.getUsername(), addressSpace.getMetadata().getNamespace()); - User user = new UserBuilder() - .withNewMetadata() - .withName(String.format("%s.%s", addressSpace.getMetadata().getName(), - Pattern.compile(".*:").matcher(serviceaccountName).replaceAll(""))) - .endMetadata() - .withNewSpec() - .withUsername(serviceaccountName) - .withNewAuthentication() - .withType(UserAuthenticationType.serviceaccount) - .endAuthentication() - .addNewAuthorization() - .withAddresses("*") - .addToOperations(Operation.send) - .addToOperations(Operation.recv) - .endAuthorization() - .endSpec() - .build(); - return createOrUpdateUser(addressSpace, user); - } - - public void removeUser(AddressSpace addressSpace, User user) throws InterruptedException { - Objects.requireNonNull(addressSpace); - Objects.requireNonNull(user); - LOGGER.info("User {} in address space {} will be removed", user.getMetadata().getName(), addressSpace.getMetadata().getName()); - kubernetes.getUserClient(addressSpace.getMetadata().getNamespace()).withName(user.getMetadata().getName()).cascading(true).delete(); - UserUtils.waitForUserDeleted(user.getMetadata().getNamespace(), user.getMetadata().getName(), new TimeoutBudget(1, TimeUnit.MINUTES)); - } - - public void removeUser(AddressSpace addressSpace, String userName) throws InterruptedException { - Objects.requireNonNull(addressSpace); - LOGGER.info("User {} in address space {} will be removed", userName, addressSpace.getMetadata().getName()); - String name = String.format("%s.%s", addressSpace.getMetadata().getName(), userName); - kubernetes.getUserClient(addressSpace.getMetadata().getNamespace()).withName(name).cascading(true).delete(); - UserUtils.waitForUserDeleted(addressSpace.getMetadata().getNamespace(), name, new TimeoutBudget(1, TimeUnit.MINUTES)); - } - - public User getUser(AddressSpace addressSpace, String username) { - String id = String.format("%s.%s", addressSpace.getMetadata().getName(), username); - List response = kubernetes.getUserClient(addressSpace.getMetadata().getNamespace()).list().getItems(); - LOGGER.info("User list for {}: {}", addressSpace.getMetadata().getName(), response); - for (User user : response) { - if (user.getMetadata().getName().equals(id)) { - LOGGER.info("User {} in addressspace {} already exists", username, addressSpace.getMetadata().getName()); - return user; - } - } - return null; - } - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedIoTManager.java b/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedIoTManager.java deleted file mode 100644 index 8e282c6319f..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedIoTManager.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.manager; - -import static io.enmasse.systemtest.bases.iot.ITestIoTBase.IOT_PROJECT_NAMESPACE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newDefaultInstance; -import static io.enmasse.systemtest.utils.IoTUtils.createIoTConfig; -import static io.enmasse.systemtest.utils.IoTUtils.createIoTProject; - -import java.nio.file.Path; -import java.util.UUID; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; - - -public class SharedIoTManager extends ResourceManager { - - private static final Logger LOGGER = CustomLogger.getLogger(); - private static SharedIoTManager instance; - protected AmqpClientFactory amqpClientFactory = null; - private IoTProject sharedIoTProject = null; - private IoTConfig sharedIoTConfig = null; - private AmqpClient amqpClient; - - private SharedIoTManager() { - } - - public static synchronized SharedIoTManager getInstance() { - if (instance == null) { - instance = new SharedIoTManager(); - } - return instance; - } - - @Override - public AddressSpace getSharedAddressSpace() { - if (sharedIoTProject == null) { - return null; - } - String addSpaceName = sharedIoTProject.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(); - return kubernetes.getAddressSpaceClient(sharedIoTProject.getMetadata().getNamespace()).withName(addSpaceName).get(); - } - - @Override - public void tearDown(ExtensionContext context) throws Exception { - closeAmqpFactory(); - if (environment.skipCleanup()) { - LOGGER.info("Skip cleanup is set, no cleanup process"); - } else { - if (sharedIoTProject != null) { - LOGGER.info("Shared IoTProject will be removed"); - var iotProjectApiClient = kubernetes.getIoTProjectClient(sharedIoTProject.getMetadata().getNamespace()); - if (iotProjectApiClient.withName(sharedIoTProject.getMetadata().getName()).get() != null) { - IoTUtils.deleteIoTProjectAndWait(kubernetes, sharedIoTProject); - sharedIoTProject = null; - } else { - LOGGER.info("IoTProject '{}' doesn't exists!", sharedIoTProject.getMetadata().getName()); - } - } - tearDownSharedIoTConfig(); - if (context.getExecutionException().isPresent()) { - Path path = TestUtils.getFailedTestLogsPath(context); - SystemtestsKubernetesApps.collectInfinispanServerLogs(path); - } - SystemtestsKubernetesApps.deleteInfinispanServer(); - SystemtestsKubernetesApps.deletePostgresqlServer(); - SystemtestsKubernetesApps.deleteH2Server(); - } - } - - public void tearDownSharedIoTConfig() throws Exception { - if (sharedIoTConfig != null) { - LOGGER.info("Shared IoTConfig will be removed"); - var iotConfigApiClient = kubernetes.getIoTConfigClient(); - if (iotConfigApiClient.withName(sharedIoTConfig.getMetadata().getName()).get() != null) { - IoTUtils.deleteIoTConfigAndWait(kubernetes, sharedIoTConfig); - sharedIoTConfig = null; - } else { - LOGGER.info("IoTConfig '{}' doesn't exists!", sharedIoTConfig.getMetadata().getName()); - } - } - } - - void initFactories(UserCredentials credentials) { - amqpClientFactory = new AmqpClientFactory(getSharedAddressSpace(), credentials); - } - - @Override - public void setup() throws Exception { - kubernetes.createNamespace(IOT_PROJECT_NAMESPACE); - - UserCredentials credentials = new UserCredentials(UUID.randomUUID().toString(), UUID.randomUUID().toString()); - - if (sharedIoTConfig == null) { - createNewIoTConfig(); - } - - if (sharedIoTProject == null) { - sharedIoTProject = IoTUtils.getBasicIoTProjectObject("shared-iot-project", defaultAddSpaceIdentifier, IOT_PROJECT_NAMESPACE, addressSpacePlan); - createIoTProject(sharedIoTProject); - } - initFactories(credentials); - createOrUpdateUser(getSharedAddressSpace(), credentials); - this.amqpClient = amqpClientFactory.createQueueClient(); - } - - private void createNewIoTConfig() throws Exception { - sharedIoTConfig = IoTTestSession - .createDefaultConfig() - .editOrNewSpec().withServices(newDefaultInstance()).endSpec() - .build(); - - createIoTConfig(sharedIoTConfig); - } - - @Override - public AmqpClientFactory getAmqpClientFactory() { - return amqpClientFactory; - } - - @Override - public void setAmqpClientFactory(AmqpClientFactory amqpClientFactory) { - this.amqpClientFactory = amqpClientFactory; - } - - public IoTProject getSharedIoTProject() { - return sharedIoTProject; - } - - public IoTConfig getSharedIoTConfig() { - return sharedIoTConfig; - } - - public String getTenantId() { - return IoTUtils.getTenantId(sharedIoTProject); - } - - public AmqpClient getAmqpClient() { - return amqpClient; - } - - public void closeAmqpFactory() throws Exception { - if (amqpClientFactory != null) { - amqpClientFactory.close(); - amqpClientFactory = null; - } - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedResourceManager.java b/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedResourceManager.java deleted file mode 100644 index 8140c7157c1..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedResourceManager.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.manager; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceBuilder; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.Kubernetes; - -public class SharedResourceManager extends ResourceManager { - private static final Logger LOGGER = CustomLogger.getLogger(); - private static SharedResourceManager instance; - private static Map spaceCountMap = new HashMap<>(); - protected AmqpClientFactory amqpClientFactory = null; - private AddressSpace sharedAddressSpace = null; - private static final String DEFAULT_ADDRESS_TEMPLATE = "-shared-"; - private UserCredentials defaultCredentials = environment.getSharedDefaultCredentials(); - private UserCredentials managementCredentials = environment.getSharedManagementCredentials(); - - public static synchronized SharedResourceManager getInstance() { - if (instance == null) { - instance = new SharedResourceManager(); - } - return instance; - } - - @Override - public AddressSpace getSharedAddressSpace() { - return sharedAddressSpace; - } - - @Override - public void tearDown(ExtensionContext context) throws Exception { - if (context.getExecutionException().isPresent()) { //test failed - if (environment.skipCleanup()) { - LOGGER.warn("No address space is deleted, SKIP_CLEANUP is set"); - } else { - LOGGER.info(String.format("test failed: %s.%s", - context.getRequiredTestClass().getName(), - context.getRequiredTestMethod().getName())); - LOGGER.info("shared address space '{}' will be removed", sharedAddressSpace); - try { - if (sharedAddressSpace != null) { - super.deleteAddressSpace(sharedAddressSpace); - } - } catch (Exception ex) { - LOGGER.warn("Failed to delete shared address space (ignored)", ex); - } finally { - spaceCountMap.compute(defaultAddSpaceIdentifier, (k, count) -> count == null ? null : count + 1); - } - } - } else { //succeed - try { - if (environment.skipCleanup()) { - LOGGER.warn("No address space is deleted, SKIP_CLEANUP is set"); - } else { - LOGGER.info("Shared address space will be deleted!"); - super.deleteAddressSpace(sharedAddressSpace); - } - } catch (Exception e) { - LOGGER.warn("Failed to delete addresses from shared address space (ignored)", e); - } - } - closeClientFactories(amqpClientFactory); - amqpClientFactory = null; - sharedAddressSpace = null; - } - - void initFactories(AddressSpace addressSpace) { - amqpClientFactory = new AmqpClientFactory(sharedAddressSpace, defaultCredentials); - } - - @Override - public void setup() throws Exception { - LOGGER.info("Shared setup"); - if (spaceCountMap == null) { - spaceCountMap = new HashMap<>(); - } - spaceCountMap.putIfAbsent(defaultAddSpaceIdentifier, 0); - sharedAddressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName(defaultAddSpaceIdentifier + DEFAULT_ADDRESS_TEMPLATE + spaceCountMap.get(defaultAddSpaceIdentifier)) - .withNamespace(Kubernetes.getInstance().getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(addressSpaceType) - .withPlan(addressSpacePlan) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - createSharedAddressSpace(sharedAddressSpace); - createOrUpdateUser(sharedAddressSpace, managementCredentials); - createOrUpdateUser(sharedAddressSpace, defaultCredentials); - initFactories(sharedAddressSpace); - } - - public void createSharedAddressSpace(AddressSpace addressSpace) throws Exception { - super.createAddressSpace(addressSpace); - sharedAddressSpace = addressSpace; - } - - @Override - public void createAddressSpace(AddressSpace addressSpace) throws Exception { - super.createAddressSpace(addressSpace); - } - - public void tearDownShared() throws Exception { - LOGGER.info("Deleting addresses"); - deleteAddresses(sharedAddressSpace); - LOGGER.info("Closing clients"); - closeClientFactories(amqpClientFactory); - initFactories(sharedAddressSpace); - } - - @Override - public AmqpClientFactory getAmqpClientFactory() { - return amqpClientFactory; - } - - @Override - public void setAmqpClientFactory(AmqpClientFactory amqpClientFactory) { - this.amqpClientFactory = amqpClientFactory; - } - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/messaginginfra/ResourceManager.java b/systemtests/src/main/java/io/enmasse/systemtest/messaginginfra/ResourceManager.java index c9e47b8100e..14b6a2f8239 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/messaginginfra/ResourceManager.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/messaginginfra/ResourceManager.java @@ -142,9 +142,6 @@ public void setDefaultMessagingTenant(MessagingTenant tenant) { // Client factories //------------------------------------------------------------------------------------------------ - public void initFactories(AddressSpace addressSpace) { - amqpClientFactory = new AmqpClientFactory(addressSpace, environment.getSharedDefaultCredentials()); - } public void initFactories(AddressSpace addressSpace, UserCredentials cred) { amqpClientFactory = new AmqpClientFactory(addressSpace, cred); diff --git a/systemtests/src/main/java/io/enmasse/systemtest/operator/EnmasseOperatorManager.java b/systemtests/src/main/java/io/enmasse/systemtest/operator/EnmasseOperatorManager.java index 08ba9d557f5..0d401210177 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/operator/EnmasseOperatorManager.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/operator/EnmasseOperatorManager.java @@ -4,22 +4,6 @@ */ package io.enmasse.systemtest.operator; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static io.enmasse.systemtest.condition.OpenShiftVersion.OCP4; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.time.Duration; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -import org.slf4j.Logger; - import io.enmasse.admin.model.v1.ConsoleService; import io.enmasse.admin.model.v1.ConsoleServiceSpec; import io.enmasse.systemtest.Environment; @@ -33,8 +17,23 @@ import io.enmasse.systemtest.platform.OpenShift; import io.enmasse.systemtest.time.TimeoutBudget; import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.api.model.EnvVar; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; +import io.fabric8.kubernetes.api.model.EnvVar; +import org.slf4j.Logger; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.Duration; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import static io.enmasse.systemtest.condition.OpenShiftVersion.OCP4; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EnmasseOperatorManager { @@ -62,22 +61,12 @@ public OLMOperatorManager olm() { } public void installEnmasseBundle() throws Exception { - LOGGER.info("***********************************************************"); - LOGGER.info(" Enmasse operator install"); - LOGGER.info("***********************************************************"); - installOperators(); - installExamplesBundle(kube.getInfraNamespace()); - waitUntilOperatorReady(kube.getInfraNamespace()); - LOGGER.info("***********************************************************"); - } - - public void installEnmasseSharedInfraBundle() throws Exception { LOGGER.info("***********************************************************"); LOGGER.info(" Enmasse operator shared infra install"); LOGGER.info("***********************************************************"); generateTemplates(); kube.createNamespace(kube.getInfraNamespace(), Collections.singletonMap("allowed", "true")); - KubeCMDClient.applyFromFile(kube.getInfraNamespace(), Paths.get(Environment.getInstance().getTemplatesPath(), "install", "preview-bundles", "enmasse")); + KubeCMDClient.applyFromFile(kube.getInfraNamespace(), Paths.get(Environment.getInstance().getTemplatesPath(), "install", "preview-bundles", "enmasse")); //TODO change it once it will be moved TestUtils.waitUntilDeployed(kube.getInfraNamespace()); LOGGER.info("***********************************************************"); } @@ -437,8 +426,7 @@ private void awaitConsoleReadiness(String namespace) throws Exception { public boolean isEnmasseBundleDeployed() { return kube.namespaceExists(kube.getInfraNamespace()) - && kube.listPods(kube.getInfraNamespace()).stream().filter(pod -> pod.getMetadata().getName().contains("enmasse-operator")).count() == 1 - && kube.listPods(kube.getInfraNamespace()).stream().filter(pod -> pod.getMetadata().getName().contains("address-space-controller")).count() == 1; + && kube.listPods(kube.getInfraNamespace()).stream().filter(pod -> pod.getMetadata().getName().contains("enmasse-operator")).count() == 1; } public boolean isEnmasseOlmDeployed() { diff --git a/systemtests/src/main/java/io/enmasse/systemtest/platform/KubeCMDClient.java b/systemtests/src/main/java/io/enmasse/systemtest/platform/KubeCMDClient.java index 2430b17f0a1..5acab5f0c2e 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/platform/KubeCMDClient.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/platform/KubeCMDClient.java @@ -18,7 +18,6 @@ import java.util.Objects; import java.util.Optional; -import io.enmasse.systemtest.bases.ITestBase; import io.enmasse.systemtest.time.TimeoutBudget; import io.enmasse.systemtest.utils.TestUtils; import org.slf4j.Logger; @@ -419,13 +418,4 @@ public static ExecutionResultData runOnClusterWithoutLogger(String... args) { command.addAll(Arrays.asList(args)); return Exec.execute(command, ONE_MINUTE_TIMEOUT, false); } - - public static void awaitRollout(TimeoutBudget budget, String namespace, String deploymentName) { - TestUtils.waitUntilCondition(String.format("Wait for deployment %s in namespace %s rollout to complete", deploymentName, namespace), waitPhase -> { - ExecutionResultData rollout = Exec.execute(Arrays.asList(ITestBase.kubernetes.getCluster().getKubeCmd(), "rollout", - "status", "deployment", deploymentName, - "--namespace", namespace), true); - return rollout.getRetCode(); - }, budget); - } } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/resources/CliOutputData.java b/systemtests/src/main/java/io/enmasse/systemtest/resources/CliOutputData.java index 89e5685ab11..8b3726ebe69 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/resources/CliOutputData.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/resources/CliOutputData.java @@ -172,7 +172,7 @@ public static class AddressSpaceRow extends CliDataRow { private String phase; private String status; - AddressSpaceRow(String[] parsedData) { + public AddressSpaceRow(String[] parsedData) { expectColumns(7, parsedData); this.name = parsedData[0]; this.type = parsedData[1]; @@ -242,7 +242,7 @@ public static class AddressRow extends CliDataRow { private String phase; private String status; - AddressRow(String[] parsedData) { + public AddressRow(String[] parsedData) { expectColumns(8, parsedData); this.name = parsedData[0]; this.address = parsedData[1]; @@ -317,7 +317,7 @@ public static class UserRow extends CliDataRow { private String username; private String phase; - UserRow(String[] parsedData) { + public UserRow(String[] parsedData) { expectColumns(5, parsedData); this.name = parsedData[0]; this.username = parsedData[1]; diff --git a/systemtests/src/main/java/io/enmasse/systemtest/utils/UserUtils.java b/systemtests/src/main/java/io/enmasse/systemtest/utils/UserUtils.java index 21dd1738478..9739c209941 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/utils/UserUtils.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/utils/UserUtils.java @@ -5,13 +5,9 @@ package io.enmasse.systemtest.utils; import com.fasterxml.jackson.databind.ObjectMapper; -import io.enmasse.address.model.AddressSpace; import io.enmasse.address.model.Phase; import io.enmasse.systemtest.UserCredentials; import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.manager.IsolatedIoTManager; -import io.enmasse.systemtest.manager.IsolatedResourcesManager; -import io.enmasse.systemtest.manager.ResourceManager; import io.enmasse.systemtest.platform.Kubernetes; import io.enmasse.systemtest.time.TimeoutBudget; import io.enmasse.user.model.v1.DoneableUser; @@ -108,8 +104,4 @@ public static String base64ToPassword(String password) { public static UserCredentials getCredentialsFromUser(User user) { return new UserCredentials(user.getSpec().getUsername(), base64ToPassword(user.getSpec().getAuthentication().getPassword())); } - - public static boolean userExist(AddressSpace addressSpace, String username) { - return IsolatedResourcesManager.getInstance().getUser(addressSpace, username) != null; - } } diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/TestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/TestBase.java index bf5dedb2750..9600fccbf27 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/TestBase.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/bases/TestBase.java @@ -5,70 +5,25 @@ package io.enmasse.systemtest.bases; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import javax.jms.DeliveryMode; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Session; - -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.message.Message; -import org.eclipse.paho.client.mqttv3.IMqttClient; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.TestInstance; -import org.junit.jupiter.api.extension.ExtendWith; -import org.slf4j.Logger; - -import com.google.common.collect.Ordering; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressSpace; import io.enmasse.systemtest.Environment; import io.enmasse.systemtest.IndicativeSentences; +import io.enmasse.systemtest.TestTag; import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.info.TestInfo; +import io.enmasse.systemtest.clients.ClientUtils; import io.enmasse.systemtest.listener.JunitCallbackListener; -import io.enmasse.systemtest.logs.GlobalLogCollector; import io.enmasse.systemtest.messaginginfra.ResourceManager; -import io.enmasse.systemtest.mqtt.MqttUtils; import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.JmsProvider; -import io.enmasse.systemtest.utils.TestUtils; +import io.enmasse.systemtest.platform.Kubernetes; import io.enmasse.systemtest.utils.ThrowingCallable; import io.enmasse.systemtest.utils.ThrowingConsumer; -import io.enmasse.systemtest.utils.UserUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.UserAuthorizationBuilder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.LinkedList; +import java.util.List; /** * Base class for all tests @@ -76,23 +31,25 @@ @ExtendWith(JunitCallbackListener.class) @DisplayNameGeneration(IndicativeSentences.class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) -public abstract class TestBase implements ITestBase, ITestSeparator { +@Tag(TestTag.SYSTEMTEST) +public abstract class TestBase implements ITestSeparator { + ClientUtils clientUtils = new ClientUtils(); + protected static final Kubernetes kubernetes = Kubernetes.getInstance(); protected static final UserCredentials clusterUser = new UserCredentials(KubeCMDClient.getOCUser()); protected static final Environment environment = Environment.getInstance(); - protected static final GlobalLogCollector logCollector = new GlobalLogCollector(kubernetes, environment.testLogDir()); - protected io.enmasse.systemtest.manager.ResourceManager resourcesManager; - protected UserCredentials defaultCredentials = null; - protected UserCredentials managementCredentials = null; - protected ResourceManager infraResourceManager = ResourceManager.getInstance(); + protected UserCredentials defaultCredentials = environment.getDefaultCredentials(); + protected UserCredentials managementCredentials = environment.getManagementCredentials(); + protected ResourceManager resourceManager = ResourceManager.getInstance(); + protected List cleanup = new LinkedList<>(); /** * Close any provided resource at the end of test, by calling the cleaner. * - * @param The type of the closable. + * @param The type of the closable. * @param resource The closable to close. - * @param cleaner The cleaner, which will be called. + * @param cleaner The cleaner, which will be called. * @return The input value, for chained calls. */ protected T cleanup(final T resource, final ThrowingConsumer cleaner) { @@ -103,36 +60,16 @@ protected T cleanup(final T resource, final ThrowingConsumer cleaner) { /** * Close an {@link AutoCloseable} at the end of the test. * - * @param The type of the closable. + * @param The type of the closable. * @param closeable The closable to close. * @return The input value, for chained calls. */ - protected T cleanup (final T closeable) { + protected T cleanup(final T closeable) { return cleanup(closeable, AutoCloseable::close); } - @BeforeEach - public void initTest() throws Exception { - LOGGER.info("Test init"); - resourcesManager = getResourceManager(); - if (TestInfo.getInstance().isTestShared()) { - defaultCredentials = environment.getSharedDefaultCredentials(); - managementCredentials = environment.getSharedManagementCredentials(); - resourcesManager.setAddressSpacePlan(getDefaultAddressSpacePlan()); - resourcesManager.setAddressSpaceType(getAddressSpaceType().toString()); - resourcesManager.setDefaultAddSpaceIdentifier(getDefaultAddrSpaceIdentifier()); - if (resourcesManager.getSharedAddressSpace() == null) { - resourcesManager.setup(); - } - } else { - defaultCredentials = environment.getDefaultCredentials(); - managementCredentials = environment.getManagementCredentials(); - resourcesManager.setup(); - } - } - @AfterEach - private void cleanup() throws Exception { + void cleanup() throws Exception { Exception exception = null; for (ThrowingCallable cleanup : this.cleanup) { try { @@ -151,243 +88,7 @@ private void cleanup() throws Exception { } } - //================================================================================================ - //======================================= Help methods =========================================== - //================================================================================================ - - protected void waitForBrokerReplicas(AddressSpace addressSpace, Address destination, int expectedReplicas) throws - Exception { - TimeoutBudget budget = new TimeoutBudget(10, TimeUnit.MINUTES); - TestUtils.waitForNBrokerReplicas(addressSpace, expectedReplicas, true, destination, budget, 5000); - } - - protected void waitForRouterReplicas(AddressSpace addressSpace, int expectedReplicas) throws - Exception { - TimeoutBudget budget = new TimeoutBudget(3, TimeUnit.MINUTES); - Map labels = new HashMap<>(); - labels.put("name", "qdrouterd"); - labels.put("infraUuid", AddressSpaceUtils.getAddressSpaceInfraUuid(addressSpace)); - TestUtils.waitForNReplicas(expectedReplicas, kubernetes.getInfraNamespace(), labels, budget); - } - - protected void waitForPodsToTerminate(List uids) throws Exception { - LOGGER.info("Waiting for following pods to be deleted {}", uids); - assertWaitForValue(true, () -> (kubernetes.listPods(kubernetes.getInfraNamespace()).stream() - .noneMatch(pod -> uids.contains(pod.getMetadata().getUid()))), new TimeoutBudget(2, TimeUnit.MINUTES)); - } - - protected void logWithSeparator(Logger logger, String... messages) { - logger.info("--------------------------------------------------------------------------------"); - for (String message : messages) { - logger.info(message); - } - } - - protected List extractBodyAsString(Future> msgs) throws Exception { - return msgs.get(1, TimeUnit.MINUTES).stream().map(m -> (String) ((AmqpValue) m.getBody()).getValue()).collect(Collectors.toList()); - } - - //================================================================================================ - //==================================== Asserts methods =========================================== - //================================================================================================ - - protected static void assertSimpleMQTTSendReceive(Address dest, IMqttClient client, int msgCount) throws Exception { - List messages = IntStream.range(0, msgCount).boxed().map(i -> { - MqttMessage m = new MqttMessage(); - m.setPayload(String.format("mqtt-simple-send-receive-%s", i).getBytes(StandardCharsets.UTF_8)); - m.setQos(1); - return m; - }).collect(Collectors.toList()); - - List> receiveFutures = MqttUtils.subscribeAndReceiveMessages(client, dest.getSpec().getAddress(), messages.size(), 1); - List> publishFutures = MqttUtils.publish(client, dest.getSpec().getAddress(), messages); - - int publishCount = MqttUtils.awaitAndReturnCode(publishFutures, 1, TimeUnit.MINUTES); - assertThat("Incorrect count of messages published", - publishCount, is(messages.size())); - - int receivedCount = MqttUtils.awaitAndReturnCode(receiveFutures, 1, TimeUnit.MINUTES); - assertThat("Incorrect count of messages received", - receivedCount, is(messages.size())); - } - - protected > void assertSorted(String message, Iterable list) throws Exception { - assertSorted(message, list, false); - } - - protected void assertSorted(String message, Iterable list, Comparator comparator) throws Exception { - assertSorted(message, list, false, comparator); - } - - protected > void assertSorted(String message, Iterable list, boolean reverse) { - LOGGER.info("Assert sort reverse: " + reverse); - if (!reverse) { - assertTrue(Ordering.natural().isOrdered(list), message); - } else { - assertTrue(Ordering.natural().reverse().isOrdered(list), message); - } - } - - protected void assertSorted(String message, Iterable list, boolean reverse, Comparator comparator) { - LOGGER.info("Assert sort reverse: " + reverse); - if (!reverse) { - assertTrue(Ordering.from(comparator).isOrdered(list), message); - } else { - assertTrue(Ordering.from(comparator).reverse().isOrdered(list), message); - } - } - - protected void assertWaitForValue(T expected, Callable fn, TimeoutBudget budget) throws Exception { - T got = null; - LOGGER.info("waiting for expected value '{}' ...", expected); - while (budget.timeLeft() >= 0) { - got = fn.call(); - if (Objects.equals(expected, got)) { - return; - } - Thread.sleep(100); - } - fail(String.format("Incorrect result value! expected: '%s', got: '%s'", expected, Objects.requireNonNull(got))); - } - - protected static void assertDefaultEnabled(final Boolean enabled) { - if (enabled != null && !Boolean.TRUE.equals(enabled)) { - fail("Default value must be 'null' or 'true'"); - } - } - - protected void assertConcurentMessaging(List

dest, List users, String destNamePrefix, int customerIndex, int messageCount) throws Exception { - ArrayList clients = new ArrayList<>(users.size()); - String sufix = AddressSpaceUtils.isBrokered(resourcesManager.getSharedAddressSpace()) ? "#" : "*"; - users.forEach((user) -> { - try { - resourcesManager.createOrUpdateUser(resourcesManager.getSharedAddressSpace(), - UserUtils.createUserResource(user) - .editSpec() - .withAuthorization(Collections.singletonList( - new UserAuthorizationBuilder() - .withAddresses(String.format("%s.%s.%s", destNamePrefix, customerIndex, sufix)) - .withOperations(Operation.send, Operation.recv).build())) - .endSpec() - .done()); - AmqpClient queueClient = resourcesManager.getAmqpClientFactory().createQueueClient(); - queueClient.getConnectOptions().setCredentials(user); - clients.add(queueClient); - } catch (Exception e) { - e.printStackTrace(); - } - }); - - AddressUtils.waitForDestinationsReady(dest.toArray(new Address[0])); - //start sending messages - int everyN = 3; - for (AmqpClient client : clients) { - for (int i = 0; i < dest.size(); i++) { - if (i % everyN == 0) { - Future sent = client.sendMessages(dest.get(i).getSpec().getAddress(), TestUtils.generateMessages(messageCount)); - //wait for messages sent - assertEquals(messageCount, sent.get(1, TimeUnit.MINUTES), - "Incorrect count of messages send"); - } - } - } - - //receive messages - for (AmqpClient client : clients) { - for (int i = 0; i < dest.size(); i++) { - if (i % everyN == 0) { - Future> received = client.recvMessages(dest.get(i).getSpec().getAddress(), messageCount); - //wait for messages received - assertEquals(messageCount, received.get(1, TimeUnit.MINUTES).size(), - "Incorrect count of messages received"); - } - } - client.close(); - } - } - - protected void assertSendReceiveLargeMessageQueue(JmsProvider jmsProvider, double sizeInMB, Address dest, int count) throws Exception { - assertSendReceiveLargeMessageQueue(jmsProvider, sizeInMB, dest, count, DeliveryMode.NON_PERSISTENT); - } - - protected void assertSendReceiveLargeMessageQueue(JmsProvider jmsProvider, double sizeInMB, Address dest, int count, int mode) throws Exception { - int size = (int) (sizeInMB * 1024 * 1024); - - Session session = jmsProvider.getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); - javax.jms.Queue testQueue = (javax.jms.Queue) jmsProvider.getDestination(dest.getSpec().getAddress()); - List messages = jmsProvider.generateMessages(session, count, size); - - MessageProducer sender = session.createProducer(testQueue); - MessageConsumer receiver = session.createConsumer(testQueue); - - assertSendReceiveLargeMessage(jmsProvider, sender, receiver, sizeInMB, mode, count, messages); - - } - - protected void assertSendReceiveLargeMessageTopic(JmsProvider jmsProvider, double sizeInMB, Address dest, int count) throws Exception { - assertSendReceiveLargeMessageTopic(jmsProvider, sizeInMB, dest, count, DeliveryMode.NON_PERSISTENT); - } - - protected void assertSendReceiveLargeMessageTopic(JmsProvider jmsProvider, double sizeInMB, Address dest, int count, int mode) throws Exception { - int size = (int) (sizeInMB * 1024 * 1024); - - Session session = jmsProvider.getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); - javax.jms.Topic testTopic = (javax.jms.Topic) jmsProvider.getDestination(dest.getSpec().getAddress()); - List messages = jmsProvider.generateMessages(session, count, size); - - MessageProducer sender = session.createProducer(testTopic); - MessageConsumer receiver = session.createConsumer(testTopic); - - assertSendReceiveLargeMessage(jmsProvider, sender, receiver, sizeInMB, mode, count, messages); - session.close(); - sender.close(); - receiver.close(); - } - - private void assertSendReceiveLargeMessage(JmsProvider jmsProvider, MessageProducer sender, MessageConsumer receiver, double sizeInMB, int mode, int count, List messages) { - List recvd; - - jmsProvider.sendMessages(sender, messages, mode, javax.jms.Message.DEFAULT_PRIORITY, javax.jms.Message.DEFAULT_TIME_TO_LIVE); - LOGGER.info("{}MB {} message sent", sizeInMB, mode == DeliveryMode.PERSISTENT ? "durable" : "non-durable"); - - recvd = jmsProvider.receiveMessages(receiver, count, 2000); - assertThat("Wrong count of received messages", recvd.size(), Matchers.is(count)); - LOGGER.info("{}MB {} message received", sizeInMB, mode == DeliveryMode.PERSISTENT ? "durable" : "non-durable"); - } - - protected void assertAddressApi(AddressSpace addressSpace, Address d1, Address d2) throws Exception { - List destinationsNames = Arrays.asList(d1.getSpec().getAddress(), d2.getSpec().getAddress()); - resourcesManager.setAddresses(d1); - resourcesManager.appendAddresses(d2); - - //d1, d2 - List response = AddressUtils.getAddresses(addressSpace).stream().map(address -> address.getSpec().getAddress()).collect(Collectors.toList()); - assertThat("Rest api does not return all addresses", response, is(destinationsNames)); - LOGGER.info("addresses {} successfully created", Arrays.toString(destinationsNames.toArray())); - - //get specific address d2 - Address res = kubernetes.getAddressClient(addressSpace.getMetadata().getNamespace()).withName(d2.getMetadata().getName()).get(); - assertThat("Rest api does not return specific address", res.getSpec().getAddress(), is(d2.getSpec().getAddress())); - - resourcesManager.deleteAddresses(d1); - - //d2 - response = AddressUtils.getAddresses(addressSpace).stream().map(address -> address.getSpec().getAddress()).collect(Collectors.toList()); - assertThat("Rest api does not return right addresses", response, is(destinationsNames.subList(1, 2))); - LOGGER.info("address {} successfully deleted", d1.getSpec().getAddress()); - - resourcesManager.deleteAddresses(d2); - - //empty - List
listRes = AddressUtils.getAddresses(addressSpace); - assertThat("Rest api returns addresses", listRes, is(Collections.emptyList())); - LOGGER.info("addresses {} successfully deleted", d2.getSpec().getAddress()); - - resourcesManager.setAddresses(d1, d2); - resourcesManager.deleteAddresses(d1, d2); - - listRes = AddressUtils.getAddresses(addressSpace); - assertThat("Rest api returns addresses", listRes, is(Collections.emptyList())); - LOGGER.info("addresses {} successfully deleted", Arrays.toString(destinationsNames.toArray())); + protected ClientUtils getClientUtils() { + return clientUtils; } } diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/authz/AuthorizationTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/authz/AuthorizationTestBase.java deleted file mode 100644 index 1abcb750b99..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/authz/AuthorizationTestBase.java +++ /dev/null @@ -1,521 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.authz; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.UnauthorizedAccessException; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.shared.ITestBaseShared; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.UserUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserAuthorizationBuilder; -import io.vertx.proton.sasl.SaslSystemException; -import org.apache.qpid.proton.message.Message; -import org.slf4j.Logger; - -import javax.security.sasl.AuthenticationException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class AuthorizationTestBase extends TestBase implements ITestBaseShared { - - private static Logger log = CustomLogger.getLogger(); - - private Address queue; - private Address topic; - private Address anycast; - private Address multicast; - private List
addresses; - - private void initAddresses() throws Exception { - queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "authz_queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("authz_queue") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "authz-topic")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("authz-topic") - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - - anycast = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "authz-anycast")) - .endMetadata() - .withNewSpec() - .withType("anycast") - .withAddress("authz-anycast") - .withPlan(DestinationPlan.STANDARD_SMALL_ANYCAST) - .endSpec() - .build(); - - multicast = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "authz-multicast")) - .endMetadata() - .withNewSpec() - .withType("multicast") - .withAddress("authz-multicast") - .withPlan(DestinationPlan.STANDARD_SMALL_MULTICAST) - .endSpec() - .build(); - - addresses = new ArrayList<>(); - addresses.add(queue); - addresses.add(topic); - if (getAddressSpaceType() == AddressSpaceType.STANDARD) { - addresses.add(anycast); - addresses.add(multicast); - } - resourcesManager.setAddresses(addresses.toArray(new Address[0])); - } - - protected void doTestSendAuthz() throws Exception { - initAddresses(); - UserCredentials allowedUser = new UserCredentials("sender", "senderPa55"); - UserCredentials noAllowedUser = new UserCredentials("notallowedsender", "nobodyPa55"); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(allowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder().withAddresses("*").withOperations(Operation.send).build())) - .endSpec() - .done()); - Thread.sleep(100); - assertSend(allowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), allowedUser.getUsername()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(allowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses(addresses.stream().map(address -> address.getSpec().getAddress()).collect(Collectors.toList())) - .withOperations(Operation.send).build())) - .endSpec() - .done()); - Thread.sleep(100); - assertSend(allowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), allowedUser.getUsername()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(noAllowedUser).done()); - assertCannotSend(noAllowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), noAllowedUser.getUsername()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(noAllowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("*") - .withOperations(Operation.recv).build())) - .endSpec() - .done()); - assertCannotSend(noAllowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), noAllowedUser.getUsername()); - } - - protected void doTestReceiveAuthz() throws Exception { - initAddresses(); - UserCredentials allowedUser = new UserCredentials("receiver", "receiverPa55"); - UserCredentials noAllowedUser = new UserCredentials("notallowedreceiver", "nobodyPa55"); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(allowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder().withAddresses("*").withOperations(Operation.recv).build())) - .endSpec() - .done()); - assertReceive(allowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), allowedUser.getUsername()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(allowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses(addresses.stream().map(address -> address.getSpec().getAddress()).collect(Collectors.toList())) - .withOperations(Operation.recv).build())) - .endSpec() - .done()); - assertReceive(allowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), allowedUser.getUsername()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(noAllowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("*") - .withOperations(Operation.send).build())) - .endSpec() - .done()); - assertCannotReceive(noAllowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), noAllowedUser.getUsername()); - } - - protected void doTestUserPermissionAfterRemoveAuthz() throws Exception { - initAddresses(); - UserCredentials user = new UserCredentials("pepa", "pepaPa55"); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(user) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withOperations(Operation.recv) - .withAddresses("*").build())) - .endSpec() - .done()); - assertReceive(user); - resourcesManager.removeUser(getSharedAddressSpace(), user.getUsername()); - Thread.sleep(5000); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(user) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withOperations(Operation.recv) - .withAddresses("pepa_address").build())) - .endSpec() - .done()); - assertCannotReceive(user); - resourcesManager.removeUser(getSharedAddressSpace(), user.getUsername()); - } - - protected void doTestSendAuthzWithWIldcards() throws Exception { - List
addresses = getAddressesWildcard(getSharedAddressSpace()); - List users = createUsersWildcard(getSharedAddressSpace(), Operation.send); - - resourcesManager.setAddresses(addresses.toArray(new Address[0])); - - for (User user : users) { - for (Address destination : addresses) { - assertSendWildcard(user, destination); - } - resourcesManager.removeUser(getSharedAddressSpace(), user.getSpec().getUsername()); - } - } - - protected void doTestReceiveAuthzWithWIldcards() throws Exception { - List
addresses = getAddressesWildcard(getSharedAddressSpace()); - List users = createUsersWildcard(getSharedAddressSpace(), Operation.recv); - - resourcesManager.setAddresses(addresses.toArray(new Address[0])); - - for (User user : users) { - for (Address destination : addresses) { - assertReceiveWildcard(user, destination); - } - resourcesManager.removeUser(getSharedAddressSpace(), user.getSpec().getUsername()); - } - } - - //=========================================================================================================== - // Help methods - //=========================================================================================================== - - private void assertSendWildcard(User user, Address destination) throws Exception { - List addresses = user.getSpec().getAuthorization().stream() - .map(authz -> authz.getAddresses().stream()) - .flatMap(Stream::distinct) - .collect(Collectors.toList()); - - UserCredentials credentials = UserUtils.getCredentialsFromUser(user); - if (addresses.stream().filter(address -> destination.getSpec().getAddress().contains(address.replace("*", ""))).count() > 0) { - assertTrue(canSend(destination, credentials), - String.format("Authz failed, user %s cannot send message to destination %s", credentials, - destination.getSpec().getAddress())); - } else { - assertFalse(canSend(destination, credentials), - String.format("Authz failed, user %s can send message to destination %s", credentials, - destination.getSpec().getAddress())); - } - } - - private void assertReceiveWildcard(User user, Address destination) throws Exception { - List addresses = user.getSpec().getAuthorization().stream() - .map(authz -> authz.getAddresses().stream()) - .flatMap(Stream::distinct) - .collect(Collectors.toList()); - - UserCredentials credentials = UserUtils.getCredentialsFromUser(user); - if (addresses.stream().filter(address -> destination.getSpec().getAddress().contains(address.replace("*", ""))).count() > 0) { - assertTrue(canReceive(destination, credentials), - String.format("Authz failed, user %s cannot receive message from destination %s", credentials, - destination.getSpec().getAddress())); - } else { - assertFalse(canReceive(destination, credentials), - String.format("Authz failed, user %s can receive message from destination %s", credentials, - destination.getSpec().getAddress())); - } - } - - private void assertSend(UserCredentials credentials) throws Exception { - log.info("Testing if client is authorized to send messages"); - String message = String.format("Authz failed, user %s cannot send message", credentials); - assertTrue(canSend(queue, credentials), message); - assertTrue(canSend(topic, credentials), message); - - if (getAddressSpaceType() == AddressSpaceType.STANDARD) { - assertTrue(canSend(multicast, credentials), message); - assertTrue(canSend(anycast, credentials), message); - } - } - - private void assertCannotSend(UserCredentials credentials) throws Exception { - log.info("Testing if client is NOT authorized to send messages"); - String message = String.format("Authz failed, user %s can send message", credentials); - assertFalse(canSend(queue, credentials), message); - assertFalse(canSend(topic, credentials), message); - - if (getAddressSpaceType() == AddressSpaceType.STANDARD) { - assertFalse(canSend(multicast, credentials), message); - assertFalse(canSend(anycast, credentials), message); - } - } - - private void assertReceive(UserCredentials credentials) throws Exception { - log.info("Testing if client is authorized to receive messages"); - String message = String.format("Authz failed, user %s cannot receive message", credentials); - assertTrue(canReceive(queue, credentials), message); - assertTrue(canReceive(topic, credentials), message); - - if (getAddressSpaceType() == AddressSpaceType.STANDARD) { - assertTrue(canReceive(multicast, credentials), message); - assertTrue(canReceive(anycast, credentials), message); - } - } - - private void assertCannotReceive(UserCredentials credentials) throws Exception { - log.info("Testing if client is NOT authorized to receive messages"); - String message = String.format("Authz failed, user %s can receive message", credentials); - assertFalse(canReceive(queue, credentials), message); - assertFalse(canReceive(topic, credentials), message); - - if (getAddressSpaceType() == AddressSpaceType.STANDARD) { - assertFalse(canReceive(multicast, credentials), message); - assertFalse(canReceive(anycast, credentials), message); - } - } - - private boolean canSend(Address destination, UserCredentials credentials) throws Exception { - logWithSeparator(log, - String.format("Try send message under user %s from %s %s", credentials, destination.getSpec().getType(), destination.getSpec().getAddress()), - String.format("***** Try to open sender client under user %s", credentials), - String.format("***** Try to open receiver client under user %s", defaultCredentials)); - AmqpClient sender = createClient(destination, credentials); - AmqpClient receiver = createClient(destination, defaultCredentials); - logWithSeparator(log); - return canAuth(sender, receiver, destination, true); - } - - private boolean canReceive(Address destination, UserCredentials credentials) throws Exception { - logWithSeparator(log, - String.format("Try receive message under user %s from %s %s", credentials, destination.getSpec().getType(), destination.getSpec().getAddress()), - String.format("***** Try to open sender client under user %s", defaultCredentials), - String.format("***** Try to open receiver client under user %s", credentials)); - - AmqpClient sender = createClient(destination, defaultCredentials); - AmqpClient receiver = createClient(destination, credentials); - logWithSeparator(log); - return canAuth(sender, receiver, destination, false); - } - - private boolean canAuth(AmqpClient sender, AmqpClient receiver, Address destination, boolean checkSender) throws Exception { - try { - log.info("Staring receiver for " + destination.getSpec().getAddress()); - Future> received = receiver.recvMessages(destination.getSpec().getAddress(), 1); - - log.info("Staring sender for " + destination.getSpec().getAddress()); - Future sent = sender.sendMessages(destination.getSpec().getAddress(), Collections.singletonList("msg1")); - - if (checkSender) { - int numSent = sent.get(1, TimeUnit.MINUTES); - log.info("Sent {}", numSent); - int numReceived = received.get(1, TimeUnit.MINUTES).size(); - return numSent == numReceived; - } else { - int numReceived = received.get(1, TimeUnit.MINUTES).size(); - int numSent = sent.get(1, TimeUnit.MINUTES); - return numSent == numReceived; - } - } catch (ExecutionException | SecurityException | UnauthorizedAccessException ex) { - Throwable cause = ex; - if (ex instanceof ExecutionException) { - cause = ex.getCause(); - } - - if (cause instanceof SecurityException || cause instanceof SaslSystemException || cause instanceof AuthenticationException || cause instanceof UnauthorizedAccessException) { - log.info("canAuth {} ({}): {}", destination.getSpec().getAddress(), destination.getSpec().getType(), ex.getMessage()); - return false; - } else { - log.warn("canAuth {} ({}) exception", destination.getSpec().getAddress(), destination.getSpec().getType(), ex); - throw ex; - } - } finally { - sender.close(); - receiver.close(); - } - } - - private AmqpClient createClient(Address dest, UserCredentials credentials) throws Exception { - AmqpClient client = null; - - switch (dest.getSpec().getType()) { - case "queue": - case "anycast": - client = getAmqpClientFactory().createQueueClient(getSharedAddressSpace()); - break; - case "topic": - client = getAmqpClientFactory().createTopicClient(getSharedAddressSpace()); - break; - case "multicast": - client = getAmqpClientFactory().createBroadcastClient(getSharedAddressSpace()); - break; - } - - Objects.requireNonNull(client).getConnectOptions().setCredentials(credentials); - return client; - } - - protected List
getAddressesWildcard(AddressSpace addressspace) { - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, "queue/1234")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue/1234") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - Address queue2 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, "queue/ABCD")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue/ABCD") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - Address topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, "topic/2345")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("topic/2345") - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - - Address topic2 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, "topic/ABCD")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("topic/ABCD") - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - - return Arrays.asList(queue, queue2, topic, topic2); - } - - protected List createUsersWildcard(AddressSpace addressSpace, Operation operation) throws - Exception { - List users = new ArrayList<>(); - users.add(UserUtils.createUserResource(new UserCredentials("user1", "password")) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("*") - .withOperations(operation) - .build())) - .endSpec() - .done()); - - users.add(UserUtils.createUserResource(new UserCredentials("user2", "password")) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("queue/*") - .withOperations(operation) - .build())) - .endSpec() - .done()); - - users.add(UserUtils.createUserResource(new UserCredentials("user3", "password")) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("topic/*") - .withOperations(operation) - .build())) - .endSpec() - .done()); - - users.add(UserUtils.createUserResource(new UserCredentials("user4", "password")) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("queueA*") - .withOperations(operation) - .build())) - .endSpec() - .done()); - - users.add(UserUtils.createUserResource(new UserCredentials("user5", "password")) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("topicA*") - .withOperations(operation) - .build())) - .endSpec() - .done()); - - for (User user : users) { - resourcesManager.createOrUpdateUser(addressSpace, user); - } - return users; - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/bridging/BridgingBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/bridging/BridgingBase.java deleted file mode 100644 index 9907442bd60..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/bridging/BridgingBase.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.bridging; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceBuilder; -import io.enmasse.address.model.AddressSpaceSpecConnectorAddressRuleBuilder; -import io.enmasse.address.model.AddressSpaceSpecConnectorBuilder; -import io.enmasse.address.model.AddressSpaceSpecConnectorCredentials; -import io.enmasse.address.model.AddressSpaceSpecConnectorCredentialsBuilder; -import io.enmasse.address.model.AddressSpaceSpecConnectorEndpointBuilder; -import io.enmasse.address.model.AddressSpaceSpecConnectorTls; -import io.enmasse.address.model.AddressSpaceSpecConnectorTlsBuilder; -import io.enmasse.address.model.StringOrSecretSelectorBuilder; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.AmqpConnectOptions; -import io.enmasse.systemtest.amqp.QueueTerminusFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.isolated.ITestIsolatedStandard; -import io.enmasse.systemtest.certs.BrokerCertBundle; -import io.enmasse.systemtest.certs.openssl.OpenSSLUtil; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.messagingclients.AbstractClient; -import io.enmasse.systemtest.messagingclients.ClientArgument; -import io.enmasse.systemtest.messagingclients.ExternalMessagingClient; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder; -import io.vertx.proton.ProtonClientOptions; -import io.vertx.proton.ProtonQoS; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import java.nio.file.Path; -import java.util.Base64; - -public abstract class BridgingBase extends TestBase implements ITestIsolatedStandard { - - private static Logger log = CustomLogger.getLogger(); - - protected static final String REMOTE_NAME = "remote1"; - - protected final String remoteBrokerName = "amq-broker"; - protected final String remoteBrokerNamespace = "systemtests-external-broker"; - protected final String remoteBrokerUsername = "test-user"; - protected final String remoteBrokerPassword = "test-password"; - protected Endpoint clientBrokerEndpoint; - protected Endpoint clientBrokerEndpointExternal; - protected Endpoint remoteBrokerEndpoint; - protected Endpoint remoteBrokerEndpointSSL; - protected Endpoint remoteBrokerEndpointMutualTLS; - protected BrokerCertBundle certBundle; - - @BeforeEach - void deployBroker() throws Exception { - String serviceName = String.format("%s.%s.svc.cluster.local", remoteBrokerName, remoteBrokerNamespace); - certBundle = OpenSSLUtil.createBrokerCertBundle(serviceName); - SystemtestsKubernetesApps.deployAMQBroker(remoteBrokerNamespace, remoteBrokerName, remoteBrokerUsername, remoteBrokerPassword, certBundle); - remoteBrokerEndpoint = new Endpoint(serviceName, 5672); - remoteBrokerEndpointSSL = new Endpoint(serviceName, 5671); - remoteBrokerEndpointMutualTLS = new Endpoint(serviceName, 55671); - clientBrokerEndpointExternal = Kubernetes.getInstance().getExternalEndpoint(remoteBrokerName, remoteBrokerNamespace); - clientBrokerEndpoint = remoteBrokerEndpoint; - log.info("Broker endpoint: {}", remoteBrokerEndpoint); - log.info("Broker SSL endpoint: {}", remoteBrokerEndpointSSL); - log.info("Client broker endpoint: {}", clientBrokerEndpoint); - } - - @AfterEach - void undeployBroker(ExtensionContext context) throws Exception { - if (context.getExecutionException().isPresent()) { //test failed - Path path = TestUtils.getFailedTestLogsPath(context); - SystemtestsKubernetesApps.collectAMQBrokerLogs(path, remoteBrokerNamespace); - } - SystemtestsKubernetesApps.deleteAMQBroker(remoteBrokerNamespace, remoteBrokerName); - } - - protected void scaleDownBroker() throws Exception { - log.info("Scaling down broker"); - SystemtestsKubernetesApps.scaleDownDeployment(remoteBrokerNamespace, remoteBrokerName); - } - - protected void scaleUpBroker() throws Exception { - log.info("Scaling up broker"); - SystemtestsKubernetesApps.scaleUpDeployment(remoteBrokerNamespace, remoteBrokerName); - } - - protected AddressSpace createAddressSpace(String name, String addressRule, AddressSpaceSpecConnectorTls tlsSettings, AddressSpaceSpecConnectorCredentials credentials) throws Exception { - var endpoint = tlsSettings != null ? tlsSettings.getClientCert() != null ? remoteBrokerEndpointMutualTLS : remoteBrokerEndpointSSL : remoteBrokerEndpoint; - var connectorBuilder = new AddressSpaceSpecConnectorBuilder() - .withName(REMOTE_NAME) - .addToEndpointHosts(new AddressSpaceSpecConnectorEndpointBuilder() - .withHost(endpoint.getHost()) - .withPort(endpoint.getPort()) - .build()) - .addToAddresses(new AddressSpaceSpecConnectorAddressRuleBuilder() - .withName("queuesrule") - .withPattern(addressRule) - .build()); - - if (tlsSettings != null) { - connectorBuilder.withTls(tlsSettings); - } - - //only set credentials when mutual tls isn't configured - if (tlsSettings == null || tlsSettings.getClientCert() == null) { - if (credentials == null) { - Assertions.fail("Connector wrongly configured, missing connector credentials"); - } - connectorBuilder.withCredentials(credentials); - } - - AddressSpace space = new AddressSpaceBuilder() - .withNewMetadata() - .withNamespace(remoteBrokerNamespace) - .withName(name) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withConnectors(connectorBuilder.build()) - .endSpec() - .build(); - resourcesManager.createAddressSpace(space); - AddressSpaceUtils.waitForAddressSpaceConnectorsReady(space); - return space; - } - - protected AmqpClient createClientToRemoteBroker() { - ProtonClientOptions clientOptions = new ProtonClientOptions(); - clientOptions.setSsl(true); - clientOptions.setTrustAll(true); - clientOptions.setHostnameVerificationAlgorithm(""); - - AmqpConnectOptions connectOptions = new AmqpConnectOptions() - .setTerminusFactory(new QueueTerminusFactory()) - .setEndpoint(clientBrokerEndpointExternal) - .setProtonClientOptions(clientOptions) - .setQos(ProtonQoS.AT_LEAST_ONCE) - .setUsername(remoteBrokerUsername) - .setPassword(remoteBrokerPassword); - return getAmqpClientFactory().createClient(connectOptions); - } - - protected ExternalMessagingClient createOnClusterClientToRemoteBroker(AbstractClient client, int messageCount) { - return new ExternalMessagingClient(false) - .withMessagingRoute(clientBrokerEndpoint) - .withMessageBody("msg no. %d") - .withCount(messageCount) - .withClientEngine(client) - .withAdditionalArgument(ClientArgument.CONN_AUTH_MECHANISM, "PLAIN") - .withCredentials(remoteBrokerUsername, remoteBrokerPassword); - } - - protected AddressSpaceSpecConnectorCredentials defaultCredentials() { - return new AddressSpaceSpecConnectorCredentialsBuilder() - .withNewUsername() - .withValue(remoteBrokerUsername) - .endUsername() - .withNewPassword() - .withValue(remoteBrokerPassword) - .endPassword() - .build(); - } - - protected AddressSpaceSpecConnectorCredentials credentialsInSecret() { - return new AddressSpaceSpecConnectorCredentialsBuilder() - .withNewUsername() - .withValueFromSecret(new SecretKeySelectorBuilder() - .withName(remoteBrokerName) - .withKey("user") - .build()) - .endUsername() - .withNewPassword() - .withValueFromSecret(new SecretKeySelectorBuilder() - .withName(remoteBrokerName) - .withKey("password") - .build()) - .endPassword() - .build(); - } - - protected AddressSpaceSpecConnectorTls defaultTls() { - return new AddressSpaceSpecConnectorTlsBuilder() - .withCaCert(new StringOrSecretSelectorBuilder() - .withValue(Base64.getEncoder().encodeToString(certBundle.getCaCert())) - .build()) - .build(); - } - - protected AddressSpaceSpecConnectorTls tlsInSecret() { - return new AddressSpaceSpecConnectorTlsBuilder() - .withCaCert(new StringOrSecretSelectorBuilder() - .withValueFromSecret(new SecretKeySelectorBuilder() - .withName(remoteBrokerName) - .withKey("ca.crt") - .build()) - .build()) - .build(); - } - - protected AddressSpaceSpecConnectorTls defaultMutualTls() { - return new AddressSpaceSpecConnectorTlsBuilder() - .withCaCert(new StringOrSecretSelectorBuilder() - .withValue(Base64.getEncoder().encodeToString(certBundle.getCaCert())) - .build()) - .withClientCert(new StringOrSecretSelectorBuilder() - .withValue(Base64.getEncoder().encodeToString(certBundle.getClientCert())) - .build()) - .withClientKey(new StringOrSecretSelectorBuilder() - .withValue(Base64.getEncoder().encodeToString(certBundle.getClientKey())) - .build()) - .build(); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClientTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClientTestBase.java deleted file mode 100644 index 531d19ec96c..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClientTestBase.java +++ /dev/null @@ -1,591 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.clients; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.shared.ITestBaseShared; -import io.enmasse.systemtest.messagingclients.AbstractClient; -import io.enmasse.systemtest.messagingclients.ClientArgument; -import io.enmasse.systemtest.messagingclients.ClientType; -import io.enmasse.systemtest.annotations.ExternalClients; -import io.enmasse.systemtest.messagingclients.ExternalMessagingClient; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.UserUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserAuthorizationBuilder; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.TestInfo; -import org.junit.jupiter.api.function.Executable; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -@ExternalClients -public abstract class ClientTestBase extends TestBase implements ITestBaseShared { - protected Path logPath = null; - private List clients; - - @BeforeEach - public void setUpClientBase(TestInfo info) { - clients = new ArrayList<>(); - String clientFolder = "clients_tests"; - logPath = environment.testLogDir().resolve( - Paths.get( - clientFolder, - info.getTestClass().get().getName(), - info.getDisplayName())); - } - - @AfterEach - public void teardownClient() { - if (clients != null) { - clients.forEach(AbstractClient::stop); - clients.clear(); - } - } - - private Endpoint getMessagingRoute(AddressSpace addressSpace, boolean websocket) throws Exception { - return websocket ? AddressSpaceUtils.getMessagingWssRoute(addressSpace) : AddressSpaceUtils.getMessagingRoute(addressSpace); - } - - protected void doBasicMessageTest(AbstractClient sender, AbstractClient receiver) throws Exception { - doBasicMessageTest(sender, receiver, false); - } - - protected void doBasicMessageTest(AbstractClient sender, AbstractClient receiver, boolean websocket) throws Exception { - clients.addAll(Arrays.asList(sender, receiver)); - int expectedMsgCount = 10; - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "message-basic" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("message-basic" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), websocket)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET, websocket) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET_PROTOCOLS, getSharedAddressSpace().getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? "binary" : "") - .withAdditionalArgument(ClientArgument.DEST_TYPE, "ANYCAST"); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), websocket)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withTimeout(30) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET, websocket) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET_PROTOCOLS, getSharedAddressSpace().getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? "binary" : "") - .withAdditionalArgument(ClientArgument.DEST_TYPE, "ANYCAST"); - - - assertTrue(senderClient.run(), "Sender failed, expected return code 0"); - assertTrue(receiverClient.run(), "Receiver failed, expected return code 0"); - - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount)); - } - - protected void doRoundRobinReceiverTest(AbstractClient sender, AbstractClient receiver, AbstractClient receiver2) - throws Exception { - clients.addAll(Arrays.asList(sender, receiver, receiver2)); - int expectedMsgCount = 10; - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "round-robin" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("round-robin" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30); - - ExternalMessagingClient receiverClient1 = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount / 2) - .withTimeout(250); - - ExternalMessagingClient receiverClient2 = new ExternalMessagingClient() - .withClientEngine(receiver2) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount / 2) - .withTimeout(250); - - Future recResult = receiverClient1.runAsync(); - Future rec2Result = receiverClient2.runAsync(); - - receiverClient1.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - receiverClient2.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - - assertTrue(senderClient.run(), "Sender failed, expected return code 0"); - assertTrue(recResult.get(), "Receiver failed, expected return code 0"); - assertTrue(rec2Result.get(), "Receiver failed, expected return code 0"); - - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - - assertAll( - () -> assertEquals(expectedMsgCount / 2, receiverClient1.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount / 2)), - () -> assertEquals(expectedMsgCount / 2, receiverClient2.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount / 2))); - } - - protected void doTopicSubscribeTest(AbstractClient sender, AbstractClient subscriber, AbstractClient subscriber2) throws Exception { - clients.addAll(Arrays.asList(sender, subscriber, subscriber2)); - int expectedMsgCount = 10; - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "topic-sub" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("topic-sub" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30) - .withAdditionalArgument(ClientArgument.DEST_TYPE, "MULTICAST"); - - ExternalMessagingClient receiverClient1 = new ExternalMessagingClient() - .withClientEngine(subscriber) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withTimeout(250) - .withAdditionalArgument(ClientArgument.DEST_TYPE, "MULTICAST"); - - ExternalMessagingClient receiverClient2 = new ExternalMessagingClient() - .withClientEngine(subscriber2) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withTimeout(250) - .withAdditionalArgument(ClientArgument.DEST_TYPE, "MULTICAST"); - - Future recResult = receiverClient1.runAsync(); - Future recResult2 = receiverClient2.runAsync(); - - receiverClient1.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - receiverClient2.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - - assertAll( - () -> assertTrue(senderClient.run(), "Producer failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount))); - assertAll( - () -> assertTrue(recResult.get(), "Subscriber failed, expected return code 0"), - () -> assertTrue(recResult2.get(), "Subscriber failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, receiverClient1.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount)), - () -> assertEquals(expectedMsgCount, receiverClient2.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount))); - } - - protected void doMessageBrowseTest(AbstractClient sender, AbstractClient receiver_browse, AbstractClient receiver_receive) - throws Exception { - clients.addAll(Arrays.asList(sender, receiver_browse, receiver_receive)); - int expectedMsgCount = 10; - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "browse" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("browse" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d"); - - ExternalMessagingClient receiverClientBrowse = new ExternalMessagingClient() - .withClientEngine(receiver_browse) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withAdditionalArgument(ClientArgument.RECV_BROWSE, "true"); - - ExternalMessagingClient receiverClientReceive = new ExternalMessagingClient() - .withClientEngine(receiver_receive) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withAdditionalArgument(ClientArgument.RECV_BROWSE, "false"); - - assertAll( - () -> assertTrue(senderClient.run(), "Sender failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount))); - assertAll( - () -> assertTrue(receiverClientBrowse.run(), "Browse receiver failed, expected return code 0"), - () -> assertTrue(receiverClientReceive.run(), "Receiver failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, receiverClientBrowse.getMessages().size(), - String.format("Expected %d browsed messages", expectedMsgCount)), - () -> assertEquals(expectedMsgCount, receiverClientReceive.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount))); - } - - protected void doDrainQueueTest(AbstractClient sender, AbstractClient receiver) throws Exception { - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "drain" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("drain" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - clients.addAll(Arrays.asList(sender, receiver)); - int expectedMsgCount = 50; - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d"); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(0) - .withTimeout(10); - - assertTrue(senderClient.run(), "Sender failed, expected return code 0"); - assertTrue(receiverClient.run(), "Drain receiver failed, expected return code 0"); - - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount)); - } - - protected void doMessageSelectorQueueTest(AbstractClient sender, AbstractClient receiver) throws Exception { - int expectedMsgCount = 10; - - clients.addAll(Arrays.asList(sender, receiver)); - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "selector-queue" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("selector-queue" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(queue); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(expectedMsgCount) - .withAddress(queue) - .withCredentials(defaultCredentials) - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "colour~red") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "number~12.65") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "a~true") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "b~false") - .withMessageBody("msg no. %d"); - - //send messages - assertTrue(senderClient.run(), "Sender failed, expected return code 0"); - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(0) - .withCredentials(defaultCredentials) - .withAddress(queue) - .withAdditionalArgument(ClientArgument.RECV_BROWSE, "true"); - - //receiver with selector colour = red - receiverClient.withAdditionalArgument(ClientArgument.SELECTOR, "colour = 'red'"); - final Executable executable = () -> assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages 'colour = red'", expectedMsgCount)); - assertAll( - () -> assertTrue(receiverClient.run(), "Receiver 'colour = red' failed, expected return code 0"), - executable); - - //receiver with selector number > 12.5 - receiverClient.withAdditionalArgument(ClientArgument.SELECTOR, "number > 12.5"); - assertAll( - () -> assertTrue(receiverClient.run(), "Receiver 'number > 12.5' failed, expected return code 0"), - executable); - - - //receiver with selector a AND b - receiverClient.withAdditionalArgument(ClientArgument.SELECTOR, "a AND b"); - assertAll( - () -> assertTrue(receiverClient.run(), "Receiver 'a AND b' failed, expected return code 0"), - () -> assertEquals(0, receiverClient.getMessages().size(), - String.format("Expected %d received messages 'a AND b'", 0))); - - //receiver with selector a OR b - receiverClient.withAdditionalArgument(ClientArgument.RECV_BROWSE, "false"); - receiverClient.withAdditionalArgument(ClientArgument.SELECTOR, "a OR b"); - - assertAll( - () -> assertTrue(receiverClient.run(), "Receiver 'a OR b' failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages 'a OR b'", expectedMsgCount))); - } - - protected void doMessageSelectorTopicTest(AbstractClient sender, AbstractClient sender2, - AbstractClient subscriber, AbstractClient subscriber2) throws Exception { - clients.addAll(Arrays.asList(sender, sender2, subscriber, subscriber2)); - int expectedMsgCount = 5; - - Address topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "selector-topic" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("selector-topic" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - resourcesManager.setAddresses(topic); - - //set up senders - ExternalMessagingClient senderClient1 = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(expectedMsgCount) - .withAddress(topic) - .withCredentials(defaultCredentials) - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "colour~red") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "number~12.65") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "a~true") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "b~false") - .withTimeout(250) - .withMessageBody("msg no. %d"); - - ExternalMessagingClient senderClient2 = new ExternalMessagingClient() - .withClientEngine(sender2) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(expectedMsgCount) - .withAddress(topic) - .withCredentials(defaultCredentials) - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "colour~blue") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "number~11.65") - .withTimeout(250) - .withMessageBody("msg no. %d"); - - //set up subscriber1 - ExternalMessagingClient receiverClient1 = new ExternalMessagingClient() - .withClientEngine(subscriber) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(expectedMsgCount) - .withCredentials(defaultCredentials) - .withAddress(topic) - .withTimeout(250) - .withAdditionalArgument(ClientArgument.SELECTOR, "colour = 'red' AND a"); - - //set up subscriber2 - ExternalMessagingClient receiverClient2 = new ExternalMessagingClient() - .withClientEngine(subscriber2) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(expectedMsgCount) - .withCredentials(defaultCredentials) - .withAddress(topic) - .withTimeout(250) - .withAdditionalArgument(ClientArgument.SELECTOR, "number < 12.5"); - - Future result1 = receiverClient1.runAsync(); - Future result2 = receiverClient2.runAsync(); - - receiverClient1.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - receiverClient2.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - - assertTrue(senderClient1.run(), "Sender failed, expected return code 0"); - assertTrue(senderClient2.run(), "Sender2 failed, expected return code 0"); - assertTrue(result1.get(), "Receiver 'colour = red' failed, expected return code 0"); - assertTrue(result2.get(), "Receiver 'number < 12.5' failed, expected return code 0"); - - assertEquals(expectedMsgCount, senderClient1.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, senderClient2.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient1.getMessages().size(), - String.format("Expected %d received messages 'colour = red' AND a", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient2.getMessages().size(), - String.format("Expected %d received messages 'number < 12.5'", expectedMsgCount)); - } - - protected void doTestUserPermissions(AbstractClient sender, AbstractClient receiver) throws Exception { - int expectedMsgCount = 5; - UserCredentials publishCred = new UserCredentials("publisher", "publish"); - UserCredentials consumCred = new UserCredentials("consumer", "consume"); - createPublisherAndConsumer(publishCred, consumCred); - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "message-basic" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("message-basic" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), false)) - .withAddress(dest) - .withCredentials(publishCred) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30) - .withCredentials(consumCred) - .withAdditionalArgument(ClientArgument.DEST_TYPE, "ANYCAST"); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), false)) - .withAddress(dest) - .withCredentials(consumCred) - .withCount(expectedMsgCount) - .withTimeout(30) - .withCredentials(publishCred) - .withAdditionalArgument(ClientArgument.DEST_TYPE, "ANYCAST"); - - - assertAll( - () -> assertFalse(senderClient.run(), "Sender failed. Specified user is not allowed to write"), - () -> assertFalse(receiverClient.run(), "Receiver failed. Specified user is not allowed to read")); - - senderClient.withCredentials(publishCred); - - receiverClient.withCredentials(consumCred); - - assertTrue(senderClient.run(), "Sender failed, expected return code 0"); - assertTrue(receiverClient.run(), "Receiver failed, expected return code 0"); - - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount)); - } - - private void createPublisherAndConsumer(UserCredentials publishCred, UserCredentials consumCred) throws Exception { - User publisher = (UserUtils.createUserResource(publishCred) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("*") - .withOperations(Operation.send) - .build())) - .endSpec() - .done()); - - User consumer = (UserUtils.createUserResource(consumCred) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("*") - .withOperations(Operation.recv) - .build())) - .endSpec() - .done()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), publisher); - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), consumer); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClusterClientTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClusterClientTestBase.java deleted file mode 100644 index 1117b5dd400..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClusterClientTestBase.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.clients; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.shared.ITestBaseShared; -import io.enmasse.systemtest.messagingclients.AbstractClient; -import io.enmasse.systemtest.messagingclients.ClientArgument; -import io.enmasse.systemtest.messagingclients.ClientType; -import io.enmasse.systemtest.annotations.ExternalClients; -import io.enmasse.systemtest.messagingclients.ExternalMessagingClient; -import io.enmasse.systemtest.messagingclients.mqtt.PahoMQTTClientReceiver; -import io.enmasse.systemtest.messagingclients.mqtt.PahoMQTTClientSender; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; - -import java.util.concurrent.Future; - -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -@ExternalClients -public abstract class ClusterClientTestBase extends TestBase implements ITestBaseShared { - - private Endpoint getMessagingRoute(AddressSpace addressSpace, boolean websocket, boolean ssl, boolean mqtt) throws Exception { - int port = ssl ? 5671 : 5672; - if (addressSpace.getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) && mqtt) { - port = ssl ? 8883 : 1883; - } - return new Endpoint(String.format("%s-%s.%s.svc.cluster.local", - (addressSpace.getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) && mqtt) ? "mqtt" : "messaging", - AddressSpaceUtils.getAddressSpaceInfraUuid(addressSpace), - environment.namespace()), - websocket && addressSpace.getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? 443 : port); - } - - protected void doBasicMessageTest(AbstractClient sender, AbstractClient receiver) throws Exception { - doBasicMessageTest(sender, receiver, false); - } - - protected void doBasicMessageTest(AbstractClient sender, AbstractClient receiver, boolean websocket) throws Exception { - int expectedMsgCount = 10; - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "message-basic-" + ClientType.getAddressName(sender) + (websocket ? "-ws" : ""))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("message-basic-" + ClientType.getAddressName(sender) + (websocket ? "-ws" : "")) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), websocket, true, false)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET, websocket) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET_PROTOCOLS, getSharedAddressSpace().getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? "binary" : ""); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), websocket, true, false)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withTimeout(30) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET, websocket) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET_PROTOCOLS, getSharedAddressSpace().getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? "binary" : ""); - - assertTrue(senderClient.run()); - assertTrue(receiverClient.run()); - - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount)); - } - - protected void doMqttMessageTest() throws Exception { - int expectedMsgCount = 10; - AbstractClient sender = new PahoMQTTClientSender(); - AbstractClient receiver = new PahoMQTTClientReceiver(); - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "basic-mqtt" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("basic-mqtt" + ClientType.getAddressName(sender)) - .withPlan(getSharedAddressSpace().getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? DestinationPlan.STANDARD_LARGE_TOPIC : getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), false, false, false)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), false, false, false)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withTimeout(40); - - Future recResult = receiverClient.runAsync(); - Thread.sleep(20_000); - - assertAll( - () -> assertTrue(senderClient.run(), "Producer failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount))); - assertAll( - () -> assertTrue(recResult.get(), "Subscriber failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount))); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/infra/InfraTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/infra/InfraTestBase.java deleted file mode 100644 index 6e368c973d7..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/infra/InfraTestBase.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.infra; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.admin.model.v1.AddressPlan; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.executor.ExecutionResultData; -import io.enmasse.systemtest.infra.InfraConfiguration; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.TestUtils; -import io.enmasse.user.model.v1.User; -import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; -import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.api.model.PodTemplateSpec; -import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.fabric8.kubernetes.api.model.Toleration; -import io.fabric8.kubernetes.api.model.storage.StorageClass; -import org.opentest4j.AssertionFailedError; -import org.slf4j.Logger; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class InfraTestBase extends TestBase implements ITestBase { - - private static final List resizingStorageProvisioners = Arrays.asList("kubernetes.io/aws-ebs", "kubernetes.io/gce-pd", - "kubernetes.io/azure-file", "kubernetes.io/azure-disk", "kubernetes.io/glusterfs", "kubernetes.io/cinder", - "kubernetes.io/portworx-volume", "kubernetes.io/rbd"); - private static Logger log = CustomLogger.getLogger(); - protected AddressPlan exampleAddressPlan; - protected AddressSpace exampleAddressSpace; - protected UserCredentials exampleUser = new UserCredentials("test", "test"); - - protected void assertBroker(InfraConfiguration brokerConfig) { - log.info("Checking broker infra"); - List brokerPods = TestUtils.listBrokerPods(kubernetes, exampleAddressSpace); - assertEquals(1, brokerPods.size()); - - Pod broker = brokerPods.stream().findFirst().get(); - - ResourceRequirements resources = broker.getSpec().getContainers().stream() - .filter(container -> container.getName().equals("broker")) - .findFirst() - .map(Container::getResources) - .get(); - assertEquals(brokerConfig.getMemory(), resources.getLimits().get("memory").getAmount(), - "Broker memory limit incorrect"); - assertEquals(brokerConfig.getMemory(), resources.getRequests().get("memory").getAmount(), - "Broker memory requests incorrect"); - if (brokerConfig.getCpu() != null) { - assertEquals(brokerConfig.getCpu(), resources.getLimits().get("cpu").getAmount(), - "Broker cpu limit incorrect"); - assertEquals(brokerConfig.getCpu(), resources.getRequests().get("cpu").getAmount(), - "Broker cpu requests incorrect"); - } - - if (brokerConfig.getBrokerStorage() != null) { - PersistentVolumeClaim brokerVolumeClaim = getBrokerPVCData(broker); - assertEquals(brokerConfig.getBrokerStorage(), brokerVolumeClaim.getSpec().getResources().getRequests().get("storage").getAmount(), - "Broker data storage request incorrect"); - } - - if (brokerConfig.getBrokerJavaOpts() != null) { - brokerPods.forEach(pod -> { - ExecutionResultData result = KubeCMDClient.runOnCluster("exec", pod.getMetadata().getName(), "-n", - pod.getMetadata().getNamespace(), "ps", "auxww"); - assertTrue(result.getRetCode(), result.getStdOut()); - assertTrue(result.getStdOut().contains(brokerConfig.getBrokerJavaOpts()), - "Unable to find expected java opts in process argument list: " + result.getStdOut()); - }); - } - - if (brokerConfig.getTemplateSpec() != null) { - assertTemplateSpec(broker, brokerConfig.getTemplateSpec()); - } - } - - protected void assertTemplateSpec(Pod pod, PodTemplateSpec templateSpec) { - if (templateSpec.getMetadata().getLabels() != null) { - for (Map.Entry labelPair : templateSpec.getMetadata().getLabels().entrySet()) { - assertEquals(labelPair.getValue(), pod.getMetadata().getLabels().get(labelPair.getKey()), "Labels do not match"); - } - } - - if (templateSpec.getSpec().getAffinity() != null) { - assertEquals(templateSpec.getSpec().getAffinity(), pod.getSpec().getAffinity(), "Affinity rules do not match"); - } - - if (templateSpec.getSpec().getPriorityClassName() != null) { - assertEquals(templateSpec.getSpec().getPriorityClassName(), pod.getSpec().getPriorityClassName(), "Priority class names do not match"); - } - - if (templateSpec.getSpec().getTolerations() != null) { - for (Toleration expected : templateSpec.getSpec().getTolerations()) { - boolean found = false; - for (Toleration actual : pod.getSpec().getTolerations()) { - if (actual.equals(expected)) { - found = true; - break; - } - } - assertTrue(found, "Did not find expected toleration " + expected); - } - } - - for (Container expectedContainer : templateSpec.getSpec().getContainers()) { - for (Container actualContainer : pod.getSpec().getContainers()) { - if (expectedContainer.getName().equals(actualContainer.getName())) { - assertEquals(expectedContainer.getResources(), actualContainer.getResources()); - } - } - } - } - - protected void assertAdminConsole(InfraConfiguration adminConfig) { - log.info("Checking admin console infra"); - List adminPods = TestUtils.listAdminConsolePods(kubernetes, exampleAddressSpace); - assertEquals(1, adminPods.size()); - - List adminResources = adminPods.stream().findFirst().get().getSpec().getContainers() - .stream().map(Container::getResources).collect(Collectors.toList()); - - for (ResourceRequirements requirements : adminResources) { - assertEquals(adminConfig.getMemory(), requirements.getLimits().get("memory").getAmount(), - "Admin console memory limit incorrect"); - assertEquals(adminConfig.getMemory(), requirements.getRequests().get("memory").getAmount(), - "Admin console memory requests incorrect"); - if (adminConfig.getCpu() != null) { - assertEquals(adminConfig.getCpu(), requirements.getLimits().get("cpu").getAmount(), - "Admin console cpu limit incorrect"); - assertEquals(adminConfig.getCpu(), requirements.getRequests().get("cpu").getAmount(), - "Admin console cpu requests incorrect"); - } - } - - if (adminConfig.getTemplateSpec() != null) { - assertTemplateSpec(adminPods.get(0), adminConfig.getTemplateSpec()); - } - } - - protected void waitUntilInfraReady(Supplier assertCall, TimeoutBudget timeout) throws InterruptedException { - log.info("Start waiting for infra ready"); - AssertionFailedError lastException = null; - while (!timeout.timeoutExpired()) { - try { - assertCall.get(); - log.info("assert infra ready succeed"); - return; - } catch (AssertionFailedError e) { - lastException = e; - } - log.debug("next iteration, remaining time: {}", timeout.timeLeft()); - Thread.sleep(5000); - } - log.error("Timeout assert infra expired"); - if (lastException != null) { - throw lastException; - } - } - - protected PersistentVolumeClaim getBrokerPVCData(Pod broker) { - String brokerVolumeClaimName = broker.getSpec().getVolumes().stream() - .filter(volume -> volume.getName().equals("data")) - .findFirst().get() - .getPersistentVolumeClaim().getClaimName(); - return TestUtils.listPersistentVolumeClaims(kubernetes, exampleAddressSpace).stream() - .filter(pvc -> pvc.getMetadata().getName().equals(brokerVolumeClaimName)) - .findFirst().get(); - } - - protected Boolean volumeResizingSupported() throws Exception { - List brokerPods = TestUtils.listBrokerPods(kubernetes, exampleAddressSpace); - assertEquals(1, brokerPods.size()); - Pod broker = brokerPods.stream().findFirst().get(); - PersistentVolumeClaim brokerVolumeClaim = getBrokerPVCData(broker); - String brokerStorageClassName = brokerVolumeClaim.getSpec().getStorageClassName(); - if (brokerStorageClassName != null) { - StorageClass brokerStorageClass = kubernetes.getStorageClass(brokerStorageClassName); - if (resizingStorageProvisioners.contains(brokerStorageClass.getProvisioner())) { - if (brokerStorageClass.getAllowVolumeExpansion() != null && brokerStorageClass.getAllowVolumeExpansion()) { - log.info("Testing broker volume resize because of {}:{}", brokerStorageClassName, brokerStorageClass.getProvisioner()); - return true; - } else { - log.info("Skipping broker volume resize due to allowVolumeExpansion in StorageClass {} disabled", brokerStorageClassName); - } - } else { - log.info("Skipping broker volume resize due to provisioner: {}", brokerStorageClass.getProvisioner()); - } - } else { - log.info("Skipping broker volume resize due to missing StorageClass name in PVC {}", brokerVolumeClaim.getMetadata().getName()); - } - return false; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/mqtt/MqttPublishTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/mqtt/MqttPublishTestBase.java deleted file mode 100644 index 6e04ec1a432..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/mqtt/MqttPublishTestBase.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.mqtt; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.eclipse.paho.client.mqttv3.IMqttClient; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.slf4j.Logger; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.shared.ITestBaseShared; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.mqtt.MqttClientFactory; -import io.enmasse.systemtest.mqtt.MqttClientFactory.Builder; -import io.enmasse.systemtest.mqtt.MqttUtils; -import io.enmasse.systemtest.utils.AddressUtils; - -public abstract class MqttPublishTestBase extends TestBase implements ITestBaseShared { - - private static final String MYTOPIC = "mytopic"; - private static final Logger log = CustomLogger.getLogger(); - - public void testPublishQoS0() throws Exception { - List messages = Stream.generate(MqttMessage::new).limit(3).collect(Collectors.toList()); - messages.forEach(m -> { - m.setPayload(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)); - m.setQos(0); - }); - - this.publish(messages, 0); - } - - public void testPublishQoS1() throws Exception { - List messages = Stream.generate(MqttMessage::new).limit(3).collect(Collectors.toList()); - messages.forEach(m -> { - m.setPayload(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)); - m.setQos(1); - }); - - this.publish(messages, 1); - } - - public void testPublishQoS2() throws Exception { - List messages = Stream.generate(MqttMessage::new).limit(3).collect(Collectors.toList()); - messages.forEach(m -> { - m.setPayload(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)); - m.setQos(2); - }); - - this.publish(messages, 2); - } - - public void testRetainedMessages() throws Exception { - Address topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "test-topic1")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("test-topic1") - .withPlan(topicPlan()) - .endSpec() - .build(); - resourcesManager.setAddresses(topic); - - MqttMessage retainedMessage = new MqttMessage(); - retainedMessage.setQos(1); - retainedMessage.setPayload("retained-message".getBytes(StandardCharsets.UTF_8)); - retainedMessage.setId(1); - retainedMessage.setRetained(true); - - // send retained message to the topic - Builder publisherBuilder = new MqttClientFactory.Builder() - .usernameAndPassword(defaultCredentials); - customizeClient(publisherBuilder); - try(IMqttClient publisher = publisherBuilder.create()) { - publisher.connect(); - publisher.publish(topic.getSpec().getAddress(), retainedMessage); - publisher.disconnect(); - } - - // each client which will subscribe to the topic should receive retained message! - Builder subscriberBuilder = new MqttClientFactory.Builder() - .usernameAndPassword(defaultCredentials); - customizeClient(subscriberBuilder); - try(IMqttClient subscriber = subscriberBuilder.create()) { - subscriber.connect(); - CompletableFuture messageFuture = new CompletableFuture<>(); - subscriber.subscribe(topic.getSpec().getAddress(), (topic1, message) -> messageFuture.complete(message)); - MqttMessage receivedMessage = messageFuture.get(1, TimeUnit.MINUTES); - assertTrue(receivedMessage.isRetained(), "Retained message expected"); - - subscriber.disconnect(); - } - } - - private void publish(List messages, int subscriberQos) throws Exception { - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), MYTOPIC)) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress(MYTOPIC) - .withPlan(topicPlan()) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - Builder clientBuilder = new MqttClientFactory.Builder() - .usernameAndPassword(defaultCredentials) - .mqttConnectionOptions(options -> { - options.setConnectionTimeout(options.getConnectionTimeout() * 2); // Default is 30 seconds, increase it to 1 min. - options.setAutomaticReconnect(true); - }); - customizeClient(clientBuilder); - - try (IMqttClient client = clientBuilder.create()) { - log.info("Connecting"); - client.connect(); - - List> receiveFutures = MqttUtils.subscribeAndReceiveMessages(client, dest.getSpec().getAddress(), messages.size(), subscriberQos); - List> publishFutures = MqttUtils.publish(client, dest.getSpec().getAddress(), messages); - - int publishCount = MqttUtils.awaitAndReturnCode(publishFutures, 1, TimeUnit.MINUTES); - assertThat("Incorrect count of messages published", - publishCount, is(messages.size())); - - int receivedCount = MqttUtils.awaitAndReturnCode(receiveFutures, 2, TimeUnit.MINUTES); - assertThat("Incorrect count of messages received", - receivedCount, is(messages.size())); - } - - } - - protected void customizeClient(Builder mqttClientBuilder) { - //optional to implement - } - - protected String topicPlan() { - return getDefaultPlan(AddressType.TOPIC); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/olm/OLMTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/olm/OLMTestBase.java deleted file mode 100644 index d77f1ae052a..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/olm/OLMTestBase.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.olm; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.admin.model.v1.AuthenticationService; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.AmqpConnectOptions; -import io.enmasse.systemtest.amqp.QueueTerminusFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.isolated.ITestIsolatedStandard; -import io.enmasse.systemtest.executor.ExecutionResultData; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.logs.GlobalLogCollector; -import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.platform.cluster.CRCCluster; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.AuthServiceUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.vertx.core.json.JsonArray; -import io.vertx.core.json.JsonObject; -import io.vertx.proton.ProtonQoS; -import org.apache.qpid.proton.message.Message; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Base64; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public abstract class OLMTestBase extends TestBase implements ITestIsolatedStandard { - private static Logger log = CustomLogger.getLogger(); - - private static final int CR_TIMEOUT_MILLIS = 30000; - private List exampleResources = new ArrayList<>(); - - protected abstract String getInstallationNamespace(); - - protected abstract String getDifferentAddressSpaceNamespace(); - - @BeforeAll - void setupExampleResources() throws Exception { - ExecutionResultData result = KubeCMDClient.runOnCluster("get", "csv", "-n", getInstallationNamespace(), "-o", "json", "-l", "app=enmasse"); - JsonObject csvList = new JsonObject(result.getStdOut()); - JsonObject csv = csvList.getJsonArray("items").getJsonObject(0); - String almExamples = csv.getJsonObject("metadata").getJsonObject("annotations").getString("alm-examples"); - JsonArray examples = new JsonArray(almExamples); - exampleResources = examples.stream().map(o -> (JsonObject) o).collect(Collectors.toList()); - - Set infraKinds = Set.of("StandardInfraConfig", "BrokeredInfraConfig", "AddressPlan", "AddressSpacePlan", "AuthenticationService"); - - for (JsonObject example : exampleResources) { - LOGGER.info("Example: {}", example); - String kind = example.getString("kind"); - if (kind.equals("AuthenticationService") && kubernetes.getCluster() instanceof CRCCluster) { - log.info("Creating standard-authservice with no persistence because of CRC cluster"); - AuthenticationService authService = AuthServiceUtils.createStandardAuthServiceObject("standard-authservice", false); - authService.getMetadata().setNamespace(getInstallationNamespace()); - kubernetes.getAuthenticationServiceClient(getInstallationNamespace()).create(authService); - } else if (infraKinds.contains(kind)) { - log.info("Creating {}", example.toString()); - createCR(getInstallationNamespace(), example); - } - } - TestUtils.waitUntilDeployed(getInstallationNamespace()); - TestUtils.waitForPodReady("standard-authservice", getInstallationNamespace()); - TestUtils.waitForSchemaInSync("standard-small"); - var addressSpacePlanClient = kubernetes.getAddressSpacePlanClient(getInstallationNamespace()); - TestUtils.waitUntilCondition("AddressSpacePlan standard-small visible", - phase -> addressSpacePlanClient.withName("standard-small").get() != null, - new TimeoutBudget(2, TimeUnit.MINUTES)); - - } - - @AfterEach - void deleteAddressSpace(ExtensionContext context) throws Exception { - if (context.getExecutionException().isPresent()) { //test failed - Path path = TestUtils.getFailedTestLogsPath(context); - GlobalLogCollector collector = new GlobalLogCollector(Kubernetes.getInstance(), path, getInstallationNamespace()); - collector.collectLogsOfPodsInNamespace(getInstallationNamespace()); - collector.collectEvents(getInstallationNamespace()); - } - for (String namespace : Arrays.asList(getInstallationNamespace(), getDifferentAddressSpaceNamespace())) { - AddressSpace addressSpace = kubernetes.getAddressSpaceClient(namespace).withName("myspace").get(); - if (addressSpace != null) { - resourcesManager.deleteAddressSpace(addressSpace); - } - } - } - - @AfterAll - void teardownExampleResources() throws Exception { - if (!environment.skipCleanup()) { - for (JsonObject example : exampleResources) { - log.info("Deleting {}", example.toString()); - KubeCMDClient.deleteCR(getInstallationNamespace(), example.toString(), CR_TIMEOUT_MILLIS); - } - kubernetes.deleteNamespace(getDifferentAddressSpaceNamespace()); - } - } - - protected void doTestExampleResourcesSameNamespaceAsOperator() throws Exception { - createdUserResources(getInstallationNamespace()); - } - - protected void doTestExampleResourcesDifferentNamespaceThanOperator() throws Exception { - kubernetes.createNamespace(getDifferentAddressSpaceNamespace()); - createdUserResources(getDifferentAddressSpaceNamespace()); - } - - private void createdUserResources(String addressSpaceNamespace) throws Exception { - JsonObject exampleAddressSpace = exampleResources.stream() - .filter(example -> example.getString("kind").equals("AddressSpace")) - .findFirst() - .orElseThrow(() -> new IllegalStateException("Example resources don't contain an address space")); - log.info("Creating {}", exampleAddressSpace.getString("kind")); - createCR(addressSpaceNamespace, exampleAddressSpace); - var client = kubernetes.getAddressSpaceClient(addressSpaceNamespace); - TestUtils.waitUntilCondition("Address space visible", - phase -> client.withName("myspace").get() != null, new TimeoutBudget(30, TimeUnit.SECONDS)); - resourcesManager.waitForAddressSpaceReady(client.withName("myspace").get()); - - - for (JsonObject example : exampleResources) { - String kind = example.getString("kind"); - if (kind.equals("Address") || kind.equals("MessagingUser")) { - log.info("Creating {}", kind); - createCR(addressSpaceNamespace, example); - } - } - Thread.sleep(10_000); - TestUtils.waitUntilDeployed(getInstallationNamespace()); - var addressClient = kubernetes.getAddressClient(addressSpaceNamespace); - TestUtils.waitUntilCondition("Address visible", - phase -> addressClient.withName("myspace.myqueue").get() != null, - new TimeoutBudget(30, TimeUnit.SECONDS)); - AddressUtils.waitForDestinationsReady(addressClient.withName("myspace.myqueue").get()); - - // Test basic messages - AddressSpace exampleSpace = kubernetes.getAddressSpaceClient(addressSpaceNamespace).withName("myspace").get(); - Address exampleAddress = kubernetes.getAddressClient(addressSpaceNamespace).withName("myspace.myqueue").get(); - - AmqpClient amqpClient = resourcesManager.getAmqpClientFactory().createClient(new AmqpConnectOptions() - .setTerminusFactory(new QueueTerminusFactory()) - .setQos(ProtonQoS.AT_LEAST_ONCE) - .setCert(new String(Base64.getDecoder().decode(exampleSpace.getStatus().getCaCert()), StandardCharsets.UTF_8)) - .setEndpoint(kubernetes.getExternalEndpoint("messaging-" + AddressSpaceUtils.getAddressSpaceInfraUuid(exampleSpace), getInstallationNamespace())) - .setUsername("user") - .setPassword("enmasse")); - - int messageCount = 10; - Future sent = amqpClient.sendMessages(exampleAddress.getSpec().getAddress(), TestUtils.generateMessages(messageCount)); - assertEquals(messageCount, sent.get(1, TimeUnit.MINUTES).intValue(), "Incorrect count of messages send"); - - Future> received = amqpClient.recvMessages(exampleAddress.getSpec().getAddress(), messageCount); - assertEquals(messageCount, received.get(1, TimeUnit.MINUTES).size(), "Incorrect count of messages received"); - } - - private void createCR(String namespace, JsonObject cr) throws IOException { - ExecutionResultData res = KubeCMDClient.createCR(namespace, cr.toString(), CR_TIMEOUT_MILLIS); - if (!res.getRetCode()) { - Assertions.fail(res.getStdErr()); - } - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/plans/PlansTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/plans/PlansTestBase.java deleted file mode 100644 index 318ab8ad12b..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/plans/PlansTestBase.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.bases.plans; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.admin.model.v1.AddressPlan; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.isolated.ITestBaseIsolated; -import io.enmasse.systemtest.broker.ArtemisUtils; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.TestUtils; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.amqp.messaging.Data; -import org.apache.qpid.proton.amqp.transport.DeliveryState; -import org.apache.qpid.proton.message.Message; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.StringDescription; -import org.hamcrest.TypeSafeMatcher; -import org.slf4j.Logger; - -import java.time.Duration; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class PlansTestBase extends TestBase { - private static Logger log = CustomLogger.getLogger(); - - - public static Matcher
assertAddressStatusNotReady(final String messageContains) { - return PlansTestBase.assertAddressStatus(false, Optional.empty(), Optional.of(messageContains)); - } - - public static Matcher
assertAddressStatusReady(String actualPlan) { - return PlansTestBase.assertAddressStatus(true, Optional.of(actualPlan), Optional.empty()); - } - - public static Matcher
assertAddressStatus(final boolean ready, final Optional actualPlan, final Optional messageContains) { - return new TypeSafeMatcher<>() { - @Override - public void describeTo(Description description) { - description.appendText("should match ready ").appendValue(ready); - actualPlan.ifPresent(s -> description.appendText("should match plan ").appendValue(s)); - messageContains.ifPresent(s -> description.appendText("should status should contain ").appendValue(s)); - } - - @Override - protected void describeMismatchSafely(Address a, Description description) { - if (a.getStatus() == null) { - description.appendText("address.status is absent"); - } - if (ready != a.getStatus().isReady()) { - description.appendText("ready was ").appendValue(a.getStatus().isReady()); - } - if (actualPlan.isPresent()) { - if (a.getStatus().getPlanStatus() == null) { - description.appendText("address.status.planStatus is absent"); - } else if (!actualPlan.get().equals(a.getStatus().getPlanStatus().getName())) { - description.appendText("actual plan was ").appendValue(a.getStatus().getPlanStatus().getName()); - } - } - if (messageContains.isPresent()) { - String cc = String.join(":", a.getStatus().getMessages()); - description.appendText("messages were: ").appendValue(cc); - } - - } - - @Override - public boolean matchesSafely(Address a) { - if (a.getStatus() == null) { - return false; - } - if (ready != a.getStatus().isReady()) { - return false; - } - if (actualPlan.isPresent() && !actualPlan.get().equals(a.getStatus().getPlanStatus().getName())) { - return false; - } - if (messageContains.isPresent()) { - Optional match = a.getStatus().getMessages().stream().filter(m -> m.contains(messageContains.get())).findFirst(); - return match.isPresent(); - } else { - return true; - } - } - }; - } - - public void doTestUnknownAddressPlan(AddressSpace addressSpace, List stageHolders) throws Exception { - - resourcesManager.createAddressSpace(addressSpace); - - do { - log.info("Starting stage"); - - List stages = stageHolders.stream().filter(StageHolder::hasStage).map(StageHolder::popStage).collect(Collectors.toList()); - - if (stages.isEmpty()) { - break; - } - - stages.stream().map(StageHolder.Stage::getAddress).forEach(address -> { - Kubernetes.getInstance().getAddressClient(address.getMetadata().getNamespace()).createOrReplace(address); - }); - - stages.forEach(s -> { - AtomicReference lastMatch = new AtomicReference<>(); - - boolean rv = TestUtils.waitUntilCondition(() -> { - Address current = resourcesManager.getAddress(s.getAddress().getMetadata().getNamespace(), s.getAddress()); - Matcher
matcher = s.getMatcher(); - boolean matches = matcher.matches(current); - StringDescription desc = new StringDescription(); - matcher.describeMismatch(current, desc); - lastMatch.set(desc.toString()); - if (matches) { - log.info("Address {} is now in expected state: {}", current.getMetadata().getName(), current.getStatus()); - } else { - log.info("Address {} is not in expected state: {} {}", current.getMetadata().getName(), lastMatch, current.getStatus()); - } - return matches; - }, Duration.ofMinutes(2), Duration.ofSeconds(10)); - assertTrue(rv, String.format("address %s did not reach desired state : %s", s.getAddress().getMetadata().getName(), lastMatch)); - }); - } while(true); - } - - public void doTestUpdatePlanBrokerCreditChangesPerAddressMaxSize(AddressSpace addressSpace, Address queueDest, AddressPlan phase1, AddressPlan phase2, AddressPlan redefinedPhase2, AmqpClientFactory amqpClientFactory) throws Exception { - //get destination - Address queue = kubernetes.getAddressClient(addressSpace.getMetadata().getNamespace()).withName(queueDest.getMetadata().getName()).get(); - - String assertMessage = "Queue plan wasn't set properly"; - assertEquals(queue.getSpec().getPlan(), - phase1.getMetadata().getName(), assertMessage); - - //Send messages to ensure queue fills up - UserCredentials user = new UserCredentials("test-newplan-name", "test_newplan_password"); - resourcesManager.createOrUpdateUser(addressSpace, user); - - AmqpClient client = amqpClientFactory.createQueueClient(addressSpace); - client.getConnectOptions().setCredentials(user); - byte[] bytes = new byte[1024 * 100]; - Random random = new Random(); - Message message = Message.Factory.create(); - random.nextBytes(bytes); - message.setBody(new AmqpValue(new Data(new Binary(bytes)))); - message.setAddress(queue.getSpec().getAddress()); - message.setDurable(true); - - Stream messageStream = Stream.generate(() -> message); - int messagesSent = client.sendMessagesCheckDelivery(queue.getSpec().getAddress(), messageStream::iterator, - protonDelivery -> protonDelivery.remotelySettled() && protonDelivery.getRemoteState().getType().equals(DeliveryState.DeliveryStateType.Rejected)) - .get(5, TimeUnit.MINUTES); - - assertTrue(messagesSent > 0, "Verify a few messages were sent before queue fills up"); - - //Verify maxSizeBytes are set - assertMaxSizeBytes(addressSpace, queue, 524288); - - //Redefine address to use next plan - Address largeQueue = new AddressBuilder(queue).editSpec().withPlan(phase2.getMetadata().getName()).endSpec().build(); - ITestBaseIsolated.isolatedResourcesManager.replaceAddress(largeQueue); - AddressUtils.waitForDestinationsReady(new TimeoutBudget(5, TimeUnit.MINUTES), largeQueue); - awaitPlanStatusResourceSync(addressSpace, largeQueue, phase2); - assertMaxSizeBytes(addressSpace, queue, 734003); - - //Redefine plan to to have more credit - ITestBaseIsolated.isolatedResourcesManager.replaceAddressPlan(redefinedPhase2); - AddressUtils.waitForDestinationsReady(new TimeoutBudget(5, TimeUnit.MINUTES), largeQueue); - awaitPlanStatusResourceSync(addressSpace, largeQueue, redefinedPhase2); - assertMaxSizeBytes(addressSpace, queue, 943718); - } - - public void awaitPlanStatusResourceSync(AddressSpace addressSpace, Address dest, AddressPlan plan) { - TestUtils.waitUntilCondition(() -> { - Address a = kubernetes.getAddressClient(addressSpace.getMetadata().getNamespace()).withName(dest.getMetadata().getName()).get(); - return a.getStatus().getPlanStatus() != null && a.getStatus().getPlanStatus().getResources().containsKey("broker") && - a.getStatus().getPlanStatus().getResources().get("broker").equals(plan.getResources().get("broker")); - }, Duration.ofMinutes(1), Duration.ofSeconds(1)); - } - - public void assertMaxSizeBytes(AddressSpace addressSpace, Address queue, Integer expected) throws Exception { - Map addressSettings = ArtemisUtils.getAddressSettings(kubernetes, addressSpace, queue.getSpec().getAddress()); - assertEquals(expected, (Integer) addressSettings.get("maxSizeBytes"), "maxSizeBytes should be set"); - } - - public class StageHolder { - private final AddressSpace addressSpace; - private final String addressName; - private final List stages = new ArrayList<>(); - - public class Stage { - private final String plan; - private final Matcher
matcher; - - Stage(Matcher
matcher, String plan) { - this.plan = plan; - this.matcher = matcher; - } - - public Address getAddress() { - return new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, addressName)) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress(StageHolder.this.addressName) - .withPlan(this.plan) - .endSpec() - .build(); - } - - public Matcher
getMatcher() { - return matcher; - } - } - - public StageHolder(AddressSpace addressSpace, String addressName) { - this.addressSpace = addressSpace; - this.addressName = addressName; - } - - public StageHolder addStage(String plan, Matcher
addressMatcher) { - stages.add(new Stage(addressMatcher, plan)); - return this; - } - - public boolean hasStage() { - return !stages.isEmpty(); - } - - public Stage popStage() { - return stages.remove(0); - } - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/soak/SoakTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/soak/SoakTestBase.java deleted file mode 100644 index 511e6506712..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/soak/SoakTestBase.java +++ /dev/null @@ -1,376 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.soak; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceBuilder; -import io.enmasse.systemtest.SysytemTestsErrorCollector; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.ThrowableRunner; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.shared.standard.QueueTest; -import io.enmasse.systemtest.shared.standard.TopicTest; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.TestUtils; -import org.apache.qpid.proton.message.Message; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.slf4j.Logger; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static io.enmasse.systemtest.TestTag.SOAK; -import static org.hamcrest.CoreMatchers.is; - -@Tag(SOAK) -public abstract class SoakTestBase extends TestBase { - private static Logger log = CustomLogger.getLogger(); - private ArrayList clients = new ArrayList<>(); - private SysytemTestsErrorCollector collector = new SysytemTestsErrorCollector(); - - @BeforeEach - void setupMarathonTests() { - collector.clear(); - } - - //======================================================================================================== - // Runner tests methods - //======================================================================================================== - - protected void runTestInLoop(int durationMinutes, ThrowableRunner test) throws Exception { - log.info(String.format("Starting test running for %d minutes at %s", - durationMinutes, new Date().toString())); - int fails = 0; - int limit = 10; - int i = 0; - for (long stop = System.nanoTime() + TimeUnit.MINUTES.toNanos(durationMinutes); stop > System.nanoTime(); ) { - try { - log.info("*********************************** Test run {} ***********************************", ++i); - test.run(); - fails = 0; - } catch (Exception ex) { - log.warn("Test run {} failed with: {}", i, ex.getMessage()); - collector.addError(ex); - if (++fails >= limit) { - throw new IllegalStateException(String.format("Test failed: %d times in a row: %s", fails, collector.toString())); - } - } finally { - closeClients(); - log.info("***********************************************************************************"); - Thread.sleep(60_000); - } - } - if (!collector.verify()) { - throw new IllegalStateException(String.format("Test failed with these exceptions: %s", collector.toString())); - } - } - - private void closeClients() { - for (AmqpClient client : clients) { - try { - client.close(); - log.info("Client is closed."); - } catch (Exception ex) { - collector.addError(ex); - } - } - clients.clear(); - } - - //======================================================================================================== - // Tests methods - //======================================================================================================== - protected void doTestQueueSendReceiveLong(AddressSpace addressSpace) throws Exception { - resourcesManager.createAddressSpace(addressSpace); - - int msgCount = 1000; - int queueCount = 10; - int senderCount = 10; - int recvCount = 20; - - List
queueList = new ArrayList<>(); - - //create queues - for (int i = 0; i < queueCount; i++) { - queueList.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-sendreceive-" + i)) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-sendreceive-" + i) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build()); - } - resourcesManager.setAddresses(queueList.toArray(new Address[0])); - - List msgBatch = TestUtils.generateMessages(msgCount); - - UserCredentials credentials = new UserCredentials("test", "test"); - resourcesManager.createOrUpdateUser(addressSpace, credentials); - - runTestInLoop(30, () -> { - //create client - AmqpClient client = resourcesManager.getAmqpClientFactory().createQueueClient(addressSpace); - client.getConnectOptions().setCredentials(credentials); - clients.add(client); - - //attach receivers - List>> recvResults = new ArrayList<>(); - for (int i = 0; i < recvCount / 2; i++) { - recvResults.add(client.recvMessages(queueList.get(i).getSpec().getAddress(), msgCount / 2)); - recvResults.add(client.recvMessages(queueList.get(i).getSpec().getAddress(), msgCount / 2)); - } - - //attach senders - for (int i = 0; i < senderCount; i++) { - collector.checkThat(client.sendMessages(queueList.get(i).getSpec().getAddress(), msgBatch).get(2, TimeUnit.MINUTES), is(msgBatch.size())); - } - - //check received messages - for (int i = 0; i < recvCount; i++) { - collector.checkThat(recvResults.get(i).get().size(), is(msgCount / 2)); - } - }); - } - - protected void doTestAuthSendReceiveLong(AddressSpace addressSpace) throws Exception { - log.info("testAuthSendReceiveLong start"); - resourcesManager.createAddressSpace(addressSpace); - log.info("Address space '{}'created", addressSpace); - - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-auth-queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-auth-queue") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - Address topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-auth-topic")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("test-auth-topic") - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - resourcesManager.setAddresses(queue, topic); - log.info("Addresses '{}', '{}' created", queue.getSpec().getAddress(), topic.getSpec().getAddress()); - - UserCredentials user = new UserCredentials("test-user", "test-user"); - resourcesManager.createOrUpdateUser(addressSpace, user); - - runTestInLoop(30, () -> { - log.info("Start test loop basic auth tests"); - getClientUtils().assertCanConnect(addressSpace, user, Arrays.asList(queue, topic), resourcesManager); - getClientUtils().assertCannotConnect(addressSpace, new UserCredentials("nobody", "nobody"), Arrays.asList(queue, topic), resourcesManager); - }); - log.info("testAuthSendReceiveLong finished"); - } - - protected void doTestTopicPubSubLong(AddressSpace addressSpace) throws Exception { - resourcesManager.createAddressSpace(addressSpace); - - int msgCount = 1000; - int topicCount = 10; - - List
topicList = new ArrayList<>(); - - //create queues - for (int i = 0; i < topicCount; i++) { - topicList.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-topic-pubsub-" + i)) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("test-topic-pubsub-" + i) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build()); - } - resourcesManager.setAddresses(topicList.toArray(new Address[0])); - - List msgBatch = TestUtils.generateMessages(msgCount); - - UserCredentials credentials = new UserCredentials("test", "test"); - resourcesManager.createOrUpdateUser(addressSpace, credentials); - runTestInLoop(30, () -> { - AmqpClient client = resourcesManager.getAmqpClientFactory().createTopicClient(addressSpace); - client.getConnectOptions().setCredentials(credentials); - clients.add(client); - - //attach subscibers - List>> recvResults = new ArrayList<>(); - for (int i = 0; i < topicCount; i++) { - recvResults.add(client.recvMessages(String.format("test-topic-pubsub-%d", i), msgCount)); - } - - //attach producers - for (int i = 0; i < topicCount; i++) { - collector.checkThat(client.sendMessages(topicList.get(i).getSpec().getAddress(), msgBatch).get(2, TimeUnit.MINUTES), is(msgBatch.size())); - } - - //check received messages - for (int i = 0; i < topicCount; i++) { - collector.checkThat(recvResults.get(i).get().size(), is(msgCount)); - } - }); - } - - //======================================================================================================== - // Help methods - //======================================================================================================== - - private void doAddressTest(AddressSpace addressSpace, String topicPattern, - String queuePattern, UserCredentials credentials) throws Exception { - List
queueList = new ArrayList<>(); - List
topicList = new ArrayList<>(); - - int destinationCount = 20; - - for (int i = 0; i < destinationCount; i++) { - queueList.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, queuePattern + i)) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-via-web") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build()); - topicList.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, topicPattern + i)) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress(topicPattern + i) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build()); - } - - AmqpClient queueClient; - AmqpClient topicClient; - - resourcesManager.setAddresses(queueList.toArray(new Address[0])); - resourcesManager.appendAddresses(topicList.toArray(new Address[0])); - - queueClient = resourcesManager.getAmqpClientFactory().createQueueClient(addressSpace); - queueClient.getConnectOptions().setCredentials(credentials); - clients.add(queueClient); - - topicClient = resourcesManager.getAmqpClientFactory().createTopicClient(addressSpace); - topicClient.getConnectOptions().setCredentials(credentials); - clients.add(topicClient); - - for (Address queue : queueList) { - QueueTest.runQueueTest(queueClient, queue, 1024); - } - - for (Address topic : topicList) { - TopicTest.runTopicTest(topicClient, topic, 1024); - } - - resourcesManager.deleteAddresses(queueList.toArray(new Address[0])); - resourcesManager.deleteAddresses(topicList.toArray(new Address[0])); - Thread.sleep(15000); - } - - protected void doTestLoad(AddressSpaceType type, String addressSpacePlans, String addressPlan) throws Exception { - - runTestInLoop(120, () -> { - int count = 5; - AmqpClient queueClient; - Map pairs = new HashMap(); - - - List addressSpaceList = IntStream.range(0, count).mapToObj(i -> - new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-address-space-" + i) - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(type.toString()) - .withPlan(addressSpacePlans) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build()).collect(Collectors.toList()); - - resourcesManager.createAddressSpace(addressSpaceList.toArray(new AddressSpace[0])); - List
addresses = new LinkedList<>(); - for (AddressSpace space : addressSpaceList) { - UserCredentials credentials = new UserCredentials("test", "test"); - resourcesManager.createOrUpdateUser(space, credentials); - queueClient = resourcesManager.getAmqpClientFactory().createQueueClient(space); - queueClient.getConnectOptions().setCredentials(credentials); - clients.add(queueClient); - - for (int i = 0; i < count; i++) { - addresses.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(space.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(space, "test-address-" + i)) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-address-" + i) - .withPlan(addressPlan) - .endSpec() - .build()); - pairs.put(addresses.get(i), queueClient); - } - } - resourcesManager.setAddresses(addresses.toArray(new Address[0])); - for (Map.Entry pair : pairs.entrySet()) { - QueueTest.runQueueTest(pair.getValue(), pair.getKey(), 1024); - } - - for (AddressSpace space : addressSpaceList) { - resourcesManager.deleteAddressSpace(space); - } - }); - } -} - - - - - - - diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/web/ConsoleTest.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/web/ConsoleTest.java deleted file mode 100644 index 47cc690d419..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/web/ConsoleTest.java +++ /dev/null @@ -1,2074 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.web; - - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceBuilder; -import io.enmasse.address.model.AuthenticationServiceType; -import io.enmasse.address.model.CertSpecBuilder; -import io.enmasse.admin.model.v1.AddressPlan; -import io.enmasse.admin.model.v1.AddressSpacePlan; -import io.enmasse.admin.model.v1.AuthenticationService; -import io.enmasse.admin.model.v1.ResourceAllowance; -import io.enmasse.admin.model.v1.ResourceRequest; -import io.enmasse.config.LabelKeys; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.certs.CertBundle; -import io.enmasse.systemtest.certs.CertProvider; -import io.enmasse.systemtest.certs.openssl.CertPair; -import io.enmasse.systemtest.certs.openssl.CertSigningRequest; -import io.enmasse.systemtest.certs.openssl.OpenSSLUtil; -import io.enmasse.systemtest.clients.ClientUtils; -import io.enmasse.systemtest.clients.ClientUtils.ClientAttacher; -import io.enmasse.systemtest.executor.Exec; -import io.enmasse.systemtest.executor.ExecutionResultData; -import io.enmasse.systemtest.info.TestInfo; -import io.enmasse.systemtest.isolated.Credentials; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.logs.GlobalLogCollector; -import io.enmasse.systemtest.messagingclients.ExternalMessagingClient; -import io.enmasse.systemtest.messagingclients.rhea.RheaClientReceiver; -import io.enmasse.systemtest.messagingclients.rhea.RheaClientSender; -import io.enmasse.systemtest.model.address.AddressStatus; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.selenium.SeleniumProvider; -import io.enmasse.systemtest.selenium.page.ConsoleWebPage; -import io.enmasse.systemtest.selenium.resources.AddressWebItem; -import io.enmasse.systemtest.selenium.resources.ConnectionWebItem; -import io.enmasse.systemtest.selenium.resources.FilterType; -import io.enmasse.systemtest.selenium.resources.SortType; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.AuthServiceUtils; -import io.enmasse.systemtest.utils.Count; -import io.enmasse.systemtest.utils.PlanUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.api.model.apps.Deployment; -import io.fabric8.openshift.api.model.Route; -import org.apache.qpid.proton.message.Message; -import org.eclipse.hono.util.Strings; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.slf4j.Logger; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.either; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -public abstract class ConsoleTest extends TestBase { - private static Logger log = CustomLogger.getLogger(); - SeleniumProvider selenium = SeleniumProvider.getInstance(); - private List clientsList; - private ConsoleWebPage consolePage; - - @AfterEach - public void tearDownWebConsoleTests(ExtensionContext context) throws Exception { - if (clientsList != null) { - getClientUtils().stopClients(clientsList, context); - clientsList.clear(); - } - } - - //============================================================================================ - //============================ do test methods for addressspace part========================== - //============================================================================================ - - protected void doTestOpen() throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.getAddressSpaceItems(); - consolePage.logout(); - } - - protected void doTestCreateDeleteAddressSpace(AddressSpace addressSpace) throws Exception { - resourcesManager.addToAddressSpaces(addressSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - consolePage.deleteAddressSpace(addressSpace); - } - - protected void doTestGoneAwayPageAfterAddressSpaceDeletion() throws Exception { - AddressSpace addressSpace = generateAddressSpaceObject(AddressSpaceType.STANDARD); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - consolePage.openAddressList(addressSpace); - resourcesManager.deleteAddressSpaceWithoutWait(addressSpace); - try { - consolePage.awaitGoneAwayPage(); - } finally { - resourcesManager.deleteAddressSpace(addressSpace); - } - } - - protected void doTestGoneAwayPageAfterAddressDeletion() throws Exception { - AddressSpace addressSpace = generateAddressSpaceObject(AddressSpaceType.STANDARD); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - consolePage.openAddressList(addressSpace); - Address address = generateAddressObject(addressSpace, DestinationPlan.STANDARD_SMALL_QUEUE); - consolePage.createAddress(address); - consolePage.openClientsList(address); - resourcesManager.deleteAddresses(address); - consolePage.awaitGoneAwayPage(); - resourcesManager.deleteAddressSpace(addressSpace); - } - - protected void doTestSnippetClient(AddressSpaceType addressSpaceType) throws Exception { - AddressSpace addressSpace = generateAddressSpaceObject(addressSpaceType); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - String firstLine = getSnippetFirstLine(addressSpace); - assertTrue(firstLine.startsWith(KubeCMDClient.getCMD()), "Snippet has right type of cmd client."); - } - - protected void doTestAddressSpaceSnippet(AddressSpaceType addressSpaceType) throws Exception { - AddressSpace addressSpace = generateAddressSpaceObject(addressSpaceType); - - getAndExecAddressSpaceDeploymentSnippet(addressSpace); - assertTrue(AddressSpaceUtils.addressSpaceExists(Kubernetes.getInstance().getInfraNamespace(), - addressSpace.getMetadata().getName())); - resourcesManager.waitForAddressSpaceReady(addressSpace); - resourcesManager.deleteAddressSpace(addressSpace); - } - - - protected void doTestCreateAddrSpaceWithCustomAuthService() throws Exception { - AuthenticationService standardAuth = AuthServiceUtils.createStandardAuthServiceObject("test-standard-authservice", true); - resourcesManager.createAuthService(standardAuth); - - AddressSpace addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-custom-auth") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan(AddressSpacePlans.BROKERED) - .withNewAuthenticationService() - .withName(standardAuth.getMetadata().getName()) - .endAuthenticationService() - .endSpec() - .build(); - resourcesManager.addToAddressSpaces(addressSpace); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - } - - protected void doTestViewAddressSpace() throws Exception { - AddressSpace addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-view-console") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan(AddressSpacePlans.BROKERED) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - resourcesManager.createAddressSpace(addressSpace); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - waitUntilAddressSpaceActive(addressSpace); - consolePage.deleteAddressSpace(addressSpace); - } - - protected void doTestCreateAddrSpaceNonClusterAdminMinimal() throws Exception { - int addressCount = 4; - String namespace = "test-namespace"; - UserCredentials user = Credentials.userCredentials(); - KubeCMDClient.createNamespace(namespace); - kubernetes.getClient().rbac().clusterRoles().createOrReplaceWithNew() - .editOrNewMetadata() - .withName(namespace) - .endMetadata() - .addNewRule() - .withApiGroups("") - .withResources("namespaces") - .withVerbs("get") - .withResourceNames(namespace) - .endRule() - .done(); - - kubernetes.getClient().rbac().clusterRoleBindings().createOrReplaceWithNew() - .editOrNewMetadata() - .withName(namespace) - .endMetadata() - .addNewSubject() - .withApiGroup("rbac.authorization.k8s.io") - .withKind("User") - .withName(user.getUsername()) - .endSubject() - .editOrNewRoleRef() - .withApiGroup("rbac.authorization.k8s.io") - .withKind("ClusterRole") - .withName(namespace) - .endRoleRef() - .done(); - - kubernetes.getClient().rbac().roleBindings().inNamespace(namespace).createOrReplaceWithNew() - .editOrNewMetadata() - .withName("pepa-admin") - .withNamespace(namespace) - .endMetadata() - .addNewSubject() - .withApiGroup("rbac.authorization.k8s.io") - .withKind("User") - .withName(user.getUsername()) - .endSubject() - .editOrNewRoleRef() - .withApiGroup("rbac.authorization.k8s.io") - .withKind("ClusterRole") - .withName("enmasse.io:tenant-edit") - .endRoleRef() - .done(); - - UserCredentials messagingUser = new UserCredentials("pepa", "zdepa"); - boolean success = false; - AddressSpace addressSpace = null; - try { - KubeCMDClient.loginUser(user.getUsername(), user.getPassword()); - - addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-api") - .withNamespace(namespace) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_MEDIUM) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), user); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - - resourcesManager.createOrUpdateUser(addressSpace, messagingUser); - - consolePage.openAddressList(addressSpace); - - List
addresses = generateQueueTopicList(addressSpace, "test", IntStream.range(0, addressCount)); - consolePage.createAddresses(addresses.toArray(new Address[0])); - AddressUtils.waitForDestinationsReady(addresses.toArray(new Address[0])); - - clientsList = attachClients(addressSpace, addresses, messagingUser); - - consolePage.switchToConnectionTab(); - TestUtils.waitUntilConditionOrFail(() -> consolePage.getConnectionItems().stream() - .allMatch(c -> c.getReceivers() > 0), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for connections count"); - - consolePage.switchToAddressTab(); - consolePage.openClientsList(addresses.get(1)); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getClientItems().stream() - .noneMatch(c -> Strings.isNullOrEmpty(c.getContainerId())), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for clients count"); - - consolePage.openConsolePage(); - success = true; - } finally { - try { - if (!success) { - GlobalLogCollector testDirLogCollector = new GlobalLogCollector(kubernetes, TestUtils.getFailedTestLogsPath(TestInfo.getInstance().getActualTest()), environment.namespace(), false); - testDirLogCollector.collectLogsOfPodsByLabels(environment.namespace(), null, - Collections.singletonMap(LabelKeys.INFRA_UUID, AddressSpaceUtils.getAddressSpaceInfraUuid(addressSpace))); - } - consolePage.deleteAddressSpace(addressSpace); - } finally { - KubeCMDClient.loginUser(environment.getApiToken()); - KubeCMDClient.switchProject(environment.namespace()); - kubernetes.deleteNamespace(namespace); - kubernetes.getClient().rbac().clusterRoleBindings().withName(namespace).delete(); - kubernetes.getClient().rbac().clusterRoles().withName(namespace).delete(); - } - } - } - - protected void doTestCreateAddrSpaceNonClusterAdmin() throws Exception { - int addressCount = 4; - String namespace = "test-namespace"; - UserCredentials user = Credentials.userCredentials(); - UserCredentials messagingUser = new UserCredentials("pepa", "zdepa"); - KubeCMDClient.runOnCluster("create", "rolebinding", "clients-admin", "--clusterrole", "admin", "--user", user.getUsername(), "--namespace", SystemtestsKubernetesApps.MESSAGING_PROJECT); - boolean success = false; - AddressSpace addressSpace = null; - try { - KubeCMDClient.loginUser(user.getUsername(), user.getPassword()); - KubeCMDClient.createNamespace(namespace); - - addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-api") - .withNamespace(namespace) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_MEDIUM) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), user); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - - resourcesManager.createOrUpdateUser(addressSpace, messagingUser); - - consolePage.openAddressList(addressSpace); - - List
addresses = generateQueueTopicList(addressSpace, "test", IntStream.range(0, addressCount)); - consolePage.createAddresses(addresses.toArray(new Address[0])); - AddressUtils.waitForDestinationsReady(addresses.toArray(new Address[0])); - - clientsList = attachClients(addressSpace, addresses, messagingUser); - - consolePage.switchToConnectionTab(); - TestUtils.waitUntilConditionOrFail(() -> consolePage.getConnectionItems().stream() - .allMatch(c -> c.getReceivers() > 0), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for connections count"); - - consolePage.switchToAddressTab(); - consolePage.openClientsList(addresses.get(1)); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getClientItems().stream() - .noneMatch(c -> Strings.isNullOrEmpty(c.getContainerId())), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for clients count"); - - consolePage.openConsolePage(); - success = true; - } finally { - try { - if (!success) { - GlobalLogCollector testDirLogCollector = new GlobalLogCollector(kubernetes, TestUtils.getFailedTestLogsPath(TestInfo.getInstance().getActualTest()), environment.namespace(), false); - testDirLogCollector.collectLogsOfPodsByLabels(environment.namespace(), null, - Collections.singletonMap(LabelKeys.INFRA_UUID, AddressSpaceUtils.getAddressSpaceInfraUuid(addressSpace))); - } - consolePage.deleteAddressSpace(addressSpace); - } finally { - KubeCMDClient.loginUser(environment.getApiToken()); - KubeCMDClient.switchProject(environment.namespace()); - kubernetes.deleteNamespace(namespace); - } - } - } - - protected void doTestRestrictAddressSpaceView() throws Exception { - String namespace = "test-namespace"; - UserCredentials user = Credentials.userCredentials(); - AddressSpace addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-api-2") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan(AddressSpacePlans.BROKERED) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - resourcesManager.createAddressSpace(addressSpace); - try { - KubeCMDClient.loginUser(user.getUsername(), user.getPassword()); - KubeCMDClient.createNamespace(namespace); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), user); - consolePage.openConsolePage(); - assertNull(consolePage.getAddressSpaceItem(addressSpace)); - - } finally { - KubeCMDClient.loginUser(environment.getApiToken()); - KubeCMDClient.switchProject(environment.namespace()); - kubernetes.deleteNamespace(namespace); - } - } - - protected void doEditAddressSpace() throws Exception { - AddressSpace addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-api") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_MEDIUM) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - resourcesManager.addToAddressSpaces(addressSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - assertEquals(AddressSpacePlans.STANDARD_MEDIUM, - resourcesManager.getAddressSpace(addressSpace.getMetadata().getName()).getSpec().getPlan()); - String currentConfig = resourcesManager.getAddressSpace(addressSpace.getMetadata().getName()).getSpec().getPlan(); - consolePage.changeAddressSpacePlan(addressSpace, AddressSpacePlans.STANDARD_UNLIMITED); - AddressSpaceUtils.waitForAddressSpaceConfigurationApplied(addressSpace, currentConfig); - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - assertEquals(AddressSpacePlans.STANDARD_UNLIMITED, - resourcesManager.getAddressSpace(addressSpace.getMetadata().getName()).getSpec().getPlan()); - - consolePage.changeAuthService(addressSpace, "none-authservice", AuthenticationServiceType.NONE); - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - assertEquals("none-authservice", - resourcesManager.getAddressSpace(addressSpace.getMetadata().getName()).getSpec().getAuthenticationService().getName()); - } - - protected void doTestViewCustomPlans() throws Exception { - final String queuePlanName1 = "web-custom-plan-queue-1"; - final String queuePlanName2 = "web-custom-plan-queue-2"; - final String addressSpacePlanName = "web-addressspace-plan"; - //Custom address plans - AddressPlan testQueuePlan1 = PlanUtils.createAddressPlanObject(queuePlanName1, - AddressType.QUEUE, - Arrays.asList( - new ResourceRequest("broker", 0.001), - new ResourceRequest("router", 0.0002))); - AddressPlan testQueuePlan2 = PlanUtils.createAddressPlanObject(queuePlanName2, - AddressType.QUEUE, - Arrays.asList( - new ResourceRequest("broker", 0.01), - new ResourceRequest("router", 0.002))); - - getResourceManager().createAddressPlan(testQueuePlan1); - getResourceManager().createAddressPlan(testQueuePlan2); - - //Custom addressspace plan - List resources = Arrays.asList( - new ResourceAllowance("broker", 10_000), - new ResourceAllowance("router", 10_000), - new ResourceAllowance("aggregate", 10_000)); - List addressPlans = Arrays.asList(testQueuePlan1, testQueuePlan2); - - AddressSpacePlan addressSpacePlan = PlanUtils.createAddressSpacePlanObject(addressSpacePlanName, "default", AddressSpaceType.STANDARD, resources, addressPlans); - getResourceManager().createAddressSpacePlan(addressSpacePlan); - - AddressSpace addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-api") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(addressSpacePlanName) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withType(AddressType.QUEUE.toString()) - .withAddress("test-queue") - .withPlan(queuePlanName1) - .endSpec() - .build(); - - getResourceManager().addToAddressSpaces(addressSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - assertEquals(addressSpacePlanName, - getResourceManager().getAddressSpace(addressSpace.getMetadata().getName()).getSpec().getPlan()); - - consolePage.openAddressList(addressSpace); - consolePage.createAddress(queue); - - AddressWebItem addressWebItem = consolePage.getAddressItem(queue); - selenium.clickOnItem(addressWebItem.getActionDropDown()); - selenium.clickOnItem(addressWebItem.getEditMenuItem()); - selenium.clickOnItem(selenium.getWebElement(consolePage::getEditAddrPlan), "Edit address plan"); - assertTrue(selenium.getDriver().findElement(By.xpath("//option[@value='" + queuePlanName1 + "']")).getText().contains(queuePlanName1)); - } - - protected void doTestFilterAddrSpace() throws Exception { - int addressSpaceCount = 2; - AddressSpace brokered = new AddressSpaceBuilder() - .withNewMetadata() - .withName("brokered-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan(AddressSpacePlans.BROKERED) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - AddressSpace standard = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - resourcesManager.createAddressSpace(brokered, standard); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(addressSpaceCount)); - - consolePage.addFilter(FilterType.NAMESPACE, "blah"); - assertThat("Console should show empty list", consolePage.getAddressSpaceItems().size(), is(0)); - - consolePage.removeAllFilters(); - - consolePage.addFilter(FilterType.TYPE, AddressSpaceType.BROKERED.toString()); - assertThat("Console should show not empty list", consolePage.getAddressSpaceItems().size(), is(addressSpaceCount / 2)); - - consolePage.addFilter(FilterType.TYPE, AddressSpaceType.STANDARD.toString()); - assertThat("Console should show not empty list", consolePage.getAddressSpaceItems().size(), is(addressSpaceCount / 2)); - - consolePage.removeAllFilters(); - - consolePage.addFilter(FilterType.NAME, "brokered"); - assertThat("Console should show not empty list", consolePage.getAddressSpaceItems().size(), is(addressSpaceCount / 2)); - - consolePage.addFilter(FilterType.NAME, "standard"); - assertThat("Console should show not empty list", consolePage.getAddressSpaceItems().size(), is(addressSpaceCount)); - - consolePage.deleteSelectedAddressSpaces(brokered, standard); - assertThat("Console should show empty list", consolePage.getAddressSpaceItems().size(), is(0)); - - WebElement emptyAddessSpace = selenium.getWebElement(() -> consolePage.getEmptyAddSpace()); - assertTrue(emptyAddessSpace.isDisplayed()); - } - - protected void doTestHelpLink() throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - String expectedUrl = environment.enmasseDocs(); - String actualLink = consolePage.getHelpLink(); - - assertEquals(expectedUrl, actualLink); - - if (expectedUrl.contains("enmasse.io")) { - consolePage.openHelpLink(expectedUrl); - } - - } - - protected void doTestFilterAddressSpaceStatus() throws Exception { - AddressSpace standard1 = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-1-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan(AddressSpacePlans.BROKERED) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - AddressSpace standard2 = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-2-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - AddressSpace failed = new AddressSpaceBuilder() - .withNewMetadata() - .withName("failed-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan("unknown") - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - - resourcesManager.createAddressSpace(standard1, false); - resourcesManager.createAddressSpace(standard2, false); - - selenium.waitUntilItemPresent(30, () -> consolePage.getAddressSpaceItem(standard1)); - selenium.waitUntilItemPresent(30, () -> consolePage.getAddressSpaceItem(standard2)); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - - consolePage.addFilter(FilterType.STATUS, "Active"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(0)); - - consolePage.addFilter(FilterType.STATUS, "Configuring"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - - resourcesManager.waitForAddressSpaceReady(standard1); - resourcesManager.waitForAddressSpaceReady(standard2); - - consolePage.removeAllFilters(); - - selenium.waitUntilItemPresent(30, () -> consolePage.getAddressSpaceItem(standard1)); - selenium.waitUntilItemPresent(30, () -> consolePage.getAddressSpaceItem(standard2)); - - consolePage.addFilter(FilterType.STATUS, "Active"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - - resourcesManager.createAddressSpace(failed, false); - - consolePage.removeAllFilters(); - - selenium.waitUntilItemPresent(30, () -> consolePage.getAddressSpaceItem(failed)); - - consolePage.addFilter(FilterType.STATUS, "Active"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - - consolePage.addFilter(FilterType.STATUS, "Pending"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(1)); - - consolePage.addFilter(FilterType.STATUS, "Terminating"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(0)); - consolePage.removeAllFilters(); - - consolePage.addFilter(FilterType.NAME, "standard"); - consolePage.addFilter(FilterType.NAMESPACE, kubernetes.getInfraNamespace()); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - consolePage.addFilter(FilterType.STATUS, "Active"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - consolePage.addFilter(FilterType.TYPE, "Standard"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(1)); - consolePage.addFilter(FilterType.STATUS, "Pending"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(0)); - } - - protected void doTestListEndpoints() throws Exception { - AddressSpace addrSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-1-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - resourcesManager.addToAddressSpaces(addrSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addrSpace); - consolePage.openEndpointList(addrSpace); - consolePage.getEndpointItems(); - - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging")).getHost()); - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging-wss").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging-wss")).getHost()); - } - - protected void doTestEndpointSystemProvided() throws Exception { - AddressSpace addrSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-2-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .withEndpoints(AddressSpaceUtils.createEndpoint("messaging", new CertSpecBuilder() - .withProvider(CertProvider.selfsigned.name()) - .build(), null, "amqps")) - .endSpec() - .build(); - - resourcesManager.addToAddressSpaces(addrSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addrSpace); - consolePage.openEndpointList(addrSpace); - consolePage.getEndpointItems(); - - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging")).getHost()); - } - - protected void doTestEndpointOpenshiftProvided() throws Exception { - UserCredentials user = new UserCredentials("pepa", "kornys"); - AddressSpace addrSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-3-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .withEndpoints( - AddressSpaceUtils.createEndpoint("messaging", new CertSpecBuilder() - .withProvider(CertProvider.openshift.name()) - .build(), null, "amqps"), - AddressSpaceUtils.createEndpoint("messaging-wss", new CertSpecBuilder() - .withProvider(CertProvider.openshift.name()) - .build(), null, "https")) - .endSpec() - .build(); - - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addrSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addrSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withType(AddressType.QUEUE.toString()) - .withAddress("test-queue") - .withPlan(DestinationPlan.STANDARD_SMALL_QUEUE) - .endSpec() - .build(); - - resourcesManager.addToAddressSpaces(addrSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addrSpace); - - resourcesManager.createOrUpdateUser(addrSpace, user); - - consolePage.openAddressList(addrSpace); - consolePage.createAddress(queue); - - consolePage.switchToEndpointTab(); - consolePage.getEndpointItems(); - - getClientUtils().assertCanConnect(addrSpace, user, Collections.singletonList(queue), resourcesManager); - - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging-wss").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging-wss")).getHost()); - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging")).getHost()); - } - - protected void doTestEndpointCustomCertsProvided() throws Exception { - CertBundle bundle = OpenSSLUtil.createCertBundle("kornys"); - - AddressSpace addrSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-4-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .withEndpoints( - AddressSpaceUtils.createEndpoint("messaging", new CertSpecBuilder() - .withProvider(CertProvider.certBundle.name()) - .withTlsCert(bundle.getCertB64()) - .withTlsKey(bundle.getKeyB64()) - .build(), null, "amqps")) - .endSpec() - .build(); - - resourcesManager.addToAddressSpaces(addrSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addrSpace); - consolePage.openEndpointList(addrSpace); - consolePage.getEndpointItems(); - - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging")).getHost()); - } - - //============================================================================================ - //============================ do test methods for address part ============================== - //============================================================================================ - - protected void doTestAddressSnippet(AddressSpaceType addressSpaceType, String destinationPlan) throws Exception { - AddressSpace addressSpace = generateAddressSpaceObject(addressSpaceType); - resourcesManager.createAddressSpace(addressSpace); - - Address address = generateAddressObject(addressSpace, destinationPlan); - getAndExecAddressDeploymentSnippet(addressSpace, address); - AddressUtils.waitForDestinationsReady(address); - AddressUtils.isAddressReady(addressSpace, address); - resourcesManager.deleteAddresses(address); - resourcesManager.deleteAddressSpace(addressSpace); - } - - protected void doTestCreateDeleteAddress(AddressSpace addressSpace, Address... destinations) throws Exception { - Kubernetes.getInstance().getAddressClient().inNamespace(addressSpace.getMetadata(). - getNamespace()).list().getItems().forEach(address -> log.info("Add from list: " + address)); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - for (Address dest : destinations) { - consolePage.createAddress(dest); - } - for (Address dest : destinations) { - consolePage.deleteAddress(dest); - } - } - - protected void doTestAddressStatus(AddressSpace addressSpace, Address destination) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddress(destination, false); - Thread.sleep(5000); - assertThat("Console failed, expected PENDING or READY state", - consolePage.getAddressItem(destination).getStatus(), - either(is(AddressStatus.PENDING)).or(is(AddressStatus.READY))); - - AddressUtils.waitForDestinationsReady(new TimeoutBudget(5, TimeUnit.MINUTES), destination); - Thread.sleep(5000); - assertEquals(AddressStatus.READY, consolePage.getAddressItem(destination).getStatus(), - "Console failed, expected READY state"); - } - - protected void doTestFilterAddressesByType(AddressSpace addressSpace) throws Exception { - int addressCount = 4; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddressesAndWait(addresses.toArray(new Address[0])); - assertThat(String.format("Console failed, does not contain %d addresses", addressCount), - consolePage.getAddressItems().size(), is(addressCount)); - - consolePage.addFilter(FilterType.TYPE, AddressType.QUEUE.toString()); - List items = consolePage.getAddressItems(); - assertThat(String.format("Console failed, does not contain %d addresses", addressCount / 2), - items.size(), is(addressCount / 2)); //assert correct count - assertAddressType("Console failed, does not contains only address type queue", - items, AddressType.QUEUE); //assert correct type - - consolePage.removeAddressFilter(FilterType.TYPE, AddressType.QUEUE.toString()); - assertThat(String.format("Console failed, does not contain %d addresses", addressCount), - consolePage.getAddressItems().size(), is(addressCount)); - - consolePage.addFilter(FilterType.TYPE, AddressType.TOPIC.toString()); - items = consolePage.getAddressItems(); - assertThat(String.format("Console failed, does not contain %d addresses", addressCount / 2), - items.size(), is(addressCount / 2)); //assert correct count - assertAddressType("Console failed, does not contains only address type topic", - items, AddressType.TOPIC); //assert correct type - - consolePage.removeAddressFilter(FilterType.TYPE, AddressType.TOPIC.toString()); - assertThat(String.format("Console failed, does not contain %d addresses", addressCount), - consolePage.getAddressItems().size(), is(addressCount)); - } - - protected void doTestFilterAddressesByName(AddressSpace addressSpace) throws Exception { - int addressCount = 4; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddressesAndWait(addresses.toArray(new Address[0])); - - String subText = "queue"; - consolePage.addFilter(FilterType.NAME, subText); - List items = consolePage.getAddressItems(); - assertEquals(addressCount / 2, items.size(), - String.format("Console failed, does not contain %d addresses", addressCount / 2)); - assertAddressName("Console failed, does not contain addresses contain " + subText, items, subText); - - subText = "topic"; - consolePage.addFilter(FilterType.NAME, subText); - items = consolePage.getAddressItems(); - assertEquals(addressCount, items.size(), - String.format("Console failed, does not contain %d addresses", addressCount)); - - - consolePage.removeAddressFilter(FilterType.NAME, "queue"); - items = consolePage.getAddressItems(); - assertEquals(addressCount / 2, items.size(), - String.format("Console failed, does not contain %d addresses", addressCount / 2)); - assertAddressName("Console failed, does not contain addresses contain " + subText, items, subText); - - consolePage.removeAllFilters(); - assertEquals(addressCount, consolePage.getAddressItems().size(), - String.format("Console failed, does not contain %d addresses", addressCount)); - - consolePage.deleteSelectedAddresses(addresses.toArray(new Address[0])); - assertEquals(0, consolePage.getAddressItems().size(), - String.format("Console failed, does not contain %d addresses", 0)); - } - - - protected void doTestFilterAddressesByStatus(AddressSpace addressSpace) throws Exception { - int addressCount = 4; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - - String nonexistentPlan = "foo-plan"; - IntStream.range(0, addressCount / 2) - .forEach(i -> { - addresses.get(i).getSpec().setPlan(nonexistentPlan); - ; - }); - List
goodAddresses = addresses.stream() - .filter(a -> !a.getSpec().getPlan().equals(nonexistentPlan)) - .collect(Collectors.toList()); - List
badAddresses = addresses.stream() - .filter(a -> a.getSpec().getPlan().equals(nonexistentPlan)) - .collect(Collectors.toList()); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - getResourceManager().appendAddresses(true, goodAddresses.toArray(new Address[0])); - getResourceManager().appendAddresses(false, badAddresses.toArray(new Address[0])); - - TestUtils.waitUntilCondition(() -> consolePage.getAddressItems().size() == addressCount, Duration.ofSeconds(30), Duration.ofMillis(500)); - - consolePage.addFilter(FilterType.STATUS, "Pending"); - List items = consolePage.getAddressItems(); - assertEquals(badAddresses.size(), items.size(), - String.format("Console failed, does not contain %d addresses when %s filter", badAddresses.size(), "Pending")); - - consolePage.addFilter(FilterType.STATUS, "Active"); - items = consolePage.getAddressItems(); - assertEquals(goodAddresses.size(), items.size(), - String.format("Console failed, does not contain %d addresses when %s filter", goodAddresses.size(), "Active")); - } - - protected void doTestPurgeMessages(AddressSpace addressSpace) throws Exception { - Address queue1 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue1")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue1") - .withPlan(addressSpace.getSpec().getType().equals(AddressSpaceType.BROKERED.toString()) ? DestinationPlan.BROKERED_QUEUE : DestinationPlan.STANDARD_SMALL_QUEUE) - .endSpec() - .build(); - - Address queue2 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue2")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue2") - .withPlan(addressSpace.getSpec().getType().equals(AddressSpaceType.BROKERED.toString()) ? DestinationPlan.BROKERED_QUEUE : DestinationPlan.STANDARD_SMALL_QUEUE) - .endSpec() - .build(); - - Address queue3 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue3")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue3") - .withPlan(addressSpace.getSpec().getType().equals(AddressSpaceType.BROKERED.toString()) ? DestinationPlan.BROKERED_QUEUE : DestinationPlan.STANDARD_XLARGE_QUEUE) - .endSpec() - .build(); - - resourcesManager.setAddresses(queue1, queue2, queue3); - - ExternalMessagingClient client = new ExternalMessagingClient() - .withClientEngine(new RheaClientSender()) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(addressSpace)) - .withCredentials(defaultCredentials) - .withCount(1000) - .withMessageBody("msg no. %d") - .withTimeout(30); - - assertTrue(client.withAddress(queue1).run(false)); - assertTrue(client.withAddress(queue2).run(false)); - assertTrue(client.withAddress(queue3).run(false)); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - assertThat(String.format("Console failed, does not contain %d addresses", 3), - consolePage.getAddressItems().size(), is(3)); - - consolePage.purgeSelectedAddresses(queue1, queue3); - - selenium.waitUntilPropertyPresent(60, 0, () -> consolePage.getAddressItem(queue1).getMessagesStored()); - selenium.waitUntilPropertyPresent(60, 0, () -> consolePage.getAddressItem(queue3).getMessagesStored()); - - assertTrue(client.withAddress(queue2).withClientEngine(new RheaClientReceiver()).run(false)); - assertThat(client.getMessages().size(), is(1000)); - assertTrue(client.withAddress(queue3).withTimeout(10).withClientEngine(new RheaClientReceiver()).run(false)); - assertThat(client.getMessages().size(), is(0)); - } - - protected void doTestConnectionClose(AddressSpace addressSpace) throws Exception { - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue1") - .withPlan(addressSpace.getSpec().getType().equals(AddressSpaceType.BROKERED.toString()) ? DestinationPlan.BROKERED_QUEUE : DestinationPlan.STANDARD_SMALL_QUEUE) - .endSpec() - .build(); - - resourcesManager.setAddresses(queue); - - ExternalMessagingClient client = new ExternalMessagingClient() - .withClientEngine(new RheaClientReceiver()) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(addressSpace)) - .withCredentials(defaultCredentials) - .withCount(1) - .withReconnect(false) - .withTimeout(180); - - client.withAddress(queue).runAsync(false); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openConnectionList(addressSpace); - - selenium.waitUntilPropertyPresent(60, 1, () -> consolePage.getConnectionItems().size()); - - Optional connRow = consolePage.getConnectionItems().stream().findFirst(); - assertThat("Connection item not found", connRow.isPresent(), is(true)); - - consolePage.closeSelectedConnection(connRow.get()); - - selenium.waitUntilPropertyPresent(60, 0, () -> consolePage.getConnectionItems().size()); - } - - protected void doTestEditAddress(AddressSpace addressSpace, Address address, String plan) throws Exception { - resourcesManager.setAddresses(address); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.changeAddressPlan(address, plan); - Thread.sleep(10_000); - AddressUtils.waitForDestinationsReady(address); - assertThat(resourcesManager.getAddress(kubernetes.getInfraNamespace(), address).getSpec().getPlan(), is(plan)); - } - - protected void doTestDeleteFilteredAddress(AddressSpace addressSpace) throws Exception { - int addressTotal = 2; - - Address destQueue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - Address destTopic = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-topic")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("test-topic") - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddresses(destQueue, destTopic); - - consolePage.addFilter(FilterType.TYPE, AddressType.QUEUE.toString()); - List items = consolePage.getAddressItems(); - - assertEquals(addressTotal / 2, items.size(), - String.format("Console failed, filter does not contain %d addresses", addressTotal / 2)); - - assertAddressName("Console failed, filter does not contain addresses", items, "queue"); - - consolePage.deleteAddress(destQueue); - items = consolePage.getAddressItems(); - assertEquals(0, items.size()); - log.info("filtered address has been deleted and no longer present in filter"); - - consolePage.removeAllFilters(); - items = consolePage.getAddressItems(); - assertEquals(addressTotal / 2, items.size()); - } - - protected void doTestSortAddressesByName(AddressSpace addressSpace) throws Exception { - int addressCount = 4; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddresses(addresses.toArray(new Address[0])); - consolePage.sortAddresses(SortType.NAME, true); - assertSorted("Console failed, items are not sorted by name asc", consolePage.getAddressItems()); - consolePage.sortAddresses(SortType.NAME, false); - assertSorted("Console failed, items are not sorted by name desc", consolePage.getAddressItems(), true); - } - - protected void doTestSortAddressesBySenders(AddressSpace addressSpace) throws Exception { - doTestSortAddresses(addressSpace, - SortType.SENDERS, - this::attachClients, - a -> a.getSendersCount() > 0, - Comparator.comparingInt(AddressWebItem::getSendersCount)); - } - - protected void doTestSortAddressesByReceivers(AddressSpace addressSpace) throws Exception { - doTestSortAddresses(addressSpace, - SortType.RECEIVERS, - this::attachClients, - a -> a.getReceiversCount() > 0, - Comparator.comparingInt(AddressWebItem::getReceiversCount)); - } - - private void doTestSortAddresses(AddressSpace addressSpace, SortType sortType, ClientAttacher attacher, Predicate readyCondition, Comparator sortingComparator) throws Exception { - int addressCount = 4; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - - getResourceManager().setAddresses(addresses.toArray(new Address[0])); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - - assertEquals(addressCount, consolePage.getAddressItems().size(), "Unexpected number of addresses present before attaching clients"); - - clientsList = attacher.attach(addressSpace, addresses, defaultCredentials); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getAddressItems().stream() - .allMatch(readyCondition), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for addresses count"); - - consolePage.sortAddresses(sortType, true); - assertSorted("Console failed, items are not sorted by count of senders asc", - consolePage.getAddressItems(), - sortingComparator); - - consolePage.sortAddresses(sortType, false); - assertSorted("Console failed, items are not sorted by count of senders desc", - consolePage.getAddressItems(), - true, - sortingComparator); - } - - protected void doTestSortConnectionsBySenders(AddressSpace addressSpace) throws Exception { - doTestSortConnections(addressSpace, - SortType.SENDERS, - this::attachClients, - c -> c.getSenders() > 0, - Comparator.comparingInt(ConnectionWebItem::getSenders)); - } - - protected void doTestSortConnectionsByReceivers(AddressSpace addressSpace) throws Exception { - doTestSortConnections(addressSpace, - SortType.RECEIVERS, - this::attachClients, - c -> c.getReceivers() > 0, - Comparator.comparingInt(ConnectionWebItem::getReceivers)); - } - - protected void doTestAddressLinks(AddressSpace addressSpace, String destinationPlan) throws Exception { - Address address = generateAddressObject(addressSpace, destinationPlan); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddress(address); - consolePage.openClientsList(address); - assertThat("Link table is not empty!", consolePage.isClientListEmpty()); - int link_count = attachClients(addressSpace, address, defaultCredentials); - selenium.waitUntilPropertyPresent(60, link_count, () -> consolePage.getClientItems().size()); - assertThat(consolePage.getClientItems().size(), is(link_count)); - } - - protected void doTestAddressLinksWithMismatchedAddressResourceNameAndSuffix(AddressSpace addressSpace, String destinationPlan) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - Address address = doCreateAddressWithMismatchedAddressResourceNameAndSuffix(addressSpace, destinationPlan); - consolePage.openClientsList(address); - assertThat("Link table is not empty!", consolePage.isClientListEmpty()); - int link_count = attachClients(addressSpace, address, defaultCredentials); - selenium.waitUntilPropertyPresent(60, link_count, () -> consolePage.getClientItems().size()); - assertThat(consolePage.getClientItems().size(), is(link_count)); - } - - private Address doCreateAddressWithMismatchedAddressResourceNameAndSuffix(AddressSpace addressSpace, String destinationPlan) throws Exception { - Address address = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queues") - .withPlan(destinationPlan) - .endSpec() - .build(); - getResourceManager().setAddresses(address); - return address; - } - - private void doTestSortConnections(AddressSpace addressSpace, SortType sortType, ClientAttacher attacher, Predicate readyCondition, Comparator sortingComparator) throws Exception { - int addressCount = 2; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - - getResourceManager().setAddresses(addresses.toArray(new Address[0])); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openConnectionList(addressSpace); - - assertEquals(0, consolePage.getConnectionItems().size(), "Unexpected number of connections present before attaching clients"); - - clientsList = attacher.attach(addressSpace, addresses, defaultCredentials); - - selenium.waitUntilPropertyPresent(60, clientsList.size(), () -> consolePage.getConnectionItems().size()); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getConnectionItems().stream() - .allMatch(readyCondition), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for connections count"); - - consolePage.sortConnections(sortType, true); - assertSorted("Console failed, items are not sorted by count of senders asc", - consolePage.getConnectionItems(), - sortingComparator); - - consolePage.sortConnections(sortType, false); - assertSorted("Console failed, items are not sorted by count of senders desc", - consolePage.getConnectionItems(), - true, - sortingComparator); - } - - protected void doTestFilterConnectionsByContainerId(AddressSpace addressSpace) throws Exception { - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-via-web")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-via-web") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - getResourceManager().setAddresses(dest); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openConnectionList(addressSpace); - - int connectionCount = 5; - clientsList = new ArrayList<>(); - clientsList.add(getClientUtils().attachConnector(addressSpace, dest, connectionCount, 1, 1, defaultCredentials, 360)); - selenium.waitUntilPropertyPresent(60, connectionCount, () -> consolePage.getConnectionItems().size()); - - String containerID = consolePage.getConnectionItems().get(0).getContainerId(); - - consolePage.addConnectionsFilter(FilterType.CONTAINER, containerID); - assertThat(String.format("Console failed, does not contain %d connections", 1), - consolePage.getConnectionItems().size(), is(1)); - - consolePage.removeAllFilters(); - assertThat(String.format("Console failed, does not contain %d connections", connectionCount), - consolePage.getConnectionItems().size(), is(connectionCount)); - } - - protected void doTestFilterClientsByContainerId(AddressSpace addressSpace) throws Exception { - Address address = generateAddressObject(addressSpace, DestinationPlan.STANDARD_SMALL_QUEUE); - getResourceManager().setAddresses(address); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.openClientsList(address); - - int connectionCount = 2; - clientsList = new ArrayList<>(); - clientsList.add(getClientUtils().attachConnector(addressSpace, address, connectionCount, 1, 1, defaultCredentials, 360)); - selenium.waitUntilPropertyPresent(60, connectionCount * 2, () -> consolePage.getClientItems().size()); - - String containerId = consolePage.getClientItems().get(0).getContainerId(); - - consolePage.addClientsFilter(FilterType.CONTAINER, containerId); - assertThat(String.format("Console failed, does not contain %d clients", 1), - consolePage.getClientItems().size(), is(2)); - - consolePage.removeAllFilters(); - - assertThat(String.format("Console failed, does not contain %d clients", connectionCount), - consolePage.getClientItems().size(), is(connectionCount * 2)); - } - - - protected void doTestFilterClientsByName(AddressSpace addressSpace) throws Exception { - Address address = generateAddressObject(addressSpace, DestinationPlan.STANDARD_SMALL_QUEUE); - getResourceManager().setAddresses(address); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.openClientsList(address); - - int connectionCount = 2; - clientsList = new ArrayList<>(); - clientsList.add(getClientUtils().attachConnector(addressSpace, address, connectionCount, 1, 1, defaultCredentials, 360)); - selenium.waitUntilPropertyPresent(60, connectionCount * 2, () -> consolePage.getClientItems().size()); - - String containerId = consolePage.getClientItems().get(0).getName(); - - consolePage.addClientsFilter(FilterType.NAME, containerId); - assertThat(String.format("Console failed, does not contain %d clients", 1), - consolePage.getClientItems().size(), is(1)); - - consolePage.removeAllFilters(); - - assertThat(String.format("Console failed, does not contain %d clients", connectionCount), - consolePage.getClientItems().size(), is(connectionCount * 2)); - } - - protected void doTestGoneAwayPageAfterConnectionClose(AddressSpace addressSpace, ExtensionContext context) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - Address address = generateAddressObject(addressSpace, DestinationPlan.STANDARD_LARGE_QUEUE); - consolePage.openAddressList(addressSpace); - consolePage.createAddress(address); - clientsList = attachClients(addressSpace, - Collections.singletonList(address), defaultCredentials); - consolePage.switchToConnectionTab(); - selenium.waitUntilPropertyPresent(30, 3, () -> consolePage.getConnectionItems().size()); - consolePage.openConnection(consolePage.getConnectionItems().get(0).getHost()); - Pod pod = kubernetes.getClient().pods() - .inNamespace(SystemtestsKubernetesApps.MESSAGING_CLIENTS).list().getItems().get(0); - kubernetes.deletePod(SystemtestsKubernetesApps.MESSAGING_CLIENTS, pod.getMetadata().getName()); - waitForPodsToTerminate(Collections.singletonList(pod.getMetadata().getUid())); - - consolePage.awaitGoneAwayPage(); - } - - protected void doTestSortConnectionsByContainerId(AddressSpace addressSpace) throws Exception { - doTestSortConnections(addressSpace, SortType.CONTAINER_ID, - this::attachClients, - c -> c.getContainerId() != null, - Comparator.comparing(ConnectionWebItem::getContainerId)); - } - - protected void doTestClientsMetrics(AddressSpace addressSpace) throws Exception { - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-in-and-out")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-in-and-out") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - - getResourceManager().setAddresses(dest); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - - assertEquals(1, consolePage.getAddressItems().size(), "Unexpected number of addresses present before attaching clients"); - - //this creates 11 senders and 11 receivers in total - clientsList = this.attachClients(addressSpace, Arrays.asList(dest), defaultCredentials); - var senderCount = 11; - var receiverCount = 11; - - selenium.waitUntilPropertyPresent(60, senderCount, () -> consolePage.getAddressItem(dest).getSendersCount()); - selenium.waitUntilPropertyPresent(60, receiverCount, () -> consolePage.getAddressItem(dest).getReceiversCount()); - - assertAll( - () -> assertEquals(receiverCount, consolePage.getAddressItem(dest).getReceiversCount(), - String.format("Console failed, does not contain %d receivers", 10)), - () -> assertEquals(senderCount, consolePage.getAddressItem(dest).getSendersCount(), - String.format("Console failed, does not contain %d senders", 5))); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getAddressItem(dest).getMessagesIn() >= 5, - Duration.ofSeconds(180), - Duration.ofSeconds(3), - () -> "Failed to wait for messagesIn/sec to reach 1"); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getAddressItem(dest).getMessagesOut() >= 5, - Duration.ofSeconds(180), - Duration.ofSeconds(3), - () -> "Failed to wait for messagesOut/sec to reach 1"); - - } - - protected void doTestMessagesStoredMetrics(AddressSpace addressSpace) throws Exception { - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-stored-msg")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-stored-msg") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - getResourceManager().setAddresses(dest); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - - assertEquals(1, consolePage.getAddressItems().size(), "Unexpected number of addresses present before attaching clients"); - - AmqpClient amqpClient = getResourceManager().getAmqpClientFactory().createQueueClient(addressSpace); - var countMessages = 50; - List msgs = TestUtils.generateMessages(countMessages); - Count predicate = new Count<>(msgs.size()); - Future numSent = amqpClient.sendMessages(dest.getSpec().getAddress(), msgs, predicate); - long timeoutMs = countMessages * ClientUtils.ESTIMATE_MAX_MS_PER_MESSAGE; - assertNotNull(numSent, "Sending messages didn't start"); - int actual = 0; - try { - actual = numSent.get(timeoutMs, TimeUnit.MILLISECONDS); - } catch (TimeoutException t) { - logCollector.collectRouterState("runQueueTestSend"); - fail("Sending messages timed out after sending " + predicate.actual()); - } - assertThat("Wrong count of messages sent", actual, is(msgs.size())); - - selenium.waitUntilPropertyPresent(30, countMessages, () -> consolePage.getAddressItem(dest).getMessagesStored()); - - amqpClient.recvMessages(dest.getSpec().getAddress(), countMessages).get(timeoutMs, TimeUnit.MILLISECONDS); - - selenium.waitUntilPropertyPresent(30, 0, () -> consolePage.getAddressItem(dest).getMessagesStored()); - - } - - protected void doTestSortMessagesCount(AddressSpace addressSpace) throws Exception { - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-stored-msg")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-stored-msg") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - Address dest2 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-stored-msg-2")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-stored-msg-2") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - Address dest3 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-stored-msg-3")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-stored-msg-3") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - getResourceManager().setAddresses(dest, dest2, dest3); - - var countMessages = 50; - AmqpClient amqpClient = getResourceManager().getAmqpClientFactory().createQueueClient(addressSpace); - - Future numSent1 = amqpClient.sendMessages(dest.getSpec().getAddress(), countMessages); - Future numSent2 = amqpClient.sendMessages(dest2.getSpec().getAddress(), countMessages - 10); - Future numSent3 = amqpClient.sendMessages(dest3.getSpec().getAddress(), countMessages - 30); - - assertThat(numSent1.get(1, TimeUnit.MINUTES), is(countMessages)); - assertThat(numSent2.get(1, TimeUnit.MINUTES), is(countMessages - 10)); - assertThat(numSent3.get(1, TimeUnit.MINUTES), is(countMessages - 30)); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - - selenium.waitUntilPropertyPresent(30, countMessages, () -> consolePage.getAddressItem(dest).getMessagesStored()); - selenium.waitUntilPropertyPresent(30, countMessages - 10, () -> consolePage.getAddressItem(dest2).getMessagesStored()); - selenium.waitUntilPropertyPresent(30, countMessages - 30, () -> consolePage.getAddressItem(dest3).getMessagesStored()); - - consolePage.sortAddresses(SortType.STORED_MESSAGES, true); - assertSorted("Addresses are not sorted by stored messages", consolePage.getAddressItems(), Comparator.comparingInt(AddressWebItem::getMessagesStored)); - consolePage.sortAddresses(SortType.STORED_MESSAGES, false); - assertSorted("Addresses are not sorted by stored messages", consolePage.getAddressItems(), true, Comparator.comparingInt(AddressWebItem::getMessagesStored)); - } - - protected void doTestCanOpenConsolePage(AddressSpace addressSpace, UserCredentials credentials, boolean userAllowed) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), credentials); - consolePage.openConsolePage(); - log.info("User {} successfully authenticated", credentials); - - if (userAllowed) { - consolePage.openAddressList(addressSpace); - } else { - try { - consolePage.openAddressList(addressSpace); - fail("Exception not thrown"); - } catch (NullPointerException ex) { - // PASS - } - - throw new IllegalAccessException(); - } - } - - protected void doTestWithStrangeAddressNames(AddressSpace addressSpace, boolean hyphen, boolean longName, AddressType... types) throws Exception { - String testString = null; - if (hyphen) { - testString = String.join("-", Collections.nCopies(2, "10charhere")); - } - if (longName) { - testString = String.join("", Collections.nCopies(5, "10charhere")); - } - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - - for (AddressType type : types) { - int assert_value = 1; - Address dest; - Address dest_topic = null; - if (type == AddressType.SUBSCRIPTION) { - dest_topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "topic-sub" + testString)) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("topic-sub" + testString) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - log.info("Creating topic for subscription"); - consolePage.createAddress(dest_topic); - dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, testString)) - .endMetadata() - .withNewSpec() - .withType("subscription") - .withAddress(testString) - .withTopic(dest_topic.getSpec().getAddress()) - .withPlan(DestinationPlan.STANDARD_SMALL_SUBSCRIPTION) - .endSpec() - .build(); - assert_value = 2; - } else { - dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, type.toString() + "-" + testString)) - .endMetadata() - .withNewSpec() - .withType(type.toString()) - .withAddress(type.toString() + "-" + testString) - .withPlan(getDefaultPlan(type)) - .endSpec() - .build(); - assert_value = 1; - } - - consolePage.createAddress(dest); - assertWaitForValue(assert_value, () -> consolePage.getAddressItems().size(), new TimeoutBudget(120, TimeUnit.SECONDS)); - - if (type.equals(AddressType.SUBSCRIPTION)) { - consolePage.deleteAddress(dest_topic); - } - consolePage.deleteAddress(dest); - assertWaitForValue(0, () -> consolePage.getAddressItems().size(), new TimeoutBudget(20, TimeUnit.SECONDS)); - } - } - - protected void doTestValidAddressNames(AddressSpace addressSpace) throws Exception { - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.openAddressCreationDialog(); - - String validName = "dummy"; - String[] invalidNames = { - "#dummy", - "du#mmy", - "dummy#", - - "*dummy", - "du*mmy", - "dummy*", - - " dummy", - "dum my", - "dummy ", - }; - - for (var name : invalidNames) { - consolePage.fillAddressName(validName); - assertFalse(consolePage.isAddressNameInvalid()); - - consolePage.fillAddressName(name); - assertTrue(consolePage.isAddressNameInvalid(), String.format("Address name %s is not marked as invalid", name)); - } - - String[] validNames = { - "du$mmy", - "du-mmy", - "dummy/foo", - "dum)my", - "dum2my", - - ":dummy", - "du:mmy", - "dummy:", - - ".dummy", - "dum.my", - "dummy.", - }; - - for (String name : validNames) { - consolePage.fillAddressName(validName); - assertFalse(consolePage.isAddressNameInvalid()); - - consolePage.fillAddressName(name); - assertFalse(consolePage.isAddressNameInvalid(), String.format("Address name %s is not marked as valid", name)); - } - } - - protected String getSnippetFirstLine(AddressSpace addressSpace) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.prepareAddressSpaceInstall(addressSpace); - return consolePage.getFirstLineOfDeploymentSnippet().getText(); - } - - protected void getAndExecAddressSpaceDeploymentSnippet(AddressSpace addressSpace) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.prepareAddressSpaceInstall(addressSpace); - String snippet = consolePage.getDeploymentSnippet(); - KubeCMDClient.createCR(Kubernetes.getInstance().getInfraNamespace(), snippet); - } - - protected void getAndExecAddressDeploymentSnippet(AddressSpace addressSpace, Address address) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.prepareAddressCreation(address); - String snippet = consolePage.getDeploymentSnippet(); - KubeCMDClient.createCR(Kubernetes.getInstance().getInfraNamespace(), snippet); - } - - protected void doTestErrorDialog(AddressSpace addressSpace) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - Address address = generateAddressObject(addressSpace, DestinationPlan.STANDARD_SMALL_QUEUE); - consolePage.createAddress(address); - consolePage.createAddress(address); - consolePage.waitForErrorDialogToBePresent(); - assertThat("Error dialog is not present after error situation!", - selenium.getWebElement(consolePage::getDangerAlertElement), notNullValue()); - - } - - protected void doTestOpenShiftWithCustomCert() throws Exception { - String openshiftConfigNamespace = "openshift-config"; - String openshiftIngressNamespace = "openshift-ingress"; - String openshiftIngressOperatorNamespace = "openshift-ingress-operator"; - String openshiftAuthenticationNamespace = "openshift-authentication"; - - Map oauthDeploymentLabels = Map.of(LabelKeys.APP, "oauth-openshift"); - Map oauthRouteLabels = Map.of(LabelKeys.APP, "oauth-openshift"); - Map consoleDeploymentLabels = Map.of(LabelKeys.APP, "enmasse", LabelKeys.NAME, "console"); - - Optional oauth = kubernetes.listDeployments(openshiftAuthenticationNamespace, oauthDeploymentLabels).stream().findFirst(); - assertThat(oauth.isPresent(), is(true)); - - Optional oauthRoute = kubernetes.listRoutes(openshiftAuthenticationNamespace, oauthRouteLabels).stream().findFirst(); - assertThat(oauthRoute.isPresent(), is(true)); - - CertPair originalOauthCert = OpenSSLUtil.downloadCert(oauthRoute.get().getSpec().getHost(), 443); - - String customCaCnName = "custom-ca"; - String customIngressSecretName = "custom-ingress"; - String wildcardSan = String.format("*.%s", environment.kubernetesDomain()); - log.info("Wildcard SAN for custom cert: {}", wildcardSan); - try (CertPair ca = OpenSSLUtil.createSelfSignedCert("/O=io.enmasse/CN=MyCA"); - CertPair unsignedCluster = OpenSSLUtil.createSelfSignedCert("/O=io.enmasse//CN=MyCluster"); - CertSigningRequest csr = OpenSSLUtil.createCsr(unsignedCluster); - CertPair cluster = OpenSSLUtil.signCsr(csr, Collections.singletonList(wildcardSan), ca) - ) { - // Steps from https://docs.openshift.com/container-platform/4.3/authentication/certificates/replacing-default-ingress-certificate.html#replacing-default-ingress_replacing-default-ingress - - assertThat(cluster.getCert().canRead(), is(true)); - assertThat(cluster.getKey().canRead(), is(true)); - - ExecutionResultData ingressSecret = Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "create", "secret", "tls", customIngressSecretName, - "--namespace", openshiftIngressNamespace, - String.format("--cert=%s", cluster.getCert()), - String.format("--key=%s", cluster.getKey())), true); - assertThat("failed to create ingress secret", ingressSecret.getRetCode(), is(true)); - - ExecutionResultData cmCustomCa = Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "create", "configmap", customCaCnName, - "--namespace", openshiftConfigNamespace, - String.format("--from-file=ca-bundle.crt=%s", ca.getCert().getAbsolutePath())), true); - assertThat("failed to create custom-ca configmap", cmCustomCa.getRetCode(), is(true)); - - ExecutionResultData patchProxy = Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "patch", "proxy/cluster", - "--type=merge", - String.format("--patch={\"spec\":{\"trustedCA\":{\"name\":\"%s\"}}}", customCaCnName)), true); - assertThat("failed to patch proxy/cluster", patchProxy.getRetCode(), is(true)); - - ExecutionResultData patchIngress = Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "patch", "ingresscontroller.operator/default", - "--type=merge", - "--namespace", openshiftIngressOperatorNamespace, - String.format("--patch={\"spec\":{\"defaultCertificate\": {\"name\": \"%s\"}}}", customIngressSecretName)), true); - assertThat("failed to patch ingress", patchIngress.getRetCode(), is(true)); - - awaitCertChange(ca, oauth.get(), oauthRoute.get()); - - awaitEnMasseConsoleAvailable("Ensuring console functional after certificate change"); - SeleniumProvider.getInstance().tearDownDrivers(); - SeleniumProvider.getInstance().setupDriver(this.getClass().getSimpleName().toLowerCase().contains("chrome") ? TestUtils.getChromeDriver() : TestUtils.getFirefoxDriver()); - } finally { - Optional bundle = kubernetes.listConfigMaps(Map.of("app", "enmasse")).stream().filter(cm -> "console-trusted-ca-bundle".equals(cm.getMetadata().getName())).findFirst(); - bundle.ifPresent(cm -> log.info("console-trusted-ca-bundle resource version before rollback : {}", cm.getMetadata().getResourceVersion())); - - Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "patch", "proxy/cluster", - "--type=merge", - "--patch={\"spec\":{\"trustedCA\": null}}"), false); - Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "patch", "ingresscontroller.operator/default", - "--type=merge", - "--namespace", openshiftIngressOperatorNamespace, - "--patch={\"spec\":{\"defaultCertificate\": null}}"), false); - Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "delete", "configmap", customCaCnName, - "--namespace", openshiftConfigNamespace), false); - Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "delete", "secret", customIngressSecretName, - "--namespace", openshiftIngressNamespace), false); - - - awaitCertChange(originalOauthCert, oauth.get(), oauthRoute.get()); - awaitEnMasseConsoleAvailable("Ensuring console functional after certificate rollback"); - } - } - - private void awaitEnMasseConsoleAvailable(String forWhat) { - TestUtils.waitUntilCondition(forWhat, waitPhase -> { - try { - doTestCanOpenConsolePage(resourcesManager.getSharedAddressSpace(), clusterUser, true); - return true; - } catch (Exception e) { - return false; - } - }, new TimeoutBudget(5, TimeUnit.MINUTES)); - } - - private void awaitCertChange(CertPair expectedCa, Deployment oauthDeployment, Route oauthRoute) { - TestUtils.waitUntilCondition("Awaiting cert change", waitPhase -> { - try { - KubeCMDClient.loginUser(clusterUser.getUsername(), clusterUser.getUsername()); - verifyCertChange(expectedCa, oauthDeployment, oauthRoute); - return true; - } catch (Exception e) { - return false; - } - }, new TimeoutBudget(5, TimeUnit.MINUTES)); - } - - private void verifyCertChange(CertPair ca, Deployment oauthDeployment, Route oauthRoute) throws Exception { - Optional bundle = kubernetes.listConfigMaps(Map.of("app", "enmasse")).stream().filter(cm -> "console-trusted-ca-bundle".equals(cm.getMetadata().getName())).findFirst(); - bundle.ifPresent(cm -> log.info("console-trusted-ca-bundle resource version : {}", cm.getMetadata().getResourceVersion())); - - log.info("Awaiting openshift oauth to be ready again"); - TestUtils.waitForChangedResourceVersion(new TimeoutBudget(1, TimeUnit.MINUTES), oauthDeployment.getMetadata().getResourceVersion(), - () -> { - Optional upd = kubernetes.listDeployments(oauthDeployment.getMetadata().getNamespace(), oauthDeployment.getMetadata().getLabels()).stream().findFirst(); - assertThat(upd.isPresent(), is(true)); - return upd.get().getMetadata().getResourceVersion(); - }); - - KubeCMDClient.awaitRollout(new TimeoutBudget(3, TimeUnit.MINUTES), oauthDeployment.getMetadata().getNamespace(), oauthDeployment.getMetadata().getName()); - - // await for oauth and verify it uses the correct certificate - if (ca != null) { - String oauthHost = oauthRoute.getSpec().getHost(); - TestUtils.waitUntilCondition(String.format("Await for oauth http endpoint to become ready: %s", oauthHost), waitPhase -> { - List curl = Arrays.asList("curl", - "--cacert", ca.getCert().getAbsolutePath(), - "--verbose", String.format("https://%s", oauthHost)); - ExecutionResultData consolePing = Exec.execute(curl, true); - return consolePing.getRetCode(); - }, new TimeoutBudget(3, TimeUnit.MINUTES)); - } - } - - //============================================================================================ - //============================ Help methods ================================================== - //============================================================================================ - - private AddressSpace generateAddressSpaceObject(AddressSpaceType addressSpaceType) { - return new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-address-space-" + addressSpaceType.toString()) - .withNamespace(Kubernetes.getInstance().getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(addressSpaceType.toString()) - .withPlan(addressSpaceType.toString().equals(AddressSpaceType.BROKERED.toString()) ? - AddressSpacePlans.BROKERED : AddressSpacePlans.STANDARD_MEDIUM) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - } - - private Address generateAddressObject(AddressSpace addressSpace, String destinationPlan) { - return new AddressBuilder() - .withNewMetadata() - .withNamespace(Kubernetes.getInstance().getInfraNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withAddress("test-queue") - .withType("queue") - .withPlan(destinationPlan) - .endSpec() - .build(); - } - - private List
generateQueueTopicList(AddressSpace addressspace, String infix, IntStream range) { - List
addresses = new ArrayList<>(); - range.forEach(i -> { - if (i % 2 == 0) { - addresses.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, String.format("topic-%s-%d", infix, i))) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress(String.format("topic-%s-%d", infix, i)) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build()); - } else { - addresses.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, String.format("queue-%s-%d", infix, i))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress(String.format("queue-%s-%d", infix, i)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build()); - } - }); - return addresses; - } - - /** - * @param addressSpace dest addressspace - * @param destination dest address - * @param userCredentials messaging user credentials - * @return senders + receivers count - * @throws Exception - */ - private int attachClients(AddressSpace addressSpace, Address destination, UserCredentials userCredentials) throws Exception { - final int SENDER_COUNT = 6; - final int RECEIVER_COUNT = 4; - if (addressSpace.getSpec().getPlan().equals(AddressSpacePlans.BROKERED)) { - for (int i = 0; i < SENDER_COUNT; i++) { - getClientUtils().attachSender(addressSpace, destination, userCredentials, 1000, 60000); - if (i < RECEIVER_COUNT) { - getClientUtils().attachReceiver(addressSpace, destination, userCredentials, 1100); - } - } - } else { - getClientUtils().attachConnector(addressSpace, destination, 1, SENDER_COUNT, RECEIVER_COUNT, userCredentials, 60000); - } - return (SENDER_COUNT + RECEIVER_COUNT); - } - - private List attachClients(AddressSpace addressSpace, List
destinations, UserCredentials userCredentials) throws Exception { - List clients = new ArrayList<>(); - for (Address destination : destinations) { - clients.add(getClientUtils().attachConnector(addressSpace, destination, 1, 6, 1, userCredentials, 60000)); - clients.add(getClientUtils().attachConnector(addressSpace, destination, 1, 4, 4, userCredentials, 60000)); - clients.add(getClientUtils().attachConnector(addressSpace, destination, 1, 1, 6, userCredentials, 60000)); - } - Thread.sleep(5000); - return clients; - } - - private void assertAddressType(String message, List allItems, AddressType type) { - assertThat(message, getAddressProperty(allItems, (item -> item.getType().contains(type.toString()))).size(), is(allItems.size())); - } - - private void assertAddressName(String message, List allItems, String subString) { - assertThat(message, getAddressProperty(allItems, (item -> item.getAddress().contains(subString))).size(), is(allItems.size())); - } - - private List getConnectionProperty(List allItems, Predicate f) { - return allItems.stream().filter(f).collect(Collectors.toList()); - } - - private List getAddressProperty(List allItems, Predicate f) { - return allItems.stream().filter(f).collect(Collectors.toList()); - } - - private void waitUntilAddressSpaceActive(AddressSpace addressSpace) throws Exception { - String name = addressSpace.getMetadata().getName(); - resourcesManager.waitForAddressSpaceReady(addressSpace); - Boolean active = Optional.ofNullable(selenium.waitUntilItemPresent(60, () -> consolePage.getAddressSpaceItem(addressSpace))) - .map(webItem -> webItem.getStatus().contains("Active")) - .orElseGet(() -> { - log.error("AddressSpaceWebItem {} not present", name); - return false; - }); - assertTrue(active, String.format("Address space %s not marked active in UI within timeout", name)); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/web/WebSocketBrowserTest.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/web/WebSocketBrowserTest.java deleted file mode 100644 index 88c88ba97e0..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/web/WebSocketBrowserTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.web; - - -import io.enmasse.address.model.Address; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.shared.ITestBaseShared; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.selenium.SeleniumProvider; -import io.enmasse.systemtest.selenium.page.RheaWebPage; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import org.junit.jupiter.api.BeforeEach; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class WebSocketBrowserTest extends TestBase implements ITestBaseShared { - - private RheaWebPage rheaWebPage; - - @BeforeEach - public void setUpWebConsoleTests() throws Exception { - rheaWebPage = new RheaWebPage(SeleniumProvider.getInstance()); - resourcesManager.deleteAddresses(getSharedAddressSpace()); - } - - //============================================================================================ - //============================ do test methods =============================================== - //============================================================================================ - - protected void doWebSocketSendReceive(Address destination) throws Exception { - resourcesManager.setAddresses(destination); - int count = 10; - - rheaWebPage.sendReceiveMessages(AddressSpaceUtils.getMessagingWssRoute(getSharedAddressSpace()).toString(), destination.getSpec().getAddress(), - count, defaultCredentials, AddressSpaceType.valueOf(getSharedAddressSpace().getSpec().getType().toUpperCase())); - assertTrue(rheaWebPage.checkCountMessage(count * 2), "Browser client didn't sent and received all messages"); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/resources/CliOutputDataTest.java b/systemtests/src/test/java/io/enmasse/systemtest/framework/CliOutputDataTest.java similarity index 98% rename from systemtests/src/test/java/io/enmasse/systemtest/resources/CliOutputDataTest.java rename to systemtests/src/test/java/io/enmasse/systemtest/framework/CliOutputDataTest.java index 8503b3c9191..0e031eb2df8 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/resources/CliOutputDataTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/framework/CliOutputDataTest.java @@ -2,9 +2,10 @@ * Copyright 2020, EnMasse authors. * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). */ -package io.enmasse.systemtest.resources; +package io.enmasse.systemtest.framework; import io.enmasse.systemtest.TestTag; +import io.enmasse.systemtest.resources.CliOutputData; import io.enmasse.systemtest.resources.CliOutputData.CliOutputDataType; import org.junit.jupiter.api.Tag; diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/CredentialsTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/CredentialsTest.java deleted file mode 100644 index c64c24b3348..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/CredentialsTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import io.enmasse.systemtest.TestTag; -import io.vertx.core.json.JsonObject; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@Tag(TestTag.FRAMEWORK) -public class CredentialsTest { - - @Test - void testCreateSecret() { - var creds = JsonObject.mapFrom(CredentialsRegistryClient.createCredentialsObject("auth-id", "foo", null)); - - var secrets = creds.getJsonArray("secrets"); - assertNotNull(secrets); - var secret = secrets.getJsonObject(0); - assertNotNull(secret); - - assertNotNull(secret.getBinary("pwd-hash")); - assertNotNull(secret.getBinary("salt")); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceCertificateManagerTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceCertificateManagerTest.java deleted file mode 100644 index 8c52eb2f6b1..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceCertificateManagerTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import static io.enmasse.systemtest.TestTag.FRAMEWORK; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.security.cert.X509Certificate; -import java.time.Duration; -import java.time.Instant; - -import javax.security.auth.x500.X500Principal; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.systemtest.iot.DeviceCertificateManager.Device; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; - -@Tag(FRAMEWORK) -public class DeviceCertificateManagerTest { - - @Test - public void testRsa() throws Exception { - final DeviceCertificateManager mgr = new DeviceCertificateManager(Mode.RSA, new X500Principal("CN=foo,OU=bar,O=baz")); - - final X509Certificate cert = mgr.getCertificate(); - assertNotNull(cert); - - final Device device = mgr.createDevice("dev1", Instant.now(), Duration.ofDays(90)); - assertNotNull(device); - assertNotNull(device.getKey()); - assertNotNull(device.getCertificate()); - } - - @Test - public void testEc() throws Exception { - final DeviceCertificateManager mgr = new DeviceCertificateManager(Mode.EC, new X500Principal("CN=foo,OU=bar,O=baz")); - - final X509Certificate cert = mgr.getCertificate(); - assertNotNull(cert); - - final Device device = mgr.createDevice("dev1", Instant.now(), Duration.ofDays(90)); - assertNotNull(device); - assertNotNull(device.getKey()); - assertNotNull(device.getCertificate()); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceSupplier.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceSupplier.java deleted file mode 100644 index 0b024785756..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceSupplier.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import java.util.Objects; - -import org.junit.jupiter.params.provider.MethodSource; - -import io.enmasse.systemtest.iot.IoTTestSession.Device; - -/** - * A supplier for devices. Required due to an issue in Surefire. - *

- * This is a workaround for SUREFIRE-1799, which silently drops unit tests in case - * there is an exception being thrown in a method of a {@link MethodSource}. As we - * create {@link Device}s for parametrized tests and creation of devices might fail, - * that will be an issue. - *

- * The idea is to delay the actual execution of the device creation until it - * is running in the actual test case. So instead of creating devices, we create - * code that creates devices. The call to the {@link #get()} method should perform - * the actual device creation, and it may fail, which is reported as a test failure. - *

- * @see SUREFIRE-1799 - */ -@FunctionalInterface -public interface DeviceSupplier { - - public Device get() throws Exception; - - /** - * Allows to override the output of the {@link #toString()} method. - *

- * This may be used to provide a stable name for parameterized test. - * - * @implNote This was originally part of the {@link Device} class. Due to - * SUREFIRE-1799 this code currently lives here. - * - * @param name The value to report from {@link #toString()}. - * @return The new instance, reporting the provided name. - */ - static DeviceSupplier named(final String name, final DeviceSupplier supplier) { - - Objects.requireNonNull(name); - Objects.requireNonNull(supplier); - - return new DeviceSupplier() { - - @Override - public Device get() throws Exception { - return supplier.get(); - } - - @Override - public String toString() { - return name; - } - }; - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/IoTTestSessionTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/IoTTestSessionTest.java deleted file mode 100644 index f5b600013c1..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/IoTTestSessionTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import static io.enmasse.systemtest.TestTag.FRAMEWORK; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.util.concurrent.atomic.AtomicBoolean; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; - -@Tag(FRAMEWORK) -public class IoTTestSessionTest { - - @Test - public void testNameInDefaultConfig() throws Exception { - var config = IoTTestSession.createDefaultConfig("default-ns", true).build(); - - assertDefaultConfig(config); - } - - @Test - public void testNameInDefaultConfigAfterChange() throws Exception { - var configBuilder = IoTTestSession.createDefaultConfig("default-ns", true); - - assertDefaultConfig(configBuilder.build()); - - for (Adapter adapter : Adapter.values()) { - configBuilder = adapter.disable(configBuilder); - } - configBuilder = HTTP.enable(configBuilder); - - assertDefaultConfig(configBuilder.build()); - - } - - private void assertDefaultConfig(IoTConfig config) { - assertNotNull(config); - - assertNotNull(config.getMetadata()); - assertEquals("default", config.getMetadata().getName()); - assertEquals("default-ns", config.getMetadata().getNamespace()); - } - - @Test - public void testEnableAdapter() throws Exception { - AtomicBoolean called = new AtomicBoolean(); - - IoTTestSession - .create("default-ns", true) - .adapters(Adapter.HTTP) - .config(configBuilder -> { - - var config = configBuilder.build(); - - assertNotNull(config.getSpec()); - assertNotNull(config.getSpec().getAdapters()); - - assertNotNull(config.getSpec().getAdapters().getHttp()); - assertEquals(Boolean.TRUE, config.getSpec().getAdapters().getHttp().getEnabled()); - - assertNotNull(config.getSpec().getAdapters().getMqtt()); - assertEquals(Boolean.FALSE, config.getSpec().getAdapters().getMqtt().getEnabled()); - - called.set(true); - - }); - - assertTrue(called.get()); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/KeyStoreCreatorTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/KeyStoreCreatorTest.java deleted file mode 100644 index 60aae1db950..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/KeyStoreCreatorTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.time.Duration; -import java.time.Instant; - -import javax.security.auth.x500.X500Principal; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; - -import io.enmasse.systemtest.TestTag; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; - -@Tag(TestTag.FRAMEWORK) -public class KeyStoreCreatorTest { - - @Test - public void testBasicRsa() throws Exception { - var mgr = new DeviceCertificateManager(Mode.RSA, new X500Principal("O=EnMasse,C=IO")); - var device = mgr.createDevice("foo", Instant.now(), Duration.ofDays(90)); - KeyStoreCreator.from(device.getKey().getPrivate(), device.getCertificate()); - } - - @Test - public void testBasicEc() throws Exception { - var mgr = new DeviceCertificateManager(Mode.EC, new X500Principal("O=EnMasse,C=IO")); - var device = mgr.createDevice("foo", Instant.now(), Duration.ofDays(90)); - KeyStoreCreator.from(device.getKey().getPrivate(), device.getCertificate()); - } - - @ParameterizedTest(name = "testToByteArray-{0}") - @EnumSource(Mode.class) - public void testToByteArray(final Mode mode) throws Exception { - var mgr = new DeviceCertificateManager(mode, new X500Principal("O=EnMasse,C=IO")); - var device = mgr.createDevice("foo", Instant.now(), Duration.ofDays(90)); - - byte[] bytes = KeyStoreCreator.toByteArray(device.getKey().getPrivate(), device.getCertificate()); - - assertNotNull(bytes); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/MessageSendTesterTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/MessageSendTesterTest.java deleted file mode 100644 index a74c23fa442..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/MessageSendTesterTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.nio.charset.StandardCharsets; -import java.util.Arrays; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.systemtest.TestTag; -import io.vertx.core.json.JsonObject; - -@Tag(TestTag.FRAMEWORK) -public class MessageSendTesterTest { - - @Test - public void testFillingEmpty() { - final JsonObject json = new JsonObject(); - var result = MessageSendTester.fillWithPayload(json, 1024); - assertEquals(1024, result.length()); - } - - @Test - public void testFillUtf8() { - final JsonObject json = new JsonObject(); - json.put("some-utf-8", "\u1F926"); - var result = MessageSendTester.fillWithPayload(json, 1024); - assertEquals(1024, result.length()); - } - - @Test - public void testFillingNonEmpty() { - - final int fixedLength = "{\"init\":\"\"}".getBytes(StandardCharsets.UTF_8).length; - - for (int initialLength = fixedLength; initialLength < 1024; initialLength++) { - - final char init[] = new char[initialLength - fixedLength]; - Arrays.fill(init, 'b'); - final String initValue = String.valueOf(init); - - for (int expectedLength = initialLength + MessageSendTester.FIXED_JSON_EXTRA_SIZE + 1; expectedLength < 1024; expectedLength++) { - - final JsonObject json = new JsonObject(); - json.put("init", initValue); - - var result = MessageSendTester.fillWithPayload(json, expectedLength); - assertEquals(expectedLength, result.length()); - - } - - } - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/StandardIoTTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/StandardIoTTests.java deleted file mode 100644 index 277a841e8e9..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/StandardIoTTests.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import java.util.List; - -public interface StandardIoTTests extends IoTTests { - - /** - * Test the test session. - */ - public IoTTestSession getSession(); - - /** - * Get a list of devices which must succeed. - */ - public List getDevices(); - - /** - * Get a list of devices which must fail. - */ - public List getInvalidDevices(); - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/http/StandardIoTHttpTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/http/StandardIoTHttpTests.java deleted file mode 100644 index 6796c8ad454..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/http/StandardIoTHttpTests.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.http; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.HttpAdapterClient.causedBy; -import static io.enmasse.systemtest.iot.HttpAdapterClient.ResponseException.statusCode; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.time.Duration; -import java.util.concurrent.TimeoutException; - -import javax.net.ssl.SSLHandshakeException; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.enmasse.systemtest.iot.DeviceSupplier; -import io.enmasse.systemtest.iot.HttpAdapterClient; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; -import io.enmasse.systemtest.iot.StandardIoTTests; - -public interface StandardIoTHttpTests extends StandardIoTTests { - - static final Logger log = LoggerFactory.getLogger(StandardIoTHttpTests.class); - - /** - * Single telemetry message with attached consumer. - */ - @Tag(ACCEPTANCE) - @ParameterizedTest(name = "testHttpTelemetrySingle-{0}") - @MethodSource("getDevices") - default void testHttpTelemetrySingle(final DeviceSupplier device) throws Exception { - - try (HttpAdapterClient client = device.get().createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(1) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Test a single event message. - *
- * Send a single message, no consumer attached. The message gets delivered - * when the consumer attaches. - */ - @ParameterizedTest(name = "testHttpEventSingle-{0}") - @MethodSource("getDevices") - default void testHttpEventSingle(final DeviceSupplier device) throws Exception { - - try (HttpAdapterClient client = device.get().createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(1) - .consume(MessageSendTester.Consume.AFTER) - .execute(); - } - - } - - /** - * Test a batch of telemetry messages, consumer is started before sending. - *
- * This is the normal telemetry case. - */ - @ParameterizedTest(name = "testHttpTelemetryBatch50-{0}") - @MethodSource("getDevices") - default void testHttpTelemetryBatch50(final DeviceSupplier device) throws Exception { - - try (HttpAdapterClient client = device.get().createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Test a batch of events, having no consumer attached. - *
- * As events get buffered by the broker, there is no requirement to start - * a consumer before sending the messages. However when the consumer is - * attached, it should receive those messages. - */ - @ParameterizedTest(name = "testHttpEventBatch5After-{0}") - @MethodSource("getDevices") - default void testHttpEventBatch5After(final DeviceSupplier device) throws Exception { - - try (HttpAdapterClient client = device.get().createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofMillis(100)) - .additionalSendTimeout(Duration.ofSeconds(10)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(5) - .consume(MessageSendTester.Consume.AFTER) - .execute(); - } - - } - - /** - * Test a batch of events, starting the consumer before sending. - *
- * This is the default use case with events, and should simply work - * as with telemetry. - */ - @ParameterizedTest(name = "testHttpEventBatch5Before-{0}") - @MethodSource("getDevices") - default void testHttpEventBatch5Before(final DeviceSupplier device) throws Exception { - - try (HttpAdapterClient client = device.get().createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ZERO) - .additionalSendTimeout(Duration.ofSeconds(10)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Test for an invalid device. - *
- * With an invalid device, no messages must pass. - */ - @ParameterizedTest(name = "testHttpDeviceFails-{0}") - @MethodSource("getInvalidDevices") - default void testHttpDeviceFails(final DeviceSupplier deviceSupplier) throws Exception { - - log.info("Testing invalid devices, the following exception may be expected"); - var device = deviceSupplier.get(); - - /* - * We test an invalid device by trying to send either telemetry or event messages. - * Two separate connections, and more than one message. - */ - - try (HttpAdapterClient client = device.createHttpAdapterClient()) { - client.suppressExceptions( - statusCode(401) - .or(causedBy(SSLHandshakeException.class))); - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - } - - try (HttpAdapterClient client = device.createHttpAdapterClient()) { - client.suppressExceptions( - statusCode(401) - .or(causedBy(SSLHandshakeException.class))); - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - } - - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/AbstractMaxPayloadSizeTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/AbstractMaxPayloadSizeTest.java deleted file mode 100644 index f54a937838f..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/AbstractMaxPayloadSizeTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated; - -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.time.Duration; -import java.util.concurrent.TimeoutException; - -import org.junit.jupiter.api.Test; - -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; -import io.enmasse.systemtest.iot.IoTTestSession.Device; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; -import io.enmasse.systemtest.iot.MessageSendTester.Sender; -import io.enmasse.systemtest.iot.MessageSendTester.Type; - -public abstract class AbstractMaxPayloadSizeTest extends TestBase implements ITestIoTIsolated { - - protected abstract Adapter adapter(); - - protected abstract Sender sender(Device device) throws Exception; - - /** - * Reduce the payload by this amount of bytes. - *

- * This is required by e.g. the MQTT protocol, as the topic name counts against the total length of - * the MQTT payload. - * - * @param type the type to send. - * - * @return The number of bytes to remove from the payload. - */ - protected int reducePayloadBy(final Type type) { - return 0; - } - - @Test - public void testDecreasedMaxPayloadDefault() throws Exception { - - IoTTestSession - .createDefault() - .adapters(adapter()) - .config(config -> config - .editOrNewSpec() - .editOrNewAdapters() - .editOrNewDefaults() - .withMaxPayloadSize(256) - .endDefaults() - .endAdapters() - .endSpec()) - .run(session -> { - - var device = session - .newDevice("4711") - .register() - .setPassword("auth-1", "123456"); - - // we expect the sending to fail, due to timeouts, as the payload exceeds the maximum - - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .payloadSize(1024 - reducePayloadBy(MessageSendTester.Type.TELEMETRY)) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(sender(device)) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - - }); - - } - - @Test - public void testIncreasedMaxPayloadDefault() throws Exception { - - IoTTestSession - .createDefault() - .adapters(adapter()) - .config(config -> config - .editOrNewSpec() - .editOrNewAdapters() - .editOrNewDefaults() - .withMaxPayloadSize(16 * 1024) - .endDefaults() - .endAdapters() - .endSpec()) - .run(session -> { - - var device = session - .newDevice("4711") - .register() - .setPassword("auth-1", "123456"); - - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .payloadSize((16 * 1024) - reducePayloadBy(MessageSendTester.Type.TELEMETRY)) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(sender(device)) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - - } - - @Test - public void testStandardMaxPayloadDefault() throws Exception { - - IoTTestSession - .createDefault() - .adapters(adapter()) - .run(session -> { - - var device = session - .newDevice("4711") - .register() - .setPassword("auth-1", "123456"); - - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .payloadSize(1024 - reducePayloadBy(MessageSendTester.Type.TELEMETRY)) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(sender(device)) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/IoTProjectManagedTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/IoTProjectManagedTest.java deleted file mode 100644 index 8cdc076141a..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/IoTProjectManagedTest.java +++ /dev/null @@ -1,421 +0,0 @@ -/* - * Copyright 2018-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.iot.isolated; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.TestTag.SMOKE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newDefaultInstance; -import static io.enmasse.systemtest.time.TimeoutBudget.ofDuration; -import static io.enmasse.user.model.v1.Operation.recv; -import static io.enmasse.user.model.v1.Operation.send; -import static java.time.Duration.ofMinutes; -import static java.util.Arrays.asList; -import static java.util.EnumSet.of; -import static java.util.Optional.ofNullable; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.beans.HasPropertyWithValue.hasProperty; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.hamcrest.core.AllOf.allOf; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.time.Duration; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.hamcrest.Matcher; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceStatus; -import io.enmasse.address.model.AddressStatus; -import io.enmasse.address.model.KubeUtil; -import io.enmasse.address.model.Phase; -import io.enmasse.iot.model.v1.DoneableIoTProject; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.iot.model.v1.IoTProjectList; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserAuthorization; -import io.enmasse.user.model.v1.UserStatus; -import io.fabric8.kubernetes.api.model.Doneable; -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.fabric8.kubernetes.api.model.OwnerReference; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -class IoTProjectManagedTest extends TestBase implements ITestIoTIsolated { - private final static Logger log = CustomLogger.getLogger(); - - @FunctionalInterface - interface ProjectModificator { - /** - * Modify a project - * - * @param timeout The timeout budget the operation has available. - * @param project The project to work with. It is an provisioned project, which already passed a - * call to {@link IoTProjectManagedTest#assertManaged(IoTProject)}. - * @return {@code true} if the state has been change and a final call to - * {@link IoTProjectManagedTest#assertManaged(IoTProject)} to be performed. - */ - boolean modify(TimeoutBudget timeout, IoTProject project) throws Exception; - } - - private Kubernetes kubernetes = Kubernetes.getInstance(); - - private MixedOperation> projectClient; - - @BeforeEach - void createIoTClient() { - this.projectClient = this.kubernetes.getIoTProjectClient(IOT_PROJECT_NAMESPACE); - } - - /** - * Simply create a project and directly test it. - */ - @Test - @Tag(SMOKE) - @Tag(ACCEPTANCE) - void testCreate() throws Exception { - // run a default test, with no modifications - doTestAddressSpaceWithModifications(ofDuration(ofMinutes(5)), (timeout, project) -> false); - } - - /** - * Delete a resource and wait for it to be re-created properly. - * - * @param The resource type. - * @param The list type of the resource. - * @param The {@link Doneable} type. - * @param project The IoT project to process. - * @param clazz The class instance of the resource type. - * @param name The kubernetes name of the resource. - * @param basicClient The basic resource client. Does not need to be namespaced. - * @param phaseExtractor The function which extracts the phase information. - */ - ProjectModificator deleteAndWaitResource(final Class clazz, final Function nameExtractor, - final MixedOperation> basicClient, final Function> phaseExtractor) { - - return (timeout, project) -> { - - final var name = nameExtractor.apply(project); - final var className = clazz.getSimpleName(); - final var client = basicClient.inNamespace(IOT_PROJECT_NAMESPACE); - - // get the current address space - - final var namedClient = client.withName(name); - final var currentResource = namedClient.get(); - assertNotNull(currentResource, () -> String.format("Unable to find resource - type: %s, name: '%s'", className, name)); - - // remember its ID - - final String originalId = currentResource.getMetadata().getUid(); - assertNotNull(originalId); - - // delete it - - client.withName(name).delete(); - - // now wait for it to be re-created - - TestUtils.waitUntilConditionOrFail(() -> { - - var current = namedClient.get(); - if (current == null) { - log.info("{} is still missing", className); - return false; - } - if (originalId.equals(current.getMetadata().getUid())) { - log.info("{} has still the same ID", className); - // still the same object - return false; - } - - // get current phase - final var phase = phaseExtractor.apply(current); - if (!phase.isPresent()) { - log.info("{} no phase information", className); - return false; - } - - if (phase.get() != Phase.Active) { - log.info("{} is not ready yet: {}", className, phase.get()); - return false; - } - - return true; - }, timeout.remaining(), Duration.ofSeconds(10), () -> className + " did not get re-created"); - - // and wait for the IoT project to become ready again - - var projectAccess = kubernetes.getIoTProjectClient(project.getMetadata().getNamespace()).withName(project.getMetadata().getName()); - TestUtils.waitUntilConditionOrFail(() -> { - var current = projectAccess.get(); - - if (current == null) { - log.info("IoTProject missing"); - return false; - } - - if (current.getStatus() == null || current.getStatus().getPhase() == null) { - log.info("IoTProject is missing status information"); - return false; - } - - if (!current.getStatus().getPhase().equals("Active")) { - return false; - } - - return true; - }, timeout.remaining(), Duration.ofSeconds(10), () -> "IoTProject failed to switch back to 'Active'"); - - return true; - }; - } - - /** - * Test deleting the whole address space. - */ - @Test - void testDeleteAddressSpace() throws Exception { - doTestAddressSpaceWithModifications( - ofDuration(ofMinutes(15)), - deleteAndWaitResource( - AddressSpace.class, - project -> project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(), - kubernetes.getAddressSpaceClient(), - addressSpace -> ofNullable(addressSpace).map(AddressSpace::getStatus).map(AddressSpaceStatus::getPhase))); - } - - /** - * Test deleting the telememtry address. - */ - @Test - void testDeleteTelemetryAddress() throws Exception { - doTestAddressSpaceWithModifications( - ofDuration(ofMinutes(10)), - deleteAndWaitResource( - Address.class, - project -> KubeUtil.sanitizeForGo( - project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(), - "telemetry/" + project.getStatus().getTenantName()), - kubernetes.getAddressClient(), - address -> ofNullable(address).map(Address::getStatus).map(AddressStatus::getPhase))); - } - - /** - * Test deleting the event address. - *
- * The event address is expected to be backed by a brokered address. Thus is might behave - * differently than the others. - */ - @Test - void testDeleteEventAddress() throws Exception { - doTestAddressSpaceWithModifications( - ofDuration(ofMinutes(15)), - deleteAndWaitResource( - Address.class, - project -> KubeUtil.sanitizeForGo( - project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(), - "event/" + project.getStatus().getTenantName()), - kubernetes.getAddressClient(), - address -> ofNullable(address).map(Address::getStatus).map(AddressStatus::getPhase))); - } - - /** - * Test deleting the adapter user. - */ - @Test - void testDeleteAdapterUser() throws Exception { - doTestAddressSpaceWithModifications( - ofDuration(ofMinutes(10)), - deleteAndWaitResource( - User.class, - project -> project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName() - + "." - + project.getStatus().getDownstreamEndpoint().getUsername(), - kubernetes.getUserClient(), - user -> ofNullable(user).map(User::getStatus).map(UserStatus::getPhase))); - } - - void doTestAddressSpaceWithModifications(final TimeoutBudget timeout, final ProjectModificator modificator) throws Exception { - - isolatedIoTManager.createIoTConfig(IoTTestSession.createDefaultConfig() - .editOrNewSpec().withServices(newDefaultInstance()).endSpec() - .build()); - - final String addressSpaceName = "managed-address-space"; - final String iotProjectName = "iot-project-managed"; - - IoTProject project = IoTUtils.getBasicIoTProjectObject(iotProjectName, addressSpaceName, - IOT_PROJECT_NAMESPACE, getDefaultAddressSpacePlan()); - LOGGER.warn("NAMESPACE EXISTS? {}, {}", project.getMetadata().getNamespace(), kubernetes.namespaceExists(project.getMetadata().getNamespace())); - isolatedIoTManager.createIoTProject(project); // waiting until ready - IoTProject created = this.projectClient.withName(iotProjectName).get(); - - assertNotNull(created); - assertEquals(IOT_PROJECT_NAMESPACE, created.getMetadata().getNamespace()); - assertEquals(project.getMetadata().getName(), created.getMetadata().getName()); - assertEquals( - project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(), - created.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName()); - - assertManaged(created); - - if (modificator.modify(timeout, created)) { - created = this.projectClient.withName(iotProjectName).get(); - assertNotNull(created); - assertManaged(created); - } - } - - private static void assertAddressType(final Address address, final AddressType type, final String plan) { - assertEquals(type.toString(), address.getSpec().getType()); - assertEquals(plan, address.getSpec().getPlan()); - } - - private void assertManaged(IoTProject project) throws Exception { - // address spaces - AddressSpace addressSpace = - isolatedIoTManager.getAddressSpace(IOT_PROJECT_NAMESPACE, project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName()); - assertEquals(project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(), addressSpace.getMetadata().getName()); - assertEquals(AddressSpaceType.STANDARD.toString(), addressSpace.getSpec().getType()); - assertEquals(AddressSpacePlans.STANDARD_SMALL, addressSpace.getSpec().getPlan()); - assertEquals(Phase.Active, addressSpace.getStatus().getPhase()); - - // addresses - // {event/control/command/command_response/telemetry}/"project-namespace"."project-name" - final String addressSuffix = "/" + project.getMetadata().getNamespace() + "." + project.getMetadata().getName(); - final List

addresses = AddressUtils.getAddresses(addressSpace); - // assert that we have the right number of addresses - assertEquals(5, addresses.size()); - // assert that all addresses have the project set as owner - assertEquals(5, addresses.stream() - .map(Address::getMetadata) - .map(ObjectMeta::getOwnerReferences) - .flatMap(List::stream) - .filter(reference -> isOwner(project, reference)) - .count()); - - int correctAddressesCounter = 0; - for (Address address : addresses) { - - final String addressName = address.getSpec().getAddress(); - - if (addressName.equals(IOT_ADDRESS_EVENT + addressSuffix)) { - - assertAddressType(address, AddressType.QUEUE, DestinationPlan.STANDARD_SMALL_QUEUE); - correctAddressesCounter++; - - } else if (addressName.equals(IOT_ADDRESS_CONTROL + addressSuffix) - || addressName.equals(IOT_ADDRESS_TELEMETRY + addressSuffix) - || addressName.equals(IOT_ADDRESS_COMMAND + addressSuffix) - || addressName.equals(IOT_ADDRESS_COMMAND_RESPONSE + addressSuffix)) { - - assertAddressType(address, AddressType.ANYCAST, DestinationPlan.STANDARD_SMALL_ANYCAST); - correctAddressesCounter++; - - } - - assertEquals(Phase.Active, address.getStatus().getPhase()); - - } - assertEquals(5, correctAddressesCounter, "There are incorrect IoT addresses " + addresses); - - // username "adapter" - // name "project-address-space"+".adapter" - User user = isolatedIoTManager.getUser(addressSpace, "adapter-" + project.getMetadata().getUid()); - assertNotNull(user); - assertEquals(1, user.getMetadata().getOwnerReferences().size()); - assertTrue(isOwner(project, user.getMetadata().getOwnerReferences().get(0))); - - final List authorizations = user.getSpec().getAuthorization(); - - assertThat(authorizations, hasSize(3)); - - assertThat(authorizations, containsInAnyOrder( - asList( - assertAdapterAuthorization(of(send), expandAddresses(addressSuffix, IOT_ADDRESS_TELEMETRY, IOT_ADDRESS_EVENT, IOT_ADDRESS_COMMAND_RESPONSE)), - assertAdapterAuthorization(of(recv), expandAddresses(addressSuffix, IOT_ADDRESS_COMMAND)), - assertAdapterAuthorization(of(recv, send), expandAddresses(addressSuffix, IOT_ADDRESS_CONTROL))))); - } - - /** - * Assert an authorization entry. - * - * @param operations The expected operations. - * @param addresses The expected addresses. - * @return A matcher, asserting the entry. - */ - private static Matcher assertAdapterAuthorization(final Set operations, final Set addresses) { - - return allOf(asList( - - hasProperty("operations", containsInAnyOrder(operations.toArray(Operation[]::new))), - hasProperty("addresses", containsInAnyOrder(addresses.toArray(String[]::new))) - - )); - - } - - /** - * Expand addresses to match ACLs. - * - * @param addressSuffix The "suffix" (tenant) of the address. - * @return A set of all addresses. - */ - private static Set expandAddresses(final String addressSuffix, final String... baseAddresses) { - - return Arrays - .stream(baseAddresses) - .flatMap(address -> { - return Stream.of( - address + addressSuffix, - address + addressSuffix + "/*"); - }) - - .collect(Collectors.toSet()); - - } - - /** - * Test if the project is the owner the reference points to. - * - * @param project The project to check for. - * @param ownerReference The reference to check. - * @return {@code true} if the reference points to the project. - */ - private boolean isOwner(final IoTProject project, final OwnerReference ownerReference) { - return ownerReference.getKind().equals(IoTProject.KIND) && - project.getMetadata().getName().equals(ownerReference.getName()); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/MultipleProjectsTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/MultipleProjectsTest.java deleted file mode 100644 index bf470525fc2..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/MultipleProjectsTest.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.iot.isolated; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newDefaultInstance; - -import java.net.HttpURLConnection; -import java.nio.charset.StandardCharsets; -import java.time.Duration; -import java.util.ArrayList; -import java.util.Base64; -import java.util.Collections; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import org.eclipse.paho.client.mqttv3.IMqttClient; -import org.eclipse.paho.client.mqttv3.MqttException; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.TestTag; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.iot.CredentialsRegistryClient; -import io.enmasse.systemtest.iot.DeviceRegistryClient; -import io.enmasse.systemtest.iot.HttpAdapterClient; -import io.enmasse.systemtest.iot.IoTProjectTestContext; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.mqtt.MqttClientFactory; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.time.WaitPhase; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserAuthenticationType; -import io.enmasse.user.model.v1.UserAuthorizationBuilder; -import io.enmasse.user.model.v1.UserBuilder; - -@Tag(TestTag.SMOKE) -class MultipleProjectsTest extends TestBase implements ITestIoTIsolated { - private static Logger log = CustomLogger.getLogger(); - private DeviceRegistryClient registryClient; - private CredentialsRegistryClient credentialsClient; - - private int numberOfProjects = 2; - private List projects = new ArrayList<>(); - - @BeforeEach - void initEnv() throws Exception { - IoTConfig iotConfig = IoTTestSession.createDefaultConfig() - .editOrNewSpec().withServices(newDefaultInstance()).endSpec() - .build(); - isolatedIoTManager.createIoTConfig(iotConfig); - - Endpoint deviceRegistryEndpoint = IoTUtils.getDeviceRegistryManagementEndpoint(); - registryClient = new DeviceRegistryClient(deviceRegistryEndpoint); - credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint); - - for (int i = 1; i <= numberOfProjects; i++) { - String projectName = String.format("project-%s", i); - - kubernetes.createNamespace(projectName); - - IoTProject project = IoTUtils.getBasicIoTProjectObject(projectName, projectName, - projectName, getDefaultAddressSpacePlan()); - isolatedIoTManager.createIoTProject(project); - IoTProjectTestContext ctx = new IoTProjectTestContext(projectName, project); - - configureDeviceSide(ctx); - - configureAmqpSide(ctx); - - projects.add(ctx); - } - } - - @AfterEach - void cleanEnv(ExtensionContext context) throws Exception { - for (IoTProjectTestContext ctx : projects) { - cleanDeviceSide(ctx); - cleanAmqpSide(ctx); - } - } - - @Test - @Tag(ACCEPTANCE) - void testMultipleProjects() throws Exception { - - for (final IoTProjectTestContext ctx : projects) { - try (var http = ctx.getHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(ctx.getAmqpClient(), IoTUtils.getTenantId(ctx.getProject()))) - .sender(http::send) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofMillis(100)) - .consumerFactory(ConsumerFactory.of(ctx.getAmqpClient(), IoTUtils.getTenantId(ctx.getProject()))) - .sender(http::send) - .amount(5) - .consume(MessageSendTester.Consume.AFTER) - .execute(); - } - } - - } - - private void configureAmqpSide(IoTProjectTestContext ctx) throws Exception { - AddressSpace addressSpace = isolatedIoTManager.getAddressSpace(ctx.getNamespace(), - ctx.getProject().getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName()); - User amqpUser = configureAmqpUser(ctx.getProject(), addressSpace); - ctx.setAmqpUser(amqpUser); - AmqpClient amqpClient = configureAmqpClient(addressSpace, amqpUser); - ctx.setAmqpClient(amqpClient); - } - - private User configureAmqpUser(IoTProject project, AddressSpace addressSpace) { - String tenant = IoTUtils.getTenantId(project); - - User amqpUser = new UserBuilder() - - .withNewMetadata() - .withName(String.format("%s.%s", addressSpace.getMetadata().getName(), project.getMetadata().getName())) - .endMetadata() - - .withNewSpec() - .withUsername(UUID.randomUUID().toString()) - .withNewAuthentication() - .withPassword(Base64.getEncoder().encodeToString(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8))) - .withType(UserAuthenticationType.password) - .endAuthentication() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses(IOT_ADDRESS_TELEMETRY + "/" + tenant, - IOT_ADDRESS_TELEMETRY + "/" + tenant + "/*", - IOT_ADDRESS_EVENT + "/" + tenant, - IOT_ADDRESS_EVENT + "/" + tenant + "/*") - .withOperations(Operation.recv) - .build())) - .endSpec() - .build(); - kubernetes.getUserClient(project.getMetadata().getNamespace()).create(amqpUser); - - return amqpUser; - } - - private AmqpClient configureAmqpClient(AddressSpace addressSpace, User user) throws Exception { - LOGGER.warn("Amqp factory: " + getAmqpClientFactory()); - AmqpClient amqpClient = getAmqpClientFactory().createQueueClient(addressSpace); - amqpClient.getConnectOptions() - .setUsername(user.getSpec().getUsername()) - .setPassword(new String(Base64.getDecoder().decode(user.getSpec().getAuthentication().getPassword()))); - return amqpClient; - } - - private void cleanAmqpSide(IoTProjectTestContext ctx) throws Exception { - ctx.getAmqpClient().close(); - var userClient = kubernetes.getUserClient(ctx.getNamespace()); - userClient.withName(ctx.getAmqpUser().getMetadata().getName()).cascading(true).delete(); - } - - private void configureDeviceSide(IoTProjectTestContext ctx) throws Exception { - String tenant = IoTUtils.getTenantId(ctx.getProject()); - ctx.setDeviceId(UUID.randomUUID().toString()); - ctx.setDeviceAuthId(UUID.randomUUID().toString()); - ctx.setDevicePassword(UUID.randomUUID().toString()); - registryClient.registerDevice(tenant, ctx.getDeviceId()); - credentialsClient.addCredentials(tenant, ctx.getDeviceId(), ctx.getDeviceAuthId(), ctx.getDevicePassword(), null, HttpURLConnection.HTTP_NO_CONTENT); - Endpoint httpAdapterEndpoint = kubernetes.getExternalEndpoint("iot-http-adapter"); - ctx.setHttpAdapterClient(new HttpAdapterClient(httpAdapterEndpoint, ctx.getDeviceAuthId(), tenant, ctx.getDevicePassword())); - IMqttClient mqttAdapterClient = new MqttClientFactory.Builder() - .clientId(ctx.getDeviceId()) - .endpoint(kubernetes.getExternalEndpoint("iot-mqtt-adapter")) - .usernameAndPassword(ctx.getDeviceAuthId() + "@" + tenant, ctx.getDevicePassword()) - .mqttConnectionOptions(options -> { - options.setAutomaticReconnect(true); - options.setConnectionTimeout(60); - options.setHttpsHostnameVerificationEnabled(false); - }) - .create(); - TestUtils.waitUntilCondition("Successfully connect to mqtt adapter", phase -> { - try { - mqttAdapterClient.connect(); - return true; - } catch (MqttException mqttException) { - if (phase == WaitPhase.LAST_TRY) { - log.error("Error waiting to connect mqtt adapter", mqttException); - } - return false; - } - }, new TimeoutBudget(1, TimeUnit.MINUTES)); - log.info("Connection to mqtt adapter succeeded"); - ctx.setMqttAdapterClient(mqttAdapterClient); - } - - private void cleanDeviceSide(IoTProjectTestContext ctx) throws Exception { - String tenant = IoTUtils.getTenantId(ctx.getProject()); - String deviceId = ctx.getDeviceId(); - credentialsClient.deleteAllCredentials(tenant, deviceId); - registryClient.deleteDeviceRegistration(tenant, deviceId); - registryClient.getDeviceRegistration(tenant, deviceId, HttpURLConnection.HTTP_NOT_FOUND); - ctx.getHttpAdapterClient().close(); - ctx.getMqttAdapterClient().close(); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/SimpleK8sDeployTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/SimpleK8sDeployTest.java deleted file mode 100644 index 0dcbe0bab1b..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/SimpleK8sDeployTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated; - -import static io.enmasse.systemtest.TestTag.SMOKE; -import static io.enmasse.systemtest.time.TimeoutBudget.ofDuration; -import static java.time.Duration.ofMinutes; -import static java.util.Collections.singletonMap; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.ObjectMapper; - -import io.enmasse.iot.model.v1.CommonAdapterContainersBuilder; -import io.enmasse.iot.model.v1.ContainerConfigBuilder; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.JavaContainerConfigBuilder; -import io.enmasse.systemtest.Environment; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.condition.Kubernetes; -import io.enmasse.systemtest.iot.DefaultDeviceRegistry; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.api.model.Quantity; - -@Tag(SMOKE) -@Kubernetes -class SimpleK8sDeployTest extends TestBase implements ITestIoTIsolated { - - private static final Logger log = LoggerFactory.getLogger(SimpleK8sDeployTest.class); - private static final String NAMESPACE = Environment.getInstance().namespace(); - private static IoTConfig config; - private io.enmasse.systemtest.platform.Kubernetes client = io.enmasse.systemtest.platform.Kubernetes.getInstance(); - - @BeforeAll - static void setup() throws Exception { - Map secrets = new HashMap<>(); - secrets.put("iot-auth-service", "systemtests-iot-auth-service-tls"); - secrets.put("iot-tenant-service", "systemtests-iot-tenant-service-tls"); - secrets.put("iot-device-connection", "systemtests-iot-device-connection-tls"); - secrets.put("iot-device-registry", "systemtests-iot-device-registry-tls"); - - var r1 = new ContainerConfigBuilder() - .withNewResources().addToLimits("memory", new Quantity("64Mi")).endResources() - .build(); - var j2 = new JavaContainerConfigBuilder() - .withNewContainerConfig() - .withNewResources().addToLimits("memory", new Quantity("256Mi")).endResources() - .endContainerConfig() - .build(); - - var commonContainers = new CommonAdapterContainersBuilder() - .withNewAdapterLike(j2).endAdapter() - .withNewProxyLike(r1).endProxy() - .withNewProxyConfiguratorLike(r1).endProxyConfigurator() - .build(); - - var jdbcEndpoint = SystemtestsKubernetesApps.deployPostgresqlServer(); - - config = IoTTestSession.createDefaultConfig() - - .editOrNewSpec() - - .editOrNewAdapters() - - .editOrNewHttp() - .withNewContainersLike(commonContainers).endContainers() - .endHttp() - - .editOrNewMqtt() - .withNewContainersLike(commonContainers).endContainers() - .endMqtt() - - .editOrNewSigfox() - .withNewContainersLike(commonContainers).endContainers() - .endSigfox() - - .editOrNewLoraWan() - .withNewContainersLike(commonContainers).endContainers() - .endLoraWan() - - .endAdapters() - - .withNewServices() - - .withNewAuthentication() - .withNewContainerLike(j2).endContainer() - .endAuthentication() - - .withNewTenant() - .withNewContainerLike(j2).endContainer() - .endTenant() - - .withDeviceConnection(DefaultDeviceRegistry.newPostgresBasedConnection(jdbcEndpoint)) - .withDeviceRegistry(DefaultDeviceRegistry.newPostgresBasedRegistry(jdbcEndpoint, false)) - - .editDeviceConnection() - .editJdbc() - .editOrNewCommonServiceConfig() - .withNewContainerLike(j2).endContainer() - .endCommonServiceConfig() - .endJdbc() - .endDeviceConnection() - - .editDeviceRegistry() - .editJdbc() - .editServer() - .editExternal() - .editManagement() - .editOrNewCommonConfig() - .withNewContainerLike(j2).endContainer() - .endCommonConfig() - .endManagement() - .endExternal() - .endServer() - .endJdbc() - .endDeviceRegistry() - - .endServices() - - .endSpec() - .build(); - - final Path configTempFile = Files.createTempFile("iot-config", "json"); - try { - Files.write(configTempFile, new ObjectMapper().writeValueAsBytes(config)); - KubeCMDClient.createFromFile(NAMESPACE, configTempFile); - } finally { - Files.deleteIfExists(configTempFile); - } - } - - @AfterAll - static void cleanup() throws Exception { - KubeCMDClient.deleteIoTConfig(NAMESPACE, "default"); - log.info("Waiting for IoT components to be removed"); - TestUtils.waitForNReplicas(0, NAMESPACE, singletonMap("component", "iot"), ofDuration(ofMinutes(5))); - } - - @Test - void testDeploy() throws Exception { - IoTUtils.waitForIoTConfigReady(client, config); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/HttpAdapterTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/HttpAdapterTest.java deleted file mode 100644 index ee4098122a3..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/HttpAdapterTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.http; - -import static io.enmasse.systemtest.TestTag.ISOLATED_IOT; -import static io.enmasse.systemtest.iot.DeviceSupplier.named; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; - -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; - -import io.enmasse.systemtest.iot.DeviceSupplier; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.http.StandardIoTHttpTests; - -@Tag(ISOLATED_IOT) -class HttpAdapterTest implements StandardIoTHttpTests { - - private static IoTTestSession session; - - @BeforeAll - public static void setup() throws Exception { - session = IoTTestSession.createDefault() - .adapters(HTTP) - .deploy(); - } - - @AfterAll - public static void cleanup() throws Exception { - if (session != null) { - session.close(); - session = null; - } - } - - @Override - public List getDevices() { - return Arrays.asList( - named("default", () -> session.newDevice() - .register() - .setPassword())); - } - - @Override - public List getInvalidDevices() { - return Arrays.asList( - named("invalidPassword", () -> session.newDevice() - .register() - .setPassword() - .overridePassword())); - } - - @Override - public IoTTestSession getSession() { - return session; - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/MaxPayloadSizeTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/MaxPayloadSizeTest.java deleted file mode 100644 index 7b57b6375fd..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/MaxPayloadSizeTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.http; - -import static io.enmasse.systemtest.iot.HttpAdapterClient.ResponseException.statusCode; - -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; -import io.enmasse.systemtest.iot.IoTTestSession.Device; -import io.enmasse.systemtest.iot.MessageSendTester.Sender; -import io.enmasse.systemtest.iot.isolated.AbstractMaxPayloadSizeTest; - -public class MaxPayloadSizeTest extends AbstractMaxPayloadSizeTest { - - @Override - protected Adapter adapter() { - return Adapter.HTTP; - } - - @SuppressWarnings("resource") - @Override - protected Sender sender(Device device) throws Exception { - return cleanup(device - .createHttpAdapterClient() - .suppressExceptions(statusCode(413)))::send; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MaxPayloadSizeTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MaxPayloadSizeTest.java deleted file mode 100644 index 5acfc5fb908..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MaxPayloadSizeTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.mqtt; - -import java.nio.charset.StandardCharsets; - -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; -import io.enmasse.systemtest.iot.IoTTestSession.Device; -import io.enmasse.systemtest.iot.MessageSendTester.Sender; -import io.enmasse.systemtest.iot.MessageSendTester.Type; -import io.enmasse.systemtest.iot.isolated.AbstractMaxPayloadSizeTest; - -public class MaxPayloadSizeTest extends AbstractMaxPayloadSizeTest { - - @Override - protected int reducePayloadBy(final Type type) { - // reduce by: 2 (length) + x (topic name) bytes + 2 (QoS 1 msg id) - return 2 + type.type().address().getBytes(StandardCharsets.UTF_8).length + 2; - } - - @Override - protected Adapter adapter() { - return Adapter.MQTT; - } - - @SuppressWarnings("resource") - @Override - protected Sender sender(Device device) throws Exception { - return cleanup(device.createMqttAdapterClient())::sendQos1; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MqttAdapterTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MqttAdapterTest.java deleted file mode 100644 index 9cc2b8e715f..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MqttAdapterTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.mqtt; - -import static io.enmasse.systemtest.TestTag.ISOLATED_IOT; -import static io.enmasse.systemtest.iot.DeviceSupplier.named; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.MQTT; - -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; - -import io.enmasse.systemtest.iot.DeviceSupplier; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.mqtt.StandardIoTMqttTests; - -/** - * Testing MQTT message transmission. - */ -@Tag(ISOLATED_IOT) -class MqttAdapterTest implements StandardIoTMqttTests { - - private static IoTTestSession session; - - @BeforeAll - public static void setup() throws Exception { - session = IoTTestSession.createDefault() - .adapters(MQTT) - .deploy(); - } - - @AfterAll - public static void cleanup() throws Exception { - if (session != null) { - session.close(); - session = null; - } - } - - @Override - public List getDevices() { - return Arrays.asList( - named("default", () -> session.newDevice() - .register() - .setPassword())); - } - - @Override - public List getInvalidDevices() { - return Arrays.asList( - named("invalidPassword", () -> session.newDevice() - .register() - .setPassword() - .overridePassword())); - } - - @Override - public IoTTestSession getSession() { - return session; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/project/ManagedTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/project/ManagedTest.java deleted file mode 100644 index eade350eb0e..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/project/ManagedTest.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.iot.isolated.project; - -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newDefaultInstance; -import static io.enmasse.systemtest.utils.AddressSpaceUtils.addressSpaceExists; -import static io.enmasse.systemtest.utils.TestUtils.waitUntilConditionOrFail; -import static java.time.Duration.ofMinutes; -import static java.time.Duration.ofSeconds; -import static org.hamcrest.collection.IsEmptyIterable.emptyIterable; -import static org.hamcrest.MatcherAssert.assertThat; - -import java.net.HttpURLConnection; -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; -import java.util.function.BiConsumer; - -import org.apache.qpid.proton.message.Message; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressList; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceList; -import io.enmasse.address.model.DoneableAddress; -import io.enmasse.address.model.DoneableAddressSpace; -import io.enmasse.address.model.KubeUtil; -import io.enmasse.iot.model.v1.DoneableIoTProject; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.iot.model.v1.IoTProjectBuilder; -import io.enmasse.iot.model.v1.IoTProjectList; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.iot.CredentialsRegistryClient; -import io.enmasse.systemtest.iot.DeviceRegistryClient; -import io.enmasse.systemtest.iot.HttpAdapterClient; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.Type; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.user.model.v1.DoneableUser; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserList; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -public class ManagedTest extends TestBase implements ITestIoTIsolated { - - private static final String MANAGED_TEST_ADDRESSSPACE = "managed-test-addrspace"; - - private static final Logger log = CustomLogger.getLogger(); - - private MixedOperation> client; - private MixedOperation> addressClient; - private MixedOperation> addressSpaceClient; - private MixedOperation> userClient; - protected DeviceRegistryClient registryClient; - protected CredentialsRegistryClient credentialsClient; - - private Endpoint httpAdapterEndpoint; - private UserCredentials credentials; - - @BeforeEach - public void initClients () throws Exception { - IoTConfig iotConfig = IoTTestSession.createDefaultConfig() - .editOrNewSpec().withServices(newDefaultInstance()).endSpec() - .build(); - - isolatedIoTManager.createIoTConfig(iotConfig); - - final Endpoint deviceRegistryEndpoint = IoTUtils.getDeviceRegistryManagementEndpoint(); - this.registryClient = new DeviceRegistryClient(deviceRegistryEndpoint); - this.credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint); - this.client = kubernetes.getIoTProjectClient(IOT_PROJECT_NAMESPACE); - this.addressClient = kubernetes.getAddressClient(IOT_PROJECT_NAMESPACE); - this.addressSpaceClient = kubernetes.getAddressSpaceClient(IOT_PROJECT_NAMESPACE); - this.userClient = kubernetes.getUserClient(IOT_PROJECT_NAMESPACE); - this.httpAdapterEndpoint = kubernetes.getExternalEndpoint("iot-http-adapter"); - - this.credentials = new UserCredentials(UUID.randomUUID().toString(), UUID.randomUUID().toString()); - } - - @Test - public void testChangeAddressSpace() throws Exception { - - var project = IoTUtils.getBasicIoTProjectObject("iot1", "as1", - IOT_PROJECT_NAMESPACE, getDefaultAddressSpacePlan()); - isolatedIoTManager.createIoTProject(project); - - assertManagedResources(Assertions::assertNotNull, project, "as1"); - - project = new IoTProjectBuilder(project) - .editSpec() - .editDownstreamStrategy() - .editManagedStrategy() - .editAddressSpace() - - .withName("as1a") - - .endAddressSpace() - .endManagedStrategy() - .endDownstreamStrategy() - .endSpec() - .build(); - - // update the project - - log.info("Update project namespace"); - client.createOrReplace(project); - - // immediately after the change, the project is still ready but the new - // address space is still missing, so we need to wait for it to be created - // otherwise io.enmasse.systemtest.utils.IoTUtils.waitForIoTProjectReady(Kubernetes, IoTProject) will fail - - waitUntilConditionOrFail( - addressSpaceExists(project.getMetadata().getNamespace(), project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName()), - ofMinutes(5), ofSeconds(10), - () -> String.format("Expected address space to be created")); - - // wait until the project and address space become ready - - log.info("For for project to become ready again"); - IoTUtils.waitForIoTProjectReady(kubernetes, project); - - // assert existence - - assertManagedResources(Assertions::assertNotNull, project, "as1a"); - assertManagedResources(Assertions::assertNull, project, "as1"); - } - - @Test - public void testTwoManagedToTheSameAddressSpace() throws Exception { - - // first create two projects for a single address space - - var project1 = IoTUtils.getBasicIoTProjectObject("iot1", MANAGED_TEST_ADDRESSSPACE, - IOT_PROJECT_NAMESPACE, getDefaultAddressSpacePlan()); - var project2 = IoTUtils.getBasicIoTProjectObject("iot2", MANAGED_TEST_ADDRESSSPACE, - IOT_PROJECT_NAMESPACE, getDefaultAddressSpacePlan()); - - var tenant1 = IoTUtils.getTenantId(project1); - var tenant2 = IoTUtils.getTenantId(project2); - - // wait for the projects to be ready - - isolatedIoTManager.createIoTProject(project1); - isolatedIoTManager.createIoTProject(project2); - - assertManagedResources(Assertions::assertNotNull, project1, MANAGED_TEST_ADDRESSSPACE); - assertManagedResources(Assertions::assertNotNull, project2, MANAGED_TEST_ADDRESSSPACE); - - // register two devices with the same ids, but for different tenants - - this.registryClient.registerDevice(tenant1, "device1"); - this.registryClient.registerDevice(tenant2, "device1"); - this.credentialsClient.addPlainPasswordCredentials(tenant1, "device1", "auth1", "password1", null, HttpURLConnection.HTTP_NO_CONTENT); - this.credentialsClient.addPlainPasswordCredentials(tenant2, "device1", "auth1", "password1", null, HttpURLConnection.HTTP_NO_CONTENT); - - // set up client - - isolatedIoTManager.createOrUpdateUser(isolatedIoTManager.getAddressSpace(IOT_PROJECT_NAMESPACE, MANAGED_TEST_ADDRESSSPACE), this.credentials); - var iotAmqpClientFactory = new AmqpClientFactory(this.resourcesManager.getAddressSpace(IOT_PROJECT_NAMESPACE, MANAGED_TEST_ADDRESSSPACE), this.credentials); - var amqpClient = iotAmqpClientFactory.createQueueClient(); - - // now try to send some messages - - final List otherMessages = new LinkedList<>(); - try ( - var httpAdapterClient = new HttpAdapterClient(this.httpAdapterEndpoint, "auth1", tenant1, "password1"); - var otherReceiver = MessageSendTester.ConsumerFactory.of(amqpClient, tenant2).start(Type.TELEMETRY, msg -> otherMessages.add(msg)) ) { - - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .amount(1) - .consumerFactory(MessageSendTester.ConsumerFactory.of(amqpClient, tenant1)) - .sender(httpAdapterClient::send) - .execute(); - - } - - assertThat(otherMessages, emptyIterable()); - } - - private void assertManagedResources(final BiConsumer assertor, final IoTProject project, final String addressSpaceName) { - assertObject(assertor, "Address space", this.addressSpaceClient, addressSpaceName); - assertObject(assertor, "Adapter user", this.userClient, addressSpaceName + ".adapter-" + project.getMetadata().getUid()); - for ( final String address : IOT_ADDRESSES) { - var addressName = address + "/" + IOT_PROJECT_NAMESPACE + "." + project.getMetadata().getName(); - var metaName = KubeUtil.sanitizeForGo(addressSpaceName, addressName); - assertObject(assertor, "Address: " + addressName + " / " + metaName, this.addressClient, metaName); - } - } - - private static void assertObject(final BiConsumer assertor, final String message, final MixedOperation client, final String name) { - var object = client.withName(name).get(); - assertor.accept(object, message); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/DeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/DeviceRegistryTest.java deleted file mode 100644 index fd709d39543..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/DeviceRegistryTest.java +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.SMOKE; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static java.net.HttpURLConnection.HTTP_CONFLICT; -import static java.net.HttpURLConnection.HTTP_CREATED; -import static java.net.HttpURLConnection.HTTP_NOT_FOUND; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.net.HttpURLConnection; -import java.nio.charset.StandardCharsets; -import java.time.Duration; -import java.time.Instant; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -import org.eclipse.hono.service.management.credentials.CommonCredential; -import org.eclipse.hono.service.management.credentials.PasswordCredential; -import org.eclipse.hono.service.management.device.Device; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.iot.CredentialsRegistryClient; -import io.enmasse.systemtest.iot.DeviceRegistryClient; -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; -import io.enmasse.systemtest.utils.IoTUtils; - -@Tag(SMOKE) -abstract class DeviceRegistryTest extends TestBase implements ITestIoTIsolated { - - private static final String DEVICE_REGISTRY_TEST_ADDRESSSPACE = "device-registry-test-addrspace"; - - private static final String DEVICE_REGISTRY_TEST_PROJECT = "device-registry-test-project"; - - private String randomDeviceId; - private IoTProject iotProject; - private Endpoint deviceRegistryEndpoint; - private Endpoint httpAdapterEndpoint; - private DeviceRegistryClient client; - - private UserCredentials credentials; - - private AmqpClientFactory iotAmqpClientFactory; - - private AmqpClient amqpClient; - - protected abstract IoTConfigBuilder provideIoTConfig() throws Exception; - - protected int tenantDoesNotExistCode() { - return HttpURLConnection.HTTP_UNAUTHORIZED; - } - - @BeforeEach - public void setAttributes() throws Exception { - var iotConfigBuilder = provideIoTConfig(); - - // disable all but HTTP - - for (Adapter adapter : Adapter.values()) { - iotConfigBuilder = adapter.disable(iotConfigBuilder); - } - iotConfigBuilder = HTTP.enable(iotConfigBuilder); - - // build config - - var iotConfig = iotConfigBuilder.build(); - - isolatedIoTManager.createIoTConfig(iotConfig); - - iotProject = IoTUtils.getBasicIoTProjectObject(DEVICE_REGISTRY_TEST_PROJECT, - DEVICE_REGISTRY_TEST_ADDRESSSPACE, IOT_PROJECT_NAMESPACE, getDefaultAddressSpacePlan()); - isolatedIoTManager.createIoTProject(iotProject); - - deviceRegistryEndpoint = IoTUtils.getDeviceRegistryManagementEndpoint(); - - httpAdapterEndpoint = kubernetes.getExternalEndpoint("iot-http-adapter"); - - client = new DeviceRegistryClient(deviceRegistryEndpoint); - - this.randomDeviceId = UUID.randomUUID().toString(); - - this.credentials = new UserCredentials(UUID.randomUUID().toString(), UUID.randomUUID().toString()); - isolatedIoTManager.createOrUpdateUser(isolatedIoTManager.getAddressSpace(IOT_PROJECT_NAMESPACE, DEVICE_REGISTRY_TEST_ADDRESSSPACE), this.credentials); - this.iotAmqpClientFactory = new AmqpClientFactory(resourcesManager.getAddressSpace(IOT_PROJECT_NAMESPACE, DEVICE_REGISTRY_TEST_ADDRESSSPACE), this.credentials); - this.amqpClient = iotAmqpClientFactory.createQueueClient(); - - } - - protected void doTestRegisterDevice() throws Exception { - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - final Device result = client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - assertNotNull(result); - assertDefaultEnabled(result.isEnabled()); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - } - - protected void doTestDisableDevice() throws Exception { - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - final Device payload = new Device(); - payload.setEnabled(false); - - client.updateDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, payload); - - final Device result = client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - - // as we set it explicitly, we expect the explicit value of "false" - assertEquals(Boolean.FALSE, result.isEnabled()); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - } - - protected void doTestDeviceCredentials() throws Exception { - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - String authId = "sensor-" + UUID.randomUUID().toString(); - String password = "password1234"; - credentialsClient.addCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, password, null, HttpURLConnection.HTTP_NO_CONTENT); - - IoTUtils.checkCredentials(authId, password, false, httpAdapterEndpoint, amqpClient, iotProject); - - credentialsClient.deleteAllCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - - } - } - - protected void doTestDeviceCredentialsPlainPassword() throws Exception { - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - String authId = "sensor-" + UUID.randomUUID().toString(); - String password = "password1234"; - credentialsClient.addPlainPasswordCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, password, null, HttpURLConnection.HTTP_NO_CONTENT); - - IoTUtils.checkCredentials(authId, password, false, httpAdapterEndpoint, amqpClient, iotProject); - - credentialsClient.deleteAllCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - - } - } - - protected void doTestDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - String authId = "sensor-" + UUID.randomUUID().toString(); - String password = "password1234"; - credentialsClient.addPlainPasswordCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, password, null, HttpURLConnection.HTTP_NO_CONTENT); - - List credentials = credentialsClient.getCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - assertEquals(1, credentials.size()); - PasswordCredential passwordCredential = ((PasswordCredential) credentials.get(0)); - assertEquals(1, passwordCredential.getSecrets().size()); - assertNull(passwordCredential.getSecrets().get(0).getHashFunction()); - assertNull(passwordCredential.getSecrets().get(0).getPasswordHash()); - assertNull(passwordCredential.getSecrets().get(0).getPasswordPlain()); - assertNull(passwordCredential.getSecrets().get(0).getSalt()); - - credentialsClient.deleteAllCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - - } - } - - - protected void doTestCacheExpiryForCredentials() throws Exception { - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - - final Duration cacheExpiration = Duration.ofMinutes(3); - - // register device - - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - final String authId = UUID.randomUUID().toString(); - final String password = "password1234"; - credentialsClient.addCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, password, null, HttpURLConnection.HTTP_NO_CONTENT); - - // first test, cache filled - - IoTUtils.checkCredentials(authId, password, false, httpAdapterEndpoint, amqpClient, iotProject); - - // set new password - - final String newPassword = "new-password1234"; - credentialsClient.updateCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, newPassword, null); - - // expect failure due to cached info - - IoTUtils.checkCredentials(authId, newPassword, true, httpAdapterEndpoint, amqpClient, iotProject); - LOGGER.info("Waiting {} seconds for credentials to expire", cacheExpiration); - Thread.sleep(cacheExpiration.toMillis()); - - // cache must be expired, new password can be used - - IoTUtils.checkCredentials(authId, newPassword, false, httpAdapterEndpoint, amqpClient, iotProject); - - credentialsClient.deleteAllCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - } - } - - - protected void doTestSetExpiryForCredentials() throws Exception { - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - final String authId = UUID.randomUUID().toString(); - final Duration expiry = Duration.ofSeconds(30); - final Instant notAfter = Instant.now().plus(expiry); - final String newPassword = "password1234"; - - credentialsClient.addCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, newPassword, notAfter, HttpURLConnection.HTTP_NO_CONTENT); - - // first check, must succeed - Thread.sleep(20_000); - IoTUtils.checkCredentials(authId, newPassword, false, httpAdapterEndpoint, amqpClient, iotProject); - - LOGGER.info("Waiting {} for credentials to expire", expiry); - Thread.sleep(expiry.toMillis()); - - // second check, after expiration, must fail - - IoTUtils.checkCredentials(authId, newPassword, true, httpAdapterEndpoint, amqpClient, iotProject); - - credentialsClient.deleteAllCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - } - } - - - protected void doTestCreateForNonExistingTenantFails() throws Exception { - var response = client.registerDeviceWithResponse("invalid-" + isolatedIoTManager.getTenantId(), randomDeviceId); - assertEquals(tenantDoesNotExistCode(), response.statusCode()); - } - - protected void doTestTenantDeletionTriggersDevicesDeletion() throws Exception { - var tenantId = isolatedIoTManager.getTenantId(); - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - client.registerDevice(tenantId, randomDeviceId); - - final String authId = UUID.randomUUID().toString(); - final Duration expiry = Duration.ofSeconds(30); - final Instant notAfter = Instant.now().plus(expiry); - final String newPassword = "password1234"; - - credentialsClient.addCredentials(tenantId, randomDeviceId, authId, newPassword, notAfter, HttpURLConnection.HTTP_NO_CONTENT); - - // first check, must succeed - - IoTUtils.checkCredentials(authId, newPassword, false, httpAdapterEndpoint, amqpClient, iotProject); - - // Now delete the tenant - isolatedIoTManager.deleteIoTProject(iotProject); - - // second check, the credentials and device should be deleted - - client.getDeviceRegistration(tenantId, randomDeviceId, tenantDoesNotExistCode()); - IoTUtils.checkCredentials(authId, newPassword, true, httpAdapterEndpoint, amqpClient, iotProject); - } - } - - protected void doCreateDuplicateDeviceFails() throws Exception { - var tenantId = isolatedIoTManager.getTenantId(); - var deviceId = UUID.randomUUID().toString(); - - // create device - - var response = client.registerDeviceWithResponse(tenantId, deviceId); - assertEquals(HTTP_CREATED, response.statusCode()); - - // create device a second time - - var response2 = client.registerDeviceWithResponse(tenantId, deviceId); - assertEquals(HTTP_CONFLICT, response2.statusCode()); - } - - @Test - public void testDeviceWithSameAuthIdOfDifferentTypesSucceeds() throws Exception { - - var tenantId = isolatedIoTManager.getTenantId(); - var deviceId = UUID.randomUUID().toString(); - - // create device - - client.registerDevice(tenantId, deviceId); - - var authId = UUID.randomUUID().toString(); - - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - credentialsClient.addPlainPasswordCredentials(tenantId, deviceId, authId, "foo-bar", null, HttpURLConnection.HTTP_NO_CONTENT); - credentialsClient.addPskCredentials(tenantId, deviceId, authId, "foo-bar".getBytes(StandardCharsets.UTF_8), null, HttpURLConnection.HTTP_NO_CONTENT); - } - - } - - @Test - public void testDeviceWithSameAuthIdOfSameTypesFails() throws Exception { - - var tenantId = isolatedIoTManager.getTenantId(); - var deviceId1 = UUID.randomUUID().toString(); - var deviceId2 = UUID.randomUUID().toString(); - - // create device - - client.registerDevice(tenantId, deviceId1); - client.registerDevice(tenantId, deviceId2); - - var authId = UUID.randomUUID().toString(); - - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - // must succeed - credentialsClient.addPlainPasswordCredentials(tenantId, deviceId1, authId, "foo-bar", null, HttpURLConnection.HTTP_NO_CONTENT); - // must fail - credentialsClient.addPlainPasswordCredentials(tenantId, deviceId2, authId, "foo-bar", null, HttpURLConnection.HTTP_BAD_REQUEST); - } - - } - - protected void doRegisterMultipleDevices() throws Exception { - - final String tenantId = isolatedIoTManager.getTenantId(); - final String prefix = UUID.randomUUID().toString(); - final Set devices = new HashSet<>(); - - for (int i = 0; i < 1_000; i++) { - var deviceId = prefix + "-" + UUID.randomUUID().toString(); - client.registerDevice(tenantId, deviceId); - devices.add(deviceId); - } - - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - for (final String deviceId : devices) { - credentialsClient.addPlainPasswordCredentials(tenantId, deviceId, UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, HttpURLConnection.HTTP_NO_CONTENT); - } - } - - for (final String deviceId : devices) { - final Device result = client.getDeviceRegistration(tenantId, deviceId); - assertNotNull(result); - assertDefaultEnabled(result.isEnabled()); - } - - for (final String deviceId : devices) { - client.deleteDeviceRegistration(tenantId, deviceId); - } - - for (final String deviceId : devices) { - client.getDeviceRegistration(tenantId, deviceId, HTTP_NOT_FOUND); - } - - } - -} \ No newline at end of file diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/H2DeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/H2DeviceRegistryTest.java deleted file mode 100644 index e1552f0288e..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/H2DeviceRegistryTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newH2Based; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectDeviceConnectionType; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectRegistryType; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.IOException; -import java.time.Duration; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeoutException; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; - -class H2DeviceRegistryTest extends DeviceRegistryTest { - - private final Logger log = CustomLogger.getLogger(); - - @Override - protected IoTConfigBuilder provideIoTConfig() throws Exception { - return IoTTestSession - .createDefaultConfig() - .editOrNewSpec() - .withServices(newH2Based()) - .endSpec(); - } - - @Test - void testCorrectTypeDeployed () { - assertCorrectDeviceConnectionType("jdbc"); - assertCorrectRegistryType("jdbc"); - } - - @Test - @Tag(ACCEPTANCE) - void testRegisterDevice() throws Exception { - super.doTestRegisterDevice(); - } - - @Test - @Tag(ACCEPTANCE) - void testDisableDevice() throws Exception { - super.doTestDisableDevice(); - } - - @Test - void testDeviceCredentials() throws Exception { - super.doTestDeviceCredentials(); - } - - @Test - void testDeviceCredentialsPlainPassword() throws Exception { - super.doTestDeviceCredentialsPlainPassword(); - } - - @Test - @Disabled("Fixed in hono/pull/1565") - void testDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - super.doTestDeviceCredentialsDoesNotContainsPasswordDetails(); - } - - @Test - @Disabled("Caches expire a bit unpredictably") - void testCacheExpiryForCredentials() throws Exception { - super.doTestCacheExpiryForCredentials(); - } - - @Test - void testSetExpiryForCredentials() throws Exception { - super.doTestSetExpiryForCredentials(); - } - - @Test - void testCreateForNonExistingTenantFails() throws Exception { - super.doTestCreateForNonExistingTenantFails(); - } - - @Test - void testCreateDuplicateDeviceFails() throws Exception { - super.doCreateDuplicateDeviceFails(); - } - - @Test - void testRegisterMultipleDevices() throws Exception { - super.doRegisterMultipleDevices(); - } - - @Test - void testTenantDeletionTriggersDevicesDeletion() throws Exception { - super.doTestTenantDeletionTriggersDevicesDeletion(); - - // dump content, just in case - - dumpH2Database(); - - // ensure that the database is still present, but has zero entries - - final List command = new ArrayList<>(Arrays.asList(SystemtestsKubernetesApps.H2_SHELL_COMMAND)); - command.addAll(Arrays.asList("-sql", "select count(*) as NUM from device_registrations")); - - var pod = SystemtestsKubernetesApps - .getH2ServerPod() - .orElseThrow(() -> new IllegalStateException("Unable to find H2 server pod")); - final String[] result = Kubernetes.executeWithInput(pod, null, null, Duration.ofSeconds(10), - command.toArray(String[]::new) - ) - .split("[\r\n]+"); - - // must have three lines - assertEquals(3, result.length); - // first: the column name - assertEquals("NUM", result[0]); - // second: the number of entries, which must be zero - assertEquals("0", result[1]); - // third: the execution statistics, which we ignore - - } - - private void dumpH2Database() throws IOException, InterruptedException, TimeoutException { - final List command = new ArrayList<>(Arrays.asList(SystemtestsKubernetesApps.H2_SHELL_COMMAND)); - command.addAll(Arrays.asList("-sql", "select * from device_registrations")); - - var pod = SystemtestsKubernetesApps - .getH2ServerPod() - .orElseThrow(() -> new IllegalStateException("Unable to find H2 server pod")); - final String result = Kubernetes.executeWithInput(pod, null, null, Duration.ofSeconds(10), - command.toArray(String[]::new)); - - log.info("Current H2 database:\n{}", result); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/InfinispanDeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/InfinispanDeviceRegistryTest.java deleted file mode 100644 index c510e7ed00c..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/InfinispanDeviceRegistryTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newInfinispanBased; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectDeviceConnectionType; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectRegistryType; - -import java.net.HttpURLConnection; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.systemtest.iot.IoTTestSession; - -class InfinispanDeviceRegistryTest extends DeviceRegistryTest { - - @Override - protected int tenantDoesNotExistCode() { - return HttpURLConnection.HTTP_UNAUTHORIZED; - } - - @Override - protected IoTConfigBuilder provideIoTConfig() throws Exception { - return IoTTestSession - .createDefaultConfig() - .editOrNewSpec() - .withServices(newInfinispanBased()) - .endSpec(); - } - - @Test - void testCorrectTypeDeployed () { - assertCorrectDeviceConnectionType("infinispan"); - assertCorrectRegistryType("infinispan"); - } - - @Test - @Tag(ACCEPTANCE) - void testRegisterDevice() throws Exception { - super.doTestRegisterDevice(); - } - - @Test - @Tag(ACCEPTANCE) - void testDisableDevice() throws Exception { - super.doTestDisableDevice(); - } - - @Test - void testDeviceCredentials() throws Exception { - super.doTestDeviceCredentials(); - } - - @Test - void testDeviceCredentialsPlainPassword() throws Exception { - super.doTestDeviceCredentialsPlainPassword(); - } - - @Test - @Disabled("Fixed in hono/pull/1565") - void testDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - super.doTestDeviceCredentialsDoesNotContainsPasswordDetails(); - } - - @Test - @Disabled("Caches expire a bit unpredictably") - void testCacheExpiryForCredentials() throws Exception { - super.doTestCacheExpiryForCredentials(); - } - - @Test - void testSetExpiryForCredentials() throws Exception { - super.doTestSetExpiryForCredentials(); - } - - @Test - void testCreateForNonExistingTenantFails() throws Exception { - super.doTestCreateForNonExistingTenantFails(); - } - - @Test - void testCreateDuplicateDeviceFails() throws Exception { - super.doCreateDuplicateDeviceFails(); - } - - @Test - void testRegisterMultipleDevices() throws Exception { - super.doRegisterMultipleDevices(); - } - - @Test - void testTenantDeletionTriggersDevicesDeletion() throws Exception { - super.doTestTenantDeletionTriggersDevicesDeletion(); - } - - @Override - @Disabled("Not supported by Infinispan") - public void testDeviceWithSameAuthIdOfSameTypesFails() throws Exception { - super.testDeviceWithSameAuthIdOfSameTypesFails(); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/MixedDeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/MixedDeviceRegistryTest.java deleted file mode 100644 index a69acad66cf..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/MixedDeviceRegistryTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newPostgresBasedRegistry; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectDeviceConnectionType; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectRegistryType; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.systemtest.iot.DefaultDeviceRegistry; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; - -class MixedDeviceRegistryTest extends DeviceRegistryTest { - - @Override - protected IoTConfigBuilder provideIoTConfig() throws Exception { - - var jdbcEndpoint = SystemtestsKubernetesApps.deployPostgresqlServer(); - var infinispanEndpoint = SystemtestsKubernetesApps.deployInfinispanServer(); - - return IoTTestSession - .createDefaultConfig() - .editOrNewSpec() - .withNewServices() - .withDeviceConnection(DefaultDeviceRegistry.newInfinispanDeviceConnectionService(infinispanEndpoint)) - .withDeviceRegistry(newPostgresBasedRegistry(jdbcEndpoint, false)) - .endServices() - .endSpec(); - - } - - @Test - void testCorrectTypeDeployed () { - assertCorrectDeviceConnectionType("infinispan"); - assertCorrectRegistryType("jdbc"); - } - - @Test - @Tag(ACCEPTANCE) - void testRegisterDevice() throws Exception { - super.doTestRegisterDevice(); - } - - @Test - @Tag(ACCEPTANCE) - void testDisableDevice() throws Exception { - super.doTestDisableDevice(); - } - - @Test - void testDeviceCredentials() throws Exception { - super.doTestDeviceCredentials(); - } - - @Test - void testDeviceCredentialsPlainPassword() throws Exception { - super.doTestDeviceCredentialsPlainPassword(); - } - - @Test - @Disabled("Fixed in hono/pull/1565") - void testDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - super.doTestDeviceCredentialsDoesNotContainsPasswordDetails(); - } - - @Test - @Disabled("Caches expire a bit unpredictably") - void testCacheExpiryForCredentials() throws Exception { - super.doTestCacheExpiryForCredentials(); - } - - @Test - void testSetExpiryForCredentials() throws Exception { - super.doTestSetExpiryForCredentials(); - } - - @Test - void testCreateForNonExistingTenantFails() throws Exception { - super.doTestCreateForNonExistingTenantFails(); - } - - @Test - void testCreateDuplicateDeviceFails() throws Exception { - super.doCreateDuplicateDeviceFails(); - } - - @Test - void testRegisterMultipleDevices() throws Exception { - super.doRegisterMultipleDevices(); - } - - @Test - void testTenantDeletionTriggersDevicesDeletion() throws Exception { - super.doTestTenantDeletionTriggersDevicesDeletion(); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableDeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableDeviceRegistryTest.java deleted file mode 100644 index f0491ad3aef..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableDeviceRegistryTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newPostgresBased; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectDeviceConnectionType; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectRegistryType; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.systemtest.iot.IoTTestSession; - -class PostgresTableDeviceRegistryTest extends DeviceRegistryTest { - - @Override - protected IoTConfigBuilder provideIoTConfig() throws Exception { - return IoTTestSession - .createDefaultConfig() - .editOrNewSpec() - .withServices(newPostgresBased(false)) - .endSpec(); - } - - @Test - void testCorrectTypeDeployed () { - assertCorrectDeviceConnectionType("jdbc"); - assertCorrectRegistryType("jdbc"); - } - - @Test - @Tag(ACCEPTANCE) - void testRegisterDevice() throws Exception { - super.doTestRegisterDevice(); - } - - @Test - @Tag(ACCEPTANCE) - void testDisableDevice() throws Exception { - super.doTestDisableDevice(); - } - - @Test - void testDeviceCredentials() throws Exception { - super.doTestDeviceCredentials(); - } - - @Test - void testDeviceCredentialsPlainPassword() throws Exception { - super.doTestDeviceCredentialsPlainPassword(); - } - - @Test - @Disabled("Fixed in hono/pull/1565") - void testDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - super.doTestDeviceCredentialsDoesNotContainsPasswordDetails(); - } - - @Test - @Disabled("Caches expire a bit unpredictably") - void testCacheExpiryForCredentials() throws Exception { - super.doTestCacheExpiryForCredentials(); - } - - @Test - void testSetExpiryForCredentials() throws Exception { - super.doTestSetExpiryForCredentials(); - } - - @Test - void testCreateForNonExistingTenantFails() throws Exception { - super.doTestCreateForNonExistingTenantFails(); - } - - @Test - void testCreateDuplicateDeviceFails() throws Exception { - super.doCreateDuplicateDeviceFails(); - } - - @Test - void testRegisterMultipleDevices() throws Exception { - super.doRegisterMultipleDevices(); - } - - @Test - void testTenantDeletionTriggersDevicesDeletion() throws Exception { - super.doTestTenantDeletionTriggersDevicesDeletion(); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableSplitDeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableSplitDeviceRegistryTest.java deleted file mode 100644 index 307a9a085e9..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableSplitDeviceRegistryTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newPostgresBased; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectRegistryType; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.systemtest.iot.IoTTestSession; - -/** - * Postgres table model, split adapter and management pods. - */ -class PostgresTableSplitDeviceRegistryTest extends DeviceRegistryTest { - - @Override - protected IoTConfigBuilder provideIoTConfig() throws Exception { - return IoTTestSession - .createDefaultConfig() - .editOrNewSpec() - .withServices(newPostgresBased(true)) - .endSpec(); - } - - @Test - void testCorrectTypeDeployed () { - assertCorrectRegistryType("jdbc"); - } - - @Test - @Tag(ACCEPTANCE) - void testRegisterDevice() throws Exception { - super.doTestRegisterDevice(); - } - - @Test - @Tag(ACCEPTANCE) - void testDisableDevice() throws Exception { - super.doTestDisableDevice(); - } - - @Test - void testDeviceCredentials() throws Exception { - super.doTestDeviceCredentials(); - } - - @Test - void testDeviceCredentialsPlainPassword() throws Exception { - super.doTestDeviceCredentialsPlainPassword(); - } - - @Test - @Disabled("Fixed in hono/pull/1565") - void testDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - super.doTestDeviceCredentialsDoesNotContainsPasswordDetails(); - } - - @Test - @Disabled("Caches expire a bit unpredictably") - void testCacheExpiryForCredentials() throws Exception { - super.doTestCacheExpiryForCredentials(); - } - - @Test - void testSetExpiryForCredentials() throws Exception { - super.doTestSetExpiryForCredentials(); - } - - @Test - void testCreateForNonExistingTenantFails() throws Exception { - super.doTestCreateForNonExistingTenantFails(); - } - - @Test - void testCreateDuplicateDeviceFails() throws Exception { - super.doCreateDuplicateDeviceFails(); - } - - @Test - void testRegisterMultipleDevices() throws Exception { - super.doRegisterMultipleDevices(); - } - - @Test - void testTenantDeletionTriggersDevicesDeletion() throws Exception { - super.doTestTenantDeletionTriggersDevicesDeletion(); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/ReloadCertificatesTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/ReloadCertificatesTest.java deleted file mode 100644 index 0e06318f3f9..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/ReloadCertificatesTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.tls; - -import static io.enmasse.systemtest.TestTag.ISOLATED; -import static io.enmasse.systemtest.condition.OpenShiftVersion.OCP4; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static io.enmasse.systemtest.time.TimeoutBudget.ofDuration; -import static java.time.Duration.ofMinutes; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.time.Duration; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.condition.OpenShift; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.IoTTestSession.Device; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.client.KubernetesClient; - -@Tag(ISOLATED) -public class ReloadCertificatesTest extends TestBase implements ITestIoTIsolated { - - private static final String NAMESPACE = Kubernetes.getInstance().getInfraNamespace(); - - private KubernetesClient client = Kubernetes.getInstance().getClient(); - - @Test - @OpenShift(version = OCP4) - public void testRecreateCertificate() throws Exception { - - IoTTestSession - .createDefault() - .adapters(HTTP) - .config(config -> { - // ensure we are using the service-ca - config.editOrNewSpec() - .withNewInterServiceCertificates() - .withNewServiceCAStrategy() - .endServiceCAStrategy() - .endInterServiceCertificates() - - .editOrNewAdapters() - .editOrNewHttp() - // reset to use service CA endpoint secret - .withNewEndpoint().endEndpoint() - .endHttp() - .endAdapters() - - .endSpec(); - }) - .run((session) -> { - - var deviceId = UUID.randomUUID().toString(); - var authId = UUID.randomUUID().toString(); - var password = UUID.randomUUID().toString(); - var device = session.newDevice(deviceId) - .register() - .setPassword(authId, password); - - // ensure everything works before starting - - assertTelemetryWorks(session, device); - - // get current pod - - var deploymentAccess = this.client - .apps().deployments() - .inNamespace(NAMESPACE) - .withName("iot-http-adapter"); - - var pod = this.client - .pods() - .inNamespace(NAMESPACE).withLabels(Map.of( - "app", "enmasse", - "name", "iot-http-adapter")) - .list().getItems().stream() - .map(p -> p.getMetadata().getName()) - .findFirst() - .orElse(null); - - assertNotNull(pod); - - // then: reset http adapter key/cert - - var deleteResult = this.client.secrets() - .inNamespace(NAMESPACE) - .withName("iot-http-adapter-tls") - .delete(); - - assertEquals(Boolean.TRUE, deleteResult); - - final TimeoutBudget budget = ofDuration(ofMinutes(10)); - - // wait until the deployment has changed - - var initialVersion = deploymentAccess.get().getMetadata().getResourceVersion(); - TestUtils.waitForChangedResourceVersion(budget, initialVersion, () -> { - return Optional.ofNullable(deploymentAccess.get()) - .map(d -> d.getMetadata().getResourceVersion()) - .orElse(initialVersion); - }); - - // and wait until the IoTConfig is ready again - - IoTUtils.waitForIoTConfigReady(Kubernetes.getInstance(), session.getConfig()); - - // now try to send messages again - - assertTelemetryWorks(session, device); - - }); - - } - - protected void assertTelemetryWorks(final IoTTestSession session, final Device device) throws Exception { - try (var adapterClient = device.createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofMillis(500)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(adapterClient::send) - .amount(30) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/TlsVersionTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/TlsVersionTest.java deleted file mode 100644 index e75bf753189..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/TlsVersionTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.tls; - -import static io.enmasse.systemtest.TestTag.ISOLATED; -import static java.util.Collections.singleton; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.time.Duration; -import java.util.concurrent.TimeoutException; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.systemtest.condition.OpenShift; -import io.enmasse.systemtest.condition.OpenShiftVersion; -import io.enmasse.systemtest.iot.HttpAdapterClient; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; - -@Tag(ISOLATED) -public class TlsVersionTest { - - @OpenShift(version = OpenShiftVersion.OCP4) - @Test - public void testWithExplicitVersion() throws Exception { - IoTTestSession - .createDefault() - .adapters(Adapter.HTTP) - .config(config -> config - .editOrNewSpec() - .editOrNewTls() - .withVersions("TLSv1.3") - .endTls() - .endSpec()) - .run(session -> { - - var device = session.registerNewRandomDeviceWithPassword(); - - try (HttpAdapterClient client = device.createHttpAdapterClient(singleton("TLSv1.3"))) { - - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(client::send) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - - } - - try (HttpAdapterClient client = device.createHttpAdapterClient(singleton("TLSv1.2"))) { - - // this must fail, as we offer TLSv1.2, but have only 1.3 configured - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(client::send) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - - } - - }); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/StandardX509Cases.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/StandardX509Cases.java deleted file mode 100644 index 0afb7cdc95e..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/StandardX509Cases.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.x509; - -import static io.enmasse.systemtest.iot.DeviceSupplier.named; - -import java.time.Duration; -import java.time.Instant; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -import javax.security.auth.x500.X500Principal; - -import io.enmasse.systemtest.iot.DeviceCertificateManager; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; -import io.enmasse.systemtest.iot.DeviceSupplier; -import io.enmasse.systemtest.iot.StandardIoTTests; - -public interface StandardX509Cases extends StandardIoTTests { - - DeviceCertificateManager getCertificateManager(); - - @Override - default List getDevices() { - - return Arrays.asList( - named("default", () -> getSession().newDevice() - .register() - .enableX509(getCertificateManager().createDevice()))); - - } - - @Override - default List getInvalidDevices() { - - return Arrays.asList( - notOurCaDevice(), - expiredCertificate(), - futureCertificate()); - - } - - /** - * Create a device which has a certificate signed by a CA with the same name, but which actually is - * not the same CA. - */ - default DeviceSupplier notOurCaDevice() { - - return named("notOurCa", () -> { - var otherMgr = new DeviceCertificateManager(Mode.RSA, new X500Principal("OU=Tenant 1,OU=IoT,O=EnMasse,C=IO")); - - return getSession().newDevice() - .register() - .enableX509(otherMgr.createDevice()); - }); - - } - - /** - * Create a device which has an expired certificate. - */ - default DeviceSupplier expiredCertificate() { - - final Instant now = Instant.now(); - - return named("expiredCertificate", () -> getSession().newDevice() - .register() - .enableX509(getCertificateManager() - .createDevice( - UUID.randomUUID().toString(), - now.minus(Duration.ofDays(30)), - now))); - - } - - /** - * Create a device which has an valid date in the future. - */ - default DeviceSupplier futureCertificate() { - - final Instant now = Instant.now(); - - return named("futureCertificate", () -> getSession().newDevice() - .register() - .enableX509(getCertificateManager() - .createDevice( - UUID.randomUUID().toString(), - now.plus(Duration.ofDays(100)), - now.plus(Duration.ofDays(200))))); - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/TrustAnchorTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/TrustAnchorTests.java deleted file mode 100644 index 4d287b288b3..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/TrustAnchorTests.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.x509; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.TestTag.ISOLATED_IOT; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static io.enmasse.systemtest.utils.TestUtils.toPem; - -import java.time.Duration; -import java.util.Optional; -import java.util.UUID; - -import javax.security.auth.x500.X500Principal; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.iot.model.v1.IoTProjectBuilder; -import io.enmasse.iot.model.v1.IoTProjectStatus; -import io.enmasse.iot.model.v1.ProjectConditionType; -import io.enmasse.systemtest.iot.DeviceCertificateManager; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.IoTTests; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; - -@Tag(ISOLATED_IOT) -public class TrustAnchorTests implements IoTTests { - - private static final Logger log = LoggerFactory.getLogger(TrustAnchorTests.class); - - /** - * Test creating duplicate "subject dn". - */ - @Test - @Tag(ACCEPTANCE) - public void testDuplicateSubjectDn() throws Exception { - var mgr1 = new DeviceCertificateManager(Mode.RSA, new X500Principal("OU=Tenant 1,OU=IoT,O=EnMasse,C=IO")); - var mgr2 = new DeviceCertificateManager(Mode.RSA, new X500Principal("OU=Tenant 1,OU=IoT,O=EnMasse,C=IO")); - - final String name2 = UUID.randomUUID().toString(); - final String ns2 = UUID.randomUUID().toString(); - Kubernetes.getInstance().createNamespace(ns2); - - try (IoTTestSession session = IoTTestSession.createDefault() - .project(project -> project.editOrNewSpec() - .editOrNewConfiguration() - .addNewTrustAnchor() - .withCertificate(toPem(mgr1.getCertificate())) - .endTrustAnchor() - .endConfiguration() - .endSpec()) - .adapters(HTTP) - .deploy()) { - - // now create a second project, in second namespace, with a new CA - // having the same name. This must fail. - - var project2 = new IoTProjectBuilder(IoTUtils.getBasicIoTProjectObject( - name2, name2, ns2, - AddressSpacePlans.STANDARD_SMALL)) - - .editOrNewSpec() - .editOrNewConfiguration() - .addNewTrustAnchor() - .withCertificate(toPem(mgr2.getCertificate())) - .endTrustAnchor() - .endConfiguration() - .endSpec() - - .build(); - - // create - - var projectClient = Kubernetes.getInstance().getIoTProjectClient(ns2); - session.addCleanup(() -> IoTUtils.deleteIoTProjectAndWait(project2)); - projectClient.create(project2); - var projectAccess = projectClient.withName(name2); - - // and wait for the condition - - TestUtils.waitUntilConditionOrFail(() -> { - - // wait until the condition 'TrustAnchorsUnique' becomes false - return Optional - .ofNullable(projectAccess.get()) - .map(IoTProject::getStatus) - .map(IoTProjectStatus::getConditions) - .flatMap(c -> c.stream() - .filter(condition -> condition.getType() == ProjectConditionType.TRUST_ANCHORS_UNIQUE) - .findAny()) - .map(c -> "false".equalsIgnoreCase(c.getStatus()) && - "DuplicateTrustAnchors".equals(c.getReason())) - .orElse(false); - - }, Duration.ofMinutes(5), Duration.ofSeconds(10), () -> "Conditions 'TrustAnchorsUnique' should become 'false'"); - - log.info("Successfully detected 'DuplicateTrustAnchors' problem on second project"); - - } - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509EcAuthenticationTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509EcAuthenticationTests.java deleted file mode 100644 index bdfa0237ceb..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509EcAuthenticationTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.x509; - -import static io.enmasse.systemtest.TestTag.ISOLATED_IOT; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.MQTT; -import static io.enmasse.systemtest.utils.TestUtils.toPem; - -import javax.security.auth.x500.X500Principal; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; - -import io.enmasse.systemtest.iot.DeviceCertificateManager; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.http.StandardIoTHttpTests; -import io.enmasse.systemtest.iot.mqtt.StandardIoTMqttTests; - -@Tag(ISOLATED_IOT) -public class X509EcAuthenticationTests implements StandardX509Cases, StandardIoTHttpTests, StandardIoTMqttTests { - - private static DeviceCertificateManager certificateManager; - private static IoTTestSession session; - - @BeforeAll - public static void setup() throws Exception { - - certificateManager = new DeviceCertificateManager(Mode.EC, new X500Principal("OU=Tenant 1,OU=IoT,O=EnMasse,C=IO")); - - session = IoTTestSession.createDefault() - .project(project -> project.editOrNewSpec() - .editOrNewConfiguration() - .addNewTrustAnchor() - .withCertificate(toPem(certificateManager.getCertificate())) - .endTrustAnchor() - .endConfiguration() - .endSpec()) - .adapters(MQTT, HTTP) - .deploy(); - - } - - @AfterAll - public static void cleanup() throws Exception { - if (session != null) { - session.close(); - session = null; - } - } - - @Override - public DeviceCertificateManager getCertificateManager() { - return certificateManager; - } - - @Override - public IoTTestSession getSession() { - return session; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509RsaAuthenticationTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509RsaAuthenticationTests.java deleted file mode 100644 index 7b3540767c1..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509RsaAuthenticationTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.x509; - -import static io.enmasse.systemtest.TestTag.ISOLATED_IOT; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.MQTT; -import static io.enmasse.systemtest.utils.TestUtils.toPem; - -import javax.security.auth.x500.X500Principal; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; - -import io.enmasse.systemtest.iot.DeviceCertificateManager; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.http.StandardIoTHttpTests; -import io.enmasse.systemtest.iot.mqtt.StandardIoTMqttTests; - -@Tag(ISOLATED_IOT) -public class X509RsaAuthenticationTests implements StandardX509Cases, StandardIoTHttpTests, StandardIoTMqttTests { - - private static DeviceCertificateManager certificateManager; - private static IoTTestSession session; - - @BeforeAll - public static void setup() throws Exception { - - certificateManager = new DeviceCertificateManager(Mode.RSA, new X500Principal("OU=Tenant 1,OU=IoT,O=EnMasse,C=IO")); - - session = IoTTestSession.createDefault() - .project(project -> project.editOrNewSpec() - .editOrNewConfiguration() - .addNewTrustAnchor() - .withCertificate(toPem(certificateManager.getCertificate())) - .endTrustAnchor() - .endConfiguration() - .endSpec()) - .adapters(MQTT, HTTP) - .deploy(); - - } - - @AfterAll - public static void cleanup() throws Exception { - if (session != null) { - session.close(); - session = null; - } - } - - @Override - public DeviceCertificateManager getCertificateManager() { - return certificateManager; - } - - @Override - public IoTTestSession getSession() { - return session; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/mqtt/StandardIoTMqttTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/mqtt/StandardIoTMqttTests.java deleted file mode 100644 index dcf43f5bba6..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/mqtt/StandardIoTMqttTests.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.mqtt; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.fail; - -import java.time.Duration; -import java.util.concurrent.TimeoutException; - -import javax.net.ssl.SSLHandshakeException; - -import org.eclipse.paho.client.mqttv3.MqttSecurityException; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Throwables; - -import io.enmasse.systemtest.iot.DeviceSupplier; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; -import io.enmasse.systemtest.iot.MqttAdapterClient; -import io.enmasse.systemtest.iot.StandardIoTTests; - -/** - * Standard MQTT IoT tests - *

- * Note: we do not test single telemetry with QoS 0 here, as we don't receive any - * feedback if the message was accepted or not. So we couldn't re-try and could only assume that a - * message loss of 100% would be acceptable, which doesn't test much. For bigger batch sizes we can - * test with an acceptable message loss rate of e.g. 10%. - */ -public interface StandardIoTMqttTests extends StandardIoTTests { - - final static Logger log = LoggerFactory.getLogger(StandardIoTMqttTests.class); - - /** - * Single telemetry message with attached consumer. QoS 1. - *
- * Sending with QoS 1 is ok. - */ - @Tag(ACCEPTANCE) - @ParameterizedTest(name = "testMqttTelemetrySingleQos1-{0}") - @MethodSource("getDevices") - default void testMqttTelemetrySingleQos1(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(1) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Single event message with non-attached consumer. - *
- * This is the normal use case. - */ - @ParameterizedTest(name = "testMqttEventSingle-{0}") - @MethodSource("getDevices") - default void testMqttEventSingle(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(1) - .consume(MessageSendTester.Consume.AFTER) - .execute(); - } - - } - - /** - * Batch of telemetry messages with attached consumer. QoS 0. - *
- * Batched version of the normal use case. We do accept message loss of 10% here. - */ - @ParameterizedTest(name = "testMqttTelemetryBatch50Qos0-{0}") - @MethodSource("getDevices") - default void testMqttTelemetryBatch50Qos0(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos0) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .acceptableMessageLoss(5) // allow for 10% - .execute(); - } - - } - - /** - * Batch of telemetry messages with attached consumer. QoS 1. - *
- * Compared to QoS 0, we do not accept message loss here. - */ - @ParameterizedTest(name = "testMqttTelemetryBatch50Qos1-{0}") - @MethodSource("getDevices") - default void testMqttTelemetryBatch50Qos1(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Batch of event messages with non-attached consumer. - *
- * This sends messages without an attached consumer. The broker is expected - * to take care of that. Still we expect to receive the messages later. - */ - @ParameterizedTest(name = "testMqttEventBatch5After-{0}") - @MethodSource("getDevices") - default void testMqttEventBatch5After(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofMillis(100)) - .additionalSendTimeout(Duration.ofSeconds(2)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(5) - .consume(MessageSendTester.Consume.AFTER) - .execute(); - } - - } - - /** - * Batch of event messages with attached consumer. - *
- * This is the normal use case. - */ - @ParameterizedTest(name = "testMqttEventBatch5Before-{0}") - @MethodSource("getDevices") - default void testMqttEventBatch5Before(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Test for an invalid device. - *
- * With an invalid device, no messages must pass. - */ - @ParameterizedTest(name = "testMqttInvalidDevice-{0}") - @MethodSource("getInvalidDevices") - default void testMqttInvalidDevice(final DeviceSupplier deviceSupplier) throws Exception { - - log.info("Testing invalid devices, the following exception may be expected"); - - // get the device now, once, throwing out of the test method - - var device = deviceSupplier.get(); - - /* - * We test an invalid device by trying to send either telemetry or event messages. - * Two separate connections, and more than one message. - * - * We do expect a failure, but it must be a specific failure. We do accept - * an MqttSecurityException when opening the connection, or a TimeoutException - * when we could open the connection, but not send/receive. - */ - - try (MqttAdapterClient client = device.createMqttAdapterClient()) { - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - } catch (Exception e) { - assertConnectionException(e); - log.debug("Accepting MQTT exception", e); - } - - try (MqttAdapterClient client = device.createMqttAdapterClient()) { - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - } catch (Exception e) { - assertConnectionException(e); - log.debug("Accepting MQTT exception", e); - } - - } - - public static void assertConnectionException(final Throwable e) { - - // if we get an exception, it must be an MqttSecurityException or SSLHandshakeException - - if (e instanceof MqttSecurityException) { - return; - } - - final Throwable cause = Throwables.getRootCause(e); - if (cause instanceof SSLHandshakeException) { - return; - } - - fail("Failed to connect with non-permitted exception", e); - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/shared/control/CommandAndControlTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/shared/control/CommandAndControlTest.java deleted file mode 100644 index 8a16e5bd431..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/shared/control/CommandAndControlTest.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.iot.shared.control; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.MessageType.COMMAND_RESPONSE; -import static io.enmasse.systemtest.iot.MessageType.TELEMETRY; -import static io.enmasse.systemtest.utils.Predicates.is; -import static java.net.HttpURLConnection.HTTP_ACCEPTED; -import static java.net.HttpURLConnection.HTTP_OK; -import static org.hamcrest.CoreMatchers.anyOf; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.collection.IsIterableContainingInOrder.contains; -import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.hamcrest.core.IsNull.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; - -import java.net.HttpURLConnection; -import java.nio.ByteBuffer; -import java.time.Duration; -import java.util.List; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.messaging.Accepted; -import org.apache.qpid.proton.amqp.messaging.Data; -import org.apache.qpid.proton.amqp.messaging.Released; -import org.apache.qpid.proton.message.Message; -import org.hamcrest.core.Is; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; - -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.amqp.QueueTerminusFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTShared; -import io.enmasse.systemtest.iot.CredentialsRegistryClient; -import io.enmasse.systemtest.iot.DeviceRegistryClient; -import io.enmasse.systemtest.iot.HttpAdapterClient; -import io.enmasse.systemtest.iot.MessageType; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.client.HttpResponse; -import io.vertx.proton.ProtonDelivery; - -class CommandAndControlTest extends TestBase implements ITestIoTShared { - - private static Logger log = CustomLogger.getLogger(); - - private Endpoint deviceRegistryEndpoint; - private Endpoint httpAdapterEndpoint; - private DeviceRegistryClient registryClient; - private CredentialsRegistryClient credentialsClient; - - private String deviceId; - - private String authId; - - private String password; - - private HttpAdapterClient httpClient; - private String commandPayload; - private int ttd; - - @BeforeEach - void init() throws Exception { - - this.deviceRegistryEndpoint = IoTUtils.getDeviceRegistryManagementEndpoint(); - this.httpAdapterEndpoint = kubernetes.getExternalEndpoint("iot-http-adapter"); - this.registryClient = new DeviceRegistryClient(this.deviceRegistryEndpoint); - this.credentialsClient = new CredentialsRegistryClient(this.deviceRegistryEndpoint); - - // setup device information - this.deviceId = UUID.randomUUID().toString(); - this.authId = UUID.randomUUID().toString(); - this.password = UUID.randomUUID().toString(); - log.info("Registering device [deviceId]: {}, [authId]: {}, [password]: {}", deviceId, authId, password); - this.httpClient = new HttpAdapterClient(this.httpAdapterEndpoint, this.authId, sharedIoTResourceManager.getTenantId(), this.password); - - // set up new random device - this.registryClient.registerDevice(sharedIoTResourceManager.getTenantId(), this.deviceId); - this.credentialsClient.addCredentials(sharedIoTResourceManager.getTenantId(), this.deviceId, this.authId, this.password, null, HttpURLConnection.HTTP_NO_CONTENT); - - // setup payload - this.commandPayload = UUID.randomUUID().toString(); - this.ttd = 30; - - } - - @AfterEach - void closeHttpClient() { - if (this.httpClient != null) { - this.httpClient.close(); - this.httpClient = null; - } - } - - @Test - void testOneShotCommand() throws Exception { - - final AtomicReference>> sentFuture = new AtomicReference<>(); - - var f1 = setupMessagingReceiver(sentFuture, null); - - IoTUtils.waitForFirstSuccess(httpClient, MessageType.TELEMETRY); - - var response = sendTelemetryWithTtd(); - - assertTelemetryResponse(response); - - assertCloudTelemetryMessage(f1); - assertCommandMessageDeliveries(sentFuture.get()); - - } - - @Test - @Tag(ACCEPTANCE) - void testRequestResponseCommand() throws Exception { - - final var reqId = UUID.randomUUID().toString(); - final var replyToAddress = "command_response/" + sharedIoTResourceManager.getTenantId() + "/" + UUID.randomUUID().toString(); - - final AtomicReference>> sentFuture = new AtomicReference<>(); - - // set up command response consumer (before responding to telemetry) - var f3 = sharedIoTResourceManager.getAmqpClient().recvMessages(replyToAddress, 1); - - var f1 = setupMessagingReceiver(sentFuture, commandMessage -> { - commandMessage.setCorrelationId(reqId); - commandMessage.setReplyTo(replyToAddress); - }); - - IoTUtils.waitForFirstSuccess(httpClient, MessageType.TELEMETRY); - - var response = sendTelemetryWithTtd(); - - assertTelemetryResponse(response); - - // also assert response id - - var responseId = response.getHeader("hono-cmd-req-id"); - assertThat(responseId, notNullValue()); - - // send the reply to the command - - TestUtils.runUntilPass(5, () -> { - this.httpClient.send(COMMAND_RESPONSE, "/" + responseId, - new JsonObject().put("data", "command-response").toBuffer(), - is(HTTP_ACCEPTED), - request -> request.putHeader("hono-cmd-status", "202" /* accepted */), Duration.ofSeconds(5)); - }); - - assertCloudTelemetryMessage(f1); - assertCommandMessageDeliveries(sentFuture.get()); - - // assert command response message - cloud side - - var responses = f3.get(10, TimeUnit.SECONDS); - assertThat(responses, hasSize(1)); - var responseMsg = responses.get(0); - assertThat(responseMsg.getCorrelationId(), Is.is(reqId)); - assertThat(responseMsg.getBody(), instanceOf(Data.class)); - assertThat(new JsonObject(Buffer.buffer(((Data) responseMsg.getBody()).getValue().getArray())), Is.is(new JsonObject().put("data", "command-response"))); - assertThat(responseMsg.getApplicationProperties().getValue().get("status"), Is.is(202) /* accepted */); - - } - - private HttpResponse sendTelemetryWithTtd() throws Exception { - - // consumer link should be ready now ... send telemetry with "ttd" - - log.info("Send telemetry with TTD - ttd: {}", this.ttd); - - var response = TestUtils.runUntilPass(5, () -> { - return this.httpClient.send(TELEMETRY, null, is(HTTP_OK /* OK for command responses */), request -> { - // set "time to disconnect" - request.putHeader("hono-ttd", Integer.toString(this.ttd)); - }, Duration.ofSeconds(this.ttd + 5)); - }); - - log.info("Telemetry response: {}: {}", response.statusCode(), response.bodyAsString()); - - return response; - - } - - private Future> setupMessagingReceiver(final AtomicReference>> sentFuture, final Consumer messageCustomizer) { - - // setup telemetry consumer - - var f1 = sharedIoTResourceManager.getAmqpClient().recvMessages(new QueueTerminusFactory().getSource("telemetry/" + sharedIoTResourceManager.getTenantId()), msg -> { - - log.info("Received message: {}", msg); - - var ttdValue = msg.getApplicationProperties().getValue().get("ttd"); - - if (ttdValue == null) { - // this was the initial message, without waiting for commands - return false; - } - - var deviceId = msg.getApplicationProperties().getValue().get("device_id").toString(); - - // prepare message - - var commandMessage = Message.Factory.create(); - commandMessage.setSubject("CMD1"); - commandMessage.setMessageId(UUID.randomUUID().toString()); - - commandMessage.setContentType("application/octet-stream"); - commandMessage.setBody(new Data(Binary.create(ByteBuffer.wrap(this.commandPayload.getBytes())))); - commandMessage.setAddress("command/" + sharedIoTResourceManager.getTenantId() + "/" + deviceId); - - if (messageCustomizer != null) { - messageCustomizer.accept(commandMessage); - } - - // send request command - - log.info("Sending out command message"); - var f2 = sharedIoTResourceManager.getAmqpClient().sendMessage("command/" + sharedIoTResourceManager.getTenantId(), commandMessage) - .whenComplete((res, err) -> { - String strres = null; - if (res != null) { - strres = res.stream().map(ProtonDelivery::getRemoteState).map(Object::toString).collect(Collectors.joining(", ")); - } - log.info("Message result - res: {}, err:", // no need for final {}, as this is an exception - strres, err); - }); - sentFuture.set(f2); - log.info("Message underway"); - - // stop listening for more messages - - return true; - - }, Optional.empty()).getResult(); - return f1; - - } - - private void assertTelemetryResponse(final HttpResponse response) { - - // assert message - device side - - final var actualCommand = response.bodyAsString(); - assertThat(response.getHeader("hono-command"), Is.is("CMD1")); - assertThat(actualCommand, Is.is(this.commandPayload)); - - } - - private void assertCloudTelemetryMessage(Future> f1) throws InterruptedException, ExecutionException, TimeoutException { - - // assert message - cloud side - - // wait for the future of the sent message - var m1 = f1.get(10, TimeUnit.SECONDS); - - // dump messages - m1.forEach(m -> log.info("Message: {}", m)); - - // we expect two messages, the "test" message and the actual one - assertThat(m1, hasSize(2)); - // get the second message, the real one - var msg = m1.get(1); - - // message must have "ttd" set - var ttdValue = msg.getApplicationProperties().getValue().get("ttd"); - assertThat(ttdValue, instanceOf(Number.class)); - assertThat(ttdValue, Is.is(30)); - - } - - private void assertCommandMessageDeliveries(Future> messageFuture) throws InterruptedException, ExecutionException, TimeoutException { - - assertThat(messageFuture, notNullValue()); - - // assert command message deliveries - cloud side - - final List deliveries = messageFuture.get(10, TimeUnit.SECONDS); - assertThat(deliveries, hasSize(1)); - assertThat(deliveries.stream().map(ProtonDelivery::getRemoteState).collect(Collectors.toList()), - contains( - anyOf( - instanceOf(Released.class), // remove once issue eclipse/hono#1149 is fixed - instanceOf(Accepted.class)))); - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/isolated/CommonTest.java b/systemtests/src/test/java/io/enmasse/systemtest/isolated/CommonTest.java deleted file mode 100644 index 30a07badaf9..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/isolated/CommonTest.java +++ /dev/null @@ -1,839 +0,0 @@ -/* - * Copyright 2018-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.isolated; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceBuilder; -import io.enmasse.admin.model.v1.AddressPlan; -import io.enmasse.admin.model.v1.AddressSpacePlan; -import io.enmasse.admin.model.v1.AddressSpacePlanBuilder; -import io.enmasse.admin.model.v1.BrokeredInfraConfig; -import io.enmasse.admin.model.v1.BrokeredInfraConfigBuilder; -import io.enmasse.admin.model.v1.BrokeredInfraConfigSpecAdminBuilder; -import io.enmasse.admin.model.v1.BrokeredInfraConfigSpecBrokerBuilder; -import io.enmasse.admin.model.v1.ResourceAllowance; -import io.enmasse.admin.model.v1.ResourceRequest; -import io.enmasse.admin.model.v1.StandardInfraConfig; -import io.enmasse.admin.model.v1.StandardInfraConfigBuilder; -import io.enmasse.admin.model.v1.StandardInfraConfigSpecAdminBuilder; -import io.enmasse.admin.model.v1.StandardInfraConfigSpecBrokerBuilder; -import io.enmasse.admin.model.v1.StandardInfraConfigSpecRouterBuilder; -import io.enmasse.config.LabelKeys; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.isolated.ITestBaseIsolated; -import io.enmasse.systemtest.executor.ExecutionResultData; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.shared.standard.QueueTest; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.PlanUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.api.model.Pod; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.amqp.messaging.Data; -import org.apache.qpid.proton.amqp.transport.DeliveryState.DeliveryStateType; -import org.apache.qpid.proton.message.Message; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.slf4j.Logger; - -import java.time.Duration; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Random; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static io.enmasse.systemtest.TestTag.ISOLATED; -import static io.enmasse.systemtest.TestTag.NON_PR; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -@Tag(ISOLATED) -class CommonTest extends TestBase implements ITestBaseIsolated { - private static Logger log = CustomLogger.getLogger(); - - @Test - void testAccessLogs() throws Exception { - AddressSpace standard = new AddressSpaceBuilder() - .withNewMetadata() - .withName("mystandard") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_UNLIMITED) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - resourcesManager.createAddressSpace(standard); - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(standard.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(standard, "test-queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue") - .withPlan(DestinationPlan.STANDARD_SMALL_QUEUE) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - kubernetes.awaitPodsReady(standard.getMetadata().getNamespace(), new TimeoutBudget(5, TimeUnit.MINUTES)); - - Multimap podsContainersWithNoLog = HashMultimap.create(); - - kubernetes.listPods().stream().filter(pod -> !pod.getMetadata().getName().contains("none-authservice")).forEach(pod -> kubernetes.getContainersFromPod(pod.getMetadata().getNamespace(), pod.getMetadata().getName()).forEach(container -> { - String podNamespace = pod.getMetadata().getNamespace(); - String podName = pod.getMetadata().getName(); - String containerName = container.getName(); - log.info("Getting log from pod: {}, for container: {}", podName, containerName); - String podlog = kubernetes.getLog(podNamespace, podName, containerName); - - // Retry - diagnostic code to help understand a sporadic Ci failure. - if (podlog.isEmpty()) { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - log.info("(Retry) Getting log from pod: {}, for container: {}", podName, containerName); - podlog = kubernetes.getLog(podNamespace, podName, containerName); - } - - if (podlog.isEmpty()) { - podsContainersWithNoLog.put(podName, containerName); - } - - })); - - if (!podsContainersWithNoLog.isEmpty()) { - String podContainerNames = podsContainersWithNoLog.entries().stream().map(e -> String.format("%s-%s", e.getKey(), e.getValue())).collect(Collectors.joining(",")); - fail(String.format("%d pod container(s) had unexpectedly empty logs : %s ", podsContainersWithNoLog.size(), podContainerNames)); - } - } - - @Test - void testRestartComponents() throws Exception { - List

brokeredAddresses = AddressUtils.getAllBrokeredAddresses(brokered); - List
standardAddresses = AddressUtils.getAllStandardAddresses(standard); - - resourcesManager.setAddresses(brokeredAddresses.toArray(new Address[0])); - resourcesManager.setAddresses(standardAddresses.toArray(new Address[0])); - - getClientUtils().assertCanConnect(brokered, user, brokeredAddresses, resourcesManager); - getClientUtils().assertCanConnect(standard, user, standardAddresses, resourcesManager); - - log.info("------------------------------------------------------------"); - log.info("------------------- Start with restarting -------------------"); - log.info("------------------------------------------------------------"); - - List pods = kubernetes.listPods(); - int runningPodsBefore = pods.size(); - log.info("Number of running pods before restarting any: {}", runningPodsBefore); - for (Label label : labels) { - log.info("Restarting {}", label.labelValue); - KubeCMDClient.deletePodByLabel(label.getLabelName(), label.getLabelValue()); - Thread.sleep(30_000); - TestUtils.waitForExpectedReadyPods(kubernetes, kubernetes.getInfraNamespace(), runningPodsBefore, new TimeoutBudget(10, TimeUnit.MINUTES)); - assertSystemWorks(brokered, standard, user, brokeredAddresses, standardAddresses); - } - - log.info("Restarting whole enmasse"); - KubeCMDClient.deletePodByLabel("app", kubernetes.getEnmasseAppLabel()); - Thread.sleep(180_000); - TestUtils.waitForExpectedReadyPods(kubernetes, kubernetes.getInfraNamespace(), runningPodsBefore, new TimeoutBudget(10, TimeUnit.MINUTES)); - AddressUtils.waitForDestinationsReady(new TimeoutBudget(10, TimeUnit.MINUTES), - standardAddresses.toArray(new Address[0])); - assertSystemWorks(brokered, standard, user, brokeredAddresses, standardAddresses); - - //TODO: Uncomment when #2127 will be fixed - -// Pod qdrouter = pods.stream().filter(pod -> pod.getMetadata().getName().contains("qdrouter")).collect(Collectors.toList()).get(0); -// kubernetes.deletePod(environment.namespace(), qdrouter.getMetadata().getName()); -// assertSystemWorks(brokered, standard, user, brokeredAddresses, standardAddresses); - } - //https://github.com/EnMasseProject/enmasse/issues/3098 - - @Test - void testRestartAdminComponent() throws Exception { - List