/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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";

package proto.org.apache.helix.gateway;

message SingleShardChangeRequest {
  enum StateChangeRequestType {
    ADD_SHARD = 0;
    DELETE_SHARD = 1;
    CHANGE_ROLE = 2;
  }
  StateChangeRequestType stateChangeRequestType = 1;   // Transition type for shard operations
  string resourceName = 2;              // Resource ID
  string shardName = 3;                 // Shard to perform operation
  string targetState = 4;     // Shard target state.
}

message ShardChangeRequests {
  repeated SingleShardChangeRequest request = 1;
}

message SingleResourceState {
  string resource = 1;             // name of the resource
  repeated SingleShardState shardStates = 2;    // State of each shard
}

message SingleShardState {
  string shardName = 1;       // Name of the shard
  string currentState = 2;     // Current state of the shard
}

message SingleShardTransitionStatus {
  string resourceName = 1;        // resource name
  string shardName = 2;           // shard name
  string currentState = 3;   // If it failed, what is the current state it should reported as.
}

message ShardTransitionStatus{
  string instanceName = 1;         // Name of the application instance
  string clusterName = 2;          // Name of the cluster to connect to
  repeated SingleShardTransitionStatus shardTransitionStatus = 3;    // state transition result for a shard
}

// Application report its state to Helix Gateway upon initial connection
message ShardState{
  string instanceName = 1;         // Name of the application instance
  string clusterName = 2;          // Name of the cluster to connect to
  repeated SingleResourceState resourceState = 3;    // State of each resource
}

// Application instance sends message upon initial connection or reply to state transition message
message ShardStateMessage{
  oneof instanceUpdate {
    ShardState shardState = 1;
    ShardTransitionStatus shardTransitionStatus = 2;
  }
}

service HelixGatewayService {
  rpc report(stream ShardStateMessage) returns (stream ShardChangeRequests) {}
}

