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 String
CFG_CRASH_HANDLER_KEY
static String
GLOBAL_INSTANCE
static int
SERVICE_STOP_GRACE_TIME
During 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 void
addCommandOption(CommandOption option)
Registers the system-wide availability of aCommandOption
.void
addConfigurationSection(String key, Spec spec)
Add the definition of an additional configuration section to the root Yamcs spec (yamcs.yaml).void
addConfigurationSection(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)
void
addGlobalServicesAndInstances()
YamcsServerInstance
addInstance(String name, InstanceMetadata metadata, boolean offline, YConfiguration config)
Creates a new yamcs instance.void
addInstanceTemplate(Template template)
void
addReadyListener(ReadyListener readyListener)
Register a listener that will be called when Yamcs has fully started.YamcsServerInstance
createInstance(String name, String templateName, Map<String,Object> templateArgs, Map<String,String> labels, Map<String,Object> customMetadata)
Create a new instance based on a template.Path
getCacheDirectory()
CommandOption
getCommandOption(String id)
Collection<CommandOption>
getCommandOptions()
Returns the command options registered to this instance.YConfiguration
getConfig()
Returns the main Yamcs configurationPath
getConfigDirectory()
Map<String,Spec>
getConfigurationSections(ConfigScope scope)
CrashHandler
getCrashHandler(String yamcsInstance)
Path
getDataDirectory()
CrashHandler
getGlobalCrashHandler()
YamcsService
getGlobalService(String serviceName)
List<ServiceWithConfig>
getGlobalServices()
<T extends YamcsService>
List<T>getGlobalServices(Class<T> serviceClass)
ServiceWithConfig
getGlobalServiceWithConfig(String serviceName)
Path
getIncomingDirectory()
YamcsServerInstance
getInstance(String yamcsInstance)
static List<YamcsServerInstance>
getInstances()
Template
getInstanceTemplate(String name)
Set<Template>
getInstanceTemplates()
PluginManager
getPluginManager()
Processor
getProcessor(String yamcsInstance, String processorName)
byte[]
getSecretKey()
SecurityStore
getSecurityStore()
static YamcsServer
getServer()
String
getServerId()
The serverId has to be unique among Yamcs servers connected to eachother.<T extends YamcsService>
List<T>getServices(String yamcsInstance, Class<T> serviceClass)
Spec
getSpec()
Returns the configuration specification for the config returned bygetConfig()
.ScheduledThreadPoolExecutor
getThreadPoolExecutor()
static TimeService
getTimeService(String yamcsInstance)
boolean
hasCommandOption(String id)
static boolean
hasInstance(String instance)
boolean
hasInstanceTemplate(String template)
static void
initServices(String instance, List<ServiceWithConfig> services)
static void
main(String[] args)
void
prepareStart()
void
removeInstance(String instanceName)
YamcsServerInstance
restartInstance(String instanceName)
Restarts a yamcs instance.static void
setMockupTimeService(TimeService timeService)
void
shutDown()
void
start()
void
startGlobalService(String serviceName)
YamcsServerInstance
startInstance(String instanceName)
Start the instance.static void
startServices(List<ServiceWithConfig> serviceList)
Starts the specified list of services.YamcsServerInstance
stopInstance(String instanceName)
Stop the instance (it will be offline after this)void
validateMainConfiguration()
-
-
-
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:
ValidationException
InitException
-
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
Link
that 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()
-
-