Merge pull request #10618 from Budibase/budi-6932/check_elastic
Check elastic search connection settings
This commit is contained in:
commit
a2e22bda71
|
@ -4,6 +4,7 @@ import {
|
||||||
QueryType,
|
QueryType,
|
||||||
IntegrationBase,
|
IntegrationBase,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
|
ConnectionInfo,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
import { Client, ClientOptions } from "@elastic/elasticsearch"
|
import { Client, ClientOptions } from "@elastic/elasticsearch"
|
||||||
|
@ -21,7 +22,7 @@ const SCHEMA: Integration = {
|
||||||
"Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents.",
|
"Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents.",
|
||||||
friendlyName: "ElasticSearch",
|
friendlyName: "ElasticSearch",
|
||||||
type: "Non-relational",
|
type: "Non-relational",
|
||||||
features: [],
|
features: [DatasourceFeature.CONNECTION_CHECKING],
|
||||||
datasource: {
|
datasource: {
|
||||||
url: {
|
url: {
|
||||||
type: DatasourceFieldType.STRING,
|
type: DatasourceFieldType.STRING,
|
||||||
|
@ -97,7 +98,7 @@ const SCHEMA: Integration = {
|
||||||
|
|
||||||
class ElasticSearchIntegration implements IntegrationBase {
|
class ElasticSearchIntegration implements IntegrationBase {
|
||||||
private config: ElasticsearchConfig
|
private config: ElasticsearchConfig
|
||||||
private client: any
|
private client
|
||||||
|
|
||||||
constructor(config: ElasticsearchConfig) {
|
constructor(config: ElasticsearchConfig) {
|
||||||
this.config = config
|
this.config = config
|
||||||
|
@ -116,6 +117,18 @@ class ElasticSearchIntegration implements IntegrationBase {
|
||||||
this.client = new Client(clientConfig)
|
this.client = new Client(clientConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async testConnection(): Promise<ConnectionInfo> {
|
||||||
|
try {
|
||||||
|
await this.client.info()
|
||||||
|
return { connected: true }
|
||||||
|
} catch (e: any) {
|
||||||
|
return {
|
||||||
|
connected: false,
|
||||||
|
error: e.message as string,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async create(query: { index: string; json: object }) {
|
async create(query: { index: string; json: object }) {
|
||||||
const { index, json } = query
|
const { index, json } = query
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
import { ElasticsearchContainer } from "testcontainers"
|
||||||
|
import elastic from "../../../../packages/server/src/integrations/elasticsearch"
|
||||||
|
|
||||||
|
jest.unmock("@elastic/elasticsearch")
|
||||||
|
|
||||||
|
describe("datasource validators", () => {
|
||||||
|
describe("elastic search", () => {
|
||||||
|
let url: string
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
const container = await new ElasticsearchContainer().start()
|
||||||
|
url = container.getHttpUrl()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("test valid connection string", async () => {
|
||||||
|
const integration = new elastic.integration({
|
||||||
|
url,
|
||||||
|
})
|
||||||
|
const result = await integration.testConnection()
|
||||||
|
expect(result).toEqual({ connected: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("test wrong connection string", async () => {
|
||||||
|
const integration = new elastic.integration({
|
||||||
|
url: `http://localhost:5656`,
|
||||||
|
})
|
||||||
|
const result = await integration.testConnection()
|
||||||
|
expect(result).toEqual({
|
||||||
|
connected: false,
|
||||||
|
error: "connect ECONNREFUSED 127.0.0.1:5656",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue