db

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomID

func RandomID(length int) string

RandomID is a helper function designed to promote the unique creation of IDs for LiveLessons, LiveSesions, and other state resources that require such a unique identifier. No caller for this function should assume global uniqueness, but rather use this as a quick and easy way of generating something that is **probably** unique. Once generated, the caller should then check to ensure that ID is not already in use where it intends to use it, and in the unlikely event that it is, re-run this function until a unique value is determined. In this way, we can keep these IDs fairly small, which is necessary since we have to use them in forming names with constraints, like kubernetes objects.

Types

type ADMInMem

type ADMInMem struct {
	AntidoteVersion string
	// contains filtered or unexported fields
}

ADMInMem is an implementation of DataManager which uses in-memory constructs as a backing data store

func (*ADMInMem) CreateLiveLesson

func (a *ADMInMem) CreateLiveLesson(sc ot.SpanContext, ll *models.LiveLesson) error

CreateLiveLesson creates a new instance of a LiveLesson to the in-memory data store

func (*ADMInMem) CreateLiveSession

func (a *ADMInMem) CreateLiveSession(sc ot.SpanContext, ls *models.LiveSession) error

CreateLiveSession creates a new instance of a LiveSession to the in-memory data store

func (*ADMInMem) DeleteLiveLesson

func (a *ADMInMem) DeleteLiveLesson(sc ot.SpanContext, id string) error

DeleteLiveLesson deletes an existing LiveLesson from the in-memory data store by ID

func (*ADMInMem) DeleteLiveSession

func (a *ADMInMem) DeleteLiveSession(sc ot.SpanContext, id string) error

DeleteLiveSession deletes an existing LiveSession from the in-memory data store by ID

func (*ADMInMem) GetCollection

func (a *ADMInMem) GetCollection(sc ot.SpanContext, slug string) (models.Collection, error)

GetCollection retrieves a specific Collection from the data store

func (*ADMInMem) GetCurriculum

func (a *ADMInMem) GetCurriculum(sc ot.SpanContext) (models.Curriculum, error)

GetCurriculum retrieves a specific Curriculum from the data store

func (*ADMInMem) GetImage

func (a *ADMInMem) GetImage(sc ot.SpanContext, slug string) (models.Image, error)

GetImage retrieves a specific Image from the data store

func (*ADMInMem) GetLesson

func (a *ADMInMem) GetLesson(sc ot.SpanContext, slug string) (models.Lesson, error)

GetLesson retrieves a specific lesson from the data store

func (*ADMInMem) GetLiveLesson

func (a *ADMInMem) GetLiveLesson(sc ot.SpanContext, id string) (models.LiveLesson, error)

GetLiveLesson retrieves a specific LiveLesson from the in-memory store via ID

func (*ADMInMem) GetLiveSession

func (a *ADMInMem) GetLiveSession(sc ot.SpanContext, id string) (models.LiveSession, error)

GetLiveSession retrieves a specific LiveSession from the in-memory store via ID

func (*ADMInMem) Initialize

func (a *ADMInMem) Initialize(sc ot.SpanContext) error

Initialize resets an Antidote datastore to its defaults. This is done by dropping any existing data or schema, and re-installing it from the embedded types. A very destructive operation - use with caution.

This function is left blank for the in-memory driver, as it's not needed.

func (*ADMInMem) InsertCollections

func (a *ADMInMem) InsertCollections(sc ot.SpanContext, collections []*models.Collection) error

InsertCollections takes a slice of Images, and creates entries for each in the in-memory store.

NOTE that this and other insert operations silently overwrite any existing entities. This is okay for this driver, but we may want to revisit this later for other drivers especially. What's the appropriate behavior when we're trying to insert an item that already exists?

func (*ADMInMem) InsertImages

func (a *ADMInMem) InsertImages(sc ot.SpanContext, images []*models.Image) error

InsertImages takes a slice of Images, and creates entries for each in the in-memory store.

NOTE that this and other insert operations silently overwrite any existing entities. This is okay for this driver, but we may want to revisit this later for other drivers especially. What's the appropriate behavior when we're trying to insert an item that already exists?

func (*ADMInMem) InsertLessons

func (a *ADMInMem) InsertLessons(sc ot.SpanContext, lessons []*models.Lesson) error

InsertLessons takes a slice of Lessons, and creates entries for each in the in-memory store.

NOTE that this and other insert operations silently overwrite any existing entities. This is okay for this driver, but we may want to revisit this later for other drivers especially. What's the appropriate behavior when we're trying to insert an item that already exists?

func (*ADMInMem) ListCollections

func (a *ADMInMem) ListCollections(sc ot.SpanContext) (map[string]models.Collection, error)

ListCollections lists the Collections currently available in the data store

func (*ADMInMem) ListImages

func (a *ADMInMem) ListImages(sc ot.SpanContext) (map[string]models.Image, error)

ListImages lists the Images currently available in the data store

func (*ADMInMem) ListLessons

func (a *ADMInMem) ListLessons(sc ot.SpanContext) (map[string]models.Lesson, error)

ListLessons lists the Lessons currently available in the data store

func (*ADMInMem) ListLiveLessons

func (a *ADMInMem) ListLiveLessons(sc ot.SpanContext) (map[string]models.LiveLesson, error)

ListLiveLessons lists all LiveLessons currently tracked in memory

func (*ADMInMem) ListLiveSessions

func (a *ADMInMem) ListLiveSessions(sc ot.SpanContext) (map[string]models.LiveSession, error)

ListLiveSessions lists all LiveSessions currently tracked in memory

func (*ADMInMem) Preflight

func (a *ADMInMem) Preflight(sc ot.SpanContext) error

