Skip to content

Commit

Permalink
Merge branch 'addOpenSearch' into batchIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
ronitagarwala01 committed Nov 21, 2023
2 parents b0ea9ac + 258a93f commit 0824151
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { launch } from './run.js'
import type { LocalElasticSearch } from './run.js'
import type { LocalOpenSearch } from './run.js'
import { populate } from './data.js'
import {
cloudformationResources as serverlessCloudformationResources,
Expand Down Expand Up @@ -58,7 +58,7 @@ export const deploy = {
},
}

let local: LocalElasticSearch
let local: LocalOpenSearch

export const sandbox = {
async start({
Expand Down
27 changes: 14 additions & 13 deletions install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ import fetch from 'make-fetch-happen'
import { Extract as unzip } from 'unzip-stream'
import { x as untar } from 'tar'
import { cache, exists, mkdirP } from './paths.js'
import { writeFile } from 'fs/promises'

Check warning on line 16 in install.ts

View workflow job for this annotation

GitHub Actions / build / build (20, ubuntu-latest)

'writeFile' is defined but never used

Check warning on line 16 in install.ts

View workflow job for this annotation

GitHub Actions / build / build (18, ubuntu-latest)

'writeFile' is defined but never used

const version = '8.6.2'
const version = '2.11.0'

const types = new Map([
['Linux', ['linux', 'tar.gz']],
['Darwin', ['darwin', 'tar.gz']],
['Windows_NT', ['windows', 'zip']],
])

const archs = new Map([
['x64', 'x86_64'],
['arm64', 'aarch64'],
])
const archs = ['x64', 'arm64']

function getFilename() {
const os_type = os.type()
const os_arch = os.arch()

const typeInfo = types.get(os_type)
const arch = archs.get(os_arch)

if (!typeInfo || !arch) {
if (
!typeInfo ||
!archs.includes(os_arch) ||
(os_type === 'Windows_NT' && os_arch === 'arm64')
) {
throw new Error(
`No ElasticSearch binary is available for your OS type (${os_type}) and architecture (${os_arch}). For supported operating systems, see https://www.elastic.co/downloads/elasticsearch.`
`No OpenSearch binary is available for your OS type (${os_type}) and architecture (${os_arch}). For supported operating systems, see https://opensearch.org/versions/opensearch-2-11-0.html.`
)
}

const [type, ext] = typeInfo
return { name: `elasticsearch-${version}-${type}-${arch}`, ext }
return { name: `opensearch-${version}-${type}-${os_arch}`, ext }
}

async function download(url: string) {
Expand All @@ -57,14 +57,15 @@ export async function install() {
const binExt = os.type() === 'Windows_NT' ? '.bat' : ''
const binPath = join(
extractPath,
`elasticsearch-${version}`,
`opensearch-${version}`,
'bin',
`elasticsearch${binExt}`
`opensearch${binExt}`
)

const binPathExists = await exists(binPath)

if (!binPathExists) {
const url = `https://artifacts.elastic.co/downloads/elasticsearch/${name}.${ext}`
const url = `https://artifacts.opensearch.org/releases/bundle/opensearch/${version}/${name}.${ext}`
const stream = await download(url)

let extract
Expand Down
12 changes: 6 additions & 6 deletions run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { pipeline } from 'stream/promises'
import { createReadStream } from 'fs'

export class LocalElasticSearch {
export class LocalOpenSearch {
private readonly child!: ChildProcess
private readonly tempDir!: string
readonly port!: number
Expand Down Expand Up @@ -55,7 +55,7 @@ export class LocalElasticSearch {
`-Epath.logs=${logsDir}`,
`-Ehttp.port=${port}`,
'-Ediscovery.type=single-node',
'-Expack.security.enabled=false',
'-Eplugins.security.disabled=true',
]

console.log('Spawning', bin, ...args)
Expand All @@ -70,12 +70,12 @@ export class LocalElasticSearch {
])
} catch (e) {
await pipeline(
createReadStream(join(logsDir, 'elasticsearch.log')),
createReadStream(join(logsDir, 'opensearch.log')),
process.stderr
)
throw e
}
console.log('ElasticSearch is ready at', url)
console.log('OpenSearch is ready at', url)
} catch (e) {
await rimraf(tempDir)
throw e
Expand All @@ -94,7 +94,7 @@ export class LocalElasticSearch {
}

export async function launch(
...args: Parameters<typeof LocalElasticSearch.launch>
...args: Parameters<typeof LocalOpenSearch.launch>
) {
return await LocalElasticSearch.launch(...args)
return await LocalOpenSearch.launch(...args)
}

0 comments on commit 0824151

Please sign in to comment.