This repository has been archived by the owner on Sep 5, 2018. It is now read-only.
/
main.go
118 lines (107 loc) · 3.64 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
package main
import (
"fmt"
"os"
"time"
"github.com/Financial-Times/base-ft-rw-app-go/baseftrwapp"
fthealth "github.com/Financial-Times/go-fthealth/v1_1"
"github.com/Financial-Times/neo-utils-go/neoutils"
"github.com/Financial-Times/organisations-rw-neo4j/organisations"
"github.com/jawher/mow.cli"
log "github.com/sirupsen/logrus"
)
func main() {
app := cli.App("organisations-rw-neo4j", "A RESTful API for managing Organisations in neo4j")
neoURL := app.String(cli.StringOpt{
Name: "neo-url",
Value: "http://localhost:7474/db/data",
Desc: "neo4j endpoint URL",
EnvVar: "NEO_URL",
})
graphiteTCPAddress := app.String(cli.StringOpt{
Name: "graphiteTCPAddress",
Value: "",
Desc: "Graphite TCP address, e.g. graphite.ft.com:2003. Leave as default if you do NOT want to output to graphite (e.g. if running locally",
EnvVar: "GRAPHITE_ADDRESS",
})
graphitePrefix := app.String(cli.StringOpt{
Name: "graphitePrefix",
Value: "",
Desc: "Prefix to use. Should start with content, include the environment, and the host name. e.g. coco.pre-prod.roles-rw-neo4j.1 or content.test.people.rw.neo4j.ftaps58938-law1a-eu-t",
EnvVar: "GRAPHITE_PREFIX",
})
port := app.Int(cli.IntOpt{
Name: "port",
Value: 8080,
Desc: "Port to listen on",
EnvVar: "APP_PORT",
})
batchSize := app.Int(cli.IntOpt{
Name: "batchSize",
Value: 1024,
Desc: "Maximum number of statements to execute per batch",
EnvVar: "BATCH_SIZE",
})
logMetrics := app.Bool(cli.BoolOpt{
Name: "logMetrics",
Value: false,
Desc: "Whether to log metrics. Set to true if running locally and you want metrics output",
EnvVar: "LOG_METRICS",
})
env := app.String(cli.StringOpt{
Name: "env",
Value: "local",
Desc: "environment this app is running in",
})
app.Action = func() {
conf := neoutils.DefaultConnectionConfig()
conf.BatchSize = *batchSize
db, err := neoutils.Connect(*neoURL, conf)
if err != nil {
log.Errorf("Could not connect to neo4j, error=[%s]\n", err)
}
organisationsDriver := organisations.NewCypherOrganisationService(db)
organisationsDriver.Initialise()
baseftrwapp.OutputMetricsIfRequired(*graphiteTCPAddress, *graphitePrefix, *logMetrics)
services := map[string]baseftrwapp.Service{
"organisations": organisationsDriver,
}
var checks []fthealth.Check
for _, service := range services {
checks = append(checks, makeCheck(service, db))
}
timedHC := fthealth.TimedHealthCheck{
HealthCheck: fthealth.HealthCheck{
SystemCode: "organisations-rw-neo4j",
Description: "Writes 'organisations' to Neo4j, usually as part of a bulk upload done on a schedule",
Name: "organisations-rw-neo4j",
Checks: checks,
},
Timeout: 10 * time.Second,
}
healthHandler := fthealth.Handler(timedHC)
baseftrwapp.RunServerWithConf(baseftrwapp.RWConf{
Services: services,
HealthHandler: healthHandler,
Port: *port,
ServiceName: "organisations-rw-neo4j",
Env: *env,
EnableReqLog: true,
})
}
log.SetLevel(log.InfoLevel)
log.Infof("Application started with args %v", os.Args)
app.Run(os.Args)
}
func makeCheck(service baseftrwapp.Service, cr neoutils.CypherRunner) fthealth.Check {
return fthealth.Check{
BusinessImpact: "Cannot read/write organisations via this writer",
Name: "Check connectivity to Neo4j - neoUrl is a parameter in hieradata for this service",
PanicGuide: "TODO - write panic guide",
Severity: 1,
TechnicalSummary: fmt.Sprintf("Cannot connect to Neo4j instance %s with at least one organisation loaded in it", cr),
Checker: func() (string, error) {
return "", service.Check()
},
}
}