Mercurial > gemma
annotate pkg/geoserver/boot.go @ 1879:9a2fbeaabd52 dev-pdf-generation
merging in from branch default
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Tue, 15 Jan 2019 10:07:10 +0100 |
parents | d7152eb11d58 |
children | 9dbaf69c7a66 |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
13 |
868
aa8f30c1ed27
Moved GeoServer configuration to own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
559
diff
changeset
|
14 package geoserver |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "bytes" |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "encoding/json" |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
19 "encoding/xml" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "fmt" |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
21 "io" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "log" |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "net/http" |
868
aa8f30c1ed27
Moved GeoServer configuration to own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
559
diff
changeset
|
24 "net/url" |
417
ff26ffc18a04
Minor: Removed unnecessary byte slice conversion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
25 "strings" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
414
c1047fd04a3a
Moved project specific Go packages to new pkg folder.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
398
diff
changeset
|
27 "gemma.intevation.de/gemma/pkg/config" |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
435
diff
changeset
|
28 "gemma.intevation.de/gemma/pkg/models" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 ) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 const ( |
1446
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
32 workspaceName = "gemma" |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
33 datastoreName = "gemma" |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
34 databaseScheme = "waterway" |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
35 databaseType = "postgis" |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
36 primaryKeyMetadataTbl = "waterway.gt_pk_metadata" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 ) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
39 const ( |
477
00b52d653039
It turns out that the GeoServer is happy with the lower privileged 'waterway_user'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
476
diff
changeset
|
40 startupSQL = `SELECT public.setrole('${user,'||encode('waterway_user', 'hex')||'}')` |
431
7cd1536a6797
Replaced sys-admin db user with a metamorphic one.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
429
diff
changeset
|
41 closeupSQL = `RESET ROLE` |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
42 ) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 func basicAuth(user, password string) func(req *http.Request) { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 return func(req *http.Request) { |
559
f827dc4f3e95
Use stdlib for basic auth instead og home brew in GeoServer config.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
46 req.SetBasicAuth(user, password) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
50 func toStream(x interface{}) io.Reader { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
51 var buf bytes.Buffer |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
52 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
53 if err := json.NewEncoder(&buf).Encode(x); err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
54 // Should not happen |
1032
4c0c4dd393de
Be more consistent with info/warn/error messages when logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
55 log.Printf("warn: bad JSON: %v\n", err) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
56 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
57 return bytes.NewReader(buf.Bytes()) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
58 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
59 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 func asJSON(req *http.Request) { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 req.Header.Set("Content-Type", "application/json") |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
64 func asContentType(req *http.Request, contentType string) { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
65 req.Header.Set("Content-Type", contentType) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
66 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
67 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 func ensureWorkspace() error { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
70 geoURL = config.GeoServerURL() |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 user = config.GeoServerUser() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 password = config.GeoServerPassword() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 auth = basicAuth(user, password) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 ) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 // Probe workspace. |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 req, err := http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 http.MethodGet, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
79 geoURL+"/rest/workspaces/"+workspaceName+".json", |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 nil) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 resp, err := http.DefaultClient.Do(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 if resp.StatusCode != http.StatusNotFound { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 log.Println("info: workspace " + workspaceName + " already exists.") |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 // Create workspace |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
96 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
97 log.Println("info: creating workspace " + workspaceName) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
98 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 const createJSON = `{"workspace":{"name":"` + workspaceName + `"}}` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 req, err = http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
103 geoURL+"/rest/workspaces", |
417
ff26ffc18a04
Minor: Removed unnecessary byte slice conversion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
104 strings.NewReader(createJSON)) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 asJSON(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 if resp, err = http.DefaultClient.Do(req); err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 if resp.StatusCode != http.StatusCreated { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 err = fmt.Errorf("Status code '%s' (%d)", |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 http.StatusText(resp.StatusCode), |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 resp.StatusCode) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 func ensureDataStore() error { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
125 geoURL = config.GeoServerURL() |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 user = config.GeoServerUser() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 password = config.GeoServerPassword() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 auth = basicAuth(user, password) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 ) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
131 // Probe datastore. |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 req, err := http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 http.MethodGet, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
134 geoURL+"/rest/workspaces/"+workspaceName+ |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
135 "/datastores/"+datastoreName+".json", |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 nil) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 resp, err := http.DefaultClient.Do(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 if resp.StatusCode != http.StatusNotFound { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 log.Println("info: datastore " + datastoreName + " already exists.") |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
151 // Create datastore. |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
152 log.Println("info: creating datastore " + datastoreName) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
153 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 type entry struct { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 Key interface{} `json:"@key"` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 Value interface{} `json:"$"` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 // Create datastore. |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 ds := map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 "dataStore": map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 "name": datastoreName, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 "connectionParameters": map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 "entry": []entry{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 {"host", config.DBHost()}, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 {"port", config.DBPort()}, |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
167 {"database", config.DBName()}, |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 {"schema", databaseScheme}, |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
169 {"user", config.DBUser()}, |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
170 {"passwd", config.DBPassword()}, |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 {"dbtype", databaseType}, |
1446
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
172 {"Primary key metadata table", primaryKeyMetadataTbl}, |
433
da05704e25c1
Removed templating from GeoServer startup SQL script.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
432
diff
changeset
|
173 {"Session startup SQL", startupSQL}, |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
174 {"Session close-up SQL", closeupSQL}, |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 }, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 }, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 }, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 req, err = http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
182 geoURL+"/rest/workspaces/"+workspaceName+"/datastores", |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
183 toStream(ds)) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 asJSON(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 resp, err = http.DefaultClient.Do(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 if resp.StatusCode != http.StatusCreated { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 err = fmt.Errorf("Status code '%s' (%d)", |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 http.StatusText(resp.StatusCode), |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 resp.StatusCode) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
203 func ensureFeatures() error { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
204 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
205 geoURL = config.GeoServerURL() |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
206 user = config.GeoServerUser() |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
207 password = config.GeoServerPassword() |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
208 auth = basicAuth(user, password) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
209 ) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
210 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
467
diff
changeset
|
211 tables := models.InternalServices.Filter(models.IntWFS) |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
212 if len(tables) == 0 { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
213 log.Println("info: no tables to publish") |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
214 return nil |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
215 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
216 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
217 log.Printf("info: number of tables to publish %d\n", len(tables)) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
218 |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
219 var features struct { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
220 FeatureTypes struct { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
221 FeatureType []struct { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
222 Name string `json:"name"` |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
223 } `json:"featureType"` |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
224 } `json:"featureTypes"` |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
225 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
226 |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
227 hasFeature := func(name string) bool { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
228 for _, ft := range features.FeatureTypes.FeatureType { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
229 if ft.Name == name { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
230 return true |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
231 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
232 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
233 return false |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
234 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
235 |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
236 // Fetch all featuretypes. |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
237 req, err := http.NewRequest( |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
238 http.MethodGet, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
239 geoURL+"/rest/workspaces/"+workspaceName+ |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
240 "/datastores/"+datastoreName+ |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
241 "/featuretypes.json", |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
242 nil) |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
243 if err != nil { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
244 return err |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
245 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
246 auth(req) |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
247 resp, err := http.DefaultClient.Do(req) |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
248 if err != nil { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
249 return err |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
250 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
251 |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
252 err = json.NewDecoder(resp.Body).Decode(&features) |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
253 resp.Body.Close() |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
254 if err != nil { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
255 // XXX: Quirk in the JSON return by GeoServer: |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
256 // If there are no features in the datastore |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
257 // featureType deserializes to an empty string "" |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
258 // instead of an empty array *palmface*. |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
259 // So assume there no features. |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
260 hasFeature = func(string) bool { return false } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
261 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
262 |
449
a74b8c2a4e75
Removed the command line option to publish tables with GeoServer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
444
diff
changeset
|
263 for i := range tables { |
a74b8c2a4e75
Removed the command line option to publish tables with GeoServer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
444
diff
changeset
|
264 table := tables[i].Name |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
435
diff
changeset
|
265 |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
266 if hasFeature(table) { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
267 log.Printf("info: featuretype %s already exists.\n", table) |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
268 continue |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
269 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
270 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
271 // Create featuretype. |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
272 log.Printf("info: creating featuretype %s.\n", table) |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
273 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
274 // Create featuretype |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
275 ft := map[string]interface{}{ |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
276 "featureType": map[string]interface{}{ |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
277 "name": table, |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
278 "nativeName": table, |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
279 "title": table, |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
280 }, |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
281 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
282 |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
283 req, err := http.NewRequest( |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
284 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
285 geoURL+"/rest/workspaces/"+workspaceName+ |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
286 "/datastores/"+datastoreName+ |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
287 "/featuretypes", |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
288 toStream(ft)) |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
289 if err != nil { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
290 return err |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
291 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
292 auth(req) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
293 asJSON(req) |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
294 resp, err := http.DefaultClient.Do(req) |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
295 if err != nil { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
296 return err |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
297 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
298 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
299 if resp.StatusCode != http.StatusCreated { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
300 return fmt.Errorf("Status code '%s' (%d)", |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
301 http.StatusText(resp.StatusCode), |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
302 resp.StatusCode) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
303 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
304 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
305 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
306 return nil |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
307 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
308 |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
309 func deleteWorkspace() error { |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
310 |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
311 // Should we delete our workspace first? |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
312 if !config.GeoServerClean() { |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
313 return nil |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
314 } |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
315 |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
316 log.Println("info: delete workspace " + workspaceName) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
317 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
318 geoURL = config.GeoServerURL() |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
319 user = config.GeoServerUser() |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
320 password = config.GeoServerPassword() |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
321 auth = basicAuth(user, password) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
322 ) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
323 |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
324 req, err := http.NewRequest( |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
325 http.MethodDelete, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
326 geoURL+"/rest/workspaces/"+workspaceName+"?recurse=true", |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
327 nil) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
328 if err != nil { |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
329 return err |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
330 } |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
331 auth(req) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
332 _, err = http.DefaultClient.Do(req) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
333 return err |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
334 } |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
335 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
336 type styles struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
337 Styles struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
338 Style []struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
339 Name string `json:"name"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
340 } `json:"style"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
341 } `json:"styles"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
342 } |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
343 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
344 func (s *styles) hasStyle(name string) bool { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
345 for i := range s.Styles.Style { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
346 if s.Styles.Style[i].Name == name { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
347 return true |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
348 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
349 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
350 return false |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
351 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
352 |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
353 func (s *styles) load() error { |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
354 var ( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
355 geoURL = config.GeoServerURL() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
356 user = config.GeoServerUser() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
357 password = config.GeoServerPassword() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
358 auth = basicAuth(user, password) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
359 ) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
360 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
361 req, err := http.NewRequest( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
362 http.MethodGet, |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
363 geoURL+"/rest/workspaces/"+workspaceName+"/styles.json", |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
364 nil) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
365 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
366 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
367 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
368 auth(req) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
369 resp, err := http.DefaultClient.Do(req) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
370 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
371 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
372 } |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
373 defer resp.Body.Close() |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
374 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
375 // Fetch all styles |
1325
9d1f8e99743b
Removed empty if branch.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1032
diff
changeset
|
376 // XXX: Avoid error checking due to quirks with featuretypes. |
9d1f8e99743b
Removed empty if branch.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1032
diff
changeset
|
377 json.NewDecoder(resp.Body).Decode(s) |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
378 return nil |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
379 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
380 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
381 func updateStyle(entry *models.IntEntry, create bool) error { |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
382 |
1032
4c0c4dd393de
Be more consistent with info/warn/error messages when logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
383 log.Printf("info: creating style %s\n", entry.Name) |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
384 |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
385 // Try to load the style data. |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
386 data, err := entry.LoadStyle() |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
387 if err != nil { |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
388 return err |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
389 } |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
390 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
391 var ( |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
392 geoURL = config.GeoServerURL() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
393 user = config.GeoServerUser() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
394 password = config.GeoServerPassword() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
395 auth = basicAuth(user, password) |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
396 ) |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
397 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
398 styleURL := geoURL + "/rest/workspaces/" + workspaceName + |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
399 "/styles" |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
400 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
401 // First create style |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
402 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
403 type Style struct { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
404 Name string `json:"name"` |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
405 Filename string `json:"filename"` |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
406 } |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
407 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
408 var styleFilename = struct { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
409 Style Style `json:"style"` |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
410 }{ |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
411 Style: Style{ |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
412 Name: entry.Name, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
413 Filename: entry.Name + ".sld", |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
414 }, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
415 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
416 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
417 if create { |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
418 req, err := http.NewRequest( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
419 http.MethodPost, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
420 styleURL, |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
421 toStream(&styleFilename)) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
422 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
423 if err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
424 return err |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
425 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
426 auth(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
427 asJSON(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
428 resp, err := http.DefaultClient.Do(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
429 if err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
430 return err |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
431 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
432 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
433 if resp.StatusCode != http.StatusCreated { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
434 return fmt.Errorf("Unable to create style %s (%s)", |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
435 entry.Name, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
436 http.StatusText(resp.StatusCode)) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
437 } |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
438 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
439 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
440 // Second upload data |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
441 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
442 req, err := http.NewRequest( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
443 http.MethodPut, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
444 styleURL+"/"+url.PathEscape(entry.Name), |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
445 strings.NewReader(data)) |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
446 if err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
447 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
448 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
449 auth(req) |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
450 if isSymbologyEncoding(data) { |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
451 asContentType(req, "application/vnd.ogc.se+xml") |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
452 } else { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
453 asContentType(req, "application/vnd.ogc.sld+xml") |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
454 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
455 resp, err := http.DefaultClient.Do(req) |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
456 if err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
457 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
458 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
459 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
460 if resp.StatusCode != http.StatusOK { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
461 return fmt.Errorf("cannot upload style %s (%s)", |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
462 entry.Name, http.StatusText(resp.StatusCode)) |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
463 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
464 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
465 // Third associate with layer |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
466 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
467 if create { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
468 req, err := http.NewRequest( |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
469 http.MethodPost, |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
470 geoURL+"/rest/layers/"+ |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
471 url.PathEscape(workspaceName+":"+entry.Name)+ |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
472 "/styles?default=true", |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
473 toStream(&styleFilename)) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
474 if err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
475 return err |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
476 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
477 auth(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
478 asJSON(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
479 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
480 resp, err = http.DefaultClient.Do(req) |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
481 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
482 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
483 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
484 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
485 if resp.StatusCode != http.StatusCreated { |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
486 return fmt.Errorf("cannot connect style %s with layer (%s)", |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
487 entry.Name, http.StatusText(resp.StatusCode)) |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
488 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
489 } |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
490 |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
491 return nil |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
492 } |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
493 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
494 // isSymbologyEncoding tries to figure out if its plain SLD or SE. |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
495 func isSymbologyEncoding(data string) bool { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
496 decoder := xml.NewDecoder(strings.NewReader(data)) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
497 for { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
498 tok, err := decoder.Token() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
499 switch { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
500 case tok == nil && err == io.EOF: |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
501 return false |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
502 case err != nil: |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
503 log.Printf("warn: invalid XML: %v\n", err) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
504 return false |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
505 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
506 if t, ok := tok.(xml.StartElement); ok && |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
507 t.Name.Space == "http://www.opengis.net/se" { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
508 return true |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
509 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
510 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
511 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
512 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
513 func ensureStyles() error { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
514 log.Println("info: creating styles") |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
515 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
516 var stls styles |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
517 if err := stls.load(); err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
518 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
519 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
520 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
521 entries := models.InternalServices.Filter( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
522 models.IntAnd( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
523 models.IntWMS, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
524 models.IntWithStyle)) |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
525 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
526 for i := range entries { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
527 entry := &entries[i] |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
528 if stls.hasStyle(entry.Name) { |
1032
4c0c4dd393de
Be more consistent with info/warn/error messages when logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
529 log.Printf("warn: already has style for %s\n", entry.Name) |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
530 continue |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
531 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
532 if err := updateStyle(entry, true); err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
533 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
534 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
535 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
536 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
537 return nil |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
538 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
539 |
1466
d7152eb11d58
Added api doc strings for the geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1446
diff
changeset
|
540 // PrepareGeoServer sets up the GeoServer to work together with the gemma server. |
d7152eb11d58
Added api doc strings for the geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1446
diff
changeset
|
541 // It sets up a workspace, a datastore and exposes the features and styles. |
890
0a563fef64a9
Reconfiguring GeoServer is now queued async.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
878
diff
changeset
|
542 func PrepareGeoServer() error { |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
543 |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
544 if config.DBUser() == "" { |
435
7d2afdc263b5
Don't panic if we have no metamorphic db user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
433
diff
changeset
|
545 log.Println("info: Need metamorphic db user to configure GeoServer") |
432
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
546 return nil |
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
547 } |
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
548 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
549 if config.GeoServerURL() == "" { |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
550 log.Println("info: No URL to GeoServer configured") |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
551 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
552 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
553 |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
554 for _, ensure := range []func() error{ |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
555 deleteWorkspace, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
556 ensureWorkspace, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
557 ensureDataStore, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
558 ensureFeatures, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
559 ensureStyles, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
560 } { |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
561 if err := ensure(); err != nil { |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
562 return err |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
563 } |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
564 } |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
565 |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
566 return nil |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
567 } |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
568 |
1466
d7152eb11d58
Added api doc strings for the geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1446
diff
changeset
|
569 // ReconfigureStyle returns a function to update a style |
d7152eb11d58
Added api doc strings for the geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1446
diff
changeset
|
570 // in the GeoServer to be in sync with the database. |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
571 func ReconfigureStyle(name string) { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
572 Reconfigure(func() error { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
573 var stls styles |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
574 if err := stls.load(); err != nil { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
575 return err |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
576 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
577 |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
578 entries := models.InternalServices.Filter( |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
579 models.IntAnd( |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
580 models.IntWMS, |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
581 models.IntWithStyle, |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
582 models.IntByName(name))) |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
583 |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
584 for i := range entries { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
585 entry := &entries[i] |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
586 create := !stls.hasStyle(entry.Name) |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
587 if err := updateStyle(entry, create); err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
588 return err |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
589 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
590 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
591 |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
592 return nil |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
593 }) |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
594 } |