Skip to content

Commit

Permalink
fix: rest-client for native, update filter (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras authored Jun 5, 2024
1 parent fd89db6 commit b9ac271
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,5 +13,6 @@ public interface DataClientApi {

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
Response updateDate(Object data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ private static Stream<Arguments> 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;
Expand Down Expand Up @@ -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<Arguments> 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
Expand Down

0 comments on commit b9ac271

Please sign in to comment.