Repository navigation
feat(rod): extract requested resources from work units using domain resources adapter #407
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b698a13
refactor(rod): populate requested_resources, shorten functions, add c…
janzak-dev 33cf9a5
refactor(rod): extractRequestedResourcesFromSpec directly operates on…
janzak-dev 09980bc
refactor(rod): simplify extractRequestedResources to read directly fr…
janzak-dev 0ac7f58
refactor(rod): use type switch on ResourceSet.resources in extractReq…
janzak-dev 61710a6
refactor(rod): use GPU and TPU as default resource type strings
janzak-dev 99c1143
refactor(rod): aggregate resources across all jobs in jobset without …
janzak-dev 27c5d9c
refactor(rod): extract resourceAccumulator struct with dedicated help…
janzak-dev e3bf04c
refactor(rod): refactor jobs_test.go to use proto.Modify and baseline…
janzak-dev 0a320c1
feat(rod): extract resourceAccumulator to separate file and test suite
janzak-dev 09d601e
refactor(rod): replace custom resourceAccumulator with domain workuni…
janzak-dev ef4891c
fix(rod): parse TPU topology dimensions to calculate total TPU chips …
janzak-dev 77d70ef
test(rod): add unit tests for TPU resource extraction and topology ch…
janzak-dev 43fe65d
refactor(rod): decompose extractRequestedResources under 15 lines and…
janzak-dev 78a5d48
feat(rod): render Resources column in Angular UI for ROD jobs table
janzak-dev 042556a
refactor(ui): simplify resource formatting logic in queue jobs table
janzak-dev bf42b43
refactor(ui): restrict QueueJobResourcesPipe input strictly to Resour…
janzak-dev 5c0f73d
refactor(rod): sync jobs.go and jobs_test.go with domain workunit.Get…
janzak-dev f223180
refactor(rod): format accelerators as ${count} x ${type}, normalize T…
janzak-dev e8f4a86
refactor(rod): extract resource type string literals into constants
janzak-dev 231cb45
refactor(rod): address PR 407 review comments
janzak-dev 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
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,132 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed 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. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| spb "xmanager_cloud/api/protos/rod" | ||
| essmsgpb "xmanager_cloud/experiment_state_server/proto/messages_go_proto" | ||
| "xmanager_cloud/internal/domain/workunit" | ||
| ) | ||
|
|
||
| const ( | ||
| resourceTypeCPU = "cpu" | ||
| resourceTypeMemory = "memory" | ||
| resourceTypeGPU = "GPU" | ||
| resourceTypeTPU = "TPU" | ||
| ) | ||
|
|
||
| type resourceAccumulator struct { | ||
| totals map[string]float64 | ||
| order []string | ||
| } | ||
|
|
||
| func (a *resourceAccumulator) add(resType string, count float64) { | ||
| if count <= 0 { | ||
| return | ||
| } | ||
| if _, exists := a.totals[resType]; !exists { | ||
| a.order = append(a.order, resType) | ||
| } | ||
| a.totals[resType] += count | ||
| } | ||
|
|
||
| // extractRequestedResources converts domain ResourceSets from workunit.GetWorkUnitResources | ||
| // into presentation DTOs ([]*spb.Resource) required by the ROD API, aggregating identical resource types. | ||
| func extractRequestedResources(wu *essmsgpb.WorkUnit) []*spb.Resource { | ||
| resourceSets := workunit.GetWorkUnitResources(wu) | ||
| if len(resourceSets) == 0 { | ||
| return nil | ||
| } | ||
| totals, order := accumulateResourceTotals(resourceSets) | ||
| return buildResourceDTOs(totals, order) | ||
| } | ||
|
|
||
| func accumulateResourceTotals(resourceSets []*essmsgpb.ResourceSet) (totals map[string]float64, order []string) { | ||
| acc := &resourceAccumulator{totals: make(map[string]float64, len(resourceSets))} | ||
| for _, rs := range resourceSets { | ||
|
VLukiantsev marked this conversation as resolved.
Resolved
VLukiantsev marked this conversation as resolved.
Resolved
|
||
| accumulateResource(rs, acc) | ||
| } | ||
| return acc.totals, acc.order | ||
| } | ||
|
|
||
| func buildResourceDTOs(totals map[string]float64, order []string) []*spb.Resource { | ||
| resources := make([]*spb.Resource, 0, len(order)) | ||
| for _, resType := range order { | ||
| resources = append(resources, &spb.Resource{ | ||
| ResourceType: resType, | ||
| Count: totals[resType], | ||
| }) | ||
| } | ||
| return resources | ||
| } | ||
|
|
||
| func accumulateResource(rs *essmsgpb.ResourceSet, acc *resourceAccumulator) { | ||
| if rs == nil || acc == nil { | ||
| return | ||
| } | ||
| if cpu := rs.GetCpuResources(); cpu != nil { | ||
| accumulateCpuResource(cpu, acc) | ||
| } else if gpu := rs.GetGpuResources(); gpu != nil { | ||
| accumulateGpuResource(gpu, acc) | ||
| } else if tpu := rs.GetTpuResources(); tpu != nil { | ||
| accumulateTpuResource(tpu, acc) | ||
| } | ||
| } | ||
|
|
||
| func accumulateCpuResource(cpu *essmsgpb.CpuResources, acc *resourceAccumulator) { | ||
| if millicores := cpu.GetCpuMillicores(); millicores > 0 { | ||
| acc.add(resourceTypeCPU, float64(millicores)/1000.0) | ||
| } | ||
| if memoryBytes := cpu.GetMemoryBytes(); memoryBytes > 0 { | ||
| acc.add(resourceTypeMemory, float64(memoryBytes)) | ||
| } | ||
| } | ||
|
|
||
| func accumulateGpuResource(gpu *essmsgpb.GpuResources, acc *resourceAccumulator) { | ||
| resType := gpu.GetType() | ||
| if resType == "" { | ||
| resType = resourceTypeGPU | ||
| } | ||
| acc.add(resType, float64(gpu.GetCount())) | ||
| } | ||
|
|
||
| func accumulateTpuResource(tpu *essmsgpb.TpuResources, acc *resourceAccumulator) { | ||
| resType := tpu.GetType() | ||
| if resType == "" { | ||
| resType = resourceTypeTPU | ||
| } | ||
| chips := parseTotalChips(tpu.GetTopology()) | ||
| acc.add(resType, float64(chips)) | ||
| } | ||
|
|
||
| func parseTotalChips(topology string) int64 { | ||
| if topology == "" { | ||
| return 1 | ||
| } | ||
| cleaned := strings.TrimSpace(strings.ToLower(topology)) | ||
| dims := strings.Split(cleaned, "x") | ||
| totalChips := int64(1) | ||
| for _, d := range dims { | ||
| v, err := strconv.ParseInt(d, 10, 64) | ||
| if err != nil || v <= 0 { | ||
| return 1 | ||
| } | ||
| totalChips *= v | ||
| } | ||
| return totalChips | ||
| } | ||
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.