src/amp/amp/node.go |
| ... | ... | @@ -4,9 +4,10 @@ |
| 4 | 4 | package main |
| 5 | 5 | |
| 6 | 6 | import ( |
| 7 | + "amp/logging" |
| 8 | + "amp/master" |
| 7 | 9 | "amp/nodule" |
| 8 | 10 | "amp/optparse" |
| 9 | | - "amp/repo" |
| 10 | 11 | "amp/runtime" |
| 11 | 12 | "os" |
| 12 | 13 | "strings" |
| ... | ... | @@ -35,33 +36,40 @@ func ampNode(argv []string, usage string) { |
| 35 | 36 | nodulePaths := opts.StringConfig("nodule-paths", ".", |
| 36 | 37 | "comma-separated list of nodule container directories [nodule]") |
| 37 | 38 | |
| 38 | | - repoNodes := opts.StringConfig("repo-nodes", "localhost:8060", |
| 39 | | - "comma-separated addresses of amp repo nodes [localhost:8060]") |
| 39 | + masterNodes := opts.StringConfig("master-nodes", "localhost:8060", |
| 40 | + "comma-separated addresses of amp master nodes [localhost:8060]") |
| 40 | 41 | |
| 41 | | - repoKeyPath := opts.StringConfig("repo-key", "cert/repo.key", |
| 42 | | - "the path to the file containing the amp repo public key [cert/repo.key]") |
| 42 | + masterKeyPath := opts.StringConfig("master-key", "cert/master.key", |
| 43 | + "the path to the file containing the amp master public key [cert/master.key]") |
| 43 | 44 | |
| 44 | 45 | debug, _, runPath := runtime.DefaultOpts("node", opts, argv, nil) |
| 45 | 46 | |
| 46 | | - repoClient, err := repo.NewClient(*repoNodes, *repoKeyPath) |
| 47 | + masterClient, err := master.NewClient(*masterNodes, *masterKeyPath) |
| 47 | 48 | |
| 48 | 49 | if err != nil { |
| 49 | 50 | runtime.StandardError(err) |
| 50 | 51 | } |
| 51 | 52 | |
| 53 | + logging.AddConsoleFilter(nodule.FilterConsoleLog) |
| 54 | + |
| 52 | 55 | node, err := nodule.NewHost( |
| 53 | 56 | runPath, *nodeHost, *nodePort, *ctrlHost, *ctrlPort, *nodules, |
| 54 | | - strings.SplitN(*nodulePaths, ",", -1), repoClient) |
| 57 | + strings.SplitN(*nodulePaths, ",", -1), masterClient) |
| 55 | 58 | |
| 56 | 59 | if err != nil { |
| 57 | 60 | runtime.StandardError(err) |
| 58 | 61 | } |
| 59 | 62 | |
| 60 | | - node.Run(debug) |
| 63 | + err = node.Run(debug) |
| 64 | + logging.Wait() |
| 65 | + |
| 66 | + if err != nil { |
| 67 | + runtime.Exit(1) |
| 68 | + } |
| 61 | 69 | |
| 62 | 70 | } |
| 63 | 71 | |
| 64 | | -func getNodules(paths []string) (nodules [][]string) { |
| 72 | +func getNodules(paths []string) (nodules []*nodule.Nodule) { |
| 65 | 73 | |
| 66 | 74 | if paths == nil { |
| 67 | 75 | cwd, err := os.Getwd() |
| ... | ... | @@ -71,7 +79,7 @@ func getNodules(paths []string) (nodules [][]string) { |
| 71 | 79 | paths = []string{cwd} |
| 72 | 80 | } |
| 73 | 81 | |
| 74 | | - nodules = make([][]string, 0) |
| 82 | + nodules = make([]*nodule.Nodule, 0) |
| 75 | 83 | seen := make(map[string]bool) |
| 76 | 84 | |
| 77 | 85 | for _, path := range paths { |
| ... | ... | @@ -79,12 +87,12 @@ func getNodules(paths []string) (nodules [][]string) { |
| 79 | 87 | if err != nil { |
| 80 | 88 | runtime.StandardError(err) |
| 81 | 89 | } |
| 82 | | - for name, confpath := range data { |
| 83 | | - if seen[confpath] { |
| 90 | + for _, nodule := range data { |
| 91 | + if seen[nodule.Path] { |
| 84 | 92 | continue |
| 85 | 93 | } |
| 86 | | - nodules = append(nodules, []string{name, confpath}) |
| 87 | | - seen[confpath] = true |
| 94 | + nodules = append(nodules, nodule) |
| 95 | + seen[nodule.Path] = true |
| 88 | 96 | } |
| 89 | 97 | } |
| 90 | 98 | |
| ... | ... | @@ -92,38 +100,85 @@ func getNodules(paths []string) (nodules [][]string) { |
| 92 | 100 | |
| 93 | 101 | } |
| 94 | 102 | |
| 95 | | -func ampBuild(argv []string, usage string) { |
| 103 | +func handleCommon(name, usage string, argv []string) (args []string) { |
| 96 | 104 | |
| 97 | 105 | opts := optparse.Parser( |
| 98 | | - "Usage: amp build <path> [options]\n\n " + usage + "\n") |
| 106 | + "Usage: amp " + name + " <path> [options]\n\n " + usage + "\n") |
| 99 | 107 | |
| 100 | | - args := opts.Parse(argv) |
| 108 | + profile := opts.String([]string{"--profile"}, "development", |
| 109 | + "the config profile to use [development]", "NAME") |
| 110 | + |
| 111 | + noConsoleLog := opts.Bool([]string{"--no-console-log"}, false, |
| 112 | + "disable output to stdout/stderr") |
| 113 | + |
| 114 | + args = opts.Parse(argv) |
| 101 | 115 | |
| 102 | 116 | if len(args) == 0 { |
| 103 | 117 | opts.PrintUsage() |
| 104 | 118 | runtime.Exit(0) |
| 105 | 119 | } |
| 106 | 120 | |
| 107 | | - for _, info := range getNodules(args) { |
| 108 | | - nodule.Build(info[0], info[1]) |
| 121 | + runtime.SetProfile(*profile) |
| 122 | + |
| 123 | + if !*noConsoleLog { |
| 124 | + logging.AddConsoleLogger() |
| 125 | + logging.AddConsoleFilter(nodule.FilterConsoleLog) |
| 109 | 126 | } |
| 110 | 127 | |
| 128 | + return |
| 129 | + |
| 111 | 130 | } |
| 112 | 131 | |
| 113 | | -func ampTest(argv []string, usage string) { |
| 132 | +func ampBuild(argv []string, usage string) { |
| 114 | 133 | |
| 115 | | - opts := optparse.Parser( |
| 116 | | - "Usage: amp test <path> [options]\n\n " + usage + "\n") |
| 134 | + args := handleCommon("build", usage, argv) |
| 135 | + status := 0 |
| 117 | 136 | |
| 118 | | - args := opts.Parse(argv) |
| 137 | + for _, nodule := range getNodules(args) { |
| 138 | + err := nodule.Build() |
| 139 | + if err != nil { |
| 140 | + status = 1 |
| 141 | + break |
| 142 | + } |
| 143 | + } |
| 119 | 144 | |
| 120 | | - if len(args) == 0 { |
| 121 | | - opts.PrintUsage() |
| 122 | | - runtime.Exit(0) |
| 145 | + logging.Wait() |
| 146 | + runtime.Exit(status) |
| 147 | + |
| 148 | +} |
| 149 | + |
| 150 | +func ampTest(argv []string, usage string) { |
| 151 | + |
| 152 | + args := handleCommon("test", usage, argv) |
| 153 | + status := 0 |
| 154 | + |
| 155 | + for _, nodule := range getNodules(args) { |
| 156 | + err := nodule.Test() |
| 157 | + if err != nil { |
| 158 | + status = 1 |
| 159 | + break |
| 160 | + } |
| 123 | 161 | } |
| 124 | 162 | |
| 125 | | - for _, info := range getNodules(args) { |
| 126 | | - nodule.Test(info[0], info[1]) |
| 163 | + logging.Wait() |
| 164 | + runtime.Exit(status) |
| 165 | + |
| 166 | +} |
| 167 | + |
| 168 | +func ampReview(argv []string, usage string) { |
| 169 | + |
| 170 | + args := handleCommon("review", usage, argv) |
| 171 | + status := 0 |
| 172 | + |
| 173 | + for _, nodule := range getNodules(args) { |
| 174 | + err := nodule.Review() |
| 175 | + if err != nil { |
| 176 | + status = 1 |
| 177 | + break |
| 178 | + } |
| 127 | 179 | } |
| 128 | 180 | |
| 181 | + logging.Wait() |
| 182 | + runtime.Exit(status) |
| 183 | + |
| 129 | 184 | } |