Package com.yahoo.vespa.model
Class AbstractService
- java.lang.Object
-
- com.yahoo.config.model.producer.AbstractConfigProducer<AbstractConfigProducer<?>>
-
- com.yahoo.vespa.model.AbstractService
-
- All Implemented Interfaces:
com.yahoo.config.ConfigInstance.Producer
,ConfigProducer
,NetworkPortRequestor
,Service
,java.io.Serializable
- Direct Known Subclasses:
ConfigProxy
,ConfigSentinel
,Configserver
,Container
,ContentNode
,Logd
,LogForwarder
,Logserver
,SearchNode
,Service
,Slobrok
,TransactionLogServer
public abstract class AbstractService extends AbstractConfigProducer<AbstractConfigProducer<?>> implements Service
Superclass for all Processes.- Author:
- gjoranv
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected PortsMeta
portsMeta
The ports metainfo object-
Fields inherited from class com.yahoo.config.model.producer.AbstractConfigProducer
log
-
-
Constructor Summary
Constructors Constructor Description AbstractService(AbstractConfigProducer parent, java.lang.String name)
Preferred constructor when building from XML.AbstractService(java.lang.String name)
Only used for testing.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendJvmOptions(java.lang.String args)
static <SERVICE extends AbstractService>
voiddistributeCpuSocketAffinity(java.util.Collection<SERVICE> services)
Distribute affinity on a collection of services.java.util.Optional<Affinity>
getAffinity()
Return the Affinity of this service if it has.boolean
getCoreOnOOM()
java.lang.String
getCoreOnOOMEnvVariable()
java.util.HashMap<java.lang.String,java.lang.String>
getDefaultMetricDimensions()
Overridden by subclasses.java.lang.String
getEnvVariables()
int
getHealthPort()
The service HTTP port for health statusHost
getHost()
java.lang.String
getHostName()
HostResource
getHostResource()
int
getId()
protected int
getIndex(HostResource host)
Computes a number that identifies the service on the given host.java.lang.String
getJvmOptions()
Optional execution args for this servicejava.lang.String
getMMapNoCoreEnvVariable()
long
getMMapNoCoreLimit()
java.lang.String
getNoVespaMalloc()
java.lang.String
getNoVespaMallocEnvVariable()
int
getNumPortsAllocated()
PortsMeta
getPortsMeta()
Gets the ports metainfo object.java.lang.String
getPreLoad()
java.util.Optional<java.lang.String>
getPreShutdownCommand()
Services that wish that a command should be run before shutdown should return the command here.int
getRelativePort(int i)
Computes and returns the i'th port for this service, based on this Service's baseport.com.yahoo.config.model.api.ServiceInfo
getServiceInfo()
Get meta information about service.java.lang.String
getServiceName()
Returns the name that identifies this service for the config-sentinel, never nulljava.lang.String
getServicePropertyString(java.lang.String key)
Gets a service property value mapped to the given key as a String, or null if no such key exists.java.lang.String
getServicePropertyString(java.lang.String key, java.lang.String defStr)
Gets a service property value mapped to the given key as a String, or the value indefStr
if no such key exists.java.lang.String
getServiceType()
Returns the type of service.java.lang.String
getStartupCommand()
Must be overridden by services that should be started by config-sentinel.java.lang.String
getVespaMalloc()
java.lang.String
getVespaMallocDebug()
java.lang.String
getVespaMallocDebugEnvVariable()
java.lang.String
getVespaMallocDebugStackTrace()
java.lang.String
getVespaMallocDebugStackTraceEnvVariable()
java.lang.String
getVespaMallocEnvVariable()
int
getWantedPort()
Returns the desired base port for the first instance of the service type.void
initService(com.yahoo.config.application.api.DeployLogger deployLogger)
Called by builder class which has not given the host or port in a constructor, hence initService is not yet run for this.boolean
isInitialized()
void
prependJvmOptions(java.lang.String args)
boolean
requiresWantedPort()
Override if the desired base port (returned by getWantedPort()) is the only allowed base port.com.yahoo.config.FileReference
sendFile(java.lang.String relativePath)
Add the given file to the application's file distributor.com.yahoo.config.FileReference
sendUri(java.lang.String uri)
void
setAffinity(Affinity affinity)
void
setBasePort(int wantedPort)
WARNING: should only be called before initService(), otherwise call at own risk!void
setCoreOnOOM(boolean coreOnOOM)
void
setHostResource(HostResource hostResource)
void
setJvmOptions(java.lang.String args)
void
setMMapNoCoreLimit(long noCoreLimit)
void
setNoVespaMalloc(java.lang.String s)
void
setPreLoad(java.lang.String preload)
AbstractService
setProp(java.lang.String key, java.lang.Integer value)
Sets a service property value for the given key.AbstractService
setProp(java.lang.String key, java.lang.String value)
Sets a service property value for the given key.void
setVespaMalloc(java.lang.String s)
void
setVespaMallocDebug(java.lang.String s)
void
setVespaMallocDebugStackTrace(java.lang.String s)
java.lang.String
toString()
-
Methods inherited from class com.yahoo.config.model.producer.AbstractConfigProducer
addChild, addConfigId, addDescendantService, addUserConfig, cascadeConfig, dump, getChildren, getChildrenByTypeRecursive, getConfigClassLoader, getConfigId, getDescendantServices, getMonitoringService, getParent, getRoot, getSubId, getUserConfigs, hostSystem, mergeUserConfigs, removeChild, setParent, setUserConfigs, stateIsHosted, validate
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.yahoo.vespa.model.ConfigProducer
addUserConfig, cascadeConfig, dump, getChildren, getConfigId, getDescendantServices, getUserConfigs, hostSystem, validate
-
Methods inherited from interface com.yahoo.vespa.model.NetworkPortRequestor
allocatePorts, getConfigId, getPortCount
-
-
-
-
Field Detail
-
portsMeta
protected PortsMeta portsMeta
The ports metainfo object
-
-
Constructor Detail
-
AbstractService
public AbstractService(AbstractConfigProducer parent, java.lang.String name)
Preferred constructor when building from XML. Use this if you are building in doBuild() in an AbstractConfigProducerBuilder. build() will call initService() in that case, after setting hostalias and baseport.- Parameters:
parent
- Parent config producer in the model tree.name
- Name of this service.
-
AbstractService
public AbstractService(java.lang.String name)
Only used for testing. Stay away.- Parameters:
name
- Name of this service.
-
-
Method Detail
-
distributeCpuSocketAffinity
public static <SERVICE extends AbstractService> void distributeCpuSocketAffinity(java.util.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
- ACollection
of services of the same type, not necessarily on the same host.
-
initService
public void initService(com.yahoo.config.application.api.DeployLogger deployLogger)
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:
getWantedPort
in 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:
requiresWantedPort
in interfaceNetworkPortRequestor
- Returns:
- false by default
-
getPortsMeta
public PortsMeta getPortsMeta()
Gets the ports metainfo object. The service implementation must populate this object in the constructor.- Specified by:
getPortsMeta
in 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:
getRelativePort
in interfaceService
- Parameters:
i
- The offset from 'basePort' of the port to return- Returns:
- the i'th port relative to the base port.
- Throws:
java.lang.IllegalStateException
- if i is out of range.
-
getStartupCommand
public java.lang.String getStartupCommand()
Must be overridden by services that should be started by config-sentinel. The returned value will be used in config-sentinel configuration. Returns null by default.- Specified by:
getStartupCommand
in interfaceService
- Returns:
- null by default.
-
getPreShutdownCommand
public java.util.Optional<java.lang.String> getPreShutdownCommand()
Description copied from interface:Service
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.- Specified by:
getPreShutdownCommand
in interfaceService
-
getServiceName
public java.lang.String getServiceName()
Returns the name that identifies this service for the config-sentinel, never null- Specified by:
getServiceName
in interfaceNetworkPortRequestor
-
getServiceType
public java.lang.String getServiceType()
Returns the type of service. This is the class name without the package prefix by default, never null- Specified by:
getServiceType
in interfaceNetworkPortRequestor
-
getHost
public Host getHost()
-
getHostName
public java.lang.String getHostName()
- Specified by:
getHostName
in interfaceService
- Returns:
- The hostname on which this service runs.
-
getId
public int getId()
- Returns:
- The id (index) of this service on the host where it runs
-
getIndex
protected int getIndex(HostResource host)
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:Service
Get meta information about service.- Specified by:
getServiceInfo
in interfaceService
- Returns:
- an instance of
ServiceInfo
-
setProp
public AbstractService setProp(java.lang.String key, java.lang.String value)
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
public AbstractService setProp(java.lang.String key, java.lang.Integer value)
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
public java.lang.String getServicePropertyString(java.lang.String key)
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
public java.lang.String getServicePropertyString(java.lang.String key, java.lang.String defStr)
Description copied from interface:Service
Gets a service property value mapped to the given key as a String, or the value indefStr
if no such key exists.- Specified by:
getServicePropertyString
in 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, or
-
getJvmOptions
public java.lang.String getJvmOptions()
Optional execution args for this service- Specified by:
getJvmOptions
in interfaceService
-
setJvmOptions
public final void setJvmOptions(java.lang.String args)
-
appendJvmOptions
public final void appendJvmOptions(java.lang.String args)
-
prependJvmOptions
public final void prependJvmOptions(java.lang.String args)
-
getPreLoad
public java.lang.String getPreLoad()
-
setPreLoad
public void setPreLoad(java.lang.String preload)
-
getMMapNoCoreLimit
public long getMMapNoCoreLimit()
-
setMMapNoCoreLimit
public void setMMapNoCoreLimit(long noCoreLimit)
-
getCoreOnOOM
public boolean getCoreOnOOM()
-
setCoreOnOOM
public void setCoreOnOOM(boolean coreOnOOM)
-
getNoVespaMalloc
public java.lang.String getNoVespaMalloc()
-
getVespaMalloc
public java.lang.String getVespaMalloc()
-
getVespaMallocDebug
public java.lang.String getVespaMallocDebug()
-
getVespaMallocDebugStackTrace
public java.lang.String getVespaMallocDebugStackTrace()
-
setNoVespaMalloc
public void setNoVespaMalloc(java.lang.String s)
-
setVespaMalloc
public void setVespaMalloc(java.lang.String s)
-
setVespaMallocDebug
public void setVespaMallocDebug(java.lang.String s)
-
setVespaMallocDebugStackTrace
public void setVespaMallocDebugStackTrace(java.lang.String s)
-
getMMapNoCoreEnvVariable
public java.lang.String getMMapNoCoreEnvVariable()
-
getCoreOnOOMEnvVariable
public java.lang.String getCoreOnOOMEnvVariable()
-
getNoVespaMallocEnvVariable
public java.lang.String getNoVespaMallocEnvVariable()
-
getVespaMallocEnvVariable
public java.lang.String getVespaMallocEnvVariable()
-
getVespaMallocDebugEnvVariable
public java.lang.String getVespaMallocDebugEnvVariable()
-
getVespaMallocDebugStackTraceEnvVariable
public java.lang.String getVespaMallocDebugStackTraceEnvVariable()
-
getEnvVariables
public java.lang.String getEnvVariables()
-
setBasePort
public void setBasePort(int wantedPort)
WARNING: should only be called before initService(), otherwise call at own risk!
-
setHostResource
public void setHostResource(HostResource hostResource)
-
isInitialized
public boolean isInitialized()
-
sendFile
public com.yahoo.config.FileReference sendFile(java.lang.String relativePath)
Add the given file to the application's file distributor.- Parameters:
relativePath
- path to the file, relative to the app package.- Returns:
- the file reference hash
-
sendUri
public com.yahoo.config.FileReference sendUri(java.lang.String uri)
-
getHealthPort
public int getHealthPort()
The service HTTP port for health status- Specified by:
getHealthPort
in interfaceService
- Returns:
- portnumber
-
getDefaultMetricDimensions
public java.util.HashMap<java.lang.String,java.lang.String> getDefaultMetricDimensions()
Overridden by subclasses. List of default dimensions to be added to this services metrics- Specified by:
getDefaultMetricDimensions
in interfaceService
- Returns:
- The default dimensions for this service
-
getNumPortsAllocated
public int getNumPortsAllocated()
-
getHostResource
public HostResource getHostResource()
-
getAffinity
public java.util.Optional<Affinity> getAffinity()
Description copied from interface:Service
Return the Affinity of this service if it has.- Specified by:
getAffinity
in interfaceService
- Returns:
- The
Affinity
for this service.
-
setAffinity
public void setAffinity(Affinity affinity)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-