Skip to content

Commit

Permalink
Add point in time api (#253)
Browse files Browse the repository at this point in the history
* Add point in time api

Signed-off-by: Jakob Hahn <[email protected]>

* opensearchapi: Add custom response type

Signed-off-by: Jakob Hahn <[email protected]>

* opensearchapi: Add InfoResp type

Signed-off-by: Jakob Hahn <[email protected]>

* opensearchapi: Add Point in Time integration test

Signed-off-by: Jakob Hahn <[email protected]>

* opensearchapi: Update comments for point in time apis

Signed-off-by: Jakob Hahn <[email protected]>

* Update Changelog

Signed-off-by: Jakob Hahn <[email protected]>

---------

Signed-off-by: Jakob Hahn <[email protected]>
  • Loading branch information
Jakob3xD authored Mar 24, 2023
1 parent 34ed92d commit 0da56b2
Show file tree
Hide file tree
Showing 7 changed files with 849 additions and 48 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Adds Go Documentation link for the client ([#182](https://github.com/opensearch-project/opensearch-go/pull/182))
- Adds implementation of Data Streams API ([#257](https://github.com/opensearch-project/opensearch-go/pull/257)
- Adds `Err()` function to Response for detailed errors ([#246](https://github.com/opensearch-project/opensearch-go/pull/246))
- Adds Point In Time API ([#253](https://github.com/opensearch-project/opensearch-go/pull/253))
- Adds InfoResp type ([#253](https://github.com/opensearch-project/opensearch-go/pull/253))

### Changed

Expand Down
30 changes: 21 additions & 9 deletions opensearchapi/api._.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
package opensearchapi

// API contains the OpenSearch APIs
//
type API struct {
Cat *Cat
Cluster *Cluster
Indices *Indices
Ingest *Ingest
Nodes *Nodes
Remote *Remote
Snapshot *Snapshot
Tasks *Tasks
Cat *Cat
Cluster *Cluster
Indices *Indices
Ingest *Ingest
Nodes *Nodes
Remote *Remote
Snapshot *Snapshot
Tasks *Tasks
PointInTime *PointInTime

Bulk Bulk
ClearScroll ClearScroll
Expand Down Expand Up @@ -226,6 +226,13 @@ type Tasks struct {
List TasksList
}

// PointInTime contains the Point In Time APIs
type PointInTime struct {
Create PointInTimeCreate
Delete PointInTimeDelete
Get PointInTimeGet
}

// New creates new API
func New(t Transport) *API {
return &API{
Expand Down Expand Up @@ -396,5 +403,10 @@ func New(t Transport) *API {
Get: newTasksGetFunc(t),
List: newTasksListFunc(t),
},
PointInTime: &PointInTime{
Create: newPointInTimeCreateFunc(t),
Delete: newPointInTimeDeleteFunc(t),
Get: newPointInTimeGetFunc(t),
},
}
}
29 changes: 19 additions & 10 deletions opensearchapi/api.info.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ func newInfoFunc(t Transport) Info {
// ----- API Definition -------------------------------------------------------

// Info returns basic information about the cluster.
//
//
type Info func(o ...func(*InfoRequest)) (*Response, error)

// InfoRequest configures the Info API request.
//
type InfoRequest struct {
Pretty bool
Human bool
Expand All @@ -62,8 +59,26 @@ type InfoRequest struct {
ctx context.Context
}

// InfoResp is a custom type to parse the Info Reponse
type InfoResp struct {
Name string `json:"name"`
ClusterName string `json:"cluster_name"`
ClusterUUID string `json:"cluster_uuid"`
Version struct {
Distribution string `json:"distribution"`
Number string `json:"number"`
BuildType string `json:"build_type"`
BuildHash string `json:"build_hash"`
BuildDate string `json:"build_date"`
BuildSnapshot bool `json:"build_snapshot"`
LuceneVersion string `json:"lucene_version"`
MinimumWireCompatibilityVersion string `json:"minimum_wire_compatibility_version"`
MinimumIndexCompatibilityVersion string `json:"minimum_index_compatibility_version"`
} `json:"version"`
Tagline string `json:"tagline"`
}

// Do executes the request and returns response or error.
//
func (r InfoRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
var (
method string
Expand Down Expand Up @@ -138,39 +153,34 @@ func (r InfoRequest) Do(ctx context.Context, transport Transport) (*Response, er
}

// WithContext sets the request context.
//
func (f Info) WithContext(v context.Context) func(*InfoRequest) {
return func(r *InfoRequest) {
r.ctx = v
}
}

// WithHuman makes statistical values human-readable.
//
func (f Info) WithHuman() func(*InfoRequest) {
return func(r *InfoRequest) {
r.Human = true
}
}

// WithErrorTrace includes the stack trace for errors in the response body.
//
func (f Info) WithErrorTrace() func(*InfoRequest) {
return func(r *InfoRequest) {
r.ErrorTrace = true
}
}

// WithFilterPath filters the properties of the response body.
//
func (f Info) WithFilterPath(v ...string) func(*InfoRequest) {
return func(r *InfoRequest) {
r.FilterPath = v
}
}

// WithHeader adds the headers to the HTTP request.
//
func (f Info) WithHeader(h map[string]string) func(*InfoRequest) {
return func(r *InfoRequest) {
if r.Header == nil {
Expand All @@ -183,7 +193,6 @@ func (f Info) WithHeader(h map[string]string) func(*InfoRequest) {
}

// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
//
func (f Info) WithOpaqueID(s string) func(*InfoRequest) {
return func(r *InfoRequest) {
if r.Header == nil {
Expand Down
Loading

0 comments on commit 0da56b2

Please sign in to comment.