Skip to content

Commit

Permalink
fix: only calculate remaining resources if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
lizable committed Aug 2, 2024
1 parent 8dbd255 commit db4f228
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
16 changes: 13 additions & 3 deletions react/src/components/AgentSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ import { useLazyLoadQuery } from 'react-relay';
interface Props extends SelectProps {
autoSelectDefault?: boolean;
fetchKey?: string;
resourceGroup?: string | null;
}

const AgentSelector: React.FC<Props> = ({ fetchKey, ...selectProps }) => {
const AgentSelector: React.FC<Props> = ({
fetchKey,
resourceGroup,
...selectProps
}) => {
const { t } = useTranslation();
const [value, setValue] = useControllableValue(selectProps);

Expand All @@ -31,12 +36,14 @@ const AgentSelector: React.FC<Props> = ({ fetchKey, ...selectProps }) => {
$offset: Int!
$status: String
$filter: String
$scaling_group: String
) {
agent_summary_list(
limit: $limit
offset: $offset
status: $status
filter: $filter
scaling_group: $scaling_group
) {
items {
id
Expand All @@ -55,6 +62,7 @@ const AgentSelector: React.FC<Props> = ({ fetchKey, ...selectProps }) => {
offset: baiPaginationOption.offset,
status: 'ALIVE',
filter: 'schedulable is true', // true, false, null
scaling_group: resourceGroup,
},
{
fetchPolicy: 'network-only',
Expand All @@ -74,9 +82,9 @@ const AgentSelector: React.FC<Props> = ({ fetchKey, ...selectProps }) => {
} = _.chain(availableSlotsInfo)
.mapValues((value, key) => {
if (key.endsWith('.shares')) {
return parseFloat(value) - parseFloat(occupiedSlotsInfo[key]);
return parseFloat(value) - parseFloat(occupiedSlotsInfo[key] ?? 0);
} else {
return parseInt(value) - parseInt(occupiedSlotsInfo[key]);
return parseInt(value) - parseInt(occupiedSlotsInfo[key] ?? 0);
}
})
.value();
Expand All @@ -103,6 +111,8 @@ const AgentSelector: React.FC<Props> = ({ fetchKey, ...selectProps }) => {
};
});

console.log(agentOptions);

return (
<Select
onChange={(value, option) => {
Expand Down
2 changes: 2 additions & 0 deletions react/src/components/ResourceAllocationFormItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface ResourceAllocationFormValue {
cluster_size: number;
enabledAutomaticShmem: boolean;
allocationPreset?: string;
agent?: string;
}

type MergedResourceAllocationFormValue = ResourceAllocationFormValue &
Expand Down Expand Up @@ -1145,6 +1146,7 @@ const ResourceAllocationFormItems: React.FC<
<Flex gap={'xs'}>
<Form.Item required noStyle style={{ flex: 1 }} name="agent">
<AgentSelector
resourceGroup={currentResourceGroup}
fetchKey={agentFetchKey}
onChange={(value, option) => {
if (value !== 'auto') {
Expand Down
4 changes: 4 additions & 0 deletions react/src/pages/SessionLauncherPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ interface SessionConfig {
startsAt?: string;
startupCommand?: string;
bootstrap_script?: string;
agent_list?: string;
}

interface CreateSessionInfo {
Expand Down Expand Up @@ -452,6 +453,9 @@ const SessionLauncherPage = () => {
..._.omit(values.hpcOptimization, 'autoEnabled'),
},
preopen_ports: transformPortValuesToNumbers(values.ports),
...(!baiClient?._config?.hideAgents && values.agent !== 'auto'
? { agent_list: values.agent }
: undefined),
},
};

Expand Down

0 comments on commit db4f228

Please sign in to comment.