io.kubernetes.client.openapi.models.V1Toleration Maven / Gradle / Ivy
The newest version!
/*
Copyright 2024 The Kubernetes Authors.
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 io.kubernetes.client.openapi.models;
import java.util.Objects;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.Arrays;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import io.kubernetes.client.openapi.JSON;
/**
* The pod this Toleration is attached to tolerates any taint that matches the triple <key,value,effect> using the matching operator <operator>.
*/
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-10-04T19:37:38.574271Z[Etc/UTC]", comments = "Generator version: 7.6.0")
public class V1Toleration {
public static final String SERIALIZED_NAME_EFFECT = "effect";
@SerializedName(SERIALIZED_NAME_EFFECT)
private String effect;
public static final String SERIALIZED_NAME_KEY = "key";
@SerializedName(SERIALIZED_NAME_KEY)
private String key;
public static final String SERIALIZED_NAME_OPERATOR = "operator";
@SerializedName(SERIALIZED_NAME_OPERATOR)
private String operator;
public static final String SERIALIZED_NAME_TOLERATION_SECONDS = "tolerationSeconds";
@SerializedName(SERIALIZED_NAME_TOLERATION_SECONDS)
private Long tolerationSeconds;
public static final String SERIALIZED_NAME_VALUE = "value";
@SerializedName(SERIALIZED_NAME_VALUE)
private String value;
public V1Toleration() {
}
public V1Toleration effect(String effect) {
this.effect = effect;
return this;
}
/**
* Effect indicates the taint effect to match. Empty means match all taint effects. When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute.
* @return effect
**/
@jakarta.annotation.Nullable
public String getEffect() {
return effect;
}
public void setEffect(String effect) {
this.effect = effect;
}
public V1Toleration key(String key) {
this.key = key;
return this;
}
/**
* Key is the taint key that the toleration applies to. Empty means match all taint keys. If the key is empty, operator must be Exists; this combination means to match all values and all keys.
* @return key
**/
@jakarta.annotation.Nullable
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public V1Toleration operator(String operator) {
this.operator = operator;
return this;
}
/**
* Operator represents a key's relationship to the value. Valid operators are Exists and Equal. Defaults to Equal. Exists is equivalent to wildcard for value, so that a pod can tolerate all taints of a particular category.
* @return operator
**/
@jakarta.annotation.Nullable
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public V1Toleration tolerationSeconds(Long tolerationSeconds) {
this.tolerationSeconds = tolerationSeconds;
return this;
}
/**
* TolerationSeconds represents the period of time the toleration (which must be of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, it is not set, which means tolerate the taint forever (do not evict). Zero and negative values will be treated as 0 (evict immediately) by the system.
* @return tolerationSeconds
**/
@jakarta.annotation.Nullable
public Long getTolerationSeconds() {
return tolerationSeconds;
}
public void setTolerationSeconds(Long tolerationSeconds) {
this.tolerationSeconds = tolerationSeconds;
}
public V1Toleration value(String value) {
this.value = value;
return this;
}
/**
* Value is the taint value the toleration matches to. If the operator is Exists, the value should be empty, otherwise just a regular string.
* @return value
**/
@jakarta.annotation.Nullable
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
V1Toleration v1Toleration = (V1Toleration) o;
return Objects.equals(this.effect, v1Toleration.effect) &&
Objects.equals(this.key, v1Toleration.key) &&
Objects.equals(this.operator, v1Toleration.operator) &&
Objects.equals(this.tolerationSeconds, v1Toleration.tolerationSeconds) &&
Objects.equals(this.value, v1Toleration.value);
}
@Override
public int hashCode() {
return Objects.hash(effect, key, operator, tolerationSeconds, value);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class V1Toleration {\n");
sb.append(" effect: ").append(toIndentedString(effect)).append("\n");
sb.append(" key: ").append(toIndentedString(key)).append("\n");
sb.append(" operator: ").append(toIndentedString(operator)).append("\n");
sb.append(" tolerationSeconds: ").append(toIndentedString(tolerationSeconds)).append("\n");
sb.append(" value: ").append(toIndentedString(value)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
public static HashSet openapiFields;
public static HashSet openapiRequiredFields;
static {
// a set of all properties/fields (JSON key names)
openapiFields = new HashSet();
openapiFields.add("effect");
openapiFields.add("key");
openapiFields.add("operator");
openapiFields.add("tolerationSeconds");
openapiFields.add("value");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet();
}
/**
* Validates the JSON Element and throws an exception if issues found
*
* @param jsonElement JSON Element
* @throws IOException if the JSON Element is invalid with respect to V1Toleration
*/
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
if (jsonElement == null) {
if (!V1Toleration.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
throw new IllegalArgumentException(String.format("The required field(s) %s in V1Toleration is not found in the empty JSON string", V1Toleration.openapiRequiredFields.toString()));
}
}
Set> entries = jsonElement.getAsJsonObject().entrySet();
// check to see if the JSON string contains additional fields
for (Map.Entry entry : entries) {
if (!V1Toleration.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `V1Toleration` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
}
}
JsonObject jsonObj = jsonElement.getAsJsonObject();
if ((jsonObj.get("effect") != null && !jsonObj.get("effect").isJsonNull()) && !jsonObj.get("effect").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `effect` to be a primitive type in the JSON string but got `%s`", jsonObj.get("effect").toString()));
}
if ((jsonObj.get("key") != null && !jsonObj.get("key").isJsonNull()) && !jsonObj.get("key").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `key` to be a primitive type in the JSON string but got `%s`", jsonObj.get("key").toString()));
}
if ((jsonObj.get("operator") != null && !jsonObj.get("operator").isJsonNull()) && !jsonObj.get("operator").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `operator` to be a primitive type in the JSON string but got `%s`", jsonObj.get("operator").toString()));
}
if ((jsonObj.get("value") != null && !jsonObj.get("value").isJsonNull()) && !jsonObj.get("value").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `value` to be a primitive type in the JSON string but got `%s`", jsonObj.get("value").toString()));
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (!V1Toleration.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'V1Toleration' and its subtypes
}
final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(V1Toleration.class));
return (TypeAdapter) new TypeAdapter() {
@Override
public void write(JsonWriter out, V1Toleration value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public V1Toleration read(JsonReader in) throws IOException {
JsonElement jsonElement = elementAdapter.read(in);
validateJsonElement(jsonElement);
return thisAdapter.fromJsonTree(jsonElement);
}
}.nullSafe();
}
}
/**
* Create an instance of V1Toleration given an JSON string
*
* @param jsonString JSON string
* @return An instance of V1Toleration
* @throws IOException if the JSON string is invalid with respect to V1Toleration
*/
public static V1Toleration fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, V1Toleration.class);
}
/**
* Convert an instance of V1Toleration to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}