This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
/
dpn_sync.go
90 lines (83 loc) · 2.76 KB
/
dpn_sync.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
package main
import (
"flag"
"fmt"
"github.com/APTrust/bagman/dpn"
"os"
)
// dpn_sync copies updated records from the registries
// at other nodes into our local DPN registry.
func main() {
configPath := "dpn/dpn_config.json"
configName := parseCommandLine()
dpnConfig, err := dpn.LoadConfig(configPath, configName)
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading dpn config file '%s': %v\n",
configPath, err)
os.Exit(2)
}
dpnSync, err := dpn.NewDPNSync(dpnConfig)
if err != nil {
fmt.Fprintf(os.Stderr, "dpn_sync failed to start: %v\n", err)
os.Exit(3)
}
nodes, err := dpnSync.GetAllNodes()
if err != nil {
fmt.Fprintf(os.Stderr, "dpn_sync could not get node list: %v\n", err)
os.Exit(4)
}
for _, node := range nodes {
if node.Namespace == "aptrust" {
continue
}
// The sync code logs to a file called dpn_sync.log
// in the log directory specified in the config file.
syncResult := dpnSync.SyncEverythingFromNode(node)
printErrors(syncResult, node)
// -- DEBUG --
// fmt.Printf("************* Sync Result for %s ************\n", node.Name)
// fmt.Println("--- BAGS ---")
// for _, bag := range syncResult.Bags {
// fmt.Println(bag.UUID)
// }
// fmt.Printf("--- XFERS ---")
// for _, xfer := range syncResult.ReplicationTransfers {
// fmt.Println("%s : % -> %s\n", xfer.BagId, xfer.FromNode, xfer.ToNode)
// }
// fmt.Println("--- RESTORES ---")
// for _, xfer := range syncResult.RestoreTransfers {
// fmt.Printf("%s : % -> %s\n", xfer.BagId, xfer.ToNode, xfer.FromNode)
// }
// fmt.Printf(">>> Bag Sync Error: %s\n", syncResult.BagSyncError)
// fmt.Printf(">>> Replication Sync Error: %s\n", syncResult.ReplicationSyncError)
// fmt.Printf(">>> Restore Sync Error: %s\n", syncResult.RestoreSyncError)
}
}
func parseCommandLine() (string) {
config := flag.String("config", "", "DPN config name [dev|test|production]")
flag.Parse()
if config == nil || *config == "" {
printUsage()
fmt.Fprintln(os.Stderr, "You must specify a DPN config name (dev|test|production)")
os.Exit(1)
}
return *config
}
func printUsage() {
fmt.Println("Usage: dpn_sync -config=pathToDPNConfigFile")
fmt.Println("Sync bag and transfer entries from remote nodes to our local registry.")
}
func printErrors(syncResult *dpn.SyncResult, node *dpn.DPNNode) {
if syncResult.BagSyncError != nil {
fmt.Fprintf(os.Stderr, "Error synching bags from %s: %v\n",
node.Namespace, syncResult.BagSyncError)
}
if syncResult.ReplicationSyncError != nil {
fmt.Fprintf(os.Stderr, "Error synching Replication Transfers from %s: %v\n",
node.Namespace, syncResult.ReplicationSyncError)
}
if syncResult.RestoreSyncError != nil {
fmt.Fprintf(os.Stderr, "Error synching Restore Transfers from %s: %v\n",
node.Namespace, syncResult.RestoreSyncError)
}
}