repository

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Copyright (C) NHR@FAU, University Erlangen-Nuremberg. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Index

Constants

View Source
const NamedJobInsert string = `INSERT INTO job (
	job_id, user, project, cluster, subcluster, ` + "`partition`" + `, array_job_id, num_nodes, num_hwthreads, num_acc,
	exclusive, monitoring_status, smt, job_state, start_time, duration, walltime, resources, meta_data,
	mem_used_max, flops_any_avg, mem_bw_avg, load_avg, net_bw_avg, net_data_vol_total, file_bw_avg, file_data_vol_total
) VALUES (
	:job_id, :user, :project, :cluster, :subcluster, :partition, :array_job_id, :num_nodes, :num_hwthreads, :num_acc,
	:exclusive, :monitoring_status, :smt, :job_state, :start_time, :duration, :walltime, :resources, :meta_data,
	:mem_used_max, :flops_any_avg, :mem_bw_avg, :load_avg, :net_bw_avg, :net_data_vol_total, :file_bw_avg, :file_data_vol_total
);`
View Source
const Version uint = 7

Variables

View Source
var (
	ErrNotFound  = errors.New("no such jobname, project or user")
	ErrForbidden = errors.New("not authorized")
)

Functions

func BuildWhereClause

func BuildWhereClause(filter *model.JobFilter, query sq.SelectBuilder) sq.SelectBuilder

Build a sq.SelectBuilder out of a schema.JobFilter.

func Connect

func Connect(driver string, db string)

func ForceDB added in v1.3.0

func ForceDB(backend string, db string) error

func GetUserFromContext added in v1.2.0

func GetUserFromContext(ctx context.Context) *schema.User

func MigrateDB

func MigrateDB(backend string, db string) error

func RevertDB added in v1.3.0

func RevertDB(backend string, db string) error

func SecurityCheck

func SecurityCheck(ctx context.Context, query sq.SelectBuilder) (sq.SelectBuilder, error)

Types

type ContextKey added in v1.2.0

type ContextKey string
const ContextUserKey ContextKey = "user"

type DBConnection

type DBConnection struct {
	DB     *sqlx.DB
	Driver string
}

func GetConnection

func GetConnection() *DBConnection

type DatabaseOptions

type DatabaseOptions struct {
	URL                   string
	MaxOpenConnections    int
	MaxIdleConnections    int
	ConnectionMaxLifetime time.Duration
	ConnectionMaxIdleTime time.Duration
}

type Hooks

type Hooks struct{}

Hooks satisfies the sqlhook.Hooks interface

func (*Hooks) After

func (h *Hooks) After(ctx context.Context, query string, args ...interface{}) (context.Context, error)

After hook will get the timestamp registered on the Before hook and print the elapsed time

func (*Hooks) Before

func (h *Hooks) Before(ctx context.Context, query string, args ...interface{}) (context.Context, error)

Before hook will print the query with it's args and return the context with the timestamp

type JobRepository

type JobRepository struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}

func GetJobRepository

func GetJobRepository() *JobRepository

func (*JobRepository) AddHistograms

func (r *JobRepository) AddHistograms(
	ctx context.Context,
	filter []*model.JobFilter,
	stat *model.JobsStatistics) (*model.JobsStatistics, error)

func (*JobRepository) AddJobCount

func (r *JobRepository) AddJobCount(
	ctx context.Context,
	filter []*model.JobFilter,
	stats []*model.JobsStatistics,
	kind string) ([]*model.JobsStatistics, error)

func (*JobRepository) AddJobCountGrouped

func (r *JobRepository) AddJobCountGrouped(
	ctx context.Context,
	filter []*model.JobFilter,
	groupBy *model.Aggregate,
	stats []*model.JobsStatistics,
	kind string) ([]*model.JobsStatistics, error)

func (*JobRepository) AddMetricHistograms added in v1.3.0

func (r *JobRepository) AddMetricHistograms(
	ctx context.Context,
	filter []*model.JobFilter,
	metrics []string,
	stat *model.JobsStatistics) (*model.JobsStatistics, error)

Requires thresholds for metric from config for cluster? Of all clusters and use largest? split to 10 + 1 for artifacts?

func (*JobRepository) AddTag

func (r *JobRepository) AddTag(job int64, tag int64) ([]*schema.Tag, error)

Add the tag with id `tagId` to the job with the database id `jobId`.

func (*JobRepository) AddTagOrCreate

func (r *JobRepository) AddTagOrCreate(jobId int64, tagType string, tagName string) (tagId int64, err error)

AddTagOrCreate adds the tag with the specified type and name to the job with the database id `jobId`. If such a tag does not yet exist, it is created.

func (*JobRepository) AllocatedNodes

func (r *JobRepository) AllocatedNodes(cluster string) (map[string]map[string]int, error)

