

syntax = "proto3";
package rqd;

option java_package = "com.imageworks.spcue.grpc.rqd";
option java_multiple_files = true;

option go_package = "opencue_gateway/gen/go";

import "report.proto";

// Interface for issuing commands to an RQD instance.

// -------- Services --------]

// Implemented by the Rqd server. Called by cuebot and tools.
service RqdInterface {
    // [Deprecated] Return the RunFrame by id
    rpc GetRunFrame(RqdStaticGetRunFrameRequest) returns (RqdStaticGetRunFrameResponse);

    // Return the RunningFrameStatus report
    rpc GetRunningFrameStatus(RqdStaticGetRunningFrameStatusRequest) returns (RqdStaticGetRunningFrameStatusResponse);

    // Kill the running frame by frame id
    rpc KillRunningFrame(RqdStaticKillRunningFrameRequest) returns (RqdStaticKillRunningFrameResponse);

    // Launch a new running frame
    rpc LaunchFrame(RqdStaticLaunchFrameRequest) returns (RqdStaticLaunchFrameResponse);

    // Lock a number of cores
    rpc Lock(RqdStaticLockRequest) returns (RqdStaticLockResponse);

    // Lock all
    rpc LockAll(RqdStaticLockAllRequest) returns (RqdStaticLockAllResponse);

    // Disable NIMBY on host
    rpc NimbyOff(RqdStaticNimbyOffRequest) returns (RqdStaticNimbyOffResponse);

    // Enable NIMBY on host
    rpc NimbyOn(RqdStaticNimbyOnRequest) returns (RqdStaticNimbyOnResponse);

    // Reboot the host when it becomes idle
    rpc RebootIdle(RqdStaticRebootIdleRequest) returns (RqdStaticRebootIdleResponse);

    // [Deprecated] Reboot the host now
    rpc RebootNow(RqdStaticRebootNowRequest) returns (RqdStaticRebootNowResponse);

    // Return the HostReport
    rpc ReportStatus(RqdStaticReportStatusRequest) returns (RqdStaticReportStatusResponse);

    // [Deprecated] Restart the rqd process when it becomes idle
    rpc RestartRqdIdle(RqdStaticRestartIdleRequest) returns (RqdStaticRestartIdleResponse);

    // [Deprecated] Restart rqd process now
    rpc RestartRqdNow(RqdStaticRestartNowRequest) returns (RqdStaticRestartNowResponse);

    // [Deprecated] Turn off rqd when it becomes idle
    rpc ShutdownRqdIdle(RqdStaticShutdownIdleRequest) returns (RqdStaticShutdownIdleResponse);

    // Stop rqd now
    rpc ShutdownRqdNow(RqdStaticShutdownNowRequest) returns (RqdStaticShutdownNowResponse);

    // Unlock a number of cores
    rpc Unlock(RqdStaticUnlockRequest) returns (RqdStaticUnlockResponse);

    // Unlock all cores
    rpc UnlockAll(RqdStaticUnlockAllRequest) returns (RqdStaticUnlockAllResponse);
}

// Implemented by the Rqd server. Called by cuebot and tools.
service RunningFrame {
    // Kill the provided running frame
    rpc Kill(RunningFrameKillRequest) returns (RunningFrameKillResponse);

    // Get the status of the running frame
    rpc Status(RunningFrameStatusRequest) returns (RunningFrameStatusResponse);
}


// -------- Enums --------]

enum ErrorCode {
    SUCCESS = 0;
    UNKNOWN = 1;
}


// -------- Primary Message Types --------]

