Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi committed Aug 22, 2024
1 parent 58dd009 commit ed225ad
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public class TransformFunction
public void initialize(Context context) {
Map<String, Object> userConfigMap = context.getUserConfigMap();
JsonNode jsonNode =
ObjectMapperFactory.getYamlMapper().convertValue(userConfigMap, JsonNode.class);
ObjectMapperFactory.getDefaultYamlMapper()
.convertValue(userConfigMap, JsonNode.class);

URNFactory urnFactory =
urn -> {
Expand All @@ -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();
Expand Down Expand Up @@ -218,7 +219,7 @@ public void initialize(Context context) {
}

transformConfig =
ObjectMapperFactory.getYamlMapper()
ObjectMapperFactory.getDefaultYamlMapper()
.convertValue(userConfigMap, TransformStepConfig.class);

serviceProvider = buildServiceProvider(transformConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

class JwtAuthenticationProviderConfigurationTest {

protected static final ObjectMapper yamlConfigReader = ObjectMapperFactory.getYamlMapper();
protected static final ObjectMapper yamlConfigReader =
ObjectMapperFactory.getDefaultYamlMapper();

@Test
void parseCamelCase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class ApiGatewayMetricsProvider {

@Bean(destroyMethod = "close")
public ApiGatewayMetrics apiGatewayMetrics() {
System.out.println("CALL ApiGatewayMetricsProvider");
return new ApiGatewayMetrics(Metrics.globalRegistry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -640,14 +640,22 @@ private void assertMessagesContent(List<MsgRecord> expected, List<String> 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;
}
})
Expand Down
7 changes: 2 additions & 5 deletions langstream-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,14 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<scope>provided</scope>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> applicationParameters) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,15 +130,11 @@ public Map<String, AgentCustomResource> 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;
Expand Down Expand Up @@ -301,15 +295,11 @@ public Map<String, ApplicationCustomResource> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ 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;
}

@SneakyThrows
public void serializeAndSetOptions(Options options) {
this.options = ObjectMapperFactory.getYamlMapper().writeValueAsString(options);
this.options = ObjectMapperFactory.getDefaultYamlMapper().writeValueAsString(options);
}

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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);
Expand All @@ -70,11 +43,6 @@ public static <T> T readJson(String string, Class<T> objectClass) {
return mapper.readValue(string, objectClass);
}

@SneakyThrows
public static <T> T convertValue(Object from, Class<T> objectClass) {
return mapper.convertValue(from, objectClass);
}

@SneakyThrows
public static byte[] writeAsJsonBytes(Object object) {
return mapper.writeValueAsBytes(object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Loading

0 comments on commit ed225ad

Please sign in to comment.