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

com.yahoo.vespa.hosted.controller.routing.RoutingStatus Maven / Gradle / Ivy

There is a newer version: 8.253.3
Show newest version
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.routing;

import java.time.Instant;
import java.util.Objects;

/**
 * Represents the routing status of a {@link RoutingPolicy} or {@link ZoneRoutingPolicy}.
 *
 * This describes which agent last changed the routing status and at which time.
 *
 * This is immutable.
 *
 * @author mpolden
 */
public class RoutingStatus {

    public static final RoutingStatus DEFAULT = new RoutingStatus(Value.in, Agent.system, Instant.EPOCH);

    private final Value value;
    private final Agent agent;
    private final Instant changedAt;

    /** DO NOT USE. Public for serialization purposes */
    public RoutingStatus(Value value, Agent agent, Instant changedAt) {
        this.value = Objects.requireNonNull(value, "value must be non-null");
        this.agent = Objects.requireNonNull(agent, "agent must be non-null");
        this.changedAt = Objects.requireNonNull(changedAt, "changedAt must be non-null");
    }

    /**
     * The wanted value of this. The system will try to set this value, but there are constraints that may lead to
     * the effective value not matching this. See {@link RoutingPolicies}.
     */
    public Value value() {
        return value;
    }

    /** The agent who last changed this */
    public Agent agent() {
        return agent;
    }

    /** The time this was last changed */
    public Instant changedAt() {
        return changedAt;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RoutingStatus that = (RoutingStatus) o;
        return value == that.value &&
               agent == that.agent &&
               changedAt.equals(that.changedAt);
    }

    @Override
    public int hashCode() {
        return Objects.hash(value, agent, changedAt);
    }

    @Override
    public String toString() {
        return "status " + value + ", changed by " + agent + " @ " + changedAt;
    }

    public static RoutingStatus create(Value value, Agent agent, Instant instant) {
        return new RoutingStatus(value, agent, instant);
    }

    // Used in serialization. Do not change.
    public enum Value {
        /** Status is determined by health checks **/
        in,

        /** Status is explicitly set to out */
        out,
    }

    /** Agents that can change the state of global routing */
    public enum Agent {
        operator,
        tenant,
        system,
        unknown, // For compatibility old values from /routing/v1 on config server, which may contain a specific username.
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy