Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
Signed-off-by: jingyang <3161362058@qq.com>
  • Loading branch information
zjy365 committed Nov 24, 2023
1 parent 8fbec57 commit 67e5d44
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 30 deletions.
3 changes: 3 additions & 0 deletions frontend/providers/dbprovider/src/api/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ export const getLogByNameAndContainerName = (data: {

export const getPodStatusByName = (podName: string) =>
GET(`/api/pod/getPodStatus?podName=${podName}`);

export const deleteMigrateJobByName = (name: string) =>
DELETE(`/api/migrate/delJobByName?name=${name}`);
3 changes: 1 addition & 2 deletions frontend/providers/dbprovider/src/api/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { Response as EnvResponse } from '@/pages/api/getEnv';
import type { Response as DBVersionMapType } from '@/pages/api/platform/getVersion';
import type { Response as resourcePriceResponse } from '@/pages/api/platform/resourcePrice';
import { GET, POST } from '@/services/request';

import type { UserQuotaItemType } from '@/types/user';
import axios, { AxiosProgressEvent } from 'axios';
import { AxiosProgressEvent } from 'axios';

export const getResourcePrice = () => GET<resourcePriceResponse>('/api/platform/resourcePrice');

Expand Down
6 changes: 3 additions & 3 deletions frontend/providers/dbprovider/src/pages/api/delDBByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getBackups } from './backup/getBackupList';
import { delBackupByName } from './backup/delBackup';
import { getMigrateList } from './migrate/list';
import { delMigrateByName } from './migrate/delete';
import { deleteJobByName, getJobByName } from './migrate/delJobByName';
import { DeleteJobByName, GetJobByName } from './migrate/delJobByName';

export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) {
try {
Expand All @@ -21,9 +21,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
});

// get job and delete
const jobs = await getJobByName({ name: name, req });
const jobs = await GetJobByName({ name: name, req });
await Promise.all(
jobs.map((item) => item?.metadata?.name && deleteJobByName({ name: item.metadata.name, req }))
jobs.map((item) => item?.metadata?.name && DeleteJobByName({ name: item.metadata.name, req }))
).catch((error) => {
console.log(error);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
throw new Error('name is empty');
}

const result = await deleteJobByName({ name, req });
const result = await DeleteJobByName({ name, req });

jsonRes(res, { code: 200, data: result });
} catch (err: any) {
jsonRes(res, {
Expand All @@ -22,7 +23,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
}
}

export async function getJobByName({ name, req }: { name: string } & { req: NextApiRequest }) {
export async function GetJobByName({ name, req }: { name: string } & { req: NextApiRequest }) {
const { k8sBatch, namespace } = await getK8s({
kubeconfig: await authSession(req)
});
Expand All @@ -37,9 +38,17 @@ export async function getJobByName({ name, req }: { name: string } & { req: Next
return data.items;
}

export async function deleteJobByName({ name, req }: { name: string } & { req: NextApiRequest }) {
export async function DeleteJobByName({ name, req }: { name: string } & { req: NextApiRequest }) {
const { k8sBatch, namespace } = await getK8s({
kubeconfig: await authSession(req)
});
return await k8sBatch.deleteNamespacedJob(name, namespace);
return await k8sBatch.deleteNamespacedJob(
name,
namespace,
undefined,
undefined,
undefined,
undefined,
'Background'
);
}
4 changes: 4 additions & 0 deletions frontend/providers/dbprovider/src/pages/api/minio/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default async function handler(req: any, res: NextApiResponse) {
console.log(files, '===files===');
const bucketName = process.env?.BUCKET_NAME || 'database-test';

const startTime = performance.now();
const upLoadResults = await Promise.all(
files.map(async (file) => {
const fileName = `${namespace}-${Date.now()}-${file.filename}`;
Expand All @@ -100,6 +101,9 @@ export default async function handler(req: any, res: NextApiResponse) {
});
})
);
const endTime = performance.now();
const duration = endTime - startTime;
console.log(`代码块运行时间:${duration} 毫秒`);

jsonRes(res, {
data: upLoadResults
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { applyYamlList, getDBSecret } from '@/api/db';
import { getLogByNameAndContainerName, getMigratePodList } from '@/api/migrate';
import {
deleteMigrateJobByName,
getLogByNameAndContainerName,
getMigratePodList
} from '@/api/migrate';
import { uploadFile } from '@/api/platform';
import FileSelect from '@/components/FileSelect';
import MyIcon from '@/components/Icon';
Expand Down Expand Up @@ -87,9 +91,7 @@ export default function DumpImport({ db }: { db?: DBDetailType }) {
formHook.setValue('fileName', result[0]);
const { yamlStr, yamlObj } = await json2DumpCR({ ...data, fileName: result[0] });
setMigrateName(yamlObj.metadata.name);

console.log(yamlStr, yamlObj.metadata.name);

await applyYamlList([yamlStr], 'create');
} catch (error: any) {
toast({
Expand Down Expand Up @@ -119,11 +121,18 @@ export default function DumpImport({ db }: { db?: DBDetailType }) {
)();
};

const closeMigrate = () => {
onClose();
setMigrateStatus(MigrateStatusEnum.Prepare);
setMigrateName('');
setPodName('');
const closeMigrate = async () => {
try {
if (migrateStatus === MigrateStatusEnum.Progress && db?.dbName && migrateName) {
await deleteMigrateJobByName(migrateName);
}
onClose();
setMigrateStatus(MigrateStatusEnum.Prepare);
setMigrateName('');
setPodName('');
} catch (error) {
console.log(error, 'close migrate error');
}
};

useQuery(['getFileMigratePodList'], () => getMigratePodList(migrateName, 'file'), {
Expand All @@ -140,15 +149,6 @@ export default function DumpImport({ db }: { db?: DBDetailType }) {
}
setPodName(data[0].metadata.name);
}
},
onSettled() {
// timeElapsedRef.current += 5000;
// console.log(timeElapsedRef.current);
// if (timeElapsedRef.current >= 8 * 60 * 1000) {
// setMigrateStatus(MigrateStatusEnum.Fail);
// setMigrateName('');
// timeElapsedRef.current = 0;
// }
}
});

Expand Down
12 changes: 8 additions & 4 deletions frontend/providers/dbprovider/src/pages/db/detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const AppDetail = ({
const { t } = useTranslation();

const { listNav } = useMemo(() => {
const PublicNetMigration = ['postgresql', 'apecloud-mysql'].includes(dbType);
const MigrateSupported = ['postgresql', 'mongodb', 'apecloud-mysql'].includes(dbType);
const BackupSupported = ['postgresql', 'mongodb', 'apecloud-mysql', 'redis'].includes(dbType);

Expand All @@ -49,14 +50,17 @@ const AppDetail = ({
{ label: 'Replicas List', value: TabEnum.pod },
...(BackupSupported ? [{ label: 'Backup List', value: TabEnum.backup }] : []),
...(MigrateSupported
? [
{ label: 'Internet Migration', value: TabEnum.InternetMigration },
{ label: 'File Migration', value: TabEnum.DumpImport }
]
? PublicNetMigration
? [
{ label: 'Internet Migration', value: TabEnum.InternetMigration },
{ label: 'File Migration', value: TabEnum.DumpImport }
]
: [{ label: 'File Migration', value: TabEnum.DumpImport }]
: [])
];

return {
isPublicNetMigration: PublicNetMigration,
isMigrationSupported: MigrateSupported,
isBackupSupported: BackupSupported,
listNav: listNavValue
Expand Down

0 comments on commit 67e5d44

Please sign in to comment.