database

package
v0.0.0-...-7bbfb33 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FastHTTPClient

func FastHTTPClient(cfg *config.Job) *http.Client

func HTTPClient

func HTTPClient(cfg *config.Job) *http.Client

Types

type AgentStatus

type AgentStatus struct {
	Id   primitive.ObjectID `bson:"_id"`
	Name string             `bson:"name"`
	Host string             `bson:"host"`
	// add state
	CreatedAt primitive.DateTime `bson:"created_at"`
	Heartbeat primitive.DateTime `bson:"heartbeat"`
}

type Client

type Client interface {
	InsertOne(interface{}) (bool, error)
	InsertMany([]interface{}) (bool, error)
	ReadOne(interface{}) (bool, error)
	ReadMany(interface{}) (bool, error)
	UpdateOne(interface{}, interface{}) (bool, error)
	DropCollection() error
	Disconnect() error
}

type Command

type Command struct {
	Id        primitive.ObjectID `bson:"_id"`
	Data      config.Job         `bson:"data"`
	Type      string             `bson:"type"`
	State     string             `bson:"state"`
	CreatedAt primitive.DateTime `bson:"created_at"`
	Version   primitive.ObjectID `bson:"version"`
}

type CommandState

type CommandState int
const (
	CommandStateCreated CommandState = iota // created
	CommandStateRunning                     // running
	CommandStateDone                        // done
	CommandStateError                       // error
)

func (CommandState) String

func (i CommandState) String() string

type CommandType

type CommandType int
const (
	CommandTypeStartWorkload CommandType = iota // start
	CommandTypeStopWorkload                     // stop
)

func (CommandType) String

func (i CommandType) String() string

type MongoClient

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

func NewInternalMongoClient

func NewInternalMongoClient(connectionString string) (*MongoClient, error)

func NewMongoClient

func NewMongoClient(connectionString string, cfg *config.Job, schema *config.Schema) (*MongoClient, error)

func (*MongoClient) AddAgentStatus

func (c *MongoClient) AddAgentStatus(stat AgentStatus) error

func (*MongoClient) AddWorkloads

func (c *MongoClient) AddWorkloads(workloads []interface{}) error

func (*MongoClient) CancelCommand

func (c *MongoClient) CancelCommand() error

func (*MongoClient) ClusterTime

func (c *MongoClient) ClusterTime() (*primitive.DateTime, error)

func (*MongoClient) Disconnect

func (c *MongoClient) Disconnect() (err error)

func (*MongoClient) DropCollection

func (c *MongoClient) DropCollection() error

func (*MongoClient) GetAgentWithHeartbeatWithin

func (c *MongoClient) GetAgentWithHeartbeatWithin() (uint64, error)

agent

func (*MongoClient) GetCommandWorkloads

func (c *MongoClient) GetCommandWorkloads(command *Command) ([]*Workload, error)

func (*MongoClient) GetNewWorkloads

func (c *MongoClient) GetNewWorkloads() (*Workload, error)

todo: temp change to stream for commands

func (*MongoClient) GetNextUnFinishedCommand

func (c *MongoClient) GetNextUnFinishedCommand() (*Command, error)

func (*MongoClient) InsertMany

func (c *MongoClient) InsertMany(data []interface{}) (bool, error)

func (*MongoClient) InsertOne

func (c *MongoClient) InsertOne(data interface{}) (bool, error)

func (*MongoClient) IsMasterAgent

func (c *MongoClient) IsMasterAgent(agentId primitive.ObjectID) (bool, error)

func (*MongoClient) ReadMany

func (c *MongoClient) ReadMany(filter interface{}) (bool, error)

func (*MongoClient) ReadOne

func (c *MongoClient) ReadOne(filter interface{}) (bool, error)

func (*MongoClient) RemoveAgentStatus

func (c *MongoClient) RemoveAgentStatus(stat AgentStatus) error

func (*MongoClient) RunJob

func (c *MongoClient) RunJob(job config.Job) error

workload

func (*MongoClient) SaveAgentStatus

func (c *MongoClient) SaveAgentStatus(stat AgentStatus) error

func (*MongoClient) SaveCommand

func (c *MongoClient) SaveCommand(command *Command) error

func (*MongoClient) SaveWorkload

func (c *MongoClient) SaveWorkload(workload *Workload) error

func (*MongoClient) UpdateOne

func (c *MongoClient) UpdateOne(filter interface{}, data interface{}) (bool, error)

type NodeInfo

type NodeInfo struct {
	OK        int                 `bson:"ok"`
	LocalTime *primitive.DateTime `bson:"localTime"`
}

mongo models

type Workload

type Workload struct {
	Id        primitive.ObjectID `bson:"_id"`
	CommandId primitive.ObjectID `bson:"command_id"`
	AgentId   primitive.ObjectID `bson:"agent_id"`
	Data      config.Job         `bson:"data"`
	State     string             `bson:"state"`
	CreatedAt primitive.DateTime `bson:"created_at"`
	Version   primitive.ObjectID `bson:"version"`
}

type WorkloadState

type WorkloadState int

todo: move to different place

const (
	WorkloadStateCreated WorkloadState = iota
	WorkloadStateToRun
	WorkloadStateRunning
	WorkloadStateDone
	WorkloadStateError
	WorkloadStateToDelete
	WorkloadStateDeleted
)

func (WorkloadState) String

func (i WorkloadState) String() string

Jump to

Keyboard shortcuts

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