/**
 * 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.
 */

// All to do with the Master.  Includes schema management since these
// changes are run by the Master process.

option java_package = "org.apache.hadoop.hbase.protobuf.generated";
option java_outer_classname = "MasterProtos";
option java_generic_services = true;
option java_generate_equals_and_hash = true;
option optimize_for = SPEED;

import "HBase.proto";
import "Client.proto";
import "ClusterStatus.proto";

/* Column-level protobufs */

message AddColumnRequest {
  required TableName table_name = 1;
  required ColumnFamilySchema column_families = 2;
}

message AddColumnResponse {
}

message DeleteColumnRequest {
  required TableName table_name = 1;
  required bytes column_name = 2;
}

message DeleteColumnResponse {
}

message ModifyColumnRequest {
  required TableName table_name = 1;
  required ColumnFamilySchema column_families = 2;
}

message ModifyColumnResponse {
}

/* Region-level Protos */

message MoveRegionRequest {
  required RegionSpecifier region = 1;
  optional ServerName dest_server_name = 2;
}

message MoveRegionResponse {
}

/**
 * Dispatch merging the specified regions.
 */
message DispatchMergingRegionsRequest {
  required RegionSpecifier region_a = 1;
  required RegionSpecifier region_b = 2;
  optional bool forcible = 3 [default = false];
}

message DispatchMergingRegionsResponse {
}

message AssignRegionRequest {
  required RegionSpecifier region = 1;
}

message AssignRegionResponse {
}

message UnassignRegionRequest {
  required RegionSpecifier region = 1;
  optional bool force = 2 [default = false];
}

message UnassignRegionResponse {
}

message OfflineRegionRequest {
  required RegionSpecifier region = 1;
}

message OfflineRegionResponse {
}

/* Table-level protobufs */

message CreateTableRequest {
  required TableSchema table_schema = 1;
  repeated bytes split_keys = 2;
}

message CreateTableResponse {
}

message DeleteTableRequest {
  required TableName table_name = 1;
}

message DeleteTableResponse {
}

message EnableTableRequest {
  required TableName table_name = 1;
}

message EnableTableResponse {
}

message DisableTableRequest {
  required TableName table_name = 1;
}

message DisableTableResponse {
}

message ModifyTableRequest {
  required TableName table_name = 1;
  required TableSchema table_schema = 2;
}

message ModifyTableResponse {
}

/* Namespace-level protobufs */

message CreateNamespaceRequest {
  required NamespaceDescriptor namespaceDescriptor = 1;
}

message CreateNamespaceResponse {
}

message DeleteNamespaceRequest {
  required string namespaceName = 1;
}

message DeleteNamespaceResponse {
}

message ModifyNamespaceRequest {
  required NamespaceDescriptor namespaceDescriptor = 1;
}

message ModifyNamespaceResponse {
}

message GetNamespaceDescriptorRequest {
  required string namespaceName = 1;
}

message GetNamespaceDescriptorResponse {
  required NamespaceDescriptor namespaceDescriptor = 1;
}

message ListNamespaceDescriptorsRequest {
}

message ListNamespaceDescriptorsResponse {
  repeated NamespaceDescriptor namespaceDescriptor = 1;
}

message ListTableDescriptorsByNamespaceRequest {
  required string namespaceName = 1;
}

message ListTableDescriptorsByNamespaceResponse {
  repeated TableSchema tableSchema = 1;
}

message ListTableNamesByNamespaceRequest {
  required string namespaceName = 1;
}

message ListTableNamesByNamespaceResponse {
  repeated TableName tableName = 1;
}

/* Cluster-level protobufs */


message ShutdownRequest {
}

message ShutdownResponse {
}

message StopMasterRequest {
}

message StopMasterResponse {
}

message BalanceRequest {
}

message BalanceResponse {
  required bool balancer_ran = 1;
}

message SetBalancerRunningRequest {
  required bool on = 1;
  optional bool synchronous = 2;
}

message SetBalancerRunningResponse {
  optional bool prev_balance_value = 1;
}

message RunCatalogScanRequest {
}

message RunCatalogScanResponse {
  optional int32 scan_result = 1;
}

message EnableCatalogJanitorRequest {
  required bool enable = 1;
}

message EnableCatalogJanitorResponse {
  optional bool prev_value = 1;
}

message IsCatalogJanitorEnabledRequest {
}

message IsCatalogJanitorEnabledResponse {
  required bool value = 1;
}

message SnapshotRequest {
	required SnapshotDescription snapshot = 1;
}

message SnapshotResponse {
	required int64 expected_timeout = 1;
}

message GetCompletedSnapshotsRequest {
}

