From ed225ade789b98e9b71b8a55fa786d40f35fb6ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Thu, 22 Aug 2024 13:56:25 +0200 Subject: [PATCH] spotless --- .../ai/embeddings/EmbeddingsService.java | 10 +- .../transforms/TransformFunction.java | 7 +- ...thenticationProviderConfigurationTest.java | 3 +- .../apigateway/gateways/ProduceGateway.java | 6 +- .../metrics/ApiGatewayMetricsProvider.java | 1 - .../apigateway/http/GatewayResourceTest.java | 4 +- .../http/ServiceAgentGatewayResourceTest.java | 2 +- .../handlers/ProduceConsumeHandlerTest.java | 14 +- langstream-api/pom.xml | 7 +- .../api/util/ObjectMapperFactory.java | 12 +- .../langstream/impl/parser/ModelBuilder.java | 2 +- .../tests/util/BaseEndToEndTest.java | 2 +- .../impl/k8s/tests/KubeTestServer.java | 26 +-- .../k8s/api/crds/agents/AgentSpec.java | 5 +- .../deployer/k8s/util/SerializationUtil.java | 38 +---- .../k8s/ResolvedDeployerConfiguration.java | 18 +-- .../k8s/controllers/apps/AppController.java | 5 +- .../impl/k8s/KubernetesClusterRuntime.java | 6 +- .../runtime/agent/AgentRunnerStarter.java | 2 +- .../runtime/tester/KubeTestServer.java | 26 +-- .../tester/LocalApplicationRunner.java | 2 +- .../webservice/archetype/ArchetypeStore.java | 2 +- .../src/main/resources/application.properties | 1 + .../archetype/ArchetypeResourceTest.java | 150 ++++++------------ 24 files changed, 118 insertions(+), 233 deletions(-) diff --git a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/embeddings/EmbeddingsService.java b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/embeddings/EmbeddingsService.java index 0ac9c4cc3..48b7bd667 100644 --- a/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/embeddings/EmbeddingsService.java +++ b/langstream-agents/langstream-ai-agents/src/main/java/com/datastax/oss/streaming/ai/embeddings/EmbeddingsService.java @@ -15,7 +15,7 @@ */ package com.datastax.oss.streaming.ai.embeddings; -import com.fasterxml.jackson.annotation.JsonInclude; +import ai.langstream.api.util.ObjectMapperFactory; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; @@ -24,11 +24,9 @@ public interface EmbeddingsService extends AutoCloseable { static ObjectMapper createObjectMapper() { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true); - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - return mapper; + return ObjectMapperFactory.getDefaultMapper() + .copy() + .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true); } default void close() throws Exception {} diff --git a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunction.java b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunction.java index c86e2f7dd..600d1f3a6 100644 --- a/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunction.java +++ b/langstream-agents/langstream-ai-agents/src/test/java/com/datastax/oss/pulsar/functions/transforms/TransformFunction.java @@ -142,7 +142,8 @@ public class TransformFunction public void initialize(Context context) { Map userConfigMap = context.getUserConfigMap(); JsonNode jsonNode = - ObjectMapperFactory.getYamlMapper().convertValue(userConfigMap, JsonNode.class); + ObjectMapperFactory.getDefaultYamlMapper() + .convertValue(userConfigMap, JsonNode.class); URNFactory urnFactory = urn -> { @@ -156,7 +157,7 @@ public void initialize(Context context) { }; JsonSchemaFactory factory = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4)) - .objectMapper(ObjectMapperFactory.getYamlMapper().copy()) + .objectMapper(ObjectMapperFactory.getDefaultYamlMapper().copy()) .addUrnFactory(urnFactory) .build(); SchemaValidatorsConfig jsonSchemaConfig = new SchemaValidatorsConfig(); @@ -218,7 +219,7 @@ public void initialize(Context context) { } transformConfig = - ObjectMapperFactory.getYamlMapper() + ObjectMapperFactory.getDefaultYamlMapper() .convertValue(userConfigMap, TransformStepConfig.class); serviceProvider = buildServiceProvider(transformConfig); diff --git a/langstream-api-gateway-auth/langstream-jwt-api-gateway-auth/src/test/java/ai/langstream/apigateway/auth/impl/jwt/admin/JwtAuthenticationProviderConfigurationTest.java b/langstream-api-gateway-auth/langstream-jwt-api-gateway-auth/src/test/java/ai/langstream/apigateway/auth/impl/jwt/admin/JwtAuthenticationProviderConfigurationTest.java index 5ff0f4dba..69e067fc9 100644 --- a/langstream-api-gateway-auth/langstream-jwt-api-gateway-auth/src/test/java/ai/langstream/apigateway/auth/impl/jwt/admin/JwtAuthenticationProviderConfigurationTest.java +++ b/langstream-api-gateway-auth/langstream-jwt-api-gateway-auth/src/test/java/ai/langstream/apigateway/auth/impl/jwt/admin/JwtAuthenticationProviderConfigurationTest.java @@ -26,7 +26,8 @@ class JwtAuthenticationProviderConfigurationTest { - protected static final ObjectMapper yamlConfigReader = ObjectMapperFactory.getYamlMapper(); + protected static final ObjectMapper yamlConfigReader = + ObjectMapperFactory.getDefaultYamlMapper(); @Test void parseCamelCase() { diff --git a/langstream-api-gateway/src/main/java/ai/langstream/apigateway/gateways/ProduceGateway.java b/langstream-api-gateway/src/main/java/ai/langstream/apigateway/gateways/ProduceGateway.java index e3f51a317..4cc0e1673 100644 --- a/langstream-api-gateway/src/main/java/ai/langstream/apigateway/gateways/ProduceGateway.java +++ b/langstream-api-gateway/src/main/java/ai/langstream/apigateway/gateways/ProduceGateway.java @@ -35,7 +35,6 @@ import ai.langstream.apigateway.websocket.AuthenticatedGatewayRequestContext; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -46,10 +45,7 @@ @Slf4j public class ProduceGateway implements AutoCloseable { - protected static final ObjectMapper mapper = - ObjectMapperFactory.getDefaultMapper() - .copy() - .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); + protected static final ObjectMapper mapper = ObjectMapperFactory.getDefaultMapper(); @Getter public static class ProduceException extends Exception { diff --git a/langstream-api-gateway/src/main/java/ai/langstream/apigateway/metrics/ApiGatewayMetricsProvider.java b/langstream-api-gateway/src/main/java/ai/langstream/apigateway/metrics/ApiGatewayMetricsProvider.java index 9aead723b..d1ce4dabf 100644 --- a/langstream-api-gateway/src/main/java/ai/langstream/apigateway/metrics/ApiGatewayMetricsProvider.java +++ b/langstream-api-gateway/src/main/java/ai/langstream/apigateway/metrics/ApiGatewayMetricsProvider.java @@ -24,7 +24,6 @@ public class ApiGatewayMetricsProvider { @Bean(destroyMethod = "close") public ApiGatewayMetrics apiGatewayMetrics() { - System.out.println("CALL ApiGatewayMetricsProvider"); return new ApiGatewayMetrics(Metrics.globalRegistry); } } diff --git a/langstream-api-gateway/src/test/java/ai/langstream/apigateway/http/GatewayResourceTest.java b/langstream-api-gateway/src/test/java/ai/langstream/apigateway/http/GatewayResourceTest.java index 4fb8f2a45..e90731034 100644 --- a/langstream-api-gateway/src/test/java/ai/langstream/apigateway/http/GatewayResourceTest.java +++ b/langstream-api-gateway/src/test/java/ai/langstream/apigateway/http/GatewayResourceTest.java @@ -172,7 +172,7 @@ private static Application buildApp(String instanceYaml) throws Exception { ModelBuilder.buildApplicationInstance( Map.of( "module.yaml", - ObjectMapperFactory.getYamlMapper() + ObjectMapperFactory.getDefaultYamlMapper() .writeValueAsString(module)), instanceYaml, null) @@ -1022,8 +1022,6 @@ private void assertMessageContent(MsgRecord expected, String actual) { final MsgRecord actualMsgRecord = new MsgRecord(consume.record().key(), consume.record().value(), headers); - System.out.println("type: " + actualMsgRecord.value().getClass()); - assertEquals(expected.value(), actualMsgRecord.value()); assertEquals(expected, actualMsgRecord); } diff --git a/langstream-api-gateway/src/test/java/ai/langstream/apigateway/http/ServiceAgentGatewayResourceTest.java b/langstream-api-gateway/src/test/java/ai/langstream/apigateway/http/ServiceAgentGatewayResourceTest.java index 6394c3ca6..73205ae89 100644 --- a/langstream-api-gateway/src/test/java/ai/langstream/apigateway/http/ServiceAgentGatewayResourceTest.java +++ b/langstream-api-gateway/src/test/java/ai/langstream/apigateway/http/ServiceAgentGatewayResourceTest.java @@ -134,7 +134,7 @@ private static Application buildApp(String instanceYaml) throws Exception { ModelBuilder.buildApplicationInstance( Map.of( "module.yaml", - ObjectMapperFactory.getYamlMapper() + ObjectMapperFactory.getDefaultYamlMapper() .writeValueAsString(module)), instanceYaml, null) diff --git a/langstream-api-gateway/src/test/java/ai/langstream/apigateway/websocket/handlers/ProduceConsumeHandlerTest.java b/langstream-api-gateway/src/test/java/ai/langstream/apigateway/websocket/handlers/ProduceConsumeHandlerTest.java index cb75c5d0b..fbc9fbbc9 100644 --- a/langstream-api-gateway/src/test/java/ai/langstream/apigateway/websocket/handlers/ProduceConsumeHandlerTest.java +++ b/langstream-api-gateway/src/test/java/ai/langstream/apigateway/websocket/handlers/ProduceConsumeHandlerTest.java @@ -168,7 +168,7 @@ private static Application buildApp(String instanceYaml) throws Exception { ModelBuilder.buildApplicationInstance( Map.of( "module.yaml", - ObjectMapperFactory.getYamlMapper() + ObjectMapperFactory.getDefaultYamlMapper() .writeValueAsString(module)), instanceYaml, null) @@ -640,14 +640,22 @@ private void assertMessagesContent(List expected, List actual actual.stream() .map( string -> { + Map asMap; try { + asMap = MAPPER.readValue(string, Map.class); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + if (asMap.containsKey("record")) { ConsumePushMessage consume = - MAPPER.readValue(string, ConsumePushMessage.class); + MAPPER.convertValue( + asMap, ConsumePushMessage.class); return new MsgRecord( consume.record().key(), consume.record().value(), consume.record().headers()); - } catch (JsonProcessingException e) { + } else { + log.info("Skipping message: {}", string); return null; } }) diff --git a/langstream-api/pom.xml b/langstream-api/pom.xml index 2a16b38b8..71b3cca04 100644 --- a/langstream-api/pom.xml +++ b/langstream-api/pom.xml @@ -52,17 +52,14 @@ com.fasterxml.jackson.core jackson-databind - provided com.fasterxml.jackson.core jackson-core - provided - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - provided + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml diff --git a/langstream-api/src/main/java/ai/langstream/api/util/ObjectMapperFactory.java b/langstream-api/src/main/java/ai/langstream/api/util/ObjectMapperFactory.java index f2beb65aa..e682029d3 100644 --- a/langstream-api/src/main/java/ai/langstream/api/util/ObjectMapperFactory.java +++ b/langstream-api/src/main/java/ai/langstream/api/util/ObjectMapperFactory.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -16,7 +17,12 @@ public class ObjectMapperFactory { MAPPER.copy().configure(SerializationFeature.INDENT_OUTPUT, true); private static final ObjectMapper YAML_MAPPER = - configureObjectMapper(new ObjectMapper(new YAMLFactory())); + configureObjectMapper( + new ObjectMapper( + YAMLFactory.builder() + .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES) + .disable(YAMLGenerator.Feature.SPLIT_LINES) + .build())); public static ObjectMapper getDefaultMapper() { return MAPPER; @@ -26,16 +32,16 @@ public static ObjectMapper getPrettyPrintMapper() { return PRETTY_PRINT_MAPPER; } - public static ObjectMapper getYamlMapper() { + public static ObjectMapper getDefaultYamlMapper() { return YAML_MAPPER; } private static ObjectMapper configureObjectMapper(ObjectMapper mapper) { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.configure(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION, true); + mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); return mapper; } } diff --git a/langstream-core/src/main/java/ai/langstream/impl/parser/ModelBuilder.java b/langstream-core/src/main/java/ai/langstream/impl/parser/ModelBuilder.java index 6d2cb5d9d..625d6decd 100644 --- a/langstream-core/src/main/java/ai/langstream/impl/parser/ModelBuilder.java +++ b/langstream-core/src/main/java/ai/langstream/impl/parser/ModelBuilder.java @@ -59,7 +59,7 @@ @Slf4j public class ModelBuilder { - static final ObjectMapper yamlParser = ObjectMapperFactory.getYamlMapper(); + static final ObjectMapper yamlParser = ObjectMapperFactory.getDefaultYamlMapper(); public static ApplicationWithPackageInfo buildApplicationInstanceFromArchetype( Path archetypePath, Map applicationParameters) throws Exception { diff --git a/langstream-e2e-tests/src/test/java/ai/langstream/tests/util/BaseEndToEndTest.java b/langstream-e2e-tests/src/test/java/ai/langstream/tests/util/BaseEndToEndTest.java index 5fb5764eb..d678bf852 100644 --- a/langstream-e2e-tests/src/test/java/ai/langstream/tests/util/BaseEndToEndTest.java +++ b/langstream-e2e-tests/src/test/java/ai/langstream/tests/util/BaseEndToEndTest.java @@ -131,7 +131,7 @@ public class BaseEndToEndTest implements TestWatcher { public static final File TEST_LOGS_DIR = new File("target", "e2e-test-logs"); protected static final String TENANT_NAMESPACE_PREFIX = "ls-tenant-"; protected static final ObjectMapper JSON_MAPPER = ObjectMapperFactory.getDefaultMapper(); - protected static final ObjectMapper YAML_MAPPER = ObjectMapperFactory.getYamlMapper(); + protected static final ObjectMapper YAML_MAPPER = ObjectMapperFactory.getDefaultYamlMapper(); protected static KubeCluster kubeCluster; protected static StreamingClusterProvider streamingClusterProvider; protected static StreamingCluster streamingCluster; diff --git a/langstream-k8s-common/src/test/java/ai/langstream/impl/k8s/tests/KubeTestServer.java b/langstream-k8s-common/src/test/java/ai/langstream/impl/k8s/tests/KubeTestServer.java index 5bcfd98a5..8c731b357 100644 --- a/langstream-k8s-common/src/test/java/ai/langstream/impl/k8s/tests/KubeTestServer.java +++ b/langstream-k8s-common/src/test/java/ai/langstream/impl/k8s/tests/KubeTestServer.java @@ -21,8 +21,6 @@ import ai.langstream.deployer.k8s.api.crds.agents.AgentCustomResource; import ai.langstream.deployer.k8s.api.crds.apps.ApplicationCustomResource; import ai.langstream.impl.k8s.KubernetesClientFactory; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; import io.fabric8.kubernetes.api.model.NamespaceBuilder; import io.fabric8.kubernetes.api.model.Secret; import io.fabric8.kubernetes.client.NamespacedKubernetesClient; @@ -132,15 +130,11 @@ public Map spyAgentCustomResources( final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); recordedRequest.getBody().copyTo(byteArrayOutputStream); - final ObjectMapper mapper = - new ObjectMapper() - .enable( - SerializationFeature - .ORDER_MAP_ENTRIES_BY_KEYS); final AgentCustomResource agent = - mapper.readValue( - byteArrayOutputStream.toByteArray(), - AgentCustomResource.class); + ObjectMapperFactory.getDefaultMapper() + .readValue( + byteArrayOutputStream.toByteArray(), + AgentCustomResource.class); log.info("received patch request for agent {}", agentId); currentAgents.put(agentId, agent); return agent; @@ -301,15 +295,11 @@ public Map spyApplicationCustomResources( final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); recordedRequest.getBody().copyTo(byteArrayOutputStream); - final ObjectMapper mapper = - new ObjectMapper() - .enable( - SerializationFeature - .ORDER_MAP_ENTRIES_BY_KEYS); final ApplicationCustomResource app = - mapper.readValue( - byteArrayOutputStream.toByteArray(), - ApplicationCustomResource.class); + ObjectMapperFactory.getDefaultMapper() + .readValue( + byteArrayOutputStream.toByteArray(), + ApplicationCustomResource.class); log.info("received patch request for app {}", appId); currentApplications.put(appId, app); return app; diff --git a/langstream-k8s-deployer/langstream-k8s-deployer-api/src/main/java/ai/langstream/deployer/k8s/api/crds/agents/AgentSpec.java b/langstream-k8s-deployer/langstream-k8s-deployer-api/src/main/java/ai/langstream/deployer/k8s/api/crds/agents/AgentSpec.java index 49db6b3f5..729f2f94b 100644 --- a/langstream-k8s-deployer/langstream-k8s-deployer-api/src/main/java/ai/langstream/deployer/k8s/api/crds/agents/AgentSpec.java +++ b/langstream-k8s-deployer/langstream-k8s-deployer-api/src/main/java/ai/langstream/deployer/k8s/api/crds/agents/AgentSpec.java @@ -59,7 +59,8 @@ private synchronized Options parseOptions() { if (parsedOptions == null) { if (options != null) { parsedOptions = - ObjectMapperFactory.getYamlMapper().readValue(options, Options.class); + ObjectMapperFactory.getDefaultYamlMapper() + .readValue(options, Options.class); } } return parsedOptions; @@ -67,7 +68,7 @@ private synchronized Options parseOptions() { @SneakyThrows public void serializeAndSetOptions(Options options) { - this.options = ObjectMapperFactory.getYamlMapper().writeValueAsString(options); + this.options = ObjectMapperFactory.getDefaultYamlMapper().writeValueAsString(options); } @JsonIgnore diff --git a/langstream-k8s-deployer/langstream-k8s-deployer-core/src/main/java/ai/langstream/deployer/k8s/util/SerializationUtil.java b/langstream-k8s-deployer/langstream-k8s-deployer-core/src/main/java/ai/langstream/deployer/k8s/util/SerializationUtil.java index 061d29917..f980d02b2 100644 --- a/langstream-k8s-deployer/langstream-k8s-deployer-core/src/main/java/ai/langstream/deployer/k8s/util/SerializationUtil.java +++ b/langstream-k8s-deployer/langstream-k8s-deployer-core/src/main/java/ai/langstream/deployer/k8s/util/SerializationUtil.java @@ -16,45 +16,18 @@ package ai.langstream.deployer.k8s.util; import ai.langstream.api.util.ObjectMapperFactory; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; import lombok.SneakyThrows; public class SerializationUtil { - private static final ObjectMapper mapper = - ObjectMapperFactory.getDefaultMapper() - .copy() - .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); + private static final ObjectMapper mapper = ObjectMapperFactory.getDefaultMapper(); - private static final ObjectMapper jsonPrettyPrint = - ObjectMapperFactory.getPrettyPrintMapper() - .copy() - .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); - private static final ObjectMapper yamlMapper = - new ObjectMapper( - YAMLFactory.builder() - .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES) - .disable(YAMLGenerator.Feature.SPLIT_LINES) - .build()) - .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true) - .configure(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION, true) - .setSerializationInclusion(JsonInclude.Include.NON_NULL); + private static final ObjectMapper jsonPrettyPrint = ObjectMapperFactory.getPrettyPrintMapper(); + private static final ObjectMapper yamlMapper = ObjectMapperFactory.getDefaultYamlMapper(); private SerializationUtil() {} - @SneakyThrows - public static T deepCloneObject(T object) { - if (object == null) { - return null; - } - return (T) mapper.readValue(mapper.writeValueAsString(object), object.getClass()); - } - @SneakyThrows public static String writeAsJson(Object object) { return mapper.writeValueAsString(object); @@ -70,11 +43,6 @@ public static T readJson(String string, Class objectClass) { return mapper.readValue(string, objectClass); } - @SneakyThrows - public static T convertValue(Object from, Class objectClass) { - return mapper.convertValue(from, objectClass); - } - @SneakyThrows public static byte[] writeAsJsonBytes(Object object) { return mapper.writeValueAsBytes(object); diff --git a/langstream-k8s-deployer/langstream-k8s-deployer-operator/src/main/java/ai/langstream/deployer/k8s/ResolvedDeployerConfiguration.java b/langstream-k8s-deployer/langstream-k8s-deployer-operator/src/main/java/ai/langstream/deployer/k8s/ResolvedDeployerConfiguration.java index 03d252200..fd2bfe2ea 100644 --- a/langstream-k8s-deployer/langstream-k8s-deployer-operator/src/main/java/ai/langstream/deployer/k8s/ResolvedDeployerConfiguration.java +++ b/langstream-k8s-deployer/langstream-k8s-deployer-operator/src/main/java/ai/langstream/deployer/k8s/ResolvedDeployerConfiguration.java @@ -15,15 +15,10 @@ */ package ai.langstream.deployer.k8s; +import ai.langstream.api.util.ObjectMapperFactory; import ai.langstream.deployer.k8s.agents.AgentResourceUnitConfiguration; import ai.langstream.deployer.k8s.util.SerializationUtil; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; import jakarta.inject.Singleton; import java.util.Map; import lombok.Getter; @@ -34,16 +29,7 @@ @JBossLog public class ResolvedDeployerConfiguration { - private static final ObjectMapper yamlMapper = - new ObjectMapper( - YAMLFactory.builder() - .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES) - .disable(YAMLGenerator.Feature.SPLIT_LINES) - .build()) - .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true) - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .configure(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION, true) - .setSerializationInclusion(JsonInclude.Include.NON_NULL); + private static final ObjectMapper yamlMapper = ObjectMapperFactory.getDefaultYamlMapper(); @SneakyThrows public ResolvedDeployerConfiguration(DeployerConfiguration configuration) { diff --git a/langstream-k8s-deployer/langstream-k8s-deployer-operator/src/main/java/ai/langstream/deployer/k8s/controllers/apps/AppController.java b/langstream-k8s-deployer/langstream-k8s-deployer-operator/src/main/java/ai/langstream/deployer/k8s/controllers/apps/AppController.java index 5de2858d7..fe8524604 100644 --- a/langstream-k8s-deployer/langstream-k8s-deployer-operator/src/main/java/ai/langstream/deployer/k8s/controllers/apps/AppController.java +++ b/langstream-k8s-deployer/langstream-k8s-deployer-operator/src/main/java/ai/langstream/deployer/k8s/controllers/apps/AppController.java @@ -29,7 +29,6 @@ import ai.langstream.deployer.k8s.util.SerializationUtil; import ai.langstream.deployer.k8s.util.SpecDiffer; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; import io.fabric8.kubernetes.api.model.ConfigMap; import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.batch.v1.Job; @@ -56,9 +55,7 @@ public class AppController extends BaseController implements ErrorStatusHandler { private static final ObjectMapper lastAppliedJsonMapper = - ObjectMapperFactory.getDefaultMapper() - .copy() - .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); + ObjectMapperFactory.getDefaultMapper(); protected static final Duration DEFAULT_RESCHEDULE_DURATION = Duration.ofSeconds(5); diff --git a/langstream-k8s-runtime/langstream-k8s-runtime-core/src/main/java/ai/langstream/runtime/impl/k8s/KubernetesClusterRuntime.java b/langstream-k8s-runtime/langstream-k8s-runtime-core/src/main/java/ai/langstream/runtime/impl/k8s/KubernetesClusterRuntime.java index 473dd7bee..8ea4fc8ed 100644 --- a/langstream-k8s-runtime/langstream-k8s-runtime-core/src/main/java/ai/langstream/runtime/impl/k8s/KubernetesClusterRuntime.java +++ b/langstream-k8s-runtime/langstream-k8s-runtime-core/src/main/java/ai/langstream/runtime/impl/k8s/KubernetesClusterRuntime.java @@ -33,7 +33,6 @@ import ai.langstream.impl.k8s.KubernetesClientFactory; import ai.langstream.runtime.api.agent.RuntimePodConfiguration; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; import io.fabric8.kubernetes.api.model.Secret; import io.fabric8.kubernetes.client.KubernetesClient; import java.security.MessageDigest; @@ -44,10 +43,7 @@ @Slf4j public class KubernetesClusterRuntime extends BasicClusterRuntime { - static final ObjectMapper mapper = - ObjectMapperFactory.getDefaultMapper() - .copy() - .enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS); + static final ObjectMapper mapper = ObjectMapperFactory.getDefaultMapper(); public static final String CLUSTER_TYPE = "kubernetes"; static final List OPTIMISERS = diff --git a/langstream-runtime/langstream-runtime-impl/src/main/java/ai/langstream/runtime/agent/AgentRunnerStarter.java b/langstream-runtime/langstream-runtime-impl/src/main/java/ai/langstream/runtime/agent/AgentRunnerStarter.java index d715e8709..ff504f8b2 100644 --- a/langstream-runtime/langstream-runtime-impl/src/main/java/ai/langstream/runtime/agent/AgentRunnerStarter.java +++ b/langstream-runtime/langstream-runtime-impl/src/main/java/ai/langstream/runtime/agent/AgentRunnerStarter.java @@ -107,7 +107,7 @@ public void start(String... args) throws Exception { } RuntimePodConfiguration configuration = - ObjectMapperFactory.getYamlMapper() + ObjectMapperFactory.getDefaultYamlMapper() .readValue(podRuntimeConfiguration.toFile(), RuntimePodConfiguration.class); AtomicBoolean continueLoop = new AtomicBoolean(true); diff --git a/langstream-runtime/langstream-runtime-tester/src/main/java/ai/langstream/runtime/tester/KubeTestServer.java b/langstream-runtime/langstream-runtime-tester/src/main/java/ai/langstream/runtime/tester/KubeTestServer.java index 174e15ed9..d41d649ac 100644 --- a/langstream-runtime/langstream-runtime-tester/src/main/java/ai/langstream/runtime/tester/KubeTestServer.java +++ b/langstream-runtime/langstream-runtime-tester/src/main/java/ai/langstream/runtime/tester/KubeTestServer.java @@ -21,8 +21,6 @@ import ai.langstream.deployer.k8s.api.crds.agents.AgentCustomResource; import ai.langstream.deployer.k8s.api.crds.apps.ApplicationCustomResource; import ai.langstream.impl.k8s.KubernetesClientFactory; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; import io.fabric8.kubernetes.api.model.NamespaceBuilder; import io.fabric8.kubernetes.api.model.Secret; import io.fabric8.kubernetes.client.NamespacedKubernetesClient; @@ -114,15 +112,11 @@ public Map spyAgentCustomResources( final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); recordedRequest.getBody().copyTo(byteArrayOutputStream); - final ObjectMapper mapper = - new ObjectMapper() - .enable( - SerializationFeature - .ORDER_MAP_ENTRIES_BY_KEYS); final AgentCustomResource agent = - mapper.readValue( - byteArrayOutputStream.toByteArray(), - AgentCustomResource.class); + ObjectMapperFactory.getDefaultMapper() + .readValue( + byteArrayOutputStream.toByteArray(), + AgentCustomResource.class); log.debug("received patch request for agent {}", agentId); currentAgents.put(agentId, agent); return agent; @@ -275,15 +269,11 @@ public Map spyApplicationCustomResources( final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); recordedRequest.getBody().copyTo(byteArrayOutputStream); - final ObjectMapper mapper = - new ObjectMapper() - .enable( - SerializationFeature - .ORDER_MAP_ENTRIES_BY_KEYS); final ApplicationCustomResource app = - mapper.readValue( - byteArrayOutputStream.toByteArray(), - ApplicationCustomResource.class); + ObjectMapperFactory.getDefaultMapper() + .readValue( + byteArrayOutputStream.toByteArray(), + ApplicationCustomResource.class); log.debug("received patch request for app {}", appId); currentApplications.put(appId, app); return app; diff --git a/langstream-runtime/langstream-runtime-tester/src/main/java/ai/langstream/runtime/tester/LocalApplicationRunner.java b/langstream-runtime/langstream-runtime-tester/src/main/java/ai/langstream/runtime/tester/LocalApplicationRunner.java index c9fa9ca50..ab29b80a3 100644 --- a/langstream-runtime/langstream-runtime-tester/src/main/java/ai/langstream/runtime/tester/LocalApplicationRunner.java +++ b/langstream-runtime/langstream-runtime-tester/src/main/java/ai/langstream/runtime/tester/LocalApplicationRunner.java @@ -56,7 +56,7 @@ public class LocalApplicationRunner implements AutoCloseable, InMemoryApplicationStore.AgentInfoCollector { - private static final ObjectMapper MAPPER = ObjectMapperFactory.getYamlMapper(); + private static final ObjectMapper MAPPER = ObjectMapperFactory.getDefaultYamlMapper(); final KubeTestServer kubeServer = new KubeTestServer(); final InMemoryApplicationStore applicationStore = new InMemoryApplicationStore(); diff --git a/langstream-webservice/src/main/java/ai/langstream/webservice/archetype/ArchetypeStore.java b/langstream-webservice/src/main/java/ai/langstream/webservice/archetype/ArchetypeStore.java index 80c696123..cdb6b0d63 100644 --- a/langstream-webservice/src/main/java/ai/langstream/webservice/archetype/ArchetypeStore.java +++ b/langstream-webservice/src/main/java/ai/langstream/webservice/archetype/ArchetypeStore.java @@ -31,7 +31,7 @@ @Slf4j public class ArchetypeStore { - private static final ObjectMapper mapper = ObjectMapperFactory.getYamlMapper(); + private static final ObjectMapper mapper = ObjectMapperFactory.getDefaultYamlMapper(); private final Map archetypeDefinitions = new HashMap<>(); private final Map archetypePaths = new HashMap<>(); diff --git a/langstream-webservice/src/main/resources/application.properties b/langstream-webservice/src/main/resources/application.properties index 72b37f0df..0b6ef5ed1 100644 --- a/langstream-webservice/src/main/resources/application.properties +++ b/langstream-webservice/src/main/resources/application.properties @@ -28,6 +28,7 @@ application.security.token.kubernetes-namespace-prefix=langstream- spring.jackson.serialization.indent-output=true spring.jackson.serialization.order-map-entries-by-keys=true +spring.jackson.default-property-inclusion=non_null application.storage.global.type=local application.storage.apps.type=kubernetes diff --git a/langstream-webservice/src/test/java/ai/langstream/webservice/archetype/ArchetypeResourceTest.java b/langstream-webservice/src/test/java/ai/langstream/webservice/archetype/ArchetypeResourceTest.java index bd4285312..339d09032 100644 --- a/langstream-webservice/src/test/java/ai/langstream/webservice/archetype/ArchetypeResourceTest.java +++ b/langstream-webservice/src/test/java/ai/langstream/webservice/archetype/ArchetypeResourceTest.java @@ -83,105 +83,57 @@ void testArchetypesMetadata() throws Exception { log.info("Result {}", result.getResponse().getContentAsString()); assertEquals( """ - { - "archetype" : { - "id" : "simple", - "title" : "Simple", - "labels" : null, - "description" : null, - "icon" : null, - "sections" : [ { - "title" : "Section 1", - "description" : "Xxxxx", - "parameters" : [ { - "default" : null, - "name" : "s1", - "label" : null, - "description" : null, - "type" : null, - "subtype" : null, - "binding" : "globals.string-value", - "required" : false - }, { - "default" : null, - "name" : "i1", - "label" : null, - "description" : null, - "type" : null, - "subtype" : null, - "binding" : "globals.input-value", - "required" : false - }, { - "default" : null, - "name" : "r1", - "label" : null, - "description" : null, - "type" : null, - "subtype" : null, - "binding" : "globals.int-value", - "required" : false - }, { - "default" : null, - "name" : "m1", - "label" : null, - "description" : null, - "type" : null, - "subtype" : null, - "binding" : "globals.map-value", - "required" : false - }, { - "default" : null, - "name" : "l1", - "label" : null, - "description" : null, - "type" : null, - "subtype" : null, - "binding" : "globals.list-value", - "required" : false - }, { - "default" : null, - "name" : "m2", - "label" : null, - "description" : null, - "type" : null, - "subtype" : null, - "binding" : "globals.nested-map.key2.key2-1", - "required" : false - } ] - }, { - "title" : "Section 2", - "description" : "Xxxxx", - "parameters" : [ { - "default" : null, - "name" : "s2", - "label" : null, - "description" : null, - "type" : null, - "subtype" : null, - "binding" : "secrets.open-ai.foo", - "required" : false - }, { - "default" : null, - "name" : "i2", - "label" : null, - "description" : null, - "type" : null, - "subtype" : null, - "binding" : "secrets.open-ai.foo-int", - "required" : false - }, { - "default" : null, - "name" : "k2", - "label" : null, - "description" : null, - "type" : null, - "subtype" : null, - "binding" : "secrets.kafka.bootstrap-servers", - "required" : false - } ] - } ] - } - }""", + { + "archetype" : { + "id" : "simple", + "title" : "Simple", + "sections" : [ { + "title" : "Section 1", + "description" : "Xxxxx", + "parameters" : [ { + "name" : "s1", + "binding" : "globals.string-value", + "required" : false + }, { + "name" : "i1", + "binding" : "globals.input-value", + "required" : false + }, { + "name" : "r1", + "binding" : "globals.int-value", + "required" : false + }, { + "name" : "m1", + "binding" : "globals.map-value", + "required" : false + }, { + "name" : "l1", + "binding" : "globals.list-value", + "required" : false + }, { + "name" : "m2", + "binding" : "globals.nested-map.key2.key2-1", + "required" : false + } ] + }, { + "title" : "Section 2", + "description" : "Xxxxx", + "parameters" : [ { + "name" : "s2", + "binding" : "secrets.open-ai.foo", + "required" : false + }, { + "name" : "i2", + "binding" : "secrets.open-ai.foo-int", + "required" : false + }, { + "name" : "k2", + "binding" : "secrets.kafka.bootstrap-servers", + "required" : false + } ] + } ] + } + }""", result.getResponse().getContentAsString()); }); }