-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
4,510 additions
and
646 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@app | ||
project | ||
|
||
@http | ||
get / | ||
|
||
@search | ||
sandboxEngine elasticsearch | ||
|
||
@plugins | ||
nasa-gcn/architect-plugin-search | ||
src ../../index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { search } from '@nasa-gcn/architect-functions-search' | ||
import { ConnectionError } from '@opensearch-project/opensearch/lib/errors.js' | ||
|
||
export async function handler() { | ||
let statusCode = 200, | ||
result = {} | ||
|
||
const client = await search() | ||
try { | ||
result = await client.info() | ||
} catch (e) { | ||
if (e instanceof ConnectionError) { | ||
statusCode = 503 | ||
} else { | ||
throw e | ||
} | ||
} | ||
|
||
return { | ||
statusCode, | ||
body: JSON.stringify(result), | ||
headers: { | ||
'cache-control': | ||
'no-cache, no-store, must-revalidate, max-age=0, s-maxage=0', | ||
'content-type': 'application/json; charset=utf8', | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@app | ||
project | ||
|
||
@http | ||
get / | ||
|
||
@search | ||
sandboxEngine opensearch | ||
|
||
@plugins | ||
nasa-gcn/architect-plugin-search | ||
src ../../index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../elasticsearch/src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import assert from 'node:assert' | ||
import { dirname, join } from 'node:path' | ||
import { describe, it } from 'node:test' | ||
import { execa, ExecaError } from 'execa' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
async function sleep(timeout: number) { | ||
return new Promise((resolve) => setTimeout(resolve, timeout)) | ||
} | ||
|
||
const signal = 'SIGINT' | ||
// const engines = ['elasticsearch', 'opensearch'] | ||
const engines = ['elasticsearch'] | ||
|
||
engines.forEach((engine) => | ||
describe(engine, () => { | ||
it('starts and stops in sandbox mode', async () => { | ||
// FIXME: replace with import.meta.resolve once it is stable in Node.js | ||
const cwd = join(dirname(fileURLToPath(import.meta.url)), engine) | ||
const process = execa('arc', ['sandbox'], { | ||
preferLocal: true, | ||
cwd, | ||
stdin: 'inherit', | ||
stdout: 'inherit', | ||
stderr: 'inherit', | ||
}) | ||
|
||
let result | ||
try { | ||
for (let i = 0; i < 30 && !result; i++) { | ||
try { | ||
const response = await fetch('http://localhost:3333/') | ||
if (!response.ok) throw new Error(`HTTP ${response.status}`) | ||
result = await response.json() | ||
} catch { | ||
await sleep(1000) | ||
} | ||
} | ||
assert.deepStrictEqual(result?.body.cluster_name, 'elasticsearch') | ||
} finally { | ||
assert.ok(process.kill(signal)) | ||
} | ||
|
||
let error | ||
try { | ||
await process | ||
} catch (e) { | ||
error = e | ||
} | ||
assert.notStrictEqual(error, undefined) | ||
assert.ok(error instanceof ExecaError) | ||
assert.strictEqual(error.isTerminated, true) | ||
assert.strictEqual(error.signal, signal) | ||
}) | ||
}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,7 @@ export const sandbox = { | |
}, | ||
|
||
async end() { | ||
console.log('****stopping') | ||
await local.stop() | ||
}, | ||
} |
Oops, something went wrong.