Skip to content

Commit

Permalink
Generate CreateSnapshot
Browse files Browse the repository at this point in the history
Signed-off-by: Tatsuya Kawakami <43780506+hogesako@users.noreply.github.com>
  • Loading branch information
hogesako committed Nov 27, 2024
1 parent bd171fb commit 4fb9852
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 230 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,120 +30,174 @@
* 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.Objects;
import java.util.function.Function;
import javax.annotation.Generated;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.json.PlainJsonSerializable;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.CopyableBuilder;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;
import org.opensearch.client.util.ToCopyableBuilder;

// typedef: snapshot.create.Response

@JsonpDeserializable
public class CreateSnapshotResponse implements PlainJsonSerializable {
@Generated("org.opensearch.client.codegen.CodeGenerator")
public class CreateSnapshotResponse
implements
PlainJsonSerializable,
ToCopyableBuilder<CreateSnapshotResponse.Builder, CreateSnapshotResponse> {

@Nullable
private final Boolean accepted;

@Nullable
private final SnapshotInfo snapshot;

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

private CreateSnapshotResponse(Builder builder) {

this.accepted = builder.accepted;
this.snapshot = ApiTypeHelper.requireNonNull(builder.snapshot, this, "snapshot");

this.snapshot = builder.snapshot;
}

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

/**
* Returns <code>true</code> if the snapshot was accepted. Present when the request had <code>wait_for_completion</code> set to
* <code>false</code>.
* <p>
* API name: {@code accepted}
* </p>
*/
@Nullable
public final Boolean accepted() {
return this.accepted;
}

/**
* Required - API name: {@code snapshot}
* API name: {@code snapshot}
*/
@Nullable
public final SnapshotInfo snapshot() {
return this.snapshot;
}

/**
* 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) {

if (this.accepted != null) {
generator.writeKey("accepted");
generator.write(this.accepted);

}
generator.writeKey("snapshot");
this.snapshot.serialize(generator, mapper);

if (this.snapshot != null) {
generator.writeKey("snapshot");
this.snapshot.serialize(generator, mapper);
}
}

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

@Override
@Nonnull
public Builder toBuilder() {
return new Builder(this);
}

@Nonnull
public static Builder builder() {
return new Builder();
}

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

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<CreateSnapshotResponse> {
public static class Builder extends ObjectBuilderBase implements CopyableBuilder<Builder, CreateSnapshotResponse> {
@Nullable
private Boolean accepted;

@Nullable
private SnapshotInfo snapshot;

public Builder() {}

private Builder(CreateSnapshotResponse o) {
this.accepted = o.accepted;
this.snapshot = o.snapshot;
}

private Builder(Builder o) {
this.accepted = o.accepted;
this.snapshot = o.snapshot;
}

@Override
@Nonnull
public Builder copy() {
return new Builder(this);
}

/**
* Returns <code>true</code> if the snapshot was accepted. Present when the request had <code>wait_for_completion</code> set to
* <code>false</code>.
* <p>
* API name: {@code accepted}
* </p>
*/
@Nonnull
public final Builder accepted(@Nullable Boolean value) {
this.accepted = value;
return this;
}

/**
* Required - API name: {@code snapshot}
* API name: {@code snapshot}
*/
public final Builder snapshot(SnapshotInfo value) {
@Nonnull
public final Builder snapshot(@Nullable SnapshotInfo value) {
this.snapshot = value;
return this;
}

/**
* Required - API name: {@code snapshot}
* API name: {@code snapshot}
*/
@Nonnull
public final Builder snapshot(Function<SnapshotInfo.Builder, ObjectBuilder<SnapshotInfo>> fn) {
return this.snapshot(fn.apply(new SnapshotInfo.Builder()).build());
return snapshot(fn.apply(new SnapshotInfo.Builder()).build());
}

/**
* Builds a {@link CreateSnapshotResponse}.
*
* @throws NullPointerException
* if some of the required fields are null.
* @throws NullPointerException if some of the required fields are null.
*/
@Override
@Nonnull
public CreateSnapshotResponse build() {
_checkSingleUse();

Expand All @@ -162,10 +216,23 @@ public CreateSnapshotResponse build() {
);

protected static void setupCreateSnapshotResponseDeserializer(ObjectDeserializer<CreateSnapshotResponse.Builder> op) {

op.add(Builder::accepted, JsonpDeserializer.booleanDeserializer(), "accepted");
op.add(Builder::snapshot, SnapshotInfo._DESERIALIZER, "snapshot");
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + Objects.hashCode(this.accepted);
result = 31 * result + Objects.hashCode(this.snapshot);
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
CreateSnapshotResponse other = (CreateSnapshotResponse) o;
return Objects.equals(this.accepted, other.accepted) && Objects.equals(this.snapshot, other.snapshot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ public final CompletableFuture<CloneSnapshotResponse> clone(
return clone(fn.apply(new CloneSnapshotRequest.Builder()).build());
}

// ----- Endpoint: snapshot.create

/**
* Creates a snapshot in a repository.
*/
public CompletableFuture<CreateSnapshotResponse> create(CreateSnapshotRequest request) throws IOException, OpenSearchException {
return this.transport.performRequestAsync(request, CreateSnapshotRequest._ENDPOINT, this.transportOptions);
}

/**
* Creates a snapshot in a repository.
*
* @param fn a function that initializes a builder to create the {@link CreateSnapshotRequest}
*/
public final CompletableFuture<CreateSnapshotResponse> create(
Function<CreateSnapshotRequest.Builder, ObjectBuilder<CreateSnapshotRequest>> fn
) throws IOException, OpenSearchException {
return create(fn.apply(new CreateSnapshotRequest.Builder()).build());
}

// ----- Endpoint: snapshot.get

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ public final CloneSnapshotResponse clone(Function<CloneSnapshotRequest.Builder,
return clone(fn.apply(new CloneSnapshotRequest.Builder()).build());
}

// ----- Endpoint: snapshot.create

/**
* Creates a snapshot in a repository.
*/
public CreateSnapshotResponse create(CreateSnapshotRequest request) throws IOException, OpenSearchException {
return this.transport.performRequest(request, CreateSnapshotRequest._ENDPOINT, this.transportOptions);
}

/**
* Creates a snapshot in a repository.
*
* @param fn a function that initializes a builder to create the {@link CreateSnapshotRequest}
*/
public final CreateSnapshotResponse create(Function<CreateSnapshotRequest.Builder, ObjectBuilder<CreateSnapshotRequest>> fn)
throws IOException, OpenSearchException {
return create(fn.apply(new CreateSnapshotRequest.Builder()).build());
}

// ----- Endpoint: snapshot.get

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,6 @@ public CompletableFuture<CreateSnapshotResponse> create(CreateSnapshotRequest re
return this.transport.performRequestAsync(request, endpoint, this.transportOptions);
}

/**
* Creates a snapshot in a repository.
*
* @param fn
* a function that initializes a builder to create the
* {@link CreateSnapshotRequest}
*
*/

public final CompletableFuture<CreateSnapshotResponse> create(
Function<CreateSnapshotRequest.Builder, ObjectBuilder<CreateSnapshotRequest>> fn
) throws IOException, OpenSearchException {
return create(fn.apply(new CreateSnapshotRequest.Builder()).build());
}

// ----- Endpoint: snapshot.create_repository

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@ public CreateSnapshotResponse create(CreateSnapshotRequest request) throws IOExc
return this.transport.performRequest(request, endpoint, this.transportOptions);
}

/**
* Creates a snapshot in a repository.
*
* @param fn
* a function that initializes a builder to create the
* {@link CreateSnapshotRequest}
*
*/

public final CreateSnapshotResponse create(Function<CreateSnapshotRequest.Builder, ObjectBuilder<CreateSnapshotRequest>> fn)
throws IOException, OpenSearchException {
return create(fn.apply(new CreateSnapshotRequest.Builder()).build());
}

// ----- Endpoint: snapshot.create_repository

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class CodeGenerator {
)
),
and(namespace("ml"), not(named("search_models"))), // TODO: search_models is complex and ideally should re-use the search structures
and(namespace("snapshot"), named("cleanup_repository", "clone", "get", "verify_repository")),
and(namespace("snapshot"), named("cleanup_repository", "clone", "create", "get", "verify_repository")),
and(namespace("tasks"))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ private static String classBaseName(@Nonnull OperationGroup operationGroup) {
return "GetIndex";
case "snapshot.clone":
return "CloneSnapshot";
case "snapshot.create":
return "CreateSnapshot";
case "snapshot.get":
return "GetSnapshot";
case "tasks.get":
Expand Down

0 comments on commit 4fb9852

Please sign in to comment.