hpcmodel

package module
v0.0.0-...-9622cf3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 5 Imported by: 0

README

hpc-model-go

A key-value model for HPC resources in CEMC/CMA. Including models for:

  • Slurm

Installation

Use go get to install the latest version.

go get github.com/cemc-oper/hpc-model-go

Getting Started

The following example uses hpc-model-go to extract job id and job owner from a squeue -o %all query.

Create category list:

categoryList := slurm.QueryCategoryList{
    QueryCategoryList: hpcmodel.QueryCategoryList{
        CategoryList: []*hpcmodel.QueryCategory{
            {
                ID:                      "sinfo.partition",
                DisplayName:             "Partition",
                Label:                   "PARTITION",
                PropertyClass:           "StringProperty",
                PropertyCreateArguments: []string{},
                RecordParserClass:       "TokenRecordParser",
            },
            {
                ID:                      "sinfo.avail",
                DisplayName:             "Avail",
                Label:                   "AVAIL",
                PropertyClass:           "StringProperty",
                PropertyCreateArguments: []string{},
                RecordParserClass:       "TokenRecordParser",
            },
            {
                ID:                      "sinfo.nodes",
                DisplayName:             "Nodes(A/I/O/T)",
                Label:                   "NODES(A/I/O/T)",
                PropertyClass:           "StringProperty",
                PropertyCreateArguments: []string{},
                RecordParserClass:       "TokenRecordParser",
            },
            {
                ID:                      "sinfo.cpus",
                DisplayName:             "CPUs(A/I/O/T)",
                Label:                   "CPUS(A/I/O/T)",
                PropertyClass:           "StringProperty",
                PropertyCreateArguments: []string{},
                RecordParserClass:       "TokenRecordParser",
            },
        },
    },
}

Get squeue -o %all output.

cmd := exec.Command("sinfo", params...)
//fmt.Println(cmd.Args)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
    return nil, fmt.Errorf("command ran error: %v", err)
}
s := out.String()
lines := strings.Split(s, "\n")

Build model from category list.

model, err := slurm.BuildModel(lines, categoryList, " ")

model contains data of all categories.

Test

Use go test to run all tests.

License

Copyright © 2019-2023, developers at cemc-oper.

hpc-model-go is licensed under The MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DateTimeAfterValueChecker

type DateTimeAfterValueChecker struct {
	ExpectedValue time.Time
}

func (*DateTimeAfterValueChecker) CheckValue

func (c *DateTimeAfterValueChecker) CheckValue(t time.Time) bool

type DateTimeBeforeValueChecker

type DateTimeBeforeValueChecker struct {
	ExpectedValue time.Time
}

func (*DateTimeBeforeValueChecker) CheckValue

func (c *DateTimeBeforeValueChecker) CheckValue(t time.Time) bool

type DateTimeEqualValueChecker

type DateTimeEqualValueChecker struct {
	ExpectedValue time.Time
}

func (*DateTimeEqualValueChecker) CheckValue

func (c *DateTimeEqualValueChecker) CheckValue(t time.Time) bool

type DateTimeInValueChecker

type DateTimeInValueChecker struct {
	ExpectedValues []time.Time
}

func (*DateTimeInValueChecker) CheckValue

func (c *DateTimeInValueChecker) CheckValue(t time.Time) bool

type DateTimeProperty

type DateTimeProperty struct {
	Category   QueryCategory
	TimeFormat string
	Value      string
	Text       string
	Data       time.Time
}

func (*DateTimeProperty) PropertyID

func (p *DateTimeProperty) PropertyID() string

func (*DateTimeProperty) SetCategory

func (p *DateTimeProperty) SetCategory(category QueryCategory)

func (*DateTimeProperty) SetValue

func (p *DateTimeProperty) SetValue(value string)

type DateTimePropertyFilterCondition

type DateTimePropertyFilterCondition struct {
	ID      string
	Checker DateTimeValueChecker
}

func (*DateTimePropertyFilterCondition) IsFit

func (f *DateTimePropertyFilterCondition) IsFit(item *Item) bool

type DateTimeValueChecker

type DateTimeValueChecker interface {
	CheckValue(t time.Time) bool
}

type Filter

type Filter struct {
	Conditions []FilterCondition
}

func (*Filter) Filter

func (f *Filter) Filter(items []Item) []Item

type FilterCondition

type FilterCondition interface {
	IsFit(item *Item) bool
}

type Item

type Item struct {
	Props []Property
}

func BuildItem

func BuildItem(records []string, categoryList QueryCategoryList) (*Item, error)

func (*Item) AddProp

func (item *Item) AddProp(p Property)

func (*Item) GetProperty

func (item *Item) GetProperty(propertyID string) Property

type ItemSorter

type ItemSorter struct {
	// contains filtered or unexported fields
}

func CreateSorter

func CreateSorter(less ...LessFunc) *ItemSorter

func (*ItemSorter) Len

func (sorter *ItemSorter) Len() int

func (*ItemSorter) Less

func (sorter *ItemSorter) Less(i, j int) bool

func (*ItemSorter) Sort

func (sorter *ItemSorter) Sort(items []Item)

func (*ItemSorter) Swap

func (sorter *ItemSorter) Swap(i, j int)

type LessFunc

type LessFunc func(item1, item2 *Item) bool

func CreatePropertyLessFunc

func CreatePropertyLessFunc(id string) LessFunc

type Model

type Model struct {
	Items        []Item
	CategoryList QueryCategoryList
}

type NumberEqualValueChecker

type NumberEqualValueChecker struct {
	ExpectedValue float64
}

func (*NumberEqualValueChecker) CheckValue

func (c *NumberEqualValueChecker) CheckValue(s float64) bool

