synch

package
v0.0.0-...-61a28a1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package synch handles all data sychronization.

Index

Constants

View Source
const (
	SIMULATION_DIR = "./simulation/"
	LOGS_DIR       = "./log/"
)
View Source
const (
	ONE_OFF synchType = iota + 1
	ONGOING
)

Variables

This section is empty.

Functions

func FindSynchType

func FindSynchType(sType string) (synchType, error)

FindSynchType returns a synch type based on a string.

Types

type Link struct {
	Cmd string
	// contains filtered or unexported fields
}

Link represents a single link in the config file like: [example_node1.example_column1 WHERE ...] TO [example_node2.example_column2 WHERE ...]

func (Link) GetID

func (l Link) GetID() string

type Mapping

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

Mapping represents a single mapping in the config file like: example_node1.example_column1 TO example_node2.example_column2

type Pair

type Pair struct {
	Link *Link
	// contains filtered or unexported fields
}

Pair represents a connection between two records, that are going to be synchronized. Can be complete or incomplete, where incomplete means that there's only a source record and the target record will have to be created if the synchronization is to be carried out. When a pair is incomplete, a target record will be created only if the parent mapping is configured to DO INSERTs.

func (Pair) Synchronize

func (p Pair) Synchronize() (bool, error)

Synchronize carries out the synchronization of the two records. Updates if this pair is complete (has both the source and the target) and inserts if a target record has to be created.

type Result

type Result struct {
	Message    string      `json:"message"`
	Operations []operation `json:"operations"`
	// contains filtered or unexported fields
}

func (*Result) OperationsToJSON

func (r *Result) OperationsToJSON() string

type Synch

type Synch struct {
	Links []*Link
	// contains filtered or unexported fields
}

Synch represents an individual synchronzation configration. It holds all configuration from an .yaml file, raw and parsed.

func (*Synch) Flush

func (s *Synch) Flush() *Result

func (*Synch) GetConfig

func (s *Synch) GetConfig() *cfg.SynchConfig

GetConfig returns the synch config struct.

func (*Synch) GetIteration

func (s *Synch) GetIteration() *iteration

GetIteration returns the synch's current iteration.

func (*Synch) GetNodes

func (s *Synch) GetNodes() map[string]*node

GetNodes returns all nodes between which synchronization takes place.

func (*Synch) GetRawMappings

func (s *Synch) GetRawMappings() []map[string]string

func (*Synch) GetType

func (s *Synch) GetType() synchType

GetType returns the type of the synch.

func (*Synch) Init

func (s *Synch) Init(DBMap map[string]*db.Database, stype string) string

Init prepares the synchronization by fetching all necessary data and parsing it.

func (*Synch) IsInitial

func (s *Synch) IsInitial() bool

func (*Synch) IsRunning

func (s *Synch) IsRunning() bool

func (*Synch) IsSimulation

func (s *Synch) IsSimulation() bool

func (*Synch) Reset

func (s *Synch) Reset()

Reset clears data preparing the Synch for the next run.

func (*Synch) Run

func (s *Synch) Run()

Run executes a single run of the synchronization.

func (*Synch) SetInitial

func (s *Synch) SetInitial(ini bool)

SetInitial sets the initial struct field indicating whether it's the first run of the synch.

func (*Synch) SetSimulation

func (s *Synch) SetSimulation(sim bool)

func (*Synch) Stop

func (s *Synch) Stop()

Stop stops the synch.

type Synchronizer

type Synchronizer interface {
	GetConfig() *cfg.SynchConfig
	GetIteration() *iteration
	GetNodes() map[string]*node
	GetRawMappings() []map[string]string
	GetType() synchType
	IsSimulation() bool
	Run()
}

Synchronizer is implemented by structs that do the actual synchronization actions.

type Synchs

type Synchs map[string]*Synch

Synchs is a collection of all synchronizations.

func CreateSynchs

func CreateSynchs() Synchs

CreateSynchs constructor function for the Synchs struct.

func (*Synchs) Init

func (s *Synchs) Init()

Init loads configs from files and validates them.

Jump to

Keyboard shortcuts

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