Skip to content

Commit

Permalink
Basic parsing working, also some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jhkolb committed Jul 22, 2016
1 parent d84e73b commit fd11e09
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 27 deletions.
49 changes: 33 additions & 16 deletions frontend/src/main/scala/edu/berkeley/cs/sdb/ConfigParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,50 @@ package edu.berkeley.cs.sdb
import scala.util.parsing.combinator._

class ConfigParser extends JavaTokenParsers {
def path: Parser[String] = """/?([~a-zA-Z\._\-]+/)*[a-zA-Z\._\-]+""".r
def entity = "entity" ~> path
private def stripQuotes(s: String) =
if (s.startsWith("\"") && s.endsWith("\"")) {
s.substring(1, s.length - 2)
} else {
s
}

// Primitives used to specify deployment options or parameters
def path: Parser[String] = """(/|~/)?([a-zA-Z\._\-]+/)*[a-zA-Z\._\-]+""".r
def URI: Parser[String] = """([a-zA-Z\._\-]+/)*[a-zA-Z\._\-]+(/\*|/\+)?""".r
def memAllocLiteral: Parser[String] = """[0-9]+[MmGg]""".r

def URI: Parser[String] = """([a-zA-Z\._\-]+/)*[a-zA-Z\._\-]+(/\* | /\+)?""".r
def spawnpointList: Parser[Seq[String]] = "spawnpoints" ~> "{" ~> rep1sep(URI, ",") <~ "}"
// The right-hand side of any parameter
def value: Parser[Any] = stringLiteral ^^ (stripQuotes(_)) |
URI |
path |
memAllocLiteral |
wholeNumber ^^ (_.toInt) |
floatingPointNumber ^^ (_.toDouble)

def valueSequence: Parser[Seq[Any]] = "[" ~> repsep(value, ",") <~ opt(",") ~ "]"

def value: Parser[Any] = stringLiteral |
wholeNumber ^^ (_.toInt) |
floatingPointNumber ^^ (_.toDouble)
def parameter: Parser[(String, Any)] = ident ~ (":" | "=") ~ (value | ident | valueSequence) ^^
{ case k ~ (":" | "=") ~ v => (k,v) }

def valueSequence: Parser[Seq[Any]] = "[" ~> rep1sep(value, ",") <~ "]"
def parameterSequence: Parser[Seq[(String, Any)]] = "{" ~> repsep(parameter, ",") <~ opt(",") ~ "}"

def parameter: Parser[(String, Any)] = ident ~ (":" | "=") ~ (ident | value | valueSequence) ^^ { case k ~ (":"|"=") ~ v => (k,v) }
def entity: Parser[String] = "entity" ~> path

def parameterSequence: Parser[Seq[(String, Any)]] = "{" ~> repsep(parameter, ",") <~ "}"
def spawnpointList: Parser[Seq[String]] = "spawnpoints" ~ "[" ~> repsep(URI, ",") <~ opt(",") ~ "]"

def dependencyList: Parser[Seq[String]] = "external" ~ "[" ~> repsep(ident | stringLiteral ^^ (stripQuotes(_)), ",") <~ opt(",") ~ "]"

def spawnpointSpec: Parser[Either[String, Seq[(String, Any)]]] =
"on" ~> (ident | stringLiteral) ^^ (Left(_))
"on" ~> (ident | stringLiteral ^^ (stripQuotes(_))) ^^ (Left(_)) |
"where" ~> parameterSequence ^^ (Right(_))

def serviceDeployment: Parser[Service] = "deploy" ~ path ~ "as" ~ ident ~ "with" ~ parameterSequence ~ spawnpointSpec ^^
{ case "deploy" ~ imgName ~ "as" ~ svcName ~ "with" ~ params ~ spec => Service(svcName, imgName, params, spec) }
def serviceDeployment: Parser[Service] = "container" ~ path ~ "as" ~ ident ~ "with" ~ parameterSequence ~ spawnpointSpec ^^
{ case "container" ~ imgName ~ "as" ~ svcName ~ "with" ~ params ~ spec => Service(svcName, imgName, params, spec) }

def svcGraph: Parser[Seq[(String, String)]] = repsep(ident, "->") ^^ (_.sliding(2).map { case List(x, y) => (x, y) }.toSeq)
def svcPath: Parser[Seq[(String, String)]] = repsep(ident, "->") ^^ (_.sliding(2).toList.map { case Seq(x,y) => (x,y) })
def svcGraph: Parser[Seq[(String, String)]] = "dependencies" ~ "{" ~> repsep(svcPath, ",") <~ opt(",") ~ "}" ^^ (_.flatten)

def deployment: Parser[Deployment] = entity ~ spawnpointList ~ rep(serviceDeployment) ~ rep(svcGraph) ^^
{ case ent ~ spawnpoints ~ svcs ~ connList => Deployment(ent, spawnpoints, svcs, connList.flatten) }
def deployment: Parser[Deployment] = entity ~ spawnpointList ~ dependencyList ~ rep(serviceDeployment) ~ svcGraph ^^ {
case ent ~ spawnpoints ~ dependencies ~ svcs ~ svcConns => Deployment(ent, spawnpoints, dependencies, svcs, svcConns)
}
}
13 changes: 12 additions & 1 deletion frontend/src/main/scala/edu/berkeley/cs/sdb/Deployment.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
package edu.berkeley.cs.sdb