Preflight performs any necessary tasks to ensure the database is ready to be used. This includes things like version compatibilty checks, schema checks, the presence of the expected data, etc. Most useful for when Antidote processes start up.

This function is left blank for the in-memory driver, as it's not needed.

func (*ADMInMem) SetCurriculum

func (a *ADMInMem) SetCurriculum(sc ot.SpanContext, curriculum *models.Curriculum) error

SetCurriculum updates the curriculum details in the datastore

func (*ADMInMem) UpdateLiveLessonEndpointIP

func (a *ADMInMem) UpdateLiveLessonEndpointIP(sc ot.SpanContext, llID, epName, IP string) error

UpdateLiveLessonEndpointIP updates a livelesson's Host property

func (*ADMInMem) UpdateLiveLessonError

func (a *ADMInMem) UpdateLiveLessonError(sc ot.SpanContext, llID string, llErr bool) error

UpdateLiveLessonError updates a livelesson's Error property

func (*ADMInMem) UpdateLiveLessonGuide

func (a *ADMInMem) UpdateLiveLessonGuide(sc ot.SpanContext, llID, guideType, guideContents string) error

UpdateLiveLessonGuide updates a LiveLesson's guide properties

func (*ADMInMem) UpdateLiveLessonStage

func (a *ADMInMem) UpdateLiveLessonStage(sc ot.SpanContext, llID string, stage int32) error

UpdateLiveLessonStage updates a livelesson's LessonStage property

func (*ADMInMem) UpdateLiveLessonStatus

func (a *ADMInMem) UpdateLiveLessonStatus(sc ot.SpanContext, llID string, status models.LiveLessonStatus) error

UpdateLiveLessonStatus updates a livelesson's Status property

func (*ADMInMem) UpdateLiveLessonTests

func (a *ADMInMem) UpdateLiveLessonTests(sc ot.SpanContext, llID string, healthy, total int32) error

UpdateLiveLessonTests updates the HealthyTests and TotalTests properties

func (*ADMInMem) UpdateLiveSessionPersistence

func (a *ADMInMem) UpdateLiveSessionPersistence(sc ot.SpanContext, lsID string, persistent bool) error

UpdateLiveSessionPersistence updates a livesession's persistent property

type DataManager

type DataManager interface {

	// Housekeeping functions
	Preflight(ot.SpanContext) error
	Initialize(ot.SpanContext) error

	// Images
	InsertImages(ot.SpanContext, []*models.Image) error
	ListImages(ot.SpanContext) (map[string]models.Image, error)
	GetImage(ot.SpanContext, string) (models.Image, error)

	// Lessons
	InsertLessons(ot.SpanContext, []*models.Lesson) error
	ListLessons(ot.SpanContext) (map[string]models.Lesson, error)
	GetLesson(ot.SpanContext, string) (models.Lesson, error)

	// Collections
	InsertCollections(ot.SpanContext, []*models.Collection) error
	ListCollections(ot.SpanContext) (map[string]models.Collection, error)
	GetCollection(ot.SpanContext, string) (models.Collection, error)

	// Curriculum
	SetCurriculum(ot.SpanContext, *models.Curriculum) error
	GetCurriculum(ot.SpanContext) (models.Curriculum, error)

	// LiveLessons
	CreateLiveLesson(ot.SpanContext, *models.LiveLesson) error
	ListLiveLessons(ot.SpanContext) (map[string]models.LiveLesson, error)
	GetLiveLesson(ot.SpanContext, string) (models.LiveLesson, error)
	/*
		I started with a basic UpdateLiveLesson function, and then in the code, I'd first call GetLiveLesson,
		make some modifications, and then run UpdateLiveLesson. The problem is, if there are any changes to the
		livelesson between these two points in time, I'd overwrite those changes inadvertently.

		So, I decided to try with these specific update functions that are designed to update a specific field.
		This way you don't have to worry about the specific state, and you update only the field you intend.
		I thought about maybe changing the update function to take in a field name by string but that felt
		sinful in the face of strong typing, so I instead opted for the safe option and just created unique functions
		for each field that fits a use case.

		The first param is the livelesson ID, and the second is the appropriate value
	*/
	UpdateLiveLessonStage(ot.SpanContext, string, int32) error
	UpdateLiveLessonGuide(ot.SpanContext, string, string, string) error
	UpdateLiveLessonStatus(ot.SpanContext, string, models.LiveLessonStatus) error
	UpdateLiveLessonError(ot.SpanContext, string, bool) error
	UpdateLiveLessonEndpointIP(ot.SpanContext, string, string, string) error //ID, epName, IP
	UpdateLiveLessonTests(ot.SpanContext, string, int32, int32) error        //ID, healthyTests, totalTests
	DeleteLiveLesson(ot.SpanContext, string) error

	// LiveSessions
	CreateLiveSession(ot.SpanContext, *models.LiveSession) error
	ListLiveSessions(ot.SpanContext) (map[string]models.LiveSession, error)
	GetLiveSession(ot.SpanContext, string) (models.LiveSession, error)
	UpdateLiveSessionPersistence(ot.SpanContext, string, bool) error
	DeleteLiveSession(ot.SpanContext, string) error
}

DataManager enforces the set of functions required by the rest of the Antidote codebase for handling internal data, such as live state or loaded curriculum resource definitions.

In general, resource types like collections or lessons only need three operations: Insert, List, Get They generally don't need to be deleted - the better option is to delete them from the source filesystem or repo, and then run a re-import, which first deletes everything and re-inserts them.

State types like LiveLesson or LiveSession are different, and need full CRUD functionality.

func NewADMInMem

func NewADMInMem() DataManager

NewADMInMem produces an initialized instance of ADMInMem ready to be used

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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