Skip to content

Commit fa1bbc0

Browse files
author
Prabhakar Kumar
committed
Contains unsupported experimental feature flags for future development.
1 parent 6e4d14d commit fa1bbc0

File tree

8 files changed

+180
-64
lines changed

8 files changed

+180
-64
lines changed

gui/src/components/App/index.js

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020-2022 The MathWorks, Inc.
1+
// Copyright 2020-2023 The MathWorks, Inc.
22

33
import React, { useState, useCallback, useEffect, useMemo } from 'react';
44
import { useSelector, useDispatch } from 'react-redux';
@@ -14,20 +14,22 @@ import Information from '../Information';
1414
import Help from '../Help';
1515
import Error from '../Error';
1616
import {
17-
selectOverlayVisible,
18-
selectFetchStatusPeriod,
19-
selectHasFetchedServerStatus,
20-
selectLicensingProvided,
21-
selectMatlabUp,
22-
selectError,
23-
selectLoadUrl,
24-
selectIsConnectionError,
25-
selectHasFetchedEnvConfig,
26-
selectAuthEnabled,
27-
selectIsAuthenticated,
28-
selectLicensingMhlmHasEntitlements,
29-
selectIsEntitled,
30-
selectLicensingInfo,
17+
selectOverlayVisible,
18+
selectFetchStatusPeriod,
19+
selectHasFetchedServerStatus,
20+
selectLicensingProvided,
21+
selectMatlabUp,
22+
selectError,
23+
selectLoadUrl,
24+
selectIsConnectionError,
25+
selectHasFetchedEnvConfig,
26+
selectAuthEnabled,
27+
selectIsAuthenticated,
28+
selectLicensingMhlmHasEntitlements,
29+
selectIsEntitled,
30+
selectLicensingInfo,
31+
selectUseMOS,
32+
selectUseMRE,
3133
} from "../../selectors";
3234

