model

package
v0.0.0-...-33a8802 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound can be returend when we look for a specific single resource
	// by its ID but we get no result.
	ErrNotFound = e.New("requested resource not found")

	// ErrBadInput can be returned when a model function is given invalid parameters.
	ErrBadInput = e.New("the provided set of parameters is invalid")
)
View Source
var IDRegexp = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)

IDRegexp defines the pattern of all acceptable identifiers.

View Source
var IDRegexpNegative = regexp.MustCompile(`[^a-zA-Z0-9_-]+`)

IDRegexpNegative defines all unacceptable characters in an identifier.

Functions

This section is empty.

Types

type Context

type Context struct {
	Session *mgo.Session
	DBName  string
	User    types.User
}

Context contains information needed to access the data model and authorize the acessor.

func Connect

func Connect(dataSourceName string, databaseName string, anonimous bool) (context Context, err error)

Connect establishes a connection with the database and returns a model context instance.

func (Context) AddModelToApplicableJobs

func (context Context) AddModelToApplicableJobs(module types.Module) (err error)

AddModelToApplicableJobs searches for all datasets to which a model is applicable, looks for all jobs running on those datasets and adds the model to them if they have "accept-new-models" set to true.

func (Context) AsRoot

func (context Context) AsRoot() (rootContext Context)

AsRoot elevates the current model access context to root access privileges. Should be used only in special cases.

func (Context) Clear

func (context Context) Clear(databaseName string) (err error)

Clear drops the specified database if it exists.

func (Context) Clone

func (context Context) Clone() (clonedContext Context)

Clone makes a copy of the mongo session.

func (Context) CountJobs

func (context Context) CountJobs(filters F) (count int, err error)

CountJobs is the same as GetJobs but returns only the count, not the actual tasks.

func (Context) CountProcesses

func (context Context) CountProcesses(filters F) (count int, err error)

CountProcesses is the same as GetProcesses but returns only the count, not the actual processes.

func (Context) CountTasks

func (context Context) CountTasks(filters F) (count int, err error)

CountTasks is the same as GetTasks but returns only the count, not the actual tasks.

func (Context) CreateDataset

func (context Context) CreateDataset(dataset types.Dataset) (result types.Dataset, err error)

CreateDataset adds a given dataset to the database.

func (Context) CreateJob

func (context Context) CreateJob(job types.Job) (result types.Job, err error)

CreateJob adds a given job to the database.

func (Context) CreateModule

func (context Context) CreateModule(module types.Module) (result types.Module, err error)

CreateModule adds a given module to the database.

func (Context) CreateProcess

func (context Context) CreateProcess(proc types.Process) (result types.Process, err error)

CreateProcess adds a given process to the database.

func (Context) CreateTask

func (context Context) CreateTask(task types.Task) (result types.Task, err error)

CreateTask adds a given task to the database.

func (Context) CreateUser

func (context Context) CreateUser(user types.User) (result types.User, err error)

CreateUser adds the given user to the database.

func (Context) FlushDatasetAccessKey

func (context Context) FlushDatasetAccessKey(id string) (err error)

FlushDatasetAccessKey removes a used accessKey from the database.

func (Context) GetConfigCaches

func (context Context) GetConfigCaches(models []string) (result []types.ConfigCache, err error)

GetConfigCaches returns a list of config for a given set of models. If models is nil, then all models are considered.

func (Context) GetDatasetByID

func (context Context) GetDatasetByID(id string) (result types.Dataset, err error)

GetDatasetByID returns the dataset given its id. The id is given as "user-id/dataset-id".

func (Context) GetDatasets

func (context Context) GetDatasets(
	filters F,
	limit int,
	cursor string,
	sortBy string,
	order string,
) (result []types.Dataset, cm types.CollectionMetadata, err error)

GetDatasets lists all datasets given some filter criteria.

func (Context) GetJobByID

func (context Context) GetJobByID(id bson.ObjectId) (result types.Job, err error)

GetJobByID returns the job given its id. The id is given as "user-id/job-id".

func (Context) GetJobConfigSpace

func (context Context) GetJobConfigSpace(job types.Job) (configSpace string, err error)

GetJobConfigSpace takes a job and builds a complete config space given its models.

func (Context) GetJobConfigSpaceByID

func (context Context) GetJobConfigSpaceByID(id bson.ObjectId) (configSpace string, err error)

GetJobConfigSpaceByID searches for a job by ID and builds a complete config space given its models.

func (Context) GetJobs

func (context Context) GetJobs(
	filters F,
	limit int,
	cursor string,
	sortBy string,
	order string,
) (result []types.Job, cm types.CollectionMetadata, err error)

