-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathqueuecontroller.js
110 lines (93 loc) · 3.25 KB
/
queuecontroller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { k8sCoreApi, k8sApi } from '../services/k8sClient.js';
// Fetch all Queues
export const getAllQueues = async (req, res) => {
try {
const page = parseInt(req.query.page) || 1;
const limit = parseInt(req.query.limit) || 10;
const searchTerm = req.query.search || "";
const stateFilter = req.query.state || "";
console.log('Fetching queues with params:', { page, limit, searchTerm, stateFilter });
const response = await k8sApi.listClusterCustomObject(
"scheduling.volcano.sh",
"v1beta1",
"queues"
);
let filteredQueues = response.body.items || [];
// Apply search filter
if (searchTerm) {
filteredQueues = filteredQueues.filter((queue) =>
queue.metadata.name.toLowerCase().includes(searchTerm.toLowerCase())
);
}
// Apply state filter
if (stateFilter && stateFilter !== "All") {
filteredQueues = filteredQueues.filter((queue) =>
queue.status.state === stateFilter
);
}
const totalCount = filteredQueues.length;
const startIndex = (page - 1) * limit;
const endIndex = Math.min(startIndex + limit, totalCount);
const paginatedQueues = filteredQueues.slice(startIndex, endIndex);
res.json({
items: paginatedQueues,
totalCount: totalCount,
page: page,
limit: limit,
totalPages: Math.ceil(totalCount / limit)
});
} catch (error) {
console.error("Error fetching queues:", error);
res.status(500).json({
error: "Failed to fetch queues",
details: error.message,
});
}
};
// Get details of a specific Queue
export const getQueueDetails = async (req, res) => {
const queueName = req.params.name;
try {
console.log("Fetching details for queue:", queueName);
const response = await k8sApi.getClusterCustomObject(
"scheduling.volcano.sh",
"v1beta1",
"queues",
queueName
);
console.log("Queue details response:", response.body);
res.json(response.body);
} catch (error) {
console.error("Error fetching queue details:", error);
res.status(500).json({
error: "Failed to fetch queue details",
details: error.message,
});
}
};
// Get YAML of a specific Queue
export const getQueueYaml = async (req, res) => {
try {
const response = await k8sApi.getClusterCustomObject(
"scheduling.volcano.sh",
"v1beta1",
"queues",
req.params.name
);
const formattedYaml = yaml.dump(response.body, {
indent: 2,
lineWidth: -1,
noRefs: true,
sortKeys: false
});
// Set the content type to text/yaml and send the response
res.setHeader('Content-Type', 'text/yaml');
res.send(formattedYaml);
} catch (error) {
console.error("Error fetching queue YAML:", error);
res.status(500).json({
error: "Failed to fetch queue YAML",
details: error.message
});
}
};