Problems with extraction of Graph from a simple Stringified JSON

34 views
Skip to first unread message

Anirudh Vyas

unread,
Jun 4, 2018, 11:06:29 AM6/4/18
to scala-graph
Hi 

First off - is this project still alive? it seems like good work and would not want it to go to waste. I am attempting to use scala-graph to translate a a user-defined workflow into a task-graph which i will serialize and send to a different kinds of workers (based on workflow), where workers are akka actors and then translate these graphs to akka.graphs perhaps and execute them in order. 

For a simple test - I am trying to extract Graph[DefTaskNode, LKDiEdge] like structure where DefTaskNode is a case class with id, name, description and is formed like this - 

// transform the graph to json and store it by associating it with a WF identifier.
val taskNodeDescriptor = new NodeDescriptor[DefTaskNode](typeId = "Tasks") {
 
def id(node: Any) = node match {
   
case DefTaskNode(id, _, _, _, _) id
 
}
}
import scalax.collection.edge.Implicits._
import scalax.collection.io.json._

val g = Graph.empty[TaskNode, LkDiEdge]
val edge = (DefTaskNode("1", "task_some_name", "some_Desc", "{}", Seq.empty) ~+#> DefTaskNode("2", "task_some_name_1", "task_some_name_1", "{}", Seq.empty)) (HAPPENS_BEFORE.constraintType.toString)
val edge1 = (DefTaskNode("2", "task_some_name_1", "task_some_name_1", "{}", Seq.empty) ~+#> DefTaskNode("3", "tk_extrapolate", "desc - extrapolate", "{}", Seq.empty)) (HAPPENS_BEFORE.constraintType.toString)
g.add(edge)
g.add(edge1)
private val mainDesc = new Descriptor[TaskNode](
  defaultNodeDescriptor
= taskNodeDescriptor,
  defaultEdgeDescriptor
= LkDi.descriptor[TaskNode, Label](HAPPENS_BEFORE)
)
private val stringified = g.toJson(mainDesc)
println(s"################# \n $stringified \n ################## \n")
import scalax.collection.io.json._
import scalax.collection.io.json.imp.Parser._
val parsed = parse(stringified, mainDesc)
println(parsed)
private val tasks = Graph.fromJson[DefTaskNode, LkDiEdge](parsed, mainDesc)
println(s"$tasks")

This doesn't compile - errors out on Graph.fromJson[DefTaskNode, LkDiEdge](parsed, mainDesc) asking for implicit scalax.collection.core.configuration.

What compiles is below: =

// transform the graph to json and store it by associating it with a WF identifier.
// transform the graph to json and store it by associating it with a WF identifier.
val taskNodeDescriptor = new NodeDescriptor[DefTaskNode](typeId = "Tasks") {
 
def id(node: Any) = node match {
   
case DefTaskNode(id, _, _, _, _) id
 
}
}
import scalax.collection.edge.Implicits._
import scalax.collection.io.json._

val g = Graph.empty[TaskNode, LkDiEdge]
val edge = (DefTaskNode("1", "tk_pk_hr_usage", "find_peak_hour_usage", "{}", Seq.empty) ~+#> DefTaskNode("2", "tk_fnd_jsession_ids", "task_find_jsession_ids", "{}", Seq.empty)) (HAPPENS_BEFORE.constraintType.toString)
val edge1 = (DefTaskNode("2", "tk_fnd_jsession_ids", "task_find_jsession_ids", "{}", Seq.empty) ~+#> DefTaskNode("3", "tk_cap_plan_extrapolate", "capacity_plan_extrapolate", "{}", Seq.empty)) (HAPPENS_BEFORE.constraintType.toString)
g.add(edge)
g.add(edge1)
private val mainDesc = new Descriptor[TaskNode](
  defaultNodeDescriptor
= taskNodeDescriptor,
  defaultEdgeDescriptor
= LkDi.descriptor[TaskNode, Label](HAPPENS_BEFORE)
)
private val stringified = g.toJson(mainDesc)
println(s"################# \n $stringified \n ################## \n")
import scalax.collection.io.json._
import scalax.collection.io.json.imp.Parser._
val parsed = parse(stringified, mainDesc)
println(parsed)
private val tasks = Graph.fromJson(stringified, mainDesc)
println(s"$tasks")


however this throws an exception - 

Exception in thread "main" net.liftweb.json.MappingException: No usable value for label
No usable value for id
Did not find value which can be converted into int
at net.liftweb.json.Meta$.fail(Meta.scala:201)
at net.liftweb.json.Extraction$.mkValue$1(Extraction.scala:369)
at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$build$1(Extraction.scala:326)
at net.liftweb.json.Extraction$$anonfun$14.apply(Extraction.scala:253)
at net.liftweb.json.Extraction$$anonfun$14.apply(Extraction.scala:253)
at scala.collection.immutable.List.map(List.scala:288)
at net.liftweb.json.Extraction$.instantiate$1(Extraction.scala:253)
at net.liftweb.json.Extraction$.newInstance$1(Extraction.scala:287)
at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$build$1(Extraction.scala:324)
at net.liftweb.json.Extraction$.extract0(Extraction.scala:375)
at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$extract0(Extraction.scala:200)
at net.liftweb.json.Extraction$.extract(Extraction.scala:43)
at net.liftweb.json.JsonAST$JValue.extract(JsonAST.scala:703)
at scalax.collection.io.json.descriptor.LEdgeDescriptor.extract(EdgeDescriptor.scala:153)
at scalax.collection.io.json.imp.Stream$$anonfun$6$$anonfun$apply$3.apply(Stream.scala:85)
at scalax.collection.io.json.imp.Stream$$anonfun$6$$anonfun$apply$3.apply(Stream.scala:82)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scalax.collection.io.json.imp.JsonList.foreach(Parser.scala:11)
at scalax.collection.io.json.imp.Stream$$anonfun$6.apply(Stream.scala:82)
at scalax.collection.io.json.imp.Stream$$anonfun$6.apply(Stream.scala:55)
at scala.collection.immutable.List.foreach(List.scala:392)
at scalax.collection.io.json.imp.Stream$.createOuterElems(Stream.scala:55)
at scalax.collection.io.json.package$JsonGraphCoreCompanion$.fromJson$extension2(package.scala:90)
at scalax.collection.io.json.package$JsonGraphCoreCompanion$.fromJson$extension1(package.scala:75)
at com.wd.perf.flow.actor.Test$.delayedEndpoint$com$wd$perf$flow$actor$Test$1(WorkflowSchedulingActor.scala:78)
at com.wd.perf.flow.actor.Test$delayedInit$body.apply(WorkflowSchedulingActor.scala:53)
at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:392)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at com.wd.perf.flow.actor.Test$.main(WorkflowSchedulingActor.scala:53)
at com.wd.perf.flow.actor.Test.main(WorkflowSchedulingActor.scala)
Caused by: net.liftweb.json.MappingException: No usable value for id
Did not find value which can be converted into int
at net.liftweb.json.Meta$.fail(Meta.scala:201)
at net.liftweb.json.Extraction$.mkValue$1(Extraction.scala:369)
at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$build$1(Extraction.scala:326)
at net.liftweb.json.Extraction$$anonfun$14.apply(Extraction.scala:253)
at net.liftweb.json.Extraction$$anonfun$14.apply(Extraction.scala:253)
at scala.collection.immutable.List.map(List.scala:284)
at net.liftweb.json.Extraction$.instantiate$1(Extraction.scala:253)
at net.liftweb.json.Extraction$.newInstance$1(Extraction.scala:287)
at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$build$1(Extraction.scala:324)
at net.liftweb.json.Extraction$.mkValue$1(Extraction.scala:362)
... 35 more
Caused by: net.liftweb.json.MappingException: Did not find value which can be converted into int
at net.liftweb.json.Meta$.fail(Meta.scala:201)
at net.liftweb.json.Extraction$.convert(Extraction.scala:413)
at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$build$1(Extraction.scala:323)
at net.liftweb.json.Extraction$.mkValue$1(Extraction.scala:362)
... 43 more



Anirudh Vyas

unread,
Jun 4, 2018, 9:07:38 PM6/4/18
to scala-graph
I was able to fix the issue by populating NON-BLANK values and making things Optional. This sort of error it seems to me is a little obtuse but it works for me at the moment so no gripes.
Reply all
Reply to author
Forward
0 new messages