db

package
v1.0.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2017 License: GPL-2.0 Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SuperAdminRoleName      = "SuperAdministrator"
	CommunityAdminRoleName  = "Administrator"
	CommunityMemberRoleName = "Member"
)

Functions

This section is empty.

Types

type Bind

type Bind struct {
	IOPort   IOPort
	VolumeID string
}

Bind describes the binding between an IOPort and a docker volume

type Community

type Community struct {
	ID          int64
	Name        string
	Description string
}

type CommunityTable

type CommunityTable struct {
	ID          int64
	Name        string
	Description string
	Revision    int
}

CommunityTable stores the communities in the db

type ContainerID

type ContainerID string

ContainerID exported

type Db

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

Db is used to keep DbMap

func InitDb

func InitDb() (Db, error)

InitDb initializes the database engine

func InitDbForTesting

func InitDbForTesting() (Db, string, error)

InitDbForTesting must only be used for tests

func (*Db) AddCmd

func (d *Db) AddCmd(service Service) error

AddCmd adds an array of cmd options to the specified service

func (*Db) AddCommunity

func (d *Db) AddCommunity(name, description string, addDefaultRoles bool) (Community, error)

AddCommunity adds a community to the database, with checks

func (*Db) AddIOPort

func (d *Db) AddIOPort(service Service) error

AddIOPort adds input and output ports to the database

func (*Db) AddJob

func (d *Db) AddJob(userID int64, job Job) error

AddJob adds a job to the database

func (*Db) AddJobTask

func (d *Db) AddJobTask(id JobID, taskName string, taskContainer string, taskSwarmService string,
	taskError string, taskExitCode int, taskConsoleOutput *bytes.Buffer) error

AddJobTask adds a task to a job

func (*Db) AddRole

func (d *Db) AddRole(name string, communityID int64, description string) (Role, error)

AddRole adds a role to the database, but only if it's not already present For roles that have no associated community use communityID: 0

func (*Db) AddRoleToUser

func (d *Db) AddRoleToUser(userID, roleID int64) error

AddRoleToUser

func (*Db) AddService

func (d *Db) AddService(userID int64, service Service) error

AddService creates a new service in the database

func (*Db) AddUser

func (d *Db) AddUser(user User) (User, error)

AddUser adds a user to the database

func (*Db) Close

func (d *Db) Close()

Close closes the db connections

func (*Db) CountRunningJobs

func (d *Db) CountRunningJobs() int64

CountRunningJobs returns a number of jobs currently running

func (*Db) CountUserRunningJobs

func (d *Db) CountUserRunningJobs(userID int64) int64

CountUserRunningJobs returns a number of running jobs owned by a specific user

func (*Db) DeleteRoleFromUser

func (d *Db) DeleteRoleFromUser(userID, roleID int64) error

DeleteRoleFromUser

func (*Db) DeleteUserToken

func (d *Db) DeleteUserToken(userID, tokenID int64) error

DeleteUserToken deletes the token from the database

func (*Db) GetCommunityByID

func (d *Db) GetCommunityByID(communityID int64) (Community, error)

GetCommunityByID gets a community from the database

func (*Db) GetCommunityByName

func (d *Db) GetCommunityByName(name string) (Community, error)

GetCommunityByName gets a community from the database

func (*Db) GetJob

func (d *Db) GetJob(id JobID) (Job, error)

GetJob returns a JSON ready representation of a job

func (*Db) GetJobOwningVolume

func (d *Db) GetJobOwningVolume(volumeID string) (Job, error)

GetJobOwningVolume returns a service ready to be converted into JSON

func (*Db) GetRoleByName

func (d *Db) GetRoleByName(name string, communityID int64) (Role, error)

GetRoleByName gets a named role from the database

func (*Db) GetRoleUsers

func (d *Db) GetRoleUsers(roleID int64) ([]User, error)

GetRoleByID gets a role from the database

func (*Db) GetService

func (d *Db) GetService(id ServiceID) (Service, error)

