feat(container): show business line workloads from Wayne
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import { getToken } from '@/utils/auth'
|
||||
|
||||
export interface ContainerServiceSummary {
|
||||
businessLineId: number
|
||||
businessLineName: string
|
||||
namespaces: number
|
||||
clusters: number
|
||||
nodes: number
|
||||
readyNodes: number
|
||||
schedulableNodes: number
|
||||
workloads: number
|
||||
pods: number
|
||||
readyPods: number
|
||||
cpuUsed: number
|
||||
cpuTotal: number
|
||||
cpuPercent: number
|
||||
memoryUsed: number
|
||||
memoryTotal: number
|
||||
memoryPercent: number
|
||||
errors?: string[]
|
||||
}
|
||||
|
||||
export interface ContainerWorkload {
|
||||
name: string
|
||||
cluster: string
|
||||
namespace: string
|
||||
workload: string
|
||||
ready: string
|
||||
readyPods: number
|
||||
pods: number
|
||||
image: string
|
||||
biz: string
|
||||
status: string
|
||||
statusClass: string
|
||||
}
|
||||
|
||||
export const emptyContainerServiceSummary: ContainerServiceSummary = {
|
||||
businessLineId: 0,
|
||||
businessLineName: '',
|
||||
namespaces: 0,
|
||||
clusters: 0,
|
||||
nodes: 0,
|
||||
readyNodes: 0,
|
||||
schedulableNodes: 0,
|
||||
workloads: 0,
|
||||
pods: 0,
|
||||
readyPods: 0,
|
||||
cpuUsed: 0,
|
||||
cpuTotal: 0,
|
||||
cpuPercent: 0,
|
||||
memoryUsed: 0,
|
||||
memoryTotal: 0,
|
||||
memoryPercent: 0,
|
||||
}
|
||||
|
||||
export const containerServiceApi = {
|
||||
async getSummary(businessLineId: number): Promise<ContainerServiceSummary> {
|
||||
return authRequest(`/auth/api/v1/container-services/business-lines/${businessLineId}/summary`)
|
||||
},
|
||||
|
||||
async listWorkloads(businessLineId: number): Promise<{ items: ContainerWorkload[]; summary: ContainerServiceSummary }> {
|
||||
const data = await authRequest(`/auth/api/v1/container-services/business-lines/${businessLineId}/workloads`)
|
||||
return {
|
||||
items: Array.isArray(data.items) ? data.items : [],
|
||||
summary: data.summary || emptyContainerServiceSummary,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
async function authRequest(path: string, init: RequestInit = {}) {
|
||||
const token = getToken()
|
||||
const response = await fetch(path, {
|
||||
...init,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
||||
...init.headers,
|
||||
},
|
||||
})
|
||||
const text = await response.text()
|
||||
const data = parseResponseBody(text)
|
||||
if (!response.ok) {
|
||||
const message = data?.error || data?.message || text || `HTTP ${response.status}`
|
||||
throw new Error(message)
|
||||
}
|
||||
return data || {}
|
||||
}
|
||||
|
||||
function parseResponseBody(text: string) {
|
||||
if (!text.trim()) {
|
||||
return {}
|
||||
}
|
||||
try {
|
||||
return JSON.parse(text)
|
||||
} catch {
|
||||
return { error: text }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user