-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·145 lines (112 loc) · 3.86 KB
/
main.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
package main
import (
"runtime"
"syscall"
"github.com/unchartedsoftware/plog"
"github.com/unchartedsoftware/veldt"
"github.com/unchartedsoftware/veldt/generation/elastic"
"github.com/unchartedsoftware/veldt/generation/file"
"github.com/unchartedsoftware/veldt/generation/remote"
"github.com/unchartedsoftware/veldt/generation/rest"
"github.com/unchartedsoftware/veldt/store/redis"
"github.com/zenazn/goji/graceful"
"github.com/gtra-uncharted-collab/topic-visualization/api"
)
const (
port = "8081"
esHost = "http://10.64.16.120"
esPort = "9200"
redisHost = "localhost"
redisPort = "6379"
)
func NewElasticPipeline() *veldt.Pipeline {
// Create pipeline
pipeline := veldt.NewPipeline()
// Add boolean expression types
pipeline.Binary(elastic.NewBinaryExpression)
pipeline.Unary(elastic.NewUnaryExpression)
// Add query types to the pipeline
pipeline.Query("exists", elastic.NewExists)
pipeline.Query("has", elastic.NewHas)
pipeline.Query("equals", elastic.NewEquals)
pipeline.Query("range", elastic.NewRange)
// Add tiles types to the pipeline
pipeline.Tile("count", elastic.NewCountTile(esHost, esPort))
pipeline.Tile("heatmap", elastic.NewHeatmapTile(esHost, esPort))
pipeline.Tile("macro", elastic.NewMacroTile(esHost, esPort))
pipeline.Tile("micro", elastic.NewMicroTile(esHost, esPort))
pipeline.Tile("top-term-count", elastic.NewTopTermCountTile(esHost, esPort))
// Set the maximum concurrent tile requests
pipeline.SetMaxConcurrent(32)
// Set the tile requests queue length
pipeline.SetQueueLength(1024)
// Add meta types to the pipeline
pipeline.Meta("default", elastic.NewDefaultMeta(esHost, esPort))
// Add a store to the pipeline
pipeline.Store(redis.NewStore(redisHost, redisPort, -1))
return pipeline
}
func NewRESTPipeline() *veldt.Pipeline {
// Create pipeline
pipeline := veldt.NewPipeline()
// Add tiles types to the pipeline
pipeline.Tile("rest", rest.NewTile())
// Set the maximum concurrent tile requests
pipeline.SetMaxConcurrent(256)
// Set the tile requests queue length
pipeline.SetQueueLength(1024)
// Add a store to the pipeline
pipeline.Store(redis.NewStore(redisHost, redisPort, -1))
return pipeline
}
func NewRemotePipeline() *veldt.Pipeline {
// Create pipeline
pipeline := veldt.NewPipeline()
// Add tiles types to the pipeline
pipeline.Tile("topic", remote.NewTopicTile())
pipeline.Tile("exclusiveness", remote.NewHitmapTile())
pipeline.Tile("geopoint", remote.NewGeoPointTile())
pipeline.Tile("wordglyph", remote.NewWordGlyphTile())
log.Debug(pipeline);
// Set the maximum concurrent tile requests
pipeline.SetMaxConcurrent(256)
// Set the tile requests queue length
pipeline.SetQueueLength(1024)
// Add a store to the pipeline
pipeline.Store(redis.NewStore(redisHost, redisPort, -1))
return pipeline
}
func NewFilePipeline() *veldt.Pipeline {
// Create pipeline
pipeline := veldt.NewPipeline()
// Add tiles types to the pipeline
pipeline.Tile("file", file.NewTile())
// Set the maximum concurrent tile requests
pipeline.SetMaxConcurrent(256)
// Set the tile requests queue length
pipeline.SetQueueLength(1024)
// Add a store to the pipeline
pipeline.Store(redis.NewStore(redisHost, redisPort, -1))
return pipeline
}
func main() {
// sets the maximum number of CPUs that can be executing simultaneously
runtime.GOMAXPROCS(runtime.NumCPU())
// register the pipelines
veldt.Register("elastic", NewElasticPipeline())
veldt.Register("file", NewFilePipeline())
veldt.Register("rest", NewRESTPipeline())
veldt.Register("remote", NewRemotePipeline())
// create server
app := api.New()
// catch kill signals for graceful shutdown
graceful.AddSignal(syscall.SIGINT, syscall.SIGTERM)
// start server
log.Infof("Veldt server listening on port %s", port)
err := graceful.ListenAndServe(":"+port, app)
if err != nil {
log.Error(err)
}
// wait until server gracefully exits
graceful.Wait()
}