diff --git a/src/components/dashboard/PageHeader.test.ts b/src/components/dashboard/PageHeader.test.ts index 88271c9a..1b36eea7 100644 --- a/src/components/dashboard/PageHeader.test.ts +++ b/src/components/dashboard/PageHeader.test.ts @@ -35,12 +35,13 @@ function pageHeaders(): Usage[] { } describe('page header docs links', () => { - it('maps every page except the manual itself to a topic and section that exist', () => { + it('maps every page except the manual and legal documents to a topic and section that exist', () => { const usages = pageHeaders() expect(usages.length).toBeGreaterThan(20) for (const usage of usages) { - if (basename(usage.file) === 'DocsView.vue') { + // The manual and the legal documents have no manual topic of their own. + if (['DocsView.vue', 'LegalView.vue'].includes(basename(usage.file))) { expect(usage.docs).toBeUndefined() continue } diff --git a/src/components/data/CreateBucketDialog.test.ts b/src/components/data/CreateBucketDialog.test.ts index 5147e24f..b4fbb6aa 100644 --- a/src/components/data/CreateBucketDialog.test.ts +++ b/src/components/data/CreateBucketDialog.test.ts @@ -1,10 +1,11 @@ import { defineComponent, h, ref } from 'vue' import * as VueRuntime from 'vue' -import { describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import * as BucketName from '@/lib/bucketName' +import * as BucketNaming from '@/lib/bucketNaming' import * as DistributedMock from '@/lib/distributedMock' import * as Utils from '@/lib/utils' -import { button, click, compileClientComponent, content, element, flush, moduleDefault, mountApp, nodes, typeValue } from '@/test/clientRender' +import { button, click, compileClientComponent, content, element, flush, moduleDefault, mountApp, nodes, typeValue, type HostNode } from '@/test/clientRender' const Slotted = (tag: string) => defineComponent({ inheritAttrs: false, setup: (_, { attrs, slots }) => () => h(tag, attrs, slots.default?.()) }) @@ -19,17 +20,14 @@ const InputStub = defineComponent({ setup: (props, { attrs, emit }) => () => h('input', { ...attrs, invalid: props.invalid, value: props.modelValue, onInput: (event: { target: { value: string } }) => emit('update:modelValue', event.target.value) }), }) -const SelectStub = defineComponent({ - props: { modelValue: String, options: { type: Array, default: () => [] } }, - emits: ['update:modelValue'], - setup: (props, { attrs, emit }) => () => - h('select', { ...attrs, value: props.modelValue, onChange: (value: string) => emit('update:modelValue', value) }, - (props.options as { value: string; label: string }[]).map((option) => h('option', { value: option.value }, option.label))), -}) const StorageStub = defineComponent({ props: { open: Boolean }, setup: (props) => () => h('aside', { 'data-storage': props.open }) }) const ResultsStub = defineComponent({ props: { open: Boolean, name: String }, setup: (props) => () => h('aside', { 'data-results': props.open }, props.name) }) const s3 = { activateContext: vi.fn(), createBucket: vi.fn() } +// The group's routing and storages per node; a node missing here answers with no rule. +const routings = new Map() +const getGroupRouting = vi.fn(async (_group: string, node: string) => routings.get(node) ?? { group_id: 'g1', warnings: [] }) +const listGroupBackends = vi.fn(async () => ({ backends: [{ backend_id: 'b2', group_id: 'g1', kind: 's3', name: 'de.NBI-spire', public_config: {} }] })) const free = new Map([['https://one', 196 * 1024 ** 3], ['https://two', null]]) const nodeList = ref([ { nodeId: 'two', kind: 'storage', reachable: true, isLocal: false, apiBase: 'https://two' }, @@ -43,7 +41,6 @@ const Dialog = compileClientComponent(new URL('./CreateBucketDialog.vue', import '@lucide/vue': new Proxy({}, { get: () => defineComponent(() => () => null) }), '@/components/ui/Button.vue': moduleDefault(ButtonStub), '@/components/ui/Input.vue': moduleDefault(InputStub), - '@/components/ui/Select.vue': moduleDefault(SelectStub), '@/components/ui/RefusalNote.vue': moduleDefault(defineComponent({ props: { message: String }, setup: (props) => () => h('p', { role: 'alert' }, props.message) })), '@/components/ui/Spinner.vue': moduleDefault(Slotted('i')), '@/components/ui/Dialog.vue': moduleDefault(Slotted('div')), @@ -54,10 +51,13 @@ const Dialog = compileClientComponent(new URL('./CreateBucketDialog.vue', import '@/components/ui/DialogClose.vue': moduleDefault(Slotted('span')), '@/components/data/BucketCreateResults.vue': moduleDefault(ResultsStub), '@/components/data/BucketStorageDialog.vue': moduleDefault(StorageStub), - '@/composables/useAruna': { useAruna: () => ({ apiBaseUrl: ref('https://one'), sessionEpoch: ref(1) }) }, + '@/composables/useAruna': { + useAruna: () => ({ apiBaseUrl: ref('https://one'), sessionEpoch: ref(1), apiGroups: ref([{ group_id: 'g1', display_name: 'spire' }]), getGroupRouting, listGroupBackends }), + }, '@/composables/useRealmNodes': { useRealmNodes: () => ({ nodes: nodeList, displayName: (id: string) => `name-${id}`, isLocalNode: () => false }) }, '@/composables/useS3': { useS3: () => s3, s3ErrorMessage: (err: Error) => err.message }, '@/lib/bucketName': BucketName, + '@/lib/bucketNaming': BucketNaming, '@/lib/bucketPlace': { readFreeSpace: async (base: string) => free.get(base) ?? null }, '@/lib/distributedMock': DistributedMock, '@/lib/utils': Utils, @@ -72,14 +72,19 @@ async function mount(nodeId: string | null = 'one') { const name = () => element(mounted.root, (node) => node.tag === 'input' && node.props['aria-label'] === 'Bucket name') const create = () => button(mounted.root, 'Create bucket') const radios = () => nodes(mounted.root).filter((node) => node.tag === 'input' && node.props.type === 'radio') - const place = () => element(mounted.root, (node) => node.tag === 'select') - const pick = async (value: string) => { - ;(place().props.onChange as (value: string) => void)(value) + // The node rows, each a label with its radio, in the order shown. + const rows = () => nodes(mounted.root).filter((node) => node.tag === 'label' && nodes(node).some((child) => child.props.name === 'bucket-node')) + const radioOf = (row: HostNode) => element(row, (node) => node.props.name === 'bucket-node') + const chosen = () => rows().find((row) => radioOf(row).props.checked) + const pick = async (label: string) => { + ;(radioOf(rows().find((row) => content(row).includes(label))!).props.onChange as () => void)() await flush() } - return { root: mounted.root, created, open, name, create, radios, place, pick } + return { root: mounted.root, created, open, name, create, radios, rows, chosen, pick } } +beforeEach(() => routings.clear()) + describe('new bucket dialog', () => { it('names the rule under the name and refuses a broken name', async () => { const { root, name, create } = await mount() @@ -91,10 +96,15 @@ describe('new bucket dialog', () => { }) it('offers the reachable realm nodes, the open node first, with their free space, and a spread', async () => { - const { root, place, name } = await mount('one') - const labels = nodes(place()).filter((node) => node.tag === 'option').map((option) => content(option)) - expect(labels).toEqual(['name-one, 196\u00a0GiB free', 'name-two', 'Spread over several nodes']) - expect(place().props.value).toBe('one') + const { root, rows, chosen, name } = await mount('one') + const labels = rows().map((row) => content(row)) + expect(labels[0]).toContain('name-one') + expect(labels[0]).toContain('196\u00a0GiB free') + expect(labels[1]).toContain('name-two') + expect(labels[1]).not.toContain('free') + expect(labels[2]).toContain('Spread over several nodes') + expect(labels).toHaveLength(3) + expect(content(chosen()!)).toContain('name-one') expect(content(root)).not.toContain('laptop') // Stored data names the node that keeps it; a valid name shows its address. expect(content(root)).toContain('Kept on name-one, counted against quotas.') @@ -104,12 +114,12 @@ describe('new bucket dialog', () => { it('chooses a storage node before the management node, even when the management node is open', async () => { nodeList.value = [{ nodeId: 'mgmt', kind: 'management', reachable: true, isLocal: true, apiBase: 'https://mgmt' }, ...nodeList.value] - const { place } = await mount('mgmt') - const values = nodes(place()).filter((node) => node.tag === 'option').map((option) => option.props.value) + const { rows, chosen } = await mount('mgmt') + const names = rows().map((row) => content(row).match(/name-(two|one|mgmt)/)?.[0]) nodeList.value = nodeList.value.slice(1) - expect(values.slice(0, 3)).toEqual(['two', 'one', 'mgmt']) - expect(place().props.value).toBe('two') + expect(names.slice(0, 3)).toEqual(['name-two', 'name-one', 'name-mgmt']) + expect(content(chosen()!)).toContain('name-two') }) it('needs a source address for a referenced bucket and hands it on after creating it', async () => { @@ -132,7 +142,7 @@ describe('new bucket dialog', () => { s3.createBucket.mockResolvedValueOnce(undefined) const { name, create, pick, created, open } = await mount('one') await typeValue(name(), 'assemblies-2026') - await pick('two') + await pick('name-two') await click(create()) expect(s3.activateContext).toHaveBeenCalledWith('two', 'g1') @@ -155,11 +165,82 @@ describe('new bucket dialog', () => { s3.activateContext.mockClear() const { root, name, create, pick } = await mount('one') await typeValue(name(), 'big-data') - await pick('several') + await pick('Spread over several nodes') expect(element(root, (node) => node.tag === 'aside' && 'data-storage' in node.props).props['data-storage']).toBe(true) await click(create()) expect(element(root, (node) => node.tag === 'aside' && 'data-results' in node.props).props['data-results']).toBe(true) expect(s3.activateContext).not.toHaveBeenCalled() }) + + it('says what a new bucket gets on each node and starts on the node whose storage has the rule', async () => { + routings.set('two', { group_id: 'g1', default_target: { backend_id: 'b2' }, bucket_template: 'aruna-{group}-{bucket}', warnings: [] }) + const { root, rows, chosen, name } = await mount('one') + expect(content(chosen()!)).toContain('name-two') + const [one, two] = rows() + expect(content(one)).toContain('Plain Aruna bucket, no storage rule on this node') + expect(content(two)).toContain('Own S3 bucket aruna-spire-{bucket}') + expect(content(two)).toContain('on de.NBI-spire') + await typeValue(name(), 'progenomes') + expect(content(rows()[1])).toContain('aruna-spire-progenomes') + expect(content(root)).toContain('Kept on name-two, counted against quotas.') + }) + + it('says nothing about a node whose rule cannot be read and keeps the open node', async () => { + getGroupRouting.mockRejectedValueOnce(new Error('forbidden')).mockRejectedValueOnce(new Error('forbidden')) + const { rows, chosen, name, create } = await mount('one') + expect(content(chosen()!)).toContain('name-one') + await typeValue(name(), 'progenomes') + expect(create().props.disabled).toBe(false) + for (const row of rows().slice(0, 2)) { + expect(content(row)).not.toContain('Plain Aruna bucket') + expect(content(row)).not.toContain('Own S3 bucket') + } + }) + + it('waits for the rule of every node before a bucket goes to the node it chose', async () => { + const replies: ((routing: object) => void)[] = [] + const late = () => new Promise((resolve) => replies.push(resolve)) + getGroupRouting.mockImplementationOnce(late).mockImplementationOnce(late) + const { chosen, name, create } = await mount('one') + await typeValue(name(), 'progenomes') + expect(content(chosen()!)).toContain('name-one') + expect(create().props.disabled).toBe(true) + + replies[0]({ group_id: 'g1', warnings: [] }) + await flush() + expect(create().props.disabled).toBe(true) + replies[1]({ group_id: 'g1', default_target: { backend_id: 'b2' }, bucket_template: 'aruna-{bucket}', warnings: [] }) + await flush() + expect(content(chosen()!)).toContain('name-two') + expect(create().props.disabled).toBe(false) + }) + + it('lets a node picked by hand take the bucket while the rules are still read', async () => { + getGroupRouting.mockImplementationOnce(() => new Promise(() => {})).mockImplementationOnce(() => new Promise(() => {})) + const { name, create, pick } = await mount('one') + await typeValue(name(), 'progenomes') + expect(create().props.disabled).toBe(true) + await pick('name-one') + expect(create().props.disabled).toBe(false) + }) + + it('chooses the node with the rule on the way back to stored data when its rule came meanwhile', async () => { + const replies: ((routing: object) => void)[] = [] + const late = () => new Promise((resolve) => replies.push(resolve)) + getGroupRouting.mockImplementationOnce(late).mockImplementationOnce(late) + const { radios, chosen, name, create } = await mount('one') + await typeValue(name(), 'progenomes') + ;(radios()[1].props.onChange as () => void)() + await flush() + replies[0]({ group_id: 'g1', warnings: [] }) + replies[1]({ group_id: 'g1', default_target: { backend_id: 'b2' }, bucket_template: 'aruna-{bucket}', warnings: [] }) + await flush() + expect(content(chosen()!)).toContain('name-one') + + ;(radios()[0].props.onChange as () => void)() + await flush() + expect(content(chosen()!)).toContain('name-two') + expect(create().props.disabled).toBe(false) + }) }) diff --git a/src/components/data/CreateBucketDialog.vue b/src/components/data/CreateBucketDialog.vue index d9f735d6..c3641235 100644 --- a/src/components/data/CreateBucketDialog.vue +++ b/src/components/data/CreateBucketDialog.vue @@ -5,7 +5,6 @@ import { computed, onBeforeUnmount, ref, watch } from 'vue' import Button from '@/components/ui/Button.vue' import Input from '@/components/ui/Input.vue' -import Select from '@/components/ui/Select.vue' import RefusalNote from '@/components/ui/RefusalNote.vue' import Spinner from '@/components/ui/Spinner.vue' import Dialog from '@/components/ui/Dialog.vue' @@ -22,6 +21,7 @@ import { s3ErrorMessage, useS3 } from '@/composables/useS3' import type { AdmissionResponse } from '@/lib/api' import type { BindSource } from '@/lib/bindSource' import { BUCKET_NAME_REQUIREMENT, bucketNameProblem } from '@/lib/bucketName' +import { fillTemplate } from '@/lib/bucketNaming' import { readFreeSpace } from '@/lib/bucketPlace' import { defaultPlacement, type Placement } from '@/lib/distributedMock' import { formatBytes } from '@/lib/utils' @@ -35,7 +35,7 @@ const emit = defineEmits<{ }>() const SPREAD = 'several' -const { apiBaseUrl, sessionEpoch } = useAruna() +const { apiBaseUrl, sessionEpoch, apiGroups, getGroupRouting, listGroupBackends } = useAruna() const realmNodes = useRealmNodes() const s3 = useS3() @@ -48,6 +48,15 @@ const storageOpen = ref(false) const resultsOpen = ref(false) // Space left per node; a missing entry is still being read. const free = ref(new Map()) +// The S3 bucket template of the group on each node and the storage it names; null: none there. +// A missing entry is being read or could not be read, so the row says nothing about it. +const rules = ref(new Map()) +// Set once the node is chosen by hand, so a later answer does not move it. +const picked = ref(false) +// The nodes whose rule is still being read; a failed read counts as read. +const reading = ref(new Set()) +// While a node's rule is read, a choice not made by hand may still move. +const settling = computed(() => !picked.value && kind.value === 'stored' && reading.value.size > 0) // The reachable realm nodes, the open node first and a management node last, as it usually // holds no data; devices hold no new buckets here. @@ -77,17 +86,23 @@ const storedLine = computed(() => : choice.value ? `Kept on ${realmNodes.displayName(choice.value)}, counted against quotas.` : 'Counted against quotas.') -const placeOptions = computed(() => [ - ...places.value.map((entry) => ({ value: entry.nodeId, label: [realmNodes.displayName(entry.nodeId), freeLabel(entry.nodeId)].filter(Boolean).join(', ') })), - ...(kind.value === 'stored' ? [{ value: SPREAD, label: 'Spread over several nodes' }] : []), -]) +const groupName = computed(() => apiGroups.value.find((group) => group.group_id === props.groupId)?.display_name ?? '{group}') +const ownBucket = (template: string) => fillTemplate(template, trimmed.value || '{bucket}', groupName.value) // A referenced bucket lives on one node; the spread stays a choice of stored data. function pickKind(value: Kind) { kind.value = value if (value === 'referenced' && spread.value) choice.value = places.value[0]?.nodeId ?? '' + if (value === 'stored') chooseRuled() +} +// Stored data not placed by hand goes to the first node, in the order shown, whose storage gives +// a new bucket its own S3 bucket. +function chooseRuled() { + const ruled = places.value.find((place) => rules.value.get(place.nodeId)) + if (!picked.value && ruled && kind.value === 'stored') choice.value = ruled.nodeId } const canCreate = computed(() => - Boolean(trimmed.value && props.groupId && choice.value && (kind.value === 'stored' || source.value.trim())) && !nameProblem.value && !creating.value) + Boolean(trimmed.value && props.groupId && choice.value && (kind.value === 'stored' || source.value.trim())) && + !nameProblem.value && !creating.value && !settling.value) function freeLabel(id: string): string { if (!free.value.has(id)) return '' @@ -106,6 +121,30 @@ function loadFree() { } } +let rulesRun = 0 +function loadRules() { + const run = ++rulesRun + const groupId = props.groupId + rules.value = new Map() + reading.value = new Set(groupId ? places.value.map((entry) => entry.nodeId) : []) + if (!groupId) return + for (const entry of places.value) { + void Promise.all([getGroupRouting(groupId, entry.nodeId), listGroupBackends(groupId, entry.nodeId).catch(() => null)]).then( + ([routing, list]) => { + if (run !== rulesRun) return + const template = routing.bucket_template + const id = routing.default_target?.backend_id + const store = list?.backends.find((backend) => backend.backend_id === id)?.name ?? null + rules.value = new Map(rules.value).set(entry.nodeId, template ? { template, store } : null) + chooseRuled() + }, + () => {}, + ).then(() => { + if (run === rulesRun) reading.value = new Set([...reading.value].filter((id) => id !== entry.nodeId)) + }) + } +} + // Bumped on every open, close and unmount, so an older create ends unseen. let generation = 0 onBeforeUnmount(() => generation++) @@ -121,7 +160,9 @@ watch( creating.value = false placement.value = defaultPlacement() choice.value = places.value[0]?.nodeId ?? '' + picked.value = false loadFree() + loadRules() }, { immediate: true }, ) @@ -130,6 +171,7 @@ watch(places, (entries) => { if (!props.open) return if (!choice.value) choice.value = entries[0]?.nodeId ?? '' loadFree() + loadRules() }) // Back to one node in the storage dialog: the first node is chosen again. @@ -138,6 +180,7 @@ watch(placement, (value) => { }) function pick(value: string) { + picked.value = true choice.value = value if (value === SPREAD && !placement.value.several) { placement.value = { ...defaultPlacement(), several: true } @@ -221,13 +264,44 @@ function spreadCreated(outcome: AdmissionResponse) { -
- + +
+ +

No reachable realm node is known yet.

diff --git a/src/components/groups/LinkBucketDialog.test.ts b/src/components/groups/LinkBucketDialog.test.ts index 988d6675..0863267d 100644 --- a/src/components/groups/LinkBucketDialog.test.ts +++ b/src/components/groups/LinkBucketDialog.test.ts @@ -1,7 +1,7 @@ import * as VueRuntime from 'vue' import { defineComponent, h, ref } from 'vue' -import { beforeEach, describe, expect, it, vi } from 'vitest' -import { click, compileClientComponent, content, element, flush, moduleDefault, mountApp, typeValue } from '@/test/clientRender' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { click, compileClientComponent, content, element, flush, moduleDefault, mountApp, nodes, typeValue } from '@/test/clientRender' import * as Api from '@/lib/api' import * as BucketNaming from '@/lib/bucketNaming' import * as LinkedFolders from '@/lib/linkedFolders' @@ -18,6 +18,21 @@ const folders = { load: vi.fn(), } const runBackendImport = vi.fn() +// Per node: its storages and the buckets it holds. +const hostList = ref<{ nodeId: string; kind: string; reachable: boolean; isLocal: boolean }[]>([]) +const nodeStores = new Map() +const nodeBuckets = new Map() +const listGroupBackends = vi.fn(async (_group: string, node: string) => ({ backends: nodeStores.get(node) ?? [] })) +const getBucketRouting = vi.fn(async (bucket: string, node: string) => { + if (!nodeBuckets.get(node)?.includes(bucket)) throw new Api.ApiError(404, 'no such bucket') + return { bucket, rules: [], warnings: [] } +}) +const nodeClientReady = vi.fn(async (node: string) => ({ baseUrl: `https://${node}`, token: 't' })) +const AddStub = defineComponent({ + props: { open: Boolean, nodeId: String, prefill: Object, rule: String }, + setup: (props) => () => + h('aside', { 'data-add': props.open, 'data-node': props.nodeId, 'data-rule': props.rule, 'data-endpoint': (props.prefill as Api.GroupBackendResponse | undefined)?.public_config.endpoint }), +}) const Slot = defineComponent((_, { slots }) => () => h('div', slots.default?.())) const ButtonStub = defineComponent({ inheritAttrs: false, @@ -42,6 +57,8 @@ const SelectStub = defineComponent({ const Dialog = compileClientComponent(new URL('./LinkBucketDialog.vue', import.meta.url), { vue: VueRuntime, + '@lucide/vue': new Proxy({}, { get: () => defineComponent(() => () => null) }), + '@/components/groups/StorageBackendDialog.vue': moduleDefault(AddStub), '@/components/ui/Button.vue': moduleDefault(ButtonStub), '@/components/ui/Dialog.vue': moduleDefault(Slot), '@/components/ui/DialogClose.vue': moduleDefault(Slot), @@ -55,7 +72,10 @@ const Dialog = compileClientComponent(new URL('./LinkBucketDialog.vue', import.m '@/components/ui/Notice.vue': moduleDefault(Slot), '@/components/ui/Select.vue': moduleDefault(SelectStub), '@/composables/useImportRoots': { useImportRoots: () => folders }, - '@/composables/useAruna': { useAruna: () => ({ apiBaseUrl: ref('https://api'), authToken: ref('t'), sessionEpoch: ref(0) }) }, + '@/composables/useAruna': { + useAruna: () => ({ apiBaseUrl: ref('https://api'), authToken: ref('t'), sessionEpoch: ref(0), nodeClientReady, listGroupBackends, getBucketRouting }), + }, + '@/composables/useRealmNodes': { useRealmNodes: () => ({ nodes: hostList, displayName: (id: string) => id }) }, '@/lib/connectivity': { OFFLINE_WRITE_HINT: 'offline', useConnectivity: () => ({ writesDisabled: ref(false) }) }, '@/lib/api': { ...Api, createBackendImport, runBackendImport }, '@/lib/bucketNaming': BucketNaming, @@ -78,7 +98,7 @@ async function mount(backend: Api.GroupBackendResponse = SPIRE, backends: Api.Gr const events: unknown[] = [] const mounted = await mountApp( defineComponent(() => () => - h(Dialog, { open: open.value, groupId: 'g1', backend, backends, links: [LINKED], onSaved: (error?: string) => events.push(error) }), + h(Dialog, { open: open.value, groupId: 'g1', backend, backends, links: [LINKED], rule: 'aruna-spire-{bucket}', onSaved: (error?: string) => events.push(error) }), ), ) open.value = true @@ -99,6 +119,10 @@ beforeEach(() => { folders.state.value = 'ready' folders.error.value = null folders.load.mockClear() + hostList.value = [] + nodeStores.clear() + nodeBuckets.clear() + nodeClientReady.mockClear() }) describe('LinkBucketDialog', () => { @@ -219,4 +243,89 @@ describe('LinkBucketDialog', () => { expect(save(open.root).props.disabled).toBe(true) }) }) + + describe('node choice', () => { + const remote = (id: string): Api.GroupBackendResponse => ({ ...SPIRE, backend_id: `r-${id}`, name: 'spire' }) + const radios = (root: Root) => nodes(root).filter((node) => node.tag === 'input' && node.props.type === 'radio') + const chosen = (root: Root) => radios(root).findIndex((node) => node.props.checked) + async function answers(root: Root, bucket: string) { + await typeValue(byId(root, '-aruna'), bucket) + await vi.advanceTimersByTimeAsync(300) + await flush() + } + + beforeEach(() => { + vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }) + hostList.value = ['node-1', 'node-2', 'node-3'].map((nodeId) => ({ nodeId, kind: 'storage', reachable: true, isLocal: nodeId === 'node-1' })) + }) + afterEach(() => vi.useRealTimers()) + + it('says why a node cannot take the link and offers to add the storage where the bucket is', async () => { + nodeStores.set('node-1', [SPIRE]).set('node-2', [{ ...SPIRE, backend_id: 'other', public_config: { endpoint: 'https://elsewhere' } }]) + nodeBuckets.set('node-2', ['progenomes']) + const { root } = await mount() + await typeValue(byId(root, '-s3'), 'aruna-spire-progenomes') + await answers(root, 'progenomes') + const text = content(root) + expect(text).toContain('Does not hold progenomes') + expect(text).toContain('No spire storage on this node') + expect(text).toContain('Does not hold progenomes, no spire storage') + expect(radios(root).map((node) => node.props.disabled)).toEqual([true, true, true]) + expect(save(root).props.disabled).toBe(true) + + const adds = nodes(root).filter((node) => node.tag === 'button' && content(node).includes('+ Add storage')) + expect(adds).toHaveLength(1) + await click(adds[0]) + const dialog = element(root, (node) => node.tag === 'aside') + expect(dialog.props).toMatchObject({ 'data-add': true, 'data-node': 'node-2', 'data-endpoint': 'https://s3', 'data-rule': 'aruna-spire-{bucket}' }) + }) + + it('chooses the one node with both and links there through its own API', async () => { + nodeStores.set('node-1', [SPIRE]).set('node-2', [remote('2')]).set('node-3', [remote('3')]) + nodeBuckets.set('node-2', ['progenomes']) + const { root, events } = await mount() + await typeValue(byId(root, '-s3'), 'aruna-spire-progenomes') + await answers(root, 'progenomes') + expect(chosen(root)).toBe(1) + expect(content(root)).toContain('Holds progenomes and spire storage') + await submit(root) + expect(nodeClientReady).toHaveBeenCalledWith('node-2') + expect(createBackendImport).toHaveBeenCalledWith( + 'g1', + expect.objectContaining({ backend_id: 'r-2', bucket: 'progenomes' }), + { baseUrl: 'https://node-2', token: 't' }, + ) + expect(runBackendImport).toHaveBeenCalledWith('g1', 'i2', { baseUrl: 'https://node-2', token: 't' }) + expect(events).toEqual([undefined]) + }) + + it('prefers the connected node when several can take the link, and follows a new bucket', async () => { + nodeStores.set('node-1', [SPIRE]).set('node-2', [remote('2')]).set('node-3', [remote('3')]) + nodeBuckets.set('node-1', ['shared']).set('node-3', ['shared', 'only-three']) + const { root } = await mount() + await typeValue(byId(root, '-s3'), 'lab-raw') + await answers(root, 'shared') + expect(chosen(root)).toBe(0) + expect(save(root).props.disabled).toBe(false) + await answers(root, 'only-three') + expect(chosen(root)).toBe(2) + }) + + it('keeps a node picked by hand while the next bucket still works there', async () => { + nodeStores.set('node-1', [SPIRE]).set('node-2', [remote('2')]).set('node-3', [remote('3')]) + nodeBuckets.set('node-1', ['shared', 'next', 'gone']).set('node-3', ['shared', 'next']) + const { root } = await mount() + await typeValue(byId(root, '-s3'), 'lab-raw') + await answers(root, 'shared') + expect(chosen(root)).toBe(0) + ;(radios(root)[2].props.onChange as () => void)() + await flush() + expect(chosen(root)).toBe(2) + await answers(root, 'next') + expect(chosen(root)).toBe(2) + // A bucket the picked node does not hold falls back to the automatic choice. + await answers(root, 'gone') + expect(chosen(root)).toBe(0) + }) + }) }) diff --git a/src/components/groups/LinkBucketDialog.vue b/src/components/groups/LinkBucketDialog.vue index 0340cc73..3849a98a 100644 --- a/src/components/groups/LinkBucketDialog.vue +++ b/src/components/groups/LinkBucketDialog.vue @@ -1,6 +1,9 @@