hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chl...@apache.org
Subject [hama] branch componentization updated: 1. Move cats, zio libraries to top level build.sbt. 2. Add Setting.get(key, defaultValue) function. 3. Build BSPMaster with cats.data.Reader.
Date Sun, 17 Mar 2019 17:14:57 GMT
This is an automated email from the ASF dual-hosted git repository.

chl501 pushed a commit to branch componentization
in repository https://gitbox.apache.org/repos/asf/hama.git


The following commit(s) were added to refs/heads/componentization by this push:
     new f8a7673  1. Move cats, zio libraries to top level build.sbt. 2. Add Setting.get(key,
defaultValue) function. 3. Build BSPMaster with cats.data.Reader.
f8a7673 is described below

commit f8a7673b078ca6622d657a87a03b45cc38e6de39
Author: Chiahung Lin <chl501@apache.org>
AuthorDate: Sun Mar 17 18:14:03 2019 +0100

    1. Move cats, zio libraries to top level build.sbt.
    2. Add Setting.get(key, defaultValue) function.
    3. Build BSPMaster with cats.data.Reader.
---
 build.sbt                                          |  2 ++
 commons.v2/build.sbt                               |  5 +----
 .../main/scala/org/apache/hama/conf/Setting.scala  |  5 ++++-
 membership/build.sbt                               |  2 --
 .../org/apache/hama/membership/BSPMaster.scala     | 24 +++++++---------------
 5 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/build.sbt b/build.sbt
index 83c3fc4..60002b8 100644
--- a/build.sbt
+++ b/build.sbt
@@ -21,6 +21,8 @@ lazy val common = Seq (
   scalaVersion := "2.12.6",
   scalacOptions := Seq ("-deprecation", "-Ypartial-unification"), 
   libraryDependencies ++= Seq (
+    "org.typelevel" %% "cats-core" % "1.6.0",
+    "org.scalaz" %% "scalaz-zio" % "0.3.1",
     "org.scalatest" %% "scalatest" % "3.0.5" % "test"
   )
 )
diff --git a/commons.v2/build.sbt b/commons.v2/build.sbt
index ba4584f..2d7fe2f 100644
--- a/commons.v2/build.sbt
+++ b/commons.v2/build.sbt
@@ -17,11 +17,8 @@
  */
 name := "commons.v2"
 
-scalacOptions += "-Ypartial-unification"
-
 libraryDependencies ++= Seq (
   "com.typesafe" % "config" % "1.3.3",
   "org.slf4j" % "slf4j-api" % "1.7.25",
-  "org.slf4j" % "slf4j-simple" % "1.7.25",
-  "org.typelevel" %% "cats-core" % "1.6.0"
+  "org.slf4j" % "slf4j-simple" % "1.7.25"
 )
diff --git a/commons.v2/src/main/scala/org/apache/hama/conf/Setting.scala b/commons.v2/src/main/scala/org/apache/hama/conf/Setting.scala
index aa82ffd..1c7414f 100644
--- a/commons.v2/src/main/scala/org/apache/hama/conf/Setting.scala
+++ b/commons.v2/src/main/scala/org/apache/hama/conf/Setting.scala
@@ -22,7 +22,6 @@ import com.typesafe.config.ConfigFactory
 import com.typesafe.config.ConfigValue
 import com.typesafe.config.ConfigValueFactory
 import scala.util.Try
-import cats.data.Reader
 
 trait Setting {
 
@@ -30,6 +29,8 @@ trait Setting {
 
   def get[T](key: String): Option[T] 
 
+  def get[T](key: String, default: T): T 
+
 }
 object Setting {
 
@@ -45,6 +46,8 @@ object Setting {
     override def get[T](key: String): Option[T] = 
       Try(config.getAnyRef(key).asInstanceOf[T]).toOption
 
+    override def get[T](key: String, default: T): T = get(key).getOrElse(default)
+
   }
 
   // TODO: hadoop configuration to  
diff --git a/membership/build.sbt b/membership/build.sbt
index ef179da..dd0d2ff 100644
--- a/membership/build.sbt
+++ b/membership/build.sbt
@@ -21,7 +21,5 @@ libraryDependencies ++= Seq (
   "com.google.guava" % "guava" % "27.0-jre",
   "io.aeron" % "aeron-all" % "1.11.3",
   "org.apache.curator" % "curator-framework" % "4.0.1",
-  "org.scalaz" %% "scalaz-zio" % "0.3.1",
-  "org.typelevel" %% "cats-core" % "1.4.0",
   "org.apache.curator" % "curator-test" % "4.0.1" % Test
 )
diff --git a/membership/src/main/scala/org/apache/hama/membership/BSPMaster.scala b/membership/src/main/scala/org/apache/hama/membership/BSPMaster.scala
index cde62d5..778ae21 100644
--- a/membership/src/main/scala/org/apache/hama/membership/BSPMaster.scala
+++ b/membership/src/main/scala/org/apache/hama/membership/BSPMaster.scala
@@ -17,7 +17,7 @@
  */
 package org.apache.hama.membership
 
-import cats.data.{ State => CatsState }
+import cats.data.{ State => CatsState, Reader }
 import cats.syntax._
 import cats.implicits._
 import com.google.common.hash.Hashing
@@ -49,8 +49,6 @@ final case class Identifier(value: String)
 
 object BSPMaster {
 
-  lazy val defaultSetting = Setting.create()
-
   object Event {
 
     case object CommunicatorReady extends Event
@@ -172,20 +170,12 @@ object BSPMaster {
   }
   sealed trait State extends Product with Serializable
 
-  /**
-   * Builder to create BSPMaster.
-   */
-  case class Builder(host: String, port: Int) {
-
-    def withAddress(host: String, port: Int) = 
-      this.copy(host = host, port = port)
-
-    def build(): ValidatedResult[BSPMaster] = (
-      Address.create(host, port), 
-      Identifier.create(host, port),
-      Master.validNel
-    ).mapN(BSPMaster.apply)
-
+  def build = Reader{ (setting: Setting) => 
+    val host = setting.get("org.apache.hama.net.host", "localhost")
+    val port = setting.get("org.apache.hama.net.port", -1)
+    (Address.create(host, port),
+    Identifier.create(host, port),
+    Master.validNel).mapN(BSPMaster.apply)
   }
 
 }


Mime
View raw message