type NumberGreaterValueChecker

type NumberGreaterValueChecker struct {
	ExpectedValue float64
}

func (*NumberGreaterValueChecker) CheckValue

func (c *NumberGreaterValueChecker) CheckValue(s float64) bool

type NumberInValueChecker

type NumberInValueChecker struct {
	ExpectedValues []float64
}

func (*NumberInValueChecker) CheckValue

func (c *NumberInValueChecker) CheckValue(s float64) bool

type NumberLessValueChecker

type NumberLessValueChecker struct {
	ExpectedValue float64
}

func (*NumberLessValueChecker) CheckValue

func (c *NumberLessValueChecker) CheckValue(s float64) bool

type NumberProperty

type NumberProperty struct {
	Category QueryCategory
	Value    string
	Text     string
	Data     float64
}

func (*NumberProperty) PropertyID

func (p *NumberProperty) PropertyID() string

func (*NumberProperty) SetCategory

func (p *NumberProperty) SetCategory(category QueryCategory)

func (*NumberProperty) SetValue

func (p *NumberProperty) SetValue(value string)

type NumberPropertyFilterCondition

type NumberPropertyFilterCondition struct {
	ID      string
	Checker NumberValueChecker
}

func (*NumberPropertyFilterCondition) IsFit

func (f *NumberPropertyFilterCondition) IsFit(item *Item) bool

type NumberValueChecker

type NumberValueChecker interface {
	CheckValue(s float64) bool
}

type Property

type Property interface {
	SetValue(value string)
	SetCategory(category QueryCategory)
	PropertyID() string
}

func BuildProperty

func BuildProperty(records []string, category QueryCategory) (Property, error)

type QueryCategory

type QueryCategory struct {
	ID                      string
	DisplayName             string
	Label                   string
	ParseRecord             RecordParser
	RecordParserClass       string
	RecordParserArguments   []string
	PropertyClass           string
	PropertyCreateArguments []string
}

func (*QueryCategory) Equal

func (q1 *QueryCategory) Equal(q2 *QueryCategory) bool

type QueryCategoryList

type QueryCategoryList struct {
	CategoryList []*QueryCategory
}

func (*QueryCategoryList) CategoryFromId

func (ql *QueryCategoryList) CategoryFromId(id string) *QueryCategory

func (*QueryCategoryList) CategoryFromLabel

func (ql *QueryCategoryList) CategoryFromLabel(label string) *QueryCategory

func (*QueryCategoryList) ContainsID

func (ql *QueryCategoryList) ContainsID(id string) bool

func (*QueryCategoryList) ContainsLabel

func (ql *QueryCategoryList) ContainsLabel(label string) bool

func (*QueryCategoryList) IndexFromId

func (ql *QueryCategoryList) IndexFromId(id string) int

func (*QueryCategoryList) IndexFromLabel

func (ql *QueryCategoryList) IndexFromLabel(label string) int

type RecordParser

type RecordParser interface {
	SetArguments(arguments []string) error
	Parse(records []string) string
}

func BuildRecordParser

func BuildRecordParser(category *QueryCategory) (RecordParser, error)

type StringContainChecker

type StringContainChecker struct {
	ExpectedValue string
}

func (*StringContainChecker) CheckValue

func (c *StringContainChecker) CheckValue(s string) bool

type StringEqualValueChecker

type StringEqualValueChecker struct {
	ExpectedValue string
}

func (*StringEqualValueChecker) CheckValue

func (c *StringEqualValueChecker) CheckValue(s string) bool

type StringInValueChecker

type StringInValueChecker struct {
	ExpectedValues []string
}

func (*StringInValueChecker) CheckValue

func (c *StringInValueChecker) CheckValue(s string) bool

type StringProperty

type StringProperty struct {
	Category QueryCategory
	Value    string
	Text     string
	Data     string
}

func (*StringProperty) PropertyID

func (p *StringProperty) PropertyID() string

func (*StringProperty) SetCategory

func (p *StringProperty) SetCategory(category QueryCategory)

func (*StringProperty) SetValue

func (p *StringProperty) SetValue(value string)

type StringPropertyFilterCondition

type StringPropertyFilterCondition struct {
	ID      string
	Checker StringValueChecker
}

func (*StringPropertyFilterCondition) IsFit

func (f *StringPropertyFilterCondition) IsFit(item *Item) bool

type StringValueChecker

type StringValueChecker interface {
	CheckValue(s string) bool
}

type TimeStringProperty

type TimeStringProperty struct {
	Category   QueryCategory
	TimeFormat string
	Value      string
	Text       string
	Data       time.Duration
}

func (*TimeStringProperty) PropertyID

func (p *TimeStringProperty) PropertyID() string

func (*TimeStringProperty) SetCategory

func (p *TimeStringProperty) SetCategory(category QueryCategory)

func (*TimeStringProperty) SetValue

func (p *TimeStringProperty) SetValue(value string)

type TimestampProperty

type TimestampProperty struct {
	Category QueryCategory
	Value    string
	Text     string
	Data     time.Time
}

func (*TimestampProperty) PropertyID

func (p *TimestampProperty) PropertyID() string

func (*TimestampProperty) SetCategory

func (p *TimestampProperty) SetCategory(category QueryCategory)

func (*TimestampProperty) SetValue

func (p *TimestampProperty) SetValue(value string)

type TokenRecordParser

type TokenRecordParser struct {
	Index int
	Sep   string
}

func (*TokenRecordParser) Parse

func (p *TokenRecordParser) Parse(records []string) string

func (*TokenRecordParser) SetArguments

func (p *TokenRecordParser) SetArguments(arguments []string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL