Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
DobbyTemplate Class Reference

Singleton class that returns the OCI JSON template. More...

#include <DobbyTemplate.h>

Collaboration diagram for DobbyTemplate:
Collaboration graph
[legend]

Static Public Member Functions

static void setSettings (const std::shared_ptr< const IDobbySettings > &settings)
 Applies the settings to the global template values.
 
static std::string apply (const ctemplate::TemplateDictionaryInterface *dictionary, bool prettyPrint)
 Applies the dictionary to the template.
 
static bool applyAt (int dirFd, const std::string &fileName, const ctemplate::TemplateDictionaryInterface *dictionary, bool prettyPrint)
 Applies the dictionary to the template and writes the output into the file.
 

Private Member Functions

void setTemplateDevNodes (const std::list< std::string > &devNodes)
 Sets up the global template values for the device nodes.
 
void setTemplateEnvVars (const std::map< std::string, std::string > &envVars)
 Converts the envVars map to json formatted string and sets it as the EXTRA_ENV_VARS template value.
 
void setTemplatePlatformEnvVars ()
 Sets the environment variables used to identify the platform.
 
void setTemplateCpuRtSched ()
 Determines if the kernel's CONFIG_RT_GROUP_SCHED is set or not.
 
void _setSettings (const std::shared_ptr< const IDobbySettings > &settings)
 Applies the settings to the global template values.
 
std::string _apply (const ctemplate::TemplateDictionaryInterface *dictionary, bool prettyPrint) const
 Applies the dictionary to the template.
 
bool _applyAt (int dirFd, const std::string &fileName, const ctemplate::TemplateDictionaryInterface *dictionary, bool prettyPrint) const
 Applies the dictionary to the template and writes the output into the file.
 

Static Private Member Functions

static void cleanUp ()
 Called at shutdown time to clean up the singleton.
 
static DobbyTemplateinstance ()
 Returns / creates singleton instance.
 

Private Attributes

const ctemplate::TemplateString mTemplateKey
 
const std::unique_ptr< ctemplate::TemplateCache > mTemplateCache
 
std::map< std::string, std::string > mExtraEnvVars
 

Static Private Attributes

static pthread_rwlock_t mInstanceLock = PTHREAD_RWLOCK_INITIALIZER
 
static DobbyTemplatemInstance = nullptr
 

Detailed Description

Singleton class that returns the OCI JSON template.

Member Function Documentation

◆ _apply()

std::string DobbyTemplate::_apply ( const ctemplate::TemplateDictionaryInterface *  dictionary,
bool  prettyPrint 
) const
private

Applies the dictionary to the template.

Parameters
[in]dictionaryThe dictionary to apply
Returns
the expanded template string

◆ _applyAt()

bool DobbyTemplate::_applyAt ( int  dirFd,
const std::string &  fileName,
const ctemplate::TemplateDictionaryInterface *  dictionary,
bool  prettyPrint 
) const
private

Applies the dictionary to the template and writes the output into the file.

If the pathname given in fileName is relative, then it is interpreted relative to the directory referred to by the file descriptor dirfd. If fileName is relative and dirfd is the special value AT_FDCWD, then fileName is interpreted relative to the current working directory

Parameters
[in]dirFdThe directory of the file.
[in]fileNameThe path to the file to write to.
[in]dictionaryThe dictionary to apply.
Returns
true on success, false on failure.

◆ _setSettings()

void DobbyTemplate::_setSettings ( const std::shared_ptr< const IDobbySettings > &  settings)
private

Applies the settings to the global template values.

This includes settings for the environment variables and GPU.

◆ apply()

std::string DobbyTemplate::apply ( const ctemplate::TemplateDictionaryInterface *  dictionary,
bool  prettyPrint 
)
static

Applies the dictionary to the template.

Parameters
[in]dictionaryThe dictionary to apply
[in]prettyPrintFormat the json file using pretty printer.
Returns
the expanded template string

◆ applyAt()

bool DobbyTemplate::applyAt ( int  dirFd,
const std::string &  fileName,
const ctemplate::TemplateDictionaryInterface *  dictionary,
bool  prettyPrint 
)
static

Applies the dictionary to the template and writes the output into the file.

If the pathname given in fileName is relative, then it is interpreted relative to the directory referred to by the file descriptor dirfd. If fileName is relative and dirfd is the special value AT_FDCWD, then fileName is interpreted relative to the current working directory

Parameters
[in]dirFdThe directory of the file.
[in]fileNameThe path to the file to write to.
[in]dictionaryThe dictionary to apply.
[in]prettyPrintPretty print the json output.
Returns
true on success, false on failure.

◆ cleanUp()

void DobbyTemplate::cleanUp ( )
staticprivate

Called at shutdown time to clean up the singleton.

Callback installed as atexit(), frees the instance pointer.

◆ setTemplateCpuRtSched()

void DobbyTemplate::setTemplateCpuRtSched ( )
private

Determines if the kernel's CONFIG_RT_GROUP_SCHED is set or not.

If CONFIG_RT_GROUP_SCHED is set in the kernel config we need to give all containers a slice of runtime scheduler. So we check if the kernel is configured that way and if it is we enabled CGROUP_RTSCHD_ENABLED section in the template.

◆ setTemplateDevNodes()

void DobbyTemplate::setTemplateDevNodes ( const std::list< std::string > &  devNodes)
private

Sets up the global template values for the device nodes.

Deprecated:
This is now down lazily in the DobbyConfig component when starting the first container that requires the GPU.

Currently the device nodes are only for the xegl/opengl.

We need to get the device numbers from the file system as runc won't do that automatically for us. We could hard code them, but it's perfectly reasonable that they could change between driver releases.

Nb: this feels like the wrong place to be doing this, however for now it is convenient and the most efficient.

◆ setTemplatePlatformEnvVars()

void DobbyTemplate::setTemplatePlatformEnvVars ( )
private

Sets the environment variables used to identify the platform.

All containers get two environment variables that define the platform;

ETHAN_STB_TYPE  = [ "GW" | "MR" | "HIP" ]
ETHAN_STB_MODEL = [ "ES140" | "ES130" | "EM150" | "ES240" | "ESi240" | ... ]

For a list of model names refer to the following confluence page

https://www.stb.bskyb.com/confluence/display/2016/STB+HW+ID

To determine platform we check for the AI_PLATFORM_IDENT environment variable. This should have been set by the user (or upstart script) that started this daemon. If it's not present then we set both templates as empty and log an error.


The documentation for this class was generated from the following files: