All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.elastic.clients.elasticsearch.snapshot.CreateSnapshotRequest Maven / Gradle / Ivy

/*
 * Licensed to Elasticsearch B.V. under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch B.V. licenses this file to you 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.
 */

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

package co.elastic.clients.elasticsearch.snapshot;

import co.elastic.clients.elasticsearch._types.ErrorResponse;
import co.elastic.clients.elasticsearch._types.RequestBase;
import co.elastic.clients.elasticsearch._types.Time;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;
import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.json.JsonpSerializable;
import co.elastic.clients.json.ObjectBuilderDeserializer;
import co.elastic.clients.json.ObjectDeserializer;
import co.elastic.clients.transport.Endpoint;
import co.elastic.clients.transport.endpoints.SimpleEndpoint;
import co.elastic.clients.util.ApiTypeHelper;
import co.elastic.clients.util.ObjectBuilder;
import co.elastic.clients.util.WithJsonObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;
import java.lang.Boolean;
import java.lang.String;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;

// typedef: snapshot.create.Request

/**
 * Creates a snapshot in a repository.
 * 
 * @see API
 *      specification
 */
@JsonpDeserializable
public class CreateSnapshotRequest extends RequestBase implements JsonpSerializable {
	private final List featureStates;

	@Nullable
	private final Boolean ignoreUnavailable;

	@Nullable
	private final Boolean includeGlobalState;

	private final List indices;

	@Nullable
	private final Time masterTimeout;

	private final Map metadata;

	@Nullable
	private final Boolean partial;

	private final String repository;

	private final String snapshot;

	@Nullable
	private final Boolean waitForCompletion;

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

	private CreateSnapshotRequest(Builder builder) {

		this.featureStates = ApiTypeHelper.unmodifiable(builder.featureStates);
		this.ignoreUnavailable = builder.ignoreUnavailable;
		this.includeGlobalState = builder.includeGlobalState;
		this.indices = ApiTypeHelper.unmodifiable(builder.indices);
		this.masterTimeout = builder.masterTimeout;
		this.metadata = ApiTypeHelper.unmodifiable(builder.metadata);
		this.partial = builder.partial;
		this.repository = ApiTypeHelper.requireNonNull(builder.repository, this, "repository");
		this.snapshot = ApiTypeHelper.requireNonNull(builder.snapshot, this, "snapshot");
		this.waitForCompletion = builder.waitForCompletion;

	}

	public static CreateSnapshotRequest of(Function> fn) {
		return fn.apply(new Builder()).build();
	}