AllocatedNodes returns a map of all subclusters to a map of hostnames to the amount of jobs running on that host. Hosts with zero jobs running on them will not show up!

func (*JobRepository) CountJobs

func (r *JobRepository) CountJobs(
	ctx context.Context,
	filters []*model.JobFilter) (int, error)

func (*JobRepository) CountTags

func (r *JobRepository) CountTags(user *schema.User) (tags []schema.Tag, counts map[string]int, err error)

func (*JobRepository) CreateTag

func (r *JobRepository) CreateTag(tagType string, tagName string) (tagId int64, err error)

CreateTag creates a new tag with the specified type and name and returns its database id.

func (*JobRepository) DeleteJobById

func (r *JobRepository) DeleteJobById(id int64) error

func (*JobRepository) DeleteJobsBefore

func (r *JobRepository) DeleteJobsBefore(startTime int64) (int, error)

func (*JobRepository) FetchMetadata

func (r *JobRepository) FetchMetadata(job *schema.Job) (map[string]string, error)

func (*JobRepository) Find

func (r *JobRepository) Find(
	jobId *int64,
	cluster *string,
	startTime *int64,
) (*schema.Job, error)

Find executes a SQL query to find a specific batch job. The job is queried using the batch job id, the cluster name, and the start time of the job in UNIX epoch time seconds. It returns a pointer to a schema.Job data structure and an error variable. To check if no job was found test err == sql.ErrNoRows

func (*JobRepository) FindAll

func (r *JobRepository) FindAll(
	jobId *int64,
	cluster *string,
	startTime *int64,
) ([]*schema.Job, error)

Find executes a SQL query to find a specific batch job. The job is queried using the batch job id, the cluster name, and the start time of the job in UNIX epoch time seconds. It returns a pointer to a schema.Job data structure and an error variable. To check if no job was found test err == sql.ErrNoRows

func (*JobRepository) FindById

func (r *JobRepository) FindById(jobId int64) (*schema.Job, error)

FindById executes a SQL query to find a specific batch job. The job is queried using the database id. It returns a pointer to a schema.Job data structure and an error variable. To check if no job was found test err == sql.ErrNoRows

func (*JobRepository) FindColumnValue

func (r *JobRepository) FindColumnValue(user *schema.User, searchterm string, table string, selectColumn string, whereColumn string, isLike bool) (result string, err error)

func (*JobRepository) FindColumnValues

func (r *JobRepository) FindColumnValues(user *schema.User, query string, table string, selectColumn string, whereColumn string) (results []string, err error)

func (*JobRepository) FindConcurrentJobs

func (r *JobRepository) FindConcurrentJobs(
	ctx context.Context,
	job *schema.Job,
) (*model.JobLinkResultList, error)

func (*JobRepository) FindJobsBetween

func (r *JobRepository) FindJobsBetween(startTimeBegin int64, startTimeEnd int64) ([]*schema.Job, error)

func (*JobRepository) FindUserOrProjectOrJobname

func (r *JobRepository) FindUserOrProjectOrJobname(user *schema.User, searchterm string) (jobid string, username string, project string, jobname string)

func (*JobRepository) Flush

func (r *JobRepository) Flush() error

func (*JobRepository) GetTags

func (r *JobRepository) GetTags(job *int64) ([]*schema.Tag, error)

GetTags returns a list of all tags if job is nil or of the tags that the job with that database ID has.

func (*JobRepository) InsertJob

func (r *JobRepository) InsertJob(job *schema.Job) (int64, error)

func (*JobRepository) JobCountGrouped

func (r *JobRepository) JobCountGrouped(
	ctx context.Context,
	filter []*model.JobFilter,
	groupBy *model.Aggregate) ([]*model.JobsStatistics, error)

func (*JobRepository) JobsStats

func (r *JobRepository) JobsStats(
	ctx context.Context,
	filter []*model.JobFilter) ([]*model.JobsStatistics, error)

func (*JobRepository) JobsStatsGrouped

func (r *JobRepository) JobsStatsGrouped(
	ctx context.Context,
	filter []*model.JobFilter,
	page *model.PageRequest,
	sortBy *model.SortByAggregate,
	groupBy *model.Aggregate) ([]*model.JobsStatistics, error)

func (*JobRepository) MarkArchived

func (r *JobRepository) MarkArchived(
	jobId int64,
	monitoringStatus int32,
	metricStats map[string]schema.JobStatistics,
) error

Stop updates the job with the database id jobId using the provided arguments.

func (*JobRepository) Optimize

func (r *JobRepository) Optimize() error

func (*JobRepository) Partitions

func (r *JobRepository) Partitions(cluster string) ([]string, error)

func (*JobRepository) QueryJobs

