-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
428 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
react/src/components/ComputeSessionNodeItems/SessionOccupiedSlot.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { convertBinarySizeUnit } from '../../helper'; | ||
import { useResourceSlotsDetails } from '../../hooks/backendai'; | ||
import { SessionOccupiedSlotFragment$key } from './__generated__/SessionOccupiedSlotFragment.graphql'; | ||
import { Divider, Typography } from 'antd'; | ||
import graphql from 'babel-plugin-relay/macro'; | ||
import _ from 'lodash'; | ||
import React from 'react'; | ||
import { useFragment } from 'react-relay'; | ||
|
||
interface OccupiedSlotViewProps { | ||
sessionFrgmt: SessionOccupiedSlotFragment$key; | ||
type: 'cpu' | 'mem' | 'accelerator'; | ||
} | ||
const SessionOccupiedSlot: React.FC<OccupiedSlotViewProps> = ({ | ||
type, | ||
sessionFrgmt, | ||
}) => { | ||
const { deviceMetadata } = useResourceSlotsDetails(); | ||
const session = useFragment( | ||
graphql` | ||
fragment SessionOccupiedSlotFragment on ComputeSessionNode { | ||
id | ||
occupied_slots | ||
} | ||
`, | ||
sessionFrgmt, | ||
); | ||
|
||
const occupiedSlots = JSON.parse(session.occupied_slots || '{}'); | ||
|
||
if (type === 'cpu') { | ||
return occupiedSlots.cpu ?? '-'; | ||
} else if (type === 'mem') { | ||
const mem = occupiedSlots.mem ?? '-'; | ||
return mem === '-' ? mem : convertBinarySizeUnit(mem, 'G')?.number + ' GiB'; | ||
} else if (type === 'accelerator') { | ||
const occupiedAccelerators = _.omit(occupiedSlots, ['cpu', 'mem']); | ||
return _.isEmpty(occupiedAccelerators) | ||
? '-' | ||
: _.map(occupiedAccelerators, (value, key) => { | ||
return ( | ||
<> | ||
<Typography.Text>{value}</Typography.Text> | ||
<Divider type="vertical" /> | ||
<Typography.Text> | ||
{deviceMetadata?.[key]?.human_readable_name} | ||
</Typography.Text> | ||
</> | ||
); | ||
}); | ||
} | ||
}; | ||
|
||
export default SessionOccupiedSlot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
|
||
const ComputeSessionNodeList = () => { | ||
return <div>ComputeSessionNodeList</div>; | ||
}; | ||
|
||
export default ComputeSessionNodeList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import BAILink from './BAILink'; | ||
import BAITable from './BAITable'; | ||
import SessionOccupiedSlot from './ComputeSessionNodeItems/SessionOccupiedSlot'; | ||
import SessionReservation from './ComputeSessionNodeItems/SessionReservation'; | ||
import SessionStatusTag from './ComputeSessionNodeItems/SessionStatusTag'; | ||
import SessionDetailDrawer from './SessionDetailDrawer'; | ||
import { SessionNodesFragment$key } from './__generated__/SessionNodesFragment.graphql'; | ||
import { TableProps } from 'antd/lib'; | ||
import graphql from 'babel-plugin-relay/macro'; | ||
import _ from 'lodash'; | ||
import React, { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useFragment } from 'react-relay'; | ||
|
||
interface SessionNodesProps extends Omit<TableProps, 'dataSource' | 'columns'> { | ||
sessionsFrgmt: SessionNodesFragment$key; | ||
} | ||
const SessionNodes: React.FC<SessionNodesProps> = ({ | ||
sessionsFrgmt, | ||
...tableProps | ||
}) => { | ||
const { t } = useTranslation(); | ||
const [selectedSessionId, setSelectedSessionId] = useState<string>(); | ||
|
||
const sessions = useFragment( | ||
graphql` | ||
fragment SessionNodesFragment on ComputeSessionNode @relay(plural: true) { | ||
id | ||
row_id | ||
name | ||
...SessionStatusTagFragment | ||
...SessionReservationFragment | ||
...SessionOccupiedSlotFragment | ||
} | ||
`, | ||
sessionsFrgmt, | ||
); | ||
|
||
return ( | ||
<> | ||
<BAITable | ||
dataSource={sessions} | ||
columns={[ | ||
{ | ||
key: 'name', | ||
title: t('session.SessionName'), | ||
dataIndex: 'name', | ||
render: (name: string, session) => { | ||
return ( | ||
<BAILink | ||
to={'#'} | ||
type="hover" | ||
onClick={(e) => { | ||
session.row_id && setSelectedSessionId(session.row_id); | ||
}} | ||
> | ||
{name} | ||
</BAILink> | ||
); | ||
}, | ||
sorter: true, | ||
}, | ||
{ | ||
key: 'status', | ||
title: t('session.Status'), | ||
dataIndex: 'status', | ||
render: (status: string, session) => { | ||
// @ts-expect-error | ||
return <SessionStatusTag sessionFrgmt={session} />; | ||
}, | ||
}, | ||
{ | ||
key: 'utils', | ||
title: t('session.Utilization'), | ||
}, | ||
{ | ||
key: 'accelerator', | ||
title: t('session.launcher.AIAccelerator'), | ||
render: (__, session) => { | ||
return ( | ||
<SessionOccupiedSlot | ||
// @ts-expect-error | ||
sessionFrgmt={session} | ||
type="accelerator" | ||
/> | ||
); | ||
}, | ||
}, | ||
{ | ||
key: 'cpu', | ||
title: t('session.launcher.CPU'), | ||
render: (__, session) => { | ||
// @ts-expect-error | ||
return <SessionOccupiedSlot sessionFrgmt={session} type="cpu" />; | ||
}, | ||
}, | ||
{ | ||
key: 'mem', | ||
title: t('session.launcher.Memory'), | ||
render: (__, session) => { | ||
// @ts-expect-error | ||
return <SessionOccupiedSlot sessionFrgmt={session} type="mem" />; | ||
}, | ||
}, | ||
{ | ||
key: 'elapsedTime', | ||
title: t('session.ElapsedTime'), | ||
render: (__, session) => { | ||
return ( | ||
<SessionReservation | ||
mode="simple-elapsed" | ||
// @ts-expect-error | ||
sessionFrgmt={session} | ||
/> | ||
); | ||
}, | ||
}, | ||
]} | ||
{...tableProps} | ||
/> | ||
<SessionDetailDrawer | ||
open={!selectedSessionId} | ||
sessionId={selectedSessionId} | ||
onClose={() => { | ||
setSelectedSessionId(undefined); | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default SessionNodes; |
Oops, something went wrong.