// Copyright 2020 gorse Project Authors
//
// 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.
syntax = "proto3";

option go_package = "github.com/zhenghaoz/gorse/protocol";

package protocol;

enum NodeType {
  ServerNode = 0;
  WorkerNode = 1;
  ClientNode = 2;
}

service Master {

  /* meta distribute */
  rpc GetMeta(NodeInfo) returns (Meta) {}

  /* data distribute */
  rpc GetRankingModel(VersionInfo) returns (stream Fragment) {}
  rpc GetClickModel(VersionInfo) returns (stream Fragment) {}

  /* task management */
  rpc StartTask(StartTaskRequest) returns (StartTaskResponse) {}
  rpc UpdateTask(UpdateTaskRequest) returns (UpdateTaskResponse) {}
  rpc FinishTask(FinishTaskRequest) returns (FinishTaskResponse) {}

}

message Meta {
  string config = 1;
  int64 ranking_model_version = 3;
  int64 click_model_version = 4;
  string me = 5;
  repeated string servers = 6;
  repeated string workers = 7;
}

message Fragment {
  bytes data = 1;
}

message VersionInfo {
  int64 version = 1;
}

message NodeInfo {
  NodeType node_type = 1;
  string node_name = 2;
  int64 http_port = 3;
  string binary_version = 4;
}

message StartTaskRequest {
  string name = 1;
  int64 total = 2;
}

message UpdateTaskRequest {
  string name = 1;
  int64 done = 2;
}

message FinishTaskRequest {
  string name = 1;
}

message StartTaskResponse {}

message UpdateTaskResponse {}

message FinishTaskResponse {}
