Skip to content

Commit

Permalink
[ProcessContainers] Runtime configurable containers
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaszm committed Aug 13, 2024
1 parent 56f9e4a commit 125e8a2
Show file tree
Hide file tree
Showing 27 changed files with 999 additions and 637 deletions.
60 changes: 10 additions & 50 deletions Source/Thunder/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,46 +362,6 @@ namespace PluginHost {
Core::JSON::String PluginConfigPath;
};

#ifdef PROCESSCONTAINERS_ENABLED

class ProcessContainerConfig : public Core::JSON::Container {
public:
ProcessContainerConfig()
: Logging(_T("NONE"))
{

Add(_T("logging"), &Logging);
}
ProcessContainerConfig(const ProcessContainerConfig& copy)
: Logging(copy.Logging)
{
Add(_T("logging"), &Logging);
}
ProcessContainerConfig(ProcessContainerConfig&& move) noexcept
: Logging(std::move(move.Logging))
{
Add(_T("logging"), &Logging);
}
~ProcessContainerConfig() override = default;

ProcessContainerConfig& operator=(const ProcessContainerConfig& RHS)
{
Logging = RHS.Logging;
return (*this);
}
ProcessContainerConfig& operator=(ProcessContainerConfig&& move) noexcept
{
if (this != &move) {
Logging = std::move(move.Logging);
}
return (*this);
}

Core::JSON::String Logging;
};

#endif