message RunFrame {
    string resource_id = 1;
    string job_id = 2;
    string job_name = 3;
    string frame_id = 4;
    string frame_name = 5;
    string layer_id = 6;
    string command = 7;
    string user_name = 8;
    string log_dir = 9;
    string show = 10;
    string shot = 11;
    // Deprecated: Not reliable and will not be taken on consideration moving forward
    string job_temp_dir = 12 [deprecated=true];
    // Deprecated: Not reliable and will not be taken on consideration moving forward
    string frame_temp_dir = 13;
    // Deprecated: The log_path is defined rqd using job_dir, job_name and frame_name.
    // This field is misleading as it doesn't give cuebot the power to define the log path
    string log_file = 14 [deprecated=true];
    // Deprecated: The log_path is defined rqd using job_dir, job_name and frame_name.
    // This field is misleading as it doesn't give cuebot the power to define the log path
    string log_dir_file = 15 [deprecated=true];
    int64 start_time = 16;
    oneof uid_optional {
        int32 uid = 17;
    }
    int32 num_cores = 18;
    int32 gid = 19;
    bool ignore_nimby = 20;
    map<string, string> environment = 21;
    map<string, string> attributes = 22;
    int32 num_gpus = 23;
    report.ChildrenProcStats children = 24;
    string os = 25;
    int64 soft_memory_limit = 26;
    int64 hard_memory_limit = 27;
    int32 pid = 28;
    string loki_url = 29;
}

message RunFrameSeq {
    repeated RunFrame run_frames = 1;
}


// -------- Requests and Responses --------]

// RQD STATIC ----
//GetRunFrame
message RqdStaticGetRunFrameRequest {
    string frame_id = 1;
    string job_id = 2;
    string layer_id = 3;
    int32 run_frame_id = 4;
}

message RqdStaticGetRunFrameResponse {
    RunFrame run_frame = 1;
}

// GetRunningFrameStatus
message RqdStaticGetRunningFrameStatusRequest {
    string frame_id = 1;
}

message RqdStaticGetRunningFrameStatusResponse {
    report.RunningFrameInfo running_frame_info = 1;
}

// KillRunningFrame
message RqdStaticKillRunningFrameRequest {
    string frame_id = 1;
    string message = 2;
}

message RqdStaticKillRunningFrameResponse {}

// LaunchFrame
message RqdStaticLaunchFrameRequest {
    RunFrame run_frame = 1;
}

message RqdStaticLaunchFrameResponse {}

// LockAll
message RqdStaticLockAllRequest {} // Empty

message RqdStaticLockAllResponse {}

// Lock
message RqdStaticLockRequest {
    int32 cores = 1;
}

message RqdStaticLockResponse {}

// NimbyOff
message RqdStaticNimbyOffRequest {} // Empty

message RqdStaticNimbyOffResponse {}

// NimbyOn
message RqdStaticNimbyOnRequest {} // Empty

message RqdStaticNimbyOnResponse {}

// RebootIdle
message RqdStaticRebootIdleRequest {} // Empty

message RqdStaticRebootIdleResponse {}

// RebootNow
message RqdStaticRebootNowRequest {} // Empty

message RqdStaticRebootNowResponse {}

// ReportStatus
message RqdStaticReportStatusRequest {} // Empty

message RqdStaticReportStatusResponse {
    report.HostReport host_report = 1;
}

// RestartIdle
message RqdStaticRestartIdleRequest {}

message RqdStaticRestartIdleResponse {}

// RestartNow
message RqdStaticRestartNowRequest {}

message RqdStaticRestartNowResponse {}

// ShutdownIdle
message RqdStaticShutdownIdleRequest {}

message RqdStaticShutdownIdleResponse {}

// ShutdownNow
message RqdStaticShutdownNowRequest {}

message RqdStaticShutdownNowResponse {}

// Unlock
message RqdStaticUnlockRequest {
    int32 cores = 1;
}

message RqdStaticUnlockResponse {}

// UnlockAll
message RqdStaticUnlockAllRequest {}

message RqdStaticUnlockAllResponse {}

// RUNNING FRAME ----
// Kill
message RunningFrameKillRequest {
    RunFrame run_frame = 1;
    string message = 2;
}

message RunningFrameKillResponse {} // Empty

// Status
message RunningFrameStatusRequest {
    RunFrame run_frame = 1;
}

message RunningFrameStatusResponse {
    report.RunningFrameInfo running_frame_info = 1;
}
