@milabench/bujang 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +12 -1
- package/dist/components/SshConnectDialog.d.ts +31 -0
- package/dist/index.js +4345 -4114
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +35 -1
- package/package.json +1 -1
- package/src/api.ts +40 -0
- package/src/components/SshConnectDialog.tsx +382 -0
- package/src/types.ts +39 -1
- package/src/views/JanitorView.tsx +10 -7
- package/src/views/JobSubmit.tsx +7 -2
- package/src/views/JobsView.tsx +5 -62
package/dist/types.d.ts
CHANGED
|
@@ -733,6 +733,39 @@ export interface SshTestResponse {
|
|
|
733
733
|
file: string | null;
|
|
734
734
|
results: SshCheckResult[];
|
|
735
735
|
}
|
|
736
|
+
/** An ssh login started from the UI (POST /ssh/login): ssh's prompts (MFA, password, host key) come back here */
|
|
737
|
+
export type SshLoginState = 'starting' | 'prompt' | 'waiting' | 'ok' | 'failed' | 'cancelled';
|
|
738
|
+
export interface SshLogin {
|
|
739
|
+
id: string;
|
|
740
|
+
host: string;
|
|
741
|
+
cluster: string | null;
|
|
742
|
+
state: SshLoginState;
|
|
743
|
+
/** the prompt waiting for an answer (state "prompt") */
|
|
744
|
+
prompt: string | null;
|
|
745
|
+
/** secret: masked input; confirm: a yes / no question (host key) */
|
|
746
|
+
kind: 'secret' | 'confirm' | null;
|
|
747
|
+
/** what ssh printed so far: the instructions of the server (Duo menu, ...) */
|
|
748
|
+
info: string[];
|
|
749
|
+
message: string;
|
|
750
|
+
prompts: number;
|
|
751
|
+
started: number;
|
|
752
|
+
finished: number | null;
|
|
753
|
+
}
|
|
754
|
+
/** GET /ssh/connections: the ssh hosts of the clusters and their shared connection (ControlMaster) */
|
|
755
|
+
export interface SshConnection {
|
|
756
|
+
host: string;
|
|
757
|
+
cluster: string;
|
|
758
|
+
/** the login node of the cluster (else an ssh executor host: data mover) */
|
|
759
|
+
login_node: boolean;
|
|
760
|
+
/** open: connected; no: not connected; none: the ssh config keeps no shared connection for the host */
|
|
761
|
+
master: 'open' | 'no' | 'none';
|
|
762
|
+
login: SshLogin | null;
|
|
763
|
+
}
|
|
764
|
+
export interface SshConnections {
|
|
765
|
+
writable: boolean;
|
|
766
|
+
read_only_reason: string | null;
|
|
767
|
+
hosts: SshConnection[];
|
|
768
|
+
}
|
|
736
769
|
/** GET /update: the running version against the latest release on PyPI (checked once a day). */
|
|
737
770
|
export interface UpdateCheck {
|
|
738
771
|
/** BUJANG_UPDATE_CHECK=0 turns the check off */
|
|
@@ -825,7 +858,8 @@ export interface SyncStatus {
|
|
|
825
858
|
/** seconds between two background syncs, null when the server does not run them */
|
|
826
859
|
interval: number | null;
|
|
827
860
|
jobs: number;
|
|
828
|
-
synced
|
|
861
|
+
/** per cluster: true synced, false failed, 'recent': not asked, a full rsync ran less than min_refresh_interval ago */
|
|
862
|
+
synced?: Record<string, boolean | 'recent'>;
|
|
829
863
|
skipped?: string;
|
|
830
864
|
}
|
|
831
865
|
export type JanitorStatus = 'ok' | 'failed' | 'timeout' | 'skipped';
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -41,6 +41,8 @@ import type {
|
|
|
41
41
|
SshPlan,
|
|
42
42
|
SshPlanRequest,
|
|
43
43
|
SshTestResponse,
|
|
44
|
+
SshConnections,
|
|
45
|
+
SshLogin,
|
|
44
46
|
JobAttachment,
|
|
45
47
|
JanitorOverview,
|
|
46
48
|
JanitorRun,
|
|
@@ -642,6 +644,44 @@ export const testSshConnections = async (
|
|
|
642
644
|
};
|
|
643
645
|
|
|
644
646
|
|
|
647
|
+
/** The ssh hosts of the clusters and whether their shared connection is open (local check, fast). */
|
|
648
|
+
export const getSshConnections = async (cluster?: string): Promise<SshConnections> => {
|
|
649
|
+
try {
|
|
650
|
+
const response = await api.get('/ssh/connections', { params: { cluster: cluster || undefined } });
|
|
651
|
+
return response.data;
|
|
652
|
+
} catch (error) { return handleError(error); }
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
/** Open the shared connection of a host (or of the login node of `cluster`); poll getSshLogin for the prompts. */
|
|
656
|
+
export const startSshLogin = async (request: { host?: string; cluster?: string }): Promise<SshLogin> => {
|
|
657
|
+
try {
|
|
658
|
+
const response = await api.post('/ssh/login', request);
|
|
659
|
+
return response.data;
|
|
660
|
+
} catch (error) { return handleError(error); }
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
export const getSshLogin = async (id: string): Promise<SshLogin> => {
|
|
664
|
+
try {
|
|
665
|
+
const response = await api.get(`/ssh/login/${encodeURIComponent(id)}`);
|
|
666
|
+
return response.data;
|
|
667
|
+
} catch (error) { return handleError(error); }
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
/** The answer of the waiting prompt (MFA passcode, ...): handed to ssh, never stored. */
|
|
671
|
+
export const answerSshLogin = async (id: string, answer: string): Promise<SshLogin> => {
|
|
672
|
+
try {
|
|
673
|
+
const response = await api.post(`/ssh/login/${encodeURIComponent(id)}/answer`, { answer });
|
|
674
|
+
return response.data;
|
|
675
|
+
} catch (error) { return handleError(error); }
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
export const cancelSshLogin = async (id: string): Promise<SshLogin> => {
|
|
679
|
+
try {
|
|
680
|
+
const response = await api.post(`/ssh/login/${encodeURIComponent(id)}/cancel`, {});
|
|
681
|
+
return response.data;
|
|
682
|
+
} catch (error) { return handleError(error); }
|
|
683
|
+
};
|
|
684
|
+
|
|
645
685
|
// Pipeline template file management (matching server endpoints)
|
|
646
686
|
export const getPipelineTemplatesList = async (): Promise<string[]> => {
|
|
647
687
|
try {
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Badge, Box, Button, Code, Dialog, HStack, IconButton, Input, Spinner, Table, Text, VStack } from '@chakra-ui/react';
|
|
3
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { LuCircleCheck, LuCircleX, LuEye, LuEyeOff, LuPlug } from 'react-icons/lu';
|
|
5
|
+
import { answerSshLogin, cancelSshLogin, getSshConnections, getSshLogin, startSshLogin } from '../api';
|
|
6
|
+
import type { ApiError, SshConnection, SshConnections, SshLogin } from '../types';
|
|
7
|
+
import { toaster } from '../toast';
|
|
8
|
+
|
|
9
|
+
export const SSH_CONNECTIONS_KEY = ['ssh-connections'];
|
|
10
|
+
|
|
11
|
+
const ACTIVE = ['starting', 'prompt', 'waiting'];
|
|
12
|
+
|
|
13
|
+
const errorMessage = (error: unknown) => (error as ApiError)?.message || String(error);
|
|
14
|
+
|
|
15
|
+
const inputStyle = {
|
|
16
|
+
bg: 'var(--color-input-bg)',
|
|
17
|
+
borderColor: 'var(--color-input-border)',
|
|
18
|
+
color: 'var(--color-text)',
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
/** The state of a host's shared connection as a badge */
|
|
22
|
+
export const MasterBadge: React.FC<{ master: SshConnection['master'] }> = ({ master }) => {
|
|
23
|
+
if (master === 'open') return <Badge colorPalette="green" variant="subtle">connected</Badge>;
|
|
24
|
+
if (master === 'none') {
|
|
25
|
+
return (
|
|
26
|
+
<Badge colorPalette="gray" variant="subtle" title="The ssh config keeps no shared connection (ControlMaster) for this host: each ssh connects on its own">
|
|
27
|
+
no shared connection
|
|
28
|
+
</Badge>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return <Badge colorPalette="orange" variant="subtle">not connected</Badge>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** One login in progress: the prompt of ssh (MFA passcode, password, host key) and its answer */
|
|
35
|
+
const LoginPanel: React.FC<{
|
|
36
|
+
login: SshLogin;
|
|
37
|
+
onRetry: () => void;
|
|
38
|
+
onCancel: () => void;
|
|
39
|
+
}> = ({ login, onRetry, onCancel }) => {
|
|
40
|
+
const [answer, setAnswer] = useState('');
|
|
41
|
+
const [show, setShow] = useState(false);
|
|
42
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
43
|
+
const send = useMutation({
|
|
44
|
+
mutationFn: (text: string) => answerSshLogin(login.id, text),
|
|
45
|
+
onSuccess: () => setAnswer(''),
|
|
46
|
+
onError: (error) => toaster.create({ title: 'Could not send the answer', description: errorMessage(error), type: 'error' }),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// a new prompt: focus the input
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (login.state === 'prompt') inputRef.current?.focus();
|
|
52
|
+
}, [login.state, login.prompts]);
|
|
53
|
+
|
|
54
|
+
const info = login.info.filter(line => line.trim() !== (login.prompt || '').trim());
|
|
55
|
+
const submit = () => { if (answer && !send.isPending) send.mutate(answer); };
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Box borderWidth="1px" borderColor="var(--color-border)" borderRadius="md" p={4}>
|
|
59
|
+
<VStack align="stretch" gap={3}>
|
|
60
|
+
<HStack justify="space-between">
|
|
61
|
+
<Text fontWeight="semibold" color="var(--color-text)">
|
|
62
|
+
{login.cluster ? `${login.cluster} · ` : ''}<Code fontSize="sm">{login.host}</Code>
|
|
63
|
+
</Text>
|
|
64
|
+
{ACTIVE.includes(login.state) && login.state !== 'prompt' && (
|
|
65
|
+
<HStack gap={2} color="var(--color-text-muted)" fontSize="sm">
|
|
66
|
+
<Spinner size="xs" />
|
|
67
|
+
<Text>{login.state === 'starting' ? 'connecting…' : 'checking the answer…'}</Text>
|
|
68
|
+
</HStack>
|
|
69
|
+
)}
|
|
70
|
+
</HStack>
|
|
71
|
+
|
|
72
|
+
{info.length > 0 && (
|
|
73
|
+
<Box as="pre" fontFamily="mono" fontSize="xs" whiteSpace="pre-wrap" bg="var(--color-bg-subtle, rgba(127,127,127,0.08))"
|
|
74
|
+
p={2} borderRadius="sm" maxH="160px" overflowY="auto" color="var(--color-text-muted)">
|
|
75
|
+
{info.join('\n')}
|
|
76
|
+
</Box>
|
|
77
|
+
)}
|
|
78
|
+
|
|
79
|
+
{login.state === 'prompt' && login.kind === 'confirm' && (
|
|
80
|
+
<VStack align="stretch" gap={2}>
|
|
81
|
+
<Text fontSize="sm" whiteSpace="pre-wrap" color="var(--color-text)">{login.prompt}</Text>
|
|
82
|
+
<HStack>
|
|
83
|
+
<Button size="sm" colorPalette="blue" loading={send.isPending} onClick={() => send.mutate('yes')}>Yes</Button>
|
|
84
|
+
<Button size="sm" variant="outline" disabled={send.isPending} onClick={() => send.mutate('no')}>No</Button>
|
|
85
|
+
</HStack>
|
|
86
|
+
</VStack>
|
|
87
|
+
)}
|
|
88
|
+
|
|
89
|
+
{login.state === 'prompt' && login.kind !== 'confirm' && (
|
|
90
|
+
<VStack align="stretch" gap={2}>
|
|
91
|
+
<Text fontSize="sm" whiteSpace="pre-wrap" color="var(--color-text)">{login.prompt}</Text>
|
|
92
|
+
<HStack>
|
|
93
|
+
<Input
|
|
94
|
+
{...inputStyle}
|
|
95
|
+
ref={inputRef}
|
|
96
|
+
size="sm"
|
|
97
|
+
fontFamily="mono"
|
|
98
|
+
type={show ? 'text' : 'password'}
|
|
99
|
+
autoComplete="one-time-code"
|
|
100
|
+
value={answer}
|
|
101
|
+
onChange={(e) => setAnswer(e.target.value)}
|
|
102
|
+
onKeyDown={(e) => { if (e.key === 'Enter') submit(); }}
|
|
103
|
+
/>
|
|
104
|
+
<IconButton size="sm" variant="ghost" aria-label={show ? 'Hide' : 'Show'} onClick={() => setShow(s => !s)}>
|
|
105
|
+
{show ? <LuEyeOff /> : <LuEye />}
|
|
106
|
+
</IconButton>
|
|
107
|
+
<Button size="sm" colorPalette="blue" loading={send.isPending} disabled={!answer} onClick={submit}>
|
|
108
|
+
Send
|
|
109
|
+
</Button>
|
|
110
|
+
</HStack>
|
|
111
|
+
<Text fontSize="xs" color="var(--color-text-muted)">
|
|
112
|
+
Handed to ssh only: bujang never stores or logs it.
|
|
113
|
+
</Text>
|
|
114
|
+
</VStack>
|
|
115
|
+
)}
|
|
116
|
+
|
|
117
|
+
{login.state === 'ok' && (
|
|
118
|
+
<HStack gap={2} color="var(--color-status-running, green)">
|
|
119
|
+
<LuCircleCheck />
|
|
120
|
+
<Text fontSize="sm">{login.message || 'connected'}</Text>
|
|
121
|
+
</HStack>
|
|
122
|
+
)}
|
|
123
|
+
{(login.state === 'failed' || login.state === 'cancelled') && (
|
|
124
|
+
<HStack gap={2} justify="space-between">
|
|
125
|
+
<HStack gap={2} color="var(--color-status-failed, red)">
|
|
126
|
+
<LuCircleX />
|
|
127
|
+
<Text fontSize="sm">{login.message || login.state}</Text>
|
|
128
|
+
</HStack>
|
|
129
|
+
<Button size="xs" variant="outline" onClick={onRetry}>Retry</Button>
|
|
130
|
+
</HStack>
|
|
131
|
+
)}
|
|
132
|
+
|
|
133
|
+
{ACTIVE.includes(login.state) && (
|
|
134
|
+
<HStack justify="flex-end">
|
|
135
|
+
<Button size="xs" variant="ghost" onClick={onCancel}>Cancel</Button>
|
|
136
|
+
</HStack>
|
|
137
|
+
)}
|
|
138
|
+
</VStack>
|
|
139
|
+
</Box>
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export interface SshConnectDialogProps {
|
|
144
|
+
open: boolean;
|
|
145
|
+
onClose: () => void;
|
|
146
|
+
/** Start the login to this cluster's login node right away (submit to a cluster not connected yet) */
|
|
147
|
+
cluster?: string | null;
|
|
148
|
+
/** The login to `cluster` succeeded: the dialog closes itself */
|
|
149
|
+
onConnected?: () => void;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Open the shared ssh connection (ControlMaster) of the clusters: the hosts and their state, a
|
|
154
|
+
* Connect button each; the prompts of ssh (MFA passcode / Duo option, password, host key) are
|
|
155
|
+
* answered here. Every other ssh of bujang reuses the connection and never prompts.
|
|
156
|
+
*/
|
|
157
|
+
export const SshConnectDialog: React.FC<SshConnectDialogProps> = ({ open, onClose, cluster, onConnected }) => {
|
|
158
|
+
const queryClient = useQueryClient();
|
|
159
|
+
const [loginId, setLoginId] = useState<string | null>(null);
|
|
160
|
+
const autoStarted = useRef(false);
|
|
161
|
+
|
|
162
|
+
const { data: connections, isLoading, error } = useQuery<SshConnections>({
|
|
163
|
+
queryKey: SSH_CONNECTIONS_KEY,
|
|
164
|
+
queryFn: () => getSshConnections(),
|
|
165
|
+
enabled: open,
|
|
166
|
+
refetchOnWindowFocus: false,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const { data: login } = useQuery<SshLogin>({
|
|
170
|
+
queryKey: ['ssh-login', loginId],
|
|
171
|
+
queryFn: () => getSshLogin(loginId as string),
|
|
172
|
+
enabled: open && !!loginId,
|
|
173
|
+
refetchInterval: (q) => (q.state.data && !ACTIVE.includes(q.state.data.state) ? false : 1000),
|
|
174
|
+
refetchOnWindowFocus: false,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const start = useMutation({
|
|
178
|
+
mutationFn: startSshLogin,
|
|
179
|
+
onSuccess: (data) => {
|
|
180
|
+
queryClient.setQueryData(['ssh-login', data.id], data);
|
|
181
|
+
setLoginId(data.id);
|
|
182
|
+
},
|
|
183
|
+
onError: (err) => toaster.create({ title: 'Could not start the ssh login', description: errorMessage(err), type: 'error' }),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// submit flow: connect to the cluster at once
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
if (open && cluster && !autoStarted.current) {
|
|
189
|
+
autoStarted.current = true;
|
|
190
|
+
start.mutate({ cluster });
|
|
191
|
+
}
|
|
192
|
+
if (!open) {
|
|
193
|
+
autoStarted.current = false;
|
|
194
|
+
setLoginId(null);
|
|
195
|
+
}
|
|
196
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- once per opening
|
|
197
|
+
}, [open, cluster]);
|
|
198
|
+
|
|
199
|
+
// the outcome: refresh the states; the submit flow goes on by itself
|
|
200
|
+
const lastState = useRef<string | null>(null);
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
if (!login || login.state === lastState.current) return;
|
|
203
|
+
lastState.current = login.state;
|
|
204
|
+
if (!ACTIVE.includes(login.state)) queryClient.invalidateQueries({ queryKey: SSH_CONNECTIONS_KEY });
|
|
205
|
+
if (login.state === 'ok' && cluster && login.cluster === cluster && onConnected) onConnected();
|
|
206
|
+
}, [login, cluster, onConnected, queryClient]);
|
|
207
|
+
|
|
208
|
+
const close = () => {
|
|
209
|
+
// a login still waiting for an answer gives up (the connections already open stay)
|
|
210
|
+
if (login && ACTIVE.includes(login.state)) cancelSshLogin(login.id).catch(() => undefined);
|
|
211
|
+
onClose();
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const connect = (c: SshConnection) => start.mutate({ host: c.host, cluster: c.cluster });
|
|
215
|
+
const busy = !!login && ACTIVE.includes(login.state);
|
|
216
|
+
const hosts = connections?.hosts || [];
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<Dialog.Root open={open} onOpenChange={(d) => { if (!d.open) close(); }} size="lg">
|
|
220
|
+
<Dialog.Backdrop />
|
|
221
|
+
<Dialog.Positioner>
|
|
222
|
+
<Dialog.Content>
|
|
223
|
+
<Dialog.Header>
|
|
224
|
+
<Dialog.Title>{cluster ? `Connect to ${cluster}` : 'Connect to the clusters'}</Dialog.Title>
|
|
225
|
+
<Dialog.CloseTrigger />
|
|
226
|
+
</Dialog.Header>
|
|
227
|
+
<Dialog.Body>
|
|
228
|
+
<VStack align="stretch" gap={4}>
|
|
229
|
+
<Text fontSize="sm" color="var(--color-text-muted)">
|
|
230
|
+
{cluster
|
|
231
|
+
? `${cluster} has no open connection: log in once (two-factor authentication included), then the job is submitted.`
|
|
232
|
+
: 'Log in once per cluster (two-factor authentication included): bujang reuses the connection for every ssh, rsync and scp until it expires.'}
|
|
233
|
+
</Text>
|
|
234
|
+
|
|
235
|
+
{login && (
|
|
236
|
+
<LoginPanel
|
|
237
|
+
login={login}
|
|
238
|
+
onRetry={() => start.mutate({ host: login.host, cluster: login.cluster || undefined })}
|
|
239
|
+
onCancel={() => cancelSshLogin(login.id).catch(() => undefined)}
|
|
240
|
+
/>
|
|
241
|
+
)}
|
|
242
|
+
|
|
243
|
+
{connections && !connections.writable && (
|
|
244
|
+
<Text fontSize="sm" color="var(--color-status-failed)">
|
|
245
|
+
{connections.read_only_reason || 'This server cannot open ssh connections.'}
|
|
246
|
+
</Text>
|
|
247
|
+
)}
|
|
248
|
+
{isLoading && <Spinner />}
|
|
249
|
+
{error && <Text fontSize="sm" color="var(--color-status-failed)">{errorMessage(error)}</Text>}
|
|
250
|
+
{connections && hosts.length === 0 && (
|
|
251
|
+
<Text fontSize="sm" color="var(--color-text-muted)">No cluster reached over ssh.</Text>
|
|
252
|
+
)}
|
|
253
|
+
|
|
254
|
+
{!cluster && hosts.length > 0 && (
|
|
255
|
+
<Table.Root size="sm">
|
|
256
|
+
<Table.Header>
|
|
257
|
+
<Table.Row>
|
|
258
|
+
<Table.ColumnHeader>Cluster</Table.ColumnHeader>
|
|
259
|
+
<Table.ColumnHeader>Host</Table.ColumnHeader>
|
|
260
|
+
<Table.ColumnHeader>State</Table.ColumnHeader>
|
|
261
|
+
<Table.ColumnHeader />
|
|
262
|
+
</Table.Row>
|
|
263
|
+
</Table.Header>
|
|
264
|
+
<Table.Body>
|
|
265
|
+
{hosts.map(c => (
|
|
266
|
+
<Table.Row key={`${c.cluster}/${c.host}`}>
|
|
267
|
+
<Table.Cell>{c.cluster}</Table.Cell>
|
|
268
|
+
<Table.Cell fontFamily="mono" fontSize="xs">
|
|
269
|
+
{c.host}
|
|
270
|
+
{!c.login_node && <Badge ml={2} size="xs" variant="outline">data mover</Badge>}
|
|
271
|
+
</Table.Cell>
|
|
272
|
+
<Table.Cell><MasterBadge master={c.master} /></Table.Cell>
|
|
273
|
+
<Table.Cell textAlign="end">
|
|
274
|
+
<Button
|
|
275
|
+
size="xs"
|
|
276
|
+
variant={c.master === 'open' ? 'ghost' : 'outline'}
|
|
277
|
+
disabled={!connections?.writable || busy || start.isPending}
|
|
278
|
+
loading={start.isPending && start.variables?.host === c.host}
|
|
279
|
+
onClick={() => connect(c)}
|
|
280
|
+
>
|
|
281
|
+
<LuPlug /> {c.master === 'open' ? 'Check' : 'Connect'}
|
|
282
|
+
</Button>
|
|
283
|
+
</Table.Cell>
|
|
284
|
+
</Table.Row>
|
|
285
|
+
))}
|
|
286
|
+
</Table.Body>
|
|
287
|
+
</Table.Root>
|
|
288
|
+
)}
|
|
289
|
+
</VStack>
|
|
290
|
+
</Dialog.Body>
|
|
291
|
+
<Dialog.Footer>
|
|
292
|
+
<Button variant="outline" onClick={close}>Close</Button>
|
|
293
|
+
</Dialog.Footer>
|
|
294
|
+
</Dialog.Content>
|
|
295
|
+
</Dialog.Positioner>
|
|
296
|
+
</Dialog.Root>
|
|
297
|
+
);
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
/** The "Connect" button of the jobs page: how many clusters are connected, opens SshConnectDialog */
|
|
301
|
+
export const SshConnectButton: React.FC = () => {
|
|
302
|
+
const [open, setOpen] = useState(false);
|
|
303
|
+
const { data } = useQuery<SshConnections>({
|
|
304
|
+
queryKey: SSH_CONNECTIONS_KEY,
|
|
305
|
+
queryFn: () => getSshConnections(),
|
|
306
|
+
refetchInterval: 60000,
|
|
307
|
+
refetchOnWindowFocus: false,
|
|
308
|
+
retry: false,
|
|
309
|
+
});
|
|
310
|
+
const logins = (data?.hosts || []).filter(h => h.login_node);
|
|
311
|
+
const shared = logins.filter(h => h.master !== 'none');
|
|
312
|
+
const connected = shared.filter(h => h.master === 'open').length;
|
|
313
|
+
const missing = shared.length - connected;
|
|
314
|
+
|
|
315
|
+
return (
|
|
316
|
+
<>
|
|
317
|
+
<Button
|
|
318
|
+
size="sm"
|
|
319
|
+
variant="outline"
|
|
320
|
+
borderRadius="full"
|
|
321
|
+
onClick={() => setOpen(true)}
|
|
322
|
+
title={data
|
|
323
|
+
? `${connected} of ${shared.length} clusters connected${missing ? ': log in to the others' : ''}`
|
|
324
|
+
: 'Open the ssh connections of the clusters'}
|
|
325
|
+
>
|
|
326
|
+
{connected > 0 ? (
|
|
327
|
+
<>
|
|
328
|
+
<Box as="span" w="8px" h="8px" borderRadius="full" flexShrink={0}
|
|
329
|
+
bg="var(--color-status-running, #22c55e)" />
|
|
330
|
+
{connected} connected
|
|
331
|
+
</>
|
|
332
|
+
) : (
|
|
333
|
+
<>
|
|
334
|
+
<LuPlug />
|
|
335
|
+
Connect
|
|
336
|
+
</>
|
|
337
|
+
)}
|
|
338
|
+
</Button>
|
|
339
|
+
<SshConnectDialog open={open} onClose={() => setOpen(false)} />
|
|
340
|
+
</>
|
|
341
|
+
);
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Before a submit: when the cluster's login node has no open connection, ask for a login first.
|
|
346
|
+
* `ensure(cluster, go)` runs `go` now, or once the login dialog succeeded; render `dialog`.
|
|
347
|
+
*/
|
|
348
|
+
export const useSshConnectGate = () => {
|
|
349
|
+
const [cluster, setCluster] = useState<string | null>(null);
|
|
350
|
+
const pending = useRef<(() => void) | null>(null);
|
|
351
|
+
|
|
352
|
+
const ensure = async (name: string, go: () => void) => {
|
|
353
|
+
let state: SshConnections | null = null;
|
|
354
|
+
try {
|
|
355
|
+
state = await getSshConnections(name);
|
|
356
|
+
} catch {
|
|
357
|
+
state = null; // unknown or local cluster, no ssh: the submit says what is wrong
|
|
358
|
+
}
|
|
359
|
+
const host = state?.hosts.find(h => h.login_node);
|
|
360
|
+
if (!state || !state.writable || !host || host.master !== 'no') {
|
|
361
|
+
go();
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
pending.current = go;
|
|
365
|
+
setCluster(name);
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const dialog = (
|
|
369
|
+
<SshConnectDialog
|
|
370
|
+
open={!!cluster}
|
|
371
|
+
cluster={cluster}
|
|
372
|
+
onClose={() => { pending.current = null; setCluster(null); }}
|
|
373
|
+
onConnected={() => {
|
|
374
|
+
const go = pending.current;
|
|
375
|
+
pending.current = null;
|
|
376
|
+
setCluster(null);
|
|
377
|
+
go?.();
|
|
378
|
+
}}
|
|
379
|
+
/>
|
|
380
|
+
);
|
|
381
|
+
return { ensure, dialog };
|
|
382
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -790,6 +790,43 @@ export interface SshTestResponse {
|
|
|
790
790
|
results: SshCheckResult[];
|
|
791
791
|
}
|
|
792
792
|
|
|
793
|
+
/** An ssh login started from the UI (POST /ssh/login): ssh's prompts (MFA, password, host key) come back here */
|
|
794
|
+
export type SshLoginState = 'starting' | 'prompt' | 'waiting' | 'ok' | 'failed' | 'cancelled';
|
|
795
|
+
|
|
796
|
+
export interface SshLogin {
|
|
797
|
+
id: string;
|
|
798
|
+
host: string;
|
|
799
|
+
cluster: string | null;
|
|
800
|
+
state: SshLoginState;
|
|
801
|
+
/** the prompt waiting for an answer (state "prompt") */
|
|
802
|
+
prompt: string | null;
|
|
803
|
+
/** secret: masked input; confirm: a yes / no question (host key) */
|
|
804
|
+
kind: 'secret' | 'confirm' | null;
|
|
805
|
+
/** what ssh printed so far: the instructions of the server (Duo menu, ...) */
|
|
806
|
+
info: string[];
|
|
807
|
+
message: string;
|
|
808
|
+
prompts: number;
|
|
809
|
+
started: number;
|
|
810
|
+
finished: number | null;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/** GET /ssh/connections: the ssh hosts of the clusters and their shared connection (ControlMaster) */
|
|
814
|
+
export interface SshConnection {
|
|
815
|
+
host: string;
|
|
816
|
+
cluster: string;
|
|
817
|
+
/** the login node of the cluster (else an ssh executor host: data mover) */
|
|
818
|
+
login_node: boolean;
|
|
819
|
+
/** open: connected; no: not connected; none: the ssh config keeps no shared connection for the host */
|
|
820
|
+
master: 'open' | 'no' | 'none';
|
|
821
|
+
login: SshLogin | null;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
export interface SshConnections {
|
|
825
|
+
writable: boolean;
|
|
826
|
+
read_only_reason: string | null;
|
|
827
|
+
hosts: SshConnection[];
|
|
828
|
+
}
|
|
829
|
+
|
|
793
830
|
/** GET /update: the running version against the latest release on PyPI (checked once a day). */
|
|
794
831
|
export interface UpdateCheck {
|
|
795
832
|
/** BUJANG_UPDATE_CHECK=0 turns the check off */
|
|
@@ -870,7 +907,8 @@ export interface SyncStatus {
|
|
|
870
907
|
/** seconds between two background syncs, null when the server does not run them */
|
|
871
908
|
interval: number | null;
|
|
872
909
|
jobs: number;
|
|
873
|
-
synced
|
|
910
|
+
/** per cluster: true synced, false failed, 'recent': not asked, a full rsync ran less than min_refresh_interval ago */
|
|
911
|
+
synced?: Record<string, boolean | 'recent'>;
|
|
874
912
|
skipped?: string;
|
|
875
913
|
}
|
|
876
914
|
|
|
@@ -207,7 +207,7 @@ const RunningCard: React.FC<{ data: JanitorOverview }> = ({ data }) => {
|
|
|
207
207
|
// ─── Periodic jobs ──────────────────────────────────────────────────
|
|
208
208
|
|
|
209
209
|
const PERIODIC_HELP: Record<string, string> = {
|
|
210
|
-
'
|
|
210
|
+
'full sync': 'pulls the job folders of the clusters that have unfinished jobs (rsync), then updates the index of the jobs page for what changed. Not a database sync.',
|
|
211
211
|
book_keeping: 'hourly: full rsync of each cluster, accounting of the finished jobs, then removal of their folders on the cluster',
|
|
212
212
|
scheduled_check: 'submits the scheduled jobs that are due',
|
|
213
213
|
janitor_prune: 'removes the history older than the retention',
|
|
@@ -278,10 +278,10 @@ const RunsTable: React.FC<{ runs: JanitorRun[] }> = ({ runs }) => (
|
|
|
278
278
|
<Box overflowX="auto" maxH="480px" overflowY="auto">
|
|
279
279
|
<Table.Root size="sm" variant="outline" stickyHeader>
|
|
280
280
|
{/* the frozen header carries its own background, above the rows scrolling under it */}
|
|
281
|
-
<Table.Header bg="
|
|
281
|
+
<Table.Header bg="bg.muted" zIndex={1}>
|
|
282
282
|
<Table.Row>
|
|
283
283
|
{['When', 'Task', 'Cluster', 'Way', 'Took', 'Waited', 'Data', 'Status', 'Detail'].map(h => (
|
|
284
|
-
<Table.ColumnHeader key={h} bg="
|
|
284
|
+
<Table.ColumnHeader key={h} bg="bg.muted">{h}</Table.ColumnHeader>
|
|
285
285
|
))}
|
|
286
286
|
</Table.Row>
|
|
287
287
|
</Table.Header>
|
|
@@ -368,7 +368,7 @@ const ClustersCard: React.FC<{ data: JanitorOverview }> = ({ data }) => {
|
|
|
368
368
|
|
|
369
369
|
const KINDS: [string, string][] = [
|
|
370
370
|
['', 'All kinds'], ['periodic', 'periodic'], ['submit', 'submissions'], ['rsync', 'rsync'], ['scp', 'scp'], ['ssh', 'ssh'],
|
|
371
|
-
['request', 'slow requests'], ['cleanup', 'cleanups'],
|
|
371
|
+
['request', 'slow requests (> 1 s)'], ['cleanup', 'cleanups'],
|
|
372
372
|
];
|
|
373
373
|
|
|
374
374
|
const TasksCard: React.FC<{ data: JanitorOverview }> = ({ data }) => {
|
|
@@ -379,7 +379,9 @@ const TasksCard: React.FC<{ data: JanitorOverview }> = ({ data }) => {
|
|
|
379
379
|
const [status, setStatus] = useState('');
|
|
380
380
|
const [selected, setSelected] = useState<JanitorStat | null>(null);
|
|
381
381
|
const clusters = useMemo(() => Object.keys(data.clusters).sort(), [data.clusters]);
|
|
382
|
-
|
|
382
|
+
// slow requests (the pages, not the background) only when asked for
|
|
383
|
+
const shownKind = (k: string) => (kind ? k === kind : k !== 'request');
|
|
384
|
+
const stats = data.stats[period].filter(s => shownKind(s.kind) && (!cluster || s.cluster === cluster));
|
|
383
385
|
|
|
384
386
|
const { data: history, isLoading } = useQuery({
|
|
385
387
|
queryKey: ['bujang-janitor-history', kind, cluster, status, selected?.name, selected?.cluster],
|
|
@@ -471,7 +473,7 @@ const TasksCard: React.FC<{ data: JanitorOverview }> = ({ data }) => {
|
|
|
471
473
|
{selected && <Button size="xs" variant="ghost" onClick={() => setSelected(null)}>Show every task</Button>}
|
|
472
474
|
</HStack>
|
|
473
475
|
{isLoading ? <Spinner /> : history && history.runs.length > 0
|
|
474
|
-
? <RunsTable runs={history.runs} />
|
|
476
|
+
? <RunsTable runs={selected ? history.runs : history.runs.filter(r => shownKind(r.kind))} />
|
|
475
477
|
: <Muted>None recorded.</Muted>}
|
|
476
478
|
</LinkableCard>
|
|
477
479
|
</>
|
|
@@ -528,7 +530,8 @@ const ArchiveTool: React.FC = () => {
|
|
|
528
530
|
<Text fontSize="sm" color="var(--color-text-muted)" mb={3}>
|
|
529
531
|
Moves the job folders out of <Code fontSize="xs">jobs/</Code> into <Code fontSize="xs"><organizer>/<value>/</Code>:
|
|
530
532
|
the link there becomes the folder itself, so <Code fontSize="xs">jobs/</Code> keeps only what is still moving.
|
|
531
|
-
The jobs stay on every page.
|
|
533
|
+
The jobs stay on every page. A pipeline run moves with its steps: the run folder, its steps inside it.
|
|
534
|
+
Jobs not over or still on their cluster are left where they are (a run with such a step too).
|
|
532
535
|
</Text>
|
|
533
536
|
<HStack gap={2} wrap="wrap">
|
|
534
537
|
<Select value={organizer} onChange={(v) => { setOrganizer(v); setValue(''); setPlan(null); }}
|
package/src/views/JobSubmit.tsx
CHANGED
|
@@ -21,6 +21,7 @@ import { toaster } from '../toast';
|
|
|
21
21
|
import { MonacoEditor } from '../components/MonacoEditor';
|
|
22
22
|
import type { MonacoCodeEditor } from '../components/MonacoEditor';
|
|
23
23
|
import AutocompleteInput from '../components/AutocompleteInput';
|
|
24
|
+
import { useSshConnectGate } from '../components/SshConnectDialog';
|
|
24
25
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
25
26
|
import { useSearchParams } from 'react-router-dom';
|
|
26
27
|
import {
|
|
@@ -266,6 +267,7 @@ export const JobSubmissionForm: React.FC<JobSubmissionFormProps> = ({
|
|
|
266
267
|
const effectiveCron = isCustomCron ? cronCustom : cronPreset;
|
|
267
268
|
|
|
268
269
|
// Mutations
|
|
270
|
+
const sshGate = useSshConnectGate();
|
|
269
271
|
const submitJobMutation = useMutation({
|
|
270
272
|
mutationFn: submitSlurmJob,
|
|
271
273
|
onSuccess: (data) => {
|
|
@@ -582,14 +584,16 @@ export const JobSubmissionForm: React.FC<JobSubmissionFormProps> = ({
|
|
|
582
584
|
toaster.create({ title: 'Cannot read the attached files', description: String(error), type: 'error', duration: 5000 });
|
|
583
585
|
return;
|
|
584
586
|
}
|
|
585
|
-
|
|
587
|
+
const request = {
|
|
586
588
|
script: editorRef.current?.getValue() || '',
|
|
587
589
|
job_name: jobNameRef.current?.value || 'bujang_job',
|
|
588
590
|
cluster: selectedCluster,
|
|
589
591
|
sbatch_args: _collectSbatchArgs(),
|
|
590
592
|
script_args: _collectScriptArgs(),
|
|
591
593
|
files,
|
|
592
|
-
}
|
|
594
|
+
};
|
|
595
|
+
// a cluster without an open ssh connection (MFA): log in first, then submit
|
|
596
|
+
await sshGate.ensure(selectedCluster, () => submitJobMutation.mutate(request));
|
|
593
597
|
};
|
|
594
598
|
|
|
595
599
|
const handleSaveScheduled = () => {
|
|
@@ -1388,6 +1392,7 @@ export const JobSubmissionForm: React.FC<JobSubmissionFormProps> = ({
|
|
|
1388
1392
|
</Grid>
|
|
1389
1393
|
|
|
1390
1394
|
</VStack>
|
|
1395
|
+
{sshGate.dialog}
|
|
1391
1396
|
</Box>
|
|
1392
1397
|
);
|
|
1393
1398
|
};
|