-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ProcessContainers] Update Dobby implementation #1771
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
accfe34
[ProcessContainers] Update Dobby implementation
sebaszm 163ce57
Merge branch 'master' into development/dobby-sync
MFransen69 c6b16ef
Remove commented out InternalLock calls
sebaszm d98ed83
Remove notice
sebaszm c322740
Merge branch 'master' into development/dobby-sync
sebaszm 91f6998
Merge branch 'master' into development/dobby-sync
MFransen69 00bc00e
Merge branch 'master' into development/dobby-sync
MFransen69 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,12 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
|
||
#include "processcontainers/Messaging.h" | ||
#include "processcontainers/ContainerProducer.h" | ||
#include "processcontainers/ContainerAdministrator.h" | ||
#include "processcontainers/common/CGroupContainerInfo.h" | ||
|
||
#include "DobbyImplementation.h" | ||
#include <Dobby/DobbyProxy.h> | ||
#include <Dobby/IpcService/IpcFactory.h> | ||
|
@@ -26,31 +32,22 @@ | |
namespace Thunder { | ||
|
||
namespace ProcessContainers { | ||
// Container administrator | ||
// ---------------------------------- | ||
IContainerAdministrator& ProcessContainers::IContainerAdministrator::Instance() | ||
{ | ||
static DobbyContainerAdministrator& dobbyContainerAdministrator = Core::SingletonType<DobbyContainerAdministrator>::Instance(); | ||
|
||
return dobbyContainerAdministrator; | ||
} | ||
|
||
IContainer* DobbyContainerAdministrator::Container(const string& id, IStringIterator& searchpaths, const string& logpath, const string& configuration VARIABLE_IS_NOT_USED) | ||
Core::ProxyType<IContainer> DobbyContainerAdministrator::Container(const string& id, IStringIterator& searchpaths, | ||
const string& logpath, const string& configuration VARIABLE_IS_NOT_USED) | ||
{ | ||
searchpaths.Reset(0); | ||
while (searchpaths.Next()) { | ||
auto path = searchpaths.Current(); | ||
|
||
auto createContainer = [&](bool useSpecFile, const string &path) -> IContainer* { | ||
auto createContainer = [&](bool useSpecFile, const string &path) -> Core::ProxyType<IContainer> { | ||
// Make sure no leftover will interfere... | ||
if (ContainerNameTaken(id)) { | ||
DestroyContainer(id); | ||
} | ||
this->InternalLock(); | ||
DobbyContainer* container = new DobbyContainer(id, path, logpath, useSpecFile); | ||
InsertContainer(container); | ||
this->InternalUnlock(); | ||
|
||
Core::ProxyType<IContainer> container; | ||
container = ContainerAdministrator::Instance().Create<DobbyContainer>(*this, id, path, logpath, useSpecFile); | ||
return container; | ||
}; | ||
|
||
|
@@ -71,17 +68,16 @@ namespace ProcessContainers { | |
|
||
TRACE(Trace::Error, (_T("Could not find suitable container config for %s in any search path"), id.c_str())); | ||
|
||
return nullptr; | ||
return Core::ProxyType<IContainer>(); | ||
} | ||
|
||
DobbyContainerAdministrator::DobbyContainerAdministrator() | ||
: BaseContainerAdministrator() | ||
uint32_t DobbyContainerAdministrator::Initialize(const string& config VARIABLE_IS_NOT_USED) | ||
{ | ||
mIpcService = AI_IPC::createIpcService("unix:path=/var/run/dbus/system_bus_socket", "org.rdk.dobby.processcontainers"); | ||
|
||
if (!mIpcService) { | ||
TRACE(Trace::Error, (_T("Failed to create Dobby IPC service"))); | ||
return; | ||
return Core::ERROR_GENERAL; | ||
} else { | ||
// Start the IPCService which kicks off the event dispatcher thread | ||
mIpcService->start(); | ||
|
@@ -90,15 +86,15 @@ namespace ProcessContainers { | |
// Create a DobbyProxy remote service that wraps up the dbus API | ||
// calls to the Dobby daemon | ||
mDobbyProxy = std::make_shared<DobbyProxy>(mIpcService, DOBBY_SERVICE, DOBBY_OBJECT); | ||
} | ||
|
||
DobbyContainerAdministrator::~DobbyContainerAdministrator() | ||
{ | ||
return Core::ERROR_NONE; | ||
} | ||
|
||
void DobbyContainerAdministrator::Logging(const string& logPath VARIABLE_IS_NOT_USED, const string& loggingOptions VARIABLE_IS_NOT_USED) | ||
void DobbyContainerAdministrator::Deinitialize() | ||
{ | ||
// Only container-scope logging | ||
mDobbyProxy.reset(); | ||
mIpcService->stop(); | ||
mIpcService.reset(); | ||
} | ||
|
||
void DobbyContainerAdministrator::DestroyContainer(const string& name) | ||
|
@@ -115,7 +111,7 @@ namespace ProcessContainers { | |
|
||
// Dobby stop is async - block until we get the notification the container | ||
// has actually stopped | ||
this->InternalLock(); | ||
// this->InternalLock(); | ||
|
||
_stopPromise = std::promise<void>(); | ||
const void* vp = static_cast<void*>(new std::string(name)); | ||
|
@@ -139,7 +135,7 @@ namespace ProcessContainers { | |
} | ||
} | ||
|
||
this->InternalUnlock(); | ||
// this->InternalUnlock(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this line as well |
||
|
||
// Always make sure we unregister our callback | ||
mDobbyProxy->unregisterListener(listenerId); | ||
|
@@ -186,8 +182,9 @@ namespace ProcessContainers { | |
|
||
// Container | ||
// ------------------------------------ | ||
DobbyContainer::DobbyContainer(const string& name, const string& path, const string& logPath, bool useSpecFile) | ||
DobbyContainer::DobbyContainer(DobbyContainerAdministrator& admin, const string& name, const string& path, const string& logPath, const bool useSpecFile) | ||
: _adminLock() | ||
, _admin(admin) | ||
, _name(name) | ||
, _path(path) | ||
, _logPath(logPath) | ||
|
@@ -199,13 +196,9 @@ namespace ProcessContainers { | |
|
||
DobbyContainer::~DobbyContainer() | ||
{ | ||
auto& admin = static_cast<DobbyContainerAdministrator&>(DobbyContainerAdministrator::Instance()); | ||
|
||
if (admin.ContainerNameTaken(_name) == true) { | ||
if (_admin.ContainerNameTaken(_name) == true) { | ||
Stop(Core::infinite); | ||
} | ||
|
||
admin.RemoveContainer(this); | ||
} | ||
|
||
const string& DobbyContainer::Id() const | ||
|
@@ -216,10 +209,9 @@ namespace ProcessContainers { | |
uint32_t DobbyContainer::Pid() const | ||
{ | ||
uint32_t returnedPid = 0; | ||
auto& admin = static_cast<DobbyContainerAdministrator&>(DobbyContainerAdministrator::Instance()); | ||
|
||
if (_pid.IsSet() == false) { | ||
std::string containerInfoString = admin.mDobbyProxy->getContainerInfo(_descriptor); | ||
std::string containerInfoString = _admin.mDobbyProxy->getContainerInfo(_descriptor); | ||
|
||
if (containerInfoString.empty()) { | ||
TRACE(Trace::Warning, (_T("Failed to get info for container %s"), _name.c_str())); | ||
|
@@ -315,10 +307,9 @@ namespace ProcessContainers { | |
bool DobbyContainer::IsRunning() const | ||
{ | ||
bool result = false; | ||
auto& admin = static_cast<DobbyContainerAdministrator&>(DobbyContainerAdministrator::Instance()); | ||
|
||
// We got a state back successfully, work out what that means in English | ||
switch (static_cast<IDobbyProxyEvents::ContainerState>(admin.mDobbyProxy->getContainerState(_descriptor))) { | ||
switch (static_cast<IDobbyProxyEvents::ContainerState>(_admin.mDobbyProxy->getContainerState(_descriptor))) { | ||
case IDobbyProxyEvents::ContainerState::Invalid: | ||
result = false; | ||
break; | ||
|
@@ -350,8 +341,6 @@ namespace ProcessContainers { | |
bool result = false; | ||
|
||
_adminLock.Lock(); | ||
auto& admin = static_cast<DobbyContainerAdministrator&>(DobbyContainerAdministrator::Instance()); | ||
|
||
std::list<int> emptyList; | ||
|
||
// construct the full command to run with all the arguments | ||
|
@@ -372,9 +361,9 @@ namespace ProcessContainers { | |
std::string containerSpecString = specFileStream.str(); | ||
TRACE(ProcessContainers::ProcessContainerization, (_T("container spec string: %s"), containerSpecString.c_str())); | ||
|
||
_descriptor = admin.mDobbyProxy->startContainerFromSpec(_name, containerSpecString , emptyList, fullCommand); | ||
_descriptor = _admin.mDobbyProxy->startContainerFromSpec(_name, containerSpecString , emptyList, fullCommand); | ||
} else { | ||
_descriptor = admin.mDobbyProxy->startContainerFromBundle(_name, _path, emptyList, fullCommand); | ||
_descriptor = _admin.mDobbyProxy->startContainerFromBundle(_name, _path, emptyList, fullCommand); | ||
} | ||
// startContainer returns -1 on failure | ||
if (_descriptor <= 0) { | ||
|
@@ -395,9 +384,8 @@ namespace ProcessContainers { | |
bool result = false; | ||
|
||
_adminLock.Lock(); | ||
auto& admin = static_cast<DobbyContainerAdministrator&>(DobbyContainerAdministrator::Instance()); | ||
|
||
bool stoppedSuccessfully = admin.mDobbyProxy->stopContainer(_descriptor, false); | ||
bool stoppedSuccessfully = _admin.mDobbyProxy->stopContainer(_descriptor, false); | ||
|
||
if (!stoppedSuccessfully) { | ||
TRACE(Trace::Error, (_T("Failed to stop container, internal Dobby error. id: %s descriptor: %d"), _name.c_str(), _descriptor)); | ||
|
@@ -409,6 +397,9 @@ namespace ProcessContainers { | |
return result; | ||
} | ||
|
||
// FACTORY REGISTRATION | ||
static ContainerProducerRegistrationType<DobbyContainerAdministrator, IContainer::containertype::DOBBY> registration; | ||
|
||
} // namespace ProcessContainers | ||
|
||
} // namespace Thunder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please remove this line if it's not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InternalLock() was used to protect the internal list of created containers, which is now handled outside of container provider implementations (since there can be multiple providers). Therefore the InternalLock() method has been removed altogether.
In this context there container list was not modified, so using this lock was not required. But, perhaps, it was reused for a different purpose, so it was only commented out - as a remark, because it may need reviewing whether a critical section is indeed needed here.
I will remove this, since the original purpose of InternalLock is gone.