GetJobs lists all jobs given some filter criteria.

func (Context) GetModuleByID

func (context Context) GetModuleByID(id string) (result types.Module, err error)

GetModuleByID returns the module given its id. The id is given as "user-id/module-id".

func (Context) GetModules

func (context Context) GetModules(
	filters F,
	limit int,
	cursor string,
	sortBy string,
	order string,
) (result []types.Module, cm types.CollectionMetadata, err error)

GetModules lists all modules given some filter criteria.

func (Context) GetProcessByID

func (context Context) GetProcessByID(id bson.ObjectId) (result types.Process, err error)

GetProcessByID returns a process given its id.

func (Context) GetProcesses

func (context Context) GetProcesses(
	filters F,
	limit int,
	cursor string,
	sortBy string,
	order string,
) (result []types.Process, cm types.CollectionMetadata, err error)

GetProcesses lists all processes given some filter criteria.

func (Context) GetTaskByID

func (context Context) GetTaskByID(id string) (result types.Task, err error)

GetTaskByID returns the task given its id. The id is given as "user-id/task-id".

func (Context) GetTasks

func (context Context) GetTasks(
	filters F,
	limit int,
	cursor string,
	sortBy string,
	order string,
) (result []types.Task, cm types.CollectionMetadata, err error)

GetTasks lists all tasks given some filter criteria.

func (Context) GetUserByAPIKey

func (context Context) GetUserByAPIKey(apiKey string) (result types.User, err error)

GetUserByAPIKey looks up a user by its API key.

func (Context) GetUserByID

func (context Context) GetUserByID(id string) (result types.User, err error)

GetUserByID returns a user given its id.

func (Context) GetUsers

func (context Context) GetUsers(
	filters F,
	limit int,
	cursor string,
	sortBy string,
	order string,
) (result []types.User, cm types.CollectionMetadata, err error)

GetUsers lists all users given some filter criteria.

func (Context) Initialize

func (context Context) Initialize(databaseName string) (err error)

Initialize ensures that the target database is properly initalized.

func (Context) LockDataset

func (context Context) LockDataset(
	filters F,
	processID bson.ObjectId,
	sortBy string,
	order string,
) (result types.Dataset, err error)

LockDataset scans the available datasets (that are not currently locked), applies the specified filters, sorts them if specified and locks the first one by assigning it to the specified process.

func (Context) LockJob

func (context Context) LockJob(
	filters F,
	processID bson.ObjectId,
	sortBy string,
	order string,
) (result types.Job, err error)

LockJob scans the available jobs (that are not currently locked), applies the specified filters, sorts them if specified and locks the first one by assigning it to the specified process.

func (Context) LockModule

func (context Context) LockModule(
	filters F,
	processID bson.ObjectId,
	sortBy string,
	order string,
) (result types.Module, err error)

LockModule scans the available modules (that are not currently locked), applies the specified filters, sorts them if specified and locks the first one by assigning it to the specified process.

func (Context) LockTask

func (context Context) LockTask(
	filters F,
	processID bson.ObjectId,
	sortBy string,
	order string,
) (result types.Task, err error)

LockTask scans the available tasks (that are not currently locked), applies the specified filters, sorts them if specified and locks the first one by assigning it to the specified process.

func (Context) PauseRunningTasks

func (context Context) PauseRunningTasks(jobID bson.ObjectId) (err error)

PauseRunningTasks goes through all tasks of a job that are still running and marks them as pausing.

func (Context) ProcessKeepalive

func (context Context) ProcessKeepalive(id bson.ObjectId) (err error)

ProcessKeepalive updates the keepalive-time field of the process thus notifying the system that it is still running.

func (Context) ReleaseDatasetLockByProcess

func (context Context) ReleaseDatasetLockByProcess(processID bson.ObjectId) (numReleased int, err error)

ReleaseDatasetLockByProcess releases all datasets that have been locked by a given process and are not in the error state.

func (Context) ReleaseJobLockByProcess

func (context Context) ReleaseJobLockByProcess(processID bson.ObjectId) (numReleased int, err error)

ReleaseJobLockByProcess releases all jobs that have been locked by a given process and are not in the error state.

func (Context) ReleaseModuleLockByProcess

func (context Context) ReleaseModuleLockByProcess(processID bson.ObjectId) (numReleased int, err error)

ReleaseModuleLockByProcess releases all modules that have been locked by a given process and are not in the error state.

func (Context) ReleaseTaskLockByProcess

func (context Context) ReleaseTaskLockByProcess(processID bson.ObjectId) (numReleased int, err error)

ReleaseTaskLockByProcess releases all tasks that have been locked by a given process and are not in the error state.