func (r *JobRepository) QueryJobs(
	ctx context.Context,
	filters []*model.JobFilter,
	page *model.PageRequest,
	order *model.OrderByInput) ([]*schema.Job, error)

func (*JobRepository) RemoveTag

func (r *JobRepository) RemoveTag(job, tag int64) ([]*schema.Tag, error)

Removes a tag from a job

func (*JobRepository) Start

func (r *JobRepository) Start(job *schema.JobMeta) (id int64, err error)

Start inserts a new job in the table, returning the unique job ID. Statistics are not transfered!

func (*JobRepository) Stop

func (r *JobRepository) Stop(
	jobId int64,
	duration int32,
	state schema.JobState,
	monitoringStatus int32,
) (err error)

Stop updates the job with the database id jobId using the provided arguments.

func (*JobRepository) StopJobsExceedingWalltimeBy

func (r *JobRepository) StopJobsExceedingWalltimeBy(seconds int) error

func (*JobRepository) TagId

func (r *JobRepository) TagId(tagType string, tagName string) (tagId int64, exists bool)

TagId returns the database id of the tag with the specified type and name.

func (*JobRepository) TransactionAdd

func (r *JobRepository) TransactionAdd(t *Transaction, job schema.Job) (int64, error)

func (*JobRepository) TransactionAddTag

func (r *JobRepository) TransactionAddTag(t *Transaction, tag *schema.Tag) (int64, error)

func (*JobRepository) TransactionCommit

func (r *JobRepository) TransactionCommit(t *Transaction) error

func (*JobRepository) TransactionEnd

func (r *JobRepository) TransactionEnd(t *Transaction) error

func (*JobRepository) TransactionInit

func (r *JobRepository) TransactionInit() (*Transaction, error)

func (*JobRepository) TransactionSetTag

func (r *JobRepository) TransactionSetTag(t *Transaction, jobId int64, tagId int64) error

func (*JobRepository) TriggerArchiving

func (r *JobRepository) TriggerArchiving(job *schema.Job)

Trigger async archiving

func (*JobRepository) UpdateMetadata

func (r *JobRepository) UpdateMetadata(job *schema.Job, key, val string) (err error)

func (*JobRepository) UpdateMonitoringStatus

func (r *JobRepository) UpdateMonitoringStatus(job int64, monitoringStatus int32) (err error)

func (*JobRepository) WaitForArchiving

func (r *JobRepository) WaitForArchiving()

Wait for background thread to finish pending archiving operations

type Transaction

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

type UserCfgRepo

type UserCfgRepo struct {
	DB     *sqlx.DB
	Lookup *sqlx.Stmt
	// contains filtered or unexported fields
}

func GetUserCfgRepo

func GetUserCfgRepo() *UserCfgRepo

func (*UserCfgRepo) GetUIConfig

func (uCfg *UserCfgRepo) GetUIConfig(user *schema.User) (map[string]interface{}, error)

Return the personalised UI config for the currently authenticated user or return the plain default config.

func (*UserCfgRepo) UpdateConfig

func (uCfg *UserCfgRepo) UpdateConfig(
	key, value string,
	user *schema.User) error

If the context does not have a user, update the global ui configuration without persisting it! If there is a (authenticated) user, update only his configuration.

type UserRepository added in v1.2.0

type UserRepository struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}

func GetUserRepository added in v1.2.0

func GetUserRepository() *UserRepository

func (*UserRepository) AddProject added in v1.2.0

func (r *UserRepository) AddProject(
	ctx context.Context,
	username string,
	project string) error

func (*UserRepository) AddRole added in v1.2.0

func (r *UserRepository) AddRole(
	ctx context.Context,
	username string,
	queryrole string) error

func (*UserRepository) AddUser added in v1.2.0

func (r *UserRepository) AddUser(user *schema.User) error

func (*UserRepository) DelUser added in v1.2.0

func (r *UserRepository) DelUser(username string) error

func (*UserRepository) FetchUserInCtx added in v1.2.0

func (r *UserRepository) FetchUserInCtx(ctx context.Context, username string) (*model.User, error)

func (*UserRepository) GetLdapUsernames added in v1.2.0

func (r *UserRepository) GetLdapUsernames() ([]string, error)

func (*UserRepository) GetUser added in v1.2.0

func (r *UserRepository) GetUser(username string) (*schema.User, error)

func (*UserRepository) ListUsers added in v1.2.0

func (r *UserRepository) ListUsers(specialsOnly bool) ([]*schema.User, error)

func (*UserRepository) RemoveProject added in v1.2.0

func (r *UserRepository) RemoveProject(ctx context.Context, username string, project string) error

func (*UserRepository) RemoveRole added in v1.2.0

func (r *UserRepository) RemoveRole(ctx context.Context, username string, queryrole string) error

Jump to

Keyboard shortcuts

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