-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opensearchapi: add pointInTimeClient
Signed-off-by: Jakob Hahn <[email protected]>
- Loading branch information
Showing
8 changed files
with
594 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// PointInTimeCreateParams represents possible parameters for the PointInTimeCreateReq | ||
type PointInTimeCreateParams struct { | ||
KeepAlive time.Duration | ||
Preference string | ||
Routing string | ||
ExpandWildcards string | ||
AllowPartialPitCreation bool | ||
|
||
Pretty bool | ||
Human bool | ||
ErrorTrace bool | ||
} | ||
|
||
func (r PointInTimeCreateParams) get() map[string]string { | ||
params := make(map[string]string) | ||
|
||
if r.KeepAlive != 0 { | ||
params["keep_alive"] = formatDuration(r.KeepAlive) | ||
} | ||
|
||
if r.Preference != "" { | ||
params["preference"] = r.Preference | ||
} | ||
|
||
if r.Routing != "" { | ||
params["routing"] = r.Routing | ||
} | ||
|
||
if r.ExpandWildcards != "" { | ||
params["expand_wildcards"] = r.ExpandWildcards | ||
} | ||
|
||
if r.AllowPartialPitCreation { | ||
params["allow_partial_pit_creation"] = "true" | ||
} | ||
|
||
if r.Pretty { | ||
params["pretty"] = "true" | ||
} | ||
|
||
if r.Human { | ||
params["human"] = "true" | ||
} | ||
|
||
if r.ErrorTrace { | ||
params["error_trace"] = "true" | ||
} | ||
|
||
return params | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/opensearch-project/opensearch-go/v2" | ||
) | ||
|
||
// PointInTimeCreateReq represents possible options for the index create request | ||
type PointInTimeCreateReq struct { | ||
Indices []string | ||
|
||
Header http.Header | ||
Params PointInTimeCreateParams | ||
} | ||
|
||
// GetRequest returns the *http.Request that gets executed by the client | ||
func (r PointInTimeCreateReq) GetRequest() (*http.Request, error) { | ||
indices := strings.Join(r.Indices, ",") | ||
|
||
var path strings.Builder | ||
path.Grow(len("//_search/point_in_time") + len(indices)) | ||
if len(r.Indices) > 0 { | ||
path.WriteString("/") | ||
path.WriteString(indices) | ||
} | ||
path.WriteString("/_search/point_in_time") | ||
|
||
return opensearch.BuildRequest( | ||
"POST", | ||
path.String(), | ||
nil, | ||
r.Params.get(), | ||
r.Header, | ||
) | ||
} | ||
|
||
// PointInTimeCreateResp represents the returned struct of the index create response | ||
type PointInTimeCreateResp struct { | ||
PitID string `json:"pit_id"` | ||
Shards struct { | ||
Total int `json:"total"` | ||
Successful int `json:"successful"` | ||
Skipped int `json:"skipped"` | ||
Failed int `json:"failed"` | ||
} `json:"_shards"` | ||
CreationTime int64 `json:"creation_time"` | ||
response *opensearch.Response | ||
} | ||
|
||
// Inspect returns the Inspect type containing the raw *opensearch.Reponse | ||
func (r PointInTimeCreateResp) Inspect() Inspect { | ||
return Inspect{Response: r.response} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
// PointInTimeDeleteParams represents possible parameters for the PointInTimeDeleteReq | ||
type PointInTimeDeleteParams struct { | ||
Pretty bool | ||
Human bool | ||
ErrorTrace bool | ||
} | ||
|
||
func (r PointInTimeDeleteParams) get() map[string]string { | ||
params := make(map[string]string) | ||
|
||
if r.Pretty { | ||
params["pretty"] = "true" | ||
} | ||
|
||
if r.Human { | ||
params["human"] = "true" | ||
} | ||
|
||
if r.ErrorTrace { | ||
params["error_trace"] = "true" | ||
} | ||
|
||
return params | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/opensearch-project/opensearch-go/v2" | ||
) | ||
|
||
// PointInTimeDeleteReq represents possible options for the index create request | ||
type PointInTimeDeleteReq struct { | ||
PitID []string | ||
|
||
Header http.Header | ||
Params PointInTimeDeleteParams | ||
} | ||
|
||
// GetRequest returns the *http.Request that gets executed by the client | ||
func (r PointInTimeDeleteReq) GetRequest() (*http.Request, error) { | ||
var body io.Reader | ||
if len(r.PitID) > 0 { | ||
bodyStruct := PointInTimeDeleteRequestBody{PitID: r.PitID} | ||
bodyJSON, err := json.Marshal(bodyStruct) | ||
if err != nil { | ||
return nil, err | ||
} | ||
body = bytes.NewBuffer(bodyJSON) | ||
} | ||
|
||
return opensearch.BuildRequest( | ||
"DELETE", | ||
"/_search/point_in_time", | ||
body, | ||
r.Params.get(), | ||
r.Header, | ||
) | ||
} | ||
|
||
// PointInTimeDeleteRequestBody is used to from the delete request body | ||
type PointInTimeDeleteRequestBody struct { | ||
PitID []string `json:"pit_id"` | ||
} | ||
|
||
// PointInTimeDeleteResp represents the returned struct of the index create response | ||
type PointInTimeDeleteResp struct { | ||
Pits []struct { | ||
PitID string `json:"pit_id"` | ||
Successful bool `json:"successful"` | ||
} `json:"pits"` | ||
response *opensearch.Response | ||
} | ||
|
||
// Inspect returns the Inspect type containing the raw *opensearch.Reponse | ||
func (r PointInTimeDeleteResp) Inspect() Inspect { | ||
return Inspect{Response: r.response} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
// PointInTimeGetParams represents possible parameters for the PointInTimeGetReq | ||
type PointInTimeGetParams struct { | ||
Pretty bool | ||
Human bool | ||
ErrorTrace bool | ||
} | ||
|
||
func (r PointInTimeGetParams) get() map[string]string { | ||
params := make(map[string]string) | ||
|
||
if r.Pretty { | ||
params["pretty"] = "true" | ||
} | ||
|
||
if r.Human { | ||
params["human"] = "true" | ||
} | ||
|
||
if r.ErrorTrace { | ||
params["error_trace"] = "true" | ||
} | ||
|
||
return params | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// The OpenSearch Contributors require contributions made to | ||
// this file be licensed under the Apache-2.0 license or a | ||
// compatible open source license. | ||
// | ||
// Modifications Copyright OpenSearch Contributors. See | ||
// GitHub history for details. | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opensearchapi | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/opensearch-project/opensearch-go/v2" | ||
) | ||
|
||
// PointInTimeGetReq represents possible options for the index create request | ||
type PointInTimeGetReq struct { | ||
Header http.Header | ||
Params PointInTimeGetParams | ||
} | ||
|
||
// GetRequest returns the *http.Request that gets executed by the client | ||
func (r PointInTimeGetReq) GetRequest() (*http.Request, error) { | ||
return opensearch.BuildRequest( | ||
"GET", | ||
"/_search/point_in_time/_all", | ||
nil, | ||
r.Params.get(), | ||
r.Header, | ||
) | ||
} | ||
|
||
// PointInTimeGetResp represents the returned struct of the index create response | ||
type PointInTimeGetResp struct { | ||
Pits []struct { | ||
PitID string `json:"pit_id"` | ||
CreationTime int `json:"creation_time"` | ||
KeepAlive int64 `json:"keep_alive"` | ||
} `json:"pits"` | ||
response *opensearch.Response | ||
} | ||
|
||
// Inspect returns the Inspect type containing the raw *opensearch.Reponse | ||
func (r PointInTimeGetResp) Inspect() Inspect { | ||
return Inspect{Response: r.response} | ||
} |
Oops, something went wrong.