-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhpipe.go
94 lines (82 loc) · 1.89 KB
/
hpipe.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
/***************************************************************
*
* Copyright (c) 2015, Menglong TAN <tanmenglong@gmail.com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GPL licence
*
**************************************************************/
/**
*
*
* @file hpipe.go
* @author Menglong TAN <tanmenglong@gmail.com>
* @date Tue Aug 25 00:16:25 2015
*
**/
package main
import (
"fmt"
"github.com/crackcell/hpipe/config"
"github.com/crackcell/hpipe/dag"
"github.com/crackcell/hpipe/log"
"github.com/crackcell/hpipe/sched"
"github.com/crackcell/hpipe/status"
"github.com/crackcell/hpipe/util"
"os"
)
func newStatusFlag() (status.Saver, error) {
switch config.StatusSaver {
case "hdfs":
return status.NewHDFSSaver(config.NameNode)
case "sqlite":
return status.NewSqliteSaver(config.SqliteFile)
default:
msg := fmt.Sprintf("invalid status keeper type: %s",
config.StatusSaver)
log.Fatal(msg)
return nil, fmt.Errorf(msg)
}
}
func newSched() (*sched.Sched, error) {
saver, err := newStatusFlag()
if err != nil {
log.Fatal(err)
os.Exit(1)
}
return sched.NewSched(status.NewStatusTracker(saver))
}
func main() {
config.InitFlags()
config.Parse()
loglevel := 0
if config.Verbose {
loglevel = log.LOG_LEVEL_ALL
} else {
loglevel = log.LOG_LEVEL_TRACE | log.LOG_LEVEL_INFO |
log.LOG_LEVEL_WARN | log.LOG_LEVEL_ERROR |
log.LOG_LEVEL_FATAL
}
if config.LessLog {
log.StdLogger = log.NewDefaultCleanLogger(
os.Stdout, "hpipe", loglevel)
} else {
log.StdLogger = log.NewDefault(
os.Stdout, "hpipe", loglevel)
}
d, err := dag.LoadFromFile(config.EntryFile)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
util.LogLines(config.LogoString(), nil)
util.LogLines(d.String(), nil)
s, err := newSched()
if err != nil {
log.Fatal(err)
os.Exit(1)
}
if err := s.Run(d); err != nil {
os.Exit(1)
}
}