Skip to content

Commit

Permalink
Allow comments in store conf
Browse files Browse the repository at this point in the history
  • Loading branch information
obermeier committed Aug 24, 2017
1 parent 749d676 commit 936504d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ class ScrayConfigurationParser(override val input: ParserInput) extends ScrayGen
*/
def InputLine: Rule1[ScrayConfiguration] = rule { ConfigModel ~ EOI }

def ConfigModel: Rule1[ScrayConfiguration] = rule { ServiceOptions ~ optional(Comment) ~ oneOrMore(Datastores) ~ ConfigurationLocations ~> {
def ConfigModel: Rule1[ScrayConfiguration] = rule { zeroOrMore(Comment) ~ ServiceOptions ~ zeroOrMore(Comment) ~ oneOrMore(Datastores) ~ ConfigurationLocations ~> {
(serviceoptions: ScrayServiceOptions, stores: Seq[DBMSConfigProperties], urls: Seq[ScrayQueryspaceConfigurationURL]) =>
ScrayConfiguration(serviceoptions, stores, urls) }}

def Datastores: Rule1[DBMSConfigProperties] = rule { "connection" ~ optional(Identifier) ~ StoreTypes ~> {
def Datastores: Rule1[DBMSConfigProperties] = rule { zeroOrMore(Comment) ~ "connection" ~ optional(Identifier) ~ StoreTypes ~ zeroOrMore(Comment) ~> {
(name: Option[String], dbmsproperties: DBMSConfigProperties) => dbmsproperties.setName(name) }}

def StoreTypes: Rule1[DBMSConfigProperties] = rule { CassandraStoreConnection | JDBCStoreConnection | HDFSStoreConnection }
Expand Down Expand Up @@ -164,11 +164,11 @@ class ScrayConfigurationParser(override val input: ParserInput) extends ScrayGen

/* -------------------------------- Queryspaces configuration location rules ----------------------------------- */

def ConfigurationLocations: Rule1[Seq[ScrayQueryspaceConfigurationURL]] = rule { "queryspacelocations" ~ BRACE_OPEN ~
oneOrMore(ConfigurationLocationSetting).separatedBy(COMMA) ~ BRACE_CLOSE}
def ConfigurationLocations: Rule1[Seq[ScrayQueryspaceConfigurationURL]] = rule { zeroOrMore(Comment) ~ "queryspacelocations" ~ BRACE_OPEN ~
oneOrMore(ConfigurationLocationSetting).separatedBy(COMMA) ~ BRACE_CLOSE ~ zeroOrMore(Comment)}

def ConfigurationLocationSetting: Rule1[ScrayQueryspaceConfigurationURL] =
rule { "url" ~ QuotedString ~ optional("reload" ~ ConfigurationLocationAutoreload) ~> {
rule { zeroOrMore(Comment) ~ "url" ~ QuotedString ~ optional("reload" ~ ConfigurationLocationAutoreload) ~ zeroOrMore(Comment) ~> {
(url: String, autoreload: Option[ScrayQueryspaceConfigurationURLReload]) =>
ScrayQueryspaceConfigurationURL(url, autoreload.getOrElse(ScrayQueryspaceConfigurationURLReload())) }}
def ConfigurationLocationAutoreload: Rule1[ScrayQueryspaceConfigurationURLReload] =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Test comment1
service {
advertise host "192.168.0.1",
service port 18181
}

# Test comment2
connection test cassandra {
hosts ( "phobos", "venus" ,"wuppertal") # Test comment3
}

# Test comment4
queryspacelocations {
url "file://tmp/test.queryspace.scray1", # Test comment5
url "file://tmp/test.queryspace.scray2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class ScrayConfigurationParserSpecs extends WordSpec with LazyLogging {
assert(urls(0).url.length() > 0)
assert(urls(0).url.substring(0, urls(0).url.length() - 1) === urls(1).url.substring(0, urls(0).url.length() - 1))
}
"load test queryspace config with comments" in {
val result = ScrayConfigurationParser.parseResource("/configs/scrayqstestconfigWithComments.txt")
val urls = result.get.urls
assert(urls.size == 2)
assert(urls(0).reload === ScrayQueryspaceConfigurationURLReload(Some(ScrayQueryspaceConfigurationURLReload.DEFAULT_URL_RELOAD)))
assert(urls(0).url.length() > 0)
assert(urls(0).url.substring(0, urls(0).url.length() - 1) === urls(1).url.substring(0, urls(0).url.length() - 1))
}
}
"Scray's queryspace configuration parser" should {
"throw on an empty config file" in {
Expand Down

0 comments on commit 936504d

Please sign in to comment.