Skip to content
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

Harmonizes SchemaConfig to a named block structure #89

Merged
merged 9 commits into from
Aug 13, 2024
40 changes: 16 additions & 24 deletions config-schema.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
{
"schemas": [
{
"name": "vitrivr",
"schemas": {
"vitrivr": {
"connection": {
"database": "CottontailConnectionProvider",
"parameters": {
"host": "127.0.0.1",
"port": "1865"
}
},
"fields": [
{
"name": "averagecolor",
"fields": {
"averagecolor": {
"factory": "AverageColor"
},
{
"name": "file",
"file": {
"factory": "FileSourceMetadata"
},
{
"name": "time",
"time": {
"factory": "TemporalMetadata"
},
{
"name": "video",
"video": {
"factory": "VideoSourceMetadata"
}
],
},
"resolvers": {
"disk": {
"factory": "DiskResolver",
Expand All @@ -35,18 +30,16 @@
}
}
},
"exporters": [
{
"name": "thumbnail",
"exporters": {
"thumbnail": {
"factory": "ThumbnailExporter",
"resolverName": "disk",
"parameters": {
"maxSideResolution": "400",
"mimeType": "JPG"
}
},
{
"name": "preview",
"preview": {
"factory": "VideoPreviewExporter",
"resolverName": "disk",
"parameters": {
Expand All @@ -55,13 +48,12 @@
"previewTimeSec": "5"
}
}
],
"extractionPipelines": [
{
"name": "ingestion",
},
"extractionPipelines": {
"ingestion": {
"path": "./config-ingestion.json"
}
]
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import org.vitrivr.engine.core.resolver.Resolver
*/
@Serializable
data class ExporterConfig(
/**
* The name of the [Exporter].
*/
val name: String,
/**
* The simple or fully qualified class name of the [ExporterFactory]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ import org.vitrivr.engine.core.model.metamodel.Schema
* @version 1.0.0
*/
@Serializable
data class FieldConfig(val name: String, val factory: String, val parameters: Map<String,String> = emptyMap(), val indexes: List<IndexConfig> = emptyList())
data class FieldConfig(val factory: String, val parameters: Map<String,String> = emptyMap(), val indexes: List<IndexConfig> = emptyList())
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import kotlinx.serialization.Serializable

@Serializable
data class PipelineConfig(
val name: String,
val path: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import java.nio.file.Paths
@Serializable
data class SchemaConfig(
/** Name of the [Schema]. */
val name: String = "vitrivr",
var name: String = "vitrivr",
lucaro marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is probably still a nicer way to handle this that does not require this field to be publicly writable, but that can be looked at at a later date and should not prevent us from merging this in a timely fashion.


/** The (database) [ConnectionConfig] for this [SchemaConfig]. */
val connection: ConnectionConfig,

/**
* List of [FieldConfig]s that are part of this [SchemaConfig].
*/
val fields: List<FieldConfig>,
val fields: Map<String, FieldConfig>,

/**
* The list of [ResolverConfig]s that are part of this [SchemaConfig].
Expand All @@ -40,12 +40,12 @@ data class SchemaConfig(
* List of [ExporterConfig]s that are part of this [SchemaConfig].
* @see Exporter
*/
val exporters: List<ExporterConfig> = emptyList(),
val exporters: Map<String, ExporterConfig> = emptyMap(),

/**
* List of [PipelineConfig]s that are part of this [SchemaConfig].
*/
val extractionPipelines: List<PipelineConfig> = emptyList()
val extractionPipelines: Map<String, PipelineConfig> = emptyMap()
) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,38 +49,49 @@ class SchemaManager {
/* Create new connection using reflection. */
val connection = connectionProvider.openConnection(config.name, config.connection.parameters)
val schema = Schema(config.name, connection)
config.fields.map {
val analyser = loadServiceForName<Analyser<*,*>>(it.factory) ?: throw IllegalArgumentException("Failed to find a factory implementation for '${it.factory}'.")
if(it.name.contains(".")){
config.fields.forEach { (fieldName, fieldConfig) ->
val analyser = loadServiceForName<Analyser<*,*>>(fieldConfig.factory) ?: throw IllegalArgumentException("Failed to find a factory implementation for '${fieldConfig.factory}'.")
if(fieldName.contains(".")){
throw IllegalArgumentException("Field names must not have a dot (.) in their name.")
}
@Suppress("UNCHECKED_CAST")
schema.addField(it.name, analyser as Analyser<ContentElement<*>, Descriptor>, it.parameters, it.indexes)
schema.addField(fieldName, analyser as Analyser<ContentElement<*>, Descriptor>, fieldConfig.parameters, fieldConfig.indexes)
}
config.resolvers.map {
schema.addResolver(it.key, (loadServiceForName<ResolverFactory>(it.value.factory) ?: throw IllegalArgumentException("Failed to find resolver factory implementation for '${it.value.factory}'.")).newResolver(schema, it.value.parameters))
config.resolvers.forEach { (resolverName, resolverConfig) ->
schema.addResolver(resolverName, (loadServiceForName<ResolverFactory>(resolverConfig.factory) ?: throw IllegalArgumentException("Failed to find resolver factory implementation for '${resolverConfig.factory}'.")).newResolver(schema, resolverConfig.parameters))
}
config.exporters.map {
config.exporters.forEach { (exporterName, exporterConfig) ->
schema.addExporter(
it.name,
loadServiceForName<ExporterFactory>(it.factory) ?: throw IllegalArgumentException("Failed to find exporter factory implementation for '${it.factory}'."),
it.parameters,
it.resolverName
exporterName,
loadServiceForName<ExporterFactory>(exporterConfig.factory) ?: throw IllegalArgumentException("Failed to find exporter factory implementation for '${exporterConfig.factory}'."),
exporterConfig.parameters,
exporterConfig.resolverName
)
}
config.extractionPipelines.map {
val ingestionConfig = IngestionConfig.read(Paths.get(it.path))
?: throw IllegalArgumentException("Failed to read pipeline configuration from '${it.path}'.")
config.extractionPipelines.forEach { (extractionPipelineName, extractionPipelineConfig) ->
val ingestionConfig = IngestionConfig.read(Paths.get(extractionPipelineConfig.path))
?: throw IllegalArgumentException("Failed to read pipeline configuration from '${extractionPipelineConfig.path}'.")
if (ingestionConfig.schema != schema.name) {
throw IllegalArgumentException("Schema name in pipeline configuration '${ingestionConfig.schema}' does not match schema name '${schema.name}'.")
}
schema.addIngestionPipeline(it.name, ingestionConfig)
schema.addIngestionPipeline(extractionPipelineName, ingestionConfig)
}

/* Cache and return connection. */
this.schemas[schema.name] = schema
}

/**
* Sets the name for a [SchemaConfig], then calls load.
*
* @param name The name of the schema.
* @param config The [SchemaConfig] to which to assign the name and load.
*/
fun load(name: String, config: SchemaConfig) {
config.name = name
load(config)
}

/**
* Lists all [Schema] managed by this [SchemaManager].
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fun main(args: Array<String>) {

/* Setup schema manager. */
val manager = SchemaManager()
for (schema in config.schemas) {
manager.load(schema)
for ((name, schemaConfig) in config.schemas) {
manager.load(name, schemaConfig)
}

/* Execution server singleton for this instance. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data class ServerConfig(
val api: ApiConfig = ApiConfig(),

/** List of [SchemaConfig] managed by this [ServerConfig]. */
val schemas: List<SchemaConfig>
val schemas: Map<String, SchemaConfig>
) {
companion object {
/** Default path to fall back to. */
Expand Down