mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudMigrations: Refactor API for async work (#89084)
* rename some stuff * more renaming * clean up api * rename more functions * rename cms -> gms * update comment * update swagger gen * update endpoints * overzealous * final touches * dont modify existing migrations * break structs into domain and dtos * add some conversion funcs * fix build * update frontend * try to make swagger happy
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
import { baseAPI as api } from './baseAPI';
|
||||
const injectedRtkApi = api.injectEndpoints({
|
||||
endpoints: (build) => ({
|
||||
getMigrationList: build.query<GetMigrationListApiResponse, GetMigrationListApiArg>({
|
||||
getSessionList: build.query<GetSessionListApiResponse, GetSessionListApiArg>({
|
||||
query: () => ({ url: `/cloudmigration/migration` }),
|
||||
}),
|
||||
createMigration: build.mutation<CreateMigrationApiResponse, CreateMigrationApiArg>({
|
||||
query: (queryArg) => ({ url: `/cloudmigration/migration`, method: 'POST', body: queryArg.cloudMigrationRequest }),
|
||||
createSession: build.mutation<CreateSessionApiResponse, CreateSessionApiArg>({
|
||||
query: (queryArg) => ({
|
||||
url: `/cloudmigration/migration`,
|
||||
method: 'POST',
|
||||
body: queryArg.cloudMigrationSessionRequestDto,
|
||||
}),
|
||||
}),
|
||||
getCloudMigrationRun: build.query<GetCloudMigrationRunApiResponse, GetCloudMigrationRunApiArg>({
|
||||
query: (queryArg) => ({ url: `/cloudmigration/migration/run/${queryArg.runUid}` }),
|
||||
}),
|
||||
deleteCloudMigration: build.mutation<DeleteCloudMigrationApiResponse, DeleteCloudMigrationApiArg>({
|
||||
deleteSession: build.mutation<DeleteSessionApiResponse, DeleteSessionApiArg>({
|
||||
query: (queryArg) => ({ url: `/cloudmigration/migration/${queryArg.uid}`, method: 'DELETE' }),
|
||||
}),
|
||||
getCloudMigration: build.query<GetCloudMigrationApiResponse, GetCloudMigrationApiArg>({
|
||||
getSession: build.query<GetSessionApiResponse, GetSessionApiArg>({
|
||||
query: (queryArg) => ({ url: `/cloudmigration/migration/${queryArg.uid}` }),
|
||||
}),
|
||||
getCloudMigrationRunList: build.query<GetCloudMigrationRunListApiResponse, GetCloudMigrationRunListApiArg>({
|
||||
@@ -32,28 +36,28 @@ const injectedRtkApi = api.injectEndpoints({
|
||||
overrideExisting: false,
|
||||
});
|
||||
export { injectedRtkApi as generatedAPI };
|
||||
export type GetMigrationListApiResponse = /** status 200 (empty) */ CloudMigrationListResponse;
|
||||
export type GetMigrationListApiArg = void;
|
||||
export type CreateMigrationApiResponse = /** status 200 (empty) */ CloudMigrationResponse;
|
||||
export type CreateMigrationApiArg = {
|
||||
cloudMigrationRequest: CloudMigrationRequest;
|
||||
export type GetSessionListApiResponse = /** status 200 (empty) */ CloudMigrationSessionListResponseDto;
|
||||
export type GetSessionListApiArg = void;
|
||||
export type CreateSessionApiResponse = /** status 200 (empty) */ CloudMigrationSessionResponseDto;
|
||||
export type CreateSessionApiArg = {
|
||||
cloudMigrationSessionRequestDto: CloudMigrationSessionRequestDto;
|
||||
};
|
||||
export type GetCloudMigrationRunApiResponse = /** status 200 (empty) */ MigrateDataResponseDto;
|
||||
export type GetCloudMigrationRunApiArg = {
|
||||
/** RunUID of a migration run */
|
||||
runUid: string;
|
||||
};
|
||||
export type DeleteCloudMigrationApiResponse = unknown;
|
||||
export type DeleteCloudMigrationApiArg = {
|
||||
/** UID of a migration */
|
||||
export type DeleteSessionApiResponse = unknown;
|
||||
export type DeleteSessionApiArg = {
|
||||
/** UID of a migration session */
|
||||
uid: string;
|
||||
};
|
||||
export type GetCloudMigrationApiResponse = /** status 200 (empty) */ CloudMigrationResponse;
|
||||
export type GetCloudMigrationApiArg = {
|
||||
/** UID of a migration */
|
||||
export type GetSessionApiResponse = /** status 200 (empty) */ CloudMigrationSessionResponseDto;
|
||||
export type GetSessionApiArg = {
|
||||
/** UID of a migration session */
|
||||
uid: string;
|
||||
};
|
||||
export type GetCloudMigrationRunListApiResponse = /** status 200 (empty) */ CloudMigrationRunList;
|
||||
export type GetCloudMigrationRunListApiResponse = /** status 200 (empty) */ SnapshotListDto;
|
||||
export type GetCloudMigrationRunListApiArg = {
|
||||
/** UID of a migration */
|
||||
uid: string;
|
||||
@@ -69,14 +73,14 @@ export type GetDashboardByUidApiResponse = /** status 200 (empty) */ DashboardFu
|
||||
export type GetDashboardByUidApiArg = {
|
||||
uid: string;
|
||||
};
|
||||
export type CloudMigrationResponse = {
|
||||
export type CloudMigrationSessionResponseDto = {
|
||||
created?: string;
|
||||
stack?: string;
|
||||
slug?: string;
|
||||
uid?: string;
|
||||
updated?: string;
|
||||
};
|
||||
export type CloudMigrationListResponse = {
|
||||
migrations?: CloudMigrationResponse[];
|
||||
export type CloudMigrationSessionListResponseDto = {
|
||||
sessions?: CloudMigrationSessionResponseDto[];
|
||||
};
|
||||
export type ErrorResponseBody = {
|
||||
/** Error An optional detailed description of the actual error. Only included if running in developer mode. */
|
||||
@@ -88,7 +92,7 @@ export type ErrorResponseBody = {
|
||||
For example, a 412 Precondition Failed error may include additional information of why that error happened. */
|
||||
status?: string;
|
||||
};
|
||||
export type CloudMigrationRequest = {
|
||||
export type CloudMigrationSessionRequestDto = {
|
||||
authToken?: string;
|
||||
};
|
||||
export type MigrateDataResponseItemDto = {
|
||||
@@ -104,7 +108,7 @@ export type MigrateDataResponseDto = {
|
||||
export type MigrateDataResponseListDto = {
|
||||
uid?: string;
|
||||
};
|
||||
export type CloudMigrationRunList = {
|
||||
export type SnapshotListDto = {
|
||||
runs?: MigrateDataResponseListDto[];
|
||||
};
|
||||
export type CreateAccessTokenResponseDto = {
|
||||
@@ -154,11 +158,11 @@ export type DashboardFullWithMeta = {
|
||||
meta?: DashboardMeta;
|
||||
};
|
||||
export const {
|
||||
useGetMigrationListQuery,
|
||||
useCreateMigrationMutation,
|
||||
useGetSessionListQuery,
|
||||
useCreateSessionMutation,
|
||||
useGetCloudMigrationRunQuery,
|
||||
useDeleteCloudMigrationMutation,
|
||||
useGetCloudMigrationQuery,
|
||||
useDeleteSessionMutation,
|
||||
useGetSessionQuery,
|
||||
useGetCloudMigrationRunListQuery,
|
||||
useRunCloudMigrationMutation,
|
||||
useCreateCloudMigrationTokenMutation,
|
||||
|
||||
@@ -10,23 +10,23 @@ export const cloudMigrationAPI = generatedAPI.enhanceEndpoints({
|
||||
createCloudMigrationToken: suppressErrorsOnQuery,
|
||||
|
||||
// List Cloud Configs
|
||||
getMigrationList: {
|
||||
getSessionList: {
|
||||
providesTags: ['cloud-migration-config'] /* should this be a -list? */,
|
||||
},
|
||||
|
||||
// Create Cloud Config
|
||||
createMigration(endpoint) {
|
||||
createSession(endpoint) {
|
||||
suppressErrorsOnQuery(endpoint);
|
||||
endpoint.invalidatesTags = ['cloud-migration-config'];
|
||||
},
|
||||
|
||||
// Get one Cloud Config
|
||||
getCloudMigration: {
|
||||
getSession: {
|
||||
providesTags: ['cloud-migration-config'],
|
||||
},
|
||||
|
||||
// Delete one Cloud Config
|
||||
deleteCloudMigration: {
|
||||
deleteSession: {
|
||||
invalidatesTags: ['cloud-migration-config'],
|
||||
},
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@ import React, { useState } from 'react';
|
||||
import { Box, Button, Text } from '@grafana/ui';
|
||||
import { Trans } from 'app/core/internationalization';
|
||||
|
||||
import { useCreateMigrationMutation } from '../../../api';
|
||||
import { useCreateSessionMutation } from '../../../api';
|
||||
|
||||
import { ConnectModal } from './ConnectModal';
|
||||
|
||||
export const CallToAction = () => {
|
||||
const [modalOpen, setModalOpen] = useState(false);
|
||||
const [createMigration, createMigrationResponse] = useCreateMigrationMutation();
|
||||
const [createMigration, createMigrationResponse] = useCreateSessionMutation();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -6,14 +6,14 @@ import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { Modal, Button, Stack, TextLink, Field, Input, Text, useStyles2, Alert } from '@grafana/ui';
|
||||
import { Trans, t } from 'app/core/internationalization';
|
||||
|
||||
import { CreateMigrationApiArg } from '../../../api';
|
||||
import { CreateSessionApiArg } from '../../../api';
|
||||
|
||||
interface Props {
|
||||
isOpen: boolean;
|
||||
isLoading: boolean;
|
||||
isError: boolean;
|
||||
hideModal: () => void;
|
||||
onConfirm: (connectStackData: CreateMigrationApiArg) => Promise<unknown>;
|
||||
onConfirm: (connectStackData: CreateSessionApiArg) => Promise<unknown>;
|
||||
}
|
||||
|
||||
interface FormData {
|
||||
@@ -39,7 +39,7 @@ export const ConnectModal = ({ isOpen, isLoading, isError, hideModal, onConfirm
|
||||
|
||||
const onConfirmConnect: SubmitHandler<FormData> = (formData) => {
|
||||
onConfirm({
|
||||
cloudMigrationRequest: {
|
||||
cloudMigrationSessionRequestDto: {
|
||||
authToken: formData.token,
|
||||
},
|
||||
}).then((resp) => {
|
||||
|
||||
@@ -5,10 +5,10 @@ import { Alert, Box, Button, Stack } from '@grafana/ui';
|
||||
import { Trans, t } from 'app/core/internationalization';
|
||||
|
||||
import {
|
||||
useDeleteCloudMigrationMutation,
|
||||
useDeleteSessionMutation,
|
||||
useGetCloudMigrationRunListQuery,
|
||||
useGetCloudMigrationRunQuery,
|
||||
useGetMigrationListQuery,
|
||||
useGetSessionListQuery,
|
||||
useRunCloudMigrationMutation,
|
||||
} from '../api';
|
||||
|
||||
@@ -33,8 +33,8 @@ import { ResourcesTable } from './ResourcesTable';
|
||||
*/
|
||||
|
||||
function useGetLatestMigrationDestination() {
|
||||
const result = useGetMigrationListQuery();
|
||||
const latestMigration = result.data?.migrations?.at(-1);
|
||||
const result = useGetSessionListQuery();
|
||||
const latestMigration = result.data?.sessions?.at(-1);
|
||||
|
||||
return {
|
||||
...result,
|
||||
@@ -68,7 +68,7 @@ export const Page = () => {
|
||||
const migrationDestination = useGetLatestMigrationDestination();
|
||||
const lastMigrationRun = useGetLatestMigrationRun(migrationDestination.data?.uid);
|
||||
const [performRunMigration, runMigrationResult] = useRunCloudMigrationMutation();
|
||||
const [performDisconnect, disconnectResult] = useDeleteCloudMigrationMutation();
|
||||
const [performDisconnect, disconnectResult] = useDeleteSessionMutation();
|
||||
|
||||
// isBusy is not a loading state, but indicates that the system is doing *something*
|
||||
// and all buttons should be disabled
|
||||
@@ -136,7 +136,7 @@ export const Page = () => {
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{migrationMeta.stack && (
|
||||
{migrationMeta.slug && (
|
||||
<Box
|
||||
borderColor="weak"
|
||||
borderStyle="solid"
|
||||
@@ -150,7 +150,7 @@ export const Page = () => {
|
||||
title={t('migrate-to-cloud.summary.target-stack-title', 'Uploading to')}
|
||||
value={
|
||||
<>
|
||||
{migrationMeta.stack}{' '}
|
||||
{migrationMeta.slug}{' '}
|
||||
<Button
|
||||
disabled={isBusy}
|
||||
onClick={() => setDisconnectModalOpen(true)}
|
||||
|
||||
Reference in New Issue
Block a user