API Reference

Apart from the CLI, which is meant to be an easy to use orchestration module for GRID sessions, the Enterprise also allows you to interact directly with GRID APIs to start/stop sessions. This section provides a detailed reference for the GRID Enterprise's GRIDSessionManager class, which manages user sessions, including session creation, management, and termination. Below is a description of the class methods and their usage.

GRIDSessionManager Class

The GRIDSessionManager class handles session management for users, including generating JWT tokens, starting and stopping sessions, and listing active sessions.

Initialization

def __init__(self, user_id: str, resource_config_file_path: str) -> None:

Initializes a GRIDSessionManager instance.

  • Parameters:
    • user_id (str): The ID of the user initiating the session.

    • resource_config_file_path (str): Path to the resource configuration file containing tokens and resource details.

  • Raises:
    • ValueError: If the configuration file does not contain 'tokens' or 'resources'.

Method: create_config

def create_config(self, session_config_file_path: str, session_id: str) -> Dict:

Creates a session configuration dictionary based on the provided session configuration file.

  • Parameters:
    • session_config_file_path (str): Path to the session configuration file containing AirGen and GRID settings.

    • session_id (str): The unique identifier for the session.

  • Returns:
    • Dict: A dictionary containing the combined session configuration.

  • Raises:
    • ValueError: If the session configuration file does not contain 'airgen' or 'grid' settings.

Method: start_session

async def start_session(self, session_id: str, resource: str, session_config_file_path: str) -> Optional[bool]:

Starts a new session by sending a request to the specified resource node.

  • Parameters:
    • session_id (str): The unique identifier for the session.

    • resource (str): The resource node to use for the session.

    • session_config_file_path (str): Path to the session configuration file.

  • Returns:
    • Optional[bool]: True if the session was started successfully, False if it failed, or None if the resource is not found or a request error occurs.

Method: stop_session

async def stop_session(self, session_id: str) -> bool:

Stops an active session by sending a termination request to the associated resource node.

  • Parameters:
    • session_id (str): The unique identifier for the session to be stopped.

  • Returns:
    • bool: True if the session was stopped successfully, False otherwise.

Method: list_sessions

async def list_sessions(self) -> List[Dict]:

Lists all active sessions, providing details such as session ID, node IP, and last active time.

  • Returns:
    • List[Dict]: A list of dictionaries containing session details, or an empty list if no active sessions are found.

Usage Examples

Below are examples of how to use the GRIDSessionManager class.

Creating an Instance:

manager = GRIDSessionManager(user_id="user123", resource_config_file_path="path/to/resource_config.json")

Starting a Session:

await manager.start_session(session_id="session_001", resource="node0", session_config_file_path="path/to/session_config.json")

Stopping a Session:

await manager.stop_session(session_id="session_001")

Listing Active Sessions:

await manager.list_sessions()