Class AbstractService

All Implemented Interfaces:
com.yahoo.config.ConfigInstance.Producer, ConfigProducer, NetworkPortRequestor, Service, Serializable
Direct Known Subclasses:
ConfigProxy, ConfigSentinel, Configserver, Container, ContentNode, Logd, LogForwarder, Logserver, SearchNode, Slobrok, TransactionLogServer

public abstract class AbstractService extends AbstractConfigProducer<AbstractConfigProducer<?>> implements Service
Superclass for all Processes.
Author:
gjoranv
See Also:
  • Field Details

    • portsMeta

      protected PortsMeta portsMeta
      The ports metainfo object
  • Constructor Details

    • AbstractService

      public AbstractService(AbstractConfigProducer<?> parent, 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 - the parent config producer in the model tree
      name - the name of this service
    • AbstractService

      public AbstractService(String name)
      Only used for testing. Stay away.
      Parameters:
      name - the name of this service.
  • Method Details

    • defaultPreload

      protected String defaultPreload()
    • remove

      public void remove()
      Description copied from class: AbstractConfigProducer
      Removes this from the config model
      Overrides:
      remove in class AbstractConfigProducer<AbstractConfigProducer<?>>
    • 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 - A Collection of services of the same type, not necessarily on the same host.
    • initService

      public void initService(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.
    • 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 interface NetworkPortRequestor
      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 interface NetworkPortRequestor
      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 interface Service
    • 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 interface Service
      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

      public Optional<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 empty by default.
      Specified by:
      getStartupCommand in interface Service
      Returns:
      empty by default.
    • getPreShutdownCommand

      public Optional<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 interface Service
    • getServiceName

      public String getServiceName()
      Returns the name that identifies this service for the config-sentinel, never null
      Specified by:
      getServiceName in interface NetworkPortRequestor
    • getServiceType

      public String getServiceType()
      Returns the type of service. This is the class name without the package prefix by default, never null
      Specified by:
      getServiceType in interface NetworkPortRequestor
    • getHost

      public HostResource getHost()
      Description copied from interface: Service
      Returns the physical host resource on which this service runs.
      Specified by:
      getHost in interface Service
    • getHostName

      public String getHostName()
      Description copied from interface: Service
      Returns the hostname on which this service runs.
      Specified by:
      getHostName in interface Service
    • 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 interface Service
      Returns:
      an instance of ServiceInfo
    • setProp

      public AbstractService setProp(String key, String value)
      Sets a service property value for the given key.
      Parameters:
      key - a key used for this property
      value - a String value associated with the key
      Returns:
      this service
    • setProp

      public AbstractService setProp(String key, Integer value)
      Sets a service property value for the given key.
      Parameters:
      key - a key used for this property
      value - an Integer value associated with the key
      Returns:
      this service
    • getServicePropertyString

      public String getServicePropertyString(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 String getServicePropertyString(String key, String defStr)
      Description copied from interface: Service
      Gets a service property value mapped to the given key as a String, or the value in defStr if no such key exists.
      Specified by:
      getServicePropertyString in interface Service
      Parameters:
      key - a key used for lookup in the service properties
      defStr - default String value returned if no value for key found
      Returns:
      the associated String value for the given key
    • getJvmOptions

      public String getJvmOptions()
      Optional execution args for this service
      Specified by:
      getJvmOptions in interface Service
    • setJvmOptions

      public final void setJvmOptions(String args)
    • appendJvmOptions

      public final void appendJvmOptions(String args)
    • prependJvmOptions

      public final void prependJvmOptions(String args)
    • getPreLoad

      public String getPreLoad()
    • setPreLoad

      public void setPreLoad(String preload)
    • 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

      public void setNoVespaMalloc(String s)
    • setVespaMalloc

      public void setVespaMalloc(String s)
    • setVespaMallocDebug

      public void setVespaMallocDebug(String s)
    • setVespaMallocDebugStackTrace

      public void setVespaMallocDebugStackTrace(String s)
    • addEnvironmentVariable

      public void addEnvironmentVariable(String nameAndValue)
    • addEnvironmentVariable

      public void addEnvironmentVariable(String name, Object value)
    • getEnvVars

      public Map<String,Object> getEnvVars()
      Specified by:
      getEnvVars in interface Service
    • getEnvStringForTesting

      public String getEnvStringForTesting()
    • setBasePort

      public void setBasePort(int wantedPort)
      WARNING: should only be called before initService()
    • setHostResource

      public void setHostResource(HostResource hostResource)
    • isInitialized

      public boolean isInitialized()
    • getHealthPort

      public int getHealthPort()
      The service HTTP port for health status
      Specified by:
      getHealthPort in interface Service
    • getDefaultMetricDimensions

      public HashMap<String,String> getDefaultMetricDimensions()
      Overridden by subclasses. List of default dimensions to be added to this services metrics
      Specified by:
      getDefaultMetricDimensions in interface Service
      Returns:
      the default dimensions for this service
    • getNumPortsAllocated

      public int getNumPortsAllocated()
    • getHostResource

      public HostResource getHostResource()
    • getAffinity

      public Optional<Affinity> getAffinity()
      Description copied from interface: Service
      Returns the Affinity of this service if it has.
      Specified by:
      getAffinity in interface Service
    • setAffinity

      public void setAffinity(Affinity affinity)
    • toString

      public String toString()
      Overrides:
      toString in class Object