Package com.yahoo.vespa.model
Class AbstractService
java.lang.Object
com.yahoo.config.model.producer.AnyConfigProducer
com.yahoo.config.model.producer.TreeConfigProducer<AnyConfigProducer>
com.yahoo.vespa.model.AbstractService
- All Implemented Interfaces:
com.yahoo.config.ConfigInstance.Producer,ConfigProducer,NetworkPortRequestor,Service,Serializable
- Direct Known Subclasses:
ConfigProxy,ConfigSentinel,Configserver,Container,ContentNode,Logd,LogForwarder,Logserver,OpenTelemetryCollector,SearchNode,Slobrok
public abstract class AbstractService
extends TreeConfigProducer<AnyConfigProducer>
implements Service
Superclass for all Processes.
- Author:
- gjoranv
- See Also:
-
Field Summary
FieldsFields inherited from class com.yahoo.config.model.producer.AnyConfigProducer
log -
Constructor Summary
ConstructorsConstructorDescriptionAbstractService(TreeConfigProducer<?> parent, String name) Preferred constructor when building from XML.AbstractService(String name) Only used for testing. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEnvironmentVariable(String nameAndValue) voidaddEnvironmentVariable(String name, Object value) final voidappendJvmOptions(String args) protected Stringstatic <SERVICE extends AbstractService>
voiddistributeCpuSocketAffinity(Collection<SERVICE> services) Distribute affinity on a collection of services.Returns the Affinity of this service if it has.Overridden by subclasses.intThe service HTTP port for health statusgetHost()Returns the physical host resource on which this service runs.Returns the hostname on which this service runs.intgetId()protected intgetIndex(HostResource host) Computes a number that identifies the service on the given host.Optional execution args for this serviceintGets the ports metainfo object.Services that wish that a command should be run before shutdown should return the command here.intgetRelativePort(int i) Computes and returns the i'th port for this service, based on this Service's baseport.com.yahoo.config.model.api.ServiceInfoGet meta information about service.Returns the name that identifies this service for the config-sentinel, never nullGets a service property value mapped to the given key as a String, or null if no such key exists.getServicePropertyString(String key, String defStr) Gets a service property value mapped to the given key as a String, or the value indefStrif no such key exists.Returns the type of service.Must be overridden by services that should be started by config-sentinel.intReturns the desired base port for the first instance of the service type.voidinitService(DeployState deployState) Called by builder class which has not given the host or port in a constructor, hence initService is not yet run for this.booleanfinal voidprependJvmOptions(String args) voidremove()Removes this from the config modelbooleanOverride if the desired base port (returned by getWantedPort()) is the only allowed base port.voidsetAffinity(Affinity affinity) voidsetBasePort(int wantedPort) WARNING: should only be called before initService()voidsetCoreOnOOM(boolean coreOnOOM) voidsetHostResource(HostResource hostResource) final voidsetJvmOptions(String args) voidsetMMapNoCoreLimit(long noCoreLimit) If larger or equal to 0 it mean that explicit mmaps shall not be included in coredump.voidvoidsetPreLoad(String preload) Sets a service property value for the given key.Sets a service property value for the given key.voidvoidvoidtoString()Methods inherited from class com.yahoo.config.model.producer.TreeConfigProducer
addChild, addDescendantService, getChildren, getChildrenByTypeRecursive, getConfigClassLoader, getDescendantServices, removeChild, validateMethods inherited from class com.yahoo.config.model.producer.AnyConfigProducer
addConfigId, addUserConfig, cascadeConfig, currentConfigId, findInheritedClassLoader, getConfigId, getMonitoringService, getParent, getRoot, getSubId, getUserConfigs, hostSystem, mergeUserConfigs, setParent, setUserConfigs, stateIsHostedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.yahoo.vespa.model.ConfigProducer
addUserConfig, cascadeConfig, dump, getChildren, getConfigId, getDescendantServices, getUserConfigs, hostSystem, validateMethods inherited from interface com.yahoo.vespa.model.NetworkPortRequestor
allocatePorts, getConfigId, getPortCountMethods inherited from interface com.yahoo.vespa.model.Service
getLogctlSpecs
-
Field Details
-
portsMeta
The ports metainfo object
-
-
Constructor Details
-
AbstractService
Preferred constructor when building from XML. Use this if you are building in doBuild() in an TreeConfigProducerBuilder. build() will call initService() in that case, after setting hostalias and baseport.- Parameters:
parent- the parent config producer in the model treename- the name of this service
-
AbstractService
Only used for testing. Stay away.- Parameters:
name- the name of this service.
-
-
Method Details
-
defaultPreload
-
remove
public void remove()Description copied from class:AnyConfigProducerRemoves this from the config model- Overrides:
removein classAnyConfigProducer
-
distributeCpuSocketAffinity
public static <SERVICE extends AbstractService> void distributeCpuSocketAffinity(Collection<SERVICE> services) Distribute affinity on a collection of services. Services that are located on the same host will be assigned a specific cpu socket on that host.- Parameters:
services- ACollectionof services of the same type, not necessarily on the same host.
-
initService
Called by builder class which has not given the host or port in a constructor, hence initService is not yet run for this. -
getWantedPort
public int getWantedPort()Returns the desired base port for the first instance of the service type. Returns '0' as default, which means that the service type should use the default port allocation mechanism.- Specified by:
getWantedPortin interfaceNetworkPortRequestor- Returns:
- The desired base port for the first instance of the service type.
-
requiresWantedPort
public boolean requiresWantedPort()Override if the desired base port (returned by getWantedPort()) is the only allowed base port.- Specified by:
requiresWantedPortin interfaceNetworkPortRequestor- Returns:
- false by default
-
getPortsMeta
Gets the ports metainfo object. The service implementation must populate this object in the constructor.- Specified by:
getPortsMetain interfaceService
-
getRelativePort
public int getRelativePort(int i) Computes and returns the i'th port for this service, based on this Service's baseport.- Specified by:
getRelativePortin interfaceService- Parameters:
i- the offset from 'basePort' of the port to return- Returns:
- the i'th port relative to the base port.
- Throws:
IllegalStateException- if i is out of range.
-
getStartupCommand
Must be overridden by services that should be started by config-sentinel. The returned value will be used in config-sentinel configuration. Returns empty by default.- Specified by:
getStartupCommandin interfaceService- Returns:
- empty by default.
-
getPreShutdownCommand
Description copied from interface:ServiceServices 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.- Specified by:
getPreShutdownCommandin interfaceService
-
getServiceName
Returns the name that identifies this service for the config-sentinel, never null- Specified by:
getServiceNamein interfaceNetworkPortRequestor
-
getServiceType
Returns the type of service. This is the class name without the package prefix by default, never null- Specified by:
getServiceTypein interfaceNetworkPortRequestor
-
getHost
Description copied from interface:ServiceReturns the physical host resource on which this service runs. -
getHostName
Description copied from interface:ServiceReturns the hostname on which this service runs.- Specified by:
getHostNamein interfaceService
-
getId
public int getId()- Returns:
- The id (index) of this service on the host where it runs
-
getIndex
Computes a number that identifies the service on the given host. The number of services of the same type (Class) is counted and the number is returned.- Parameters:
host- the host on which the service will run- Returns:
- id number for the given service.
-
getServiceInfo
public com.yahoo.config.model.api.ServiceInfo getServiceInfo()Description copied from interface:ServiceGet meta information about service.- Specified by:
getServiceInfoin interfaceService- Returns:
- an instance of
ServiceInfo
-
setProp
Sets a service property value for the given key.- Parameters:
key- a key used for this propertyvalue- a String value associated with the key- Returns:
- this service
-
setProp
Sets a service property value for the given key.- Parameters:
key- a key used for this propertyvalue- an Integer value associated with the key- Returns:
- this service
-
getServicePropertyString
Gets a service property value mapped to the given key as a String, or null if no such key exists.- Parameters:
key- a key used for lookup in the service properties- Returns:
- the associated String value for the given key, or null
-
getServicePropertyString
Description copied from interface:ServiceGets a service property value mapped to the given key as a String, or the value indefStrif no such key exists.- Specified by:
getServicePropertyStringin interfaceService- Parameters:
key- a key used for lookup in the service propertiesdefStr- default String value returned if no value for key found- Returns:
- the associated String value for the given key
-
getJvmOptions
Optional execution args for this service- Specified by:
getJvmOptionsin interfaceService
-
setJvmOptions
-
appendJvmOptions
-
prependJvmOptions
-
getPreLoad
-
setPreLoad
-
setMMapNoCoreLimit
public void setMMapNoCoreLimit(long noCoreLimit) If larger or equal to 0 it mean that explicit mmaps shall not be included in coredump. -
setCoreOnOOM
public void setCoreOnOOM(boolean coreOnOOM) -
setNoVespaMalloc
-
setVespaMalloc
-
setVespaMallocDebug
-
setVespaMallocDebugStackTrace
-
addEnvironmentVariable
-
addEnvironmentVariable
-
getEnvVars
- Specified by:
getEnvVarsin interfaceService
-
getEnvStringForTesting
-
setBasePort
public void setBasePort(int wantedPort) WARNING: should only be called before initService() -
setHostResource
-
isInitialized
public boolean isInitialized() -
getHealthPort
public int getHealthPort()The service HTTP port for health status- Specified by:
getHealthPortin interfaceService
-
getDefaultMetricDimensions
Overridden by subclasses. List of default dimensions to be added to this services metrics- Specified by:
getDefaultMetricDimensionsin interfaceService- Returns:
- the default dimensions for this service
-
getNumPortsAllocated
public int getNumPortsAllocated() -
getHostResource
-
getAffinity
Description copied from interface:ServiceReturns the Affinity of this service if it has.- Specified by:
getAffinityin interfaceService
-
setAffinity
-
toString
-