message GetCompletedSnapshotsResponse {
	repeated SnapshotDescription snapshots = 1;
}

message DeleteSnapshotRequest {
	required SnapshotDescription snapshot = 1;
}

message DeleteSnapshotResponse {
}

message RestoreSnapshotRequest {
  required SnapshotDescription snapshot = 1;
}

message RestoreSnapshotResponse {
}

/* if you don't send the snapshot, then you will get it back
 * in the response (if the snapshot is done) so you can check the snapshot
 */
message IsSnapshotDoneRequest {
	optional SnapshotDescription snapshot = 1;
}

message IsSnapshotDoneResponse {
	optional bool done = 1 [default = false];
	optional SnapshotDescription snapshot = 2;
}

message IsRestoreSnapshotDoneRequest {
  optional SnapshotDescription snapshot = 1;
}

message IsRestoreSnapshotDoneResponse {
  optional bool done = 1 [default = false];
}

message GetSchemaAlterStatusRequest {
  required TableName table_name = 1;
}

message GetSchemaAlterStatusResponse {
  optional uint32 yet_to_update_regions = 1;
  optional uint32 total_regions = 2;
}

message GetTableDescriptorsRequest {
  repeated TableName table_names = 1;
}

message GetTableDescriptorsResponse {
  repeated TableSchema table_schema = 1;
}

message GetTableNamesRequest {
}

message GetTableNamesResponse {
  repeated TableName table_names = 1;
}

message GetClusterStatusRequest {
}

message GetClusterStatusResponse {
  required ClusterStatus cluster_status = 1;
}

message IsMasterRunningRequest {
}

message IsMasterRunningResponse {
  required bool is_master_running = 1;
}

message ExecProcedureRequest {
        required ProcedureDescription procedure = 1;
}

message ExecProcedureResponse {
        required int64 expected_timeout = 1;
}

message IsProcedureDoneRequest {
        optional ProcedureDescription procedure = 1;
}

message IsProcedureDoneResponse {
        optional bool done = 1 [default = false];
        optional ProcedureDescription snapshot = 2;
}

