Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89cca7f183 |
@@ -8,38 +8,24 @@ const findValidJSONStrings = (inputStr: string) => {
|
|||||||
const openingBraceIndex = inputStr.indexOf('{', startIndex);
|
const openingBraceIndex = inputStr.indexOf('{', startIndex);
|
||||||
if (openingBraceIndex === -1) break; // No more opening braces
|
if (openingBraceIndex === -1) break; // No more opening braces
|
||||||
|
|
||||||
// find the matching closing brace, ignoring braces inside string
|
let closingBraceIndex = openingBraceIndex;
|
||||||
// literals (e.g. a state_message containing `{`/`}`)
|
|
||||||
let closingBraceIndex = -1;
|
|
||||||
let braceCount = 0;
|
let braceCount = 0;
|
||||||
let inString = false;
|
|
||||||
let escaped = false;
|
|
||||||
|
|
||||||
for (let i = openingBraceIndex; i < inputStr.length; i++) {
|
// find couple of braces
|
||||||
const char = inputStr[i];
|
while (closingBraceIndex < inputStr.length) {
|
||||||
if (inString) {
|
if (inputStr[closingBraceIndex] === '{') {
|
||||||
if (escaped) {
|
|
||||||
escaped = false;
|
|
||||||
} else if (char === '\\') {
|
|
||||||
escaped = true;
|
|
||||||
} else if (char === '"') {
|
|
||||||
inString = false;
|
|
||||||
}
|
|
||||||
} else if (char === '"') {
|
|
||||||
inString = true;
|
|
||||||
} else if (char === '{') {
|
|
||||||
braceCount++;
|
braceCount++;
|
||||||
} else if (char === '}') {
|
} else if (inputStr[closingBraceIndex] === '}') {
|
||||||
braceCount--;
|
braceCount--;
|
||||||
if (braceCount === 0) {
|
|
||||||
closingBraceIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (braceCount === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
closingBraceIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closingBraceIndex === -1) {
|
if (braceCount !== 0) {
|
||||||
// no matching closing brace yet, wait for more data
|
// no matching closing brace
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,11 +37,11 @@ const findValidJSONStrings = (inputStr: string) => {
|
|||||||
try {
|
try {
|
||||||
const parsedData = JSON.parse(jsonString);
|
const parsedData = JSON.parse(jsonString);
|
||||||
validJSONStrings.push(parsedData);
|
validJSONStrings.push(parsedData);
|
||||||
|
startIndex = closingBraceIndex + 1;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// skip the malformed segment instead of breaking, otherwise it jams
|
// mabye invalid JSON
|
||||||
// the buffer and every later event on this stream is lost
|
break;
|
||||||
}
|
}
|
||||||
startIndex = closingBraceIndex + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -43,11 +43,8 @@ export const createAxiosToken = (): CancelTokenSource => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const sliceData = (data: string, loaded: number, loadedSize: any) => {
|
export const sliceData = (data: string, loaded: number, loadedSize: any) => {
|
||||||
// `loaded` is a byte count while `data` is a UTF-16 string; with any
|
|
||||||
// non-ASCII payload the two drift apart, so track consumed characters by
|
|
||||||
// string length only
|
|
||||||
const result = data.slice(loadedSize.current);
|
const result = data.slice(loadedSize.current);
|
||||||
loadedSize.current = data.length;
|
loadedSize.current = loaded;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -163,11 +163,7 @@ const PoolRows: React.FC<PoolRowsProps> = ({
|
|||||||
key={col.dataIndex || col.key}
|
key={col.dataIndex || col.key}
|
||||||
span={spanFor(col.dataIndex)}
|
span={spanFor(col.dataIndex)}
|
||||||
style={{
|
style={{
|
||||||
color: 'var(--ant-color-text-secondary)',
|
color: 'var(--ant-color-text-secondary)'
|
||||||
// CellContent shrinks to its content inside the flex
|
|
||||||
// cell, so its own align class can't center it —
|
|
||||||
// center at the cell level instead.
|
|
||||||
justifyContent: col.align
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CellContent
|
<CellContent
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ const useClusterColumns = (
|
|||||||
span: 3,
|
span: 3,
|
||||||
render: (text: string, record: ClusterListItem) => (
|
render: (text: string, record: ClusterListItem) => (
|
||||||
<>
|
<>
|
||||||
<AutoTooltip ghost title={text} minWidth={20}>
|
<AutoTooltip ghost title={text}>
|
||||||
<span className="text-primary">{record.name}</span>
|
<span className="text-primary">{record.name}</span>
|
||||||
</AutoTooltip>
|
</AutoTooltip>
|
||||||
{record.is_default && (
|
{record.is_default && (
|
||||||
@@ -176,7 +176,6 @@ const useClusterColumns = (
|
|||||||
dataIndex: 'provider',
|
dataIndex: 'provider',
|
||||||
sorter: tableSorter(2),
|
sorter: tableSorter(2),
|
||||||
span: spans.provider,
|
span: spans.provider,
|
||||||
minWidth: 110,
|
|
||||||
render: (value: string) => (
|
render: (value: string) => (
|
||||||
<AutoTooltip ghost minWidth={20}>
|
<AutoTooltip ghost minWidth={20}>
|
||||||
{ProviderLabelMap[value]}
|
{ProviderLabelMap[value]}
|
||||||
@@ -186,7 +185,7 @@ const useClusterColumns = (
|
|||||||
{
|
{
|
||||||
title: intl.formatMessage({ id: 'dashboard.totalgpus' }),
|
title: intl.formatMessage({ id: 'dashboard.totalgpus' }),
|
||||||
dataIndex: 'gpus',
|
dataIndex: 'gpus',
|
||||||
width: 100,
|
span: 2,
|
||||||
sorter: tableSorter(3),
|
sorter: tableSorter(3),
|
||||||
render: (value: number) => <span>{value}</span>
|
render: (value: number) => <span>{value}</span>
|
||||||
},
|
},
|
||||||
@@ -195,15 +194,13 @@ const useClusterColumns = (
|
|||||||
dataIndex: 'models',
|
dataIndex: 'models',
|
||||||
sorter: tableSorter(4),
|
sorter: tableSorter(4),
|
||||||
span: spans.deployments,
|
span: spans.deployments,
|
||||||
maxWidth: 150,
|
|
||||||
render: (value: number) => <span>{value}</span>
|
render: (value: number) => <span>{value}</span>
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({ id: 'resources.nodes' }),
|
title: intl.formatMessage({ id: 'resources.nodes' }),
|
||||||
dataIndex: 'workers',
|
dataIndex: 'workers',
|
||||||
minWidth: 100,
|
|
||||||
maxWidth: 120,
|
|
||||||
sorter: tableSorter(5),
|
sorter: tableSorter(5),
|
||||||
|
span: spans.workers,
|
||||||
render: (value: number, record: ClusterListItem) => (
|
render: (value: number, record: ClusterListItem) => (
|
||||||
<span>
|
<span>
|
||||||
{record.ready_workers} / {record.workers}
|
{record.ready_workers} / {record.workers}
|
||||||
@@ -214,8 +211,6 @@ const useClusterColumns = (
|
|||||||
title: intl.formatMessage({ id: 'common.table.status' }),
|
title: intl.formatMessage({ id: 'common.table.status' }),
|
||||||
dataIndex: 'state',
|
dataIndex: 'state',
|
||||||
span: spans.status,
|
span: spans.status,
|
||||||
minWidth: 80,
|
|
||||||
align: 'center',
|
|
||||||
render: (value: number, record: ClusterListItem) => (
|
render: (value: number, record: ClusterListItem) => (
|
||||||
<StatusTag
|
<StatusTag
|
||||||
statusValue={{
|
statusValue={{
|
||||||
|
|||||||
@@ -116,7 +116,6 @@ const usePoolsColumns = (
|
|||||||
dataIndex: 'replicas',
|
dataIndex: 'replicas',
|
||||||
span: 6,
|
span: 6,
|
||||||
key: 'replicas',
|
key: 'replicas',
|
||||||
align: 'center',
|
|
||||||
editable: {
|
editable: {
|
||||||
valueType: 'number',
|
valueType: 'number',
|
||||||
title: intl.formatMessage({ id: 'models.table.replicas.edit' })
|
title: intl.formatMessage({ id: 'models.table.replicas.edit' })
|
||||||
|
|||||||
@@ -248,13 +248,7 @@ const Models = forwardRef((props, ref) => {
|
|||||||
chunkInstanceRequedtRef.current = setModelInstanceChunkRequest({
|
chunkInstanceRequedtRef.current = setModelInstanceChunkRequest({
|
||||||
url: `${MODEL_INSTANCE_API}`,
|
url: `${MODEL_INSTANCE_API}`,
|
||||||
params: {},
|
params: {},
|
||||||
handler: updateInstanceHandler,
|
handler: updateInstanceHandler
|
||||||
beforeReconnect() {
|
|
||||||
// treat the reconnect snapshot as the new baseline, otherwise
|
|
||||||
// instances deleted while the stream was down linger in the cache
|
|
||||||
// (their DELETE events are never re-sent)
|
|
||||||
cacheInsDataListRef.current = [];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// ignore
|
// ignore
|
||||||
@@ -458,20 +452,6 @@ const Models = forwardRef((props, ref) => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// watch events can still be lost (stream hiccup, reconnect gap); a low
|
|
||||||
// frequency relist keeps the instance cache eventually consistent, so a
|
|
||||||
// missed DELETE event can't leave a stale instance behind for good
|
|
||||||
useEffect(() => {
|
|
||||||
const timer = setInterval(() => {
|
|
||||||
if (!isPageHidden.current) {
|
|
||||||
getAllModelInstances();
|
|
||||||
}
|
|
||||||
}, 60 * 1000);
|
|
||||||
return () => {
|
|
||||||
clearInterval(timer);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const setDisableExpand = useMemoizedFn((record: any) => {
|
const setDisableExpand = useMemoizedFn((record: any) => {
|
||||||
return !record?.replicas;
|
return !record?.replicas;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -153,50 +153,26 @@ const BasicForm: React.FC<BasicFormProps> = (props) => {
|
|||||||
// Use the seed callback (not handleClusterChange) so this auto-pick refreshes
|
// Use the seed callback (not handleClusterChange) so this auto-pick refreshes
|
||||||
// options without firing an evaluate request before a model is selected.
|
// options without firing an evaluate request before a model is selected.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Options derive from clusterList: an empty source list means clusters
|
if (!clusterOptions?.length) {
|
||||||
// are still loading — leave the field alone until they arrive.
|
|
||||||
if (!clusterList?.length) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Scope off the live form value, not the `useWatch` snapshot: the scope
|
|
||||||
// field's default lands in a child effect that flushes before this one,
|
|
||||||
// while the watch still reports the previous render's null — scoping off
|
|
||||||
// the watch would seed a cluster from the unscoped list here and only
|
|
||||||
// re-scope a render later.
|
|
||||||
const liveScopeOrgId = form.getFieldValue('organization_id') ?? null;
|
|
||||||
const scoped = clusterList.filter(
|
|
||||||
(item) =>
|
|
||||||
liveScopeOrgId == null || item.owner_principal_id === liveScopeOrgId
|
|
||||||
);
|
|
||||||
const current = form.getFieldValue('cluster_id');
|
const current = form.getFieldValue('cluster_id');
|
||||||
if (!scoped.length) {
|
const stillValid = clusterOptions.some((c) => c.value === current);
|
||||||
// Clusters are loaded but the picked org owns none. Any leftover
|
|
||||||
// selection points at another org's cluster (seeded before the scope
|
|
||||||
// settled) and would make requests fail with "Cluster not found" —
|
|
||||||
// clear it so the required rule surfaces instead. Create only: an
|
|
||||||
// edit's cluster is existing data, not a seed.
|
|
||||||
if (action === PageAction.CREATE && current != null) {
|
|
||||||
form.setFieldValue('cluster_id', undefined);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const stillValid = scoped.some((c) => c.value === current);
|
|
||||||
if (current != null && stillValid) {
|
if (current != null && stillValid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const next =
|
const next =
|
||||||
scoped.find((c) => c.is_default)?.value ??
|
clusterOptions.find((c) => c.is_default)?.value ??
|
||||||
scoped.find((c) => c.state === ClusterStatusValueMap.Ready)?.value ??
|
clusterOptions.find((c) => c.state === ClusterStatusValueMap.Ready)
|
||||||
scoped[0]?.value ??
|
?.value ??
|
||||||
|
clusterOptions[0]?.value ??
|
||||||
null;
|
null;
|
||||||
if (next == null || next === current) {
|
if (next == null || next === current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
form.setFieldValue('cluster_id', next);
|
form.setFieldValue('cluster_id', next);
|
||||||
onClusterSeed?.(next);
|
onClusterSeed?.(next);
|
||||||
// `clusterOptions` is the re-run trigger for scope changes: it recomputes
|
}, [clusterOptions, form, onClusterSeed]);
|
||||||
// whenever the watched org scope or the cluster list settles.
|
|
||||||
}, [clusterOptions, clusterList, action, form, onClusterSeed]);
|
|
||||||
|
|
||||||
const clusterOptionRender = (option: any) => {
|
const clusterOptionRender = (option: any) => {
|
||||||
const { data } = option;
|
const { data } = option;
|
||||||
|
|||||||
Reference in New Issue
Block a user