Browse Source

Merge remote-tracking branch 'upstream/main' into bugfix/style-adjust

tumao 4 years ago
parent
commit
c707d08688

+ 7 - 4
client/src/http/Collection.ts

@@ -1,6 +1,6 @@
 import { ChildrenStatusType, StatusEnum } from '../components/status/Types';
 import { CollectionView } from '../pages/collections/Types';
-import { IndexState } from '../types/Milvus';
+import { IndexState, ShowCollectionsType } from '../types/Milvus';
 import BaseModel from './BaseModel';
 
 export class CollectionHttp extends BaseModel implements CollectionView {
@@ -10,6 +10,7 @@ export class CollectionHttp extends BaseModel implements CollectionView {
   private rowCount!: string;
   private index_status!: string;
   private id!: string;
+  private isLoaded!: boolean;
 
   static COLLECTIONS_URL = '/collections';
   static COLLECTIONS_INDEX_STATUS_URL = '/collections/indexes/status';
@@ -22,8 +23,10 @@ export class CollectionHttp extends BaseModel implements CollectionView {
     Object.assign(this, props);
   }
 
-  static getCollections(): Promise<CollectionHttp[]> {
-    return super.findAll({ path: this.COLLECTIONS_URL, params: {} });
+  static getCollections(data?: {
+    type: ShowCollectionsType;
+  }): Promise<CollectionHttp[]> {
+    return super.findAll({ path: this.COLLECTIONS_URL, params: data || {} });
   }
 
   static createCollection(data: any) {
@@ -78,7 +81,7 @@ export class CollectionHttp extends BaseModel implements CollectionView {
   }
 
   get _status() {
-    return StatusEnum.loaded;
+    return this.isLoaded === true ? StatusEnum.loaded : StatusEnum.unloaded;
   }
 
   get _indexState() {

+ 19 - 41
client/src/pages/overview/Overview.tsx

@@ -7,6 +7,7 @@ import { StatusEnum } from '../../components/status/Types';
 import { useNavigationHook } from '../../hooks/Navigation';
 import { CollectionHttp } from '../../http/Collection';
 import { ALL_ROUTER_TYPES } from '../../router/Types';
+import { ShowCollectionsType } from '../../types/Milvus';
 import { formatNumber } from '../../utils/Common';
 import CollectionCard from './collectionCard/CollectionCard';
 import { CollectionData } from './collectionCard/Types';
@@ -39,10 +40,16 @@ const Overview = () => {
     totalData: 0,
   });
 
+  const [loadCollections, setLoadCollections] = useState<CollectionHttp[]>([]);
+
   useEffect(() => {
     const fetchData = async () => {
       const res = await CollectionHttp.getStatistics();
+      const loadCollections = await CollectionHttp.getCollections({
+        type: ShowCollectionsType.InMemory,
+      });
       setStatistics(res);
+      setLoadCollections(loadCollections);
     };
     fetchData();
   }, []);
@@ -52,7 +59,7 @@ const Overview = () => {
       data: [
         {
           label: overviewTrans('load'),
-          value: formatNumber(4337),
+          value: formatNumber(loadCollections.length),
           valueColor: '#07d197',
         },
         {
@@ -69,46 +76,17 @@ const Overview = () => {
         },
       ],
     };
-  }, [overviewTrans, statistics]);
+  }, [overviewTrans, statistics, loadCollections]);
 
-  const mockCollections: CollectionData[] = [
-    {
-      name: 'collection1',
-      id: 'c1',
-      status: StatusEnum.loaded,
-      rowCount: 2,
-    },
-    {
-      name: 'collection2',
-      id: 'c2',
-      status: StatusEnum.loaded,
-      rowCount: 2,
-    },
-    {
-      name: 'collection3',
-      id: 'c3',
-      status: StatusEnum.loaded,
-      rowCount: 2,
-    },
-    {
-      name: 'collection4',
-      id: 'c4',
+  const loadCollectionsData: CollectionData[] = useMemo(() => {
+    return loadCollections.map(v => ({
+      id: v._id,
+      name: v._name,
       status: StatusEnum.loaded,
-      rowCount: 2,
-    },
-    {
-      name: 'collection5',
-      id: 'c5',
-      status: StatusEnum.loaded,
-      rowCount: 2,
-    },
-    {
-      name: 'collection6',
-      id: 'c6',
-      status: StatusEnum.loaded,
-      rowCount: 2,
-    },
-  ];
+      rowCount: Number(v._rowCount),
+    }));
+  }, [loadCollections]);
+
   const CollectionIcon = icons.navCollection;
 
   return (
@@ -117,9 +95,9 @@ const Overview = () => {
       <Typography className={classes.collectionTitle}>
         {overviewTrans('load')}
       </Typography>
-      {mockCollections.length > 0 ? (
+      {loadCollectionsData.length > 0 ? (
         <div className={classes.cardsWrapper}>
-          {mockCollections.map(collection => (
+          {loadCollectionsData.map(collection => (
             <CollectionCard key={collection.id} data={collection} />
           ))}
         </div>

+ 2 - 2
client/src/pages/overview/collectionCard/CollectionCard.tsx

@@ -56,7 +56,7 @@ const CollectionCard: FC<CollectionCardProps> = ({
   wrapperClass = '',
 }) => {
   const classes = useStyles();
-  const { name, status, id, rowCount } = data;
+  const { name, status, rowCount } = data;
   const RightArrowIcon = icons.rightArrow;
   const InfoIcon = icons.info;
   const ReleaseIcon = icons.release;
@@ -73,7 +73,7 @@ const CollectionCard: FC<CollectionCardProps> = ({
       <Link
         classes={{ root: classes.link }}
         underline="none"
-        href={`/collection/${id}`}
+        href={`/collections/${name}`}
       >
         {name}
         <RightArrowIcon classes={{ root: classes.icon }} />

+ 5 - 0
client/src/types/Milvus.ts

@@ -5,3 +5,8 @@ export enum IndexState {
   Finished = 'Finished',
   Failed = 'Failed',
 }
+
+export enum ShowCollectionsType {
+  All = 0,
+  InMemory = 1,
+}

+ 4 - 1
server/nest-cli.json

@@ -1,4 +1,7 @@
 {
   "collection": "@nestjs/schematics",
-  "sourceRoot": "src"
+  "sourceRoot": "src",
+  "compilerOptions": {
+    "plugins": ["@nestjs/swagger"]
+  }
 }

+ 1 - 1
server/package.json

@@ -30,7 +30,7 @@
     "@nestjs/swagger": "^4.8.0",
     "@types/passport-jwt": "^3.0.5",
     "@types/passport-local": "^1.0.33",
-    "@zilliz/milvus-sdk-node-dev": "^0.1.4",
+    "@zilliz/milvus2-sdk-node": "^0.1.0",
     "class-transformer": "^0.4.0",
     "class-validator": "^0.13.1",
     "passport": "^0.4.1",

+ 8 - 3
server/src/collections/collections.controller.ts

@@ -6,19 +6,24 @@ import {
   Param,
   Post,
   Put,
+  Query,
   UsePipes,
   ValidationPipe,
 } from '@nestjs/common';
+import { ApiTags } from '@nestjs/swagger';
 import { CollectionsService } from './collections.service';
-import { CreateCollection } from './dto';
+import { CreateCollection, ShowCollections } from './dto';
 
+@ApiTags('collections')
 @Controller('collections')
 export class CollectionsController {
   constructor(private collectionsService: CollectionsService) {}
 
   @Get()
-  async getCollections() {
-    return await this.collectionsService.showCollections();
+  async getCollections(@Query() data?: ShowCollections) {
+    return Number(data.type) === 1
+      ? await this.collectionsService.getLoadedColletions()
+      : await this.collectionsService.getAllCollections();
   }
 
   @Get('statistics')

+ 32 - 4
server/src/collections/collections.service.ts

@@ -8,10 +8,14 @@ import {
   GetIndexStateReq,
   LoadCollectionReq,
   ReleaseLoadCollectionReq,
-} from '@zilliz/milvus-sdk-node-dev/dist/milvus/types';
+} from '@zilliz/milvus2-sdk-node/dist/milvus/types';
 import { throwErrorFromSDK } from '../utils/Error';
 import { findKeyValue } from '../utils/Helper';
 import { ROW_COUNT } from '../utils/Const';
+import {
+  ShowCollectionsReq,
+  ShowCollectionsType,
+} from '@zilliz/milvus2-sdk-node/dist/milvus/types/Collection';
 @Injectable()
 export class CollectionsService {
   constructor(private milvusService: MilvusService) {}
@@ -20,8 +24,8 @@ export class CollectionsService {
     return this.milvusService.milvusClientGetter;
   }
 
-  async getCollectionNames() {
-    const res = await this.milvusClient.showCollections();
+  async getCollectionNames(data?: ShowCollectionsReq) {
+    const res = await this.milvusClient.showCollections(data);
     throwErrorFromSDK(res.status);
     return res;
   }
@@ -78,9 +82,12 @@ export class CollectionsService {
    * Get all collections meta data
    * @returns {id:string, collection_name:string, schema:Field[], autoID:boolean, rowCount: string}
    */
-  async showCollections() {
+  async getAllCollections() {
     const data = [];
     const res = await this.getCollectionNames();
+    const loadedCollections = await this.getCollectionNames({
+      type: ShowCollectionsType.InMemory,
+    });
     if (res.collection_names.length > 0) {
       for (const name of res.collection_names) {
         const collectionInfo = await this.describeCollection({
@@ -96,6 +103,27 @@ export class CollectionsService {
           autoID: collectionInfo.schema.autoID,
           rowCount: findKeyValue(collectionStatistics.stats, ROW_COUNT),
           id: collectionInfo.collectionID,
+          isLoaded: loadedCollections.collection_names.includes(name),
+        });
+      }
+    }
+    return data;
+  }
+
+  async getLoadedColletions() {
+    const data = [];
+    const res = await this.getCollectionNames({
+      type: ShowCollectionsType.InMemory,
+    });
+    if (res.collection_names.length > 0) {
+      for (const [index, value] of res.collection_names.entries()) {
+        const collectionStatistics = await this.getCollectionStatistics({
+          collection_name: value,
+        });
+        data.push({
+          id: res.collection_ids[index],
+          collection_name: value,
+          rowCount: findKeyValue(collectionStatistics.stats, ROW_COUNT),
         });
       }
     }

+ 27 - 4
server/src/collections/dto.ts

@@ -5,24 +5,37 @@ import {
   IsOptional,
   IsArray,
   ArrayNotEmpty,
+  IsEnum,
 } from 'class-validator';
-import { FieldType } from '@zilliz/milvus-sdk-node-dev/dist/milvus/types/Collection'; // todo: need improve like export types in root file.
+import {
+  FieldType,
+  ShowCollectionsType,
+} from '@zilliz/milvus2-sdk-node/dist/milvus/types/Collection'; // todo: need improve like export types in root file.
+import { DataType } from '@zilliz/milvus2-sdk-node/dist/milvus/types/Common';
 import { ApiProperty } from '@nestjs/swagger';
 
 export class CreateCollection {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsNotEmpty({
     message: 'collection_name is empty',
   })
   readonly collection_name: string;
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Generate ID automatically by milvus',
+    type: Boolean,
+  })
   @IsBoolean()
   @IsOptional()
   readonly autoID: boolean;
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Field data type',
+    enum: DataType,
+  })
   @IsArray()
   @ArrayNotEmpty()
   @IsNotEmpty({
@@ -30,3 +43,13 @@ export class CreateCollection {
   })
   readonly fields: FieldType[];
 }
+
+export class ShowCollections {
+  @ApiProperty({
+    description: 'Type allow all->0 inmemory->1',
+    enum: ShowCollectionsType,
+  })
+  @IsOptional()
+  @IsEnum(ShowCollectionsType, { message: 'Type allow all->0 inmemory->1' })
+  readonly type: ShowCollectionsType;
+}

+ 2 - 2
server/src/main.ts

@@ -6,15 +6,15 @@ async function bootstrap() {
   const app = await NestFactory.create(AppModule, {
     cors: true,
   });
+  app.setGlobalPrefix('/api/v1');
 
   const config = new DocumentBuilder()
-    .setTitle('Milvus admin')
+    .setTitle('Milvus insight')
     .setVersion('1.0')
     .build();
   const document = SwaggerModule.createDocument(app, config);
   SwaggerModule.setup('api', app, document);
 
-  app.setGlobalPrefix('/api/v1');
   await app.listen(3000);
 }
 bootstrap();

+ 6 - 2
server/src/milvus/dto.ts

@@ -2,7 +2,9 @@ import { ApiProperty } from '@nestjs/swagger';
 import { IsNotEmpty, IsString } from 'class-validator';
 
 export class ConnectMilvus {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus url'
+  })
   @IsString()
   @IsNotEmpty({
     message: 'address is empty',
@@ -11,7 +13,9 @@ export class ConnectMilvus {
 }
 
 export class CheckMilvus {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus url'
+  })
   @IsString()
   @IsNotEmpty({
     message: 'address is empty',

+ 3 - 0
server/src/milvus/milvus.controller.ts

@@ -1,7 +1,10 @@
 import { Body, Controller, Get, Post, Query, UsePipes } from '@nestjs/common';
+import { ApiTags } from '@nestjs/swagger';
 import { ValidationPipe } from 'src/pipe/validation.pipe';
 import { CheckMilvus, ConnectMilvus } from './dto';
 import { MilvusService } from './milvus.service';
+
+@ApiTags('milvus')
 @Controller('milvus')
 export class MilvusController {
   constructor(private milvusService: MilvusService) {}

+ 1 - 1
server/src/milvus/milvus.service.ts

@@ -1,5 +1,5 @@
 import { Injectable } from '@nestjs/common';
-import { MilvusNode } from '@zilliz/milvus-sdk-node-dev';
+import { MilvusNode } from '@zilliz/milvus2-sdk-node';
 @Injectable()
 export class MilvusService {
   private milvusAddress: string;

+ 19 - 6
server/src/partitions/dto.ts

@@ -12,7 +12,9 @@ export enum ManageType {
   CREATE = 'create',
 }
 export class GetPartitionsInfo {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsNotEmpty({
     message: 'collection_name is empty',
@@ -21,34 +23,45 @@ export class GetPartitionsInfo {
 }
 
 export class ManagePartition {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsNotEmpty({
     message: 'collection_name is empty',
   })
   readonly collection_name: string;
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus partition name',
+  })
   @IsString()
   @IsNotEmpty({
     message: 'partition_name is empty',
   })
   readonly partition_name: string;
 
-  @ApiProperty({ enum: ManageType })
+  @ApiProperty({ 
+    description: 'Type allow delete and create',
+    enum: ManageType
+  })
   @IsEnum(ManageType, { message: 'Type allow delete and create' })
   readonly type: ManageType;
 }
 
 export class LoadPartitions {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsNotEmpty({
     message: 'collection_name is empty',
   })
   readonly collection_name: string;
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus partition name',
+  })
   @IsArray()
   @ArrayNotEmpty()
   @IsNotEmpty({

+ 2 - 0
server/src/partitions/partitions.controller.ts

@@ -8,6 +8,7 @@ import {
   UsePipes,
   ValidationPipe,
 } from '@nestjs/common';
+import { ApiTags } from '@nestjs/swagger';
 import {
   GetPartitionsInfo,
   LoadPartitions,
@@ -16,6 +17,7 @@ import {
 } from './dto';
 import { PartitionsService } from './partitions.service';
 
+@ApiTags('partitions')
 @Controller('partitions')
 export class PartitionsController {
   constructor(private partitionsService: PartitionsService) {}

+ 1 - 1
server/src/partitions/partitions.service.ts

@@ -7,7 +7,7 @@ import {
   LoadPartitionsReq,
   ReleasePartitionsReq,
   ShowPartitionsReq,
-} from '@zilliz/milvus-sdk-node-dev/dist/milvus/types'; // todo: need improve like export types in root file.
+} from '@zilliz/milvus2-sdk-node/dist/milvus/types'; // todo: need improve like export types in root file.
 import { throwErrorFromSDK } from 'src/utils/Error';
 import { findKeyValue } from '../utils/Helper';
 import { ROW_COUNT } from '../utils/Const';

+ 27 - 9
server/src/schema/dto.ts

@@ -24,14 +24,18 @@ export class ManageIndex {
   @IsEnum(ManageType, { message: 'Type allow delete and create' })
   readonly type: ManageType;
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsNotEmpty({
     message: 'collection_name is empty',
   })
   readonly collection_name: string;
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'field name',
+  })
   @IsString()
   @IsNotEmpty({
     message: 'field_name is empty',
@@ -47,49 +51,63 @@ export class ManageIndex {
 }
 
 export class DescribeIndex {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection description',
+  })
   @IsString()
   @IsNotEmpty({
     message: 'collection_name is empty',
   })
   readonly collection_name: string;
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'field name',
+  })
   @IsString()
   @IsOptional()
   readonly field_name?: string;
 }
 
 export class GetIndexState {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsNotEmpty({
     message: 'collection_name is empty',
   })
   readonly collection_name: string;
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'field name',
+  })
   @IsString()
   @IsOptional()
   readonly field_name?: string;
 }
 
 export class GetIndexProgress {
-  @ApiProperty()
+  @ApiProperty({
+    description: 'Milvus collection name',
+  })
   @IsString()
   @IsNotEmpty({
     message: 'collection_name is empty',
   })
   readonly collection_name: string;
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'index name',
+  })
   @IsString()
   @IsNotEmpty({
     message: 'index_name is empty',
   })
   readonly index_name: string;
 
-  @ApiProperty()
+  @ApiProperty({
+    description: 'field name',
+  })
   @IsString()
   @IsOptional()
   readonly field_name?: string;

+ 2 - 0
server/src/schema/schema.controller.ts

@@ -7,6 +7,7 @@ import {
   UsePipes,
   ValidationPipe,
 } from '@nestjs/common';
+import { ApiTags } from '@nestjs/swagger';
 import {
   DescribeIndex,
   GetIndexProgress,
@@ -16,6 +17,7 @@ import {
 } from './dto';
 import { SchemaService } from './schema.service';
 
+@ApiTags('schema')
 @Controller('schema')
 export class SchemaController {
   constructor(private schemaService: SchemaService) {}

+ 1 - 1
server/src/schema/schema.service.ts

@@ -5,7 +5,7 @@ import {
   DropIndexReq,
   GetIndexBuildProgressReq,
   GetIndexStateReq,
-} from '@zilliz/milvus-sdk-node-dev/dist/milvus/types';
+} from '@zilliz/milvus2-sdk-node/dist/milvus/types';
 import { throwErrorFromSDK } from 'src/utils/Error';
 import { MilvusService } from '../milvus/milvus.service';
 

+ 1 - 1
server/src/utils/Error.ts

@@ -1,7 +1,7 @@
 import {
   ErrorCode,
   ResStatus,
-} from '@zilliz/milvus-sdk-node-dev/dist/milvus/types/Response';
+} from '@zilliz/milvus2-sdk-node/dist/milvus/types/Response';
 
 export const throwErrorFromSDK = (res: ResStatus) => {
   if (res.error_code !== ErrorCode.SUCCESS) {

+ 1 - 1
server/src/utils/Helper.ts

@@ -1,4 +1,4 @@
-import { KeyValuePair } from '@zilliz/milvus-sdk-node-dev/dist/milvus/types/Common';
+import { KeyValuePair } from '@zilliz/milvus2-sdk-node/dist/milvus/types/Common';
 
 export const findKeyValue = (obj: KeyValuePair[], key: string) =>
   obj.find((v) => v.key === key)?.value;

+ 4 - 4
server/yarn.lock

@@ -1287,10 +1287,10 @@
   resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
   integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==
 
-"@zilliz/milvus-sdk-node-dev@^0.1.4":
-  version "0.1.4"
-  resolved "https://registry.yarnpkg.com/@zilliz/milvus-sdk-node-dev/-/milvus-sdk-node-dev-0.1.4.tgz#858e83b0ba0a309cbdf0b87e313b3b41de0052a4"
-  integrity sha512-4REU6TxqjsIZ7a7mL1M19IPg3oBBfE9kJmC7XUmcFz1+F2fYWpl7Iw4R8g69trpzUNnaFIBgwjAnSb0oVrRLeQ==
+"@zilliz/milvus2-sdk-node@^0.1.0":
+  version "0.1.0"
+  resolved "https://registry.yarnpkg.com/@zilliz/milvus2-sdk-node/-/milvus2-sdk-node-0.1.0.tgz#feab0f956a84f73e228d40ce4efc358e86c97e60"
+  integrity sha512-sehxvOndtqFknKdHYSaoks1kZo5q8t72mHqWiduIwsuIsCkpQMoOUyHOpWXvakWajrKrfksIdgn2oaUj5/JcBQ==
   dependencies:
     "@grpc/grpc-js" "^1.2.12"
     "@grpc/proto-loader" "^0.6.0"