DMR.scala


  • Scala client library for DMR
  • DSL for operations
  • Good citizen in the Scala ecosystem¬†


@haraldpehl ~ http://hpehl.info

DSL


val n1 = ModelNode() at root op 'read_resource

val n2 = ModelNode() at root op 'read_children_names(
  'child_type -> "server-group")

val n3 = ModelNode() at 
  ("subsystem" -> "datasources") / 
  ("data-source" -> "ExampleDS") 
  op 'read_resource(
    'include_runtime -> true, 
    'recursive_depth -> 2)
val comp = ModelNode.composite(n1, n2, n3)

Reading


val node = ModelNode(
  "flag" -> true,
  "child" -> ModelNode(
    "inner-a" -> 123,
    "inner-b" -> "test",
    "deep-inside" -> ModelNode("foo" -> "bar")
  )
)
node("flag")
node.get("child" / "deep-inside" / "foo")
for {
  foo <- node.get("child" / "deep-insight" / "foo")
  value <- foo.asString
} yield value

Model Nodes the Scala Way


val node = ModelNode(
  "flag" -> true,
  "hello" -> "world",
  "answer" -> 42)
node map { case (key, node) => (key.toUpperCase -> node) }
node.filter { case (key, _) => key contains "a" }
node.filter { case (_, node) => node == ModelNode(42) }
import org.jboss.dmr.ModelType._
for {
  (_, node) <- node
  ModelNode(typ) = node if typ == INT
} yield node

DMR.repl


  • REPL based on DMR.scala
  • Execute DMR operations
  • Scripts

Execute Operations


val node = ModelNode() at ("subsystem" -> "datasources") 
  op 'read_resource
val client = connect()
import org.jboss.dmr.repl.Response.{Success, Failure}(client ! node) map {
case Response(Success, result) => ... case Response(Failure, failure) => ... }
import scala.util.{Success, Failure}(client ? node).onComplete {
  case Success(response) => ...
  case Failure(ex) => ...
}

Scripts


class CrazyStuff extends Script[ModelNode] {
  def code: Try[ModelNode] = {
    // setup and execute operations
    (client ! node) map {
      case Response(Success, result) => {
        // loop, filter, map result
        result
      }
      case Response(Failure, failure) => {
         throw new ScriptException(failure)
      }
    }
  }
}
import org.jboss.dmr.repl.Client._
connect()

val script = new CrazyStuff()
val result = script.run()

Get in Touch




DMR.scala

By Harald Pehl

DMR.scala

Scala client library for DMR operations

  • 825
Loading comments...