	/**
	 * Feature states to include in the snapshot. Each feature state includes one or
	 * more system indices containing related data. You can view a list of eligible
	 * features using the get features API. If include_global_state is
	 * true, all current feature states are included by default. If
	 * include_global_state is false, no feature states
	 * are included by default.
	 * 

* API name: {@code feature_states} */ public final List featureStates() { return this.featureStates; } /** * If true, the request ignores data streams and indices in * indices that are missing or closed. If false, the * request returns an error for any data stream or index that is missing or * closed. *

* API name: {@code ignore_unavailable} */ @Nullable public final Boolean ignoreUnavailable() { return this.ignoreUnavailable; } /** * If true, the current cluster state is included in the snapshot. * The cluster state includes persistent cluster settings, composable index * templates, legacy index templates, ingest pipelines, and ILM policies. It * also includes data stored in system indices, such as Watches and task records * (configurable via feature_states). *

* API name: {@code include_global_state} */ @Nullable public final Boolean includeGlobalState() { return this.includeGlobalState; } /** * Data streams and indices to include in the snapshot. Supports multi-target * syntax. Includes all data streams and indices by default. *

* API name: {@code indices} */ public final List indices() { return this.indices; } /** * Period to wait for a connection to the master node. If no response is * received before the timeout expires, the request fails and returns an error. *

* API name: {@code master_timeout} */ @Nullable public final Time masterTimeout() { return this.masterTimeout; } /** * Optional metadata for the snapshot. May have any contents. Must be less than * 1024 bytes. This map is not automatically generated by Elasticsearch. *

* API name: {@code metadata} */ public final Map metadata() { return this.metadata; } /** * If true, allows restoring a partial snapshot of indices with * unavailable shards. Only shards that were successfully included in the * snapshot will be restored. All missing shards will be recreated as empty. If * false, the entire restore operation will fail if one or more * indices included in the snapshot do not have all primary shards available. *

* API name: {@code partial} */ @Nullable public final Boolean partial() { return this.partial; } /** * Required - Repository for the snapshot. *

* API name: {@code repository} */ public final String repository() { return this.repository; } /** * Required - Name of the snapshot. Must be unique in the repository. *

* API name: {@code snapshot} */ public final String snapshot() { return this.snapshot; } /** * If true, the request returns a response when the snapshot is * complete. If false, the request returns a response when the * snapshot initializes. *

* API name: {@code wait_for_completion} */ @Nullable public final Boolean waitForCompletion() { return this.waitForCompletion; } /** * Serialize this object to JSON. */ public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); serializeInternal(generator, mapper); generator.writeEnd(); } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { if (ApiTypeHelper.isDefined(this.featureStates)) { generator.writeKey("feature_states"); generator.writeStartArray(); for (String item0 : this.featureStates) { generator.write(item0); } generator.writeEnd(); } if (this.ignoreUnavailable != null) { generator.writeKey("ignore_unavailable"); generator.write(this.ignoreUnavailable); } if (this.includeGlobalState != null) { generator.writeKey("include_global_state"); generator.write(this.includeGlobalState); } if (ApiTypeHelper.isDefined(this.indices)) { generator.writeKey("indices"); generator.writeStartArray(); for (String item0 : this.indices) { generator.write(item0); } generator.writeEnd(); } if (ApiTypeHelper.isDefined(this.metadata)) { generator.writeKey("metadata"); generator.writeStartObject(); for (Map.Entry item0 : this.metadata.entrySet()) { generator.writeKey(item0.getKey()); item0.getValue().serialize(generator, mapper); } generator.writeEnd(); } if (this.partial != null) { generator.writeKey("partial"); generator.write(this.partial); } } // --------------------------------------------------------------------------------------------- /** * Builder for {@link CreateSnapshotRequest}. */ public static class Builder extends WithJsonObjectBuilderBase implements ObjectBuilder { @Nullable private List featureStates; @Nullable private Boolean ignoreUnavailable; @Nullable private Boolean includeGlobalState; @Nullable private List indices; @Nullable private Time masterTimeout; @Nullable private Map metadata; @Nullable private Boolean partial; private String repository; private String snapshot; @Nullable private Boolean waitForCompletion; /** * Feature states to include in the snapshot. Each feature state includes one or * more system indices containing related data. You can view a list of eligible * features using the get features API. If include_global_state is * true, all current feature states are included by default. If * include_global_state is false, no feature states * are included by default. *

* API name: {@code feature_states} *

