-
Notifications
You must be signed in to change notification settings - Fork 117
feat(gui): add full computing unit tab #4331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gracecluvohio
wants to merge
25
commits into
apache:main
Choose a base branch
from
gracecluvohio:add-computing-unit-tab-full
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c0962de
feat(gui): add computing unit types
gracecluvohio 70860c4
feat(gui): add computing unit shell
gracecluvohio df3a9ba
feat(gui): add computing unit full
gracecluvohio e7b1d51
Merge branch 'main' into add-computing-unit-tab-full
chenlica ac4dddc
fix(gui): change "Computing Units" to "Compute" on dashboard
gracecluvohio b2b720d
Merge remote-tracking branch 'origin/add-computing-unit-tab-full' int…
gracecluvohio c2c8218
Merge branch 'main' into add-computing-unit-tab-full
kunwp1 1d0a56c
Merge branch 'main' into add-computing-unit-tab-full
chenlica 0f8eb7e
Merge branch 'main' into add-computing-unit-tab-full
gracecluvohio f049bd7
test(gui): add test for dashboard computing unit tab
gracecluvohio 749222d
style: fix linting errors in computing unit components
gracecluvohio 6c6d957
fix(ui): remove xss vector by turning metadata table into a component
gracecluvohio de266c4
fix(ui): use optimized cdkVirtualFor instead of ngFor
gracecluvohio dd6d2c4
test(ui): add async and await to handle asynchronous compileComponent…
gracecluvohio 4353862
fix(ui): change buildComputingUnitMetadataTable to ComputingUnitMetad…
gracecluvohio e2f78c5
refactor(ui): remove unused editable field
gracecluvohio b7fdd1d
feat(ui): add default URI to local computing units
gracecluvohio c00782a
feat(ui): remove extra delete computing unit confirmation
gracecluvohio ccd6d0b
fix(ui): replace duplicate id's with classes
gracecluvohio 0ebad51
feat(ui): add sharing to dashboard computing units
gracecluvohio ca7d78a
style: add prettier formatting
gracecluvohio d71df44
refactor(ui): add creation of computing unit to ComputingUnitActionsS…
gracecluvohio 3d230aa
refactor(ui): add termination of computing unit to ComputingUnitActio…
gracecluvohio d4c072b
refactor(ui): remove redundant code from ComputingUnitSelectionCompon…
gracecluvohio b22c915
style: add prettier formatting
gracecluvohio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { Component, inject } from "@angular/core"; | ||
| import { NZ_MODAL_DATA } from "ng-zorro-antd/modal"; | ||
| import { DashboardWorkflowComputingUnit } from "../../workspace/types/workflow-computing-unit"; | ||
|
|
||
| @Component({ | ||
| template: ` | ||
| <table class="ant-table"> | ||
| <tbody> | ||
| <tr> | ||
| <th style="width: 150px;">Name</th> | ||
| <td>{{ unit.computingUnit.name }}</td> | ||
| </tr> | ||
| <tr> | ||
| <th>Status</th> | ||
| <td>{{ unit.status }}</td> | ||
| </tr> | ||
| <tr> | ||
| <th>Type</th> | ||
| <td>{{ unit.computingUnit.type }}</td> | ||
| </tr> | ||
| <tr> | ||
| <th>CPU Limit</th> | ||
| <td>{{ unit.computingUnit.resource.cpuLimit }}</td> | ||
| </tr> | ||
| <tr> | ||
| <th>Memory Limit</th> | ||
| <td>{{ unit.computingUnit.resource.memoryLimit }}</td> | ||
| </tr> | ||
| <tr> | ||
| <th>GPU Limit</th> | ||
| <td>{{ unit.computingUnit.resource.gpuLimit || "None" }}</td> | ||
| </tr> | ||
| <tr> | ||
| <th>JVM Memory</th> | ||
| <td>{{ unit.computingUnit.resource.jvmMemorySize }}</td> | ||
| </tr> | ||
| <tr> | ||
| <th>Shared Memory</th> | ||
| <td>{{ unit.computingUnit.resource.shmSize }}</td> | ||
| </tr> | ||
| <tr> | ||
| <th>Created</th> | ||
| <td>{{ createdAt }}</td> | ||
| </tr> | ||
| <tr> | ||
| <th>Access</th> | ||
| <td>{{ unit.isOwner ? "Owner" : unit.accessPrivilege }}</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| `, | ||
| }) | ||
| export class ComputingUnitMetadataComponent { | ||
| readonly unit: DashboardWorkflowComputingUnit = inject(NZ_MODAL_DATA); | ||
| readonly createdAt = new Date(this.unit.computingUnit.creationTime).toLocaleString(); | ||
| } | ||
|
|
||
| export function parseResourceUnit(resource: string): string { | ||
| // check if has a capacity (is a number followed by a unit) | ||
| if (!resource || resource === "NaN") return "NaN"; | ||
| const re = /^(\d+(\.\d+)?)([a-zA-Z]*)$/; | ||
| const match = resource.match(re); | ||
| if (match) { | ||
| return match[3] || ""; | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| export function parseResourceNumber(resource: string): number { | ||
| // check if has a capacity (is a number followed by a unit) | ||
| if (!resource || resource === "NaN") return 0; | ||
| const re = /^(\d+(\.\d+)?)([a-zA-Z]*)$/; | ||
| const match = resource.match(re); | ||
| if (match) { | ||
| return parseFloat(match[1]); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| export function cpuResourceConversion(from: string, toUnit: string): string { | ||
| // cpu conversions | ||
| type CpuUnit = "n" | "u" | "m" | ""; | ||
| const cpuScales: { [key in CpuUnit]: number } = { | ||
| n: 1, | ||
| u: 1_000, | ||
| m: 1_000_000, | ||
| "": 1_000_000_000, | ||
| }; | ||
| const fromUnit = parseResourceUnit(from) as CpuUnit; | ||
| const fromNumber = parseResourceNumber(from); | ||
|
|
||
| // Handle empty unit in input (means cores) | ||
| const effectiveFromUnit = (fromUnit || "") as CpuUnit; | ||
| const effectiveToUnit = (toUnit || "") as CpuUnit; | ||
|
|
||
| // Convert to base units (nanocores) then to target unit | ||
| const fromScaled = fromNumber * (cpuScales[effectiveFromUnit] || cpuScales["m"]); | ||
| const toScaled = fromScaled / (cpuScales[effectiveToUnit] || cpuScales[""]); | ||
|
|
||
| // For display purposes, use appropriate precision | ||
| if (effectiveToUnit === "") { | ||
| return toScaled.toFixed(4); // 4 decimal places for cores | ||
| } else if (effectiveToUnit === "m") { | ||
| return toScaled.toFixed(2); // 2 decimal places for millicores | ||
| } else { | ||
| return Math.round(toScaled).toString(); // Whole numbers for smaller units | ||
| } | ||
| } | ||
|
|
||
| export function memoryResourceConversion(from: string, toUnit: string): string { | ||
| // memory conversion | ||
| type MemoryUnit = "Ki" | "Mi" | "Gi" | ""; | ||
| const memoryScales: { [key in MemoryUnit]: number } = { | ||
| "": 1, | ||
| Ki: 1024, | ||
| Mi: 1024 * 1024, | ||
| Gi: 1024 * 1024 * 1024, | ||
| }; | ||
| const fromUnit = parseResourceUnit(from) as MemoryUnit; | ||
| const fromNumber = parseResourceNumber(from); | ||
|
|
||
| // Handle empty unit in input (means bytes) | ||
| const effectiveFromUnit = (fromUnit || "") as MemoryUnit; | ||
| const effectiveToUnit = (toUnit || "") as MemoryUnit; | ||
|
|
||
| // Convert to base units (bytes) then to target unit | ||
| const fromScaled = fromNumber * (memoryScales[effectiveFromUnit] || 1); | ||
| const toScaled = fromScaled / (memoryScales[effectiveToUnit] || 1); | ||
|
|
||
| // For memory, we want to show in the same format as the limit (typically X.XXX Gi) | ||
| return toScaled.toFixed(4); | ||
| } | ||
|
|
||
| export function cpuPercentage(usage: string, limit: string): number { | ||
| if (usage === "N/A" || limit === "N/A") return 0; | ||
|
|
||
| // Convert to the same unit for comparison | ||
| const displayUnit = ""; // Convert to cores for percentage calculation | ||
|
|
||
| // Use our existing conversion method to get values in the same unit | ||
| const usageValue = parseFloat(cpuResourceConversion(usage, displayUnit)); | ||
| const limitValue = parseFloat(cpuResourceConversion(limit, displayUnit)); | ||
|
|
||
| if (limitValue <= 0) return 0; | ||
|
|
||
| // Calculate percentage and ensure it doesn't exceed 100% | ||
| const percentage = (usageValue / limitValue) * 100; | ||
|
|
||
| return Math.min(percentage, 100); | ||
| } | ||
|
|
||
| export function memoryPercentage(usage: string, limit: string): number { | ||
| if (usage === "N/A" || limit === "N/A") return 0; | ||
|
|
||
| // Convert to the same unit for comparison | ||
| const displayUnit = "Gi"; // Convert to GiB for percentage calculation | ||
|
|
||
| // Use our existing conversion method to get values in the same unit | ||
| const usageValue = parseFloat(memoryResourceConversion(usage, displayUnit)); | ||
| const limitValue = parseFloat(memoryResourceConversion(limit, displayUnit)); | ||
|
|
||
| if (limitValue <= 0) return 0; | ||
|
|
||
| // Calculate percentage and ensure it doesn't exceed 100% | ||
| const percentage = (usageValue / limitValue) * 100; | ||
|
|
||
| return Math.min(percentage, 100); | ||
| } | ||
|
|
||
| export function findNearestValidStep(value: number, jvmMemorySteps: number[]): number { | ||
| if (jvmMemorySteps.length === 0) return 1; | ||
| if (jvmMemorySteps.includes(value)) return value; | ||
|
|
||
| // Find the closest step value | ||
| return jvmMemorySteps.reduce((prev, curr) => { | ||
| return Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev; | ||
| }); | ||
| } | ||
|
|
||
| export const unitTypeMessageTemplate = { | ||
| local: { | ||
| createTitle: "Connect to a Local Computing Unit", | ||
| terminateTitle: "Disconnect from Local Computing Unit", | ||
| terminateWarning: "", // no red warning | ||
| createSuccess: "Successfully connected to the local computing unit", | ||
| createFailure: "Failed to connect to the local computing unit", | ||
| terminateSuccess: "Disconnected from the local computing unit", | ||
| terminateFailure: "Failed to disconnect from the local computing unit", | ||
| terminateTooltip: "Disconnect from this computing unit", | ||
| }, | ||
| kubernetes: { | ||
| createTitle: "Create Computing Unit", | ||
| terminateTitle: "Terminate Computing Unit", | ||
| terminateWarning: | ||
| "<p style='color: #ff4d4f;'><strong>Warning:</strong> All execution results in this computing unit will be lost.</p>", | ||
| createSuccess: "Successfully created the Kubernetes computing unit", | ||
kunwp1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| createFailure: "Failed to create the Kubernetes computing unit", | ||
| terminateSuccess: "Terminated Kubernetes computing unit", | ||
| terminateFailure: "Failed to terminate Kubernetes computing unit", | ||
| terminateTooltip: "Terminate this computing unit", | ||
| }, | ||
| } as const; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.