3335
import {
@@ -56,17 +58,34 @@ function App() {
5658
const isAuthenticated = useSelector(selectIsAuthenticated)
5759
const authEnabled = useSelector(selectAuthEnabled);
5860
const licensingInfo = useSelector(selectLicensingInfo);
61+
const useMOS = useSelector(selectUseMOS);
62+
const useMRE = useSelector(selectUseMRE);
5963

6064
const baseUrl = useMemo(() => {
61-
const url = document.URL
65+
const url = document.URL
6266
return url.split(window.location.origin)[1].split('index.html')[0]
6367
}, [])
64-
65-
const parseQueryParams = (url) => {
68+
69+
const parseQueryParams = (url) => {
6670
const queryParams = new URLSearchParams(url.search);
6771
return queryParams;
6872
}
6973

74+
const fullyQualifiedUrl = useMemo(() => {
75+
// Returns the Fully Qualified URL used to load the page.
76+
const url = document.URL
77+
let baseUrlStr = url.split('/index.html')[0]
78+
return baseUrlStr;
79+
}, [])
80+
81+
const htmlToRenderMATLAB = () => {
82+
let theHtmlToRenderMATLAB = useMOS ? "index-matlabonlineserver.html" : 'index-jsd-cr.html'
83+
if (useMRE) {
84+
theHtmlToRenderMATLAB += `?mre=${fullyQualifiedUrl}`
85+
}
86+
return theHtmlToRenderMATLAB
87+
}
88+
7089
const toggleOverlayVisible = useCallback(
7190
() => dispatch(setOverlayVisibility(!overlayVisible)),
7291
[overlayVisible, dispatch]
@@ -137,42 +156,42 @@ function App() {
137156
// Periodic fetch server status
138157
useInterval(() => {
139158
dispatch(fetchServerStatus());
140-
}, fetchStatusPeriod);
159+
}, fetchStatusPeriod);
141160

142161
// Load URL
143-
useEffect(() => {
162+
useEffect(() => {
144163
if (loadUrl !== null) {
145164
window.location.href = loadUrl;
146165
}
147166
}, [loadUrl]);
148167

149168
useEffect(() => {
150169
const queryParams = parseQueryParams(window.location);
151-
const token = queryParams.get("mwi_auth_token");
170+
const token = queryParams.get("mwi_auth_token");
152171

153-
if(token){
154-
dispatch(updateAuthStatus(token));
172+
if (token) {
173+
dispatch(updateAuthStatus(token));
155174
}
156-
window.history.replaceState(null, '', `${baseUrl}index.html`);
175+
window.history.replaceState(null, '', `${baseUrl}index.html`);
157176
}, [dispatch, baseUrl]);
158-
177+
159178
// Display one of:
160179
// * Confirmation
161180
// * Help
162181
// * Error
163182
// * License gatherer
164183
// * License selector
165184
// * Status Information
166-
let overlayContent;
185+
let overlayContent;
167186

168187
if (dialog) {
169188
// TODO Inline confirmation component build
170189
overlayContent = dialog;
171-
}
190+
}
172191
// Give precedence to token auth over licensing info ie. once after token auth is done, show licensing if not provided.
173-
else if((!licensingProvided) && hasFetchedServerStatus && (!authEnabled || isAuthenticated)) {
192+
else if ((!licensingProvided) && hasFetchedServerStatus && (!authEnabled || isAuthenticated)) {
174193
overlayContent = <LicensingGatherer role="licensing" aria-describedby="license-window" />;
175-
}
194+
}
176195
// Show license selector if the user has entitlements and is not currently entitled
177196
else if (hasEntitlements && !isEntitled) {
178197
overlayContent = <EntitlementSelector options={licensingInfo.entitlements} />;
@@ -192,19 +211,23 @@ function App() {
192211
</Overlay>
193212
) : null;
194213

214+
195215
// FIXME Until https://github.com/http-party/node-http-proxy/issues/1342
196216
// is addressed, use a direct URL in development mode. Once that is
197217
// fixed, the request will be served by the fake MATLAB Embedded Connector
198218
// process in development mode
219+
220+
// MW Internal Comment: See g2992889 for a discussion on why a FQDN is required in the MRE parameter.
221+
// MW Internal Comment: Using websocket on breaks some UI components : `./index-matlabonlineserver.html?websocket=on&mre=${fullyQualifiedUrl}`;
199222
const matlabUrl = process.env.NODE_ENV === 'development'
200223
? 'http://localhost:31515/index-jsd-cr.html'
201-
: './index-jsd-cr.html';
224+
: `./${htmlToRenderMATLAB()}`;
202225

203226
let matlabJsd = null;
204-
if(matlabUp){
205-
matlabJsd = (!authEnabled || isAuthenticated)
206-
? ( <MatlabJsd url={matlabUrl} /> )
207-
: <img style={{objectFit: 'fill'}}src={blurredBackground} alt='Blurred MATLAB environment'/>
227+
if (matlabUp) {
228+
matlabJsd = (!authEnabled || isAuthenticated)
229+
? (<MatlabJsd url={matlabUrl} />)
230+
: <img style={{ objectFit: 'fill' }} src={blurredBackground} alt='Blurred MATLAB environment' />
208231
}
209232

210233
const overlayTrigger = overlayVisible ? null : <OverlayTrigger />;

gui/src/reducers/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ export function authEnabled(state = false, action) {
3535
}
3636
}
3737

38+
// Stores information on whether to use MOS HTML while rendering MATLAB.
39+
export function useMOS(state = false, action) {
40+
switch (action.type) {
41+
case RECEIVE_ENV_CONFIG:
42+
return action.config.useMOS;
43+
default:
44+
return state;
45+
}
46+
}
47+
48+
// Stores information on whether to provide MRE parameter to HTML while rendering MATLAB.
49+
export function useMRE(state = false, action) {
50+
switch (action.type) {
51+
case RECEIVE_ENV_CONFIG:
52+
return action.config.useMRE;
53+
default:
54+
return state;
55+
}
56+
}
57+
3858
// Stores status of token authentication.
3959
export function authStatus(state = false, action) {
4060
switch (action.type) {
@@ -251,7 +271,7 @@ export function envConfig(state = null, action) {
251271
case RECEIVE_ENV_CONFIG:
252272
// Token authentication info is also sent as a response to /get_env_config endpoint.
253273
// As its already stored in 'authStatus', 'authEnabled' and 'authToken', ignoring it in envConfig.
254-
const { authStatus, authEnabled, ...envConfig } = action.config
274+
const { authStatus, authEnabled, useMOS, useMRE, ...envConfig } = action.config
255275
return envConfig
256276
default:
257277
return state;
@@ -284,4 +304,6 @@ export default combineReducers({
284304
error,
285305
envConfig,
286306
authInfo,
307+
useMOS,
308+
useMRE,
287309
});

gui/src/selectors/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const selectError = state => state.error;
1515
export const selectAuthEnabled = state => state.authInfo.authEnabled;
1616
export const selectAuthToken = state => state.authInfo.authToken;
1717
export const selectIsAuthenticated = state => state.authInfo.authStatus === true;
18+
export const selectUseMOS = state => state.useMOS === true;
19+
export const selectUseMRE = state => state.useMRE === true;
1820

1921
export const selectTriggerPosition = createSelector(
2022
state => state.triggerPosition,

matlab_proxy/app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ async def get_env_config(req):
152152
config = state.settings["env_config"]
153153
config["authEnabled"] = state.settings["mwi_is_token_auth_enabled"]
154154

155+
config["useMOS"] = mwi_env.Experimental.should_use_mos_html()
156+
config["useMRE"] = mwi_env.Experimental.should_use_mre_html()
157+
155158
# In a previously authenticated session, if the url is accessed without the token(using session cookie), send the token as well.
156159
config["authStatus"] = True if await token_auth.authenticate_request(req) else False
157160
return web.json_response(config)

matlab_proxy/app_state.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,18 @@ async def __setup_env_for_matlab(self) -> dict:
679679
# The mwi_logs_dir is where MATLAB will write any subsequent logs
680680
matlab_env["MATLAB_LOG_DIR"] = str(self.mwi_logs_dir)
681681

682+
# Set MW_CONNECTOR_CONTEXT_ROOT for MPA
683+
if mwi_env.Experimental.is_mpa_enabled():
684+
matlab_env["MW_CONNECTOR_CONTEXT_ROOT"] = self.settings.get("base_url", "/")
685+
logger.info(
686+
f"MW_CONNECTOR_CONTEXT_ROOT is set to: {matlab_env['MW_CONNECTOR_CONTEXT_ROOT']}"
687+
)
688+
689+
# Setup Simulink Online which requires a pre-warm stage
690+
if mwi_env.Experimental.is_simulink_enabled():
691+
logger.info("Enabling usage of Simulink Online...")
692+
matlab_env["PREWARM_SIMULINK"] = "true"
693+
682694
# Env setup related to logging
683695
# Very verbose logging in debug mode
684696
if logger.isEnabledFor(logging.getLevelName("DEBUG")):

matlab_proxy/settings.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,14 @@ def get_matlab_settings():
369369
f"Set {mwi_env.get_env_name_custom_matlab_root()} to a valid MATLAB root path"
370370
)
371371

372+
mpa_flags = (
373+
mwi_env.Experimental.get_mpa_flags()
374+
if mwi_env.Experimental.is_mpa_enabled()
375+
else ""
376+
)
377+
profile_matlab_startup = (
378+
"-timing" if mwi_env.Experimental.is_matlab_startup_profiling_enabled() else ""
379+
)
372380
return {
373381
"matlab_path": matlab_root_path,
374382
"matlab_version": matlab_version,
@@ -377,7 +385,10 @@ def get_matlab_settings():
377385
"-nosplash",
378386
*flag_to_hide_desktop,
379387
"-softwareopengl",
388+
# " v=mvm ",
380389
*matlab_lic_mode,
390+
*mpa_flags,
391+
profile_matlab_startup,
381392
"-r",
382393
f"try; run('{matlab_startup_file}'); catch ME; disp(ME.message); end;",
383394
],

0 commit comments

Comments
 (0)