Package org.yamcs
Class YamcsServer
- java.lang.Object
-
- org.yamcs.YamcsServer
-
public class YamcsServer extends Object
Yamcs server together with the global instances
-
-
Field Summary
Fields Modifier and Type Field Description static StringCFG_CRASH_HANDLER_KEYstatic StringGLOBAL_INSTANCEstatic intSERVICE_STOP_GRACE_TIMEDuring shutdown, allow services this number of seconds for stopping
-
Constructor Summary
Constructors Constructor Description YamcsServer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCommandOption(CommandOption option)Registers the system-wide availability of aCommandOption.voidaddConfigurationSection(String key, Spec spec)Add the definition of an additional configuration section to the root Yamcs spec (yamcs.yaml).voidaddConfigurationSection(ConfigScope scope, String key, Spec spec)Add the definition of an additional configuration section to a particulat configuration type<T extends YamcsService>
voidaddGlobalService(String name, Class<T> serviceClass, YConfiguration args)voidaddGlobalServicesAndInstances()YamcsServerInstanceaddInstance(String name, InstanceMetadata metadata, boolean offline, YConfiguration config)Creates a new yamcs instance.voidaddInstanceTemplate(Template template)voidaddReadyListener(ReadyListener readyListener)Register a listener that will be called when Yamcs has fully started.YamcsServerInstancecreateInstance(String name, String templateName, Map<String,Object> templateArgs, Map<String,String> labels, Map<String,Object> customMetadata)Create a new instance based on a template.PathgetCacheDirectory()CommandOptiongetCommandOption(String id)Collection<CommandOption>getCommandOptions()Returns the command options registered to this instance.YConfigurationgetConfig()Returns the main Yamcs configurationPathgetConfigDirectory()Map<String,Spec>getConfigurationSections(ConfigScope scope)CrashHandlergetCrashHandler(String yamcsInstance)PathgetDataDirectory()CrashHandlergetGlobalCrashHandler()YamcsServicegetGlobalService(String serviceName)List<ServiceWithConfig>getGlobalServices()<T extends YamcsService>
List<T>getGlobalServices(Class<T> serviceClass)ServiceWithConfiggetGlobalServiceWithConfig(String serviceName)PathgetIncomingDirectory()YamcsServerInstancegetInstance(String yamcsInstance)static List<YamcsServerInstance>getInstances()TemplategetInstanceTemplate(String name)Set<Template>getInstanceTemplates()PluginManagergetPluginManager()ProcessorgetProcessor(String yamcsInstance, String processorName)byte[]getSecretKey()SecurityStoregetSecurityStore()static YamcsServergetServer()StringgetServerId()The serverId has to be unique among Yamcs servers connected to eachother.<T extends YamcsService>
List<T>getServices(String yamcsInstance, Class<T> serviceClass)SpecgetSpec()Returns the configuration specification for the config returned bygetConfig().ScheduledThreadPoolExecutorgetThreadPoolExecutor()static TimeServicegetTimeService(String yamcsInstance)booleanhasCommandOption(String id)static booleanhasInstance(String instance)booleanhasInstanceTemplate(String template)static voidinitServices(String instance, List<ServiceWithConfig> services)static voidmain(String[] args)voidprepareStart()voidremoveInstance(String instanceName)YamcsServerInstancerestartInstance(String instanceName)Restarts a yamcs instance.static voidsetMockupTimeService(TimeService timeService)voidshutDown()voidstart()voidstartGlobalService(String serviceName)YamcsServerInstancestartInstance(String instanceName)Start the instance.static voidstartServices(List<ServiceWithConfig> serviceList)Starts the specified list of services.YamcsServerInstancestopInstance(String instanceName)Stop the instance (it will be offline after this)voidvalidateMainConfiguration()
-
-
-
Field Detail
-
CFG_CRASH_HANDLER_KEY
public static final String CFG_CRASH_HANDLER_KEY
- See Also:
- Constant Field Values
-
GLOBAL_INSTANCE
public static final String GLOBAL_INSTANCE
- See Also:
- Constant Field Values
-
SERVICE_STOP_GRACE_TIME
public static final int SERVICE_STOP_GRACE_TIME
During shutdown, allow services this number of seconds for stopping- See Also:
- Constant Field Values
-
-
Method Detail
-
initServices
public static void initServices(String instance, List<ServiceWithConfig> services) throws InitException
- Throws:
InitException
-
addGlobalService
public <T extends YamcsService> void addGlobalService(String name, Class<T> serviceClass, YConfiguration args) throws ValidationException, InitException
- Throws:
ValidationExceptionInitException
-
startServices
public static void startServices(List<ServiceWithConfig> serviceList) throws ConfigurationException
Starts the specified list of services.- Parameters:
serviceList- list of service configurations- Throws:
ConfigurationException
-
shutDown
public void shutDown()
-
hasInstance
public static boolean hasInstance(String instance)
-
hasInstanceTemplate
public boolean hasInstanceTemplate(String template)
-
getServerId
public String getServerId()
The serverId has to be unique among Yamcs servers connected to eachother.It is used to distinguish the data generated by one particular server.
- Returns:
-
getSecretKey
public byte[] getSecretKey()
-
addCommandOption
@Experimental public void addCommandOption(CommandOption option)
Registers the system-wide availability of aCommandOption. Command options represent additional arguments that commands may require, but that are not used by Yamcs in building telecommand binary.An example use case would be a custom TC
Linkthat may support additional arguments for controlling its behaviour.While not enforced we recommend to call this method from a
Plugin.onLoad(YConfiguration)hook as this will avoid registering an option multiple times (attempts to do so would generate an error).- Parameters:
option- the new command option.
-
getCommandOptions
public Collection<CommandOption> getCommandOptions()
Returns the command options registered to this instance.
-
hasCommandOption
public boolean hasCommandOption(String id)
-
getCommandOption
public CommandOption getCommandOption(String id)
-
getConfig
public YConfiguration getConfig()
Returns the main Yamcs configuration
-
getSpec
public Spec getSpec()
Returns the configuration specification for the config returned bygetConfig().
-
restartInstance
public YamcsServerInstance restartInstance(String instanceName) throws IOException
Restarts a yamcs instance.- Parameters:
instanceName- the name of the instance- Returns:
- the newly created instance
- Throws:
IOException
-
stopInstance
public YamcsServerInstance stopInstance(String instanceName) throws IOException
Stop the instance (it will be offline after this)- Parameters:
instanceName- the name of the instance- Returns:
- the instance
- Throws:
IOException
-
removeInstance
public void removeInstance(String instanceName) throws IOException
- Throws:
IOException
-
startInstance
public YamcsServerInstance startInstance(String instanceName) throws IOException
Start the instance. If the instance is already started, do nothing. If the instance is FAILED, restart the instance If the instance is OFFLINE, rename the <instance>.yaml.offline to <instance>.yaml and start the instance- Parameters:
instanceName- the name of the instance- Returns:
- the instance
- Throws:
IOException
-
getPluginManager
public PluginManager getPluginManager()
-
addConfigurationSection
public void addConfigurationSection(String key, Spec spec)
Add the definition of an additional configuration section to the root Yamcs spec (yamcs.yaml).- Parameters:
key- the name of this section. This represent a direct subkey of the main app configspec- the specification of this configuration section.
-
addConfigurationSection
public void addConfigurationSection(ConfigScope scope, String key, Spec spec)
Add the definition of an additional configuration section to a particulat configuration type- Parameters:
scope- the scope where this section belongs. When using file-based configuration this can be thought of as the type of the configuration file.key- the name of this section. This represent a direct subkey of the main app configspec- the specification of this configuration section.
-
getConfigurationSections
public Map<String,Spec> getConfigurationSections(ConfigScope scope)
-
addInstance
public YamcsServerInstance addInstance(String name, InstanceMetadata metadata, boolean offline, YConfiguration config)
Creates a new yamcs instance. If the instance already exists an IllegalArgumentException is thrown- Parameters:
name- the name of the new instancemetadata- the metadata associated to this instance (labels or other attributes)offline- if true, the instance will be created offline and it does not need a configconfig- the configuration for this instance (equivalent of yamcs.instance.yaml)- Returns:
- the newly created instance
-
createInstance
public YamcsServerInstance createInstance(String name, String templateName, Map<String,Object> templateArgs, Map<String,String> labels, Map<String,Object> customMetadata) throws IOException
Create a new instance based on a template.- Parameters:
name- the name of the instancetemplateName- the name of an available templatetemplateArgs- arguments to use while processing the templatelabels- labels associated to this instancecustomMetadata- custom metadata associated with this instance.- Returns:
- the newly create instance
- Throws:
IOException- when a disk operation failed
-
getInstances
public static List<YamcsServerInstance> getInstances()
-
getInstance
public YamcsServerInstance getInstance(String yamcsInstance)
-
getTimeService
public static TimeService getTimeService(String yamcsInstance)
-
getSecurityStore
public SecurityStore getSecurityStore()
-
getGlobalServices
public List<ServiceWithConfig> getGlobalServices()
-
getGlobalServiceWithConfig
public ServiceWithConfig getGlobalServiceWithConfig(String serviceName)
-
getServices
public <T extends YamcsService> List<T> getServices(String yamcsInstance, Class<T> serviceClass)
-
setMockupTimeService
public static void setMockupTimeService(TimeService timeService)
-
getGlobalService
public YamcsService getGlobalService(String serviceName)
-
getGlobalServices
public <T extends YamcsService> List<T> getGlobalServices(Class<T> serviceClass)
-
startGlobalService
public void startGlobalService(String serviceName) throws ConfigurationException, ValidationException, InitException
-
getCrashHandler
public CrashHandler getCrashHandler(String yamcsInstance)
-
getGlobalCrashHandler
public CrashHandler getGlobalCrashHandler()
-
getConfigDirectory
public Path getConfigDirectory()
-
getDataDirectory
public Path getDataDirectory()
-
getIncomingDirectory
public Path getIncomingDirectory()
-
getCacheDirectory
public Path getCacheDirectory()
-
addReadyListener
public void addReadyListener(ReadyListener readyListener)
Register a listener that will be called when Yamcs has fully started. If you register a listener after Yamcs has already started, your callback will not be executed.
-
getServer
public static YamcsServer getServer()
- Returns:
- the (singleton) server
-
main
public static void main(String[] args)
-
prepareStart
public void prepareStart() throws ValidationException, IOException, InitException
-
validateMainConfiguration
public void validateMainConfiguration() throws ValidationException- Throws:
ValidationException
-
start
public void start() throws PluginException- Throws:
PluginException
-
addInstanceTemplate
public void addInstanceTemplate(Template template)
-
addGlobalServicesAndInstances
public void addGlobalServicesAndInstances() throws IOException, ValidationException, InitException
-
getThreadPoolExecutor
public ScheduledThreadPoolExecutor getThreadPoolExecutor()
-
-