GetService returns a service ready to be converted into JSON

func (*Db) GetTokenByID

func (d *Db) GetTokenByID(tokenID int64) (Token, error)

GetTokenByID returns a token by its ID

func (*Db) GetTokenBySecret

func (d *Db) GetTokenBySecret(accessToken string) (Token, error)

GetTokenBySecret returns a token by its Secret

func (*Db) GetUserByEmail

func (d *Db) GetUserByEmail(email string) (*User, error)

GetUserByEmail searches for a user in the database

func (*Db) GetUserByID

func (d *Db) GetUserByID(id int64) (*User, error)

GetUserByID searches for a user in the database

func (*Db) GetUserRoles

func (d *Db) GetUserRoles(userID int64) ([]Role, error)

GetUserRoles

func (*Db) GetUserTokens

func (d *Db) GetUserTokens(userID int64) ([]Token, error)

GetUserTokens returns the user's tokens

func (*Db) HasSuperAdminRole

func (d *Db) HasSuperAdminRole(userID int64) bool

HasSuperAdminRole checks if a a user has super admin privileges

func (*Db) IsJobOwner

func (d *Db) IsJobOwner(userID int64, jobID JobID) bool

IsJobOwner checks if a certain user owns a certain job

func (*Db) IsServiceOwner

func (d *Db) IsServiceOwner(userID int64, serviceID ServiceID) bool

IsServiceOwner checks if a certain user owns a certain service

func (*Db) ListCommunities

func (d *Db) ListCommunities() ([]Community, error)

ListCommunities gets the list of all the communities

func (*Db) ListJobs

func (d *Db) ListJobs() ([]Job, error)

ListJobs returns a list of all jobs ready to be converted into JSON

func (*Db) ListRoles

func (d *Db) ListRoles() ([]Role, error)

ListRoles returns the list of all roles

func (*Db) ListServices

func (d *Db) ListServices() ([]Service, error)

ListServices produces a list of all services ready to be converted into JSON

func (*Db) NewUserToken

func (d *Db) NewUserToken(userID int64, name string, expire time.Time) (Token, error)

NewUserToken creates a new user access token

func (*Db) RemoveJob

func (d *Db) RemoveJob(userID int64, id JobID) error

RemoveJob removes a job and all corresponding tasks from the database

func (*Db) RemoveJobTask

func (d *Db) RemoveJobTask(taskID string) error

RemoveJobTask removes a task from the database

func (*Db) RemoveService

func (d *Db) RemoveService(userID int64, id ServiceID) error

RemoveService removes a service and the corresponding IOPorts from the database

func (*Db) SetJobDurationTime

func (d *Db) SetJobDurationTime(id JobID, duration int64) error

SetJobDurationTime sets job finish time

func (*Db) SetJobInputVolume

func (d *Db) SetJobInputVolume(id JobID, inputVolume VolumeID) error

SetJobInputVolume sets a job input volume

func (*Db) SetJobOutputVolume

func (d *Db) SetJobOutputVolume(id JobID, outputVolume VolumeID) error

SetJobOutputVolume sets a job output volume

func (*Db) SetJobState

func (d *Db) SetJobState(id JobID, state JobState) error

SetJobState sets a job state

func (*Db) UpdateUser

func (d *Db) UpdateUser(user User) error

UpdateUser updates user information in the database

type IOPort

type IOPort struct {
	ID   string
	Name string
	Path string
}

IOPort is an i/o specification for a service The service can only read data from volumes and write to a single volume Path specifies where the volumes are mounted

type IOPortTable

type IOPortTable struct {
	ID        string
	Name      string
	Path      string
	IsInput   bool
	ServiceID string
	Revision  int
}

IOPortTable is used to store info about service inputs and outputs in a database

type ImageID

type ImageID string

ImageID exported

type Job

type Job struct {
	ID           JobID
	ServiceID    ServiceID
	Input        string
	Created      time.Time
	Duration     int64
	State        *JobState
	InputVolume  VolumeID
	OutputVolume VolumeID
	Tasks        []Task
}

