/
processor.go
161 lines (126 loc) · 3.35 KB
/
processor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package processor
import (
"database/sql"
"time"
"github.com/aleksasiriski/rffmpeg-go/migrate"
)
type Config struct {
Db *sql.DB
DbType string
Mg *migrate.Migrator
}
type Host struct {
Id int
Servername string
Hostname string
Weight int
Created time.Time
}
type Process struct {
Id int
HostId int
ProcessId int
Cmd string
}
type State struct {
Id int
HostId int
ProcessId int
State string
}
func New(config Config) (*Processor, error) {
store, err := newDatastore(config.Db, config.DbType, config.Mg)
if err != nil {
return nil, err
}
proc := &Processor{
store: store,
}
return proc, nil
}
type Processor struct {
store *datastore
processed int64
}
// version
func (p *Processor) GetVersion() (string, error) {
return p.store.SelectVersion()
}
// hosts
func (p *Processor) AddHost(host Host) error {
return p.store.UpsertHost(host)
}
func (p *Processor) RemoveHosts() error {
return p.store.DeleteHosts()
}
func (p *Processor) RemoveHost(host Host) error {
return p.store.DeleteHost(host)
}
func (p *Processor) NumberOfHosts() (int, error) {
return p.store.SelectCountHosts()
}
func (p *Processor) GetHosts() ([]Host, error) {
return p.store.SelectHosts()
}
func (p *Processor) GetHostsByField(field string, value string) ([]Host, error) {
return p.store.SelectHostsWhere(field, value)
}
func (p *Processor) GetHostsIdByField(field string, value string) ([]Host, error) {
return p.store.SelectHostsIdWhere(field, value)
}
// processes
func (p *Processor) AddProcess(process Process) error {
return p.store.InsertProcess(process)
}
func (p *Processor) RemoveProcesses() error {
return p.store.DeleteProcesses()
}
func (p *Processor) RemoveProcessesByField(field string, process Process) error {
return p.store.DeleteProcessesWhere(field, process)
}
func (p *Processor) NumberOfProcesses() (int, error) {
return p.store.SelectCountProcesses()
}
func (p *Processor) NumberOfProcessesFromHost(host Host) (int, error) {
return p.store.SelectCountProcessesWhere(host)
}
func (p *Processor) GetProcesses() ([]Process, error) {
return p.store.SelectProcesses()
}
func (p *Processor) GetProcessesId() ([]Process, error) {
return p.store.SelectProcessesId()
}
func (p *Processor) GetProcessesFromHost(host Host) ([]Process, error) {
return p.store.SelectProcessesWhere(host)
}
func (p *Processor) GetProcessesIdFromHost(host Host) ([]Process, error) {
return p.store.SelectProcessesIdWhere(host)
}
// states
func (p *Processor) AddState(state State) error {
return p.store.InsertState(state)
}
func (p *Processor) RemoveStates() error {
return p.store.DeleteStates()
}
func (p *Processor) RemoveStatesByField(field string, state State) error {
return p.store.DeleteStatesWhere(field, state)
}
func (p *Processor) NumberOfStates() (int, error) {
return p.store.SelectCountStates()
}
func (p *Processor) NumberOfStatesFromHost(host Host) (int, error) {
return p.store.SelectCountStatesWhere(host)
}
func (p *Processor) GetStates() ([]State, error) {
return p.store.SelectStates()
}
func (p *Processor) GetStatesId() ([]State, error) {
return p.store.SelectStatesId()
}
func (p *Processor) GetStatesFromHost(host Host) ([]State, error) {
return p.store.SelectStatesWhere(host)
}
func (p *Processor) GetStatesIdFromHost(host Host) ([]State, error) {
return p.store.SelectStatesIdWhere(host)
}