@ejfdelgado/ejflab-back 1.20.0 → 1.20.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/srv/MilvusSrv.mjs +82 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ejfdelgado/ejflab-back",
|
3
|
-
"version": "1.20.
|
3
|
+
"version": "1.20.3",
|
4
4
|
"repository": {
|
5
5
|
"type": "git",
|
6
6
|
"url": "git+https://github.com/ejfdelgado/ejflab-back.git"
|
@@ -18,7 +18,7 @@
|
|
18
18
|
"license": "ISC",
|
19
19
|
"private": false,
|
20
20
|
"dependencies": {
|
21
|
-
"@ejfdelgado/ejflab-common": "1.12.
|
21
|
+
"@ejfdelgado/ejflab-common": "1.12.3",
|
22
22
|
"@google-cloud/compute": "^4.7.0",
|
23
23
|
"@google-cloud/firestore": "^7.9.0",
|
24
24
|
"@google-cloud/storage": "^7.11.3",
|
package/srv/MilvusSrv.mjs
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
import fs from "fs";
|
1
2
|
import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";
|
2
3
|
import { encode, decode } from "@msgpack/msgpack";
|
4
|
+
import { General } from "./common/General.mjs";
|
5
|
+
import { CommandMilvus } from "@ejfdelgado/ejflab-common/src/flowchart/steps/CommandMilvus.js";
|
6
|
+
import { SimpleObj } from "@ejfdelgado/ejflab-common/src/SimpleObj.js";
|
3
7
|
|
4
8
|
export class MilvusSrv {
|
5
9
|
// MilvusSrv.checkErrors(res);
|
@@ -27,6 +31,10 @@ export class MilvusSrv {
|
|
27
31
|
client
|
28
32
|
}
|
29
33
|
}
|
34
|
+
static async releaseConnection(client) {
|
35
|
+
console.log("Milvus disconnect");
|
36
|
+
await client.closeConnection();
|
37
|
+
}
|
30
38
|
static async existsDatabase(client, name) {
|
31
39
|
const res = await client.listDatabases();
|
32
40
|
return res.db_names.indexOf(name) >= 0;
|
@@ -41,9 +49,15 @@ export class MilvusSrv {
|
|
41
49
|
const res = await client.listDatabases();
|
42
50
|
MilvusSrv.checkErrors(res);
|
43
51
|
const databases = res.db_names;
|
52
|
+
const response = { dbs: [] };
|
44
53
|
for (let i = 0; i < databases.length; i++) {
|
45
54
|
const database = databases[i];
|
46
55
|
console.log(`- Database: ${database}`);
|
56
|
+
const myDb = {
|
57
|
+
name: database,
|
58
|
+
collections: []
|
59
|
+
};
|
60
|
+
response.dbs.push(myDb);
|
47
61
|
const resUseDatabase = await client.useDatabase({ db_name: database });
|
48
62
|
MilvusSrv.checkErrors(resUseDatabase);
|
49
63
|
const resListCollections = await client.listCollections();
|
@@ -52,8 +66,10 @@ export class MilvusSrv {
|
|
52
66
|
for (let j = 0; j < data.length; j++) {
|
53
67
|
const collection = data[j];
|
54
68
|
console.log(` - Collection: ${collection.name}`);
|
69
|
+
myDb.collections.push({ name: collection.name });
|
55
70
|
}
|
56
71
|
}
|
72
|
+
return response;
|
57
73
|
}
|
58
74
|
static async dropDatabaseTemp(client) {
|
59
75
|
const res = await client.listDatabases();
|
@@ -66,6 +82,21 @@ export class MilvusSrv {
|
|
66
82
|
}
|
67
83
|
}
|
68
84
|
}
|
85
|
+
|
86
|
+
static async describeCollectionOfDatabase(client, db_name, collection_name) {
|
87
|
+
const resUseDatabase1 = await client.useDatabase({ db_name: db_name });
|
88
|
+
MilvusSrv.checkErrors(resUseDatabase1);
|
89
|
+
const description = await client.describeCollection({ collection_name: collection_name });
|
90
|
+
return description;
|
91
|
+
}
|
92
|
+
|
93
|
+
static async dropCollectionOfDatabase(client, db_name, collection_name) {
|
94
|
+
const resUseDatabase1 = await client.useDatabase({ db_name: db_name });
|
95
|
+
MilvusSrv.checkErrors(resUseDatabase1);
|
96
|
+
await MilvusSrv.dropCollection(client, collection_name);
|
97
|
+
return true;
|
98
|
+
}
|
99
|
+
|
69
100
|
static async dropCollection(client, collection_name) {
|
70
101
|
console.log(`Drop collection ${collection_name}...`);
|
71
102
|
const resHasCollection = await client.hasCollection({ collection_name });
|
@@ -121,6 +152,7 @@ export class MilvusSrv {
|
|
121
152
|
// Translate data types
|
122
153
|
const myCopy = JSON.parse(JSON.stringify(myJson));
|
123
154
|
const collection_name = myCopy.collection_name;
|
155
|
+
console.log(`createCollectionWithSchema... ${collection_name}`);
|
124
156
|
const exists = await this.existsCollection(client, collection_name);
|
125
157
|
if (exists) {
|
126
158
|
if (recreate) {
|
@@ -140,6 +172,56 @@ export class MilvusSrv {
|
|
140
172
|
const res = await client.createCollection(myCopy);
|
141
173
|
MilvusSrv.checkErrors(res);
|
142
174
|
}
|
175
|
+
/*
|
176
|
+
action:
|
177
|
+
database.create
|
178
|
+
database.recreate
|
179
|
+
collection.create
|
180
|
+
collection.destroy
|
181
|
+
introspect
|
182
|
+
database.destroy
|
183
|
+
database.destroy_temp
|
184
|
+
*/
|
185
|
+
static async admin(req, res, next) {
|
186
|
+
//this.context.getSuperContext().getMilvusClient();
|
187
|
+
const context = {
|
188
|
+
getSuperContext: () => {
|
189
|
+
return {
|
190
|
+
getMilvusClient: () => {
|
191
|
+
return MilvusSrv;
|
192
|
+
}
|
193
|
+
};
|
194
|
+
},
|
195
|
+
data: {
|
196
|
+
configuration: {}
|
197
|
+
},
|
198
|
+
};
|
199
|
+
const id = '';
|
200
|
+
const commandName = 'milvus';
|
201
|
+
const argsTxt = '';
|
202
|
+
const command = new CommandMilvus(context, id, commandName, argsTxt);
|
203
|
+
const action = General.readParam(req, "action", null);
|
204
|
+
const db = General.readParam(req, "db", null);
|
205
|
+
let collection = General.readParam(req, "collection", null);
|
206
|
+
if (action == "collection.create") {
|
207
|
+
// Read configuration file...
|
208
|
+
const json = General.readParam(req, "json", null);
|
209
|
+
const jsonTxt = fs.readFileSync(json, { encoding: "utf8" });
|
210
|
+
const jsonParsed = JSON.parse(jsonTxt);
|
211
|
+
const path = General.readParam(req, "path", null);
|
212
|
+
const configuration = SimpleObj.getValue(jsonParsed, path, null);
|
213
|
+
context.data.configuration = configuration;
|
214
|
+
collection = "configuration";
|
215
|
+
}
|
216
|
+
command.args = [action, db, collection];
|
217
|
+
const answer = await command.computation();
|
218
|
+
const response = {
|
219
|
+
args: command.args,
|
220
|
+
answer: answer,
|
221
|
+
status: "ok",
|
222
|
+
};
|
223
|
+
res.status(200).send(response);
|
224
|
+
}
|
143
225
|
static async ping(req, res, next) {
|
144
226
|
const { client } = MilvusSrv.connect();
|
145
227
|
const databases = await client.listDatabases();
|