This repository has been archived by the owner on Dec 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
566 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name := "cheesecake-client" | ||
|
||
|
||
// Scalastyle setup | ||
lazy val testScalastyle = taskKey[Unit]("testScalastyle") | ||
lazy val testScalastyleInCompile = taskKey[Unit]("testScalastyleInCompile") | ||
testScalastyle := org.scalastyle.sbt.ScalastylePlugin.scalastyle.in(Test).toTask("").value | ||
testScalastyleInCompile := org.scalastyle.sbt.ScalastylePlugin.scalastyle.in(Compile).toTask("").value | ||
(test in Test) <<= (test in Test) dependsOn (testScalastyle, testScalastyleInCompile) | ||
scalastyleFailOnError := true |
11 changes: 11 additions & 0 deletions
11
client/src/main/scala/ru/maizy/cheesecake/client/Stub.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ru.maizy.cheesecake.client | ||
|
||
import ru.maizy.cheesecake.api | ||
import ru.maizy.cheesecake.core.utils.CollectionsUtils | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2016 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
case class Stub(stub: String, apiDep: api.Stub, coreDep: CollectionsUtils.type) // FIXME: tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name := "cheesecake-core" | ||
|
||
// Scalastyle setup | ||
lazy val testScalastyle = taskKey[Unit]("testScalastyle") | ||
lazy val testScalastyleInCompile = taskKey[Unit]("testScalastyleInCompile") | ||
testScalastyle := org.scalastyle.sbt.ScalastylePlugin.scalastyle.in(Test).toTask("").value | ||
testScalastyleInCompile := org.scalastyle.sbt.ScalastylePlugin.scalastyle.in(Compile).toTask("").value | ||
(test in Test) <<= (test in Test) dependsOn (testScalastyle, testScalastyleInCompile) | ||
scalastyleFailOnError := true |
122 changes: 122 additions & 0 deletions
122
core/src/main/scala/ru/maizy/cheesecake/core/RichTypesafeConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package ru.maizy.cheesecake.core | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2016 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
import scala.collection.JavaConversions.asScalaBuffer | ||
import scala.collection.JavaConverters.asScalaSetConverter | ||
import scala.util.{ Failure, Success, Try } | ||
import com.typesafe.config.{ Config, ConfigException, ConfigObject } | ||
|
||
object RichTypesafeConfig { | ||
|
||
type WarnMessages = Seq[String] | ||
case class ConfigLookupResults[T](result: T, warnings: WarnMessages) | ||
|
||
sealed trait ConfigError { | ||
def errorMessage: String | ||
override def toString: String = errorMessage | ||
} | ||
case class MissingValue(errorMessage: String) extends ConfigError | ||
case class WrongType(errorMessage: String) extends ConfigError | ||
case class UnknownError(errorMessage: String, cause: Option[Throwable] = None) extends ConfigError | ||
|
||
private def wrapExceptionToEitherWithEmptyForMissing[T]( | ||
path: String, | ||
typeName: String, | ||
empty: T)(getter: String => T): Either[ConfigError, T] = { | ||
|
||
Try(getter(path)) match { | ||
case Failure(e: ConfigException.Missing) => | ||
Right(empty) | ||
case Failure(e: ConfigException.WrongType) => | ||
Left(WrongType(s"value for path `$path` isn't $typeName")) | ||
case Failure(e: Throwable) => | ||
Left(UnknownError(s"unable to get value for path `$path`: $e", Some(e))) | ||
case Success(c) => Right(c) | ||
} | ||
} | ||
|
||
private def wrapExceptionToEither[T](path: String, typeName: String)(getter: String => T): Either[ConfigError, T] = { | ||
Try(getter(path)) match { | ||
case Failure(e: ConfigException.Missing) => | ||
Left(MissingValue(s"value for path `$path` is missing")) | ||
case Failure(e: ConfigException.WrongType) => | ||
Left(WrongType(s"value for path `$path` isn't $typeName")) | ||
case Failure(e: Throwable) => | ||
Left(UnknownError(s"unable to get value for path `$path`: $e", Some(e))) | ||
case Success(c) => Right(c) | ||
} | ||
} | ||
|
||
implicit class ConfigListImplicits(val config: Config) extends AnyVal { | ||
|
||
@throws[ConfigException] | ||
def asScalaConfigList(path: String): IndexedSeq[Config] = config.getConfigList(path).toIndexedSeq | ||
|
||
def eitherConfigList(path: String, allowEmpty: Boolean = false): Either[ConfigError, IndexedSeq[Config]] = | ||
wrapExceptionToEitherWithEmptyForMissing[IndexedSeq[Config]](path, "list", IndexedSeq.empty) { asScalaConfigList } | ||
|
||
def optConfigList(path: String, allowEmpty: Boolean = false): Option[IndexedSeq[Config]] = | ||
eitherConfigList(path, allowEmpty).right.toOption | ||
} | ||
|
||
|
||
implicit class StringImplicits(val config: Config) extends AnyVal { | ||
|
||
def eitherString(path: String): Either[ConfigError, String] = | ||
wrapExceptionToEither(path, "string") { config.getString } | ||
|
||
def optString(path: String): Option[String] = eitherString(path).right.toOption | ||
} | ||
|
||
|
||
implicit class IntImplicits(val config: Config) extends AnyVal { | ||
|
||
def eitherInt(path: String): Either[ConfigError, Int] = | ||
wrapExceptionToEither(path, "int") { config.getInt } | ||
|
||
def optInt(path: String): Option[Int] = eitherInt(path).right.toOption | ||
} | ||
|
||
implicit class ObjectImplicits(val config: Config) extends AnyVal { | ||
|
||
def eitherObject(path: String): Either[ConfigError, ConfigObject] = | ||
wrapExceptionToEither(path, "object") { config.getObject } | ||
|
||
def optObject(path: String): Option[ConfigObject] = eitherObject(path).right.toOption | ||
|
||
def eitherStringMapWithWarnings(path: String): ConfigLookupResults[Either[ConfigError, Map[String, String]]] = { | ||
eitherObject(path) match { | ||
case Right(obj) => | ||
val entiries = obj.entrySet.asScala.toIndexedSeq | ||
ConfigLookupResults( | ||
Right( | ||
entiries | ||
.filter(_.getValue.unwrapped.isInstanceOf[String]) | ||
.map(e => (e.getKey, e.getValue.unwrapped.asInstanceOf[String])) | ||
.toMap | ||
), | ||
entiries | ||
.filterNot(_.getValue.unwrapped.isInstanceOf[String]) | ||
.map(wrongValue => s"Value for `${wrongValue.getKey}` isn't string") | ||
) | ||
case Left(error) => ConfigLookupResults(Left(error), Seq.empty) | ||
} | ||
} | ||
|
||
def eitherStringMap(path: String): Either[ConfigError, Map[String, String]] = | ||
eitherStringMapWithWarnings(path).result | ||
|
||
def optStringMapWithWarnings(path: String): ConfigLookupResults[Option[Map[String, String]]] = { | ||
val eitherMapResults = eitherStringMapWithWarnings(path) | ||
ConfigLookupResults(eitherMapResults.result.right.toOption, eitherMapResults.warnings) | ||
} | ||
|
||
def optStringMap(path: String): Option[Map[String, String]] = optStringMapWithWarnings(path).result | ||
} | ||
|
||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// HOCON syntax: https://github.com/typesafehub/config/blob/master/HOCON.md | ||
|
||
cheesecake.services: [ | ||
{ | ||
name: nginx | ||
endpoints: [ | ||
|
||
// default endpoint keys | ||
{ | ||
// only the "http" type currenly supported | ||
type: http | ||
host: localhost | ||
port: 80 | ||
// path to check | ||
path: / | ||
} | ||
|
||
// so simply some keys may be omitted | ||
{ | ||
port: 8080 | ||
path: /status | ||
} | ||
|
||
// ip http endpoint (DNS resolving not used) | ||
{ | ||
type: http | ||
ip: 127.0.0.1 | ||
} | ||
|
||
// symbolic http endpoint (DNS resolving used for every check) | ||
{ | ||
type: http | ||
host: example.com | ||
} | ||
|
||
// all http endpoint params | ||
{ | ||
type: http | ||
// ip: 127.0.0.1 | ||
host: localhost | ||
path: "/some/path?with_arguments=%2Fquoted%2F" | ||
headers: {"X-Checker": "cheesecake", "Accept": "application/json"} | ||
|
||
} | ||
] | ||
} | ||
// other services | ||
{ | ||
name: myapp | ||
endpoints: [ | ||
{ | ||
type: http | ||
ip: 192.168.1.33 | ||
path: /status | ||
} | ||
] | ||
|
||
} | ||
// myself | ||
{ | ||
name: myself | ||
endpoints: [ | ||
{ | ||
type: http | ||
port: 52022 | ||
path: /status | ||
} | ||
] | ||
|
||
} | ||
// ... | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
|
||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | ||
<target>System.out</target> | ||
<encoder> | ||
<pattern>%gray(%d{HH:mm:ss.SSS}) %highlight(%.-1level) [%cyan(%logger{5}) %green(%X{akkaSource})]: %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="akka" level="INFO"/> | ||
<logger name="ru.maizy.cheesecake" level="DEBUG"/> | ||
|
||
<!-- suppress some verbose loggers --> | ||
<logger name="akka.serialization" level="INFO" /> | ||
|
||
<root level="DEBUG"> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.