This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
/
dpn_copy.go
69 lines (60 loc) · 1.93 KB
/
dpn_copy.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
package main
import (
"flag"
"fmt"
"github.com/APTrust/exchange/context"
"github.com/APTrust/exchange/dpn/workers"
"github.com/APTrust/exchange/models"
apt_workers "github.com/APTrust/exchange/workers"
"os"
)
// dpn_copy copies bags from other nodes into our staging area
// for replication.
func main() {
pathToConfigFile := parseCommandLine()
config, err := models.LoadConfigFile(pathToConfigFile)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
_context := context.NewContext(config)
_context.MessageLog.Info("Connecting to NSQLookupd at %s", _context.Config.NsqLookupd)
_context.MessageLog.Info("NSQDHttpAddress is %s", _context.Config.NsqdHttpAddress)
consumer, err := apt_workers.CreateNsqConsumer(_context.Config, &_context.Config.DPN.DPNCopyWorker)
if err != nil {
_context.MessageLog.Fatalf(err.Error())
}
copier, err := workers.NewDPNCopier(_context)
if err != nil {
_context.MessageLog.Error(err.Error())
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
_context.MessageLog.Info("dpn_copy started")
consumer.AddHandler(copier)
consumer.ConnectToNSQLookupd(_context.Config.NsqLookupd)
// This reader blocks until we get an interrupt, so our program does not exit.
<-consumer.StopChan
}
// See if you can figure out from the function name what this does.
func parseCommandLine() (configFile string) {
var pathToConfigFile string
flag.StringVar(&pathToConfigFile, "config", "", "Path to APTrust config file")
flag.Parse()
if pathToConfigFile == "" {
printUsage()
os.Exit(1)
}
return pathToConfigFile
}
// Tell the user about the program.
func printUsage() {
message := `
dpn_copy copies bags from remote nodes into our staging area so
we can replicate them. Copying is done through rsync over ssh.
Usage: dpn_copy -config=<path to APTrust config file>
Param -config is required and can be an absolute path or config/env.json,
where env is dev, test, production, etc.
`
fmt.Println(message)
}