diff --git a/Source/com/Communicator.h b/Source/com/Communicator.h index 107053c1d..655bae973 100644 --- a/Source/com/Communicator.h +++ b/Source/com/Communicator.h @@ -965,7 +965,7 @@ namespace RPC { ContainerConfig() : Core::JSON::Container() - , ContainerType(ProcessContainers::IContainer::LXC) + , ContainerType(ProcessContainers::IContainer::DEFAULT) #ifdef __DEBUG__ , ContainerPath() #endif diff --git a/Source/extensions/processcontainers/ContainerAdministrator.cpp b/Source/extensions/processcontainers/ContainerAdministrator.cpp index 92c1475c8..18d723364 100644 --- a/Source/extensions/processcontainers/ContainerAdministrator.cpp +++ b/Source/extensions/processcontainers/ContainerAdministrator.cpp @@ -1,4 +1,4 @@ -/* +/* * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * @@ -52,10 +52,16 @@ namespace ProcessContainers { container.Add(value.Data(), &specific); container.FromString(configuration); + if ((specific.IsSet() == false) && (_producers.size() == 1)) { + // Looks like the configuration for this provider is not specified, however there is only one container + // system available, so let's forward the entire config (perhaps it's a legacy config file). + specific = configuration; + } + TRACE(Trace::Information, (_T("Initializing container runtime system '%s'..."), value.Data())); // Pass the configuration to the runtime - const uint32_t initResult = runtime.second->Initialize(specific); + const uint32_t initResult = runtime.second->Initialize(specific.Value()); if (initResult != Core::ERROR_NONE) { TRACE(Trace::Error, (_T("Initialization failure"))); @@ -63,6 +69,33 @@ namespace ProcessContainers { } } + if (_producers.empty() == true) { + SYSLOG(Logging::Error, (_T("No container runtime systems are available!"))); + } + else if (_producers.size() == 1) { + // Since there is only one provider available, make it the default one + _default = _producers.cbegin()->first; + } + else { + Core::JSON::EnumType defaultProducer; + Core::JSON::Container config; + config.Add(_T("default"), &defaultProducer); + config.FromString(configuration); + + if (defaultProducer.IsSet() == true) { + _default = defaultProducer.Value(); + ASSERT(_default != IContainer::DEFAULT); + ASSERT(_producers.find(_default) != _producers.end()); + + const Core::EnumerateType value(_default); + DEBUG_VARIABLE(value); + TRACE(Trace::Information, (_T("Default container runtime is '%s'"), value.Data())); + } + else { + TRACE(Trace::Information, (_T("Default container runtime is not set"))); + } + } + _adminLock.Unlock(); return (result); @@ -86,27 +119,35 @@ namespace ProcessContainers { _adminLock.Lock(); - auto it = _producers.find(type); + const IContainer::containertype containerType = (type == IContainer::DEFAULT? _default : type); + + if (containerType != IContainer::DEFAULT) { - const Core::EnumerateType value(type); - DEBUG_VARIABLE(value); + auto it = _producers.find(containerType); - ASSERT(value.IsSet() == true); + const Core::EnumerateType value(containerType); + DEBUG_VARIABLE(value); - if (it != _producers.end()) { + ASSERT(value.IsSet() == true); + + if (it != _producers.end()) { - auto& runtime = (*it).second; - ASSERT(runtime != nullptr); + auto& runtime = (*it).second; + ASSERT(runtime != nullptr); - container = runtime->Container(id, searchPaths, logPath, configuration); + container = runtime->Container(id, searchPaths, logPath, configuration); - if (container.IsValid() == true) { - TRACE(Trace::Information, (_T("Container '%s' created successfully (runtime system '%s')"), - container->Id().c_str(), value.Data())); + if (container.IsValid() == true) { + TRACE(Trace::Information, (_T("Container '%s' created successfully (runtime system '%s')"), + container->Id().c_str(), value.Data())); + } + } + else { + TRACE(Trace::Error, (_T("Container runtime system '%s' is not enabled!"), value.Data())); } } else { - TRACE(Trace::Error, (_T("Container runtime system '%s' is not enabled!"), value.Data())); + TRACE(Trace::Error, (_T("Container runtime system not specified for '%s'"), id.c_str())); } _adminLock.Unlock(); @@ -143,4 +184,4 @@ namespace ProcessContainers { } } // namespace ProcessContainers -} \ No newline at end of file +} diff --git a/Source/extensions/processcontainers/ContainerAdministrator.h b/Source/extensions/processcontainers/ContainerAdministrator.h index d4409a80f..e63c4eac7 100644 --- a/Source/extensions/processcontainers/ContainerAdministrator.h +++ b/Source/extensions/processcontainers/ContainerAdministrator.h @@ -34,6 +34,9 @@ namespace ProcessContainers { ContainerAdministrator() : _adminLock() + , _producers() + , _containers() + , _default(IContainer::DEFAULT) { } @@ -107,6 +110,7 @@ namespace ProcessContainers { mutable Core::CriticalSection _adminLock; std::map _producers; Core::ProxyListType _containers; + IContainer::containertype _default; }; } // namespace ProcessContainers diff --git a/Source/extensions/processcontainers/IProcessContainers.h b/Source/extensions/processcontainers/IProcessContainers.h index 264f279b7..139734cb8 100644 --- a/Source/extensions/processcontainers/IProcessContainers.h +++ b/Source/extensions/processcontainers/IProcessContainers.h @@ -74,6 +74,7 @@ namespace ProcessContainers { struct IContainer { enum containertype : uint8_t { + DEFAULT, LXC, RUNC, CRUN,