cluster_ec_shards.templ 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. package app
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/admin/dash"
  5. )
  6. templ ClusterEcShards(data dash.ClusterEcShardsData) {
  7. <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
  8. <div>
  9. <h1 class="h2">
  10. <i class="fas fa-th-large me-2"></i>EC Shards
  11. </h1>
  12. if data.FilterCollection != "" {
  13. <div class="d-flex align-items-center mt-2">
  14. if data.FilterCollection == "default" {
  15. <span class="badge bg-secondary text-white me-2">
  16. <i class="fas fa-filter me-1"></i>Collection: default
  17. </span>
  18. } else {
  19. <span class="badge bg-info text-white me-2">
  20. <i class="fas fa-filter me-1"></i>Collection: {data.FilterCollection}
  21. </span>
  22. }
  23. <a href="/cluster/ec-shards" class="btn btn-sm btn-outline-secondary">
  24. <i class="fas fa-times me-1"></i>Clear Filter
  25. </a>
  26. </div>
  27. }
  28. </div>
  29. <div class="btn-toolbar mb-2 mb-md-0">
  30. <div class="btn-group me-2">
  31. <select class="form-select form-select-sm me-2" id="pageSizeSelect" onchange="changePageSize()" style="width: auto;">
  32. <option value="50" if data.PageSize == 50 { selected="selected" }>50 per page</option>
  33. <option value="100" if data.PageSize == 100 { selected="selected" }>100 per page</option>
  34. <option value="200" if data.PageSize == 200 { selected="selected" }>200 per page</option>
  35. <option value="500" if data.PageSize == 500 { selected="selected" }>500 per page</option>
  36. </select>
  37. <button type="button" class="btn btn-sm btn-outline-primary" onclick="exportEcShards()">
  38. <i class="fas fa-download me-1"></i>Export
  39. </button>
  40. </div>
  41. </div>
  42. </div>
  43. <!-- Statistics Cards -->
  44. <div class="row mb-4">
  45. <div class="col-md-3">
  46. <div class="card text-bg-primary">
  47. <div class="card-body">
  48. <div class="d-flex justify-content-between">
  49. <div>
  50. <h6 class="card-title">Total Shards</h6>
  51. <h4 class="mb-0">{fmt.Sprintf("%d", data.TotalShards)}</h4>
  52. </div>
  53. <div class="align-self-center">
  54. <i class="fas fa-puzzle-piece fa-2x"></i>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="col-md-3">
  61. <div class="card text-bg-info">
  62. <div class="card-body">
  63. <div class="d-flex justify-content-between">
  64. <div>
  65. <h6 class="card-title">EC Volumes</h6>
  66. <h4 class="mb-0">{fmt.Sprintf("%d", data.TotalVolumes)}</h4>
  67. </div>
  68. <div class="align-self-center">
  69. <i class="fas fa-database fa-2x"></i>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. <div class="col-md-3">
  76. <div class="card text-bg-success">
  77. <div class="card-body">
  78. <div class="d-flex justify-content-between">
  79. <div>
  80. <h6 class="card-title">Healthy Volumes</h6>
  81. <h4 class="mb-0">{fmt.Sprintf("%d", data.VolumesWithAllShards)}</h4>
  82. <small>Complete (14/14 shards)</small>
  83. </div>
  84. <div class="align-self-center">
  85. <i class="fas fa-check-circle fa-2x"></i>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. <div class="col-md-3">
  92. <div class="card text-bg-warning">
  93. <div class="card-body">
  94. <div class="d-flex justify-content-between">
  95. <div>
  96. <h6 class="card-title">Degraded Volumes</h6>
  97. <h4 class="mb-0">{fmt.Sprintf("%d", data.VolumesWithMissingShards)}</h4>
  98. <small>Incomplete/Critical</small>
  99. </div>
  100. <div class="align-self-center">
  101. <i class="fas fa-exclamation-triangle fa-2x"></i>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. <!-- Shards Table -->
  109. <div class="table-responsive">
  110. <table class="table table-striped table-hover" id="ecShardsTable">
  111. <thead>
  112. <tr>
  113. <th>
  114. <a href="#" onclick="sortBy('volume_id')" class="text-dark text-decoration-none">
  115. Volume ID
  116. if data.SortBy == "volume_id" {
  117. if data.SortOrder == "asc" {
  118. <i class="fas fa-sort-up ms-1"></i>
  119. } else {
  120. <i class="fas fa-sort-down ms-1"></i>
  121. }
  122. } else {
  123. <i class="fas fa-sort ms-1 text-muted"></i>
  124. }
  125. </a>
  126. </th>
  127. if data.ShowCollectionColumn {
  128. <th>
  129. <a href="#" onclick="sortBy('collection')" class="text-dark text-decoration-none">
  130. Collection
  131. if data.SortBy == "collection" {
  132. if data.SortOrder == "asc" {
  133. <i class="fas fa-sort-up ms-1"></i>
  134. } else {
  135. <i class="fas fa-sort-down ms-1"></i>
  136. }
  137. } else {
  138. <i class="fas fa-sort ms-1 text-muted"></i>
  139. }
  140. </a>
  141. </th>
  142. }
  143. <th>
  144. <a href="#" onclick="sortBy('server')" class="text-dark text-decoration-none">
  145. Server
  146. if data.SortBy == "server" {
  147. if data.SortOrder == "asc" {
  148. <i class="fas fa-sort-up ms-1"></i>
  149. } else {
  150. <i class="fas fa-sort-down ms-1"></i>
  151. }
  152. } else {
  153. <i class="fas fa-sort ms-1 text-muted"></i>
  154. }
  155. </a>
  156. </th>
  157. if data.ShowDataCenterColumn {
  158. <th>
  159. <a href="#" onclick="sortBy('datacenter')" class="text-dark text-decoration-none">
  160. Data Center
  161. if data.SortBy == "datacenter" {
  162. if data.SortOrder == "asc" {
  163. <i class="fas fa-sort-up ms-1"></i>
  164. } else {
  165. <i class="fas fa-sort-down ms-1"></i>
  166. }
  167. } else {
  168. <i class="fas fa-sort ms-1 text-muted"></i>
  169. }
  170. </a>
  171. </th>
  172. }
  173. if data.ShowRackColumn {
  174. <th>
  175. <a href="#" onclick="sortBy('rack')" class="text-dark text-decoration-none">
  176. Rack
  177. if data.SortBy == "rack" {
  178. if data.SortOrder == "asc" {
  179. <i class="fas fa-sort-up ms-1"></i>
  180. } else {
  181. <i class="fas fa-sort-down ms-1"></i>
  182. }
  183. } else {
  184. <i class="fas fa-sort ms-1 text-muted"></i>
  185. }
  186. </a>
  187. </th>
  188. }
  189. <th class="text-dark">Distribution</th>
  190. <th class="text-dark">Status</th>
  191. <th class="text-dark">Actions</th>
  192. </tr>
  193. </thead>
  194. <tbody>
  195. for _, shard := range data.EcShards {
  196. <tr>
  197. <td>
  198. <span class="fw-bold">{fmt.Sprintf("%d", shard.VolumeID)}</span>
  199. </td>
  200. if data.ShowCollectionColumn {
  201. <td>
  202. if shard.Collection != "" {
  203. <a href="/cluster/ec-shards?collection={shard.Collection}" class="text-decoration-none">
  204. <span class="badge bg-info text-white">{shard.Collection}</span>
  205. </a>
  206. } else {
  207. <a href="/cluster/ec-shards?collection=default" class="text-decoration-none">
  208. <span class="badge bg-secondary text-white">default</span>
  209. </a>
  210. }
  211. </td>
  212. }
  213. <td>
  214. <code class="small">{shard.Server}</code>
  215. </td>
  216. if data.ShowDataCenterColumn {
  217. <td>
  218. <span class="badge bg-outline-primary">{shard.DataCenter}</span>
  219. </td>
  220. }
  221. if data.ShowRackColumn {
  222. <td>
  223. <span class="badge bg-outline-secondary">{shard.Rack}</span>
  224. </td>
  225. }
  226. <td>
  227. @displayShardDistribution(shard, data.EcShards)
  228. </td>
  229. <td>
  230. @displayVolumeStatus(shard)
  231. </td>
  232. <td>
  233. <div class="btn-group" role="group">
  234. <button type="button" class="btn btn-sm btn-outline-primary"
  235. onclick="showShardDetails(event)"
  236. data-volume-id={ fmt.Sprintf("%d", shard.VolumeID) }
  237. title="View EC volume details">
  238. <i class="fas fa-info-circle"></i>
  239. </button>
  240. if !shard.IsComplete {
  241. <button type="button" class="btn btn-sm btn-outline-warning"
  242. onclick="repairVolume(event)"
  243. data-volume-id={ fmt.Sprintf("%d", shard.VolumeID) }
  244. title="Repair missing shards">
  245. <i class="fas fa-wrench"></i>
  246. </button>
  247. }
  248. </div>
  249. </td>
  250. </tr>
  251. }
  252. </tbody>
  253. </table>
  254. </div>
  255. <!-- Pagination -->
  256. if data.TotalPages > 1 {
  257. <nav aria-label="EC Shards pagination">
  258. <ul class="pagination justify-content-center">
  259. if data.CurrentPage > 1 {
  260. <li class="page-item">
  261. <a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.CurrentPage-1) }>
  262. <i class="fas fa-chevron-left"></i>
  263. </a>
  264. </li>
  265. }
  266. <!-- First page -->
  267. if data.CurrentPage > 3 {
  268. <li class="page-item">
  269. <a class="page-link" href="#" onclick="goToPage(1)">1</a>
  270. </li>
  271. if data.CurrentPage > 4 {
  272. <li class="page-item disabled">
  273. <span class="page-link">...</span>
  274. </li>
  275. }
  276. }
  277. <!-- Current page and neighbors -->
  278. if data.CurrentPage > 1 && data.CurrentPage-1 >= 1 {
  279. <li class="page-item">
  280. <a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.CurrentPage-1) }>{fmt.Sprintf("%d", data.CurrentPage-1)}</a>
  281. </li>
  282. }
  283. <li class="page-item active">
  284. <span class="page-link">{fmt.Sprintf("%d", data.CurrentPage)}</span>
  285. </li>
  286. if data.CurrentPage < data.TotalPages && data.CurrentPage+1 <= data.TotalPages {
  287. <li class="page-item">
  288. <a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.CurrentPage+1) }>{fmt.Sprintf("%d", data.CurrentPage+1)}</a>
  289. </li>
  290. }
  291. <!-- Last page -->
  292. if data.CurrentPage < data.TotalPages-2 {
  293. if data.CurrentPage < data.TotalPages-3 {
  294. <li class="page-item disabled">
  295. <span class="page-link">...</span>
  296. </li>
  297. }
  298. <li class="page-item">
  299. <a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.TotalPages) }>{fmt.Sprintf("%d", data.TotalPages)}</a>
  300. </li>
  301. }
  302. if data.CurrentPage < data.TotalPages {
  303. <li class="page-item">
  304. <a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.CurrentPage+1) }>
  305. <i class="fas fa-chevron-right"></i>
  306. </a>
  307. </li>
  308. }
  309. </ul>
  310. </nav>
  311. }
  312. <!-- JavaScript -->
  313. <script>
  314. function sortBy(field) {
  315. const currentSort = "{data.SortBy}";
  316. const currentOrder = "{data.SortOrder}";
  317. let newOrder = 'asc';
  318. if (currentSort === field && currentOrder === 'asc') {
  319. newOrder = 'desc';
  320. }
  321. updateUrl({
  322. sortBy: field,
  323. sortOrder: newOrder,
  324. page: 1
  325. });
  326. }
  327. function goToPage(event) {
  328. // Get data from the link element (not any child elements)
  329. const link = event.target.closest('a');
  330. const page = link.getAttribute('data-page');
  331. updateUrl({ page: page });
  332. }
  333. function changePageSize() {
  334. const pageSize = document.getElementById('pageSizeSelect').value;
  335. updateUrl({ pageSize: pageSize, page: 1 });
  336. }
  337. function updateUrl(params) {
  338. const url = new URL(window.location);
  339. Object.keys(params).forEach(key => {
  340. if (params[key]) {
  341. url.searchParams.set(key, params[key]);
  342. } else {
  343. url.searchParams.delete(key);
  344. }
  345. });
  346. window.location.href = url.toString();
  347. }
  348. function exportEcShards() {
  349. const url = new URL('/api/cluster/ec-shards/export', window.location.origin);
  350. const params = new URLSearchParams(window.location.search);
  351. params.forEach((value, key) => {
  352. url.searchParams.set(key, value);
  353. });
  354. window.open(url.toString(), '_blank');
  355. }
  356. function showShardDetails(event) {
  357. // Get data from the button element (not the icon inside it)
  358. const button = event.target.closest('button');
  359. const volumeId = button.getAttribute('data-volume-id');
  360. // Navigate to the EC volume details page
  361. window.location.href = `/cluster/ec-volumes/${volumeId}`;
  362. }
  363. function repairVolume(event) {
  364. // Get data from the button element (not the icon inside it)
  365. const button = event.target.closest('button');
  366. const volumeId = button.getAttribute('data-volume-id');
  367. if (confirm(`Are you sure you want to repair missing shards for volume ${volumeId}?`)) {
  368. fetch(`/api/cluster/volumes/${volumeId}/repair`, {
  369. method: 'POST',
  370. headers: {
  371. 'Content-Type': 'application/json',
  372. }
  373. })
  374. .then(response => response.json())
  375. .then(data => {
  376. if (data.success) {
  377. alert('Repair initiated successfully');
  378. location.reload();
  379. } else {
  380. alert('Failed to initiate repair: ' + data.error);
  381. }
  382. })
  383. .catch(error => {
  384. alert('Error: ' + error.message);
  385. });
  386. }
  387. }
  388. </script>
  389. }
  390. // displayShardDistribution shows the distribution summary for a volume's shards
  391. templ displayShardDistribution(shard dash.EcShardWithInfo, allShards []dash.EcShardWithInfo) {
  392. <div class="small">
  393. <i class="fas fa-sitemap me-1"></i>
  394. { calculateDistributionSummary(shard.VolumeID, allShards) }
  395. </div>
  396. }
  397. // displayVolumeStatus shows an improved status display
  398. templ displayVolumeStatus(shard dash.EcShardWithInfo) {
  399. if shard.IsComplete {
  400. <span class="badge bg-success"><i class="fas fa-check me-1"></i>Complete</span>
  401. } else {
  402. if len(shard.MissingShards) > 10 {
  403. <span class="badge bg-danger"><i class="fas fa-skull me-1"></i>Critical ({fmt.Sprintf("%d", len(shard.MissingShards))} missing)</span>
  404. } else if len(shard.MissingShards) > 6 {
  405. <span class="badge bg-warning"><i class="fas fa-exclamation-triangle me-1"></i>Degraded ({fmt.Sprintf("%d", len(shard.MissingShards))} missing)</span>
  406. } else if len(shard.MissingShards) > 2 {
  407. <span class="badge bg-warning"><i class="fas fa-info-circle me-1"></i>Incomplete ({fmt.Sprintf("%d", len(shard.MissingShards))} missing)</span>
  408. } else {
  409. <span class="badge bg-info"><i class="fas fa-info-circle me-1"></i>Minor Issues ({fmt.Sprintf("%d", len(shard.MissingShards))} missing)</span>
  410. }
  411. }
  412. }
  413. // calculateDistributionSummary calculates and formats the distribution summary
  414. func calculateDistributionSummary(volumeID uint32, allShards []dash.EcShardWithInfo) string {
  415. dataCenters := make(map[string]bool)
  416. racks := make(map[string]bool)
  417. servers := make(map[string]bool)
  418. for _, s := range allShards {
  419. if s.VolumeID == volumeID {
  420. dataCenters[s.DataCenter] = true
  421. racks[s.Rack] = true
  422. servers[s.Server] = true
  423. }
  424. }
  425. return fmt.Sprintf("%d DCs, %d racks, %d servers", len(dataCenters), len(racks), len(servers))
  426. }