refactor: gpu service API alignment
This commit is contained in:
@@ -2,6 +2,7 @@ import { request } from '@umijs/max';
|
||||
import _ from 'lodash';
|
||||
import { omitPathParams } from '../../utils';
|
||||
import {
|
||||
FormData,
|
||||
InstanceEvents,
|
||||
InstanceLog,
|
||||
InstanceLogQueryParams,
|
||||
@@ -9,176 +10,89 @@ import {
|
||||
ListItem
|
||||
} from '../config/types';
|
||||
|
||||
export const GPU_SERVICE_INSTANCES_API = (params: {
|
||||
namespace: string;
|
||||
clusterID?: number;
|
||||
}) =>
|
||||
`/clusters/${params.clusterID}/proxy/apis/worker.gpustack.ai/v1/namespaces/${params.namespace}/instances`;
|
||||
export const GPU_SERVICE_INSTANCES_API = '/gpu-instances';
|
||||
|
||||
export const GPU_SERVICE_INSTANCES_TYPE_API = (params: {
|
||||
clusterID?: number;
|
||||
}) => {
|
||||
return `/clusters/${params.clusterID}/proxy/apis/worker.gpustack.ai/v1/instancetypes`;
|
||||
};
|
||||
export const GPU_SERVICE_INSTANCES_TYPE_API = '/gpu-instance-types';
|
||||
|
||||
// View logs / events still go through the K8s proxy until the /v2
|
||||
// /gpu-instances API exposes equivalents. clusterID and namespace come
|
||||
// per-row from `row.clusterId` and `row.status.namespace`.
|
||||
|
||||
export const GPU_SERVICE_INSTANCES_LOG_API = (params: {
|
||||
namespace: string;
|
||||
name: string;
|
||||
clusterID?: number;
|
||||
}) => {
|
||||
return `/clusters/${params.clusterID}/proxy/apis/worker.gpustack.ai/v1/namespaces/${params.namespace}/instances/${params.name}/log`;
|
||||
};
|
||||
}) =>
|
||||
`/clusters/${params.clusterID}/proxy/apis/worker.gpustack.ai/v1/namespaces/${params.namespace}/instances/${params.name}/log`;
|
||||
|
||||
export const GPU_SERVICE_INSTANCES_EVENTS_API = (params: {
|
||||
namespace: string;
|
||||
name: string;
|
||||
clusterID?: number;
|
||||
}) => {
|
||||
return `/clusters/${params.clusterID}/proxy/apis/worker.gpustack.ai/v1/namespaces/${params.namespace}/instances/${params.name}/events`;
|
||||
};
|
||||
}) =>
|
||||
`/clusters/${params.clusterID}/proxy/apis/worker.gpustack.ai/v1/namespaces/${params.namespace}/instances/${params.name}/events`;
|
||||
|
||||
export const GPU_SERVICE_INSTANCE_PV_EVENTS_API = (params: {
|
||||
namespace: string;
|
||||
name: string;
|
||||
clusterID?: number;
|
||||
}) => {
|
||||
return `/clusters/${params.clusterID}/proxy/apis/worker.gpustack.ai/v1/namespaces/${params.namespace}/instancepersistentvolumes/${params.name}/events`;
|
||||
};
|
||||
|
||||
// TODO: replace placeholder once start/stop endpoints are finalized
|
||||
export const GPU_SERVICE_INSTANCE_START_API = (params: {
|
||||
namespace: string;
|
||||
name: string;
|
||||
clusterID?: number;
|
||||
}) => {
|
||||
return `/clusters/${params.clusterID}/proxy/apis/worker.gpustack.ai/v1/namespaces/${params.namespace}/instances/${params.name}/start`;
|
||||
};
|
||||
|
||||
// TODO: replace placeholder once start/stop endpoints are finalized
|
||||
export const GPU_SERVICE_INSTANCE_STOP_API = (params: {
|
||||
namespace: string;
|
||||
name: string;
|
||||
clusterID?: number;
|
||||
}) => {
|
||||
return `/clusters/${params.clusterID}/proxy/apis/worker.gpustack.ai/v1/namespaces/${params.namespace}/instances/${params.name}/stop`;
|
||||
};
|
||||
}) =>
|
||||
`/clusters/${params.clusterID}/proxy/apis/worker.gpustack.ai/v1/namespaces/${params.namespace}/instancepersistentvolumes/${params.name}/events`;
|
||||
|
||||
// =========== Instances ===========
|
||||
|
||||
export async function queryGPUServiceInstances(
|
||||
params: Global.K8sSearchParams & {
|
||||
namespace: string;
|
||||
clusterID?: number;
|
||||
},
|
||||
params: Global.SearchParams,
|
||||
options?: any
|
||||
) {
|
||||
if (!params.clusterID) {
|
||||
return;
|
||||
}
|
||||
return request<Global.K8sPageResponse<ListItem>>(
|
||||
GPU_SERVICE_INSTANCES_API({
|
||||
namespace: params.namespace,
|
||||
clusterID: params.clusterID
|
||||
}),
|
||||
{
|
||||
method: 'GET',
|
||||
params: omitPathParams(params),
|
||||
cancelToken: options?.token
|
||||
}
|
||||
);
|
||||
return request<Global.PageResponse<ListItem>>(GPU_SERVICE_INSTANCES_API, {
|
||||
method: 'GET',
|
||||
params,
|
||||
cancelToken: options?.token
|
||||
});
|
||||
}
|
||||
|
||||
export async function createGPUServiceInstance(
|
||||
params: {
|
||||
namespace: string;
|
||||
clusterID?: number;
|
||||
data: Global.K8sCommonData;
|
||||
},
|
||||
option?: any
|
||||
) {
|
||||
if (!params.clusterID) {
|
||||
return;
|
||||
}
|
||||
return request<ListItem>(
|
||||
GPU_SERVICE_INSTANCES_API({
|
||||
namespace: params.namespace,
|
||||
clusterID: params.clusterID
|
||||
}),
|
||||
{
|
||||
method: 'POST',
|
||||
data: params.data,
|
||||
cancelToken: option?.token
|
||||
}
|
||||
);
|
||||
export async function createGPUServiceInstance(params: { data: FormData }) {
|
||||
return request<ListItem>(GPU_SERVICE_INSTANCES_API, {
|
||||
method: 'POST',
|
||||
data: params.data
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateGPUServiceInstance(
|
||||
params: {
|
||||
namespace: string;
|
||||
clusterID?: number;
|
||||
id: number;
|
||||
data: Global.K8sCommonData;
|
||||
},
|
||||
option?: any
|
||||
) {
|
||||
if (!params.clusterID) {
|
||||
return;
|
||||
}
|
||||
return request<ListItem>(
|
||||
`${GPU_SERVICE_INSTANCES_API({
|
||||
namespace: params.namespace,
|
||||
clusterID: params.clusterID
|
||||
})}/${params.data?.metadata?.name}`,
|
||||
{
|
||||
method: 'PUT',
|
||||
data: params.data,
|
||||
cancelToken: option?.token
|
||||
}
|
||||
);
|
||||
export async function updateGPUServiceInstance(params: {
|
||||
id: number;
|
||||
data: Partial<FormData>;
|
||||
}) {
|
||||
return request<ListItem>(`${GPU_SERVICE_INSTANCES_API}/${params.id}`, {
|
||||
method: 'PUT',
|
||||
data: params.data
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteGPUServiceInstance(
|
||||
params: {
|
||||
namespace: string;
|
||||
clusterID?: number;
|
||||
id: number;
|
||||
},
|
||||
option?: any
|
||||
) {
|
||||
if (!params.clusterID) {
|
||||
return;
|
||||
}
|
||||
return request(
|
||||
`${GPU_SERVICE_INSTANCES_API({
|
||||
namespace: params.namespace,
|
||||
clusterID: params.clusterID
|
||||
})}/${params.id}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
cancelToken: option?.token
|
||||
}
|
||||
);
|
||||
export async function deleteGPUServiceInstance(id: number) {
|
||||
return request(`${GPU_SERVICE_INSTANCES_API}/${id}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
}
|
||||
|
||||
// =========== Instance Types ===========
|
||||
|
||||
export async function queryGPUServiceInstanceTypes(
|
||||
params: Global.K8sSearchParams & { clusterID?: number },
|
||||
params: Global.SearchParams = { page: 1, perPage: 100 },
|
||||
options?: any
|
||||
) {
|
||||
if (!params.clusterID) {
|
||||
return;
|
||||
}
|
||||
return request<Global.K8sPageResponse<InstanceTypeItem>>(
|
||||
GPU_SERVICE_INSTANCES_TYPE_API({ clusterID: params.clusterID }),
|
||||
return request<Global.PageResponse<InstanceTypeItem>>(
|
||||
GPU_SERVICE_INSTANCES_TYPE_API,
|
||||
{
|
||||
method: 'GET',
|
||||
params: omitPathParams(params),
|
||||
params,
|
||||
cancelToken: options?.token
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// =========== Logs / Events (K8s proxy) ===========
|
||||
|
||||
export async function queryGPUServiceInstanceEvents(
|
||||
params: {
|
||||
namespace: string;
|
||||
@@ -192,11 +106,11 @@ export async function queryGPUServiceInstanceEvents(
|
||||
return;
|
||||
}
|
||||
return request<InstanceEvents>(
|
||||
`${GPU_SERVICE_INSTANCES_EVENTS_API({
|
||||
GPU_SERVICE_INSTANCES_EVENTS_API({
|
||||
namespace: params.namespace,
|
||||
clusterID: params.clusterID,
|
||||
name: params.name
|
||||
})}`,
|
||||
}),
|
||||
{
|
||||
method: 'GET',
|
||||
params: omitPathParams(_.omit(params, ['name'])),
|
||||
@@ -217,11 +131,11 @@ export async function queryGPUServiceInstancePVEvents(
|
||||
return;
|
||||
}
|
||||
return request<InstanceEvents>(
|
||||
`${GPU_SERVICE_INSTANCE_PV_EVENTS_API({
|
||||
GPU_SERVICE_INSTANCE_PV_EVENTS_API({
|
||||
namespace: params.namespace,
|
||||
clusterID: params.clusterID,
|
||||
name: params.name
|
||||
})}`,
|
||||
}),
|
||||
{
|
||||
method: 'GET',
|
||||
params: omitPathParams(_.omit(params, ['name'])),
|
||||
@@ -230,56 +144,6 @@ export async function queryGPUServiceInstancePVEvents(
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: replace placeholder once start/stop endpoints are finalized
|
||||
export async function startGPUServiceInstance(
|
||||
params: {
|
||||
namespace: string;
|
||||
name: string;
|
||||
clusterID?: number;
|
||||
},
|
||||
option?: any
|
||||
) {
|
||||
if (!params.clusterID) {
|
||||
return;
|
||||
}
|
||||
return request(
|
||||
GPU_SERVICE_INSTANCE_START_API({
|
||||
namespace: params.namespace,
|
||||
clusterID: params.clusterID,
|
||||
name: params.name
|
||||
}),
|
||||
{
|
||||
method: 'POST',
|
||||
cancelToken: option?.token
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: replace placeholder once start/stop endpoints are finalized
|
||||
export async function stopGPUServiceInstance(
|
||||
params: {
|
||||
namespace: string;
|
||||
name: string;
|
||||
clusterID?: number;
|
||||
},
|
||||
option?: any
|
||||
) {
|
||||
if (!params.clusterID) {
|
||||
return;
|
||||
}
|
||||
return request(
|
||||
GPU_SERVICE_INSTANCE_STOP_API({
|
||||
namespace: params.namespace,
|
||||
clusterID: params.clusterID,
|
||||
name: params.name
|
||||
}),
|
||||
{
|
||||
method: 'POST',
|
||||
cancelToken: option?.token
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function queryGPUServiceInstanceLog(
|
||||
params: InstanceLogQueryParams & {
|
||||
namespace: string;
|
||||
@@ -292,11 +156,11 @@ export async function queryGPUServiceInstanceLog(
|
||||
return;
|
||||
}
|
||||
return request<InstanceLog>(
|
||||
`${GPU_SERVICE_INSTANCES_LOG_API({
|
||||
GPU_SERVICE_INSTANCES_LOG_API({
|
||||
namespace: params.namespace,
|
||||
clusterID: params.clusterID,
|
||||
name: params.name
|
||||
})}`,
|
||||
}),
|
||||
{
|
||||
method: 'GET',
|
||||
params: omitPathParams(_.omit(params, ['name'])),
|
||||
@@ -304,23 +168,3 @@ export async function queryGPUServiceInstanceLog(
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export async function queryGPUServiceInstanceTypeItems(
|
||||
params: {
|
||||
name: string;
|
||||
clusterID?: number;
|
||||
},
|
||||
options?: any
|
||||
) {
|
||||
if (!params.clusterID) {
|
||||
return;
|
||||
}
|
||||
return request<InstanceTypeItem>(
|
||||
`${GPU_SERVICE_INSTANCES_TYPE_API({ clusterID: params.clusterID })}/${params.name}`,
|
||||
{
|
||||
method: 'GET',
|
||||
params: omitPathParams(params),
|
||||
cancelToken: options?.token
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user