diff --git a/api/queryService/api.gen.go b/api/queryService/api.gen.go index 9657e0c8..6459c433 100644 --- a/api/queryService/api.gen.go +++ b/api/queryService/api.gen.go @@ -18,21 +18,82 @@ import ( "github.com/oapi-codegen/runtime" ) +// Defines values for ExportStatus. +const ( + Completed ExportStatus = "completed" + Failed ExportStatus = "failed" + InProgress ExportStatus = "in_progress" +) + +// Defines values for FieldFilterCondition. +const ( + ClosedInterval FieldFilterCondition = "closed_interval" + Exclude FieldFilterCondition = "exclude" + GreaterThan FieldFilterCondition = "greater_than" + Include FieldFilterCondition = "include" + LeftClosedInterval FieldFilterCondition = "left_closed_interval" + LessThan FieldFilterCondition = "less_than" + OpenInterval FieldFilterCondition = "open_interval" + RightClosedInterval FieldFilterCondition = "right_closed_interval" +) + // Defines values for QueryType. const ( CONTEXTFULL QueryType = "CONTEXT_FULL" JSONEXTRACTOR QueryType = "JSON_EXTRACTOR" ) +// ExportDetails Payload for export trigger response. +type ExportDetails struct { + // JobId The job id relative to the export. + JobId *string `json:"job_id,omitempty"` + + // OutputLocation The location in which the export zip file will be found. + OutputLocation *string `json:"output_location,omitempty"` + + // Status The possible export job states. + Status ExportStatus `json:"status"` +} + +// ExportStatus The possible export job states. +type ExportStatus string + // ExportTrigger Payload for triggering an export. type ExportTrigger struct { - // ExampleProperty Example property for ExportTrigger. - ExampleProperty *string `json:"example_property,omitempty"` + // FieldFilters Filter the scope based on field output values. + FieldFilters *[]FieldFilter `json:"field_filters,omitempty"` + + // IngestionFilters Filter the scope based on ingestion parameters. + IngestionFilters *struct { + // EndDate The last date of ingestion. + EndDate *string `json:"end_date,omitempty"` + + // StartDate This first date of ingestion. + StartDate *string `json:"start_date,omitempty"` + } `json:"ingestion_filters,omitempty"` + + // JobId The job id of the query results to be exported. + JobId string `json:"job_id"` } +// FieldFilter Filtering a column +type FieldFilter struct { + // Condition The possible field filtering conditions. + Condition FieldFilterCondition `json:"condition"` + + // FieldName The name of the field in question. + FieldName string `json:"field_name"` + + // Values The values useful to the filter. + Values []string `json:"values"` +} + +// FieldFilterCondition The possible field filtering conditions. +type FieldFilterCondition string + // IdMessage defines model for IdMessage. type IdMessage struct { - // Id Unique identifier. + // Id Unique identifier for entity. Id string `json:"id"` } @@ -144,8 +205,11 @@ type TestQueryJSONRequestBody = QueryTestRequest // ServerInterface represents all server handlers. type ServerInterface interface { // Trigger an export - // (POST /exports/trigger) + // (POST /export) TriggerExport(ctx echo.Context) error + // Check export state. + // (GET /export/{id}) + ExportState(ctx echo.Context, id string) error // Create a job collector // (POST /job-collectors) CreateJobCollector(ctx echo.Context) error @@ -189,6 +253,22 @@ func (w *ServerInterfaceWrapper) TriggerExport(ctx echo.Context) error { return err } +// ExportState converts echo context to params. +func (w *ServerInterfaceWrapper) ExportState(ctx echo.Context) error { + var err error + // ------------- Path parameter "id" ------------- + var id string + + err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err)) + } + + // Invoke the callback with all the unmarshaled arguments + err = w.Handler.ExportState(ctx, id) + return err +} + // CreateJobCollector converts echo context to params. func (w *ServerInterfaceWrapper) CreateJobCollector(ctx echo.Context) error { var err error @@ -340,7 +420,8 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL Handler: si, } - router.POST(baseURL+"/exports/trigger", wrapper.TriggerExport) + router.POST(baseURL+"/export", wrapper.TriggerExport) + router.GET(baseURL+"/export/:id", wrapper.ExportState) router.POST(baseURL+"/job-collectors", wrapper.CreateJobCollector) router.GET(baseURL+"/job-collectors/:id", wrapper.GetJobCollectorById) router.PUT(baseURL+"/job-collectors/:id", wrapper.UpdateJobCollector) @@ -356,32 +437,40 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ -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ibk0ft", - "YOVoro8E64+Rfb24UKVgP7hits6+nL44mfLyNWEVNydAG50spsCJTgMTp1UahruxScnr6dQX4i0LBSdZ", - "sMhScnN6P6I6jSJmxqo8sOWbyoCCrbUpd6f2o4MLvTcXJ49y+VeQD566O72uh2rCbB98lEsSVGfgenbd", - "4dq75jwp9jxHfqU8v6uGyb2FTpps5zJh9XxUMl6Nz3N5n3wXfG9sWAP6GhgqAVubfe26S1BXSZY7IlCT", - "+VUbDG8Bq2a82c25ZRjFIkAwmPviG3vLgaKuCSVRmT2Wfs15Q1d0RGMW2abBaRMBo0o2my33voWO6Vnw", - "2Q8QDshEqDNMvPbuAirHY4lkJdOYN2HxFrCJCZOg+VUvMkY0SbGrE2pHKsKOXA3xXwVuLDMUPjRh4GQ0", - "OOEYFKTFK/lEGDgvPWVD0yB66k19mo0mR1HJcSBz/vwQ91Qmrl6+CeuLCrJkGjgxE5EIEQypCgQlWBtw", - "1cXIGUu8qsZT4RdND4anqSyO7mS5Oa8zSfbN+VQEIU+NvVWr+gE93029ttBNPSZKbgUH3l3x7rrb95yn", - "vqqv+1+p77usnLHfF/noTmql0IruziEE36LzChIFQZbrosO7hD/T2YtreY4PoPPiKc9zIWft5r78FJrP", - "w6M9pVkEj7C+VI4OGMt6k/YWLF3tDp/DipT9PvNXtq7uqtD6wPVzKNkNZ0WaakNZm5cZBpth81iFngfM", - "YcdU7G8weFXXVIMaQydJnGTS8g9OBxL4BPOtrLdZX3+DIHUMbreuKrVrU9bZt6tYbq1nwA01PwqRfL35", - "awOkuu0ejpJT68+2yR6SWtg82u3xkUshu4bvBZy5A2rrz/StkjwNioUjmFE/VSGd0Q1iomeTCUvEOPvf", - "z3Ego8n2BTXpy7Q15d3kgNNEQWhrDGVlVs3gUrNxPxompfYkqQjzPUmGyswWoaWw+jZtf7//PwAA///0", - "wy/PGCEAAA==", + "H4sIAAAAAAAC/9RaUW/bOBL+KwTvHn12ut0nv3WTtHDR2/RS97DAojBocmQzS5MKSbn1Bv7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9k4D6Knk6Evyvb0uZqI", + "ASAL9nwX90Rd90m+Ec1hVfwpyH+MoZpb0Jx0ARcPx54xxWM1iQx/07ZgeJjiT0l9wQq9fm+Q/NzhvnZC", + "FRq/q5H1A2p+uPn4RHf5mGu15QxYf8aH7WHm9zz5FU94XlLdD1F5xnpfx6M/qFGi1dWdgesxu7qvINdA", + "y1jXFT4E/Ehlr7dVMT6DzutxDquEPGs1T8Wn1vw8PHoiNWvnIXIqlKMz2rKTQXsHnq525/dhdch+nv6r", + "/GTRl6HNhuvHUHJozuowNZqyLi8TS9fD+rGIngf0YY/J2J+g8YpHlYMKQy9JPEmnlW6cziTwia0m88li", + "ff0NaBEY3E/edeFH56S3bjf/UqU1q4PQ1HwvRKoR98sGSPzFYzhKnlp/+UUhQVJzH0f/BeFxkPOCTgPO", + "7QG9TUf6o1asoPXQGVyrX2iBp3htbW6mkwnJ+bj8Aj6majPZvsIufKW2trybCnAm/H0gMAecQ69awqVx", + "xv1omJTGlSQSlrqSDJUZhmqRsOY0bf9l/08AAAD//yOojal5KQAA", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/api/queryService/export.go b/api/queryService/export.go index 60af915c..e915f938 100644 --- a/api/queryService/export.go +++ b/api/queryService/export.go @@ -9,3 +9,7 @@ import ( func (s *Controllers) TriggerExport(ctx echo.Context) error { return ctx.JSON(http.StatusOK, map[string]string{"status": "export triggered"}) } + +func (s *Controllers) ExportState(ctx echo.Context, id string) error { + return ctx.JSON(http.StatusOK, map[string]string{"status": "export triggered"}) +} diff --git a/api/queryService/export_test.go b/api/queryService/export_test.go index 29dbd7d1..ed5bbddc 100644 --- a/api/queryService/export_test.go +++ b/api/queryService/export_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/go-playground/validator/v10" + "github.com/google/uuid" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" ) @@ -25,3 +26,19 @@ func TestTriggerExport(t *testing.T) { assert.Equal(t, http.StatusOK, rec.Code) assert.NotEmpty(t, rec.Body.String()) } + +func TestExportState(t *testing.T) { + e := echo.New() + req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader("")) + rec := httptest.NewRecorder() + ctx := e.NewContext(req, rec) + + cons := queryservice.NewControllers(validator.New(), &queryservice.Services{}) + + id := uuid.NewString() + + err := cons.ExportState(ctx, id) + assert.Nil(t, err) + assert.Equal(t, http.StatusOK, rec.Code) + assert.NotEmpty(t, rec.Body.String()) +} diff --git a/go.mod b/go.mod index e5bd72d4..c2ae8e9e 100644 --- a/go.mod +++ b/go.mod @@ -132,5 +132,5 @@ require ( golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect + gopkg.in/yaml.v3 v3.0.1 ) diff --git a/pkg/queryService/api.gen.go b/pkg/queryService/api.gen.go index 4cce23e7..84558802 100644 --- a/pkg/queryService/api.gen.go +++ b/pkg/queryService/api.gen.go @@ -16,21 +16,82 @@ import ( "github.com/oapi-codegen/runtime" ) +// Defines values for ExportStatus. +const ( + Completed ExportStatus = "completed" + Failed ExportStatus = "failed" + InProgress ExportStatus = "in_progress" +) + +// Defines values for FieldFilterCondition. +const ( + ClosedInterval FieldFilterCondition = "closed_interval" + Exclude FieldFilterCondition = "exclude" + GreaterThan FieldFilterCondition = "greater_than" + Include FieldFilterCondition = "include" + LeftClosedInterval FieldFilterCondition = "left_closed_interval" + LessThan FieldFilterCondition = "less_than" + OpenInterval FieldFilterCondition = "open_interval" + RightClosedInterval FieldFilterCondition = "right_closed_interval" +) + // Defines values for QueryType. const ( CONTEXTFULL QueryType = "CONTEXT_FULL" JSONEXTRACTOR QueryType = "JSON_EXTRACTOR" ) +// ExportDetails Payload for export trigger response. +type ExportDetails struct { + // JobId The job id relative to the export. + JobId *string `json:"job_id,omitempty"` + + // OutputLocation The location in which the export zip file will be found. + OutputLocation *string `json:"output_location,omitempty"` + + // Status The possible export job states. + Status ExportStatus `json:"status"` +} + +// ExportStatus The possible export job states. +type ExportStatus string + // ExportTrigger Payload for triggering an export. type ExportTrigger struct { - // ExampleProperty Example property for ExportTrigger. - ExampleProperty *string `json:"example_property,omitempty"` + // FieldFilters Filter the scope based on field output values. + FieldFilters *[]FieldFilter `json:"field_filters,omitempty"` + + // IngestionFilters Filter the scope based on ingestion parameters. + IngestionFilters *struct { + // EndDate The last date of ingestion. + EndDate *string `json:"end_date,omitempty"` + + // StartDate This first date of ingestion. + StartDate *string `json:"start_date,omitempty"` + } `json:"ingestion_filters,omitempty"` + + // JobId The job id of the query results to be exported. + JobId string `json:"job_id"` } +// FieldFilter Filtering a column +type FieldFilter struct { + // Condition The possible field filtering conditions. + Condition FieldFilterCondition `json:"condition"` + + // FieldName The name of the field in question. + FieldName string `json:"field_name"` + + // Values The values useful to the filter. + Values []string `json:"values"` +} + +// FieldFilterCondition The possible field filtering conditions. +type FieldFilterCondition string + // IdMessage defines model for IdMessage. type IdMessage struct { - // Id Unique identifier. + // Id Unique identifier for entity. Id string `json:"id"` } @@ -217,6 +278,9 @@ type ClientInterface interface { TriggerExport(ctx context.Context, body TriggerExportJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // ExportState request + ExportState(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) + // CreateJobCollectorWithBody request with any body CreateJobCollectorWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -279,6 +343,18 @@ func (c *Client) TriggerExport(ctx context.Context, body TriggerExportJSONReques return c.Client.Do(req) } +func (c *Client) ExportState(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewExportStateRequest(c.Server, id) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) CreateJobCollectorWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewCreateJobCollectorRequestWithBody(c.Server, contentType, body) if err != nil { @@ -467,7 +543,7 @@ func NewTriggerExportRequestWithBody(server string, contentType string, body io. return nil, err } - operationPath := fmt.Sprintf("/exports/trigger") + operationPath := fmt.Sprintf("/export") if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -487,6 +563,40 @@ func NewTriggerExportRequestWithBody(server string, contentType string, body io. return req, nil } +// NewExportStateRequest generates requests for ExportState +func NewExportStateRequest(server string, id string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/export/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + // NewCreateJobCollectorRequest calls the generic CreateJobCollector builder with application/json body func NewCreateJobCollectorRequest(server string, body CreateJobCollectorJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader @@ -885,6 +995,9 @@ type ClientWithResponsesInterface interface { TriggerExportWithResponse(ctx context.Context, body TriggerExportJSONRequestBody, reqEditors ...RequestEditorFn) (*TriggerExportResponse, error) + // ExportStateWithResponse request + ExportStateWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*ExportStateResponse, error) + // CreateJobCollectorWithBodyWithResponse request with any body CreateJobCollectorWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateJobCollectorResponse, error) @@ -945,6 +1058,28 @@ func (r TriggerExportResponse) StatusCode() int { return 0 } +type ExportStateResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *ExportDetails +} + +// Status returns HTTPResponse.Status +func (r ExportStateResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ExportStateResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type CreateJobCollectorResponse struct { Body []byte HTTPResponse *http.Response @@ -1157,6 +1292,15 @@ func (c *ClientWithResponses) TriggerExportWithResponse(ctx context.Context, bod return ParseTriggerExportResponse(rsp) } +// ExportStateWithResponse request returning *ExportStateResponse +func (c *ClientWithResponses) ExportStateWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*ExportStateResponse, error) { + rsp, err := c.ExportState(ctx, id, reqEditors...) + if err != nil { + return nil, err + } + return ParseExportStateResponse(rsp) +} + // CreateJobCollectorWithBodyWithResponse request with arbitrary body returning *CreateJobCollectorResponse func (c *ClientWithResponses) CreateJobCollectorWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateJobCollectorResponse, error) { rsp, err := c.CreateJobCollectorWithBody(ctx, contentType, body, reqEditors...) @@ -1304,6 +1448,32 @@ func ParseTriggerExportResponse(rsp *http.Response) (*TriggerExportResponse, err return response, nil } +// ParseExportStateResponse parses an HTTP response from a ExportStateWithResponse call +func ParseExportStateResponse(rsp *http.Response) (*ExportStateResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ExportStateResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest ExportDetails + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + // ParseCreateJobCollectorResponse parses an HTTP response from a CreateJobCollectorWithResponse call func ParseCreateJobCollectorResponse(rsp *http.Response) (*CreateJobCollectorResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/scripts/Taskfile.yml b/scripts/Taskfile.yml index 74e42300..711dfb00 100644 --- a/scripts/Taskfile.yml +++ b/scripts/Taskfile.yml @@ -33,6 +33,7 @@ tasks: - touch .env fullsuite: cmds: + - task generate - task lint - task test:unit:coverage - task test:integration diff --git a/serviceAPIs/queryService.yaml b/serviceAPIs/queryService.yaml index 5bcf5b76..06a22387 100644 --- a/serviceAPIs/queryService.yaml +++ b/serviceAPIs/queryService.yaml @@ -229,7 +229,7 @@ paths: '404': description: Job collector not found. - /exports/trigger: + /export: post: operationId: triggerExport tags: @@ -251,6 +251,32 @@ paths: $ref: '#/components/schemas/IdMessage' '400': description: Invalid request body. + '404': + description: Job not found. + + /export/{id}: + get: + operationId: exportState + tags: + - ExportService + summary: Check export state. + description: Checks the current state of an export. + parameters: + - in: path + name: id + required: true + schema: + type: string + description: The ID of the export. + responses: + '200': + description: Export has been completed. + content: + application/json: + schema: + $ref: '#/components/schemas/ExportDetails' + '404': + description: Export job not found. components: @@ -366,7 +392,7 @@ components: properties: id: type: string - description: Unique identifier. + description: Unique identifier for entity. required: - id @@ -397,7 +423,81 @@ components: ExportTrigger: type: object properties: - example_property: + job_id: type: string - description: Example property for ExportTrigger. + description: The job id of the query results to be exported. + ingestion_filters: + type: object + description: Filter the scope based on ingestion parameters. + properties: + start_date: + type: string + description: This first date of ingestion. + end_date: + type: string + description: The last date of ingestion. + field_filters: + type: array + description: Filter the scope based on field output values. + items: + $ref: '#/components/schemas/FieldFilter' description: Payload for triggering an export. + required: + - job_id + + FieldFilter: + type: object + properties: + field_name: + type: string + description: The name of the field in question. + condition: + $ref: "#/components/schemas/FieldFilterCondition" + values: + type: array + description: The values useful to the filter. + items: + type: string + description: Filtering a column + required: + - field_name + - condition + - values + + FieldFilterCondition: + type: string + enum: + - less_than + - greater_than + - closed_interval + - open_interval + - left_closed_interval + - right_closed_interval + - include + - exclude + description: The possible field filtering conditions. + + ExportStatus: + type: string + enum: + - completed + - in_progress + - failed + description: The possible export job states. + + ExportDetails: + type: object + properties: + job_id: + type: string + description: The job id relative to the export. + status: + $ref: '#/components/schemas/ExportStatus' + output_location: + type: string + description: The location in which the export zip file will be found. + example: s3://{bucket}/{clientid}/{jobid}/{timestamp}_{exportid}.zip + description: Payload for export trigger response. + required: + - id + - status