Update README.md
This commit is contained in:
355
static/app.js
Normal file
355
static/app.js
Normal file
@ -0,0 +1,355 @@
|
||||
// API endpoints
|
||||
const API_BASE_URL = '/api/claude';
|
||||
const ENDPOINTS = {
|
||||
listJobs: `${API_BASE_URL}/list-jobs`,
|
||||
manageJob: `${API_BASE_URL}/jobs`,
|
||||
jobLogs: `${API_BASE_URL}/job-logs`
|
||||
};
|
||||
|
||||
// DOM elements
|
||||
const elements = {
|
||||
namespaceSelector: document.getElementById('namespace-selector'),
|
||||
refreshBtn: document.getElementById('refresh-btn'),
|
||||
jobList: document.getElementById('job-list'),
|
||||
jobTable: document.getElementById('job-table'),
|
||||
jobDetails: document.getElementById('job-details'),
|
||||
logContent: document.getElementById('log-content'),
|
||||
logTabs: document.querySelectorAll('.log-tab'),
|
||||
loading: document.getElementById('loading'),
|
||||
errorMessage: document.getElementById('error-message')
|
||||
};
|
||||
|
||||
// State
|
||||
let state = {
|
||||
jobs: [],
|
||||
selectedJob: null,
|
||||
selectedNamespace: 'development',
|
||||
logs: {
|
||||
stdout: '',
|
||||
stderr: '',
|
||||
currentTab: 'stdout'
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize the app
|
||||
function init() {
|
||||
// Set up event listeners
|
||||
elements.namespaceSelector.addEventListener('change', handleNamespaceChange);
|
||||
elements.refreshBtn.addEventListener('click', loadJobs);
|
||||
elements.logTabs.forEach(tab => {
|
||||
tab.addEventListener('click', () => {
|
||||
const logType = tab.getAttribute('data-log-type');
|
||||
switchLogTab(logType);
|
||||
});
|
||||
});
|
||||
|
||||
// Load initial jobs
|
||||
loadJobs();
|
||||
}
|
||||
|
||||
// Load jobs from the API
|
||||
async function loadJobs() {
|
||||
showLoading(true);
|
||||
hideError();
|
||||
|
||||
try {
|
||||
const namespace = elements.namespaceSelector.value;
|
||||
const response = await fetch(`${ENDPOINTS.listJobs}?namespace=${namespace}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load jobs: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const jobs = await response.json();
|
||||
state.jobs = jobs;
|
||||
state.selectedNamespace = namespace;
|
||||
|
||||
renderJobList();
|
||||
showLoading(false);
|
||||
} catch (error) {
|
||||
console.error('Error loading jobs:', error);
|
||||
showError(`Failed to load jobs: ${error.message}`);
|
||||
showLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Render the job list
|
||||
function renderJobList() {
|
||||
elements.jobList.innerHTML = '';
|
||||
|
||||
if (state.jobs.length === 0) {
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `<td colspan="4" class="no-jobs">No jobs found in the ${state.selectedNamespace} namespace</td>`;
|
||||
elements.jobList.appendChild(row);
|
||||
return;
|
||||
}
|
||||
|
||||
state.jobs.forEach(job => {
|
||||
const row = document.createElement('tr');
|
||||
row.setAttribute('data-job-id', job.id);
|
||||
row.innerHTML = `
|
||||
<td>${job.id}</td>
|
||||
<td>${job.type}</td>
|
||||
<td><span class="status status-${job.status.toLowerCase()}">${job.status}</span></td>
|
||||
<td class="job-actions">
|
||||
<button class="btn btn-primary btn-view" data-job-id="${job.id}">View</button>
|
||||
<button class="btn btn-success btn-restart" data-job-id="${job.id}">Restart</button>
|
||||
<button class="btn btn-danger btn-stop" data-job-id="${job.id}">Stop</button>
|
||||
</td>
|
||||
`;
|
||||
|
||||
elements.jobList.appendChild(row);
|
||||
});
|
||||
|
||||
// Add event listeners to buttons
|
||||
document.querySelectorAll('.btn-view').forEach(btn => {
|
||||
btn.addEventListener('click', () => viewJob(btn.getAttribute('data-job-id')));
|
||||
});
|
||||
|
||||
document.querySelectorAll('.btn-restart').forEach(btn => {
|
||||
btn.addEventListener('click', () => restartJob(btn.getAttribute('data-job-id')));
|
||||
});
|
||||
|
||||
document.querySelectorAll('.btn-stop').forEach(btn => {
|
||||
btn.addEventListener('click', () => stopJob(btn.getAttribute('data-job-id')));
|
||||
});
|
||||
}
|
||||
|
||||
// View job details
|
||||
async function viewJob(jobId) {
|
||||
showLoading(true);
|
||||
|
||||
try {
|
||||
// Get job status
|
||||
const statusResponse = await fetch(ENDPOINTS.manageJob, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
job_id: jobId,
|
||||
action: 'status',
|
||||
namespace: state.selectedNamespace
|
||||
})
|
||||
});
|
||||
|
||||
if (!statusResponse.ok) {
|
||||
throw new Error(`Failed to get job status: ${statusResponse.statusText}`);
|
||||
}
|
||||
|
||||
const jobStatus = await statusResponse.json();
|
||||
state.selectedJob = jobStatus;
|
||||
|
||||
// Get job logs
|
||||
const logsResponse = await fetch(`${ENDPOINTS.jobLogs}/${jobId}?namespace=${state.selectedNamespace}`);
|
||||
|
||||
if (logsResponse.ok) {
|
||||
const logsData = await logsResponse.json();
|
||||
|
||||
if (logsData.success) {
|
||||
state.logs.stdout = logsData.logs.stdout || 'No stdout logs available';
|
||||
state.logs.stderr = logsData.logs.stderr || 'No stderr logs available';
|
||||
} else {
|
||||
state.logs.stdout = 'Logs not available';
|
||||
state.logs.stderr = 'Logs not available';
|
||||
}
|
||||
} else {
|
||||
state.logs.stdout = 'Failed to load logs';
|
||||
state.logs.stderr = 'Failed to load logs';
|
||||
}
|
||||
|
||||
renderJobDetails();
|
||||
renderLogs();
|
||||
showLoading(false);
|
||||
|
||||
// Highlight the selected job in the table
|
||||
document.querySelectorAll('#job-list tr').forEach(row => {
|
||||
row.classList.remove('selected');
|
||||
});
|
||||
|
||||
const selectedRow = document.querySelector(`#job-list tr[data-job-id="${jobId}"]`);
|
||||
if (selectedRow) {
|
||||
selectedRow.classList.add('selected');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error viewing job:', error);
|
||||
showError(`Failed to view job: ${error.message}`);
|
||||
showLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Restart a job
|
||||
async function restartJob(jobId) {
|
||||
if (!confirm(`Are you sure you want to restart job "${jobId}"?`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
showLoading(true);
|
||||
|
||||
try {
|
||||
const response = await fetch(ENDPOINTS.manageJob, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
job_id: jobId,
|
||||
action: 'restart',
|
||||
namespace: state.selectedNamespace
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to restart job: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
alert(`Job "${jobId}" has been restarted successfully.`);
|
||||
loadJobs();
|
||||
} else {
|
||||
throw new Error(result.message);
|
||||
}
|
||||
|
||||
showLoading(false);
|
||||
} catch (error) {
|
||||
console.error('Error restarting job:', error);
|
||||
showError(`Failed to restart job: ${error.message}`);
|
||||
showLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Stop a job
|
||||
async function stopJob(jobId) {
|
||||
const purge = confirm(`Do you want to purge job "${jobId}" after stopping?`);
|
||||
|
||||
if (!confirm(`Are you sure you want to stop job "${jobId}"?`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
showLoading(true);
|
||||
|
||||
try {
|
||||
const response = await fetch(ENDPOINTS.manageJob, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
job_id: jobId,
|
||||
action: 'stop',
|
||||
namespace: state.selectedNamespace,
|
||||
purge: purge
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to stop job: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
alert(`Job "${jobId}" has been stopped${purge ? ' and purged' : ''} successfully.`);
|
||||
loadJobs();
|
||||
} else {
|
||||
throw new Error(result.message);
|
||||
}
|
||||
|
||||
showLoading(false);
|
||||
} catch (error) {
|
||||
console.error('Error stopping job:', error);
|
||||
showError(`Failed to stop job: ${error.message}`);
|
||||
showLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Render job details
|
||||
function renderJobDetails() {
|
||||
if (!state.selectedJob) {
|
||||
elements.jobDetails.innerHTML = '<p class="select-job-message">Select a job to view details</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
const job = state.selectedJob;
|
||||
const details = job.details?.job || {};
|
||||
const allocation = job.details?.latest_allocation || {};
|
||||
|
||||
let detailsHtml = `
|
||||
<h3>${job.job_id}</h3>
|
||||
<p><span class="label">Status:</span> <span class="status status-${job.status.toLowerCase()}">${job.status}</span></p>
|
||||
`;
|
||||
|
||||
if (details.Type) {
|
||||
detailsHtml += `<p><span class="label">Type:</span> ${details.Type}</p>`;
|
||||
}
|
||||
|
||||
if (details.Namespace) {
|
||||
detailsHtml += `<p><span class="label">Namespace:</span> ${details.Namespace}</p>`;
|
||||
}
|
||||
|
||||
if (details.Datacenters) {
|
||||
detailsHtml += `<p><span class="label">Datacenters:</span> ${details.Datacenters.join(', ')}</p>`;
|
||||
}
|
||||
|
||||
if (allocation.ID) {
|
||||
detailsHtml += `
|
||||
<h3>Latest Allocation</h3>
|
||||
<p><span class="label">ID:</span> ${allocation.ID}</p>
|
||||
<p><span class="label">Status:</span> ${allocation.ClientStatus || 'Unknown'}</p>
|
||||
`;
|
||||
|
||||
if (allocation.ClientDescription) {
|
||||
detailsHtml += `<p><span class="label">Description:</span> ${allocation.ClientDescription}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
elements.jobDetails.innerHTML = detailsHtml;
|
||||
}
|
||||
|
||||
// Render logs
|
||||
function renderLogs() {
|
||||
elements.logContent.textContent = state.logs[state.logs.currentTab];
|
||||
}
|
||||
|
||||
// Switch log tab
|
||||
function switchLogTab(logType) {
|
||||
state.logs.currentTab = logType;
|
||||
|
||||
// Update active tab
|
||||
elements.logTabs.forEach(tab => {
|
||||
if (tab.getAttribute('data-log-type') === logType) {
|
||||
tab.classList.add('active');
|
||||
} else {
|
||||
tab.classList.remove('active');
|
||||
}
|
||||
});
|
||||
|
||||
renderLogs();
|
||||
}
|
||||
|
||||
// Handle namespace change
|
||||
function handleNamespaceChange() {
|
||||
loadJobs();
|
||||
}
|
||||
|
||||
// Show/hide loading indicator
|
||||
function showLoading(show) {
|
||||
elements.loading.style.display = show ? 'block' : 'none';
|
||||
elements.jobTable.style.display = show ? 'none' : 'table';
|
||||
}
|
||||
|
||||
// Show error message
|
||||
function showError(message) {
|
||||
elements.errorMessage.textContent = message;
|
||||
elements.errorMessage.style.display = 'block';
|
||||
}
|
||||
|
||||
// Hide error message
|
||||
function hideError() {
|
||||
elements.errorMessage.style.display = 'none';
|
||||
}
|
||||
|
||||
// Initialize the app when the DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', init);
|
66
static/index.html
Normal file
66
static/index.html
Normal file
@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Nomad Job Manager</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1>Nomad Job Manager</h1>
|
||||
<div class="controls">
|
||||
<select id="namespace-selector">
|
||||
<option value="development">development</option>
|
||||
<option value="default">default</option>
|
||||
<option value="system">system</option>
|
||||
</select>
|
||||
<button id="refresh-btn" class="btn btn-primary">Refresh</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<div class="job-list-container">
|
||||
<h2>Jobs</h2>
|
||||
<div id="loading" class="loading">Loading jobs...</div>
|
||||
<div id="error-message" class="error-message"></div>
|
||||
<table id="job-table" class="job-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Job ID</th>
|
||||
<th>Type</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="job-list">
|
||||
<!-- Jobs will be populated here -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="job-details-container">
|
||||
<h2>Job Details</h2>
|
||||
<div id="job-details">
|
||||
<p class="select-job-message">Select a job to view details</p>
|
||||
</div>
|
||||
<div id="job-logs" class="job-logs">
|
||||
<h3>Logs</h3>
|
||||
<div class="log-tabs">
|
||||
<button class="log-tab active" data-log-type="stdout">stdout</button>
|
||||
<button class="log-tab" data-log-type="stderr">stderr</button>
|
||||
</div>
|
||||
<pre id="log-content" class="log-content">Select a job to view logs</pre>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<p>Nomad MCP Service - Claude Integration</p>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
244
static/styles.css
Normal file
244
static/styles.css
Normal file
@ -0,0 +1,244 @@
|
||||
/* Base styles */
|
||||
:root {
|
||||
--primary-color: #1976d2;
|
||||
--secondary-color: #424242;
|
||||
--success-color: #4caf50;
|
||||
--danger-color: #f44336;
|
||||
--warning-color: #ff9800;
|
||||
--light-gray: #f5f5f5;
|
||||
--border-color: #e0e0e0;
|
||||
--text-color: #333;
|
||||
--text-light: #666;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
line-height: 1.6;
|
||||
color: var(--text-color);
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
/* Header */
|
||||
header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.btn {
|
||||
padding: 8px 16px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background-color: var(--success-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background-color: var(--danger-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-warning {
|
||||
background-color: var(--warning-color);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* Form elements */
|
||||
select {
|
||||
padding: 8px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 4px;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
/* Main content */
|
||||
main {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
/* Job list */
|
||||
.job-list-container {
|
||||
background-color: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.job-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.job-table th,
|
||||
.job-table td {
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.job-table th {
|
||||
background-color: var(--light-gray);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.job-table tr:hover {
|
||||
background-color: var(--light-gray);
|
||||
}
|
||||
|
||||
.job-actions {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
/* Job details */
|
||||
.job-details-container {
|
||||
background-color: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.job-details {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.job-details h3 {
|
||||
margin-top: 15px;
|
||||
margin-bottom: 5px;
|
||||
color: var(--secondary-color);
|
||||
}
|
||||
|
||||
.job-details p {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.job-details .label {
|
||||
font-weight: 600;
|
||||
color: var(--text-light);
|
||||
}
|
||||
|
||||
/* Logs */
|
||||
.job-logs {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.log-tabs {
|
||||
display: flex;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.log-tab {
|
||||
padding: 8px 16px;
|
||||
background-color: var(--light-gray);
|
||||
border: 1px solid var(--border-color);
|
||||
border-bottom: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.log-tab.active {
|
||||
background-color: white;
|
||||
border-bottom: 2px solid var(--primary-color);
|
||||
}
|
||||
|
||||
.log-content {
|
||||
background-color: #282c34;
|
||||
color: #abb2bf;
|
||||
padding: 15px;
|
||||
border-radius: 4px;
|
||||
overflow: auto;
|
||||
max-height: 300px;
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
/* Status indicators */
|
||||
.status {
|
||||
display: inline-block;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.85em;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.status-running {
|
||||
background-color: rgba(76, 175, 80, 0.2);
|
||||
color: #2e7d32;
|
||||
}
|
||||
|
||||
.status-pending {
|
||||
background-color: rgba(255, 152, 0, 0.2);
|
||||
color: #ef6c00;
|
||||
}
|
||||
|
||||
.status-dead {
|
||||
background-color: rgba(244, 67, 54, 0.2);
|
||||
color: #c62828;
|
||||
}
|
||||
|
||||
/* Loading and error states */
|
||||
.loading {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
color: var(--text-light);
|
||||
}
|
||||
|
||||
.error-message {
|
||||
padding: 10px;
|
||||
background-color: rgba(244, 67, 54, 0.1);
|
||||
color: var(--danger-color);
|
||||
border-radius: 4px;
|
||||
margin: 10px 0;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.select-job-message {
|
||||
color: var(--text-light);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Footer */
|
||||
footer {
|
||||
margin-top: 40px;
|
||||
text-align: center;
|
||||
color: var(--text-light);
|
||||
font-size: 0.9em;
|
||||
}
|
Reference in New Issue
Block a user