diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..62fd46ad --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,20 @@ +name: Attu docker build test + +on: + pull_request: + branches: + - main + types: [opened, synchronize] + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Docker Build + run: docker build -t zilliz/attu:dev --build-arg VERSION=dev . diff --git a/client/src/components/layout/GlobalEffect.tsx b/client/src/components/layout/GlobalEffect.tsx index 92fce2e3..80f8abc3 100644 --- a/client/src/components/layout/GlobalEffect.tsx +++ b/client/src/components/layout/GlobalEffect.tsx @@ -1,7 +1,8 @@ import React, { useContext } from 'react'; import axiosInstance from '@/http/Axios'; import { rootContext, authContext } from '@/context'; -import { HTTP_STATUS_CODE, MILVUS_ADDRESS } from '@/consts'; +import { MILVUS_ADDRESS } from '@/consts'; +import { HTTP_STATUS_CODE } from '@server/utils/Const'; let axiosResInterceptor: number | null = null; // let timer: Record | number>[] = []; diff --git a/client/src/consts/Http.ts b/client/src/consts/Http.ts deleted file mode 100644 index 4beb69ed..00000000 --- a/client/src/consts/Http.ts +++ /dev/null @@ -1,61 +0,0 @@ -export enum HTTP_STATUS_CODE { - CONTINUE = 100, - SWITCHING_PROTOCOLS = 101, - PROCESSING = 102, - EARLYHINTS = 103, - OK = 200, - CREATED = 201, - ACCEPTED = 202, - NON_AUTHORITATIVE_INFORMATION = 203, - NO_CONTENT = 204, - RESET_CONTENT = 205, - PARTIAL_CONTENT = 206, - AMBIGUOUS = 300, - MOVED_PERMANENTLY = 301, - FOUND = 302, - SEE_OTHER = 303, - NOT_MODIFIED = 304, - TEMPORARY_REDIRECT = 307, - PERMANENT_REDIRECT = 308, - BAD_REQUEST = 400, - UNAUTHORIZED = 401, - PAYMENT_REQUIRED = 402, - FORBIDDEN = 403, - NOT_FOUND = 404, - METHOD_NOT_ALLOWED = 405, - NOT_ACCEPTABLE = 406, - PROXY_AUTHENTICATION_REQUIRED = 407, - REQUEST_TIMEOUT = 408, - CONFLICT = 409, - GONE = 410, - LENGTH_REQUIRED = 411, - PRECONDITION_FAILED = 412, - PAYLOAD_TOO_LARGE = 413, - URI_TOO_LONG = 414, - UNSUPPORTED_MEDIA_TYPE = 415, - REQUESTED_RANGE_NOT_SATISFIABLE = 416, - EXPECTATION_FAILED = 417, - I_AM_A_TEAPOT = 418, - MISDIRECTED = 421, - UNPROCESSABLE_ENTITY = 422, - FAILED_DEPENDENCY = 424, - TOO_MANY_REQUESTS = 429, - INTERNAL_SERVER_ERROR = 500, - NOT_IMPLEMENTED = 501, - BAD_GATEWAY = 502, - SERVICE_UNAVAILABLE = 503, - GATEWAY_TIMEOUT = 504, - HTTP_VERSION_NOT_SUPPORTED = 505, -} - - -export const START_LOADING_TIME = 350; - -export enum WS_EVENTS { - COLLECTION = 'COLLECTION', -} - -export enum WS_EVENTS_TYPE { - START, - STOP, -} diff --git a/client/src/consts/index.ts b/client/src/consts/index.ts index 39781dd7..a4dfac54 100644 --- a/client/src/consts/index.ts +++ b/client/src/consts/index.ts @@ -1,4 +1,3 @@ -export * from './Http'; export * from './Insert'; export * from './Localstorage'; export * from './Milvus'; diff --git a/client/src/context/WebSocket.tsx b/client/src/context/WebSocket.tsx index 0826bc87..12ee9bde 100644 --- a/client/src/context/WebSocket.tsx +++ b/client/src/context/WebSocket.tsx @@ -1,11 +1,11 @@ import { createContext, useContext, useEffect, useState, useRef } from 'react'; import { io, Socket } from 'socket.io-client'; -import { WS_EVENTS, WS_EVENTS_TYPE } from '@/consts'; import { authContext } from '@/context'; import { url, CollectionHttp, MilvusHttp } from '@/http'; import { CollectionView } from '@/pages/collections/Types'; import { checkIndexBuilding, checkLoading } from '@/utils'; import { WebSocketType } from './Types'; +import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const'; export const webSocketContext = createContext({ collections: [], diff --git a/client/src/http/Milvus.ts b/client/src/http/Milvus.ts index 5c7da2d0..d35b2226 100644 --- a/client/src/http/Milvus.ts +++ b/client/src/http/Milvus.ts @@ -1,4 +1,4 @@ -import { WS_EVENTS, WS_EVENTS_TYPE } from '@/consts'; +import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const'; import BaseModel from './BaseModel'; export class MilvusHttp extends BaseModel { diff --git a/client/src/pages/collections/Collections.tsx b/client/src/pages/collections/Collections.tsx index d95f66db..2427663e 100644 --- a/client/src/pages/collections/Collections.tsx +++ b/client/src/pages/collections/Collections.tsx @@ -29,7 +29,8 @@ import DropCollectionDialog from '../dialogs/DropCollectionDialog'; import RenameCollectionDialog from '../dialogs/RenameCollectionDialog'; import InsertDialog from '../dialogs/insert/Dialog'; import ImportSampleDialog from '../dialogs/ImportSampleDialog'; -import { LOADING_STATE, WS_EVENTS, WS_EVENTS_TYPE } from '@/consts'; +import { LOADING_STATE } from '@/consts'; +import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const'; import { checkIndexBuilding, checkLoading } from '@/utils'; import Aliases from './Aliases'; diff --git a/client/src/pages/overview/Overview.tsx b/client/src/pages/overview/Overview.tsx index 611b1b2e..889ce762 100644 --- a/client/src/pages/overview/Overview.tsx +++ b/client/src/pages/overview/Overview.tsx @@ -13,12 +13,8 @@ import dayjs from 'dayjs'; import { rootContext, webSocketContext, dataContext } from '@/context'; import EmptyCard from '@/components/cards/EmptyCard'; import icons from '@/components/icons/Icons'; -import { - WS_EVENTS, - WS_EVENTS_TYPE, - LOADING_STATE, - MILVUS_DEPLOY_MODE, -} from '@/consts'; +import { LOADING_STATE, MILVUS_DEPLOY_MODE } from '@/consts'; +import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const'; import { useNavigationHook } from '@/hooks'; import { CollectionHttp, MilvusHttp } from '@/http'; import { ALL_ROUTER_TYPES } from '@/router/Types'; diff --git a/client/tsconfig.json b/client/tsconfig.json index aaabfd75..6433ec72 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -10,7 +10,8 @@ ], "baseUrl": "./", "paths": { - "@/*": ["src/*"] + "@/*": ["src/*"], + "@server/*": ["../server/src/*"] }, "allowJs": true, "skipLibCheck": true, diff --git a/client/vite.config.ts b/client/vite.config.ts index cd5a87ef..98d315c1 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -27,6 +27,8 @@ export default defineConfig({ // extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"], alias: { '@': path.resolve(__dirname, './src'), + // be careful to include server modules in the client + '@server': path.resolve(__dirname, './../server/src'), }, }, }); diff --git a/server/src/app.ts b/server/src/app.ts index c53a7bb0..f7b649db 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -21,13 +21,13 @@ import { ErrorMiddleware, ReqHeaderMiddleware, } from './middleware'; -import { EXPIRED_TIME, INSIGHT_CACHE } from './utils/Const'; +import { EXPIRED_TIME, CACHE_KEY } from './utils'; import { getIp } from './utils/Network'; // initialize express app export const app = express(); // initialize cache store -const insightCache = new LruCache({ +const cache = new LruCache({ maxAge: EXPIRED_TIME, updateAgeOnGet: true, }); @@ -54,7 +54,7 @@ const server = http.createServer(app); const PORT = 3000; // setup middlewares // use cache -app.set(INSIGHT_CACHE, insightCache); +app.set(CACHE_KEY, cache); // use cors https://expressjs.com/en/resources/middleware/cors.html app.use(cors()); // use helmet https://github.com/helmetjs/helmet diff --git a/server/src/collections/collections.controller.ts b/server/src/collections/collections.controller.ts index c3bfbab0..1c8d71ca 100644 --- a/server/src/collections/collections.controller.ts +++ b/server/src/collections/collections.controller.ts @@ -84,8 +84,8 @@ export class CollectionController { ); // segments - this.router.get('/:name/psegments', this.getPSegement.bind(this)); - this.router.get('/:name/qsegments', this.getQSegement.bind(this)); + this.router.get('/:name/psegments', this.getPSegment.bind(this)); + this.router.get('/:name/qsegments', this.getQSegment.bind(this)); this.router.put('/:name/compact', this.compact.bind(this)); return this.router; @@ -335,7 +335,7 @@ export class CollectionController { } } - async getPSegement(req: Request, res: Response, next: NextFunction) { + async getPSegment(req: Request, res: Response, next: NextFunction) { const name = req.params?.name; try { const result = await this.collectionsService.getPersistentSegmentInfo({ @@ -347,7 +347,7 @@ export class CollectionController { } } - async getQSegement(req: Request, res: Response, next: NextFunction) { + async getQSegment(req: Request, res: Response, next: NextFunction) { const name = req.params?.name; try { const result = await this.collectionsService.getQuerySegmentInfo({ diff --git a/server/src/collections/collections.service.ts b/server/src/collections/collections.service.ts index 7e212b66..84347c3d 100644 --- a/server/src/collections/collections.service.ts +++ b/server/src/collections/collections.service.ts @@ -21,13 +21,11 @@ import { GePersistentSegmentInfoReq, CompactReq, } from '@zilliz/milvus2-sdk-node'; -import { throwErrorFromSDK } from '../utils/Error'; -import { findKeyValue, genRows } from '../utils/Helper'; -import { ROW_COUNT } from '../utils/Const'; +import { throwErrorFromSDK, findKeyValue, genRows, ROW_COUNT } from '../utils'; import { QueryDto, ImportSampleDto, GetReplicasDto } from './dto'; export class CollectionsService { - constructor(private milvusService: MilvusService) {} + constructor(private milvusService: MilvusService) { } async getCollections(data?: ShowCollectionsReq) { const res = await this.milvusService.client.showCollections(data); @@ -189,8 +187,8 @@ export class CollectionsService { try { replicas = loadCollection ? await this.getReplicas({ - collectionID: collectionInfo.collectionID, - }) + collectionID: collectionInfo.collectionID, + }) : replicas; } catch (e) { console.log('ignore getReplica'); diff --git a/server/src/collections/swagger.yml b/server/src/collections/swagger.yml deleted file mode 100644 index 82983ed1..00000000 --- a/server/src/collections/swagger.yml +++ /dev/null @@ -1,247 +0,0 @@ -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":""} diff --git a/server/src/crons/crons.controller.ts b/server/src/crons/crons.controller.ts index c9698300..aeedd40f 100644 --- a/server/src/crons/crons.controller.ts +++ b/server/src/crons/crons.controller.ts @@ -3,7 +3,7 @@ import { dtoValidationMiddleware } from '../middleware/validation'; import { CronsService, SchedulerRegistry } from './crons.service'; import { collectionsService } from '../collections'; import { ToggleCronJobByNameDto } from './dto'; -import { MILVUS_ADDRESS } from '../utils/Const'; +import { MILVUS_ADDRESS } from '../utils'; export class CronsController { private router: Router; diff --git a/server/src/crons/crons.service.ts b/server/src/crons/crons.service.ts index 7fa7acff..3751c3c4 100644 --- a/server/src/crons/crons.service.ts +++ b/server/src/crons/crons.service.ts @@ -1,6 +1,6 @@ -import { CollectionsService } from '../collections/collections.service'; -import { WS_EVENTS, WS_EVENTS_TYPE } from '../utils/Const'; import { schedule, ScheduledTask } from 'node-cron'; +import { CollectionsService } from '../collections/collections.service'; +import { WS_EVENTS, WS_EVENTS_TYPE } from '../utils'; import { pubSub } from '../events'; export class CronsService { diff --git a/server/src/crons/dto.ts b/server/src/crons/dto.ts index c091a9f1..3fe24bd1 100644 --- a/server/src/crons/dto.ts +++ b/server/src/crons/dto.ts @@ -1,5 +1,5 @@ import { IsEnum, IsString } from "class-validator"; -import { WS_EVENTS_TYPE } from "../utils/Const"; +import { WS_EVENTS_TYPE } from "../utils"; export class ToggleCronJobByNameDto { @IsString() diff --git a/server/src/crons/swagger.yml b/server/src/crons/swagger.yml deleted file mode 100644 index 3f112855..00000000 --- a/server/src/crons/swagger.yml +++ /dev/null @@ -1,28 +0,0 @@ -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 - - \ No newline at end of file diff --git a/server/src/middleware/index.ts b/server/src/middleware/index.ts index b9745347..43725eb6 100644 --- a/server/src/middleware/index.ts +++ b/server/src/middleware/index.ts @@ -2,9 +2,8 @@ import { Request, Response, NextFunction } from 'express'; import morgan from 'morgan'; import chalk from 'chalk'; import { MilvusService } from '../milvus/milvus.service'; -import { INSIGHT_CACHE, MILVUS_ADDRESS } from '../utils/Const'; +import { CACHE_KEY, MILVUS_ADDRESS, HTTP_STATUS_CODE } from '../utils'; import { HttpError } from 'http-errors'; -import { HTTP_STATUS_CODE } from '../utils/Error'; import HttpErrors from 'http-errors'; export const ReqHeaderMiddleware = ( @@ -12,7 +11,7 @@ export const ReqHeaderMiddleware = ( res: Response, next: NextFunction ) => { - const insightCache = req.app.get(INSIGHT_CACHE); + const cache = req.app.get(CACHE_KEY); // all ape requests need set milvus address in header. // server will set active address in milvus service. const milvusAddress = (req.headers[MILVUS_ADDRESS] as string) || ''; @@ -21,10 +20,10 @@ export const ReqHeaderMiddleware = ( // only api request has MILVUS_ADDRESS. // When client run in express, we dont need static files like: xx.js run this logic. // Otherwise will cause 401 error. - if (milvusAddress && insightCache.has(milvusAddress)) { + if (milvusAddress && cache.has(milvusAddress)) { MilvusService.activeAddress = milvusAddress; // insight cache will update expire time when use insightCache.get - MilvusService.activeMilvusClient = insightCache.get(milvusAddress); + MilvusService.activeMilvusClient = cache.get(milvusAddress); } const CONNECT_URL = `/api/v1/milvus/connect`; diff --git a/server/src/milvus/milvus.controller.ts b/server/src/milvus/milvus.controller.ts index dd1d8e8f..4626c56b 100644 --- a/server/src/milvus/milvus.controller.ts +++ b/server/src/milvus/milvus.controller.ts @@ -2,7 +2,7 @@ import { NextFunction, Request, Response, Router } from 'express'; import { dtoValidationMiddleware } from '../middleware/validation'; import { MilvusService } from './milvus.service'; import { ConnectMilvusDto, FlushDto, UseDatabaseDto } from './dto'; -import { INSIGHT_CACHE } from '../utils/Const'; +import { CACHE_KEY } from '../utils'; import packageJson from '../../package.json'; export class MilvusController { @@ -44,11 +44,11 @@ export class MilvusController { async connectMilvus(req: Request, res: Response, next: NextFunction) { const { address, username, password } = req.body; - const insightCache = req.app.get(INSIGHT_CACHE); + const cache = req.app.get(CACHE_KEY); try { const result = await this.milvusService.connectMilvus( { address, username, password }, - insightCache + cache ); res.send(result); @@ -60,13 +60,10 @@ export class MilvusController { async checkConnect(req: Request, res: Response, next: NextFunction) { const address = '' + req.query?.address; - const insightCache = req.app.get(INSIGHT_CACHE); + const cache = req.app.get(CACHE_KEY); try { - const result = await this.milvusService.checkConnect( - address, - insightCache - ); + const result = await this.milvusService.checkConnect(address, cache); res.send(result); } catch (error) { next(error); diff --git a/server/src/milvus/milvus.service.ts b/server/src/milvus/milvus.service.ts index fef6b88e..09345b01 100644 --- a/server/src/milvus/milvus.service.ts +++ b/server/src/milvus/milvus.service.ts @@ -5,8 +5,8 @@ import { } from '@zilliz/milvus2-sdk-node'; import HttpErrors from 'http-errors'; import LruCache from 'lru-cache'; -import { HTTP_STATUS_CODE } from '../utils/Error'; -import { DEFAULT_MILVUS_PORT } from '../utils/Const'; +import { HTTP_STATUS_CODE } from '../utils/Const'; +import { DEFAULT_MILVUS_PORT } from '../utils'; import { connectivityState } from '@grpc/grpc-js'; export class MilvusService { diff --git a/server/src/milvus/swagger.yml b/server/src/milvus/swagger.yml deleted file mode 100644 index 2dc38307..00000000 --- a/server/src/milvus/swagger.yml +++ /dev/null @@ -1,80 +0,0 @@ -paths: - /milvus/connect: - post: - tags: - - Milvus - description: Connect to milvus server - 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/disconnect: - post: - tags: - - Milvus - description: Disconnect to milvus server - 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 diff --git a/server/src/partitions/partitions.service.ts b/server/src/partitions/partitions.service.ts index f1b8c70b..2c26aa39 100644 --- a/server/src/partitions/partitions.service.ts +++ b/server/src/partitions/partitions.service.ts @@ -9,7 +9,7 @@ import { } from '@zilliz/milvus2-sdk-node'; import { throwErrorFromSDK } from '../utils/Error'; import { findKeyValue } from '../utils/Helper'; -import { ROW_COUNT } from '../utils/Const'; +import { ROW_COUNT } from '../utils'; export class PartitionsService { constructor(private milvusService: MilvusService) {} diff --git a/server/src/partitions/swagger.yml b/server/src/partitions/swagger.yml deleted file mode 100644 index 818a0144..00000000 --- a/server/src/partitions/swagger.yml +++ /dev/null @@ -1,97 +0,0 @@ -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 - \ No newline at end of file diff --git a/server/src/schema/swagger.yml b/server/src/schema/swagger.yml deleted file mode 100644 index 2e911255..00000000 --- a/server/src/schema/swagger.yml +++ /dev/null @@ -1,78 +0,0 @@ -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 \ No newline at end of file diff --git a/server/src/utils/Const.ts b/server/src/utils/Const.ts index d5014c53..4726c9fd 100644 --- a/server/src/utils/Const.ts +++ b/server/src/utils/Const.ts @@ -1,10 +1,11 @@ +// note, this module will be shared between server and client, so please don't import server only module here export const ROW_COUNT = 'row_count'; // use in req header export const MILVUS_ADDRESS = 'milvus-address'; // for lru cache -export const INSIGHT_CACHE = 'insight_cache'; +export const CACHE_KEY = 'insight_cache'; export const EXPIRED_TIME = 1000 * 60 * 60 * 24; export enum LOADING_STATE { @@ -23,3 +24,53 @@ export enum WS_EVENTS_TYPE { } export const DEFAULT_MILVUS_PORT = 19530; + +export enum HTTP_STATUS_CODE { + CONTINUE = 100, + SWITCHING_PROTOCOLS = 101, + PROCESSING = 102, + EARLYHINTS = 103, + OK = 200, + CREATED = 201, + ACCEPTED = 202, + NON_AUTHORITATIVE_INFORMATION = 203, + NO_CONTENT = 204, + RESET_CONTENT = 205, + PARTIAL_CONTENT = 206, + AMBIGUOUS = 300, + MOVED_PERMANENTLY = 301, + FOUND = 302, + SEE_OTHER = 303, + NOT_MODIFIED = 304, + TEMPORARY_REDIRECT = 307, + PERMANENT_REDIRECT = 308, + BAD_REQUEST = 400, + UNAUTHORIZED = 401, + PAYMENT_REQUIRED = 402, + FORBIDDEN = 403, + NOT_FOUND = 404, + METHOD_NOT_ALLOWED = 405, + NOT_ACCEPTABLE = 406, + PROXY_AUTHENTICATION_REQUIRED = 407, + REQUEST_TIMEOUT = 408, + CONFLICT = 409, + GONE = 410, + LENGTH_REQUIRED = 411, + PRECONDITION_FAILED = 412, + PAYLOAD_TOO_LARGE = 413, + URI_TOO_LONG = 414, + UNSUPPORTED_MEDIA_TYPE = 415, + REQUESTED_RANGE_NOT_SATISFIABLE = 416, + EXPECTATION_FAILED = 417, + I_AM_A_TEAPOT = 418, + MISDIRECTED = 421, + UNPROCESSABLE_ENTITY = 422, + FAILED_DEPENDENCY = 424, + TOO_MANY_REQUESTS = 429, + INTERNAL_SERVER_ERROR = 500, + NOT_IMPLEMENTED = 501, + BAD_GATEWAY = 502, + SERVICE_UNAVAILABLE = 503, + GATEWAY_TIMEOUT = 504, + HTTP_VERSION_NOT_SUPPORTED = 505, +} diff --git a/server/src/utils/Error.ts b/server/src/utils/Error.ts index 3e4871d4..0ec64139 100644 --- a/server/src/utils/Error.ts +++ b/server/src/utils/Error.ts @@ -8,53 +8,3 @@ export const throwErrorFromSDK = (res: ResStatus) => { throw res.reason; } }; - -export enum HTTP_STATUS_CODE { - CONTINUE = 100, - SWITCHING_PROTOCOLS = 101, - PROCESSING = 102, - EARLYHINTS = 103, - OK = 200, - CREATED = 201, - ACCEPTED = 202, - NON_AUTHORITATIVE_INFORMATION = 203, - NO_CONTENT = 204, - RESET_CONTENT = 205, - PARTIAL_CONTENT = 206, - AMBIGUOUS = 300, - MOVED_PERMANENTLY = 301, - FOUND = 302, - SEE_OTHER = 303, - NOT_MODIFIED = 304, - TEMPORARY_REDIRECT = 307, - PERMANENT_REDIRECT = 308, - BAD_REQUEST = 400, - UNAUTHORIZED = 401, - PAYMENT_REQUIRED = 402, - FORBIDDEN = 403, - NOT_FOUND = 404, - METHOD_NOT_ALLOWED = 405, - NOT_ACCEPTABLE = 406, - PROXY_AUTHENTICATION_REQUIRED = 407, - REQUEST_TIMEOUT = 408, - CONFLICT = 409, - GONE = 410, - LENGTH_REQUIRED = 411, - PRECONDITION_FAILED = 412, - PAYLOAD_TOO_LARGE = 413, - URI_TOO_LONG = 414, - UNSUPPORTED_MEDIA_TYPE = 415, - REQUESTED_RANGE_NOT_SATISFIABLE = 416, - EXPECTATION_FAILED = 417, - I_AM_A_TEAPOT = 418, - MISDIRECTED = 421, - UNPROCESSABLE_ENTITY = 422, - FAILED_DEPENDENCY = 424, - TOO_MANY_REQUESTS = 429, - INTERNAL_SERVER_ERROR = 500, - NOT_IMPLEMENTED = 501, - BAD_GATEWAY = 502, - SERVICE_UNAVAILABLE = 503, - GATEWAY_TIMEOUT = 504, - HTTP_VERSION_NOT_SUPPORTED = 505, -} diff --git a/server/src/utils/index.ts b/server/src/utils/index.ts index addb908b..4a00787e 100644 --- a/server/src/utils/index.ts +++ b/server/src/utils/index.ts @@ -1,12 +1,12 @@ -import glob from "glob"; -import fs from "fs"; +import glob from 'glob'; +import fs from 'fs'; // Utils: read files under specified directories export const getDirectories = ( src: string, callback: (err: Error, res: string[]) => void ) => { - glob(src + "/**/*", callback); + glob(src + '/**/*', callback); }; // sync: read files under specified directories @@ -15,7 +15,7 @@ export const getDirectoriesSync = ( callback: (err: Error, res: string[]) => void ) => { try { - const results = glob.sync(src + "/**/*"); + const results = glob.sync(src + '/**/*'); callback(undefined, results); } catch (error) { callback(error, []); @@ -28,12 +28,12 @@ export const generateCfgs = ( isSrcPlugin: boolean = true ) => { dirRes.forEach((item: string) => { - if (item.endsWith("/config.json")) { + if (item.endsWith('/config.json')) { const fileData = fs.readFileSync(item); const jsonData = JSON.parse(fileData.toString()); const apiPath = jsonData?.server?.api; - const dirName = item.split("/config.json").shift().split("/").pop(); - const dir = item.split("/config.json").shift(); + const dirName = item.split('/config.json').shift().split('/').pop(); + const dir = item.split('/config.json').shift(); const cfg = { path: item, dir, @@ -48,3 +48,8 @@ export const generateCfgs = ( } }); }; + +export * from './Const'; +export * from './Error'; +export * from './Helper'; +export * from './Network';