Skip to content

Commit 7751e0c

Browse files
committed
MINOR: process manager for programs handling
1 parent cc21335 commit 7751e0c

37 files changed

+4852
-6
lines changed

configure_data_plane.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,13 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler {
568568
api.CacheGetCachesHandler = &handlers.GetCachesHandlerImpl{Client: client}
569569
api.CacheReplaceCacheHandler = &handlers.ReplaceCacheHandlerImpl{Client: client, ReloadAgent: ra}
570570

571+
// setup program handlers
572+
api.ProcessManagerCreateProgramHandler = &handlers.CreateProgramHandlerImpl{Client: client, ReloadAgent: ra}
573+
api.ProcessManagerDeleteProgramHandler = &handlers.DeleteProgramHandlerImpl{Client: client, ReloadAgent: ra}
574+
api.ProcessManagerGetProgramHandler = &handlers.GetProgramHandlerImpl{Client: client}
575+
api.ProcessManagerGetProgramsHandler = &handlers.GetProgramsHandlerImpl{Client: client}
576+
api.ProcessManagerReplaceProgramHandler = &handlers.ReplaceProgramHandlerImpl{Client: client, ReloadAgent: ra}
577+
571578
// setup fcgi handlers
572579
api.FCGIAppCreateFCGIAppHandler = &handlers.CreateFCGIAppHandlerImpl{Client: client, ReloadAgent: ra}
573580
api.FCGIAppDeleteFCGIAppHandler = &handlers.DeleteFCGIAppHandlerImpl{Client: client, ReloadAgent: ra}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2022 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "process-manager: Create one new program" {
27+
resource_post "$_PROGRAMS_BASE_PATH" "data/program.json" "force_reload=true"
28+
assert_equal "$SC" 201
29+
30+
resource_get "$_PROGRAMS_BASE_PATH/mirror"
31+
assert_equal "$SC" 200
32+
assert_equal "mirror" "$(get_json_path "$BODY" ".data.name")"
33+
assert_equal "nobody" "$(get_json_path "$BODY" ".data.user")"
34+
assert_equal "nobody" "$(get_json_path "$BODY" ".data.group")"
35+
}
36+
37+
@test "process-manager: Fail creating program with same name" {
38+
resource_post "$_PROGRAMS_BASE_PATH" "data/program_duplicated.json" "force_reload=true"
39+
assert_equal "$SC" 409
40+
}
41+
42+
@test "process-manager: Fail creating program that isn't valid" {
43+
resource_post "$_PROGRAMS_BASE_PATH" "data/program_invalid.json" "force_reload=true"
44+
assert_equal "$SC" 422
45+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# _version=42
2+
3+
global
4+
log 127.0.0.1 local2
5+
chroot /var/lib/haproxy
6+
pidfile /var/run/haproxy.pid
7+
maxconn 4000
8+
user haproxy
9+
group haproxy
10+
stats socket /var/lib/haproxy/stats level admin
11+
12+
defaults
13+
mode http
14+
log global
15+
option httplog
16+
option dontlognull
17+
option http-server-close
18+
option forwardfor except 127.0.0.0/8
19+
option redispatch
20+
retries 3
21+
timeout http-request 10s
22+
timeout queue 1m
23+
timeout connect 10s
24+
timeout client 1m
25+
timeout server 1m
26+
timeout http-keep-alive 10s
27+
timeout check 10s
28+
maxconn 3000
29+
30+
program echo
31+
command echo "Hello, World!"
32+
33+
program dataplaneapi
34+
command /usr/local/bin/dataplaneapi --host 0.0.0.0 --port 5555 --haproxy-bin /opt/hapee-2.5/sbin/hapee-lb --config-file /etc/hapee-2.5/hapee-lb.cfg --reload-cmd "systemctl reload hapee-2.5" --reload-delay 5 --userlist haproxy-dataplaneapi
35+
no option start-on-reload
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "mirror",
3+
"command": "spoa-mirror --runtime 0 --mirror-url http://test.local",
4+
"user": "nobody",
5+
"group": "nobody"
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "dataplaneapi",
3+
"command": "/usr/local/bin/dataplaneapi -f /path/to/file.cfg",
4+
"start-on-reload": "disabled",
5+
"user": "nobody",
6+
"group": "nobody"
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "program_created",
3+
"user": "haproxy",
4+
"group": "group"
5+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2022 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "process-manager: Delete one program by name" {
27+
resource_delete "$_PROGRAMS_BASE_PATH/echo" "force_reload=true"
28+
assert_equal "$SC" 204
29+
30+
resource_get "$_PROGRAMS_BASE_PATH/echo"
31+
assert_equal "$SC" 404
32+
}
33+
34+
@test "process-manager: Fail deleting app that doesn't exist" {
35+
resource_delete "$_PROGRAMS_BASE_PATH/i_am_not_here" "force_reload=true"
36+
assert_equal "$SC" 404
37+
}

e2e/tests/process_manager/get.bats

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2022 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "process-manager: Return one program by name" {
27+
resource_get "$_PROGRAMS_BASE_PATH/dataplaneapi"
28+
assert_equal "$SC" 200
29+
assert_equal "dataplaneapi" "$(get_json_path "$BODY" ".data.name")"
30+
}
31+
32+
@test "process-manager: Fail returning program that doesn't exist" {
33+
resource_get "$_PROGRAMS_BASE_PATH/i_am_not_here"
34+
assert_equal "$SC" 404
35+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2022 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "process-manager: Return an array of programs" {
27+
resource_get "$_PROGRAMS_BASE_PATH"
28+
assert_equal "$SC" 200
29+
assert_equal 2 "$(get_json_path "$BODY" ".data | length")"
30+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2022 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "process-manager: Replace one program" {
27+
resource_put "$_PROGRAMS_BASE_PATH/dataplaneapi" "data/program_duplicated.json" "force_reload=true"
28+
assert_equal "$SC" 200
29+
30+
resource_get "$_PROGRAMS_BASE_PATH/dataplaneapi"
31+
assert_equal "$SC" 200
32+
assert_equal "dataplaneapi" "$(get_json_path "$BODY" ".data.name")"
33+
assert_equal "/usr/local/bin/dataplaneapi -f /path/to/file.cfg" "$(get_json_path "$BODY" ".data.command")"
34+
}
35+
36+
@test "process-manager: Fail replacing program that doesn't exist" {
37+
resource_put "$_PROGRAMS_BASE_PATH/i_am_not_here" "data/program_duplicated.json" "force_reload=true"
38+
assert_equal "$SC" 409
39+
}

0 commit comments

Comments
 (0)