Skip to content

Commit

Permalink
Bump JSON Schema version and lower cache size. (#789)
Browse files Browse the repository at this point in the history
* Bump JSON Schema version and lower cache size.

Summary:
This will lower the memory usage by ignoring the JSON schema cache.
Since we are not using any URIs to load the JSON schema it is cached
each time a new.

JIRA issues: D2IQ-68617

* fixup! disable cache completely.

* Update cosmos-common/src/main/scala/com/mesosphere/cosmos/render/PackageDefinitionRenderer.scala

* fixup! remove trailing whitespace.

Co-authored-by: Kaiwalya Joshi <[email protected]>
  • Loading branch information
jeschkies and kaiwalyajoshi authored Aug 22, 2020
1 parent dfd3e71 commit e49fb1b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object JsonSchema {
val Right(documentNode) = document.as[JsonNode]
val Right(schemaNode) = schema.as[JsonNode]

val validationErrors = jsf.getValidator.validate(schemaNode, documentNode)
val validationErrors = jsf.getJsonSchema(schemaNode).validate(documentNode)
if (validationErrors.isSuccess) {
Right[ValidationErrors, Unit](())
} else {
Expand Down Expand Up @@ -147,7 +147,7 @@ object JsonSchema {
},
jsonObject = { obj =>
val objectNode = JsonNodeFactory.instance.objectNode()
objectNode.setAll(obj.toMap.mapValues(circeJsonToJsonNode).asJava)
objectNode.setAll[JsonNode](obj.toMap.mapValues(circeJsonToJsonNode).asJava)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import java.io.StringWriter
import java.io.Writer
import java.nio.charset.StandardCharsets
import java.util.Base64

import com.github.fge.jsonschema.cfg.ValidationConfiguration

import collection.JavaConverters._

object PackageDefinitionRenderer {
Expand All @@ -38,7 +41,13 @@ object PackageDefinitionRenderer {
}
}

private[this] implicit val jsf: JsonSchemaFactory = JsonSchemaFactory.byDefault()
private[this] implicit val jsf: JsonSchemaFactory = {
// Disable cache because it uses the URI as a key. Since we are not using the URI the key is different on each
// call and thus has not performance advantage.
val validationConfiguration = ValidationConfiguration.newBuilder().setCacheSize(0).freeze()
JsonSchemaFactory.newBuilder()
.setValidationConfiguration(validationConfiguration).freeze()
}

def renderMarathonV2App(
sourceUri: Uri,
Expand Down
7 changes: 5 additions & 2 deletions project/Deps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ object Deps {

// APLv2.0 / LGPLv3.0
val jsonSchema = Seq(
"com.github.fge" % "json-schema-validator" % V.jsonSchema
"com.github.java-json-tools" % "json-schema-validator" % V.jsonSchema,
// Override Jackson dependency
"com.fasterxml.jackson.module" %% "jackson-module-scala" % V.jackson
)

// EPLv1.0 / LGPLv2.1
Expand Down Expand Up @@ -146,7 +148,8 @@ object V {
val fastparse = "1.0.0"
val finch = "0.18.0"
val guava = "28.0-jre"
val jsonSchema = "2.2.6"
val jackson = "2.11.0"
val jsonSchema = "2.2.14"
val logback = "1.2.3"
val mockito = "2.16.0"
val mustache = "0.9.6"
Expand Down

0 comments on commit e49fb1b

Please sign in to comment.