repository

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 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.

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 = `` /* 563-byte string literal not displayed */
View Source
const Version uint = 8

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 LoadJobStat added in v1.4.0

func LoadJobStat(job *schema.JobMeta, metric string, statType string) float64

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)

func SecurityCheckWithUser added in v1.4.0

func SecurityCheckWithUser(user *schema.User, query sq.SelectBuilder) (sq.SelectBuilder, error)

func TriggerJobStart added in v1.4.0

func TriggerJobStart(req JobWithUser)

Trigger async archiving

func WaitForJobStart added in v1.4.0

func WaitForJobStart()

Wait for background thread to finish pending archiving operations

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(user *schema.User, 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(user *schema.User, jobId int64, tagType string, tagName string, tagScope 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, tagScope 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) Execute added in v1.4.0

func (r *JobRepository) Execute(stmt sq.UpdateBuilder) error

func (*JobRepository) FetchEnergyFootprint added in v1.4.0

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

func (*JobRepository) FetchFootprint added in v1.4.0

func (r *JobRepository) FetchFootprint(job *schema.Job) (map[string]float64, 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(ctx context.Context, 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) FindByIdDirect added in v1.4.0

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

FindByIdDirect 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) FindByIdWithUser added in v1.4.0

func (r *JobRepository) FindByIdWithUser(user *schema.User, jobId int64) (*schema.Job, error)

FindByIdWithUser executes a SQL query to find a specific batch job. The job is queried using the database id. The user is passed directly, instead as part of the context. 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) FindByJobId added in v1.4.0

func (r *JobRepository) FindByJobId(ctx context.Context, jobId int64, startTime int64, cluster string) (*schema.Job, error)

FindByJobId executes a SQL query to find a specific batch job. The job is queried using the slurm id and the clustername. 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) FindRunningJobs added in v1.4.0

func (r *JobRepository) FindRunningJobs(cluster string) ([]*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(user *schema.User, job *int64) ([]*schema.Tag, error)

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

func (*JobRepository) ImportTag added in v1.4.0

func (r *JobRepository) ImportTag(jobId int64, tagType string, tagName string, tagScope string) (err error)

func (*JobRepository) InsertJob

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

func (*JobRepository) IsJobOwner added in v1.4.0

func (r *JobRepository) IsJobOwner(jobId int64, startTime int64, user string, cluster string) bool

IsJobOwner executes a SQL query to find a specific batch job. The job is queried using the slurm id,a username and the cluster. It returns a bool. If job was found, user is owner: test err != sql.ErrNoRows

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(
	stmt sq.UpdateBuilder,
	monitoringStatus int32,
) sq.UpdateBuilder

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(user *schema.User, 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, tagScope 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, query string, args ...interface{}) (int64, error)

func (*JobRepository) TransactionAddNamed added in v1.4.0

func (r *JobRepository) TransactionAddNamed(
	t *Transaction,
	query string,
	args ...interface{},
) (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) UpdateDuration added in v1.4.0

func (r *JobRepository) UpdateDuration() error

func (*JobRepository) UpdateEnergy added in v1.4.0

func (r *JobRepository) UpdateEnergy(
	stmt sq.UpdateBuilder,
	jobMeta *schema.JobMeta,
) (sq.UpdateBuilder, error)

func (*JobRepository) UpdateFootprint added in v1.4.0

func (r *JobRepository) UpdateFootprint(
	stmt sq.UpdateBuilder,
	jobMeta *schema.JobMeta,
) (sq.UpdateBuilder, error)

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)

type JobWithUser added in v1.4.0

type JobWithUser struct {
	Job  *schema.JobMeta
	User *schema.User
}

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

func (*UserRepository) UpdateUser added in v1.4.0

func (r *UserRepository) UpdateUser(dbUser *schema.User, user *schema.User) error

Jump to

Keyboard shortcuts

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