Job stores the information about a service execution (used to serialize JSON)

type JobID

type JobID string

JobID exported

type JobState

type JobState struct {
	Status string
	Error  string
	Code   int
}

JobState keeps information about a job state

func NewJobStateError

func NewJobStateError(err string, code int) JobState

NewJobStateError creates a new JobState with specified error

func NewJobStateOk

func NewJobStateOk(status string, code int) JobState

NewJobStateOk creates a new JobState with no error

type JobTable

type JobTable struct {
	ID           string
	ServiceID    string
	Input        string
	Created      time.Time
	Duration     int64 // duration time in seconds
	Error        string
	Status       string
	Code         int
	InputVolume  string
	OutputVolume string
	Revision     int
}

JobTable stores the information about a service execution (used to store data in a database)

type LatestOutput

type LatestOutput struct {
	Name          string
	ConsoleOutput string
}

LatestOutput used to serialize console output to JSON

type OwnerTable

type OwnerTable struct {
	UserID     int64
	ObjectType string
	ObjectID   string
	Revision   int
}

OwnerTable stores object ownerships

type Role

type Role struct {
	ID            int64
	Name          string
	Description   string
	CommunityID   int64
	CommunityName string
}

type RoleTable

type RoleTable struct {
	ID          int64
	Name        string
	CommunityID int64 // most roles are per community
	Description string
	Revision    int
}

RoleTable stores user roles in the db

type Service

type Service struct {
	ID          ServiceID
	ImageID     ImageID
	Name        string
	RepoTag     string
	Description string
	Version     string
	Cmd         []string
	Created     time.Time
	Deleted     bool
	Size        int64
	Input       []IOPort
	Output      []IOPort
}

Service describes metadata for a GEF service (used to serialize JSON)

type ServiceCmdTable

type ServiceCmdTable struct {
	ID        int
	Cmd       string
	Index     int
	ServiceID string
	Revision  int
}

ServiceCmdTable stores CMD options for services

type ServiceID

type ServiceID string

ServiceID exported

type ServiceTable

type ServiceTable struct {
	ID          string
	ImageID     string
	Name        string
	RepoTag     string
	Description string
	Version     string
	Created     time.Time
	Deleted     bool
	Size        int64
	Revision    int
}

ServiceTable describes metadata for a GEF service (used to store data in a database)

type Task

type Task struct {
	ID             string
	Name           string
	ContainerID    ContainerID
	SwarmServiceID string
	Error          string
	ExitCode       int
	ConsoleOutput  string
}

Task contains tasks related to a specific job (used to serialize JSON)

type TaskTable

type TaskTable struct {
	ID             string
	Name           string
	ContainerID    string
	SwarmServiceID string
	Error          string
	ExitCode       int
	ConsoleOutput  string
	JobID          string
	Revision       int
}

TaskTable contains tasks related to a specific job (used to store data in a database)

type Token

type Token struct {
	ID     int64
	Name   string
	Secret string
	UserID int64
	Expire time.Time
}

Token struct, also used to serialize JSON

type TokenTable

type TokenTable struct {
	ID       int64
	Name     string // token name, user defined
	Secret   string // token secret, a random string
	UserID   int64
	Expire   time.Time
	Revision int
}

TokenTable stores user tokens in the db

type User

type User struct {
	ID      int64
	Name    string
	Email   string
	Created time.Time
	Updated time.Time
}

User struct, also used to serialize JSON

type UserRoleTable

type UserRoleTable struct {
	UserID   int64
	RoleID   int64
	Revision int
}

UserRoleTable stores user mapping to roles in the db

type UserTable

type UserTable struct {
	ID       int64
	Name     string
	Email    string
	Created  time.Time
	Updated  time.Time
	Revision int
}

UserTable stores the users in the db

type VolumeID

type VolumeID string

VolumeID contains a docker volume ID

Jump to

Keyboard shortcuts

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