Skip to content

Commit

Permalink
Generate snapshot.clone
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Sep 24, 2024
1 parent 0771775 commit 088c27c
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 199 deletions.
5 changes: 4 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ After:
- The `name` field, getter and builder method have been renamed to `repository`.

### CleanupRepositoryRequest property naming
- The `name` field, getter and builder method have been renamed to `repository`.
- The `name` field, getter and builder method have been renamed to `repository`.

### CloneSnapshotRequest timeout removal
- The `timeout` field, getter and builder method have been removed from `CloneSnapshotRequest` as it is not supported by OpenSearch.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@
* GitHub history for details.
*/

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package org.opensearch.client.opensearch.snapshot;

import jakarta.json.stream.JsonGenerator;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
Expand All @@ -55,47 +60,53 @@
// typedef: snapshot.clone.Request

/**
* Clones indices from one snapshot into another snapshot in the same
* repository.
* Clones indices from one snapshot into another snapshot in the same repository.
*/
@JsonpDeserializable
@Generated("org.opensearch.client.codegen.CodeGenerator")
public class CloneSnapshotRequest extends RequestBase implements PlainJsonSerializable {

@Nullable
private final Time clusterManagerTimeout;

private final String indices;

@Deprecated
@Nullable
private final Time masterTimeout;

@Nullable
private final Time clusterManagerTimeout;

private final String repository;

private final String snapshot;

private final String targetSnapshot;

@Nullable
private final Time timeout;

// ---------------------------------------------------------------------------------------------

private CloneSnapshotRequest(Builder builder) {

this.clusterManagerTimeout = builder.clusterManagerTimeout;
this.indices = ApiTypeHelper.requireNonNull(builder.indices, this, "indices");
this.masterTimeout = builder.masterTimeout;
this.clusterManagerTimeout = builder.clusterManagerTimeout;
this.repository = ApiTypeHelper.requireNonNull(builder.repository, this, "repository");
this.snapshot = ApiTypeHelper.requireNonNull(builder.snapshot, this, "snapshot");
this.targetSnapshot = ApiTypeHelper.requireNonNull(builder.targetSnapshot, this, "targetSnapshot");
this.timeout = builder.timeout;

}

public static CloneSnapshotRequest of(Function<Builder, ObjectBuilder<CloneSnapshotRequest>> fn) {
public static CloneSnapshotRequest of(Function<CloneSnapshotRequest.Builder, ObjectBuilder<CloneSnapshotRequest>> fn) {
return fn.apply(new Builder()).build();
}

/**
* Operation timeout for connection to cluster-manager node.
* <p>
* API name: {@code cluster_manager_timeout}
* </p>
*/
@Nullable
public final Time clusterManagerTimeout() {
return this.clusterManagerTimeout;
}

/**
* Required - API name: {@code indices}
*/
Expand All @@ -107,26 +118,19 @@ public final String indices() {
* Explicit operation timeout for connection to master node
* <p>
* API name: {@code master_timeout}
* </p>
*/
@Deprecated
@Nullable
public final Time masterTimeout() {
return this.masterTimeout;
}

/**
* Explicit operation timeout for connection to cluster-manager node
* <p>
* API name: {@code cluster_manager_timeout}
*/
@Nullable
public final Time clusterManagerTimeout() {
return this.clusterManagerTimeout;
}

/**
* Required - A repository name
* <p>
* API name: {@code repository}
* </p>
*/
public final String repository() {
return this.repository;
Expand All @@ -136,6 +140,7 @@ public final String repository() {
* Required - The name of the snapshot to clone from
* <p>
* API name: {@code snapshot}
* </p>
*/
public final String snapshot() {
return this.snapshot;
Expand All @@ -145,59 +150,61 @@ public final String snapshot() {
* Required - The name of the cloned snapshot to create
* <p>
* API name: {@code target_snapshot}
* </p>
*/
public final String targetSnapshot() {
return this.targetSnapshot;
}

/**
* API name: {@code timeout}
*/
@Nullable
public final Time timeout() {
return this.timeout;
}

/**
* Serialize this object to JSON.
*/
@Override
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

generator.writeKey("indices");
generator.write(this.indices);

}

// ---------------------------------------------------------------------------------------------

/**
* Builder for {@link CloneSnapshotRequest}.
*/

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<CloneSnapshotRequest> {
@Nullable
private Time clusterManagerTimeout;
private String indices;

@Deprecated
@Nullable
private Time masterTimeout;

@Nullable
private Time clusterManagerTimeout;

private String repository;

private String snapshot;

private String targetSnapshot;

@Nullable
private Time timeout;
/**
* Operation timeout for connection to cluster-manager node.
* <p>
* API name: {@code cluster_manager_timeout}
* </p>
*/
public final Builder clusterManagerTimeout(@Nullable Time value) {
this.clusterManagerTimeout = value;
return this;
}

/**
* Operation timeout for connection to cluster-manager node.
* <p>
* API name: {@code cluster_manager_timeout}
* </p>
*/
public final Builder clusterManagerTimeout(Function<Time.Builder, ObjectBuilder<Time>> fn) {
return clusterManagerTimeout(fn.apply(new Time.Builder()).build());
}

/**
* Required - API name: {@code indices}
Expand All @@ -211,6 +218,7 @@ public final Builder indices(String value) {
* Explicit operation timeout for connection to master node
* <p>
* API name: {@code master_timeout}
* </p>
*/
@Deprecated
public final Builder masterTimeout(@Nullable Time value) {
Expand All @@ -222,35 +230,18 @@ public final Builder masterTimeout(@Nullable Time value) {
* Explicit operation timeout for connection to master node
* <p>
* API name: {@code master_timeout}
* </p>
*/
@Deprecated
public final Builder masterTimeout(Function<Time.Builder, ObjectBuilder<Time>> fn) {
return this.masterTimeout(fn.apply(new Time.Builder()).build());
}

/**
* Explicit operation timeout for connection to cluster-manager node
* <p>
* API name: {@code cluster_manager_timeout}
*/
public final Builder clusterManagerTimeout(@Nullable Time value) {
this.clusterManagerTimeout = value;
return this;
}

/**
* Explicit operation timeout for connection to cluster-manager node
* <p>
* API name: {@code cluster_manager_timeout}
*/
public final Builder clusterManagerTimeout(Function<Time.Builder, ObjectBuilder<Time>> fn) {
return this.clusterManagerTimeout(fn.apply(new Time.Builder()).build());
return masterTimeout(fn.apply(new Time.Builder()).build());
}

/**
* Required - A repository name
* <p>
* API name: {@code repository}
* </p>
*/
public final Builder repository(String value) {
this.repository = value;
Expand All @@ -261,6 +252,7 @@ public final Builder repository(String value) {
* Required - The name of the snapshot to clone from
* <p>
* API name: {@code snapshot}
* </p>
*/
public final Builder snapshot(String value) {
this.snapshot = value;
Expand All @@ -271,32 +263,17 @@ public final Builder snapshot(String value) {
* Required - The name of the cloned snapshot to create
* <p>
* API name: {@code target_snapshot}
* </p>
*/
public final Builder targetSnapshot(String value) {
this.targetSnapshot = value;
return this;
}

/**
* API name: {@code timeout}
*/
public final Builder timeout(@Nullable Time value) {
this.timeout = value;
return this;
}

/**
* API name: {@code timeout}
*/
public final Builder timeout(Function<Time.Builder, ObjectBuilder<Time>> fn) {
return this.timeout(fn.apply(new Time.Builder()).build());
}

/**
* Builds a {@link CloneSnapshotRequest}.
*
* @throws NullPointerException
* if some of the required fields are null.
* @throws NullPointerException if some of the required fields are null.
*/
public CloneSnapshotRequest build() {
_checkSingleUse();
Expand All @@ -316,9 +293,7 @@ public CloneSnapshotRequest build() {
);

protected static void setupCloneSnapshotRequestDeserializer(ObjectDeserializer<CloneSnapshotRequest.Builder> op) {

op.add(Builder::indices, JsonpDeserializer.stringDeserializer(), "indices");

}

// ---------------------------------------------------------------------------------------------
Expand All @@ -327,55 +302,29 @@ protected static void setupCloneSnapshotRequestDeserializer(ObjectDeserializer<C
* Endpoint "{@code snapshot.clone}".
*/
public static final Endpoint<CloneSnapshotRequest, CloneSnapshotResponse, ErrorResponse> _ENDPOINT = new SimpleEndpoint<>(

// Request method
request -> {
return "PUT";

},

request -> "PUT",
// Request path
request -> {
final int _targetSnapshot = 1 << 0;
final int _repository = 1 << 1;
final int _snapshot = 1 << 2;

int propsSet = 0;

propsSet |= _targetSnapshot;
propsSet |= _repository;
propsSet |= _snapshot;

if (propsSet == (_repository | _snapshot | _targetSnapshot)) {
StringBuilder buf = new StringBuilder();
buf.append("/_snapshot");
buf.append("/");
SimpleEndpoint.pathEncode(request.repository, buf);
buf.append("/");
SimpleEndpoint.pathEncode(request.snapshot, buf);
buf.append("/_clone");
buf.append("/");
SimpleEndpoint.pathEncode(request.targetSnapshot, buf);
return buf.toString();
}
throw SimpleEndpoint.noPathTemplateFound("path");

StringBuilder buf = new StringBuilder();
buf.append("/_snapshot/");
SimpleEndpoint.pathEncode(request.repository, buf);
buf.append("/");
SimpleEndpoint.pathEncode(request.snapshot, buf);
buf.append("/_clone/");
SimpleEndpoint.pathEncode(request.targetSnapshot, buf);
return buf.toString();
},

// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
if (request.masterTimeout != null) {
params.put("master_timeout", request.masterTimeout._toJsonString());
}
if (request.clusterManagerTimeout != null) {
params.put("cluster_manager_timeout", request.clusterManagerTimeout._toJsonString());
}
if (request.timeout != null) {
params.put("timeout", request.timeout._toJsonString());
if (request.masterTimeout != null) {
params.put("master_timeout", request.masterTimeout._toJsonString());
}
return params;

},
SimpleEndpoint.emptyMap(),
true,
Expand Down
Loading

0 comments on commit 088c27c

Please sign in to comment.