Skip to content

Commit 8cc06c4

Browse files
committed
Merge pull request #364 from MG-RAST/develop
app support - big merge
2 parents 2af852c + e15cf74 commit 8cc06c4

30 files changed

+2641
-1056
lines changed

Diff for: awe-client/awe-client.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,35 @@ func main() {
1515

1616
// workstealer -> dataMover (download from Shock) -> processor -> deliverer (upload to Shock)
1717

18-
if !conf.INIT_SUCCESS {
19-
conf.PrintClientUsage()
18+
err := conf.Init_conf("client")
19+
20+
if err != nil {
21+
fmt.Fprintf(os.Stderr, "ERROR: error reading conf file: "+err.Error())
2022
os.Exit(1)
2123
}
2224

23-
if _, err := os.Stat(conf.WORK_PATH); err != nil && os.IsNotExist(err) {
25+
//if !conf.INIT_SUCCESS {
26+
// conf.PrintClientUsage()
27+
// os.Exit(1)
28+
//}
29+
30+
if _, err = os.Stat(conf.WORK_PATH); err != nil && os.IsNotExist(err) {
2431
if err := os.MkdirAll(conf.WORK_PATH, 0777); err != nil {
25-
fmt.Fprintf(os.Stderr, "ERROR in creating work_path %s\n", err.Error())
32+
fmt.Fprintf(os.Stderr, "ERROR in creating work_path \"%s\" : %s\n", conf.WORK_PATH, err.Error())
2633
os.Exit(1)
2734
}
2835
}
2936

3037
if _, err := os.Stat(conf.DATA_PATH); err != nil && os.IsNotExist(err) {
3138
if err := os.MkdirAll(conf.DATA_PATH, 0777); err != nil {
32-
fmt.Fprintf(os.Stderr, "ERROR in creating data_path %s\n", err.Error())
39+
fmt.Fprintf(os.Stderr, "ERROR in creating data_path \"%s\" : %s\n", conf.DATA_PATH, err.Error())
3340
os.Exit(1)
3441
}
3542
}
3643

3744
if _, err := os.Stat(conf.LOGS_PATH); err != nil && os.IsNotExist(err) {
3845
if err := os.MkdirAll(conf.LOGS_PATH, 0777); err != nil {
39-
fmt.Fprintf(os.Stderr, "ERROR in creating log_path %s\n", err.Error())
46+
fmt.Fprintf(os.Stderr, "ERROR in creating log_path \"%s\" : %s\n", conf.LOGS_PATH, err.Error())
4047
os.Exit(1)
4148
}
4249
}

Diff for: awe-proxy/awe-proxy.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@ func launchAPI(control chan int, port int) {
3737

3838
func main() {
3939

40-
if !conf.INIT_SUCCESS {
41-
conf.PrintServerUsage()
40+
err := conf.Init_conf("proxy") // TODO config not adapted for proxy
41+
42+
if err != nil {
43+
fmt.Fprintf(os.Stderr, "ERROR: error reading conf file: "+err.Error())
4244
os.Exit(1)
4345
}
46+
//if !conf.INIT_SUCCESS {
47+
// conf.PrintServerUsage()
48+
// os.Exit(1)
49+
//}
4450
fmt.Printf("--------AWE Proxy running--------\n\n")
4551
conf.Print("proxy")
4652

Diff for: awe-server/awe-server.go

+48-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import (
1111
"github.com/MG-RAST/AWE/lib/logger/event"
1212
"github.com/MG-RAST/AWE/lib/user"
1313
"github.com/MG-RAST/golib/goweb"
14+
"io"
15+
"io/ioutil"
1416
"os"
17+
"path"
1518
"runtime"
19+
"strings"
1620
)
1721

1822
func launchSite(control chan int, port int) {
@@ -40,6 +44,39 @@ func launchSite(control chan int, port int) {
4044
}
4145

4246
}
47+
48+
if conf.API_URL == "" {
49+
fmt.Fprintf(os.Stderr, "ERROR: API_URL is not defined. \n")
50+
logger.Error("ERROR: API_URL is not defined.")
51+
}
52+
template_conf_filename := path.Join(conf.SITE_PATH, "js/config.js.tt")
53+
target_conf_filename := path.Join(conf.SITE_PATH, "js/config.js")
54+
buf, err := ioutil.ReadFile(template_conf_filename)
55+
if err != nil {
56+
fmt.Fprintf(os.Stderr, "ERROR: could not read config template: %v\n", err)
57+
logger.Error("ERROR: could not read config template: " + err.Error())
58+
}
59+
template_conf_string := string(buf)
60+
61+
// example: [% api_url %]
62+
63+
template_conf_string = strings.Replace(template_conf_string, "[% api_url %]", conf.API_URL, -1)
64+
65+
target_conf_file, err := os.Create(target_conf_filename)
66+
if err != nil {
67+
fmt.Fprintf(os.Stderr, "ERROR: could not write config for Retina: %v\n", err)
68+
logger.Error("ERROR: could not write config for Retina: " + err.Error())
69+
}
70+
71+
_, err = io.WriteString(target_conf_file, template_conf_string)
72+
73+
if err != nil {
74+
fmt.Fprintf(os.Stderr, "ERROR: could not write config for Retina: %v\n", err)
75+
logger.Error("ERROR: could not write config for Retina: " + err.Error())
76+
}
77+
78+
target_conf_file.Close()
79+
4380
r.MapFunc("*", controller.SiteDir)
4481
if conf.SSL_ENABLED {
4582
err := goweb.ListenAndServeRoutesTLS(fmt.Sprintf(":%d", conf.SITE_PORT), conf.SSL_CERT_FILE, conf.SSL_KEY_FILE, r)
@@ -91,23 +128,30 @@ func launchAPI(control chan int, port int) {
91128

92129
func main() {
93130

94-
if !conf.INIT_SUCCESS {
95-
conf.PrintServerUsage()
131+
err := conf.Init_conf("server")
132+
133+
if err != nil {
134+
fmt.Fprintf(os.Stderr, "ERROR: error reading conf file: "+err.Error())
96135
os.Exit(1)
97136
}
137+
138+
//if !conf.INIT_SUCCESS {
139+
// conf.PrintServerUsage()
140+
// os.Exit(1)
141+
//}
98142
if conf.DEBUG_LEVEL > 0 {
99143
fmt.Println("DEBUG_LEVEL > 0")
100144
}
101145
if _, err := os.Stat(conf.DATA_PATH); err != nil && os.IsNotExist(err) {
102146
if err := os.MkdirAll(conf.DATA_PATH, 0777); err != nil {
103-
fmt.Fprintf(os.Stderr, "ERROR in creating data_path %s\n", err.Error())
147+
fmt.Fprintf(os.Stderr, "ERROR in creating data_path \"%s\", %s\n", conf.DATA_PATH, err.Error())
104148
os.Exit(1)
105149
}
106150
}
107151

108152
if _, err := os.Stat(conf.LOGS_PATH); err != nil && os.IsNotExist(err) {
109153
if err := os.MkdirAll(conf.LOGS_PATH, 0777); err != nil {
110-
fmt.Fprintf(os.Stderr, "ERROR in creating log_path %s\n", err.Error())
154+
fmt.Fprintf(os.Stderr, "ERROR in creating log_path \"%s\" %s\n", conf.LOGS_PATH, err.Error())
111155
os.Exit(1)
112156
}
113157
}

Diff for: lib/cache/cache.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"fmt"
77
"github.com/MG-RAST/AWE/lib/conf"
88
"github.com/MG-RAST/AWE/lib/core"
9-
"github.com/MG-RAST/AWE/lib/httpclient"
109
"github.com/MG-RAST/AWE/lib/logger"
1110
"github.com/MG-RAST/AWE/lib/logger/event"
1211
"github.com/MG-RAST/AWE/lib/shock"
12+
"github.com/MG-RAST/golib/httpclient"
1313
"io"
1414
"io/ioutil"
1515
"os"
@@ -167,7 +167,7 @@ func MoveInputData(work *core.Workunit) (size int64, err error) {
167167

168168
// download file
169169
if datamoved, _, err := shock.FetchFile(inputFilePath, dataUrl, work.Info.DataToken, io.Uncompress, false); err != nil {
170-
return size, err
170+
return size, errors.New("shock.FetchFile returned: " + err.Error())
171171
} else {
172172
size += datamoved
173173
}
@@ -179,7 +179,8 @@ func MoveInputData(work *core.Workunit) (size int64, err error) {
179179
// get node
180180
node, err := shock.ShockGet(io.Host, io.Node, work.Info.DataToken)
181181
if err != nil {
182-
return size, err
182+
//return size, err
183+
return size, errors.New("shock.ShockGet (node attributes) returned: " + err.Error())
183184
}
184185
logger.Debug(2, "mover: fetching input attributes from node:"+node.Id)
185186
logger.Event(event.ATTR_IN, "workid="+work.Id+";node="+node.Id)

0 commit comments

Comments
 (0)