
9 changed files with 162 additions and 38 deletions
-
1package.json
-
BINresources/icon/es.png
-
10src/common/constants.ts
-
40src/model/es/esNode.ts
-
26src/model/es/indexNode.ts
-
16src/provider/treeDataProvider.ts
-
3src/service/connect/connection.ts
-
42src/service/connect/esConnection.ts
-
62src/vue/connect/index.vue
After Width: 48 | Height: 48 | Size: 699 B |
@ -0,0 +1,40 @@ |
|||
import * as path from "path"; |
|||
import { Constants, ModelType } from "../../common/constants"; |
|||
import { ConnectionManager } from "../../service/connectionManager"; |
|||
import { Node } from "../interface/node"; |
|||
import axios from "axios"; |
|||
import { IndexNode } from "./indexNode"; |
|||
import { InfoNode } from "../other/infoNode"; |
|||
|
|||
export class EsNode extends Node { |
|||
|
|||
public iconPath: string = path.join(Constants.RES_PATH, "icon/es.png"); |
|||
public contextValue: string = ModelType.ES_CONNECTION; |
|||
constructor(readonly uid: string, readonly parent: Node) { |
|||
super(uid) |
|||
this.init(parent) |
|||
this.cacheSelf() |
|||
const lcp = ConnectionManager.getLastConnectionOption(false); |
|||
if (lcp && lcp.getConnectId() == this.getConnectId()) { |
|||
this.iconPath = path.join(Constants.RES_PATH, "icon/connection-active.svg"); |
|||
this.description = `Active` |
|||
} |
|||
} |
|||
|
|||
|
|||
async getChildren(): Promise<Node[]> { |
|||
|
|||
return axios.get("http://localhost:9200/_cat/indices").then(res => { |
|||
let indexes = []; |
|||
const results = res.data.match(/[^\r\n]+/g); |
|||
for (const result of results) { |
|||
indexes.push(new IndexNode(result, this)) |
|||
} |
|||
return indexes; |
|||
}).catch(err => { |
|||
return [new InfoNode(err)] |
|||
}) |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,26 @@ |
|||
import * as path from "path"; |
|||
import { Constants, ModelType } from "@/common/constants"; |
|||
import { ConnectionManager } from "@/service/connectionManager"; |
|||
import { Node } from "../interface/node"; |
|||
|
|||
|
|||
export class IndexNode extends Node { |
|||
|
|||
public iconPath: string = path.join(Constants.RES_PATH, "icon/server.png"); |
|||
public contextValue: string = ModelType.ES_INDEX; |
|||
constructor(readonly info: string, readonly parent: Node) { |
|||
super(null) |
|||
this.init(parent) |
|||
const [health, status, index, uuid, pri, rep, docsCount, docsDeleted, storeSize, priStoreSize] = info.split(/\s+/) |
|||
this.label = index |
|||
const lcp = ConnectionManager.getLastConnectionOption(false); |
|||
if (lcp && lcp.getConnectId() == this.getConnectId()) { |
|||
this.iconPath = path.join(Constants.RES_PATH, "icon/connection-active.svg"); |
|||
this.description = `Active` |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,42 @@ |
|||
import axios from "axios"; |
|||
import { Node } from "@/model/interface/node"; |
|||
import { IConnection, queryCallback } from "./connection"; |
|||
|
|||
export class EsConnection implements IConnection { |
|||
|
|||
private url: string; |
|||
private conneted: boolean; |
|||
constructor(opt: Node) { |
|||
this.url = `http://${opt.host}:${opt.port}` |
|||
} |
|||
|
|||
query(sql: string, callback?: queryCallback): void; |
|||
query(sql: string, values: any, callback?: queryCallback): void; |
|||
query(sql: any, values?: any, callback?: any) { |
|||
throw new Error("Method not implemented."); |
|||
} |
|||
connect(callback: (err: Error) => void): void { |
|||
axios.get(`${this.url}/_cluster/health`).then(res => { |
|||
this.conneted = true; |
|||
callback(null) |
|||
}).catch(err => { |
|||
callback(err) |
|||
}) |
|||
|
|||
} |
|||
beginTransaction(callback: (err: Error) => void): void { |
|||
throw new Error("Method not implemented."); |
|||
} |
|||
rollback(): void { |
|||
throw new Error("Method not implemented."); |
|||
} |
|||
commit(): void { |
|||
throw new Error("Method not implemented."); |
|||
} |
|||
end(): void { |
|||
} |
|||
isAlive(): boolean { |
|||
return this.conneted; |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue