Skip to content

Commit d7778d4

Browse files
review addressed
1 parent ca283c8 commit d7778d4

File tree

6 files changed

+20
-43
lines changed

6 files changed

+20
-43
lines changed

tests/acceptance/bootstrap/OcisConfigContext.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,20 @@ public function theConfigHasBeenSetToValue(TableNode $table): void {
192192
}
193193

194194
/**
195-
* @Given the ocis server has served service :service separately
195+
* @Given the ocis server has started service :service separately
196196
*
197197
* @param string $service
198198
*
199199
* @return void
200200
* @throws GuzzleException
201201
*/
202-
public function theOcisServerHasExcludedService(string $service) {
202+
public function theOcisServerHasStartedServiceSeparately(string $service) {
203203
$response = OcisConfigHelper::startService($service);
204204

205205
Assert::assertEquals(
206206
200,
207207
$response->getStatusCode(),
208-
"Failed to set config"
208+
"Failed to start service $service."
209209
);
210210
}
211211

tests/acceptance/features/apiServiceAvailability/serviceAvailabilityCheck.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Feature: service health check
134134

135135
@env-config
136136
Scenario: check services health while running separately
137-
Given the ocis server has served service "storage-users" separately
137+
Given the ocis server has started service "storage-users" separately
138138
When a user requests these URLs with "GET" and no authentication
139139
| endpoint | service |
140140
| http://%base_url_hostname%:9159/healthz | storage-users |

tests/ociswrapper/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Also, see `./bin/ociswrapper help` for more information.
125125
- `200 OK` - oCIS server is stopped
126126
- `500 Internal Server Error` - Unable to stop oCIS server
127127

128-
6. `POST /services/<service-name>`
128+
6. `POST /services/{service-name}`
129129

130130
Restart oCIS with service excluded and start excluded oCIS service individually, not covered by the oCIS supervisor.
131131

@@ -143,7 +143,7 @@ Also, see `./bin/ociswrapper help` for more information.
143143
- `200 OK` - oCIS server is stopped
144144
- `500 Internal Server Error` - Unable to stop oCIS server
145145

146-
7. `DELETE /services/<service-name>`
146+
7. `DELETE /services/{service-name}`
147147

148148
Stop individually running oCIS service
149149

tests/ociswrapper/ocis/ocis.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var EnvConfigs = []string{}
2929
var runningServices = make(map[string]int)
3030

3131
func Start(envMap []string) {
32+
log.Println("Starting oCIS service........\n")
3233
StartService("", envMap)
3334
}
3435

@@ -37,7 +38,7 @@ func Stop() (bool, string) {
3738
stopSignal = true
3839

3940
for service := range runningServices {
40-
StopService(service)
41+
go StopService(service)
4142
}
4243

4344
success, message := waitUntilCompleteShutdown()
@@ -188,14 +189,7 @@ func RunCommand(command string, inputs []string) (int, string) {
188189
return c.ProcessState.ExitCode(), cmdOutput
189190
}
190191

191-
func RunOcisService(service string, envMap []string) {
192-
log.Println(fmt.Sprintf("Environment variable envMap: %s\n", envMap))
193-
StartService(service, envMap)
194-
}
195-
196-
// startService is a common function for starting a service (ocis or other)
197192
func StartService(service string, envMap []string) {
198-
log.Println(fmt.Sprintf("Start service: %s with Environment variable envMap: %s\n", service, envMap))
199193
// Initialize command args based on service presence
200194
cmdArgs := []string{"server"} // Default command args
201195

@@ -244,8 +238,8 @@ func StartService(service string, envMap []string) {
244238
runningServices[service] = cmd.Process.Pid
245239
}
246240

247-
for listservice, pid := range runningServices {
248-
log.Println(fmt.Sprintf("Service started: %s with process and id: %v\n", listservice, pid))
241+
for listService, pid := range runningServices {
242+
log.Println(fmt.Sprintf("%s service started with process id %v\n", listService, pid))
249243
}
250244

251245
// Read the logs when the 'ocis server' command is running
@@ -303,7 +297,7 @@ func StartService(service string, envMap []string) {
303297
func StopService(service string) (bool, string) {
304298
pid, exists := runningServices[service]
305299
if !exists {
306-
return false, fmt.Sprintf("Service %s is not running", service)
300+
return false, fmt.Sprintf("Running service doesn't not include %s service", service)
307301
}
308302

309303
process, err := os.FindProcess(pid)

tests/ociswrapper/wrapper/handlers/handler.go

+8-25
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net/http"
1010
"ociswrapper/common"
1111
"ociswrapper/ocis"
12-
"strings"
1312
)
1413

1514
type BasicResponse struct {
@@ -206,29 +205,15 @@ func CommandHandler(res http.ResponseWriter, req *http.Request) {
206205
}
207206

208207
func OcisServiceHandler(res http.ResponseWriter, req *http.Request) {
209-
if req.Method != http.MethodPost && req.Method != http.MethodDelete {
210-
sendResponse(res, http.StatusMethodNotAllowed, "Method not allowed")
211-
return
212-
}
213-
214-
serviceName := strings.TrimPrefix(req.URL.Path, "/services/")
215-
216-
if serviceName == "" {
217-
sendResponse(res, http.StatusUnprocessableEntity, "Service name not specified")
218-
return
219-
}
220-
208+
serviceName := req.PathValue("service")
221209
envMap := []string{fmt.Sprintf("OCIS_EXCLUDE_RUN_SERVICES=%s", serviceName)}
222210

223211
if req.Method == http.MethodPost {
224212
// restart oCIS without service that need to start separately
225213
success, _ := ocis.Restart(envMap)
226214
if success {
227-
// Clear `EnvConfigs` to prevent persistence of temporary changes
228-
log.Println(fmt.Sprintf("Environment Config when service Post request has been hit: %s\n", ocis.EnvConfigs))
229-
230215
var envBody map[string]interface{}
231-
var envMap []string
216+
var serviceEnvMap []string
232217

233218
if req.Body != nil && req.ContentLength > 0 {
234219
var err error
@@ -240,29 +225,27 @@ func OcisServiceHandler(res http.ResponseWriter, req *http.Request) {
240225
}
241226

242227
for key, value := range envBody {
243-
envMap = append(envMap, fmt.Sprintf("%s=%v", key, value))
228+
serviceEnvMap = append(serviceEnvMap, fmt.Sprintf("%s=%v", key, value))
244229
}
245230

246-
log.Println(fmt.Sprintf("serviceName to start: %s\n", serviceName))
231+
log.Println(fmt.Sprintf("Starting oCIS service %s......", serviceName))
247232

248-
go ocis.RunOcisService(serviceName, envMap)
233+
go ocis.StartService(serviceName, serviceEnvMap)
249234
success, _ := ocis.WaitForConnection()
250235
if success {
251236
sendResponse(res, http.StatusOK, fmt.Sprintf("oCIS service %s started successfully", serviceName))
252237
return
253238
}
254239
}
255-
256240
sendResponse(res, http.StatusInternalServerError, fmt.Sprintf("Failed to restart oCIS without service %s", serviceName))
257-
}
258-
259-
if req.Method == http.MethodDelete {
241+
} else if req.Method == http.MethodDelete {
260242
success, message := ocis.StopService(serviceName)
261243
if success {
262244
sendResponse(res, http.StatusOK, fmt.Sprintf("oCIS service %s stopped successfully", serviceName))
263245
} else {
264246
sendResponse(res, http.StatusInternalServerError, message)
265247
}
248+
} else {
249+
sendResponse(res, http.StatusMethodNotAllowed, "Invalid method requested")
266250
}
267-
268251
}

tests/ociswrapper/wrapper/wrapper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Start(port string) {
2727
mux.HandleFunc("/command", handlers.CommandHandler)
2828
mux.HandleFunc("/stop", handlers.StopOcisHandler)
2929
mux.HandleFunc("/start", handlers.StartOcisHandler)
30-
mux.HandleFunc("/services/", handlers.OcisServiceHandler)
30+
mux.HandleFunc("/services/{service}", handlers.OcisServiceHandler)
3131

3232
httpServer.Handler = mux
3333

0 commit comments

Comments
 (0)