diff --git a/airavata-local-agent/main/background.js b/airavata-local-agent/main/background.js index fc9e19a821..e7f2d3678b 100644 --- a/airavata-local-agent/main/background.js +++ b/airavata-local-agent/main/background.js @@ -1,5 +1,5 @@ import path from 'path'; -import { app, ipcMain, dialog, session, net } from 'electron'; +import { app, ipcMain, dialog, session, BrowserWindow } from 'electron'; const url = require('node:url'); import serve from 'electron-serve'; import { createWindow } from './helpers'; @@ -121,29 +121,11 @@ ipcMain.on('ci-logon-login', async (event) => { }); authWindow.loadURL('https://md.cybershuttle.org/auth/redirect_login/cilogon/'); - authWindow.show(); - /* - setTimeout(async () => { - const tokens = await getToken(url); - if (tokens.length > 0) { - const [accessToken, refreshToken] = tokens; - console.log("Tokens", accessToken, refreshToken); - event.sender.send('ci-logon-success', accessToken, refreshToken); - - // authWindow.loadURL('https://md.cybershuttle.org/auth/redirect_login/cilogon/'); - - } - }, 5000); - */ - // after we hit https://md.cybershuttle.org/auth/callback, once we get the next URL that starts with md.cybershuttle.org, we can send the info back to the user - - let hitUrl = false; authWindow.webContents.on('will-redirect', async (e, url) => { if (url.startsWith("https://md.cybershuttle.org/auth/callback/")) { - // hitUrl = true; - + // hitUrl = true setTimeout(async () => { const tokens = await getToken(url); @@ -157,16 +139,6 @@ ipcMain.on('ci-logon-login', async (event) => { authWindow.hide(); } - - // if (hitUrl && url.startsWith("https://md.cybershuttle.org/")) { - // const tokens = await getToken(url); - - // if (tokens.length > 0) { - // const [accessToken, refreshToken] = tokens; - // event.sender.send('ci-logon-success', accessToken, refreshToken); - // // authWindow.hide(); - // } - // } }); }); @@ -175,12 +147,10 @@ ipcMain.on('show-window', (event, url) => { let window = createWindow(url, { width: 600, height: 500, - 'node-integration': false, + 'node-integration': true, 'web-security': false }); window.loadURL(url); - window.show(); - }); \ No newline at end of file diff --git a/airavata-local-agent/renderer/components/ExperimentModal.jsx b/airavata-local-agent/renderer/components/ExperimentModal.jsx index 13a8f1c2f9..db09cd1d3d 100644 --- a/airavata-local-agent/renderer/components/ExperimentModal.jsx +++ b/airavata-local-agent/renderer/components/ExperimentModal.jsx @@ -10,14 +10,14 @@ import { } from "@chakra-ui/react"; import { useEffect, useRef, useState } from "react"; import { TextWithBoldKey } from "./TextWithBoldKey"; -import { getColorScheme, getRelativeTime } from "../lib/utilityFuncs"; +import { getColorScheme, getExperimentStatusFromNum, getRelativeTime, getResourceFromId } from "../lib/utilityFuncs"; const ExperimentModal = ({ activeExperiment, onOpen, onClose, accessToken }) => { const toast = useToast(); const [experimentData, setExperimentData] = useState(null); const [loading, setLoading] = useState(false); const experimentId = activeExperiment.experimentId; - const experimentStatus = activeExperiment.experimentStatus; + const [experimentStatus, setExperimentStatus] = useState(activeExperiment.experimentStatus); const [experimentOutputs, setExperimentOutputs] = useState([]); const [experimentInputList, setExperimentInputList] = useState([]); const [experimentJobs, setExperimentJobs] = useState([]); @@ -47,6 +47,15 @@ const ExperimentModal = ({ activeExperiment, onOpen, onClose, accessToken }) => setExperimentJobs(data); } + function processExperimentStatus(status) { + // get last status in list + if (!status || status.length === 0) { + return; + } + const lastStatus = status[status.length - 1]; + setExperimentStatus(getExperimentStatusFromNum(lastStatus.state)); + } + async function fetchExperimentData() { const resp = await fetch(`https://md.cybershuttle.org/api/experiments/${experimentId}/?format=json`, { headers: { @@ -60,9 +69,9 @@ const ExperimentModal = ({ activeExperiment, onOpen, onClose, accessToken }) => const data = await resp.json(); try { - // await fetchExperimentOutputFiles(data.experimentOutputs); - // await fetchExperimentInputs(data.experimentInputs); + // don't load inputs and outputs here because it will be too slow await fetchExperimentJobs(); + processExperimentStatus(data.experimentStatus); } catch (e) { console.log(e); } @@ -488,7 +497,7 @@ const ExperimentModal = ({ activeExperiment, onOpen, onClose, accessToken }) => - + @@ -503,7 +512,7 @@ const ExperimentModal = ({ activeExperiment, onOpen, onClose, accessToken }) => Jobs - + {experimentJobs && experimentJobs.length > 0 && @@ -531,7 +540,7 @@ const ExperimentModal = ({ activeExperiment, onOpen, onClose, accessToken }) => }
-
+
}
diff --git a/airavata-local-agent/renderer/lib/utilityFuncs.js b/airavata-local-agent/renderer/lib/utilityFuncs.js index c9907d888e..766e30a782 100644 --- a/airavata-local-agent/renderer/lib/utilityFuncs.js +++ b/airavata-local-agent/renderer/lib/utilityFuncs.js @@ -12,26 +12,23 @@ export function getRelativeTime(timestamp) { return dayjs(timestamp).fromNow(); } -export function getStatusFromNum(num) { - switch (num) { - case 2: - return 'CREATED'; - case 3: - return 'CREATED'; - case 4: - return 'EXECUTING'; - case 2: - return 'COMPLETED'; - case 5: - return 'CANCELING'; - case 6: - return 'CANCELED'; - case 4: - return 'FAILED'; - default: - return 'UNKNOWN'; +export function getExperimentStatusFromNum(num) { + let arr = ['CREATED', + 'VALIDATED', + 'SCHEDULED', + 'LAUNCHED', + 'EXECUTING', + 'CANCELING', + 'CANCELED', + 'COMPLETED', + 'FAILED' + ]; + + if (num < 0 || num >= arr.length) { + return 'UNKNOWN'; } + return arr[num]; } @@ -52,6 +49,11 @@ export const getColorScheme = (status) => { } }; +export const getResourceFromId = (id) => { + if (!id) return ''; + return id.split('_')[0]; +}; + export const truncTextToN = (str, n) => { return (str.length > n) ? str.substr(0, n - 1) + '...' : str; }; diff --git a/airavata-local-agent/renderer/pages/tabs-view.jsx b/airavata-local-agent/renderer/pages/tabs-view.jsx index d0b882b814..656b903e94 100644 --- a/airavata-local-agent/renderer/pages/tabs-view.jsx +++ b/airavata-local-agent/renderer/pages/tabs-view.jsx @@ -20,7 +20,7 @@ import { ModalCloseButton, useDisclosure, } from "@chakra-ui/react"; -import { getColorScheme, truncTextToN } from "../lib/utilityFuncs"; +import { getColorScheme, getResourceFromId, truncTextToN } from "../lib/utilityFuncs"; import { FaHome } from "react-icons/fa"; import { IoClose } from "react-icons/io5"; import { @@ -596,24 +596,25 @@ const TabsView = () => { onPageChange={handlePageChange} > - +
- + + - + { experiments?.results?.map((experiment) => { return ( + +
Name UserTypeApplicationResource Created Status Actions
- + { {getExperimentApplication(experiment.executionId)} + {getResourceFromId(experiment.resourceHostId)} + {dayjs(experiment.creationTime).fromNow(true)} ago