diff --git a/api/openapi.yaml b/api/openapi.yaml index a0b6dc8..81cde65 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -159,6 +159,7 @@ paths: tags: - other summary: Get the health status. + security: [] description: Retrieve information about the status of openEm components. operationId: OtherController_getHealth responses: @@ -467,15 +468,17 @@ components: OtherHealthResponse: type: object properties: - ingestorStatus: + status: type: string description: Status of the ingestor. - scicatStatus: - type: string - description: Status of SciCat. - globusStatus: - type: string - description: Status of Globus. + errors: + type: object + additionalProperties: + type: string + required: + - status + - scicatStatus + - globusStatus GetExtractorResponse: type: object properties: diff --git a/cmd/openem-ingestor-service/main.go b/cmd/openem-ingestor-service/main.go index 9808f88..bd3923b 100644 --- a/cmd/openem-ingestor-service/main.go +++ b/cmd/openem-ingestor-service/main.go @@ -30,6 +30,11 @@ func main() { ctx := context.Background() + // setup globus if we have a refresh token + if config.Transfer.Globus.RefreshToken != "" { + core.GlobusLoginWithRefreshToken(config.Transfer.Globus) + } + tq := core.TaskQueue{ Config: config, AppContext: ctx, diff --git a/internal/core/globus.go b/internal/core/globus.go index 24022c1..a08fba8 100644 --- a/internal/core/globus.go +++ b/internal/core/globus.go @@ -67,6 +67,12 @@ func GlobusIsClientReady() bool { return globusClient.IsClientSet() } +/*func GlobusHealthCheck() error { + // NOTE: this is not a proper health check and takes a long time to finish (~900ms) + _, err := globusClient.TransferGetTaskList(0, 1) + return err +}*/ + func GlobusSetHttpClient(client *http.Client) { globusClient = globus.HttpClientToGlobusClient(client) } @@ -99,14 +105,6 @@ func globusCheckTransfer(globusTaskId string) (bytesTransferred int, filesTransf } func GlobusTransfer(globusConf task.GlobusTransferConfig, task task.IngestionTask, taskCtx context.Context, localTaskId uuid.UUID, datasetFolder string, fileList []datasetIngestor.Datafile, notifier ProgressNotifier) error { - // check if globus client is properly set up, use refresh token if available - if !globusClient.IsClientSet() { - if globusConf.RefreshToken == "" { - return fmt.Errorf("globus: not logged into globus") - } - GlobusLoginWithRefreshToken(globusConf) - } - // transfer given filelist var filePathList []string var fileIsSymlinkList []bool diff --git a/internal/core/scicathealth.go b/internal/core/scicathealth.go new file mode 100644 index 0000000..efdb633 --- /dev/null +++ b/internal/core/scicathealth.go @@ -0,0 +1,26 @@ +package core + +import ( + "errors" + "fmt" + "net/http" +) + +func ScicatHealthTest(APIServer string) error { + // note: there's no function to use the /health endpoint in scicat-cli + // so here's a function that uses it. + resp, err := http.DefaultClient.Get(APIServer + "/health") + if err != nil { + return err + } + defer resp.Body.Close() + + if resp.StatusCode == 503 { + return errors.New("health check failed") + } + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("unexpected status code: %d %s", resp.StatusCode, resp.Status) + } + + return nil +} diff --git a/internal/webserver/api.gen.go b/internal/webserver/api.gen.go index 2260f7d..2da6b0c 100644 --- a/internal/webserver/api.gen.go +++ b/internal/webserver/api.gen.go @@ -88,14 +88,10 @@ type MethodItem struct { // OtherHealthResponse defines model for OtherHealthResponse. type OtherHealthResponse struct { - // GlobusStatus Status of Globus. - GlobusStatus *string `json:"globusStatus,omitempty"` + Errors *map[string]string `json:"errors,omitempty"` - // IngestorStatus Status of the ingestor. - IngestorStatus *string `json:"ingestorStatus,omitempty"` - - // ScicatStatus Status of SciCat. - ScicatStatus *string `json:"scicatStatus,omitempty"` + // Status Status of the ingestor. + Status string `json:"status"` } // OtherVersionResponse defines model for OtherVersionResponse. @@ -346,8 +342,6 @@ func (siw *ServerInterfaceWrapper) ExtractorControllerGetExtractorMethods(c *gin // OtherControllerGetHealth operation middleware func (siw *ServerInterfaceWrapper) OtherControllerGetHealth(c *gin.Context) { - c.Set(CookieAuthScopes, []string{"ingestor_read", "ingestor_write", "admin"}) - for _, middleware := range siw.HandlerMiddlewares { middleware(c) if c.IsAborted() { @@ -1190,52 +1184,52 @@ func (sh *strictHandler) OtherControllerGetVersion(ctx *gin.Context) { // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xaW2/byBX+KwdsgSQALbu72z7ozfU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saBJgdVWlczybLSKcATqMRF9/alGzdEzEbeCTBOObhS5fDNL0jag", - "k79NLiYX5DlVoWQVT6bJ95OLyfdEyswWzh/nGROClHWkiC5KCQ/OfuRpynBXcQ09qFmJ1mWh97ueeK40", - "FEzmgsul05vVtlCa/+a9QeUmpXfkK8xhoVXpFr2e/XgFlVYrnjvHO1CQupsWE6FSbcPc6hoPJo1d2RrB", - "HUyubt8+pzMtZqGeHzuVXPBlx97TYk8rzrzfX3w3BKxTONodTJ1laMyiFkmaFMjykOGF8iAePq8x55pi", - "7JAkFC8/XFz4mJMWpXOtxc/2vBKMy7aBG306PSjzgnFB9VqNRD9crpjgufev0uDNtk2Tvz/c+TNpUUsm", - "4Bb1CjX4nqhLMsn0/X2amLosmd7sSkxRw5aE2YQwidIGikjuaY/zQNydINjlGKs5rtABdqFEjqSmrjNb", - "a4y8zVaMCzYX2Gta+tEUcs+VklYrIVC3DdYwusYwWVGn1nV8X9A3xBWhpCSgV2zJJYtV70LpklniWC7t", - "aD+w/9Bb/tuhg18Ny1io0AmAJx29GzrfDcDDqkoEt53/atQOhA4VwiNd7AjGwpJORIoN6OD5fJI8bETN", - "QtToUB45LDfofYH2AKYiliNs77dpUikzAtwrjcwisPg4oMASpaWGNOQPl2wo18UKhmK6rTSP4NdnnxbC", - "QZ1/qnzzYO4bKSa3/aqPeHn7iAAaKxsPIKitDTvs/hXg01Jhv9J63zQrv6w1t5jcb3tc6Z0IDCSuI1JG", - "YUZciXF8chpbtggejEkOTUiG0GvGNj3ybK7eNMOL/7Poo7HocHQ2As3LXY8rbVoepZCI7HoyajWyfBe0", - "RJGHwNUBcAtZD+HCTQeO45caDjK4q8nnqvac3HZrVFhfl9Daaoha14X3EOtHE8kjOmpsAjLiJ78iqtNz", - "UMdD3yDpFV3BuvlOkWLBh0It/fGjLpxJbrlr1poWo9+MLIRaD731Au1Lt+8pdfzbUIdTvuw1MY4zmK27", - "debD1vbH6l4RlDhY9Aq1VLU91Pi99CtOMYZf6rGDOe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wtywkmUxs7euTtjL6BuZjfXDXd3dCD1BplvcrQU", - "y3HBamEfLInHae8g//0s8XPl3/l3arSmKlui7b1HbMZgbt157LG9TQRaHFbB8XVZ28L1vzB6pLJl/IOq", - "rzz12vMt1Ygf4hrImMxQfIMm8o+Ovq6cwAEZzdSlU743l+636ZFxAYuDIsyboqGd47iyOWYMWHBhkTQc", - "NqFDyHW+MjltvtV5V3vkLdmDT8e+4jTsa0+/TomEF2ihiYZvPlr5E6O1AYAn8DqCtw5NYQszaN+vWgVK", - "ig0Q+SqJ7nOhyXhAEQl3PkA5PkzOaq0pGa72f5xybPwWvmt59Pnb7pc3oy4LrXtU538BKPdjEznXaPAd", - "cccGc18CunSXmtOE5SWXHo1h68HL8+he021nOp9+BnppEn16+g4t1odMevJGI+1+u1s7iB5u97zWZEVQ", - "7bbErkuUqJnozqLb/bzdt/fb/wYAAP//5iRKWZwtAAA=", + "H4sIAAAAAAAC/+xaW2/cxhX+KwdsAdsAtXKTtA96cxXFWTRODCspUFhCMss5u5x4OEPPDHe9Cfa/F2cu", + "vCy5F7WSm4c+CNCSw5lz+c53LuTvWaGrWitUzmZXv2e2KLFi/t+vUaLDHw1TdonmHX5s0Dq6URtdo3EC", + "/TKhVmjdnNP/HG1hRO2EVtlVNvd3hFYgODgNbKGNA1ciiHQnyzO3rTG7yqwzQq2y3a69ohe/YuGyXT6S", + "xNZaWXxyUfLMOuYaO97ue9xAuAd6Odxmdp5KN8ZoM9ag0NzrNZKkQmvZaureLs8MfmyEQZ5dvQ87dOvv", + "J85+je5r5phFd9iUPCwIZnVY2Ump4gVmDNv639oxOTbXj3QZVFMt0JDB0uY9WwnlcIVmpE4rR9r8gEI3", + "n5xhhdNH0FGhKzWf8OZ3wrrkxwodozMBw4YEmfAgKFahhUKrpVg1BjkI1XO9NlneWerPBpfZVfanyy66", + "LmNoXb7x280dVv+FCZMyJw3YW3jMfm+i3gfDfCkkvmWunBCtRKC7UDNXJjtalFg45N7XYLDQhs+mQizI", + "9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AA//8/6heolC0AAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/internal/webserver/other.go b/internal/webserver/other.go index a952092..e76b057 100644 --- a/internal/webserver/other.go +++ b/internal/webserver/other.go @@ -1,6 +1,10 @@ package webserver -import "context" +import ( + "context" + + "github.com/SwissOpenEM/Ingestor/internal/core" +) func (i *IngestorWebServerImplemenation) OtherControllerGetVersion(ctx context.Context, request OtherControllerGetVersionRequestObject) (OtherControllerGetVersionResponseObject, error) { return OtherControllerGetVersion200JSONResponse{ @@ -9,5 +13,26 @@ func (i *IngestorWebServerImplemenation) OtherControllerGetVersion(ctx context.C } func (i *IngestorWebServerImplemenation) OtherControllerGetHealth(ctx context.Context, request OtherControllerGetHealthRequestObject) (OtherControllerGetHealthResponseObject, error) { - return nil, nil + errors := map[string]string{} + + err := core.ScicatHealthTest(i.taskQueue.Config.Scicat.Host) + if err != nil { + errors["scicat"] = err.Error() + } + + /*err = core.GlobusHealthCheck() + if err != nil { + errors["globus"] = err.Error() + }*/ + + if len(errors) > 0 { + return OtherControllerGetHealth200JSONResponse{ + Status: "error", + Errors: &errors, + }, nil + } else { + return OtherControllerGetHealth200JSONResponse{ + Status: "ok", + }, nil + } }