Package titan
Class TitanCLI
java.lang.Object
titan.TitanCLI
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate StringcreateUploadPayload(File file) Creates the payload string for a file upload operation.private voidhandleCommand(String input) Parses a user-provided command string, maps it to the appropriate Titan protocol operation code, and constructs the necessary payload.private voidhandleUpload(String localPath) Handles the 'upload' command.static voidThe main entry point for the Titan CLI application.private voidPrints a list of available commands and their basic usage to the console.private StringsendAndReceive(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.voidstart()Initiates the main command-line interface loop.
-
Field Details
-
host
The hostname or IP address of the Titan scheduler to connect to. -
port
private final int portThe port number of the Titan scheduler to connect to. -
scanner
A `Scanner` object used to read user input from the console.
-
-
Constructor Details
-
TitanCLI
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
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
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
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
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
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).
-