Skip to content

Commit

Permalink
refactor http export/import
Browse files Browse the repository at this point in the history
Signed-off-by: ruiyi.jiang <[email protected]>
  • Loading branch information
shanghaikid committed Aug 7, 2023
1 parent 8271ddc commit ccef94f
Show file tree
Hide file tree
Showing 35 changed files with 169 additions and 173 deletions.
2 changes: 1 addition & 1 deletion client/src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next';
import { makeStyles, Theme, createStyles, Typography } from '@material-ui/core';
import { useNavigate } from 'react-router-dom';
import { navContext, databaseContext, authContext } from '@/context';
import { MilvusHttp } from '@/http/Milvus';
import { MilvusHttp } from '@/http';
import { MILVUS_ADDRESS } from '@/consts';
import CustomSelector from '@/components/customSelector/CustomSelector';
import icons from '../icons/Icons';
Expand Down
2 changes: 1 addition & 1 deletion client/src/context/Auth.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext, useEffect, useState } from 'react';
import { MILVUS_ADDRESS } from '@/consts';
import { MilvusHttp } from '@/http/Milvus';
import { MilvusHttp } from '@/http';
import { AuthContextType } from './Types';

export const authContext = createContext<AuthContextType>({
Expand Down
2 changes: 1 addition & 1 deletion client/src/context/Database.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useEffect, useState } from 'react';
import { DatabaseHttp } from '@/http/Database';
import { DatabaseHttp } from '@/http';
import { DatabaseContextType } from './Types';

export const databaseContext = createContext<DatabaseContextType>({
Expand Down
2 changes: 1 addition & 1 deletion client/src/context/Prometheus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
WITH_PROMETHEUS,
} from '@/consts';
import { formatPrometheusAddress } from '@/utils';
import { PrometheusHttp } from '@/http/Prometheus';
import { PrometheusHttp } from '@/http';

export const prometheusContext = createContext<PrometheusContextType>({
withPrometheus: false,
Expand Down
2 changes: 1 addition & 1 deletion client/src/context/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from './Types';
import CustomSnackBar from '@/components/customSnackBar/CustomSnackBar';
import CustomDialog from '@/components/customDialog/CustomDialog';
import { MilvusHttp } from '@/http/Milvus';
import { MilvusHttp } from '@/http';
import { theme } from '../styles/theme';

const DefaultDialogConfigs: DialogType = {
Expand Down
4 changes: 1 addition & 3 deletions client/src/context/WebSocket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ 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 } from '@/http/Axios';
import { CollectionHttp } from '@/http/Collection';
import { MilvusHttp } from '@/http/Milvus';
import { url, CollectionHttp, MilvusHttp } from '@/http';
import { CollectionView } from '@/pages/collections/Types';
import { checkIndexBuilding, checkLoading } from '@/utils';
import { WebSocketType } from './Types';
Expand Down
117 changes: 10 additions & 107 deletions client/src/http/Index.ts
Original file line number Diff line number Diff line change
@@ -1,107 +1,10 @@
import {
IndexCreateParam,
IndexManageParam,
IndexView,
} from '../pages/schema/Types';
import { ManageRequestMethods } from '../types/Common';
import { IndexState } from '../types/Milvus';
import { findKeyValue } from '../utils/Common';
import { getKeyValueListFromJsonString } from '../utils/Format';
import BaseModel from './BaseModel';

export class IndexHttp extends BaseModel implements IndexView {
params!: { key: string; value: string }[];
field_name!: string;
index_name!: string;

constructor(props: {}) {
super(props);
Object.assign(this, props);
}

static BASE_URL = `/schema/index`;

static async getIndexStatus(
collectionName: string,
fieldName: string,
indexName: string
): Promise<{ state: IndexState }> {
const path = `${this.BASE_URL}/state`;
return super.search({
path,
params: {
collection_name: collectionName,
field_name: fieldName,
index_name: indexName,
},
});
}

static async getIndexInfo(collectionName: string): Promise<IndexHttp[]> {
const path = this.BASE_URL;

const res = await super.findAll({
path,
params: { collection_name: collectionName },
});
return res.index_descriptions.map((index: any) => new this(index));
}

static async createIndex(param: IndexCreateParam) {
const path = this.BASE_URL;
const type: ManageRequestMethods = ManageRequestMethods.CREATE;

return super.create({
path,
data: { ...param, type },
});
}

static async deleteIndex(param: IndexManageParam) {
const path = this.BASE_URL;
const type: ManageRequestMethods = ManageRequestMethods.DELETE;

return super.batchDelete({ path, data: { ...param, type } });
}

static async getIndexBuildProgress(
collectionName: string,
fieldName: string,
indexName: string
) {
const path = `${this.BASE_URL}/progress`;
return super.search({
path,
params: {
collection_name: collectionName,
field_name: fieldName,
index_name: indexName,
},
});
}

get _indexType() {
return this.params.find(p => p.key === 'index_type')?.value || '';
}
get _indexName() {
return this.index_name;
}

get _indexParameterPairs() {
const metricType = this.params.filter(v => v.key === 'metric_type');
// parms is json string, so we need parse it to key value array
const params = findKeyValue(this.params, 'params');
if (params) {
return [...metricType, ...getKeyValueListFromJsonString(params)];
}
return metricType;
}

get _fieldName() {
return this.field_name;
}

get _metricType() {
return this.params.find(p => p.key === 'metric_type')?.value || '';
}
}
export * from './Axios';
export * from './BaseModel';
export * from './Collection';
export * from './Database';
export * from './Milvus';
export * from './MilvusIndex';
export * from './Field';
export * from './Partition';
export * from './Prometheus';
export * from './User';
107 changes: 107 additions & 0 deletions client/src/http/MilvusIndex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import {
IndexCreateParam,
IndexManageParam,
IndexView,
} from '../pages/schema/Types';
import { ManageRequestMethods } from '../types/Common';
import { IndexState } from '../types/Milvus';
import { findKeyValue } from '../utils/Common';
import { getKeyValueListFromJsonString } from '../utils/Format';
import BaseModel from './BaseModel';

export class IndexHttp extends BaseModel implements IndexView {
params!: { key: string; value: string }[];
field_name!: string;
index_name!: string;

constructor(props: {}) {
super(props);
Object.assign(this, props);
}

static BASE_URL = `/schema/index`;

static async getIndexStatus(
collectionName: string,
fieldName: string,
indexName: string
): Promise<{ state: IndexState }> {
const path = `${this.BASE_URL}/state`;
return super.search({
path,
params: {
collection_name: collectionName,
field_name: fieldName,
index_name: indexName,
},
});
}

static async getIndexInfo(collectionName: string): Promise<IndexHttp[]> {
const path = this.BASE_URL;

const res = await super.findAll({
path,
params: { collection_name: collectionName },
});
return res.index_descriptions.map((index: any) => new this(index));
}

static async createIndex(param: IndexCreateParam) {
const path = this.BASE_URL;
const type: ManageRequestMethods = ManageRequestMethods.CREATE;

return super.create({
path,
data: { ...param, type },
});
}

static async deleteIndex(param: IndexManageParam) {
const path = this.BASE_URL;
const type: ManageRequestMethods = ManageRequestMethods.DELETE;

return super.batchDelete({ path, data: { ...param, type } });
}

static async getIndexBuildProgress(
collectionName: string,
fieldName: string,
indexName: string
) {
const path = `${this.BASE_URL}/progress`;
return super.search({
path,
params: {
collection_name: collectionName,
field_name: fieldName,
index_name: indexName,
},
});
}

get _indexType() {
return this.params.find(p => p.key === 'index_type')?.value || '';
}
get _indexName() {
return this.index_name;
}

get _indexParameterPairs() {
const metricType = this.params.filter(v => v.key === 'metric_type');
// parms is json string, so we need parse it to key value array
const params = findKeyValue(this.params, 'params');
if (params) {
return [...metricType, ...getKeyValueListFromJsonString(params)];
}
return metricType;
}

get _fieldName() {
return this.field_name;
}

get _metricType() {
return this.params.find(p => p.key === 'metric_type')?.value || '';
}
}
2 changes: 1 addition & 1 deletion client/src/pages/collections/Aliases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import icons from '@/components/icons/Icons';
import DeleteIcon from '@material-ui/icons/Delete';
import CreateAliasDialog from '../dialogs/CreateAliasDialog';
import DeleteTemplate from '@/components/customDialog/DeleteDialogTemplate';
import { CollectionHttp } from '@/http/Collection';
import { CollectionHttp } from '@/http';

const useStyles = makeStyles((theme: Theme) => ({
wrapper: {
Expand Down
3 changes: 1 addition & 2 deletions client/src/pages/collections/Collections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import { ChildrenStatusType } from '@/components/status/Types';
import StatusIcon from '@/components/status/StatusIcon';
import CustomToolTip from '@/components/customToolTip/CustomToolTip';
import CreateCollectionDialog from '../dialogs/CreateCollectionDialog';
import { CollectionHttp } from '@/http/Collection';
import { CollectionHttp, MilvusHttp } from '@/http';
import LoadCollectionDialog from '../dialogs/LoadCollectionDialog';
import ReleaseCollectionDialog from '../dialogs/ReleaseCollectionDialog';
import DropCollectionDialog from '../dialogs/DropCollectionDialog';
import RenameCollectionDialog from '../dialogs/RenameCollectionDialog';
import InsertDialog from '../dialogs/insert/Dialog';
import ImportSampleDialog from '../dialogs/ImportSampleDialog';
import { MilvusHttp } from '@/http/Milvus';
import { LOADING_STATE, WS_EVENTS, WS_EVENTS_TYPE } from '@/consts';
import { checkIndexBuilding, checkLoading } from '@/utils';
import Aliases from './Aliases';
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/connect/AuthForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import icons from '@/components/icons/Icons';
import { ITextfieldConfig } from '@/components/customInput/Types';
import { useFormValidation } from '@/hooks';
import { formatForm } from '@/utils';
import { MilvusHttp } from '@/http/Milvus';
import { MilvusHttp } from '@/http';
import { useNavigate } from 'react-router-dom';
import { rootContext, authContext, prometheusContext } from '@/context';
import { MILVUS_ADDRESS, LAST_TIME_ADDRESS, MILVUS_URL } from '@/consts';
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/database/Database.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useContext, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { DatabaseHttp } from '@/http/Database';
import { DatabaseHttp } from '@/http';
import AttuGrid from '@/components/grid/Grid';
import { ColDefinitionsType, ToolBarConfig } from '@/components/grid/Types';
import {
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/dialogs/CreateAliasDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CustomInput from '@/components/customInput/CustomInput';
import { formatForm } from '@/utils';
import { useFormValidation } from '@/hooks';
import { ITextfieldConfig } from '@/components/customInput/Types';
import { CollectionHttp } from '@/http/Collection';
import { CollectionHttp } from '@/http';
import { CreateAliasProps } from './Types';

const useStyles = makeStyles((theme: Theme) => ({
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/dialogs/CreateCollectionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { rootContext } from '@/context';
import { useFormValidation } from '@/hooks';
import { formatForm, TypeEnum } from '@/utils';
import CreateFields from '../collections/CreateFields';
import { CollectionHttp } from '@/http/Collection';
import { CollectionHttp } from '@/http';
import {
CollectionCreateParam,
CollectionCreateProps,
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/dialogs/CreatePartitionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import CustomInput from '@/components/customInput/CustomInput';
import { ITextfieldConfig } from '@/components/customInput/Types';
import { useFormValidation } from '@/hooks';
import { formatForm } from '@/utils';
import { PartitionHttp } from '@/http';
import { PartitionCreateProps } from './Types';
import { PartitionManageParam } from '../partitions/Types';
import { ManageRequestMethods } from '../../types/Common';
import { PartitionHttp } from '@/http/Partition';

const useStyles = makeStyles((theme: Theme) => ({
input: {
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/dialogs/DropCollectionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FC, useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { rootContext } from '@/context';
import DeleteTemplate from '@/components/customDialog/DeleteDialogTemplate';
import { CollectionHttp } from '@/http/Collection';
import { CollectionHttp } from '@/http';
import { DropCollectionProps } from './Types';

const DropCollectionDialog: FC<DropCollectionProps> = props => {
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/dialogs/DropPartitionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { FC, useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { rootContext } from '@/context';
import DeleteTemplate from '@/components/customDialog/DeleteDialogTemplate';
import { DropPartitionProps } from './Types';
import { PartitionHttp } from '@/http/Partition';
import { PartitionHttp } from '@/http';
import { PartitionManageParam } from '../partitions/Types';
import { ManageRequestMethods } from '../../types/Common';
import { DropPartitionProps } from './Types';

const DropPartitionDialog: FC<DropPartitionProps> = props => {
const { partitions, onDelete, collectionName } = props;
Expand Down
3 changes: 1 addition & 2 deletions client/src/pages/dialogs/ImportSampleDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import DialogTemplate from '@/components/customDialog/DialogTemplate';
import CustomSelector from '@/components/customSelector/CustomSelector';
import { rootContext } from '@/context';
import { InsertStatusEnum } from './insert/Types';
import { CollectionHttp } from '@/http/Collection';
import { MilvusHttp } from '@/http/Milvus';
import { CollectionHttp, MilvusHttp } from '@/http';
import { LoadSampleParam } from './Types';

const getStyles = makeStyles((theme: Theme) => {
Expand Down
Loading

0 comments on commit ccef94f

Please sign in to comment.