Skip to content

Commit 0041449

Browse files
krisctlPrabhakar Kumar
authored andcommitted
Introduces infrastructure for planned feature development.
There is no functional impact of this change on the product.
1 parent 7b8e6c3 commit 0041449

28 files changed

+2642
-1
lines changed

matlab_proxy_manager/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# MATLAB Proxy Manager
2+
3+
----
4+
This README is intended for MathWorks® developers only.
5+
`matlab-proxy-manager` is part of the `matlab-proxy` package and it helps in managing the lifecycle and proxying of MATLAB proxy processes.
6+
7+
It provides a seamless integration with Jupyter environments, allowing MATLAB to be accessed and controlled via a proxy.
8+
9+
Upon installation, this package introduces an executable `matlab-proxy-manager-app`, which is utilized by the Jupyter Server Proxy to initiate `matlab-proxy-manager`.
10+
11+
----
12+
13+
**Table of Contents**
14+
- [Project Structure](#structure)
15+
- [Installation](#installation)
16+
- [PyPI](#pypi)
17+
- [Building From Sources](#building-from-sources)
18+
- [Usage](#usage)
19+
- [Security](#security)
20+
21+
## Structure
22+
`matlab-proxy-manager` is organized into several key sub-folders:
23+
24+
1. lib:
25+
26+
* This directory contains the library APIs that facilitate the invocation of MATLAB proxy processes. It supports API calls, enabling the MATLAB Kernel to manage proxy instances effectively. For detailed information, refer to the README within the lib folder.
27+
28+
2. storage:
29+
* The file system serves as the source of truth for `matlab-proxy-manager`, storing metadata about each MATLAB proxy server in dedicated files. A new file is generated whenever a proxy instance is launched and is removed upon termination of the instance or deletion of the Kernel that initiated it.
30+
31+
3. web:
32+
* This component handles proxy workflows through HTTP/WebSocket requests, which are part of the executable process spawned by clients using the `matlab-proxy-manager-app`. For specific requirements and constraints, consult the README located in the web folder.
33+
34+
4. utils:
35+
* A collection of helper functions utilized across various parts of the project, ensuring modularity and code reuse.
36+
37+
## Installation
38+
39+
### PyPI
40+
`matlab-proxy-manager` is included in the `matlab-proxy` repository and can be easily installed from the Python Package Index:
41+
42+
```bash
43+
python -m pip install matlab-proxy
44+
```
45+
46+
### Building From Sources
47+
Building from sources requires Node.js® version 16 or higher. [Click here to install Node.js](https://nodejs.org/en/)
48+
49+
```bash
50+
git clone https://github.com/mathworks/matlab-proxy.git
51+
52+
cd matlab-proxy
53+
54+
python -m pip install .
55+
```
56+
57+
Installing the package creates an executable called `matlab-proxy-app`, which is placed onto your system PATH by `pip`, usually in: `$HOME/.local/bin/`
58+
```bash
59+
# Verify its presence on the PATH
60+
which matlab-proxy-manager-app
61+
```
62+
63+
## Usage
64+
`matlab-proxy-manager` can be deployed in two modes:
65+
66+
1. Library Mode: Import the relevant module within your client code to invoke public APIs directly.
67+
68+
Example:
69+
70+
```python
71+
import matlab_proxy_manager.lib.api as mpm_lib
72+
response = await mpm_lib.start_matlab_proxy_for_kernel(...)
73+
await mpm_lib.shutdown(...)
74+
```
75+
76+
2. Process Mode: This mode is primarily managed by Jupyter-Server-Proxy for proxy workflows involving web-based MATLAB desktop access.
77+
78+
## Security
79+
Security is paramount in matlab-proxy-manager. Communication between the Kernel, proxy manager, and Jupyter Server Proxy is secured using authentication tokens. These tokens are mandatory for API invocations and proxy workflows. They are passed via environment variables when the proxy manager is initiated by the Jupyter Server Proxy and are included in the arguments during Kernel API calls.
80+
81+
---
82+
83+
Copyright 2024 The MathWorks, Inc.
84+
85+
---

matlab_proxy_manager/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright 2024 The MathWorks, Inc.
2+
3+
4+
def get_executable_name() -> str:
5+
"""Fetches and returns matlab proxy manager executable name"""
6+
return "matlab-proxy-manager-app"

matlab_proxy_manager/lib/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# MATLAB Proxy Manager - Library
2+
3+
This README is intended for MathWorks® developers only.
4+
`matlab-proxy-manager` module is designed to be flexible and robust, supporting both direct library calls and process-based workflows. The lib folder contains the code blocks providing the core library APIs that facilitate the management of MATLAB proxy instances.
5+
6+
# Key Features
7+
## API Invocation:
8+
9+
The lib module allows for the invocation of MATLAB proxy processes through a well-defined set of APIs. These APIs are designed to be intuitive and easy to integrate into existing workflows, enabling developers to start, stop, and manage MATLAB proxy instances programmatically.
10+
11+
## Integration with MATLAB Kernel:
12+
13+
The APIs in the lib directory are used by the MATLAB Kernel to manage the lifecycle of MATLAB proxy instances. This includes starting new instances and shutting them down when they are no longer needed.
14+
15+
## Error Handling and Logging:
16+
17+
Comprehensive error handling mechanisms are in place to ensure that any issues encountered during the management of proxy instances are logged and reported. This aids in troubleshooting and ensures the reliability of the system.
18+
19+
Users are required to set `MWI_MPM_LOG_LEVEL` environment variable to their desired log level (`INFO`, `DEBUG` etc.) to enable logging in `matlab-proxy-manager`.
20+
21+
# Usage
22+
To use the lib APIs, you can import the relevant module in your Python code and invoke the provided functions. Here’s a basic example of how you might start and stop a MATLAB proxy instance:
23+
24+
```python
25+
26+
import matlab_proxy_manager.lib.api as mpm_lib
27+
28+
# Start a MATLAB proxy instance
29+
response = await mpm_lib.start_matlab_proxy_for_kernel(
30+
caller_id=self.kernel_id,
31+
parent_id=self.parent_pid,
32+
is_isolated_matlab=False,
33+
)
34+
return (
35+
response.get("absolute_url"),
36+
response.get("mwi_base_url"),
37+
response.get("headers"),
38+
response.get("mpm_auth_token"),
39+
)
40+
41+
# Perform operations with the MATLAB instance...
42+
43+
# Shut down the MATLAB proxy instance
44+
await mpm_lib.shutdown(
45+
self.parent_pid, self.kernel_id, self.mpm_auth_token
46+
)
47+
```
48+
49+
---
50+
51+
Copyright 2024 The MathWorks, Inc.
52+
53+
---

matlab_proxy_manager/lib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Copyright 2024 The MathWorks, Inc.

0 commit comments

Comments
 (0)