Skip to content

Commit

Permalink
#432 Continue the parsing of the catalog if a invalid definition is f…
Browse files Browse the repository at this point in the history
…ound
  • Loading branch information
To-om committed Oct 5, 2022
1 parent e925976 commit d12bee9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion app/org/thp/cortex/models/WorkerDefinition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,23 @@ object WorkerDefinition {

def reads(workerType: WorkerType.Type): Reads[List[WorkerDefinition]] = {
val reads = singleReads(workerType)
reads.map(List(_)) orElse Reads.list(reads)
implicitly[Reads[JsArray]]
reads.map(List(_)) orElse JsArrayReads.map(array =>
array
.value
.toList
.flatMap { js =>
reads
.reads(js)
.fold(
invalid => {
logger.warn(s"The catalog contains an invalid entry\n entry:$js\n $invalid")
Seq.empty
},
Seq(_)
)
}
)
}

implicit val writes: Writes[WorkerDefinition] = Writes[WorkerDefinition] { workerDefinition =>
Expand Down
2 changes: 1 addition & 1 deletion app/org/thp/cortex/services/WorkerSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class WorkerSrv @Inject() (
.set("command", workerDefinition.command.map(p => JsString(p.toString)))
.set("url", workerDefinition.url)
.set("license", workerDefinition.license)
.set("baseConfig", workerDefinition.baseConfiguration.map(JsString.apply))
.set("baseConfig", workerDefinition.baseConfiguration.fold(JsString(workerDefinition.name))(JsString.apply))
.set("configuration", cfg.toString)
.set("type", workerDefinition.tpe.toString)
.addIfAbsent("dataTypeList", StringInputValue(workerDefinition.dataTypeList))
Expand Down

0 comments on commit d12bee9

Please sign in to comment.