service MasterService {
  /** Used by the client to get the number of regions that have received the updated schema */
  rpc GetSchemaAlterStatus(GetSchemaAlterStatusRequest)
    returns(GetSchemaAlterStatusResponse);

  /** Get list of TableDescriptors for requested tables. */
  rpc GetTableDescriptors(GetTableDescriptorsRequest)
    returns(GetTableDescriptorsResponse);

  /** Get the list of table names. */
  rpc GetTableNames(GetTableNamesRequest)
    returns(GetTableNamesResponse);

  /** Return cluster status. */
  rpc GetClusterStatus(GetClusterStatusRequest)
    returns(GetClusterStatusResponse);

  /** return true if master is available */
  rpc IsMasterRunning(IsMasterRunningRequest) returns(IsMasterRunningResponse);

  /** Adds a column to the specified table. */
  rpc AddColumn(AddColumnRequest)
    returns(AddColumnResponse);

  /** Deletes a column from the specified table. Table must be disabled. */
  rpc DeleteColumn(DeleteColumnRequest)
    returns(DeleteColumnResponse);

  /** Modifies an existing column on the specified table. */
  rpc ModifyColumn(ModifyColumnRequest)
    returns(ModifyColumnResponse);

  /** Move the region region to the destination server. */
  rpc MoveRegion(MoveRegionRequest)
    returns(MoveRegionResponse);

 /** Master dispatch merging the regions */
  rpc DispatchMergingRegions(DispatchMergingRegionsRequest)
    returns(DispatchMergingRegionsResponse);    

  /** Assign a region to a server chosen at random. */
  rpc AssignRegion(AssignRegionRequest)
    returns(AssignRegionResponse);

  /**
   * Unassign a region from current hosting regionserver.  Region will then be
   * assigned to a regionserver chosen at random.  Region could be reassigned
   * back to the same server.  Use MoveRegion if you want
   * to control the region movement.
   */
  rpc UnassignRegion(UnassignRegionRequest)
    returns(UnassignRegionResponse);

  /**
   * Offline a region from the assignment manager's in-memory state.  The
   * region should be in a closed state and there will be no attempt to
   * automatically reassign the region as in unassign.   This is a special
   * method, and should only be used by experts or hbck.
   */
  rpc OfflineRegion(OfflineRegionRequest)
    returns(OfflineRegionResponse);

  /** Deletes a table */
  rpc DeleteTable(DeleteTableRequest)
    returns(DeleteTableResponse);

  /** Puts the table on-line (only needed if table has been previously taken offline) */
  rpc EnableTable(EnableTableRequest)
    returns(EnableTableResponse);

  /** Take table offline */
  rpc DisableTable(DisableTableRequest)
    returns(DisableTableResponse);

  /** Modify a table's metadata */
  rpc ModifyTable(ModifyTableRequest)
    returns(ModifyTableResponse);

  /** Creates a new table asynchronously */
  rpc CreateTable(CreateTableRequest)
    returns(CreateTableResponse);

    /** Shutdown an HBase cluster. */
  rpc Shutdown(ShutdownRequest)
    returns(ShutdownResponse);

  /** Stop HBase Master only.  Does not shutdown the cluster. */
  rpc StopMaster(StopMasterRequest)
    returns(StopMasterResponse);

  /**
   * Run the balancer.  Will run the balancer and if regions to move, it will
   * go ahead and do the reassignments.  Can NOT run for various reasons.
   * Check logs.
   */
  rpc Balance(BalanceRequest)
    returns(BalanceResponse);

  /**
   * Turn the load balancer on or off.
   * If synchronous is true, it waits until current balance() call, if outstanding, to return.
   */
  rpc SetBalancerRunning(SetBalancerRunningRequest)
    returns(SetBalancerRunningResponse);

  /** Get a run of the catalog janitor */
  rpc RunCatalogScan(RunCatalogScanRequest)
     returns(RunCatalogScanResponse);

  /**
   * Enable the catalog janitor on or off.
   */
  rpc EnableCatalogJanitor(EnableCatalogJanitorRequest)
     returns(EnableCatalogJanitorResponse);

  /**
   * Query whether the catalog janitor is enabled.
   */
  rpc IsCatalogJanitorEnabled(IsCatalogJanitorEnabledRequest)
     returns(IsCatalogJanitorEnabledResponse);

  /**
   * Call a master coprocessor endpoint
   */
  rpc ExecMasterService(CoprocessorServiceRequest)
    returns(CoprocessorServiceResponse);

  /** 
   * Create a snapshot for the given table.
   */
  rpc Snapshot(SnapshotRequest) returns(SnapshotResponse);

  /**
   * Get completed snapshots.
   * Returns a list of snapshot descriptors for completed snapshots
   */
  rpc GetCompletedSnapshots(GetCompletedSnapshotsRequest) returns(GetCompletedSnapshotsResponse);

  /**
   * Delete an existing snapshot. This method can also be used to clean up an aborted snapshot.
   */
  rpc DeleteSnapshot(DeleteSnapshotRequest) returns(DeleteSnapshotResponse);

  /**
   * Determine if the snapshot is done yet.
   */
  rpc IsSnapshotDone(IsSnapshotDoneRequest) returns(IsSnapshotDoneResponse);

  /**
   * Restore a snapshot
   */
  rpc RestoreSnapshot(RestoreSnapshotRequest) returns(RestoreSnapshotResponse);

  /**
   * Determine if the snapshot restore is done yet.
   */
  rpc IsRestoreSnapshotDone(IsRestoreSnapshotDoneRequest) returns(IsRestoreSnapshotDoneResponse);

  /**
   * Execute a distributed procedure.
   */
  rpc ExecProcedure(ExecProcedureRequest) returns(ExecProcedureResponse);

  /**
   * Determine if the procedure is done yet.
   */
  rpc IsProcedureDone(IsProcedureDoneRequest) returns(IsProcedureDoneResponse);

  /** return true if master is available */
  /** rpc IsMasterRunning(IsMasterRunningRequest) returns(IsMasterRunningResponse); */

  /** Modify a namespace's metadata */
  rpc ModifyNamespace(ModifyNamespaceRequest)
    returns(ModifyNamespaceResponse);

  /** Creates a new namespace synchronously */
  rpc CreateNamespace(CreateNamespaceRequest)
    returns(CreateNamespaceResponse);

  /** Deletes namespace synchronously */
  rpc DeleteNamespace(DeleteNamespaceRequest)
    returns(DeleteNamespaceResponse);

  /** Get a namespace descriptor by name */
  rpc GetNamespaceDescriptor(GetNamespaceDescriptorRequest)
    returns(GetNamespaceDescriptorResponse);

  /** returns a list of namespaces */
  rpc ListNamespaceDescriptors(ListNamespaceDescriptorsRequest)
    returns(ListNamespaceDescriptorsResponse);

  /** returns a list of tables for a given namespace*/
  rpc ListTableDescriptorsByNamespace(ListTableDescriptorsByNamespaceRequest)
    returns(ListTableDescriptorsByNamespaceResponse);

  /** returns a list of tables for a given namespace*/
  rpc ListTableNamesByNamespace(ListTableNamesByNamespaceRequest)
    returns(ListTableNamesByNamespaceResponse);
}
