Skip to content

Commit

Permalink
Merge branch 'dev' into feature/simplify-cli-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgooz authored Aug 17, 2018
2 parents db10cb9 + 2168689 commit a9c4818
Show file tree
Hide file tree
Showing 66 changed files with 5,118 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- (#282) Branch support added. You can now specify your branches with a `#branch` fragment at the end of your git url. E.g.: https://github.com/mesg-foundation/service-ethereum-erc20#websocket
- (#299) Add more user friendly errors when failing to connect to the Core or Docker
- (#356) Use github.com/stretchr/testify package
- (#352) Use logrus logging package

#### Added
- (#242) Add more details in command `mesg-core service validate`
Expand Down
22 changes: 21 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
# go-tests = true
# unused-packages = true

[[constraint]]
branch = "master"
name = "github.com/grpc-ecosystem/go-grpc-middleware"

[[constraint]]
version = "1.0.6"
name = "github.com/sirupsen/logrus"

[[constraint]]
branch = "master"
Expand Down Expand Up @@ -69,7 +76,7 @@
branch = "master"
name = "golang.org/x/net"

[[constraint]]
[[override]]
branch = "master"
name = "google.golang.org/grpc"

Expand Down
38 changes: 19 additions & 19 deletions api/core/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import "github.com/mesg-foundation/core/service/service.proto";
// This is the primary API to interact with MESG Core functionalities.
// It can be consumed by any applications or tools that you'd like to interact with MESG Core.
// It is actually used by the MESG CLI and MESG Application libraries.
//
//
// This API is only accessible through [gRPC](https://grpc.io/).
//
//
// Services must not use this API, but rather use the [Service API](./service.md).
//
//
// The source file of this API is hosted on [GitHub](https://github.com/mesg-foundation/core/blob/master/api/core/api.proto).
service Core {
// Subscribe to a stream that listens for events from a service.
rpc ListenEvent (ListenEventRequest) returns (stream EventData) {}

// Subscribe to a stream that listens for task's result from a service.
rpc ListenResult (ListenResultRequest) returns (stream ResultData) {}

// Execute a service's task through [Core](../guide/start-here/core.md).
rpc ExecuteTask (ExecuteTaskRequest) returns (ExecuteTaskReply) {}

Expand All @@ -29,7 +29,7 @@ service Core {

// Stop a service. The service must be already deployed to [Core](../guide/start-here/core.md).
rpc StopService (StopServiceRequest) returns (StopServiceReply) {}

// Deploy a service to [Core](../guide/start-here/core.md). This will give you an unique identifier which is used to interact with the service.
rpc DeployService (stream DeployServiceRequest) returns (stream DeployServiceReply) {}

Expand All @@ -44,7 +44,7 @@ service Core {
}

// The request's data for the `ListenEvent` stream's API.
//
//
// **Example**
// ```json
// {
Expand All @@ -59,7 +59,7 @@ message ListenEventRequest {

// The data received from the stream of the `ListenEvent` API.
// The data will be received over time as long as the stream is open.
//
//
// **Example**
// ```json
// {
Expand All @@ -73,7 +73,7 @@ message EventData {
}

// The request's data for the `ListenResult` stream API.
//
//
// **Example**
// ```json
// {
Expand All @@ -90,7 +90,7 @@ message ListenResultRequest {

// The data received from the stream of the `ListenResult` API.
// The data will be received over time as long as the stream is open.
//
//
// **Example**
// ```json
// {
Expand All @@ -108,7 +108,7 @@ message ResultData {
}

// The request's data for the `ExecuteTask` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -124,7 +124,7 @@ message ExecuteTaskRequest {
}

// The reply's data of the `ExecuteTask` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -136,7 +136,7 @@ message ExecuteTaskReply {
}

// The request's data for the `StartService` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -152,7 +152,7 @@ message StartServiceReply {
}

// The request's data for the `StopService` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -168,7 +168,7 @@ message StopServiceReply {
}

// The request's data for `DeployService` API.
//
//
// **Example**
// ```json
// {
Expand Down Expand Up @@ -211,7 +211,7 @@ message DeployServiceRequest {
}

// The reply's data of `DeployService` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -234,7 +234,7 @@ message DeployServiceReply {
}

// Request's data of the `DeleteService` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -254,7 +254,7 @@ message ListServicesRequest {
}

// The reply's data of the `ListServices` API.
//
//
// **Example**
// ```json
// [{
Expand Down Expand Up @@ -289,7 +289,7 @@ message ListServicesReply {
}

// The request's data for the `GetService` API.
//
//
// **Example**
// ```json
// {
Expand All @@ -301,7 +301,7 @@ message GetServiceRequest {
}

// The reply's data of the `GetService` API.
//
//
// **Example**
// ```json
// {
Expand Down
15 changes: 12 additions & 3 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package api

import (
"errors"
"log"
"net"
"os"

"github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
"github.com/mesg-foundation/core/api/core"
"github.com/mesg-foundation/core/api/service"
"github.com/mesg-foundation/core/mesg"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
Expand Down Expand Up @@ -36,10 +38,17 @@ func (s *Server) Serve() error {
}

s.listener = listener
s.instance = grpc.NewServer()
s.instance = grpc.NewServer(
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
grpc_logrus.StreamServerInterceptor(logrus.NewEntry(logrus.StandardLogger())),
)),
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
grpc_logrus.UnaryServerInterceptor(logrus.NewEntry(logrus.StandardLogger())),
)),
)
s.register()

