-
Notifications
You must be signed in to change notification settings - Fork 59
Support yaml partially #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
37bb1f3
NO-ISSUE Support yaml partially
Yang-33 3ec1618
NO-ISSUE fix test
Yang-33 92530e9
Merge branch 'master' into support-yaml-partially
Yang-33 0c1da8a
NO-ISSUE Fix which keys are used to update dynamic properties
Yang-33 e56aa28
NO-ISSUE Move internal classes into internal package
Yang-33 f7661b0
NO-ISSUE Fix docs
Yang-33 925f8f0
NO-ISSUE Fix version in doc
Yang-33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...a/src/main/java/com/linecorp/decaton/centraldogma/internal/DecatonPropertyFileFormat.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright 2025 LINE Corporation | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 … | ||
| */ | ||
|
|
||
| package com.linecorp.decaton.centraldogma.internal; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Locale; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.linecorp.centraldogma.client.CentralDogmaRepository; | ||
| import com.linecorp.centraldogma.client.Watcher; | ||
| import com.linecorp.centraldogma.common.Change; | ||
| import com.linecorp.decaton.centraldogma.CentralDogmaPropertySupplier; | ||
|
|
||
| /** | ||
| * Encapsulates Central Dogma–specific concerns for reading and writing | ||
| * configuration files in various text formats (JSON, YAML, ...). | ||
| * <p> | ||
| * Implementations convert between raw file contents managed by Central Dogma | ||
| * and {@link JsonNode} values consumed by {@link CentralDogmaPropertySupplier}. | ||
| */ | ||
| public interface DecatonPropertyFileFormat { | ||
| /** | ||
| * Create and start a Watcher that emits {@link JsonNode} for each file update. | ||
| */ | ||
| Watcher<JsonNode> createWatcher(CentralDogmaRepository repo, String fileName); | ||
|
|
||
| /** | ||
| * Serialize the given node and wrap it as Central Dogma {@link Change} for initial file creation. | ||
| */ | ||
| Change<?> createUpsertChange(String fileName, JsonNode initialNode) throws IOException; | ||
|
|
||
| static DecatonPropertyFileFormat of(String fileName) { | ||
| String lower = fileName.toLowerCase(Locale.ROOT); | ||
| return (lower.endsWith(".yml") || lower.endsWith(".yaml")) | ||
| ? new YamlFormat() | ||
| : new JsonFormat(); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
centraldogma/src/main/java/com/linecorp/decaton/centraldogma/internal/JsonFormat.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * Copyright 2025 LINE Corporation | ||
| */ | ||
|
|
||
| package com.linecorp.decaton.centraldogma.internal; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.linecorp.centraldogma.client.CentralDogmaRepository; | ||
| import com.linecorp.centraldogma.client.Watcher; | ||
| import com.linecorp.centraldogma.common.Change; | ||
| import com.linecorp.centraldogma.common.Query; | ||
|
|
||
| public class JsonFormat implements DecatonPropertyFileFormat { | ||
| @Override | ||
| public Watcher<JsonNode> createWatcher(CentralDogmaRepository repo, String fileName) { | ||
| return repo.watcher(Query.ofJsonPath(fileName)).start(); | ||
| } | ||
|
|
||
| @Override | ||
| public Change<?> createUpsertChange(String fileName, JsonNode initialNode) { | ||
| return Change.ofJsonUpsert(fileName, initialNode); | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
centraldogma/src/main/java/com/linecorp/decaton/centraldogma/internal/YamlFormat.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright 2025 LINE Corporation | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 … | ||
| */ | ||
|
|
||
| package com.linecorp.decaton.centraldogma.internal; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
| import com.linecorp.centraldogma.client.CentralDogmaRepository; | ||
| import com.linecorp.centraldogma.client.Watcher; | ||
| import com.linecorp.centraldogma.common.Change; | ||
| import com.linecorp.centraldogma.common.Query; | ||
|
|
||
| import static com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.WRITE_DOC_START_MARKER; | ||
|
|
||
| public class YamlFormat implements DecatonPropertyFileFormat { | ||
| private static final ObjectMapper YAML_MAPPER = new ObjectMapper( | ||
| new YAMLFactory() | ||
| .disable(WRITE_DOC_START_MARKER) | ||
| ); | ||
|
|
||
| @Override | ||
| public Watcher<JsonNode> createWatcher(CentralDogmaRepository repo, String fileName) { | ||
| return repo.watcher(Query.ofText(fileName)) | ||
| .map(text -> { | ||
| try { | ||
| return YAML_MAPPER.readTree(text); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException("Failed to parse YAML from " + fileName, e); | ||
| } | ||
| }) | ||
| .start(); | ||
| } | ||
|
|
||
| @Override | ||
| public Change<?> createUpsertChange(String fileName, JsonNode initialNode) throws IOException { | ||
| String yaml = YAML_MAPPER.writeValueAsString(initialNode); | ||
| return Change.ofTextUpsert(fileName, yaml); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class doesn't need to be exposed to users, so let's move to
internalpackage (refs: https://github.com/line/decaton/blob/master/VERSIONING.md#public-apis)JsonFormat, YamlFormat as well