Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
ganning127 committed Jun 25, 2024
1 parent 4d3ae60 commit 161470e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 63 deletions.
36 changes: 3 additions & 33 deletions airavata-local-agent/main/background.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);

Expand All @@ -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();
// }
// }
});
});

Expand All @@ -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();

});
23 changes: 16 additions & 7 deletions airavata-local-agent/renderer/components/ExperimentModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down Expand Up @@ -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: {
Expand All @@ -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);
}
Expand Down Expand Up @@ -488,7 +497,7 @@ const ExperimentModal = ({ activeExperiment, onOpen, onClose, accessToken }) =>

<TextWithBoldKey keyName="Owner" text={experimentData.userName} />

<TextWithBoldKey keyName="Compute Resource ID" text={experimentData.userConfigurationData.computationalResourceScheduling.resourceHostId} />
<TextWithBoldKey keyName="Compute Resource ID" text={getResourceFromId(experimentData.userConfigurationData.computationalResourceScheduling.resourceHostId)} />

<TextWithBoldKey keyName="Queue" text={experimentData.userConfigurationData.computationalResourceScheduling.queueName} />

Expand All @@ -503,7 +512,7 @@ const ExperimentModal = ({ activeExperiment, onOpen, onClose, accessToken }) =>
<Box>
<Text fontWeight='bold'>Jobs</Text>

<TableContainer>
{experimentJobs && experimentJobs.length > 0 && <TableContainer>
<Table variant='simple'>
<Thead>
<Tr>
Expand Down Expand Up @@ -531,7 +540,7 @@ const ExperimentModal = ({ activeExperiment, onOpen, onClose, accessToken }) =>
}
</Tbody>
</Table>
</TableContainer>
</TableContainer>}
</Box>


Expand Down
38 changes: 20 additions & 18 deletions airavata-local-agent/renderer/lib/utilityFuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}


Expand All @@ -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;
};
Expand Down
15 changes: 10 additions & 5 deletions airavata-local-agent/renderer/pages/tabs-view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -596,24 +596,25 @@ const TabsView = () => {
onPageChange={handlePageChange}
>
<TableContainer>
<Table variant='simple'>
<Table variant='simple' >
<Thead>
<Tr>
<Th>Name</Th>
<Th>User</Th>
<Th>Type</Th>
<Th>Application</Th>
<Th>Resource</Th>
<Th>Created</Th>
<Th>Status</Th>
<Th>Actions</Th>
</Tr>
</Thead>
<Tbody>
<Tbody >
{
experiments?.results?.map((experiment) => {
return (
<Tr key={experiment.experimentId} fontSize='sm' alignItems='center'>
<Td>
<Box>
<Box >
<Tooltip label={experiment.experimentId}>
<Text whiteSpace='pre-wrap'
_hover={{
Expand All @@ -638,6 +639,10 @@ const TabsView = () => {
<Text>{getExperimentApplication(experiment.executionId)}</Text>
</Td>

<Td>
<Text >{getResourceFromId(experiment.resourceHostId)}</Text>
</Td>

<Td>
<Tooltip label={new Date(experiment.creationTime).toLocaleString()}><Text>{dayjs(experiment.creationTime).fromNow(true)} ago</Text></Tooltip>
</Td>
Expand Down

0 comments on commit 161470e

Please sign in to comment.