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

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

Go to download

This package contains Microsoft Azure SDK for Service Fabric Managed Clusters Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt. Service Fabric Managed Clusters Management Client. Package tag package-2024-04.

There is a newer version: 1.0.0
Show newest version
// 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 ScalingPolicy implements JsonSerializable {
    /*
     * Specifies the mechanism associated with this scaling policy
     */
    private ScalingMechanism scalingMechanism;

    /*
     * Specifies the trigger associated with this scaling policy.
     */
    private ScalingTrigger scalingTrigger;

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

    /**
     * Get the scalingMechanism property: Specifies the mechanism associated with this scaling policy.
     * 
     * @return the scalingMechanism value.
     */
    public ScalingMechanism scalingMechanism() {
        return this.scalingMechanism;
    }

    /**
     * Set the scalingMechanism property: Specifies the mechanism associated with this scaling policy.
     * 
     * @param scalingMechanism the scalingMechanism value to set.
     * @return the ScalingPolicy object itself.
     */
    public ScalingPolicy withScalingMechanism(ScalingMechanism scalingMechanism) {
        this.scalingMechanism = scalingMechanism;
        return this;
    }

    /**
     * Get the scalingTrigger property: Specifies the trigger associated with this scaling policy.
     * 
     * @return the scalingTrigger value.
     */
    public ScalingTrigger scalingTrigger() {
        return this.scalingTrigger;
    }

    /**
     * Set the scalingTrigger property: Specifies the trigger associated with this scaling policy.
     * 
     * @param scalingTrigger the scalingTrigger value to set.
     * @return the ScalingPolicy object itself.
     */
    public ScalingPolicy withScalingTrigger(ScalingTrigger scalingTrigger) {
        this.scalingTrigger = scalingTrigger;
        return this;
    }

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

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

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeJsonField("scalingMechanism", this.scalingMechanism);
        jsonWriter.writeJsonField("scalingTrigger", this.scalingTrigger);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of ScalingPolicy from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of ScalingPolicy 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 ScalingPolicy.
     */
    public static ScalingPolicy fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            ScalingPolicy deserializedScalingPolicy = new ScalingPolicy();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("scalingMechanism".equals(fieldName)) {
                    deserializedScalingPolicy.scalingMechanism = ScalingMechanism.fromJson(reader);
                } else if ("scalingTrigger".equals(fieldName)) {
                    deserializedScalingPolicy.scalingTrigger = ScalingTrigger.fromJson(reader);
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedScalingPolicy;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy