aboutsummaryrefslogtreecommitdiffstats
path: root/service-monitor/src/main/java/com/yahoo/vespa/service/monitor/ServiceMonitor.java
blob: 463b80435131af15a2df74c2bfa2a9f3c499819e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.service.monitor;

import com.yahoo.vespa.applicationmodel.ApplicationInstance;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceReference;
import com.yahoo.vespa.applicationmodel.HostName;

import java.util.Optional;
import java.util.Set;

/**
 * The service monitor interface. A service monitor provides up to date information about the liveness status
 * (up, down or not known) of each service instance in a Vespa zone
 *
 * @author bratseth
 */
public interface ServiceMonitor {

    /**
     * Returns a ServiceModel which contains the current liveness status (up, down or unknown) of all instances
     * of all services of all clusters of all applications in a zone.
     *
     * <p>Please use the more specific methods below to avoid the cost of this method.</p>
     */
    ServiceModel getServiceModelSnapshot();

    default Set<ApplicationInstanceReference> getAllApplicationInstanceReferences() {
        return getServiceModelSnapshot().getAllApplicationInstances().keySet();
    }

    default Optional<ApplicationInstanceReference> getApplicationInstanceReference(HostName hostname) {
        return getApplication(hostname).map(ApplicationInstance::reference);
    }

    default Optional<ApplicationInstance> getApplication(HostName hostname) {
        return getServiceModelSnapshot().getApplication(hostname);
    }

    default Optional<ApplicationInstance> getApplication(ApplicationInstanceReference reference) {
        return getServiceModelSnapshot().getApplicationInstance(reference);
    }

    default Optional<ApplicationInstance> getApplicationNarrowedTo(HostName hostname) {
        return getApplication(hostname);
    }

    /**
     * Get notified of changes to the set of applications, or set of hosts assigned to an application.
     *
     * <p>When notified of model changes, the new model can be accessed through this interface
     * by the listener. The model changes are visible to other threads strictly after the listener
     * has been notified.</p>
     *
     * <p>WARNING: Methods on the listener may be invoked before returning from this method.</p>
     */
    default void registerListener(ServiceHostListener listener) { }
}