case class Deployment(entity: String, spawnPointUris: Seq[String], services: Seq[Service],
/**
* A collection of Spawnpoint services that form a cohesive deployment
* @param entity The Bosswave entity to use for container deployment to Spawnpoint instances
* @param spawnPointUris Bosswave base URIs for the Spawnpoints to deploy to. May identify particular
* spawnpoint instances or express a base URI under which multiple Spawnpoints
* reside.
* @param dependencies External services that this deployment requires to function.
* @param services A list of specifications for the services to be deployed.
* @param topology The relationships between the deployment's services, i.e. an expression of
* which services rely upon each other to function properly.
*/
case class Deployment(entity: String, spawnPointUris: Seq[String], dependencies: Seq[String], services: Seq[Service],
topology: Seq[(String, String)])
16 changes: 10 additions & 6 deletions frontend/src/test/resources/test1.rpt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
entity ~/bosswave/keys/jackDev.ent

spawnpoints { scratch.ns/spawnpoint/alpha, jkolb.ns/spawnpoint/* }
spawnpoints [scratch.ns/spawnpoint/alpha, jkolb.ns/spawnpoint/*]

deploy r.cal-sdb.org/demosvc as demosvc with {
external [vision_driver,]

container r.cal-sdb.org/demosvc as demosvc with {
entity: ~/bosswave/keys/demosvc.ent,
memAlloc: 512M,
cpuShares: 1024,
volumes: [demosvc-store],
includedFiles: [params.yml],
} on alpha

deploy r.cal-sdb.org/enphase-driver as enphase with {
container r.cal-sdb.org/enphase-driver as enphase with {
entity = enphase.ent,
memAlloc = 2G,
cpuShares = 2048,
Expand All @@ -19,7 +21,7 @@ deploy r.cal-sdb.org/enphase-driver as enphase with {
owner = culler-mayeno.ns
}

deploy r.cal-sdb/cellmate as cellmate with {
container r.cal-sdb/cellmate as cellmate with {
entity = cellmate.ent,
memAlloc = 4G,
cpuShares = 4096,
Expand All @@ -29,5 +31,7 @@ deploy r.cal-sdb/cellmate as cellmate with {
hasGpu = true
}

cellmate -> visionDriver -> demosvc
enphase -> demosvc
dependencies {
cellmate -> visionDriver -> demosvc,
enphase -> demosvc,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class DeploymentParserSpec extends FunSuite {
test("Simple config file should parse successfully into deployment") {
val configText = Source.fromURL(getClass.getResource("/test1.rpt")).mkString
val parser = new ConfigParser()
println(parser.parseAll(parser.deployment, configText))
// case parser.Success(result, _) => println(result)
// case parser.NoSuccess(cause, _) => fail(cause)
// }
parser.parseAll(parser.deployment, configText) match {
case parser.Success(result, _) => println(result)
case parser.NoSuccess(cause, _) => fail(cause)
}
}
}

0 comments on commit fd11e09

Please sign in to comment.