#ifdef HIBERNATE_SUPPORT_ENABLED
class HibernateConfig : public Core::JSON::Container {
public:
Expand Down Expand Up @@ -572,7 +532,7 @@ namespace PluginHost {
Core::JSON::DecSInt32 Longitude;
Core::JSON::Boolean DelegatedReleases;
#ifdef PROCESSCONTAINERS_ENABLED
ProcessContainerConfig ProcessContainers;
Core::JSON::String ProcessContainers;
#endif
Core::JSON::ArrayType<Core::JSON::String> LinkerPluginPaths;
Observables Observe;
Expand Down Expand Up @@ -737,13 +697,13 @@ namespace PluginHost {
, _substituter(*this)
, _configLock()
, _delegatedReleases(true)
#ifdef PROCESSCONTAINERS_ENABLED
, _ProcessContainersLogging()
#endif
#ifdef PROCESSCONTAINERS_ENABLED
, _processContainersConfig()
#endif
, _linkerPluginPaths()
#ifdef HIBERNATE_SUPPORT_ENABLED
#ifdef HIBERNATE_SUPPORT_ENABLED
, _hibernateLocator()
#endif
#endif
{
JSONConfig config;

Expand All @@ -754,7 +714,7 @@ namespace PluginHost {
_webPrefix = '/' + _prefix;
_JSONRPCPrefix = '/' + config.JSONRPC.Value();
#ifdef PROCESSCONTAINERS_ENABLED
_ProcessContainersLogging = config.ProcessContainers.Logging.Value();
_processContainersConfig = config.ProcessContainers.Value();
#endif
#ifdef HIBERNATE_SUPPORT_ENABLED
_hibernateLocator = config.Hibernate.Locator.Value();
Expand Down Expand Up @@ -882,8 +842,8 @@ POP_WARNING()
return (_JSONRPCPrefix);
}
#ifdef PROCESSCONTAINERS_ENABLED
inline const string& ProcessContainersLogging() const {
return (_ProcessContainersLogging);
inline const string& ProcessContainersConfig() const {
return (_processContainersConfig);
}
#endif

Expand Down Expand Up @@ -1175,7 +1135,7 @@ POP_WARNING()
bool _delegatedReleases;

#ifdef PROCESSCONTAINERS_ENABLED
string _ProcessContainersLogging;
string _processContainersConfig;
#endif
std::vector<std::string> _linkerPluginPaths;
#ifdef HIBERNATE_SUPPORT_ENABLED
Expand Down
9 changes: 4 additions & 5 deletions Source/Thunder/PluginServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#endif

#ifdef PROCESSCONTAINERS_ENABLED
#include "../processcontainers/ProcessContainer.h"
#include "../processcontainers/processcontainers.h"
#endif

#ifdef HIBERNATE_SUPPORT_ENABLED
Expand Down Expand Up @@ -1175,11 +1175,10 @@ namespace PluginHost {
// Add the controller as a service to the services.
_controller = _services.Insert(metaDataConfig, Service::mode::CONFIGURED);

#ifdef PROCESSCONTAINERS_ENABLED
#ifdef PROCESSCONTAINERS_ENABLED
// turn on ProcessContainer logging
ProcessContainers::IContainerAdministrator& admin = ProcessContainers::IContainerAdministrator::Instance();
admin.Logging(_config.VolatilePath(), configuration.ProcessContainersLogging());
#endif
ProcessContainers::ContainerAdministrator::Instance().Initialize(_config.ProcessContainersConfig());
#endif
}
POP_WARNING()

Expand Down
2 changes: 1 addition & 1 deletion Source/Thunder/PluginServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "PostMortem.h"

#ifdef PROCESSCONTAINERS_ENABLED
#include "../processcontainers/ProcessContainer.h"
#include "../processcontainers/processcontainers.h"
#endif

#ifndef HOSTING_COMPROCESS
Expand Down
9 changes: 5 additions & 4 deletions Source/com/Communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace RPC {
DynamicLoaderPaths& operator=(DynamicLoaderPaths&&) = delete;
DynamicLoaderPaths& operator=(const DynamicLoaderPaths&) = delete;

DynamicLoaderPaths()
DynamicLoaderPaths()
: _downloadLists()
{
ReadList(LoaderConfig, _downloadLists);
Expand Down Expand Up @@ -342,14 +342,15 @@ namespace RPC {

void Communicator::ContainerProcess::Terminate() /* override */
{
ASSERT(_container != nullptr);
g_destructor.Destruct(Id(), *this);
if (_container.IsValid() == true) {
g_destructor.Destruct(Id(), *this);
}
}

void Communicator::ContainerProcess::PostMortem() /* override */
{
Core::process_t pid;
if ( (_container != nullptr) && ((pid = static_cast<Core::process_t>(_container->Pid())) != 0) ) {
if ( (_container.IsValid() == true) && ((pid = static_cast<Core::process_t>(_container->Pid())) != 0) ) {
Core::ProcessInfo process(pid);
process.Dump();
}
Expand Down
59 changes: 37 additions & 22 deletions Source/com/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


#ifdef PROCESSCONTAINERS_ENABLED
#include <processcontainers/ProcessContainer.h>
#include <processcontainers/processcontainers.h>
#endif


Expand Down Expand Up @@ -172,8 +172,9 @@ namespace RPC {
move._version = ~0;
move._threads = 0;
move._priority = 0;
}
return (*this);
}

return (*this);
}

public:
Expand Down Expand Up @@ -823,16 +824,21 @@ namespace RPC {

ContainerConfig()
: Core::JSON::Container()
, ContainerType(ProcessContainers::IContainer::LXC)
#ifdef __DEBUG__
, ContainerPath()
#endif
{
Add(_T("containertype"), &ContainerType);
#ifdef __DEBUG__
Add(_T("containerpath"), &ContainerPath);
#endif
}
~ContainerConfig() = default;

public:
Core::JSON::EnumType<ProcessContainers::IContainer::containertype> ContainerType;

#ifdef __DEBUG__
Core::JSON::String ContainerPath;
#endif
Expand All @@ -850,33 +856,42 @@ namespace RPC {
: MonitorableProcess(instance.Callsign(), parent)
, _process(RemoteConnection::Id(), baseConfig, instance)
{
ProcessContainers::IContainerAdministrator& admin = ProcessContainers::IContainerAdministrator::Instance();

std::vector<string> searchpaths(3);
searchpaths[0] = baseConfig.VolatilePath();
searchpaths[1] = baseConfig.PersistentPath();
searchpaths[2] = baseConfig.DataPath();

#ifdef __DEBUG__
ContainerConfig config;
config.FromString(instance.Configuration());

if (config.ContainerPath.IsSet() == true) {
searchpaths.emplace(searchpaths.cbegin(), config.ContainerPath.Value());
// Fetch container type
Core::OptionalType<Core::JSON::Error> error;
config.FromString(instance.Configuration(), error);

if (error.IsSet() == true) {
TRACE_L1("Invalid process container configuration");
}
else {
std::vector<string> searchPaths(3);

#endif
#ifdef __DEBUG__
if (config.ContainerPath.IsSet() == true) {
searchPaths.push_back(config.ContainerPath.Value());
}
#endif

Core::IteratorType<std::vector<string>, const string> searchpathsit(searchpaths);
searchPaths.push_back(baseConfig.VolatilePath());
searchPaths.push_back(baseConfig.PersistentPath());
searchPaths.push_back(baseConfig.DataPath());

string volatilecallsignpath(baseConfig.VolatilePath() + instance.Callsign() + _T('/'));
_container = admin.Container(instance.Callsign(), searchpathsit, volatilecallsignpath, instance.Configuration());
Core::IteratorType<std::vector<string>, const string> searchPathsIt(searchPaths);

const string volatilePath(Core::Directory::Normalize(baseConfig.VolatilePath() + instance.Callsign()));

_container = ProcessContainers::ContainerAdministrator::Instance().Container(config.ContainerType, instance.Callsign(),
searchPathsIt, volatilePath, instance.Configuration());
}
}

~ContainerProcess() override
{
if (_container != nullptr) {
_container->Release();
printf("Container dead\n");
if (_container.IsValid() == true) {
_container.Release();
}
}

Expand All @@ -885,7 +900,7 @@ namespace RPC {
{
uint32_t result = Core::ERROR_GENERAL;

if (_container != nullptr) {
if (_container.IsValid() == true) {

// Note: replace below code with something more efficient when Iterators redesigned
Core::Process::Options::Iterator it(_process.Options());
Expand Down Expand Up @@ -954,7 +969,7 @@ namespace RPC {
END_INTERFACE_MAP

private:
ProcessContainers::IContainer* _container;
Core::ProxyType<ProcessContainers::IContainer> _container;
Process _process;
};

Expand Down
25 changes: 23 additions & 2 deletions Source/core/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ POP_WARNING()
for (const auto& entry : _map) {
if(callback.Check(entry.first, entry.second.first) == true){
found = true;
break;
break;
}
}
_lock.Unlock();
Expand Down Expand Up @@ -1794,7 +1794,28 @@ POP_WARNING()

return (result);
}

template<typename ACTION>
void Visit(ACTION&& action)
{
_lock.Lock();
for (auto& entry : _list) {
if (action(entry.first) == true) {
break;
}
}
_lock.Unlock();
}
template<typename ACTION>
void Visit(ACTION&& action) const
{
_lock.Lock();
for (auto const& entry : _list) {
if (action(entry.first) == true) {
break;
}
}
_lock.Unlock();
}
void Clear()
{
_lock.Lock();
Expand Down
Loading

0 comments on commit 125e8a2

Please sign in to comment.