func (Context) ResumePausedTasks

func (context Context) ResumePausedTasks(jobID bson.ObjectId) (err error)

ResumePausedTasks goes through all tasks of a job that are pausing or paused and marks them as scheduled.

func (Context) SetProcessStatus

func (context Context) SetProcessStatus(id bson.ObjectId, status string) (result types.Process, err error)

SetProcessStatus updates the processes state to terminated.

func (Context) StartProcess

func (context Context) StartProcess(processType string) (result types.Process, err error)

StartProcess starts a process of a given type and initializes all other fields automatically.

func (Context) TerminateDeadProcesses

func (context Context) TerminateDeadProcesses(cutoffTime time.Time) (err error)

TerminateDeadProcesses goes through all processes that have stopped making keepalive updates and sets their status to terminated.

func (Context) TerminateRunningTasks

func (context Context) TerminateRunningTasks(jobID bson.ObjectId) (err error)

TerminateRunningTasks goes through all tasks of a job that are still running and marks them as terminating.

func (Context) UnlockDataset

func (context Context) UnlockDataset(id string, processID bson.ObjectId) (err error)

UnlockDataset releases the lock on a given dataset.

func (Context) UnlockJob

func (context Context) UnlockJob(id bson.ObjectId, processID bson.ObjectId) (err error)

UnlockJob releases the lock on a given job.

func (Context) UnlockModule

func (context Context) UnlockModule(id string, processID bson.ObjectId) (err error)

UnlockModule releases the lock on a given module.

func (Context) UnlockTask

func (context Context) UnlockTask(id string, processID bson.ObjectId) (err error)

UnlockTask releases the lock on a given task.

func (Context) UpdateDataset

func (context Context) UpdateDataset(id string, updates map[string]interface{}) (result types.Dataset, err error)

UpdateDataset updates the information about a given dataset.

func (Context) UpdateDatasetStatus

func (context Context) UpdateDatasetStatus(id string, status string, statusMessage string) (err error)

UpdateDatasetStatus sets the status of the dataset and assigns the given status message.

func (Context) UpdateJob

func (context Context) UpdateJob(id bson.ObjectId, updates map[string]interface{}) (result types.Job, err error)

UpdateJob updates the information about a given job.

func (Context) UpdateModule

func (context Context) UpdateModule(id string, updates map[string]interface{}) (result types.Module, err error)

UpdateModule updates the information about a given module.

func (Context) UpdateModuleStatus

func (context Context) UpdateModuleStatus(id string, status string, statusMessage string) (err error)

UpdateModuleStatus sets the status of the module and assigns the given status message.

func (Context) UpdateProcess

func (context Context) UpdateProcess(id bson.ObjectId, updates map[string]interface{}) (result types.Process, err error)

UpdateProcess updates the information about a given process.

func (Context) UpdateTask

func (context Context) UpdateTask(id string, updates map[string]interface{}) (result types.Task, err error)

UpdateTask updates the information about a given task.

func (Context) UpdateTaskStage

func (context Context) UpdateTaskStage(id string, stage string) (err error)

UpdateTaskStage sets the stage of the task.

func (Context) UpdateTaskStatus

func (context Context) UpdateTaskStatus(id string, status string, statusMessage string) (err error)

UpdateTaskStatus sets the status of the task and assigns the given status message.

func (Context) UpdateUser

func (context Context) UpdateUser(id string, updates map[string]interface{}) (result types.User, err error)

UpdateUser updates the information about a given user.

func (Context) UserAuthenticate

func (context Context) UserAuthenticate(user types.User) (result types.User, err error)

UserAuthenticate checks the credentials of a given user against the users in the database. If the APIKey field contains a non-zero value, then an attempt to authenticate is made with that key. Otherwise, an attempt is made with the ID and PasswordHash fields.

func (Context) UserDeleteAPIKey

func (context Context) UserDeleteAPIKey() (err error)

UserDeleteAPIKey deletes the API key of the user.

func (Context) UserGenerateAPIKey

func (context Context) UserGenerateAPIKey() (result string, err error)

UserGenerateAPIKey creates a new API key for the user and stores it in the database. The operation only works if the API key in the context corresponds to the API key in the database. Otherwise, no change will be applied and the caller should try again.

func (Context) UserLogin

func (context Context) UserLogin() (result types.User, err error)

UserLogin logs in the user from the context. It is assumed that the user is already authenticated.

func (Context) UserLogout

func (context Context) UserLogout() (err error)

UserLogout logs the user out and invalidates their API key.

type F

type F map[string]interface{}

F represents a map of filters where keys are field names and values are equality constraints.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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