Package titan

Class TitanCLI

java.lang.Object
titan.TitanCLI

public class TitanCLI extends Object
The `TitanCLI` class provides a command-line interface for interacting with the Titan Distributed Orchestrator. It allows users to send commands such as uploading files, deploying services, running scripts, viewing cluster statistics, and managing worker nodes to a remote Titan scheduler.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final String
    The hostname or IP address of the Titan scheduler to connect to.
    private final int
    The port number of the Titan scheduler to connect to.
    private final Scanner
    A `Scanner` object used to read user input from the console.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TitanCLI(String host, int port)
    Constructs a new `TitanCLI` instance, initializing it with the target host and port of the Titan scheduler.
  • Method Summary

    Modifier and Type
    Method
    Description
    private String
    Creates the payload string for a file upload operation.
    private void
    Parses a user-provided command string, maps it to the appropriate Titan protocol operation code, and constructs the necessary payload.
    private void
    handleUpload(String localPath)
    Handles the 'upload' command.
    static void
    main(String[] args)
    The main entry point for the Titan CLI application.
    private void
    Prints a list of available commands and their basic usage to the console.
    private String
    sendAndReceive(byte opCode, String payload)
    Establishes a socket connection to the Titan scheduler, sends a command with the specified operation code and payload, and then waits for and returns the server's response.
    void
    Initiates the main command-line interface loop.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • host

      private final String host
      The hostname or IP address of the Titan scheduler to connect to.
    • port

      private final int port
      The port number of the Titan scheduler to connect to.
    • scanner

      private final Scanner scanner
      A `Scanner` object used to read user input from the console.
  • Constructor Details

    • TitanCLI

      public TitanCLI(String host, int port)
      Constructs a new `TitanCLI` instance, initializing it with the target host and port of the Titan scheduler.
      Parameters:
      host - The hostname or IP address of the Titan scheduler.
      port - The port number of the Titan scheduler.
  • Method Details

    • printHelp

      private void printHelp()
      Prints a list of available commands and their basic usage to the console. This method is called when the user types 'help'.
    • start

      public void start()
      Initiates the main command-line interface loop. It displays a welcome message, connection details, and then continuously prompts the user for commands until 'exit' is entered. User input is processed by the `handleCommand` method.
    • handleCommand

      private void handleCommand(String input)
      Parses a user-provided command string, maps it to the appropriate Titan protocol operation code, and constructs the necessary payload. It then sends the command to the Titan scheduler and prints the response. Supported commands include `stats`, `upload`, `submit`, `dag`, `run`, `deploy`, `stop`, and `shutdown`.
      Parameters:
      input - The raw command string entered by the user.
    • handleUpload

      private void handleUpload(String localPath)
      Handles the 'upload' command. It reads the specified local file, encodes its content, creates an upload payload, and sends it to the Titan scheduler using the `OP_UPLOAD_ASSET` operation code.
      Parameters:
      localPath - The path to the local file to be uploaded.
    • createUploadPayload

      private String createUploadPayload(File file) throws IOException
      Creates the payload string for a file upload operation. The payload consists of the file's name followed by its Base64-encoded content, separated by a pipe (`|`).
      Parameters:
      file - The `File` object representing the local file to be uploaded.
      Returns:
      A string formatted as "FILENAME|BASE64_CONTENT" suitable for the upload payload.
      Throws:
      FileNotFoundException - If the specified file does not exist.
      IOException - If an I/O error occurs during file reading.
    • sendAndReceive

      private String sendAndReceive(byte opCode, String payload)
      Establishes a socket connection to the Titan scheduler, sends a command with the specified operation code and payload, and then waits for and returns the server's response.
      Parameters:
      opCode - The byte representing the Titan protocol operation code (e.g., `TitanProtocol.OP_STATS`).
      payload - The string payload associated with the command.
      Returns:
      The payload string received from the server as a response, or an error message if the connection fails or a protocol error occurs.
    • main

      public static void main(String[] args)
      The main entry point for the Titan CLI application. It creates a new `TitanCLI` instance connected to `localhost:9090` and starts the command-line interface.
      Parameters:
      args - Command-line arguments (not currently used).