summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/Service.java
blob: 29ec26b06d2b0c92923b367d695a942919741dda (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model;

import com.yahoo.config.model.api.ServiceInfo;

import java.util.HashMap;
import java.util.Optional;

/**
 * Representation of a markProcessed which runs a service
 *
 * @author gjoranv
 */
public interface Service extends ConfigProducer {

    /**
     * Services that should be started by config-sentinel must return
     * non-null. The returned value will be used in config-sentinel
     * configuration.
     * TODO: Should change this to Optional of String
     */
    String getStartupCommand();

    /**
     * Services that wish that a command should be run before shutdown
     * should return the command here. The command will be executed
     * by the config sentinel before sending SIGTERM to the service.
     * The command is executed without a timeout.
     */
    Optional<String> getPreShutdownCommand();

    /**
     * Tells if this service should be autostarted by
     * config-sentinel. Returned value will be used to configure the
     * config-sentinel.
     */
    boolean getAutostartFlag();

    /**
     * Tells if this service should be autorestarted by
     * config-sentinel. Returned value will be used to configure the
     * config-sentinel.
     */
    boolean getAutorestartFlag();

    /**
     * Returns the type of service. E.g. the class-name without the
     * package prefix.
     */
    String getServiceType();

   /**
     * Returns the name that identifies this service for the config-sentinel.
     */
    String getServiceName();

    /**
     * Returns the desired base port for this service, or '0' if this
     * service should use the default port allocation mechanism.
     *
     * @return The desired base port for this service.
     */
    int getWantedPort();

    /**
     * Returns true if the desired base port (returned by
     * getWantedPort()) for this service is the only allowed base
     * port.
     *
     * @return true if this Service requires the wanted base port.
     */
    boolean requiresWantedPort();

    /**
     * Returns the number of ports needed by this service.
     */
    int getPortCount();

    /**
     * Returns a PortsMeta object, giving access to more information
     * about the different ports of this service.
     */
    PortsMeta getPortsMeta();

    /**
     * @return the physical host on which this service runs.
     */
    Host getHost();

    /**
     * Get meta information about service.
     * @return an instance of {@link com.yahoo.config.model.api.ServiceInfo}
     */
    ServiceInfo getServiceInfo();

    /**
     * @return The hostname on which this service runs.
     */
    String getHostName();

    /** Optional JVM execution args for this service */
    String getJvmArgs();

    /**
     * Computes and returns the i'th port for this service, based on
     * this Service's baseport.
     *
     * @param i The offset from 'basePort' of the port to return
     * @return the i'th port relative to the base port.
     * @throws IllegalStateException if i is out of range.
     */
    int getRelativePort(int i);

    /**
     * Gets a service property value mapped to the given key
     * as a String, or the value in <code>defStr</code> if no such key exists.
     *
     * @param key    a key used for lookup in the service properties
     * @param defStr default String value returned if no value for key found
     * @return the associated String value for the given key, or
     */
    String getServicePropertyString(String key, String defStr);

    int getHealthPort();

    /**
     *
     * @return HashMap of default dimensions for metrics.
     */
    HashMap<String,String> getDefaultMetricDimensions();

    /**
     * Return the Affinity of this service if it has.
     *
     * @return The {@link com.yahoo.vespa.model.Affinity} for this service.
     */
    Optional<Affinity> getAffinity();

}