Browse Source

add partition api

nameczz 4 years ago
parent
commit
a20156c6b2

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

@@ -88,7 +88,7 @@ export class CollectionsService {
         });
         data.push({
           collection_name: name,
-          // schema: collectionInfo.schema,
+          schema: collectionInfo.schema,
           description: collectionInfo.schema.description,
           autoID: collectionInfo.schema.autoID,
           rowCount: findKeyValue(collectionStatistics.stats, ROW_COUNT),

+ 43 - 1
server/src/partitions/dto.ts

@@ -1,5 +1,15 @@
-import { IsNotEmpty, IsString } from 'class-validator';
+import {
+  IsNotEmpty,
+  IsString,
+  IsEnum,
+  IsArray,
+  ArrayNotEmpty,
+} from 'class-validator';
 
+export enum ManageType {
+  DELETE = 'delete',
+  CREATE = 'create',
+}
 export class GetPartitionsInfo {
   @IsString()
   @IsNotEmpty({
@@ -7,3 +17,35 @@ export class GetPartitionsInfo {
   })
   readonly collection_name: string;
 }
+
+export class ManagePartition {
+  @IsString()
+  @IsNotEmpty({
+    message: 'collection_name is empty',
+  })
+  readonly collection_name: string;
+
+  @IsString()
+  @IsNotEmpty({
+    message: 'partition_name is empty',
+  })
+  readonly partition_name: string;
+
+  @IsEnum(ManageType, { message: 'Type allow delete and create' })
+  readonly type: ManageType;
+}
+
+export class LoadPartitions {
+  @IsString()
+  @IsNotEmpty({
+    message: 'collection_name is empty',
+  })
+  readonly collection_name: string;
+
+  @IsArray()
+  @ArrayNotEmpty()
+  @IsNotEmpty({
+    message: 'partition_names is empty',
+  })
+  readonly partition_names: string[];
+}

+ 31 - 1
server/src/partitions/partitions.controller.ts

@@ -1,11 +1,19 @@
 import {
+  Body,
   Controller,
   Get,
+  Post,
+  Put,
   Query,
   UsePipes,
   ValidationPipe,
 } from '@nestjs/common';
-import { GetPartitionsInfo } from './dto';
+import {
+  GetPartitionsInfo,
+  LoadPartitions,
+  ManagePartition,
+  ManageType,
+} from './dto';
 import { PartitionsService } from './partitions.service';
 
 @Controller('partitions')
@@ -17,4 +25,26 @@ export class PartitionsController {
   async getPartitions(@Query() query: GetPartitionsInfo) {
     return await this.partitionsService.getPatitionsInfo(query);
   }
+
+  @Post()
+  @UsePipes(new ValidationPipe())
+  async managePartition(@Body() body: ManagePartition) {
+    const { type, ...params } = body;
+
+    return type.toLocaleLowerCase() === ManageType.CREATE
+      ? await this.partitionsService.createParition(params)
+      : await this.partitionsService.deleteParition(params);
+  }
+
+  @Put('load')
+  @UsePipes(new ValidationPipe())
+  async loadPartition(@Body() body: LoadPartitions) {
+    return await this.partitionsService.loadPartitions(body);
+  }
+
+  @Put('release')
+  @UsePipes(new ValidationPipe())
+  async releasePartitions(@Body() body: LoadPartitions) {
+    return await this.partitionsService.loadPartitions(body);
+  }
 }