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 Nov 5, 2024
1 parent 76d3820 commit b1f9d48
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
20 changes: 15 additions & 5 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 @@ -65,18 +73,18 @@ const AgentSelector: React.FC<Props> = ({ fetchKey, ...selectProps }) => {
const agentOptions = _.map(agent_summary_list?.items, (agent) => {
const availableSlotsInfo: {
[key in string]: string;
} = JSON.parse(agent?.available_slots);
} = JSON.parse(agent?.available_slots ?? '{}');
const occupiedSlotsInfo: {
[key in string]: string;
} = JSON.parse(agent?.occupied_slots);
} = JSON.parse(agent?.occupied_slots ?? '{}');
const remainingSlotsInfo: {
[key in string]: number;
} = _.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
1 change: 1 addition & 0 deletions react/src/components/ResourceAllocationFormItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,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
5 changes: 5 additions & 0 deletions react/src/pages/SessionLauncherPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ interface SessionConfig {
startsAt?: string;
startupCommand?: string;
bootstrap_script?: string;
agent_list?: string;
}

interface CreateSessionInfo {
Expand Down Expand Up @@ -491,6 +492,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 Expand Up @@ -1826,6 +1830,7 @@ const SessionLauncherPage = () => {
command: undefined,
scheduleDate: undefined,
},
agent: 'auto', // Add the missing 'agent' property
} as Omit<
Required<OptionalFieldsOnly<SessionLauncherFormValue>>,
'autoMountedFolderNames'
Expand Down

0 comments on commit b1f9d48

Please sign in to comment.