mongo

package
v0.0.0-...-870cc59 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DBInstance is db instance type name in the instances collection
	DBInstance = "database"

	// Mysql is db instance type name for mysql database in the instances collection
	Mysql = types.MySQL

	// MongoDB is db instance type name in the instances collection
	MongoDB = types.MongoDB

	// AppInstance is app instance type name in the instances collection
	AppInstance = "application"

	// InstanceCollection is the collection for all the instances
	InstanceCollection = "instances"

	// UserCollection is the collection for all users
	UserCollection = "users"

	// MetricsCollection is the collection to hold the metrics of the instances
	MetricsCollection = "metrics"

	// NameKey is the key holding the name of an instance
	NameKey = "name"

	// OwnerKey is the key holding the owner of an instance
	OwnerKey = "owner"

	// InstanceTypeKey is the key holding the instance type of an instance
	InstanceTypeKey = "instance_type"

	// LanguageKey is the key holding the language of an instance
	LanguageKey = "language"

	// HostIPKey is the key holding the host IP address of an instance
	HostIPKey = "host_ip"

	// ContainerPortKey is the key holding the port of the container in which an application is deployed
	ContainerPortKey = "container_port"

	// PortKey is the key holding the port of the container in which a database server is deployed
	PortKey = "port"

	// EmailKey is the key holding the email of a user
	EmailKey = "email"

	// UsernameKey is the key holding the username of a user
	UsernameKey = "username"

	// PasswordKey is the key holding the password of a user/instance
	PasswordKey = "password"

	// AdminKey is the key denoting whether a user has superuser privileges or not
	AdminKey = "admin"

	// TimestampKey is the key holding the timestamp of when a metrics collection was inserted
	TimestampKey = "timestamp"

	//GctlUUIDKey is the key holding a unique key for authentication of user by jwt
	GctlUUIDKey = "gctl_uuid"

	// DatetimeKey is the key holding the timestamp of when the instance was created
	DatetimeKey = "datetime"
)

Variables

View Source
var ErrNoDocuments = mongo.ErrNoDocuments

ErrNoDocuments is the error when no matching documents are found for an update operation

Functions

func BulkRegisterMetrics

func BulkRegisterMetrics(data []interface{}) ([]interface{}, error)

BulkRegisterMetrics is an abstraction over InsertMany which inserts multiple metrics documents into the mongoDB

func BulkUpsert

func BulkUpsert(collectionName string, data []m.WriteModel, options *options.BulkWriteOptions) (interface{}, error)

BulkUpsert upserts multiple documents using BulkWrite

func CountDocs

func CountDocs(collectionName string, filter types.M) (int64, error)

CountDocs returns the number of documents matching a filter

func CountInstanceInTimeFrame

func CountInstanceInTimeFrame(owner string, instance string, rate time.Duration) int

CountInstanceInTimeFrame returns the number of instances created by a user

func CountInstances

func CountInstances(filter types.M) (int64, error)

CountInstances returns the number of instances matching a filter

func CountInstancesByUser

func CountInstancesByUser(owner string, instance string) int

CountInstancesByUser returns the number of specified instances by the user

func CountServiceInstances

func CountServiceInstances(service, hostIP string) (int64, error)

CountServiceInstances returns the number of applications of a given service deployed in a host machine

func CountUsers

func CountUsers(filter types.M) (int64, error)

CountUsers returns the number of users matching a filter

func DeleteInstance

func DeleteInstance(filter types.M) (interface{}, error)

DeleteInstance is an abstraction over DeleteOne which deletes an application from mongoDB

func DeleteMetrics

func DeleteMetrics(filter types.M) (interface{}, error)

DeleteMetrics is an abstraction over DeleteOne which deletes a container metrics from mongoDB

func DeleteOne

func DeleteOne(collectionName string, filter types.M) (interface{}, error)

DeleteOne deletes a document from a mongoDB collection

func DeleteUser

func DeleteUser(filter types.M) (interface{}, error)

DeleteUser is an abstraction over DeleteOne which deletes a user from mongoDB

func FetchAppInfo

func FetchAppInfo(filter types.M) []types.M

FetchAppInfo is an abstraction over FetchDocs for retrieving application related documents

