Skip to content

Commit

Permalink
Add for comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jhkolb committed Sep 9, 2016
1 parent c53355c commit 50e97b9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 37 deletions.
3 changes: 0 additions & 3 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ func DeployConfig(configFile string, sched Scheduler) ([]chan *objects.SPLogMsg,

// Set up overlay network for apps that want to use normal sockets
netName := uuid.NewV4().String()
if err = createOverlayNet(netName); err != nil {
return nil, fmt.Errorf("Failed to create overlay net: %v", err)
}

logs := make([]chan *objects.SPLogMsg, len(placement))
for service, spAlias := range placement {
Expand Down
26 changes: 0 additions & 26 deletions backend/dockerUtils.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,26 @@ object ConfigParser extends JavaTokenParsers {
"on" ~> (ident | stringLiteral ^^ (stripQuotes(_))) ^^ (Left(_)) |
"where" ~> parameterSequence ^^ (Right(_))

def serviceDeployment: Parser[Service] = "container" ~ containerName ~ "as" ~ ident ~ "with" ~ parameterSequence ~ spawnpointSpec ^^
def serviceDeployment: Parser[Seq[Service]] = "container" ~ containerName ~ "as" ~ ident ~ "with" ~ parameterSequence ~ spawnpointSpec ^^
{ case "container" ~ imgName ~ "as" ~ svcName ~ "with" ~ params ~ spec =>
spec match {
case Left(spawnpointName) => Service(svcName, imgName, params, spawnpointName, Map.empty[String, String])
case Right(spawnpointParams) => Service(svcName, imgName, params, "", spawnpointParams)
case Left(spawnpointName) => Seq(Service(svcName, imgName, params, spawnpointName, Map.empty[String, String]))
case Right(spawnpointParams) => Seq(Service(svcName, imgName, params, "", spawnpointParams))
}
}

def forComprehension: Parser[Seq[Service]] = "for" ~ ident ~ "in" ~ "[" ~ rep1sep(value, ",") ~ "]" ~ "{" ~ serviceDeployment ~ "}" ^^
{ case "for" ~ varName ~ "in" ~ "[" ~ varValues ~ "]" ~ "{" ~ Seq(service) ~ "}" => varValues.zipWithIndex.map { case (varValue, idx) =>
val svcName = if (service.name.contains(varName)) {
service.name.replace(varName, varValue)
} else {
service.name + idx.toString
}
val imageName = service.imageName.replace(varName, varValue)
val params = service.params.map { case (k, v) => (k, v.replace(varName, varValue)) }
val spawnpointName = service.spawnpointName.replace(varName, varValue)
val constraints = service.constraints.map { case (k, v) => (k, v.replace(varName, varValue)) }
Service(svcName, imageName, params, spawnpointName, constraints)
}
}

Expand All @@ -69,10 +84,12 @@ object ConfigParser extends JavaTokenParsers {
case Some(links) => links
}

def deployment: Parser[Deployment] = entity ~ spawnpointList ~ dependencySpec ~ rep1(serviceDeployment) ~ svcGraphSpec ^^ {
case ent ~ spawnpoints ~ dependencies ~ svcs ~ svcConns => Deployment(ent, spawnpoints, dependencies, svcs, svcConns)
def deployment: Parser[Deployment] = entity ~ spawnpointList ~ dependencySpec ~ rep1(serviceDeployment | forComprehension) ~ svcGraphSpec ^^ {
case ent ~ spawnpoints ~ dependencies ~ svcs ~ svcConns =>
Deployment(ent, spawnpoints, dependencies, svcs.flatten, svcConns)
}


private def findMissingParam(paramName: String, services: Seq[Service]): Option[String] = {
services.find(!_.params.contains(paramName)) match {
case None => None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ object ExecParser {
ConfigParser.parseAll(ConfigParser.deployment, rawInput) match {
case ConfigParser.Failure(msg, _) =>
println("Syntax error in config file: " + msg)
System.exit(1)
case ConfigParser.Success(deployment, _) =>
ConfigParser.validate(deployment) match {
case Some(err) =>
println("Invalid configuration file: " + err)
System.exit(1)
case None =>
val outputFile = new File(args(1))
val fos = new FileOutputStream(outputFile)
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func actionSubmit(c *cli.Context) error {
os.Exit(1)
}

cmd := exec.Command("scala", parserLocation, inputFile, tempOutputFile)
if err := cmd.Run(); err != nil {
fmt.Println("Failed to parse config file")
output, err := exec.Command("scala", parserLocation, inputFile, tempOutputFile).Output()
if err != nil {
fmt.Print(string(output))
os.Exit(1)
}

Expand Down

0 comments on commit 50e97b9

Please sign in to comment.