log.Println("Server listens on", s.listener.Addr())
logrus.Info("Server listens on ", s.listener.Addr())

// TODO: check if server still on after a connection throw an error. otherwise, add a for around serve
return s.instance.Serve(s.listener)
Expand Down
14 changes: 7 additions & 7 deletions api/service/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ option go_package = "service";
// This is the API for MESG Services to interact with MESG Core.
// It is to be consumed only by MESG Services.
// It provides all necessary functions that MESG Services need in order to interact with MESG Core.
//
//
// This API is only accessible through [gRPC](https://grpc.io/).
//
//
// Applications must not use this API, but rather use the [Core API](./core.md).
//
//
// The source file of this API is hosted on [GitHub](https://github.com/mesg-foundation/core/blob/master/api/service/api.proto).
service Service {
// Emit an event to [Core](../guide/start-here/core.md).
Expand All @@ -27,7 +27,7 @@ service Service {
}

// The request's data for the `EmitEvent` API.
//
//
// **Example:**
// ```json
// {
Expand All @@ -47,7 +47,7 @@ message EmitEventReply {
}

// The request's data for the `ListenTask` stream API.
//
//
// **Example:**
// ```json
// {
Expand All @@ -61,7 +61,7 @@ message ListenTaskRequest {
// The data received from the stream of the `ListenTask` API.
// The data will be received over time as long as the stream is open.
// The `executionID` value must be kept and sent with the result when calling the [`SubmitResult` API](#submitresult).
//
//
// **Example:**
// ```json
// {
Expand All @@ -78,7 +78,7 @@ message TaskData {

// The request's data for the `SubmitResult` API.
// The data must contain the `executionID` of the executed task received from the stream of [`ListenTask` API](#listentask).
//
//
// **Example:**
// ```json
// {
Expand Down
10 changes: 5 additions & 5 deletions cmd/service/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package service
import (
"context"
"fmt"
"log"

"github.com/logrusorgru/aurora"
"github.com/mesg-foundation/core/api/core"
"github.com/mesg-foundation/core/cmd/utils"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -72,10 +72,10 @@ func listenEvents(serviceID string, filter string) {
for {
event, err := stream.Recv()
if err != nil {
log.Println(aurora.Red(err))
logrus.Info(aurora.Red(err))
return
}
log.Println("Receive event", aurora.Green(event.EventKey), ":", aurora.Bold(event.EventData))
logrus.Info("Receive event", aurora.Green(event.EventKey), ":", aurora.Bold(event.EventData))
}
}

Expand All @@ -90,9 +90,9 @@ func listenResults(serviceID string, result string, output string) {
for {
result, err := stream.Recv()
if err != nil {
log.Println(aurora.Red(err))
logrus.Info(aurora.Red(err))
return
}
log.Println("Receive result", aurora.Green(result.TaskKey), aurora.Cyan(result.OutputKey), "with data", aurora.Bold(result.OutputData))
logrus.Info("Receive result", aurora.Green(result.TaskKey), aurora.Cyan(result.OutputKey), "with data", aurora.Bold(result.OutputData))
}
}
Loading

0 comments on commit a9c4818

Please sign in to comment.