func FetchContainerMetrics

func FetchContainerMetrics(filter types.M, count int64) []types.M

FetchContainerMetrics is an abstraction over FetchDocs for retrieving metrics of a container

func FetchDBInfo

func FetchDBInfo(filter types.M) []types.M

FetchDBInfo is an abstraction over FetchDocs for retrieving database related documents

func FetchDatabaseLanguage

func FetchDatabaseLanguage(name string) (string, error)

FetchDatabaseLanguage returns the language of a database

func FetchDocs

func FetchDocs(collectionName string, filter types.M, opts ...*options.FindOptions) []types.M

FetchDocs is a generic function which takes a collection name and mongoDB filter as input and returns documents

func FetchInstanceField

func FetchInstanceField(name, instanceType, field string) (interface{}, error)

FetchInstanceField returns the value of a given field from an instance

func FetchInstances

func FetchInstances(filter types.M) []types.M

FetchInstances is an abstraction over FetchDocs for retrieving any instance documents

func FetchSingleApp

func FetchSingleApp(name string) (*types.ApplicationConfig, error)

FetchSingleApp returns an application based on a name based filter

func FetchSingleDatabase

func FetchSingleDatabase(name string) (*types.DatabaseConfig, error)

FetchSingleDatabase returns a database based on a name based filter

func FetchSingleUser

func FetchSingleUser(email string, opts ...*options.FindOneOptions) (*types.User, error)

FetchSingleUser returns a user based on a email based filter

func FetchSingleUserWithoutPassword

func FetchSingleUserWithoutPassword(email string) (*types.User, error)

FetchSingleUserWithoutPassword returns a user based on a email based filter without his/her password

func FetchUserInfo

func FetchUserInfo(filter types.M) []types.M

FetchUserInfo is an abstraction over FetchDocs for retrieving user details

func InsertMany

func InsertMany(collectionName string, data []interface{}) ([]interface{}, error)

InsertMany inserts multiple document into a mongoDB collection

func InsertOne

func InsertOne(collectionName string, data interface{}) (interface{}, error)

InsertOne inserts a document into a mongoDB collection

func RegisterInstance

func RegisterInstance(data interface{}) (interface{}, error)

RegisterInstance is an abstraction over InsertOne which inserts application info into mongoDB

func RegisterMetrics

func RegisterMetrics(data interface{}) (interface{}, error)

RegisterMetrics is an abstraction over InsertOne which inserts metrics into the mongoDB

func RegisterUser

func RegisterUser(data interface{}) (interface{}, error)

RegisterUser is an abstraction over InsertOne which inserts user into the mongoDB

func UpdateInstance

func UpdateInstance(filter types.M, data interface{}) error

UpdateInstance is an abstraction over UpdateOne which updates an application in mongoDB

func UpdateInstances

func UpdateInstances(filter types.M, data interface{}) (interface{}, error)

UpdateInstances is an abstraction over UpdateMany which updates multiple applications in mongoDB

func UpdateMany

func UpdateMany(collectionName string, filter types.M, data interface{}) (interface{}, error)

UpdateMany updates multiple documents in the mongoDB collection

func UpdateOne

func UpdateOne(collectionName string, filter types.M, data interface{}, option *options.FindOneAndUpdateOptions) error

UpdateOne updates a document in the mongoDB collection

func UpdateUser

func UpdateUser(filter types.M, data interface{}) error

UpdateUser is an abstraction over UpdateOne which updates an application in mongoDB

func UpsertInstance

func UpsertInstance(filter types.M, data interface{}) error

UpsertInstance is an abstraction over UpdateOne which updates an application in mongoDB or inserts it if the corresponding document doesn't exist

func UpsertMetrics

func UpsertMetrics(data []m.WriteModel) (interface{}, error)

UpsertMetrics is an abstraction over BulkUpsert which updates multiple metrics documents in mongoDB or inserts them if the corresponding document doesn't exist

func UpsertUser

func UpsertUser(filter types.M, data interface{}) error

UpsertUser is an abstraction over UpdateOne which updates an application in mongoDB or inserts it if the corresponding document doesn't exist

Types

This section is empty.

Jump to

Keyboard shortcuts

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