diff --git a/.gitignore b/.gitignore index bc865b4da..c1ae241e6 100755 --- a/.gitignore +++ b/.gitignore @@ -29,5 +29,3 @@ project/plugins/project/ .DS_Store /secring.gpg -demo/http/gateway/*json -demo/http/gateway/*go diff --git a/.travis.yml b/.travis.yml index 55dff0e88..9f052df97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,11 +9,6 @@ scala: jdk: - oraclejdk8 -env: - global: - - GOPATH="${HOME}/go" - - PATH="${GOPATH}/bin:${PATH}" - before_cache: - du -h -d 1 $HOME/.ivy2/ - du -h -d 2 $HOME/.sbt/ @@ -35,19 +30,9 @@ before_install: - if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then openssl aes-256-cbc -K $encrypted_80bb47bfd841_key -iv $encrypted_80bb47bfd841_iv -in secring.gpg.enc -out secring.gpg -d; fi -- sh ./scripts/protobuf.sh -- sh ./scripts/gimme.sh - -install: -- go get -u github.com/golang/protobuf/{proto,protoc-gen-go} -- go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway -- go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger -- go get -u -v google.golang.org/grpc -- go get -u github.com/golang/protobuf/protoc-gen-go script: - sbt ++$TRAVIS_SCALA_VERSION orgScriptCI -- sbt -Dgo.path=$GOPATH ++$TRAVIS_SCALA_VERSION validateHttpDemo after_success: - bash <(curl -s https://codecov.io/bash) -t 5b75b318-ab71-4fbc-9203-bfa7765cdbdc diff --git a/README.md b/README.md index b09b30a34..273c0f7fa 100644 --- a/README.md +++ b/README.md @@ -9,113 +9,9 @@ Simple RPC with Freestyle -## Greeting Demo +# Demo -Run server: - -``` -sbt runServer -``` - -Run client: - -``` -sbt runClient -``` - -## User Demo - -Based on https://github.com/grpc-ecosystem/grpc-gateway. - -[grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway) is a plugin of protoc. It reads gRPC service definition, and generates a reverse-proxy server which translates a RESTful JSON API into gRPC. -This server is generated according to [custom options](https://cloud.google.com/service-management/reference/rpc/google.api#http) in your gRPC definition. - -### Prerequisites - -It's mandatory to follow these [instructions](https://github.com/grpc-ecosystem/grpc-gateway#installation) before proceeding. You might want use `brew install protobuf` if you're using OSX. - -And then: - -```bash -$ brew install go -$ go get -u github.com/golang/protobuf/{proto,protoc-gen-go} -$ go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway -$ go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger -$ go get -u -v google.golang.org/grpc -$ go get -u github.com/golang/protobuf/protoc-gen-go -``` - -Finally, make sure that your `$GOPATH/bin` is in your `$PATH`. - -### Troubleshooting - -#### `failed to run aclocal: No such file or directory` - -The development release of a program source code often comes with `autogen.sh` which is used to prepare a build process, including verifying program functionality and generating configure script. This `autogen.sh` script then relies on `autoreconf` to invoke `autoconf`, `automake`, `aclocal` and other related tools. - -The missing `aclocal` is part of `automake` package. Thus, to fix this error, install `automake` package. - -* `OSX`: - -https://gist.github.com/justinbellamy/2672db1c78f024f2d4fe - -* `Debian`, `Ubuntu` or `Linux Mint`: - -```bash -$ sudo apt-get install automake -``` - -* `CentOS`, `Fedora` or `RHEL`: - -```bash -$ sudo yum install automake -``` - -## Run Demo - -### Running the Server - -``` -sbt -Dgo.path=$GOPATH ";project demo-http;runMain freestyle.rpc.demo.user.UserServerApp" -``` - -### Running the Client - -Now, you could invoke the service: - -* Using the client, as usual: - -``` -sbt -Dgo.path=$GOPATH ";project demo-http;runMain freestyle.rpc.demo.user.UserClientApp" -``` - -### Generating and Running the Gateway - -You could generate a reverse proxy and writing an endpoint as it's described [here](https://github.com/grpc-ecosystem/grpc-gateway#usage). - -To run the gateway: - -```bash -go run demo/http/gateway/server/entry.go -``` - -Then, you could use `curl` or similar to fetch the user over `HTTP`: - -```bash -curl -X POST \ - -H "Content-Type: application/json" \ - -H "Cache-Control: no-cache" \ - -H "Postman-Token: 1e813409-6aa6-8cd1-70be-51305f31667f" \ - -d '{ - "password" : "password" - }' "http://127.0.0.1:8080/v1/frees" -``` - -HTTP Response: - -```bash -{"name":"Freestyle","email":"hello@frees.io"}% -``` +See [freestyle-rpc-examples repo](https://github.com/frees-io/freestyle-rpc-examples). [comment]: # (Start Copyright) # Copyright diff --git a/build.sbt b/build.sbt index 499eced91..d70a1dd56 100644 --- a/build.sbt +++ b/build.sbt @@ -1,19 +1,11 @@ -import com.trueaccord.scalapb.compiler.{Version => cv} - pgpPassphrase := Some(getEnvVar("PGP_PASSPHRASE").getOrElse("").toCharArray) pgpPublicRing := file(s"$gpgFolder/pubring.gpg") pgpSecretRing := file(s"$gpgFolder/secring.gpg") -lazy val root = project - .in(file(".")) - .settings(name := "freestyle-rpc") - .settings(moduleName := "root") - .settings(noPublishSettings: _*) - .aggregate(rpc, `demo-greeting`, `demo-protocolgen`) - lazy val rpc = project .in(file("rpc")) - .settings(moduleName := "freestyle-rpc") + .settings(moduleName := "frees-rpc") + .settings(scalaMetaSettings: _*) .settings( Seq( resolvers += Resolver.bintrayRepo("beyondthelines", "maven"), @@ -26,79 +18,7 @@ lazy val rpc = project "beyondthelines" %% "pbdirect" % "0.0.3", %%("monix"), %%("scalamockScalatest") % "test" - ) - ): _* - ) - -lazy val protogen = taskKey[Unit]("Generates .proto files from freestyle-rpc service definitions") - -lazy val `demo-protocolgen` = project - .in(file("demo/protocolgen")) - .settings(moduleName := "freestyle-rpc-demo-protocolgen") - .aggregate(rpc) - .dependsOn(rpc) - .settings(noPublishSettings: _*) - .settings(commandAliases: _*) - .settings(demoCommonSettings: _*) - .settings( - protogen := { - toError( - (runner in Compile).value - .run( - mainClass = "freestyle.rpc.protocol.ProtoCodeGen", - classpath = sbt.Attributed.data((fullClasspath in Compile).value), - options = Seq( - (baseDirectory.value / "src" / "main" / "scala").absolutePath, - (baseDirectory.value / "src" / "main" / "proto").absolutePath - ), - log = streams.value.log - ) - ) - } - ) - -lazy val `demo-greeting` = project - .in(file("demo/greeting")) - .settings(moduleName := "freestyle-rpc-demo-greeting") - .aggregate(rpc) - .dependsOn(rpc) - .settings(noPublishSettings: _*) - .settings(commandAliases: _*) - .settings(demoCommonSettings: _*) - .settings( - Seq( - libraryDependencies ++= Seq( - %%("freestyle-async"), - %%("freestyle-config") - ) - ): _*) - -lazy val googleApi = project - .in(file("third_party")) - .settings( - PB.protoSources.in(Compile) ++= Seq( - file(s"$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/") - ), - PB.targets.in(Compile) := Seq(scalapb.gen() -> sourceManaged.in(Compile).value), - libraryDependencies += "com.trueaccord.scalapb" %% "scalapb-runtime" % cv.scalapbVersion % "protobuf" - ) - -lazy val `demo-http` = project - .in(file("demo/http")) - .settings(moduleName := "freestyle-rpc-demo-http") - .aggregate(rpc, googleApi, `demo-greeting`) - .dependsOn(rpc, googleApi, `demo-greeting`) - .settings(noPublishSettings: _*) - .settings(demoCommonSettings: _*) - .settings( - Seq( - PB.protocOptions.in(Compile) ++= Seq( - "-I/usr/local/include -I.", - s"-I$GOPATH/src", - s"-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis", - "--go_out=plugins=grpc:./demo/http/gateway", - "--grpc-gateway_out=logtostderr=true:./demo/http/gateway", - "--swagger_out=logtostderr=true:./demo/http/gateway" - ) + ), + coverageExcludedPackages := ";freestyle\\.rpc\\.demo\\..*" ): _* - ) + ) \ No newline at end of file diff --git a/demo/greeting/src/main/proto/echo.proto b/demo/greeting/src/main/proto/echo.proto deleted file mode 100644 index c362c1f37..000000000 --- a/demo/greeting/src/main/proto/echo.proto +++ /dev/null @@ -1,9 +0,0 @@ -syntax = "proto3"; - -import "echo_messages.proto"; - -package freestyle.rpc.demo; - -service EchoService { - rpc Echo (EchoRequest) returns (EchoResponse); -} diff --git a/demo/greeting/src/main/proto/echo_messages.proto b/demo/greeting/src/main/proto/echo_messages.proto deleted file mode 100644 index f11510e4f..000000000 --- a/demo/greeting/src/main/proto/echo_messages.proto +++ /dev/null @@ -1,11 +0,0 @@ -syntax = "proto3"; - -package freestyle.rpc.demo; - -message EchoRequest { - string message = 1; -} - -message EchoResponse { - string message = 1; -} \ No newline at end of file diff --git a/demo/greeting/src/main/proto/greeting.proto b/demo/greeting/src/main/proto/greeting.proto deleted file mode 100644 index cdad90737..000000000 --- a/demo/greeting/src/main/proto/greeting.proto +++ /dev/null @@ -1,19 +0,0 @@ -syntax = "proto3"; - -package freestyle.rpc.demo; - -service Greeter { - rpc SayHello (MessageRequest) returns (MessageReply) {} - rpc SayGoodbye (MessageRequest) returns (MessageReply) {} - rpc LotsOfReplies(MessageRequest) returns (stream MessageReply) {} - rpc LotsOfGreetings(stream MessageRequest) returns (MessageReply) {} - rpc BidiHello(stream MessageRequest) returns (stream MessageReply) {} -} - -message MessageRequest { - string name = 1; -} - -message MessageReply { - string message = 1; -} diff --git a/demo/greeting/src/main/resources/application.conf b/demo/greeting/src/main/resources/application.conf deleted file mode 100644 index 74d884eb2..000000000 --- a/demo/greeting/src/main/resources/application.conf +++ /dev/null @@ -1,15 +0,0 @@ -rpc { - server { - port = 50051 - port = ${?RPC_PORT} - } -} - -rpc { - client { - host = "localhost" - host = ${?RPC_HOST} - port = 50051 - port = ${?RPC_PORT} - } -} \ No newline at end of file diff --git a/demo/greeting/src/main/scala/greeting/GreetingClient.scala b/demo/greeting/src/main/scala/greeting/GreetingClient.scala deleted file mode 100644 index 43a9f47fe..000000000 --- a/demo/greeting/src/main/scala/greeting/GreetingClient.scala +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package greeting - -import java.util.concurrent.{CountDownLatch, TimeUnit} - -import freestyle.rpc.demo.greeting.GreeterGrpc._ -import io.grpc.ManagedChannelBuilder -import io.grpc.stub.StreamObserver - -import scala.collection.immutable -import scala.concurrent.{Await, Future, Promise} -import scala.concurrent.duration._ -import scala.util.Random - -class GreetingClient { - - // This channel construction is pending to be changed once streaming is supported - private[this] val channel = - ManagedChannelBuilder.forAddress("localhost", 50051).usePlaintext(true).build - - private[this] val asyncHelloClient: GreeterStub = GreeterGrpc.stub(channel) - - def serverStreamingDemo(request: MessageRequest): Future[Unit] = { - val lotOfRepliesStreamingPromise = Promise[Unit]() - val lotOfRepliesObserver = new StreamObserver[MessageReply] { - - override def onError(t: Throwable): Unit = - println(s"[lotOfRepliesObserver] Streaming failure: ${t.getMessage}") - - override def onCompleted(): Unit = { - println("[lotOfRepliesObserver] Lot of Replies streaming completed") - lotOfRepliesStreamingPromise.success((): Unit) - } - - override def onNext(value: MessageReply): Unit = - println(s"[lotOfRepliesObserver] Received by streaming -> $value") - } - - asyncHelloClient.lotsOfReplies(request, lotOfRepliesObserver) - - Await.ready(lotOfRepliesStreamingPromise.future, Duration.Inf) - } - - def clientStreamingDemo(): Boolean = { - val countDownLatch = new CountDownLatch(1) - val responseObserver = new StreamObserver[MessageReply] { - - override def onError(t: Throwable): Unit = { - println(s"[responseObserver] Streaming failure: ${t.getMessage}") - countDownLatch.countDown() - } - - override def onCompleted(): Unit = { - println("[responseObserver] Lot of greetings streaming completed") - countDownLatch.countDown() - } - - override def onNext(value: MessageReply): Unit = - println(s"[responseObserver] Received by streaming -> $value") - } - - val requestObserver = asyncHelloClient.lotsOfGreetings(responseObserver) - - val randomRequestList = 1 to math.min(5, Random.nextInt(20)) - - try { - randomRequestList foreach (i => requestObserver.onNext(MessageRequest(s"I'm Freestyle $i"))) - } catch { - case t: Throwable => - countDownLatch.countDown() - requestObserver.onError(t) - } - - requestObserver.onCompleted() - countDownLatch.await(1, TimeUnit.MINUTES) - } - - def biStreamingDemo(): Boolean = { - - val countDownLatch = new CountDownLatch(1) - val requestObserver = asyncHelloClient.bidiHello(new StreamObserver[MessageReply] { - - override def onError(t: Throwable): Unit = { - println(s"Bi-Streaming failure: ${t.getMessage}") - countDownLatch.countDown() - } - - override def onCompleted(): Unit = { - println("Finished Bi-streaming") - countDownLatch.countDown() - } - - override def onNext(value: MessageReply): Unit = - println(s"Got $value from server") - }) - - val randomRequestList: immutable.Seq[MessageRequest] = (1 to math.min(5, Random.nextInt(20))) map ( - i => MessageRequest(s"Message $i")) - - try { - for (request <- randomRequestList) { - println(s"Sending message $request") - requestObserver.onNext(request) - } - } catch { - case e: RuntimeException => - requestObserver.onError(e) - throw e - } - - requestObserver.onCompleted() - countDownLatch.await(1, TimeUnit.MINUTES) - } -} diff --git a/demo/greeting/src/main/scala/greeting/GreetingClientApp.scala b/demo/greeting/src/main/scala/greeting/GreetingClientApp.scala deleted file mode 100644 index 7ab2f3831..000000000 --- a/demo/greeting/src/main/scala/greeting/GreetingClientApp.scala +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package greeting - -import cats.implicits._ -import freestyle._ -import freestyle.implicits._ -import freestyle.config.ConfigM -import freestyle.config.implicits._ -import freestyle.rpc.demo.echo_messages._ -import runtime.client.implicits._ -import greeting.client._ -import io.grpc._ - -import scala.concurrent.{Await, Future} -import scala.concurrent.duration.Duration - -@module -trait ClientAPP { - val greetingClientM: GreetingClientM - val echoClientM: EchoClientM -} - -object GreetingClientApp { - - type UnaryDemoResponse = (MessageReply, MessageReply, EchoResponse) - - val messageRequest = MessageRequest("Freestyle") - val echoRequest = EchoRequest("echo...") - - def unaryDemo[F[_]](implicit APP: ClientAPP[F]): FreeS[F, UnaryDemoResponse] = { - - val greetingClientM: GreetingClientM[F] = APP.greetingClientM - val echoClientM: EchoClientM[F] = APP.echoClientM - - val defaultOptions = CallOptions.DEFAULT - - val tupled = ( - greetingClientM.sayHello(messageRequest, defaultOptions) |@| - greetingClientM.sayGoodbye(messageRequest, defaultOptions) |@| - echoClientM.echo(echoRequest, defaultOptions) - ).tupled - - tupled.map { - case (hi: MessageReply, bye: MessageReply, echo: EchoResponse) => - println(s"Received -> (${hi.message}, ${bye.message}, ${echo.message})") - (hi, bye, echo) - } - } - - def main(args: Array[String]): Unit = { - - Await.result(unaryDemo[ClientAPP.Op].interpret[Future], Duration.Inf) - - val client = new GreetingClient - - // Server streaming RPCs where the client sends a request to the server and - // gets a stream to read a sequence of messages back. The client reads from - // the returned stream until there are no more messages. - - client.serverStreamingDemo(messageRequest) - - // Client streaming RPCs where the client writes a sequence of messages and sends them - // to the server, again using a provided stream. Once the client has finished writing the messages, - // it waits for the server to read them and return its response. - - client.clientStreamingDemo() - - // Bidirectional streaming RPCs where both sides send a sequence of messages using a read-write stream. - // The two streams operate independently, so clients and servers can read and write in whatever order - // they like: for example, the server could wait to receive all the client messages before writing its - // responses, or it could alternately read a message then write a message, or some other combination - // of reads and writes. The order of messages in each stream is preserved. - - client.biStreamingDemo() - - (): Unit - } -} diff --git a/demo/greeting/src/main/scala/greeting/GreetingServerApp.scala b/demo/greeting/src/main/scala/greeting/GreetingServerApp.scala deleted file mode 100644 index 09625878b..000000000 --- a/demo/greeting/src/main/scala/greeting/GreetingServerApp.scala +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package greeting - -import cats.implicits._ -import freestyle.rpc.server._ -import freestyle.rpc.server.implicits._ -import runtime.server.implicits._ - -import scala.concurrent.duration.Duration -import scala.concurrent.Await - -object GreetingServerApp { - - def main(args: Array[String]): Unit = - Await.result(server[GrpcServer.Op].bootstrapFuture, Duration.Inf) -} diff --git a/demo/greeting/src/main/scala/greeting/client/EchoClientM.scala b/demo/greeting/src/main/scala/greeting/client/EchoClientM.scala deleted file mode 100644 index 2c283e053..000000000 --- a/demo/greeting/src/main/scala/greeting/client/EchoClientM.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package greeting.client - -import freestyle._ -import freestyle.rpc.client._ -import freestyle.rpc.demo.echo.EchoServiceGrpc -import freestyle.rpc.demo.echo_messages._ -import io.grpc.CallOptions - -@module -trait EchoClientM { - - val clientCallsM: ClientCallsM - val channelOps: ChannelM - - def echo( - request: EchoRequest, - options: CallOptions = CallOptions.DEFAULT): FS.Seq[EchoResponse] = - for { - call <- channelOps.newCall(EchoServiceGrpc.METHOD_ECHO, options) - response <- clientCallsM.asyncM(call, request) - } yield response - -} diff --git a/demo/greeting/src/main/scala/greeting/client/GreetingClientM.scala b/demo/greeting/src/main/scala/greeting/client/GreetingClientM.scala deleted file mode 100644 index f20ceeb3c..000000000 --- a/demo/greeting/src/main/scala/greeting/client/GreetingClientM.scala +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package greeting.client - -import freestyle._ -import freestyle.rpc.client._ -import freestyle.rpc.demo.greeting._ -import io.grpc.CallOptions -import io.grpc.stub.StreamObserver - -@module -trait GreetingClientM { - - val clientCallsM: ClientCallsM - val channelOps: ChannelM - - def sayHello( - request: MessageRequest, - options: CallOptions = CallOptions.DEFAULT): FS.Seq[MessageReply] = - for { - call <- channelOps.newCall(GreeterGrpc.METHOD_SAY_HELLO, options) - response <- clientCallsM.asyncM(call, request) - } yield response - - def sayGoodbye( - request: MessageRequest, - options: CallOptions = CallOptions.DEFAULT): FS.Seq[MessageReply] = - for { - call <- channelOps.newCall(GreeterGrpc.METHOD_SAY_GOODBYE, options) - response <- clientCallsM.asyncM(call, request) - } yield response - - def lotsOfReplies( - request: MessageRequest, - responseObserver: StreamObserver[MessageReply], - options: CallOptions = CallOptions.DEFAULT): FS.Seq[Unit] = - for { - call <- channelOps.newCall(GreeterGrpc.METHOD_LOTS_OF_REPLIES, options) - response <- clientCallsM.asyncStreamServer(call, request, responseObserver) - } yield response - - def lotsOfGreetings( - responseObserver: StreamObserver[MessageReply], - options: CallOptions = CallOptions.DEFAULT): FS.Seq[StreamObserver[MessageRequest]] = - for { - call <- channelOps.newCall(GreeterGrpc.METHOD_LOTS_OF_GREETINGS, options) - response <- clientCallsM.asyncStreamClient(call, responseObserver) - } yield response - - def bidiHello( - responseObserver: StreamObserver[MessageReply], - options: CallOptions = CallOptions.DEFAULT): FS.Seq[StreamObserver[MessageRequest]] = - for { - call <- channelOps.newCall(GreeterGrpc.METHOD_BIDI_HELLO, options) - response <- clientCallsM.asyncStreamBidi(call, responseObserver) - } yield response - -} diff --git a/demo/greeting/src/main/scala/greeting/runtime/implicits.scala b/demo/greeting/src/main/scala/greeting/runtime/implicits.scala deleted file mode 100644 index 12369561a..000000000 --- a/demo/greeting/src/main/scala/greeting/runtime/implicits.scala +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package greeting.runtime - -import cats.~> -import cats.implicits._ -import freestyle._ -import freestyle.implicits._ -import freestyle.async.implicits._ -import freestyle.config.implicits._ -import freestyle.rpc.demo.echo.EchoServiceGrpc -import freestyle.rpc.demo.greeting._ -import freestyle.rpc.demo.greeting.service._ - -import scala.concurrent.duration._ -import scala.concurrent.{Await, ExecutionContext, Future} - -trait CommonImplicits { - - implicit val ec: ExecutionContext = ExecutionContext.Implicits.global - -} - -object server { - - trait Implicits extends CommonImplicits { - - import freestyle.rpc.server._ - import freestyle.rpc.server.handlers._ - import freestyle.rpc.server.implicits._ - - val grpcConfigs: List[GrpcConfig] = List( - AddService(GreeterGrpc.bindService(new GreetingService, ec)), - AddService(EchoServiceGrpc.bindService(new EchoService, ec)) - ) - - val conf: ServerW = Await.result( - BuildServerFromConfig[ServerConfig.Op]("rpc.server.port", grpcConfigs) - .interpret[Future], - 1.seconds) - - implicit val grpcServerHandler: GrpcServer.Op ~> Future = - new GrpcServerHandler[Future] andThen - new GrpcKInterpreter[Future](conf.server) - - } - - object implicits extends Implicits - -} - -object client { - - trait Implicits extends CommonImplicits { - - import freestyle.rpc.client._ - import freestyle.rpc.client.implicits._ - import freestyle.rpc.client.handlers.{ChannelMHandler, ClientCallsMHandler} - - val channelFor: ManagedChannelFor = - Await.result( - ConfigForAddress[ChannelConfig.Op]("rpc.client.host", "rpc.client.port") - .interpret[Future], - 1.seconds) - - val channelConfigList: List[ManagedChannelConfig] = List(UsePlaintext(true)) - - implicit def channelMHandler[F[_]]: ChannelM.Op ~> Future = - new ChannelMHandler[Future] andThen - new ManagedChannelInterpreter[Future](channelFor, channelConfigList) - - implicit val clientCallsMHandler: ClientCallsM.Op ~> Future = new ClientCallsMHandler[Future] - - } - - object implicits extends Implicits - -} diff --git a/demo/greeting/src/main/scala/greeting/service/EchoService.scala b/demo/greeting/src/main/scala/greeting/service/EchoService.scala deleted file mode 100644 index 13fd10d6d..000000000 --- a/demo/greeting/src/main/scala/greeting/service/EchoService.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package greeting -package service - -import freestyle.rpc.demo.echo.EchoServiceGrpc -import freestyle.rpc.demo.echo_messages.{EchoRequest, EchoResponse} - -import scala.concurrent.Future - -class EchoService extends EchoServiceGrpc.EchoService { - - override def echo(request: EchoRequest): Future[EchoResponse] = { - println(s"Echo request ${request.message}") - Future.successful(EchoResponse("Server Echo!")) - } - -} diff --git a/demo/greeting/src/main/scala/greeting/service/GreetingService.scala b/demo/greeting/src/main/scala/greeting/service/GreetingService.scala deleted file mode 100644 index f55b2ac6d..000000000 --- a/demo/greeting/src/main/scala/greeting/service/GreetingService.scala +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package greeting -package service - -import java.util.concurrent.{Executors, TimeUnit} -import java.util.concurrent.atomic.AtomicInteger - -import io.grpc.stub.StreamObserver - -import scala.concurrent.Future - -class GreetingService extends GreeterGrpc.Greeter { - - val numberOfReplies = 10 - val initialDelay: Long = 0l - val interval: Long = 500l - - // rpc SayHello (MessageRequest) returns (MessageReply) {} - def sayHello(request: MessageRequest): Future[MessageReply] = { - println(s"Hi message received from ${request.name}") - Future.successful(MessageReply(s"Hello ${request.name} from HelloService!")) - } - - // rpc SayGoodbye (MessageRequest) returns (MessageReply) {} - def sayGoodbye(request: MessageRequest): Future[MessageReply] = { - println(s"Goodbye message received from ${request.name}") - Future.successful(MessageReply(s"See you soon ${request.name}!")) - } - - // rpc LotsOfReplies(MessageRequest) returns (stream MessageReply) {} - def lotsOfReplies( - request: MessageRequest, - responseObserver: StreamObserver[MessageReply]): Unit = { - val scheduler = Executors.newSingleThreadScheduledExecutor() - val tick = new Runnable { - val counter = new AtomicInteger(10) - def run(): Unit = { - val n: Int = counter.getAndDecrement() - - if (n >= 0) { - responseObserver.onNext( - MessageReply( - s"[$n] I'm sorry to be a bore, but I wanted to say hi again ${request.name}!")) - } else { - scheduler.shutdown() - responseObserver.onCompleted() - } - } - } - - scheduler.scheduleAtFixedRate(tick, initialDelay, interval, TimeUnit.MILLISECONDS) - (): Unit - } - - // rpc LotsOfGreetings(stream MessageRequest) returns (MessageReply) {} - override def lotsOfGreetings( - responseObserver: StreamObserver[MessageReply]): StreamObserver[MessageRequest] = - new StreamObserver[MessageRequest] { - val loggerInfo = "lotsOfGreetings" - val counter = new AtomicInteger(0) - - override def onError(t: Throwable): Unit = - println(s"[$loggerInfo] Streaming failure: ${t.getMessage}") - - override def onCompleted(): Unit = { - println(s"[$loggerInfo] Streaming completed.") - - responseObserver.onNext(MessageReply(s"$loggerInfo - It's done ;)")) - responseObserver.onCompleted() - } - - override def onNext(value: MessageRequest): Unit = - println(s"[$loggerInfo] This is your message ${counter.incrementAndGet()}, ${value.name}") - } - - // rpc BidiHello(stream MessageRequest) returns (stream MessageReply) {} - override def bidiHello( - responseObserver: StreamObserver[MessageReply]): StreamObserver[MessageRequest] = - new StreamObserver[MessageRequest] { - val loggerInfo = "bidiHello" - val counter = new AtomicInteger(0) - - override def onError(t: Throwable): Unit = - println(s"[$loggerInfo] Streaming failure: ${t.getMessage}") - - override def onCompleted(): Unit = { - println(s"[$loggerInfo] Streaming completed.") - - responseObserver.onNext(MessageReply(s"$loggerInfo - It's done ;)")) - responseObserver.onCompleted() - } - - override def onNext(value: MessageRequest): Unit = { - responseObserver.onNext(MessageReply(s"$loggerInfo - I did receive $value")) - println(s"[$loggerInfo] This is your message ${counter.incrementAndGet()}, ${value.name}") - } - } -} diff --git a/demo/http/gateway/server/entry.go b/demo/http/gateway/server/entry.go deleted file mode 100644 index 8cd209aee..000000000 --- a/demo/http/gateway/server/entry.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "flag" - "net/http" - - "github.com/golang/glog" - "golang.org/x/net/context" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "google.golang.org/grpc" - - gw ".." -) - -var ( - userEndpoint = flag.String("user_endpoint", "localhost:50051", "/") -) - -func run() error { - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - mux := runtime.NewServeMux() - opts := []grpc.DialOption{grpc.WithInsecure()} - err := gw.RegisterUserServiceHandlerFromEndpoint(ctx, mux, *userEndpoint, opts) - if err != nil { - return err - } - - return http.ListenAndServe(":8080", mux) -} - -func main() { - flag.Parse() - defer glog.Flush() - - if err := run(); err != nil { - glog.Fatal(err) - } -} \ No newline at end of file diff --git a/demo/http/src/main/proto/user.proto b/demo/http/src/main/proto/user.proto deleted file mode 100644 index 749d67a2b..000000000 --- a/demo/http/src/main/proto/user.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto3"; - -package freestyle.rpc.demo; - -import "google/api/annotations.proto"; - -service UserService { - rpc Login (UserPassword) returns (User) { - option (google.api.http) = { - post: "/v1/{login=*}" - body: "*" - }; - } -} - -message UserPassword { - string login = 1; - string password = 2; -} - -message User { - string name = 1; - string email = 2; -} \ No newline at end of file diff --git a/demo/http/src/main/resources/application.conf b/demo/http/src/main/resources/application.conf deleted file mode 100644 index 74d884eb2..000000000 --- a/demo/http/src/main/resources/application.conf +++ /dev/null @@ -1,15 +0,0 @@ -rpc { - server { - port = 50051 - port = ${?RPC_PORT} - } -} - -rpc { - client { - host = "localhost" - host = ${?RPC_HOST} - port = 50051 - port = ${?RPC_PORT} - } -} \ No newline at end of file diff --git a/demo/http/src/main/scala/user/UserClient.scala b/demo/http/src/main/scala/user/UserClient.scala deleted file mode 100644 index 7646e8dc1..000000000 --- a/demo/http/src/main/scala/user/UserClient.scala +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package user - -import freestyle.rpc.demo.user.UserServiceGrpc.UserServiceStub -import io.grpc.ManagedChannelBuilder - -import scala.concurrent.{Await, Future} -import scala.concurrent.duration._ - -class UserClient { - - // This channel construction is pending to be changed once streaming is supported - private[this] val channel = - ManagedChannelBuilder.forAddress("localhost", 50051).usePlaintext(true).build - - private[this] val client: UserServiceStub = UserServiceGrpc.stub(channel) - - def login(request: UserPassword): Future[User] = - client.login(request) -} diff --git a/demo/http/src/main/scala/user/UserClientApp.scala b/demo/http/src/main/scala/user/UserClientApp.scala deleted file mode 100644 index f632a9f23..000000000 --- a/demo/http/src/main/scala/user/UserClientApp.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package user - -import scala.concurrent.Await -import scala.concurrent.duration.Duration - -object UserClientApp { - - def main(args: Array[String]): Unit = { - val request = UserPassword("frees", "password") - val client = new UserClient - - val response = client.login(request) - - println(s"Login Result -> ${Await.result(response, Duration.Inf)}") - } -} diff --git a/demo/http/src/main/scala/user/UserServerApp.scala b/demo/http/src/main/scala/user/UserServerApp.scala deleted file mode 100644 index 98581b8d0..000000000 --- a/demo/http/src/main/scala/user/UserServerApp.scala +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package user - -import cats.implicits._ -import freestyle.rpc.server._ -import freestyle.rpc.server.implicits._ -import runtime.implicits._ - -import scala.concurrent.duration.Duration -import scala.concurrent.Await - -object UserServerApp { - - def main(args: Array[String]): Unit = - Await.result(server[GrpcServer.Op].bootstrapFuture, Duration.Inf) -} diff --git a/demo/http/src/main/scala/user/UserService.scala b/demo/http/src/main/scala/user/UserService.scala deleted file mode 100644 index 9a58cb37e..000000000 --- a/demo/http/src/main/scala/user/UserService.scala +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package user - -import io.grpc.Status.Code -import io.grpc.{Metadata, Status, StatusException} - -import scala.concurrent.Future - -class UserService extends UserServiceGrpc.UserService { - - val errorStatus: Status = Code.NOT_FOUND.toStatus.withDescription("Unknown user") - - def login(request: UserPassword): Future[User] = { - database.get((request.login, request.password)) match { - case Some(user) => Future.successful(user) - case None => - Future.failed(new StatusException(errorStatus, new Metadata())) - } - } -} diff --git a/demo/http/src/main/scala/user/package.scala b/demo/http/src/main/scala/user/package.scala deleted file mode 100644 index cdd798e96..000000000 --- a/demo/http/src/main/scala/user/package.scala +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo - -package object user { - - type DB = Map[(String, String), User] - - val database: DB = - Map[(String, String), User](("frees", "password") -> User("Freestyle", "hello@frees.io")) -} diff --git a/demo/http/src/main/scala/user/runtime/implicits.scala b/demo/http/src/main/scala/user/runtime/implicits.scala deleted file mode 100644 index 73d4a49d9..000000000 --- a/demo/http/src/main/scala/user/runtime/implicits.scala +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc.demo -package user.runtime - -import cats.implicits._ -import cats.~> -import freestyle._ -import freestyle.implicits._ -import freestyle.config.implicits._ -import freestyle.rpc.demo.user._ -import freestyle.rpc.server._ -import freestyle.rpc.server.implicits._ -import freestyle.rpc.server.handlers._ - -import scala.concurrent.duration._ -import scala.concurrent.{Await, ExecutionContext, Future} - -object implicits { - - implicit val ec: ExecutionContext = ExecutionContext.Implicits.global - - val grpcConfigs: List[GrpcConfig] = List( - AddService(UserServiceGrpc.bindService(new UserService, ExecutionContext.global)) - ) - - val conf: ServerW = Await.result( - BuildServerFromConfig[ServerConfig.Op]("rpc.server.port", grpcConfigs) - .interpret[Future], - 1.seconds) - - implicit val grpcServerHandler: GrpcServer.Op ~> Future = - new GrpcServerHandler[Future] andThen - new GrpcKInterpreter[Future](conf.server) - -} diff --git a/demo/protocolgen/src/main/proto/service.proto b/demo/protocolgen/src/main/proto/service.proto deleted file mode 100644 index e9562afad..000000000 --- a/demo/protocolgen/src/main/proto/service.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto3"; - -option java_package = "com.example.foo"; -option java_multiple_files = true; -option java_outer_classname = "Ponycopter"; - -message MessageRequest { - string name = 1; - int32 n = 2; -} - -message MessageReply { - string name = 1; - repeated int32 n = 2; -} - -service GreetingService { - rpc sayHello (MessageRequest) returns (MessageReply) {} - rpc lotsOfReplies (MessageRequest) returns (stream MessageReply) {} - rpc lotsOfGreetings (stream MessageRequest) returns (MessageReply) {} - rpc bidiHello (stream MessageRequest) returns (stream MessageReply) {} -} - - \ No newline at end of file diff --git a/demo/protocolgen/src/main/scala/ClientApp.scala b/demo/protocolgen/src/main/scala/ClientApp.scala deleted file mode 100644 index addb05a3d..000000000 --- a/demo/protocolgen/src/main/scala/ClientApp.scala +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc -package demo -package protocolgen - -import java.util.concurrent.TimeUnit - -import freestyle.rpc.demo.protocolgen.protocols._ -import io.grpc._ - -import scala.concurrent.{Await, ExecutionContext, Future} -import scala.concurrent.duration.Duration -import freestyle.async.implicits._ -import freestyle.rpc.client.implicits._ -import monix.execution.Scheduler -import monix.reactive.Observable - -object ClientApp { - - def main(args: Array[String]): Unit = { - - implicit val ec: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global - implicit val scheduler: Scheduler = monix.execution.Scheduler.Implicits.global - - val channel = ManagedChannelBuilder.forAddress("localhost", 50051).usePlaintext(true).build - - val client: GreetingService.Client[Future] = - GreetingService.client[Future](channel) - - val resultM: Future[Unit] = for { - _ <- lotOfRepliesFuture(client) - _ <- bidiHelloTaskFuture(client) - _ <- sayHelloFuture(client) - _ <- lotsOfGreetingsFuture(client) - } yield (): Unit - - Await.result( - resultM, - Duration.Inf - ) - - channel.shutdown().awaitTermination(10, TimeUnit.SECONDS) - - (): Unit - } - - private[this] def lotOfRepliesFuture(client: GreetingService.Client[Future])( - implicit S: Scheduler): Future[Unit] = - client - .lotsOfReplies(MessageRequest("hi", Some(2))) - .runF("lotsOfReplies") - - private[this] def bidiHelloTaskFuture(client: GreetingService.Client[Future])( - implicit S: Scheduler): Future[Unit] = - client - .bidiHello(Observable.fromIterable(getSampleIterable("bidirectional", 4))) - .runF("bidiHello") - - private[this] def sayHelloFuture(client: GreetingService.Client[Future])( - implicit S: Scheduler): Future[Unit] = - client - .sayHello(MessageRequest("hi", Some(1))) - .map(m => println(s"1 - sayHello = $m")) - - private[this] def lotsOfGreetingsFuture(client: GreetingService.Client[Future])( - implicit S: Scheduler): Future[Unit] = - client - .lotsOfGreetings(Observable.fromIterable(getSampleIterable("client-streaming", 3))) - .map(m => println(s"2 - lotsOfGreetings = $m")) - - private[this] def getSampleIterable(str: String, id: Int): List[MessageRequest] = - (1 to 10).map(i => MessageRequest(s"[$str] hello$i", Some(id))).toList - - implicit class ObservableHandlerOps[A](obs: Observable[A]) { - - def runF(svc: String)(implicit S: Scheduler): Future[Unit] = - obs.zipWithIndex - .map { - case (message, index) => - println(s"[$svc] Received Message from Server => #$index: $message") - } - .onErrorHandle { - case e: StatusRuntimeException => - println(s"[$svc] Unexpected RPC failure: ${e.getStatus}") - throw e - } - .completedL - .runAsync(S) - } - -} diff --git a/demo/protocolgen/src/main/scala/ServerApp.scala b/demo/protocolgen/src/main/scala/ServerApp.scala deleted file mode 100644 index d40212193..000000000 --- a/demo/protocolgen/src/main/scala/ServerApp.scala +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc -package demo -package protocolgen - -import cats.implicits._ -import freestyle.rpc.server.GrpcServer -import freestyle.rpc.server.implicits._ -import freestyle.rpc.demo.protocolgen.runtime.server.implicits._ - -import scala.concurrent.Await -import scala.concurrent.duration.Duration - -object ServerApp { - - def main(args: Array[String]): Unit = - Await.result(server[GrpcServer.Op].bootstrapFuture, Duration.Inf) - -} diff --git a/demo/protocolgen/src/main/scala/runtime/implicits.scala b/demo/protocolgen/src/main/scala/runtime/implicits.scala deleted file mode 100644 index dd6781c1b..000000000 --- a/demo/protocolgen/src/main/scala/runtime/implicits.scala +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle.rpc -package demo -package protocolgen -package runtime - -import cats.{~>, Comonad} -import freestyle.rpc.demo.protocolgen.protocols.{GreetingService, MessageReply} -import monix.reactive.Observable - -import scala.concurrent.duration._ -import scala.concurrent.{Await, ExecutionContext, Future} - -trait CommonImplicits { - - implicit val ec: ExecutionContext = ExecutionContext.Implicits.global - implicit val S: monix.execution.Scheduler = monix.execution.Scheduler.Implicits.global - -} - -object server { - - trait Implicits extends CommonImplicits { - - import cats.implicits._ - import freestyle.rpc.server._ - import freestyle.rpc.server.handlers._ - import freestyle.rpc.server.implicits._ - import freestyle.rpc.client.implicits._ - - implicit val finiteDuration: FiniteDuration = 5.seconds - - implicit def futureComonad( - implicit ec: ExecutionContext, - atMost: FiniteDuration): Comonad[Future] = - new Comonad[Future] { - def extract[A](x: Future[A]): A = - Await.result(x, atMost) - - override def coflatMap[A, B](fa: Future[A])(f: (Future[A]) => B): Future[B] = Future(f(fa)) - - override def map[A, B](fa: Future[A])(f: (A) => B): Future[B] = fa.map(f) - } - - implicit val greetingServiceHandler: GreetingService.Handler[Future] = - new GreetingService.Handler[Future] { - - private[this] val commonListN: List[Int] = List(1, 2, 3, 4, 5) - private[this] val messageReplyList: List[MessageReply] = - (1 to 10).map(i => MessageReply(s"hello$i", commonListN map (_ * i))).toList - - override protected[this] def sayHello( - msg: protocols.MessageRequest): Future[protocols.MessageReply] = - Future.successful(MessageReply("hello", commonListN)) - - override protected[this] def lotsOfReplies( - msg: protocols.MessageRequest): Future[Observable[protocols.MessageReply]] = { - println(s"[lots of replies] Received: $msg") - Future.successful(Observable.fromIterable(messageReplyList)) - } - - override protected[this] def lotsOfGreetings( - msgs: Observable[protocols.MessageRequest]): Future[MessageReply] = { - msgs.zipWithIndex - .map { case (m, i) => println(s"Hi ${m.name}, message $i received [${m.n}]") } - .completedL - .runAsync - - Future.successful(MessageReply("hello", commonListN)) - } - - override protected[this] def bidiHello(msgs: Observable[protocols.MessageRequest]): Future[ - Observable[protocols.MessageReply]] = - Future.successful( - msgs.flatMap { request => - println(s"Hi ${request.name}, message received [${request.n}]") - Observable.fromIterable(messageReplyList) - } - ) - } - - val grpcConfigs: List[GrpcConfig] = List( - AddService(GreetingService.bindService[GreetingService.Op, Future]) - ) - - val conf: ServerW = ServerW(50051, grpcConfigs) - - implicit val grpcServerHandler: GrpcServer.Op ~> Future = - new GrpcServerHandler[Future] andThen - new GrpcKInterpreter[Future](conf.server) - - } - - object implicits extends Implicits - -} diff --git a/demo/protocolgen/src/main/scala/service.scala b/demo/protocolgen/src/main/scala/service.scala deleted file mode 100644 index 45801cc91..000000000 --- a/demo/protocolgen/src/main/scala/service.scala +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2017 47 Degrees, LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package freestyle -package rpc -package demo -package protocolgen - -import freestyle.rpc.protocol._ -import monix.reactive.Observable - -@option(name = "java_package", value = "com.example.foo", quote = true) -@option(name = "java_multiple_files", value = "true", quote = false) -@option(name = "java_outer_classname", value = "Ponycopter", quote = true) -object protocols { - - @message - case class MessageRequest(name: String, n: Option[Int]) - - @message - case class MessageReply(name: String, n: List[Int]) - - @free - @service - @debug - trait GreetingService { - - @rpc def sayHello(msg: MessageRequest): FS[MessageReply] - - @rpc - @stream[ResponseStreaming.type] - def lotsOfReplies(msg: MessageRequest): FS[Observable[MessageReply]] - - @rpc - @stream[RequestStreaming.type] - def lotsOfGreetings(msg: Observable[MessageRequest]): FS[MessageReply] - - @rpc - @stream[BidirectionalStreaming.type] - def bidiHello(msg: Observable[MessageRequest]): FS[Observable[MessageReply]] - } - -} diff --git a/project/ProjectPlugin.scala b/project/ProjectPlugin.scala deleted file mode 100644 index 556218ca9..000000000 --- a/project/ProjectPlugin.scala +++ /dev/null @@ -1,51 +0,0 @@ -import freestyle.FreestylePlugin -import sbt.Keys._ -import sbt._ -import sbtorgpolicies.OrgPoliciesPlugin.autoImport._ -import sbtprotoc.ProtocPlugin.autoImport.PB -import com.trueaccord.scalapb.compiler.{Version => cv} -import scoverage.ScoverageKeys -import scoverage.ScoverageKeys._ - -object ProjectPlugin extends AutoPlugin { - - override def requires: Plugins = FreestylePlugin - - override def trigger: PluginTrigger = allRequirements - - object autoImport { - - lazy val demoCommonSettings = Seq( - PB.protoSources.in(Compile) := Seq(sourceDirectory.in(Compile).value / "proto"), - PB.targets.in(Compile) := Seq(scalapb.gen() -> sourceManaged.in(Compile).value), - libraryDependencies ++= Seq( - "io.grpc" % "grpc-netty" % cv.grpcJavaVersion, - "com.trueaccord.scalapb" %% "scalapb-runtime" % cv.scalapbVersion % "protobuf", - "com.trueaccord.scalapb" %% "scalapb-runtime-grpc" % cv.scalapbVersion - ) - ) - - lazy val commandAliases: Seq[Def.Setting[_]] = - addCommandAlias( - "runServer", - ";project demo-greeting;runMain freestyle.rpc.demo.greeting.GreetingServerApp") ++ - addCommandAlias( - "runClient", - ";project demo-greeting;runMain freestyle.rpc.demo.greeting.GreetingClientApp") ++ - addCommandAlias("validateHttpDemo", ";project demo-http;clean;compile;test") ++ - addCommandAlias( - "runS", - ";project demo-protocolgen;runMain freestyle.rpc.demo.protocolgen.ServerApp") ++ - addCommandAlias( - "runC", - ";project demo-protocolgen;runMain freestyle.rpc.demo.protocolgen.ClientApp") - - lazy val GOPATH = Option(sys.props("go.path")).getOrElse("/your/go/path") - - } - - override def projectSettings: Seq[Def.Setting[_]] = scalaMetaSettings ++ Seq( - coverageExcludedPackages := ";freestyle\\.rpc\\.demo\\..*" - ) - -} diff --git a/project/scalapb.sbt b/project/scalapb.sbt deleted file mode 100644 index 77b0c88ab..000000000 --- a/project/scalapb.sbt +++ /dev/null @@ -1,3 +0,0 @@ -addSbtPlugin( - "com.thesamet" % "sbt-protoc" % "0.99.8" exclude ("com.trueaccord.scalapb", "protoc-bridge_2.10")) -libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin-shaded" % "0.6.0-pre5" diff --git a/scripts/gimme.sh b/scripts/gimme.sh deleted file mode 100644 index 3593fe923..000000000 --- a/scripts/gimme.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -mkdir -p ~/bin/gimme -curl -sL -o ~/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme; -chmod +x ~/bin/gimme; \ No newline at end of file diff --git a/scripts/protobuf.sh b/scripts/protobuf.sh deleted file mode 100644 index b486ddf9b..000000000 --- a/scripts/protobuf.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -ex -wget https://github.com/google/protobuf/archive/v3.3.1.tar.gz -tar -xzvf v3.3.1.tar.gz -cd protobuf-3.3.1 && ./autogen.sh && ./configure --prefix=/usr && make && sudo make install