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

com.azure.resourcemanager.servicefabricmanagedclusters.models.ServiceLoadMetric Maven / Gradle / Ivy

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.servicefabricmanagedclusters.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;

/**
 * Specifies a metric to load balance a service during runtime.
 */
@Fluent
public final class ServiceLoadMetric implements JsonSerializable {
    /*
     * The name of the metric. If the service chooses to report load during runtime, the load metric name should match
     * the name that is specified in Name exactly. Note that metric names are case sensitive.
     */
    private String name;

    /*
     * The service load metric relative weight, compared to other metrics configured for this service, as a number.
     */
    private ServiceLoadMetricWeight weight;

    /*
     * Used only for Stateful services. The default amount of load, as a number, that this service creates for this
     * metric when it is a Primary replica.
     */
    private Integer primaryDefaultLoad;

    /*
     * Used only for Stateful services. The default amount of load, as a number, that this service creates for this
     * metric when it is a Secondary replica.
     */
    private Integer secondaryDefaultLoad;

    /*
     * Used only for Stateless services. The default amount of load, as a number, that this service creates for this
     * metric.
     */
    private Integer defaultLoad;

    /**
     * Creates an instance of ServiceLoadMetric class.
     */
    public ServiceLoadMetric() {
    }

    /**
     * Get the name property: The name of the metric. If the service chooses to report load during runtime, the load
     * metric name should match the name that is specified in Name exactly. Note that metric names are case sensitive.
     * 
     * @return the name value.
     */
    public String name() {
        return this.name;
    }

    /**
     * Set the name property: The name of the metric. If the service chooses to report load during runtime, the load
     * metric name should match the name that is specified in Name exactly. Note that metric names are case sensitive.
     * 
     * @param name the name value to set.
     * @return the ServiceLoadMetric object itself.
     */
    public ServiceLoadMetric withName(String name) {
        this.name = name;
        return this;
    }

    /**
     * Get the weight property: The service load metric relative weight, compared to other metrics configured for this
     * service, as a number.
     * 
     * @return the weight value.
     */
    public ServiceLoadMetricWeight weight() {
        return this.weight;
    }

    /**
     * Set the weight property: The service load metric relative weight, compared to other metrics configured for this
     * service, as a number.
     * 
     * @param weight the weight value to set.
     * @return the ServiceLoadMetric object itself.
     */
    public ServiceLoadMetric withWeight(ServiceLoadMetricWeight weight) {
        this.weight = weight;
        return this;
    }

    /**
     * Get the primaryDefaultLoad property: Used only for Stateful services. The default amount of load, as a number,
     * that this service creates for this metric when it is a Primary replica.
     * 
     * @return the primaryDefaultLoad value.
     */
    public Integer primaryDefaultLoad() {
        return this.primaryDefaultLoad;
    }

    /**
     * Set the primaryDefaultLoad property: Used only for Stateful services. The default amount of load, as a number,
     * that this service creates for this metric when it is a Primary replica.
     * 
     * @param primaryDefaultLoad the primaryDefaultLoad value to set.
     * @return the ServiceLoadMetric object itself.
     */
    public ServiceLoadMetric withPrimaryDefaultLoad(Integer primaryDefaultLoad) {
        this.primaryDefaultLoad = primaryDefaultLoad;
        return this;
    }

    /**
     * Get the secondaryDefaultLoad property: Used only for Stateful services. The default amount of load, as a number,
     * that this service creates for this metric when it is a Secondary replica.
     * 
     * @return the secondaryDefaultLoad value.
     */
    public Integer secondaryDefaultLoad() {
        return this.secondaryDefaultLoad;
    }

    /**
     * Set the secondaryDefaultLoad property: Used only for Stateful services. The default amount of load, as a number,
     * that this service creates for this metric when it is a Secondary replica.
     * 
     * @param secondaryDefaultLoad the secondaryDefaultLoad value to set.
     * @return the ServiceLoadMetric object itself.
     */
    public ServiceLoadMetric withSecondaryDefaultLoad(Integer secondaryDefaultLoad) {
        this.secondaryDefaultLoad = secondaryDefaultLoad;
        return this;
    }

    /**
     * Get the defaultLoad property: Used only for Stateless services. The default amount of load, as a number, that
     * this service creates for this metric.
     * 
     * @return the defaultLoad value.
     */
    public Integer defaultLoad() {
        return this.defaultLoad;
    }

    /**
     * Set the defaultLoad property: Used only for Stateless services. The default amount of load, as a number, that
     * this service creates for this metric.
     * 
     * @param defaultLoad the defaultLoad value to set.
     * @return the ServiceLoadMetric object itself.
     */
    public ServiceLoadMetric withDefaultLoad(Integer defaultLoad) {
        this.defaultLoad = defaultLoad;
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (name() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException("Missing required property name in model ServiceLoadMetric"));
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(ServiceLoadMetric.class);

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("name", this.name);
        jsonWriter.writeStringField("weight", this.weight == null ? null : this.weight.toString());
        jsonWriter.writeNumberField("primaryDefaultLoad", this.primaryDefaultLoad);
        jsonWriter.writeNumberField("secondaryDefaultLoad", this.secondaryDefaultLoad);
        jsonWriter.writeNumberField("defaultLoad", this.defaultLoad);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of ServiceLoadMetric from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of ServiceLoadMetric if the JsonReader was pointing to an instance of it, or null if it was
     * pointing to JSON null.
     * @throws IllegalStateException If the deserialized JSON object was missing any required properties.
     * @throws IOException If an error occurs while reading the ServiceLoadMetric.
     */
    public static ServiceLoadMetric fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            ServiceLoadMetric deserializedServiceLoadMetric = new ServiceLoadMetric();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("name".equals(fieldName)) {
                    deserializedServiceLoadMetric.name = reader.getString();
                } else if ("weight".equals(fieldName)) {
                    deserializedServiceLoadMetric.weight = ServiceLoadMetricWeight.fromString(reader.getString());
                } else if ("primaryDefaultLoad".equals(fieldName)) {
                    deserializedServiceLoadMetric.primaryDefaultLoad = reader.getNullable(JsonReader::getInt);
                } else if ("secondaryDefaultLoad".equals(fieldName)) {
                    deserializedServiceLoadMetric.secondaryDefaultLoad = reader.getNullable(JsonReader::getInt);
                } else if ("defaultLoad".equals(fieldName)) {
                    deserializedServiceLoadMetric.defaultLoad = reader.getNullable(JsonReader::getInt);
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedServiceLoadMetric;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy