Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Allow for multiple observers with the same schema (close #86)
Browse files Browse the repository at this point in the history
  • Loading branch information
polymorfiq authored and rzats committed Jul 24, 2017
1 parent 80be214 commit a0b14c7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/scala/com.snowplowanalytics.sauna/SaunaOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import observers._

/**
* Options parsed from command line
*
*
* @param configurationLocation root to directory with all configuration files
*/
case class SaunaOptions(configurationLocation: File) {
Expand All @@ -57,7 +57,7 @@ case class SaunaOptions(configurationLocation: File) {
/**
* Lazy enabledConfigs for all configurations parsed from `configurations` directory,
* which was valid self-describing Avro
* Key - class name, value - map of ids to content of `data` field
* Key - class name, value - map of ids to content of `data` field
* anything except observers is single-element/no-element list
*/
private lazy val configMap: Map[String, List[Array[Byte]]] =
Expand Down Expand Up @@ -144,7 +144,7 @@ object SaunaOptions {
*/
def buildConfigMap(files: List[File]): Either[String, Map[String, List[Envelope]]] = {
val enabledConfigs = sequence(files.map(parseSelfDescribing)).right.map { configs =>
configs.filter(filterEnabled).groupBy(_.schema.name)
configs.filter(filterEnabled).groupBy(_.schema)
}.left.map( list => list.mkString(", "))

enabledConfigs.right.flatMap { map =>
Expand Down Expand Up @@ -224,9 +224,9 @@ object SaunaOptions {
* @param enabledConfigs configuration enabledConfigs with list of possible enabled configurations
* @return validated configuration enabledConfigs with
*/
private[sauna] def getUnique(enabledConfigs: Map[String, List[Envelope]]): Either[String, Map[String, List[Envelope]]] = {
private[sauna] def getUnique(enabledConfigs: Map[SchemaKey, List[Envelope]]): Either[String, Map[String, List[Envelope]]] = {
val (valid, invalid) = enabledConfigs.partition {
case (schema, envelopes) => schema.contains(".observers") || envelopes.size == 1
case (schema, envelopes) => schema.vendor.contains(".observers") || envelopes.size == 1
}

val ids = valid.flatMap {
Expand All @@ -238,7 +238,9 @@ object SaunaOptions {
} else if (invalid.nonEmpty) {
Left(s"Multiple configurations enabled: [${invalid.keys.mkString(",")}]")
} else {
Right(valid)
Right(valid.map {
case (schema, envelopes) => (schema.name, envelopes)
})
}
}

Expand Down

0 comments on commit a0b14c7

Please sign in to comment.