From b9ac27107fc2b48140b1f7b599b798f92524785b Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Wed, 5 Jun 2024 13:44:51 +0200 Subject: [PATCH] fix: rest-client for native, update filter (#6) --- ...onecx-data-orchestrator-operator-docs.adoc | 2 +- .../orchestrator/operator/DataController.java | 9 +++- .../operator/client/DataClientApi.java | 2 + .../operator/client/KeyFactory.java | 8 +++ src/main/resources/application.properties | 2 +- .../operator/DataControllerTest.java | 51 ++++++++++++++++++- 6 files changed, 69 insertions(+), 5 deletions(-) diff --git a/docs/modules/onecx-data-orchestrator-operator/pages/onecx-data-orchestrator-operator-docs.adoc b/docs/modules/onecx-data-orchestrator-operator/pages/onecx-data-orchestrator-operator-docs.adoc index c8498fe..c42cca1 100644 --- a/docs/modules/onecx-data-orchestrator-operator/pages/onecx-data-orchestrator-operator-docs.adoc +++ b/docs/modules/onecx-data-orchestrator-operator/pages/onecx-data-orchestrator-operator-docs.adoc @@ -10,7 +10,7 @@ include::onecx-data-orchestrator-operator-attributes.adoc[opts=optional] ---- onecx.data-orchestrator.client.key.workspace=http://onecx-workspace-svc:8080/data/v1 onecx.data-orchestrator.client.key.theme=http://onecx-theme-svc:8080/data/v1 -onecx.data-orchestrator.client.key.tenant=http://onecx-tenant-svc:8080/data/v1 +onecx.data-orchestrator.client.key.tenant=http://onecx-tenant-svc:8080/exim/v1/tenants/operator onecx.data-orchestrator.client.key.permission=http://onecx-permission-svc:8080/data/v1 quarkus.operator-sdk.controllers.microservice.namespaces=JOSDK_WATCH_CURRENT quarkus.operator-sdk.helm.enabled=true diff --git a/src/main/java/org/tkit/onecx/data/orchestrator/operator/DataController.java b/src/main/java/org/tkit/onecx/data/orchestrator/operator/DataController.java index f6523f4..fc31a0f 100644 --- a/src/main/java/org/tkit/onecx/data/orchestrator/operator/DataController.java +++ b/src/main/java/org/tkit/onecx/data/orchestrator/operator/DataController.java @@ -114,8 +114,13 @@ public boolean accept(Data newResource, Data oldResource) { if (newResource.getSpec().getData() == null || newResource.getSpec().getData().isEmpty()) { return false; } - return oldResource.getStatus().getChecksum() - .equals(createCheckSum(newResource.getSpec().getData())); + if (oldResource.getStatus() == null) { + return true; + } + if (oldResource.getStatus().getChecksum() == null) { + return true; + } + return !oldResource.getStatus().getChecksum().equals(createCheckSum(newResource.getSpec().getData())); } } diff --git a/src/main/java/org/tkit/onecx/data/orchestrator/operator/client/DataClientApi.java b/src/main/java/org/tkit/onecx/data/orchestrator/operator/client/DataClientApi.java index d24125b..b3f1da2 100644 --- a/src/main/java/org/tkit/onecx/data/orchestrator/operator/client/DataClientApi.java +++ b/src/main/java/org/tkit/onecx/data/orchestrator/operator/client/DataClientApi.java @@ -1,5 +1,6 @@ package org.tkit.onecx.data.orchestrator.operator.client; +import jakarta.ws.rs.Consumes; import jakarta.ws.rs.POST; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; @@ -12,5 +13,6 @@ public interface DataClientApi { @POST @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) Response updateDate(Object data); } diff --git a/src/main/java/org/tkit/onecx/data/orchestrator/operator/client/KeyFactory.java b/src/main/java/org/tkit/onecx/data/orchestrator/operator/client/KeyFactory.java index 3be0af2..a5274fe 100644 --- a/src/main/java/org/tkit/onecx/data/orchestrator/operator/client/KeyFactory.java +++ b/src/main/java/org/tkit/onecx/data/orchestrator/operator/client/KeyFactory.java @@ -3,8 +3,16 @@ import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; +import org.tkit.quarkus.log.rs.RestClientLogInterceptor; +import org.tkit.quarkus.log.rs.RestClientPayloadInterceptor; + +import io.quarkus.runtime.annotations.RegisterForReflection; import io.smallrye.jwt.util.KeyUtils; +@RegisterForReflection(targets = { + RestClientLogInterceptor.class, + RestClientPayloadInterceptor.class, +}) class KeyFactory { static final PrivateKey PRIVATE_KEY = createKey(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 047d5f1..49bcfb7 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ onecx.data-orchestrator.client.key.workspace=http://onecx-workspace-svc:8080/data/v1 onecx.data-orchestrator.client.key.theme=http://onecx-theme-svc:8080/data/v1 -onecx.data-orchestrator.client.key.tenant=http://onecx-tenant-svc:8080/data/v1 +onecx.data-orchestrator.client.key.tenant=http://onecx-tenant-svc:8080/exim/v1/tenants/operator onecx.data-orchestrator.client.key.permission=http://onecx-permission-svc:8080/data/v1 # OIDC diff --git a/src/test/java/org/tkit/onecx/data/orchestrator/operator/DataControllerTest.java b/src/test/java/org/tkit/onecx/data/orchestrator/operator/DataControllerTest.java index 9106960..dbf7a0f 100644 --- a/src/test/java/org/tkit/onecx/data/orchestrator/operator/DataControllerTest.java +++ b/src/test/java/org/tkit/onecx/data/orchestrator/operator/DataControllerTest.java @@ -68,9 +68,13 @@ private static Stream provideTestData() { } private static DataSpec createSpec(String key, String data) { + return createSpec(key, data, "description"); + } + + private static DataSpec createSpec(String key, String data, String description) { DataSpec spec = new DataSpec(); spec.setKey(key); - spec.setDescription("description"); + spec.setDescription(description); spec.setData(data); spec.setOrgId("default"); return spec; @@ -183,14 +187,59 @@ void dataUpdateEmptySpecTest() { }); } + @Test + void dataUpdateErrorSpecTest() { + + operator.start(); + + var spec = new DataSpec(); + spec.setData("workspace"); + spec.setKey("does-not-exists"); + + Data data = new Data(); + data.setMetadata( + new ObjectMetaBuilder().withName("does-not-exists-key-spec").withNamespace(client.getNamespace()).build()); + data.setSpec(spec); + + client.resource(data).serverSideApply(); + + await().pollDelay(2, SECONDS).untilAsserted(() -> { + DataStatus mfeStatus = client.resource(data).get().getStatus(); + assertThat(mfeStatus).isNotNull(); + assertThat(mfeStatus.getStatus()).isNotNull().isEqualTo(DataStatus.Status.ERROR); + assertThat(mfeStatus.getMessage()).isNotNull().isEqualTo("Missing configuration for key does-not-exists"); + }); + + var m = new DataSpec(); + m.setAppId("test-1"); + m.setProductName("product-test"); + m.setKey("workspace"); + m.setData("{}"); + + client.resource(data).inNamespace(client.getNamespace()) + .edit(s -> { + s.setSpec(m); + return s; + }); + + await().pollDelay(4, SECONDS).untilAsserted(() -> { + DataStatus mfeStatus = client.resource(data).get().getStatus(); + assertThat(mfeStatus).isNotNull(); + assertThat(mfeStatus.getStatus()).isNotNull().isEqualTo(DataStatus.Status.CREATED); + }); + } + private static Stream provideUpdateData() { return Stream.of( Arguments.of("test-update-1", createSpec("workspace", "{\"items\":[]}"), createSpec(null, "{\"items\":[]}")), Arguments.of("test-update-2", createSpec("workspace", "{\"items\":[]}"), createSpec("", "{\"items\":[]}")), Arguments.of("test-update-21", createSpec("workspace", "{\"items\":[]}"), createSpec("workspace", "{\"items\": [ {} ]}")), + Arguments.of("test-update-3-1", createSpec("workspace", "{\"items\":[]}", "test1"), + createSpec("workspace", "{\"items\":[]}", "test-2")), Arguments.of("test-update-3", createSpec("workspace", "{\"items\":[]}"), createSpec("workspace", null)), Arguments.of("test-update-4", createSpec("workspace", "{\"items\":[]}"), createSpec("workspace", ""))); + } @ParameterizedTest