* Adds all elements of list to featureStates. */ public final Builder featureStates(List list) { this.featureStates = _listAddAll(this.featureStates, list); return this; } /** * Feature states to include in the snapshot. Each feature state includes one or * more system indices containing related data. You can view a list of eligible * features using the get features API. If include_global_state is * true, all current feature states are included by default. If * include_global_state is false, no feature states * are included by default. *

* API name: {@code feature_states} *

* Adds one or more values to featureStates. */ public final Builder featureStates(String value, String... values) { this.featureStates = _listAdd(this.featureStates, value, values); return this; } /** * If true, the request ignores data streams and indices in * indices that are missing or closed. If false, the * request returns an error for any data stream or index that is missing or * closed. *

* API name: {@code ignore_unavailable} */ public final Builder ignoreUnavailable(@Nullable Boolean value) { this.ignoreUnavailable = value; return this; } /** * If true, the current cluster state is included in the snapshot. * The cluster state includes persistent cluster settings, composable index * templates, legacy index templates, ingest pipelines, and ILM policies. It * also includes data stored in system indices, such as Watches and task records * (configurable via feature_states). *

* API name: {@code include_global_state} */ public final Builder includeGlobalState(@Nullable Boolean value) { this.includeGlobalState = value; return this; } /** * Data streams and indices to include in the snapshot. Supports multi-target * syntax. Includes all data streams and indices by default. *

* API name: {@code indices} *

* Adds all elements of list to indices. */ public final Builder indices(List list) { this.indices = _listAddAll(this.indices, list); return this; } /** * Data streams and indices to include in the snapshot. Supports multi-target * syntax. Includes all data streams and indices by default. *

* API name: {@code indices} *

* Adds one or more values to indices. */ public final Builder indices(String value, String... values) { this.indices = _listAdd(this.indices, value, values); return this; } /** * Period to wait for a connection to the master node. If no response is * received before the timeout expires, the request fails and returns an error. *

* API name: {@code master_timeout} */ public final Builder masterTimeout(@Nullable Time value) { this.masterTimeout = value; return this; } /** * Period to wait for a connection to the master node. If no response is * received before the timeout expires, the request fails and returns an error. *

* API name: {@code master_timeout} */ public final Builder masterTimeout(Function> fn) { return this.masterTimeout(fn.apply(new Time.Builder()).build()); } /** * Optional metadata for the snapshot. May have any contents. Must be less than * 1024 bytes. This map is not automatically generated by Elasticsearch. *

* API name: {@code metadata} *

* Adds all entries of map to metadata. */ public final Builder metadata(Map map) { this.metadata = _mapPutAll(this.metadata, map); return this; } /** * Optional metadata for the snapshot. May have any contents. Must be less than * 1024 bytes. This map is not automatically generated by Elasticsearch. *

* API name: {@code metadata} *

* Adds an entry to metadata. */ public final Builder metadata(String key, JsonData value) { this.metadata = _mapPut(this.metadata, key, value); return this; } /** * If true, allows restoring a partial snapshot of indices with * unavailable shards. Only shards that were successfully included in the * snapshot will be restored. All missing shards will be recreated as empty. If * false, the entire restore operation will fail if one or more * indices included in the snapshot do not have all primary shards available. *

* API name: {@code partial} */ public final Builder partial(@Nullable Boolean value) { this.partial = value; return this; } /** * Required - Repository for the snapshot. *

* API name: {@code repository} */ public final Builder repository(String value) { this.repository = value; return this; } /** * Required - Name of the snapshot. Must be unique in the repository. *

* API name: {@code snapshot} */ public final Builder snapshot(String value) { this.snapshot = value; return this; } /** * If true, the request returns a response when the snapshot is * complete. If false, the request returns a response when the * snapshot initializes. *

* API name: {@code wait_for_completion} */ public final Builder waitForCompletion(@Nullable Boolean value) { this.waitForCompletion = value; return this; } @Override protected Builder self() { return this; } /** * Builds a {@link CreateSnapshotRequest}. * * @throws NullPointerException * if some of the required fields are null. */ public CreateSnapshotRequest build() { _checkSingleUse(); return new CreateSnapshotRequest(this); } } // --------------------------------------------------------------------------------------------- /** * Json deserializer for {@link CreateSnapshotRequest} */ public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer .lazy(Builder::new, CreateSnapshotRequest::setupCreateSnapshotRequestDeserializer); protected static void setupCreateSnapshotRequestDeserializer(ObjectDeserializer op) { op.add(Builder::featureStates, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "feature_states"); op.add(Builder::ignoreUnavailable, JsonpDeserializer.booleanDeserializer(), "ignore_unavailable"); op.add(Builder::includeGlobalState, JsonpDeserializer.booleanDeserializer(), "include_global_state"); op.add(Builder::indices, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "indices"); op.add(Builder::metadata, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "metadata"); op.add(Builder::partial, JsonpDeserializer.booleanDeserializer(), "partial"); } // --------------------------------------------------------------------------------------------- /** * Endpoint "{@code snapshot.create}". */ public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( "es/snapshot.create", // Request method request -> { return "PUT"; }, // Request path request -> { final int _repository = 1 << 0; final int _snapshot = 1 << 1; int propsSet = 0; propsSet |= _repository; propsSet |= _snapshot; if (propsSet == (_repository | _snapshot)) { StringBuilder buf = new StringBuilder(); buf.append("/_snapshot"); buf.append("/"); SimpleEndpoint.pathEncode(request.repository, buf); buf.append("/"); SimpleEndpoint.pathEncode(request.snapshot, buf); return buf.toString(); } throw SimpleEndpoint.noPathTemplateFound("path"); }, // Request parameters request -> { Map params = new HashMap<>(); if (request.masterTimeout != null) { params.put("master_timeout", request.masterTimeout._toJsonString()); } if (request.waitForCompletion != null) { params.put("wait_for_completion", String.valueOf(request.waitForCompletion)); } return params; }, SimpleEndpoint.emptyMap(), true, CreateSnapshotResponse._DESERIALIZER); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy