maintenance_config.templ 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. package app
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/admin/maintenance"
  5. )
  6. templ MaintenanceConfig(data *maintenance.MaintenanceConfigData) {
  7. <div class="container-fluid">
  8. <div class="row mb-4">
  9. <div class="col-12">
  10. <div class="d-flex justify-content-between align-items-center">
  11. <h2 class="mb-0">
  12. <i class="fas fa-cog me-2"></i>
  13. Maintenance Configuration
  14. </h2>
  15. <div class="btn-group">
  16. <a href="/maintenance" class="btn btn-outline-secondary">
  17. <i class="fas fa-arrow-left me-1"></i>
  18. Back to Queue
  19. </a>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="row">
  25. <div class="col-12">
  26. <div class="card">
  27. <div class="card-header">
  28. <h5 class="mb-0">System Settings</h5>
  29. </div>
  30. <div class="card-body">
  31. <form>
  32. <div class="mb-3">
  33. <div class="form-check form-switch">
  34. <input class="form-check-input" type="checkbox" id="enabled" checked?={data.IsEnabled}>
  35. <label class="form-check-label" for="enabled">
  36. <strong>Enable Maintenance System</strong>
  37. </label>
  38. </div>
  39. <small class="form-text text-muted">
  40. When enabled, the system will automatically scan for and execute maintenance tasks.
  41. </small>
  42. </div>
  43. <div class="mb-3">
  44. <label for="scanInterval" class="form-label">Scan Interval (minutes)</label>
  45. <input type="number" class="form-control" id="scanInterval"
  46. value={fmt.Sprintf("%.0f", float64(data.Config.ScanIntervalSeconds)/60)}
  47. placeholder="30 (default)" min="1" max="1440">
  48. <small class="form-text text-muted">
  49. How often to scan for maintenance tasks (1-1440 minutes). <strong>Default: 30 minutes</strong>
  50. </small>
  51. </div>
  52. <div class="mb-3">
  53. <label for="workerTimeout" class="form-label">Worker Timeout (minutes)</label>
  54. <input type="number" class="form-control" id="workerTimeout"
  55. value={fmt.Sprintf("%.0f", float64(data.Config.WorkerTimeoutSeconds)/60)}
  56. placeholder="5 (default)" min="1" max="60">
  57. <small class="form-text text-muted">
  58. How long to wait for worker heartbeat before considering it inactive (1-60 minutes). <strong>Default: 5 minutes</strong>
  59. </small>
  60. </div>
  61. <div class="mb-3">
  62. <label for="taskTimeout" class="form-label">Task Timeout (hours)</label>
  63. <input type="number" class="form-control" id="taskTimeout"
  64. value={fmt.Sprintf("%.0f", float64(data.Config.TaskTimeoutSeconds)/3600)}
  65. placeholder="2 (default)" min="1" max="24">
  66. <small class="form-text text-muted">
  67. Maximum time allowed for a single task to complete (1-24 hours). <strong>Default: 2 hours</strong>
  68. </small>
  69. </div>
  70. <div class="mb-3">
  71. <label for="globalMaxConcurrent" class="form-label">Global Concurrent Limit</label>
  72. <input type="number" class="form-control" id="globalMaxConcurrent"
  73. value={fmt.Sprintf("%d", data.Config.Policy.GlobalMaxConcurrent)}
  74. placeholder="4 (default)" min="1" max="20">
  75. <small class="form-text text-muted">
  76. Maximum number of maintenance tasks that can run simultaneously across all workers (1-20). <strong>Default: 4</strong>
  77. </small>
  78. </div>
  79. <div class="mb-3">
  80. <label for="maxRetries" class="form-label">Default Max Retries</label>
  81. <input type="number" class="form-control" id="maxRetries"
  82. value={fmt.Sprintf("%d", data.Config.MaxRetries)}
  83. placeholder="3 (default)" min="0" max="10">
  84. <small class="form-text text-muted">
  85. Default number of times to retry failed tasks (0-10). <strong>Default: 3</strong>
  86. </small>
  87. </div>
  88. <div class="mb-3">
  89. <label for="retryDelay" class="form-label">Retry Delay (minutes)</label>
  90. <input type="number" class="form-control" id="retryDelay"
  91. value={fmt.Sprintf("%.0f", float64(data.Config.RetryDelaySeconds)/60)}
  92. placeholder="15 (default)" min="1" max="120">
  93. <small class="form-text text-muted">
  94. Time to wait before retrying failed tasks (1-120 minutes). <strong>Default: 15 minutes</strong>
  95. </small>
  96. </div>
  97. <div class="mb-3">
  98. <label for="taskRetention" class="form-label">Task Retention (days)</label>
  99. <input type="number" class="form-control" id="taskRetention"
  100. value={fmt.Sprintf("%.0f", float64(data.Config.TaskRetentionSeconds)/(24*3600))}
  101. placeholder="7 (default)" min="1" max="30">
  102. <small class="form-text text-muted">
  103. How long to keep completed/failed task records (1-30 days). <strong>Default: 7 days</strong>
  104. </small>
  105. </div>
  106. <div class="d-flex gap-2">
  107. <button type="button" class="btn btn-primary" onclick="saveConfiguration()">
  108. <i class="fas fa-save me-1"></i>
  109. Save Configuration
  110. </button>
  111. <button type="button" class="btn btn-secondary" onclick="resetToDefaults()">
  112. <i class="fas fa-undo me-1"></i>
  113. Reset to Defaults
  114. </button>
  115. </div>
  116. </form>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. <!-- Individual Task Configuration Menu -->
  122. <div class="row mt-4">
  123. <div class="col-12">
  124. <div class="card">
  125. <div class="card-header">
  126. <h5 class="mb-0">
  127. <i class="fas fa-cogs me-2"></i>
  128. Task Configuration
  129. </h5>
  130. </div>
  131. <div class="card-body">
  132. <p class="text-muted mb-3">Configure specific settings for each maintenance task type.</p>
  133. <div class="list-group">
  134. for _, menuItem := range data.MenuItems {
  135. <a href={templ.SafeURL(menuItem.Path)} class="list-group-item list-group-item-action">
  136. <div class="d-flex w-100 justify-content-between">
  137. <h6 class="mb-1">
  138. <i class={menuItem.Icon + " me-2"}></i>
  139. {menuItem.DisplayName}
  140. </h6>
  141. if menuItem.IsEnabled {
  142. <span class="badge bg-success">Enabled</span>
  143. } else {
  144. <span class="badge bg-secondary">Disabled</span>
  145. }
  146. </div>
  147. <p class="mb-1 small text-muted">{menuItem.Description}</p>
  148. </a>
  149. }
  150. </div>
  151. </div>
  152. </div>
  153. </div>
  154. </div>
  155. <!-- Statistics Overview -->
  156. <div class="row mt-4">
  157. <div class="col-12">
  158. <div class="card">
  159. <div class="card-header">
  160. <h5 class="mb-0">System Statistics</h5>
  161. </div>
  162. <div class="card-body">
  163. <div class="row">
  164. <div class="col-md-3">
  165. <div class="text-center">
  166. <h6 class="text-muted">Last Scan</h6>
  167. <p class="mb-0">{data.LastScanTime.Format("2006-01-02 15:04:05")}</p>
  168. </div>
  169. </div>
  170. <div class="col-md-3">
  171. <div class="text-center">
  172. <h6 class="text-muted">Next Scan</h6>
  173. <p class="mb-0">{data.NextScanTime.Format("2006-01-02 15:04:05")}</p>
  174. </div>
  175. </div>
  176. <div class="col-md-3">
  177. <div class="text-center">
  178. <h6 class="text-muted">Total Tasks</h6>
  179. <p class="mb-0">{fmt.Sprintf("%d", data.SystemStats.TotalTasks)}</p>
  180. </div>
  181. </div>
  182. <div class="col-md-3">
  183. <div class="text-center">
  184. <h6 class="text-muted">Active Workers</h6>
  185. <p class="mb-0">{fmt.Sprintf("%d", data.SystemStats.ActiveWorkers)}</p>
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. <script>
  195. function saveConfiguration() {
  196. // First, get current configuration to preserve existing values
  197. fetch('/api/maintenance/config')
  198. .then(response => response.json())
  199. .then(currentConfig => {
  200. // Update only the fields from the form
  201. const updatedConfig = {
  202. ...currentConfig.config, // Preserve existing config
  203. enabled: document.getElementById('enabled').checked,
  204. scan_interval_seconds: parseInt(document.getElementById('scanInterval').value) * 60, // Convert to seconds
  205. worker_timeout_seconds: parseInt(document.getElementById('workerTimeout').value) * 60, // Convert to seconds
  206. task_timeout_seconds: parseInt(document.getElementById('taskTimeout').value) * 3600, // Convert to seconds
  207. retry_delay_seconds: parseInt(document.getElementById('retryDelay').value) * 60, // Convert to seconds
  208. max_retries: parseInt(document.getElementById('maxRetries').value),
  209. task_retention_seconds: parseInt(document.getElementById('taskRetention').value) * 24 * 3600, // Convert to seconds
  210. policy: {
  211. ...currentConfig.config.policy, // Preserve existing policy
  212. global_max_concurrent: parseInt(document.getElementById('globalMaxConcurrent').value)
  213. }
  214. };
  215. // Send the updated configuration
  216. return fetch('/api/maintenance/config', {
  217. method: 'PUT',
  218. headers: {
  219. 'Content-Type': 'application/json',
  220. },
  221. body: JSON.stringify(updatedConfig)
  222. });
  223. })
  224. .then(response => response.json())
  225. .then(data => {
  226. if (data.success) {
  227. alert('Configuration saved successfully');
  228. location.reload(); // Reload to show updated values
  229. } else {
  230. alert('Failed to save configuration: ' + (data.error || 'Unknown error'));
  231. }
  232. })
  233. .catch(error => {
  234. alert('Error: ' + error.message);
  235. });
  236. }
  237. function resetToDefaults() {
  238. if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {
  239. // Reset form to defaults (matching DefaultMaintenanceConfig values)
  240. document.getElementById('enabled').checked = false;
  241. document.getElementById('scanInterval').value = '30';
  242. document.getElementById('workerTimeout').value = '5';
  243. document.getElementById('taskTimeout').value = '2';
  244. document.getElementById('globalMaxConcurrent').value = '4';
  245. document.getElementById('maxRetries').value = '3';
  246. document.getElementById('retryDelay').value = '15';
  247. document.getElementById('taskRetention').value = '7';
  248. }
  249. }
  250. </script>
  251. }