Browse Source

Resolve conflict

tumao 3 years ago
parent
commit
e753fb8ab2

+ 1 - 1
express/package.json

@@ -82,6 +82,6 @@
     "watch": [
       "src"
     ],
-    "ext": "ts"
+    "ext": "ts yml"
   }
 }

+ 1 - 15
express/src/collections/collections.controller.ts

@@ -6,7 +6,6 @@ import {
   CreateAliasDto,
   CreateCollectionDto,
   InsertDataDto,
-  ShowCollectionsDto,
   VectorSearchDto,
   QueryDto,
 } from "./dto";
@@ -26,20 +25,7 @@ export class CollectionController {
   }
 
   generateRoutes() {
-    /**
-     * @swagger
-     * /collections:
-     *   get:
-     *     description: Get all or loaded collection
-     *     responses:
-     *       200:
-     *         Collections List
-     */
-    this.router.get(
-      "/",
-      dtoValidationMiddleware(ShowCollectionsDto),
-      this.showCollections.bind(this)
-    );
+    this.router.get("/", this.showCollections.bind(this));
 
     this.router.post(
       "/",

+ 247 - 0
express/src/collections/swagger.yml

@@ -0,0 +1,247 @@
+paths:
+  /collections:
+    get:
+      tags: 
+        - Collection
+      description: Get all or loaded collection
+      parameters:
+        - in: query
+          name: type
+          type: number
+          description: If type is 1 return loaded collections, otherwise return all collections.
+      responses:
+        200:
+          description: CollectionList
+          schema:
+            type: object
+    post:
+      tags: 
+        - Collection
+      description: Create collection in milvus
+      requestBody:
+        description: Create collection request body
+        required: true
+        content:
+          application/json:
+            schema:
+              $ref: '#/definitions/CreateCollection'
+         
+      responses:
+        200:
+          schema:
+            type: object
+  /collections/statistics:
+    get:
+      tags: 
+        - Collection
+      description: Get all collections statistics like row count
+      responses:
+        200:
+          schema:
+            type: object
+
+  /collections/{name}/statistics:
+    get:
+      tags: 
+        - Collection
+      description: Get single collection statistics like row count
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+
+      responses:
+        200:
+          schema:
+            type: object
+  /collections/indexes/status:
+    get:
+      tags: 
+        - Collection
+      description: Get all collections index status
+
+      responses:
+        200:
+          schema:
+            type: object
+
+  /collections/{name}:
+    delete:
+      tags: 
+        - Collection
+      description: Delete collection by name
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+      responses:
+        200:
+          schema:
+            type: object
+    get:
+      tags: 
+        - Collection
+      description: Get single collection informations like schema, name, id
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+      responses:
+        200:
+          schema:
+            type: object
+  /collections/{name}/load:
+    put:
+      tags: 
+        - Collection
+      description: Load data to cache
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+      responses:
+        200:
+          schema:
+            type: object
+  /collections/{name}/release:
+    put:
+      tags: 
+        - Collection
+      description: Release data from cache
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+      responses:
+        200:
+          schema:
+            type: object
+  /collections/{name}/insert:
+    post:
+      tags: 
+        - Collection
+      description: Insert data into collection
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+      requestBody:
+        description: Insert data into collection
+        required: true
+        content:
+          application/json:
+            schema:
+              $ref: '#/definitions/Insert'
+      responses:
+        200:
+          schema:
+            type: object
+            
+  /collections/{name}/search:
+    post:
+      tags: 
+        - Collection
+      description: Vector search 
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+      requestBody:
+        description: Do vector search
+        required: true
+        content:
+          application/json:
+            schema:
+              $ref: '#/definitions/Search'
+      responses:
+        200:
+          schema:
+            type: object
+
+  /collections/{name}/query:
+    post:
+      tags: 
+        - Collection
+      description: query data
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+      requestBody:
+        description: query data body
+        required: true
+        content:
+          application/json:
+            schema:
+              type: object
+              required:
+                - "expr"
+              properties:
+                expr:
+                  type: string
+                  example: id in [1]
+      responses:
+        200:
+          schema:
+            type: object      
+
+/collections/{name}/alias:
+    post:
+      tags: 
+        - Collection
+      description: Create alias for collection
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+      requestBody:
+        description: alias name
+        required: true
+        content:
+          application/json:
+            schema:
+              type: object
+              required:
+                - "alias"
+              properties:
+                alias:
+                  type: string
+                  example: collection_alias
+      responses:
+        200:
+          schema:
+            type: object                   
+
+
+definitions:
+  CollectionName:
+    in: path
+    name: name
+    type: string
+    description: Collection name
+  CreateCollection:
+    type: object
+    required:
+      - "collection_name"
+      - "fields"
+    properties:
+      collection_name:
+        type: string
+        example: collection_01
+      fields:
+        type: array
+        example: []
+  Insert:
+    type: object
+    required:
+      - "fields_data"
+    properties:
+      partition_name:
+        type: string
+        example: _default
+      fields_data:
+        type: array
+        example: []
+      hash_keys:
+        type: array
+        example: []
+  Search:
+    type: object
+    required:
+      - "vectors"
+      - "vector_type"
+      - "search_params"
+    properties:
+      vectors:
+        type: array
+        example: []
+        
+      vector_type:
+        description: BinaryVector - 100 , FloatVector - 101
+        type: number
+        example: 100 
+      search_params:
+        type: object
+        example: {"anns_field":"","topk":10,"metric_type":"L2","params":""}

+ 28 - 0
express/src/crons/swagger.yml

@@ -0,0 +1,28 @@
+paths:
+  /crons:
+    put:
+      tags: 
+        - Crons
+      description: Toggle cronjob status
+      requestBody:
+        description: Cron job name, status(start->0, stop->1)
+        required: true
+        content:
+          application/json:
+            schema:
+              type: object
+              required:
+                - "name"
+              properties:
+                name:
+                  type: string
+                  example: COLLECTION
+                type:
+                  type: number
+                  example: 0
+      responses:
+        200:
+          schema:
+            type: object
+
+ 

+ 9 - 4
express/src/middlewares/validation.ts

@@ -4,15 +4,20 @@ import { validate, ValidationError } from "class-validator";
 import { sanitize } from "class-sanitizer";
 import HttpException from "../exception/HttpException";
 
+/**
+ * Only check for req.body
+ * When use req.query or req.params cant use dto to validate.
+ * Because all datas are string in req.query.
+ * @param type
+ * @param skipMissingProperties
+ * @returns
+ */
 export const dtoValidationMiddleware = (
   type: any,
   skipMissingProperties = false
 ): RequestHandler => {
   return (req, res, next) => {
-    const dtoObj = plainToClass(
-      type,
-      req.method === "GET" || req.method === "DELETE" ? req.query : req.body
-    );
+    const dtoObj = plainToClass(type, req.body);
     validate(dtoObj, { skipMissingProperties }).then(
       (errors: ValidationError[]) => {
         if (errors.length > 0) {

+ 3 - 6
express/src/milvus/milvus.controller.ts

@@ -1,7 +1,7 @@
 import { NextFunction, Request, Response, Router } from "express";
 import { dtoValidationMiddleware } from "../middlewares/validation";
 import { MilvusService } from "./milvus.service";
-import { CheckMilvusDto, ConnectMilvusDto, FlushDto } from "./dto";
+import { ConnectMilvusDto, FlushDto } from "./dto";
 
 export class MilvusController {
   private router: Router;
@@ -23,11 +23,7 @@ export class MilvusController {
       this.connectMilvus.bind(this)
     );
 
-    this.router.get(
-      "/check",
-      dtoValidationMiddleware(CheckMilvusDto),
-      this.checkConnect.bind(this)
-    );
+    this.router.get("/check", this.checkConnect.bind(this));
 
     this.router.put(
       "/flush",
@@ -44,6 +40,7 @@ export class MilvusController {
     const address = req.body?.address;
     try {
       const result = await this.milvusService.connectMilvus(address);
+
       res.send(result);
     } catch (error) {
       next(error);

+ 70 - 0
express/src/milvus/swagger.yml

@@ -0,0 +1,70 @@
+paths:
+  /milvus/connect:
+    post:
+      tags: 
+        - Milvus
+      description: Connect milvus
+      requestBody:
+        description: Milvus address 
+        required: true
+        content:
+          application/json:
+            schema:
+              type: object
+              required:
+                - "address"
+              properties:
+                address:
+                  type: string
+                  example: 127.0.0.1:19530
+      responses:
+        200:
+          schema:
+            type: object
+
+  /milvus/check:
+    get:
+      tags: 
+        - Milvus
+      description: Check milvus alive or not.
+      parameters:
+        - in: query
+          name: address
+          description: Milvus address
+      responses:
+        200:
+          schema:
+            type: object
+
+  /milvus/metrics:
+    get:
+      tags: 
+        - Milvus
+      description: Get milvus metrics     
+      responses:
+        200:
+          schema:
+            type: object
+
+  /milvus/flush:
+    post:
+      tags: 
+        - Milvus
+      description: Flush data in milvus
+      requestBody:
+        description: The collection names you want to flush
+        required: true
+        content:
+          application/json:
+            schema:
+              type: object
+              required:
+                - "collection_names"
+              properties:
+                collection_names:
+                  type: array
+                  example: [collectionName]
+      responses:
+        200:
+          schema:
+            type: object

+ 3 - 7
express/src/partitions/partitions.controller.ts

@@ -19,11 +19,7 @@ export class PartitionController {
   }
 
   generateRoutes() {
-    this.router.get(
-      '/',
-      dtoValidationMiddleware(GetPartitionsInfoDto),
-      this.getPartitionsInfo.bind(this)
-    );
+    this.router.get('/', this.getPartitionsInfo.bind(this));
 
     this.router.post(
       '/',
@@ -31,13 +27,13 @@ export class PartitionController {
       this.managePartition.bind(this)
     );
 
-    this.router.post(
+    this.router.put(
       '/load',
       dtoValidationMiddleware(LoadPartitionsDto),
       this.loadPartition.bind(this)
     );
 
-    this.router.post(
+    this.router.put(
       '/release',
       dtoValidationMiddleware(LoadPartitionsDto),
       this.releasePartition.bind(this)

+ 97 - 0
express/src/partitions/swagger.yml

@@ -0,0 +1,97 @@
+paths:
+  /partitions:
+    get:
+      tags: 
+        - Partition
+      description: Get all partitions information
+      parameters:
+        - in: query
+          name: collection_name
+          type: string
+          description: Collection name
+      responses:
+        200:
+          schema:
+            type: object
+  
+    post:
+      tags: 
+        - Partition
+      description: Create or delete partition excepte _default
+      requestBody:
+        description: Manage partition req body
+        required: true
+        content:
+          application/json:
+            schema:
+              type: object
+              required:
+                - type
+                - collection_name
+                - partition_name
+              properties:
+                type:
+                  type: string
+                  example: create
+                collection_name:
+                  type: string
+                  example: ''
+                partition_name:
+                  type: string
+                  example: ''
+      responses:
+        200:
+          schema:
+            type: object
+
+  /partitions/load:
+    put:
+      tags: 
+        - Partition
+      description: Load partition to cache
+      requestBody:
+        required: true
+        content:
+          application/json:
+            schema:
+              type: object
+              required:
+                - collection_name
+                - partition_name
+              properties:
+                collection_name:
+                  type: string
+                  example: ''
+                partition_names:
+                  type: array
+                  example: []
+      responses:
+        200:
+          schema:
+            type: object
+  /partitions/release:
+    put:
+      tags: 
+        - Partition
+      description: Release partition from cache
+      requestBody:
+        required: true
+        content:
+          application/json:
+            schema:
+              type: object
+              required:
+                - collection_name
+                - partition_name
+              properties:
+                collection_name:
+                  type: string
+                  example: ''
+                partition_names:
+                  type: array
+                  example: []
+      responses:
+        200:
+          schema:
+            type: object
+ 

+ 4 - 21
express/src/schema/schema.controller.ts

@@ -3,12 +3,7 @@ import { dtoValidationMiddleware } from "../middlewares/validation";
 import { SchemaService } from "./schema.service";
 import { milvusService } from "../milvus";
 
-import {
-  ManageIndexDto,
-  DescribeIndexDto,
-  GetIndexProgressDto,
-  GetIndexStateDto,
-} from "./dto";
+import { ManageIndexDto } from "./dto";
 
 export class SchemaController {
   private router: Router;
@@ -26,23 +21,11 @@ export class SchemaController {
       this.manageIndex.bind(this)
     );
 
-    this.router.get(
-      "/index",
-      dtoValidationMiddleware(DescribeIndexDto),
-      this.describeIndex.bind(this)
-    );
+    this.router.get("/index", this.describeIndex.bind(this));
 
-    this.router.post(
-      "/index/progress",
-      dtoValidationMiddleware(GetIndexProgressDto),
-      this.getIndexBuildProgress.bind(this)
-    );
+    this.router.get("/index/progress", this.getIndexBuildProgress.bind(this));
 
-    this.router.post(
-      "/index/state",
-      dtoValidationMiddleware(GetIndexStateDto),
-      this.getIndexState.bind(this)
-    );
+    this.router.get("/index/state", this.getIndexState.bind(this));
 
     return this.router;
   }

+ 78 - 0
express/src/schema/swagger.yml

@@ -0,0 +1,78 @@
+paths:
+  /schema/index:
+    get:
+      tags: 
+        - Schema
+      description: Get index information
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+      responses:
+        200:
+          schema:
+            type: object
+  
+    post:
+      tags: 
+        - Schema
+      description: Create or delete index in collection
+      requestBody:
+        description: Only type is create need extra_params
+        required: true
+        content:
+          application/json:
+            schema:
+              type: object
+              required:
+                - type
+                - collection_name
+                - field_name
+              properties:
+                type:
+                  type: string
+                  example: create
+                collection_name:
+                  type: string
+                  example: ''
+                field_name:
+                  type: string
+                  example: 'vector field'
+                extra_params:
+                  type: object
+                  example: {"index_type":"","metric_type":"","params":""}
+      responses:
+        200:
+          schema:
+            type: object
+
+  /schema/index/progress:
+    get:
+      tags: 
+        - Schema
+      description: Get index building progress percentage
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+      responses:
+        200:
+          schema:
+            type: object
+
+  /schema/index/state:
+    get:
+      tags: 
+        - Schema
+      description: Get index state 
+      parameters:
+        - $ref: '#/definitions/CollectionName'
+      responses:
+        200:
+          schema:
+            type: object
+ 
+
+
+definitions:
+  CollectionName:
+    in: query
+    name: collection_name
+    type: string
+    description: Collection name

+ 1 - 1
express/src/swagger.ts

@@ -15,7 +15,7 @@ export const surveSwaggerSpecification = () => {
       },
       servers: [{ url: "/api/v1" }],
     },
-    apis: ["./src/**/*.ts"],
+    apis: ["./src/**/*.yml"],
   };
   const swaggerSpec = swaggerJsdoc(options);