Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2c89f38
Updated transfer.go
dynamic-Archu Apr 22, 2025
2bc54fb
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Apr 22, 2025
f7352f2
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Apr 24, 2025
bf1f9e5
Updated transfer.go
dynamic-Archu May 13, 2025
8c30e54
Update transfer.go
dynamic-Archu May 16, 2025
01c7a17
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu May 17, 2025
45c44cb
Updated transfer.go
dynamic-Archu May 21, 2025
182aeab
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu May 21, 2025
30d6f56
Update transfer.go
dynamic-Archu May 21, 2025
1c40c7f
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu May 26, 2025
3f8feb0
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu May 27, 2025
8679921
Update transfer.go
dynamic-Archu Jun 6, 2025
652e25c
Update transfer.go
dynamic-Archu Jun 6, 2025
4e19e51
Update transfer.go
dynamic-Archu Jun 6, 2025
eb15c0b
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Jun 19, 2025
29f767d
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Jun 21, 2025
a3b738b
Update transfer.go
dynamic-Archu Jun 23, 2025
3b15227
Update transfer.go
dynamic-Archu Jun 23, 2025
b6425da
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Jun 24, 2025
7628679
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Jun 24, 2025
8ef7222
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Jul 2, 2025
167ca50
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Jul 11, 2025
d776796
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Jul 14, 2025
134034e
Attribute update transfer.go
dynamic-Archu Jul 14, 2025
71780af
Create maxworkersattr.go
dynamic-Archu Jul 14, 2025
908c503
Update maxworkersattr.go
dynamic-Archu Jul 14, 2025
040ffef
Update init.go
dynamic-Archu Jul 14, 2025
4f36d21
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Jul 14, 2025
fad83e5
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Jul 16, 2025
f963953
Update transfer.go - comment changes
dynamic-Archu Jul 16, 2025
8350f2c
Update transfer.go
dynamic-Archu Jul 17, 2025
a2424ab
Merge branch 'main' into dynamic-Archu-patch-1
jakobmoellerdev Sep 3, 2025
29e9ce7
Update transfer.go
Umang2608 Sep 26, 2025
a8e1082
Update maxworkersattr.go
Umang2608 Sep 26, 2025
114f00b
Merge pull request #2 from Umang2608/patch-1
dynamic-Archu Oct 3, 2025
862b3aa
Revert "Patch 1"
dynamic-Archu Oct 3, 2025
e2ec35b
Merge pull request #3 from dynamic-Archu/revert-2-patch-1
dynamic-Archu Oct 3, 2025
6979f2a
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Oct 3, 2025
e345377
Update transfer_u.go
dynamic-Archu Oct 3, 2025
9db9057
Update maxworkersattr_u.go
dynamic-Archu Oct 3, 2025
54830a1
Update transfer.go
dynamic-Archu Oct 7, 2025
3ef9a1d
Merge branch 'main' into dynamic-Archu-patch-1
dynamic-Archu Oct 7, 2025
5573842
Update transfer.go
dynamic-Archu Oct 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/ocm/extensions/attrs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
_ "ocm.software/ocm/api/ocm/extensions/attrs/hashattr"
_ "ocm.software/ocm/api/ocm/extensions/attrs/keepblobattr"
_ "ocm.software/ocm/api/ocm/extensions/attrs/mapocirepoattr"
_ "ocm.software/ocm/api/ocm/extensions/attrs/maxworkersattr"
_ "ocm.software/ocm/api/ocm/extensions/attrs/ociuploadattr"
_ "ocm.software/ocm/api/ocm/extensions/attrs/plugincacheattr"
_ "ocm.software/ocm/api/ocm/extensions/attrs/plugindirattr"
_ "ocm.software/ocm/api/ocm/extensions/attrs/signingattr"

)
99 changes: 99 additions & 0 deletions api/ocm/extensions/attrs/maxworkersattr/maxworkersattr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package maxworkersattr

import (
"fmt"
"strconv"

"ocm.software/ocm/api/datacontext"
"ocm.software/ocm/api/utils/runtime"
)

const (
// ATTR_KEY is the full unique key for the max workers attribute.
// This key should reflect its location or purpose within the ocm.software domain.
ATTR_KEY = "ocm.software/ocm/api/ocm/extensions/attrs/maxworkers"
// ATTR_SHORT is a shorter alias for the max workers attribute, useful for CLI.
ATTR_SHORT = "maxworkers"

// InternalDefault is now 0. If the user doesn't specify the attribute,
// Get() will return 0, signaling the calling code to use CPU-based auto-detection.
InternalDefault uint = 0
)

func init() {
// This function runs automatically when the package is imported.
// It registers your attribute type with the OCM data context.
datacontext.RegisterAttributeType(ATTR_KEY, AttributeType{}, ATTR_SHORT)
}

// AttributeType implements the datacontext.AttributeType interface for max workers.
type AttributeType struct{}

// Name returns the full unique key of the attribute.
func (a AttributeType) Name() string {
return ATTR_KEY
}

// Description provides documentation for the attribute, visible in help messages.
func (a AttributeType) Description() string {
return `
*integer*
Specifies the maximum number of concurrent workers to use for resource and source
transfer operations. This can influence performance and resource consumption.
A value of 0 (or not specified) indicates auto-detection based on CPU cores.
`
}

// Encode converts the attribute's Go value (uint) to its marshaled byte representation (e.g., JSON).
func (a AttributeType) Encode(v interface{}, marshaller runtime.Marshaler) ([]byte, error) {
val, ok := v.(uint) // Expecting a uint for number of workers
if !ok {
// Attempt to convert from int if it's passed as int (common Go numeric type)
if intVal, ok := v.(int); ok {
if intVal < 0 {
return nil, fmt.Errorf("negative integer for maxworkers not allowed")
}
val = uint(intVal)
} else {
return nil, fmt.Errorf("unsigned integer (uint) or integer (int) required for maxworkers")
}
}
return marshaller.Marshal(val) // Marshal the uint value
}

// Decode converts the marshaled byte representation (e.g., JSON) to the attribute's Go value (uint).
func (a AttributeType) Decode(data []byte, unmarshaller runtime.Unmarshaler) (interface{}, error) {
var value uint // Decode into a uint
err := unmarshaller.Unmarshal(data, &value)
if err != nil {
var s string
if e := unmarshaller.Unmarshal(data, &s); e == nil {
parsedVal, err := strconv.ParseUint(s, 10, 32)
if err == nil {
return uint(parsedVal), nil
}
}
return nil, fmt.Errorf("failed to decode maxworkers as uint: %w", err)
}
return value, nil
}

////////////////////////////////////////////////////////////////////////////////

func Get(ctx datacontext.Context) uint {
a := ctx.GetAttributes().GetAttribute(ATTR_KEY)
if a == nil {
// If the attribute is NOT explicitly set by the user, return 0.
// This 0 will signal the calling code to use the CPU-based auto-detection.
return 50
}
if val, ok := a.(uint); ok {
return val // Return the user-specified value (can be 0 if user explicitly set it to 0).
}
// Fallback in case of type mismatch (should ideally not happen with correct Encode/Decode)
return 0 // Default to 0 for auto-detection in case of error
}

func Set(ctx datacontext.Context, workers uint) error {
return ctx.GetAttributes().SetAttribute(ATTR_KEY, workers)
}
Loading
Loading