-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert radar-commons-server to Kotlin
- Loading branch information
1 parent
a79e5a1
commit b14bc4a
Showing
21 changed files
with
809 additions
and
968 deletions.
There are no files selected for viewing
This file contains 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
81 changes: 0 additions & 81 deletions
81
radar-commons-server/src/main/java/org/radarbase/config/AvroTopicConfig.java
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
radar-commons-server/src/main/java/org/radarbase/config/AvroTopicConfig.kt
This file contains 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,60 @@ | ||
/* | ||
* Copyright 2017 The Hyve and King's College London | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.radarbase.config | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import org.apache.avro.specific.SpecificRecord | ||
import org.radarbase.topic.AvroTopic | ||
import org.radarbase.topic.AvroTopic.Companion.parse | ||
|
||
/** | ||
* Specifies an Avro topic. | ||
*/ | ||
open class AvroTopicConfig { | ||
@JvmField | ||
var topic: String? = null | ||
|
||
@JvmField | ||
@JsonProperty("key_schema") | ||
var keySchema: String? = null | ||
|
||
@JvmField | ||
@JsonProperty("value_schema") | ||
var valueSchema: String? = null | ||
var tags: List<String>? = null | ||
|
||
/** | ||
* Parse an AvroTopic from the values in this class. | ||
* | ||
* @throws IllegalStateException if the key_schema or value_schema properties are not valid | ||
* Avro SpecificRecord classes | ||
*/ | ||
open fun <K : SpecificRecord, V : SpecificRecord> parseAvroTopic(): AvroTopic<K, V> { | ||
|
||
return try { | ||
parse( | ||
checkNotNull(topic) { "Topic is not specified" }, | ||
checkNotNull(keySchema) { "Key schema is not specified" }, | ||
checkNotNull(valueSchema) { "Value schema is not specified" }, | ||
) | ||
} catch (ex: IllegalArgumentException) { | ||
throw IllegalStateException( | ||
"Topic $topic schema cannot be instantiated", | ||
ex, | ||
) | ||
} | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
radar-commons-server/src/main/java/org/radarbase/config/ServerConfigMixin.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
radar-commons-server/src/main/java/org/radarbase/config/ServerConfigMixin.kt
This file contains 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,16 @@ | ||
package org.radarbase.config | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.annotation.JsonSetter | ||
|
||
/** Mixin class to load ServerConfig files with. */ | ||
abstract class ServerConfigMixin { | ||
@get:JsonProperty("proxy_host") | ||
abstract val proxyHost: String? | ||
|
||
@get:JsonProperty("proxy_port") | ||
abstract val proxyPort: String? | ||
|
||
@JsonSetter("path") | ||
abstract fun setPath(path: String?) | ||
} |
97 changes: 0 additions & 97 deletions
97
radar-commons-server/src/main/java/org/radarbase/config/YamlConfigLoader.java
This file was deleted.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
radar-commons-server/src/main/java/org/radarbase/config/YamlConfigLoader.kt
This file contains 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,93 @@ | ||
/* | ||
* Copyright 2017 The Hyve and King's College London | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.radarbase.config | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect | ||
import com.fasterxml.jackson.core.JsonFactory | ||
import com.fasterxml.jackson.core.JsonProcessingException | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies | ||
import com.fasterxml.jackson.databind.SerializationFeature | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory | ||
import java.io.IOException | ||
import java.nio.file.Path | ||
import kotlin.io.path.bufferedReader | ||
import kotlin.io.path.bufferedWriter | ||
|
||
/** | ||
* A YAML Config file loader, to load YAML files into equivalent POJO Objects. | ||
*/ | ||
class YamlConfigLoader @JvmOverloads constructor(mapperConfigurator: (ObjectMapper) -> Unit = {}) { | ||
private val yamlMapper = ObjectMapper(YAML_FACTORY).apply { | ||
setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE) | ||
setVisibility( | ||
serializationConfig.getDefaultVisibilityChecker() | ||
.withFieldVisibility(JsonAutoDetect.Visibility.ANY) | ||
.withGetterVisibility(JsonAutoDetect.Visibility.NONE) | ||
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE) | ||
.withSetterVisibility(JsonAutoDetect.Visibility.NONE) | ||
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE) | ||
) | ||
|
||
addMixIn(ServerConfig::class.java, ServerConfigMixin::class.java) | ||
} | ||
|
||
/** Config loader that does some additional object mapper configuration after initialization. */ | ||
init { | ||
mapperConfigurator(yamlMapper) | ||
} | ||
|
||
/** | ||
* Load a YAML file into given class. | ||
* @param file file to load. | ||
* @param configClass class for the config. | ||
* @param <T> type of the config. | ||
* @return loaded file. | ||
* @throws IOException if the file cannot be opened or parsed. | ||
</T> */ | ||
@Throws(IOException::class) | ||
fun <T> load(file: Path, configClass: Class<T>): T = file.bufferedReader() | ||
.use { reader -> | ||
yamlMapper.readValue(reader, configClass) | ||
} | ||
|
||
/** Store config into given YAML file. */ | ||
@Throws(IOException::class) | ||
fun store(file: Path, config: Any) { | ||
file.bufferedWriter().use { writer -> | ||
yamlMapper.writeValue(writer, config) | ||
} | ||
} | ||
|
||
/** | ||
* Pretty-print the given object as a YAML string. | ||
*/ | ||
fun prettyString(config: Any): String = yamlMapper.copy().run { | ||
// pretty print | ||
enable(SerializationFeature.INDENT_OUTPUT) | ||
// make ConfigRadar the root element | ||
enable(SerializationFeature.WRAP_ROOT_VALUE) | ||
return try { | ||
writeValueAsString(config) | ||
} catch (ex: JsonProcessingException) { | ||
throw UnsupportedOperationException("Cannot serialize config", ex) | ||
} | ||
} | ||
|
||
companion object { | ||
val YAML_FACTORY: JsonFactory = YAMLFactory() | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
radar-commons-server/src/main/java/org/radarbase/stream/collector/.gitignore
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.