ContainerAdmin::ContainerAdmin(ContainerConfig& config)
: mConfig(config), mDom(utils::readFileContent(mConfig.config)), mId(getDomainName(mDom.get()))
{
+ LOGD(mId << ": Instantiating ContainerAdmin object");
}
ContainerAdmin::~ContainerAdmin()
{
// Try to shutdown
+ LOGD(mId << ": Destroying ContainerAdmin object...");
try {
shutdown();
} catch (ServerException& e) {}
try {
stop();
} catch (ServerException& e) {
- LOGE("Failed to destroy the container!");
+ LOGE(mId << ": Failed to destroy the container!");
}
+
+ LOGD(mId << ": ContainerAdmin object destroyed");
}
{
assert(mDom);
+ LOGD(mId << ": Starting...");
if (isRunning()) {
+ LOGD(mId << ": Already running - nothing to do...");
return;
}
u_int flags = VIR_DOMAIN_START_AUTODESTROY;
if (virDomainCreateWithFlags(mDom.get(), flags) < 0) {
- LOGE("Failed to start the domain:\n"
- << libvirt::libvirtFormatError(mId));
+ LOGE(mId << ": Failed to start the domain\n"
+ << libvirt::libvirtFormatError());
throw DomainOperationException();
}
+ LOGD(mId << ": Started");
// TODO: the container should be started in the background,
// unfortunately libvirt doesn't allow us to set cgroups
// before the start, hence we do it immediately afterwards
+ LOGD(mId << ": Sending to the background");
setSchedulerLevel(SchedulerLevel::BACKGROUND);
}
{
assert(mDom);
+ LOGD(mId << ": Stopping...");
if (isStopped()) {
+ LOGD(mId << ": Already crashed/down/off - nothing to do...");
return;
}
u_int flags = VIR_DOMAIN_DESTROY_DEFAULT;
if (virDomainDestroyFlags(mDom.get(), flags) < 0) {
- LOGE("Error while stopping the domain:\n"
- << libvirt::libvirtFormatError(mId));
+ LOGE(mId << ": Error while stopping the domain:\n"
+ << libvirt::libvirtFormatError());
throw DomainOperationException();
}
+
+ LOGD(mId << ": Stopped");
}
{
assert(mDom);
+ LOGD(mId << ": Shutting down...");
if (isStopped()) {
+ LOGD(mId << ": Already crashed/down/off - nothing to do...");
return;
}
resume();
if (virDomainShutdown(mDom.get()) < 0) {
- LOGE("Error while shutting down the domain:\n"
- << libvirt::libvirtFormatError(mId));
+ LOGE(mId << ": Error while shutting down the domain:\n"
+ << libvirt::libvirtFormatError());
throw DomainOperationException();
}
+
+ LOGD(mId << ": Shut down");
}
{
assert(mDom);
+ LOGD(mId << ": Pausing...");
if (isPaused()) {
+ LOGD(mId << ": Already paused - nothing to do...");
return;
}
if (virDomainSuspend(mDom.get()) < 0) {
- LOGE("Error while suspending the domain:\n"
- << libvirt::libvirtFormatError(mId));
+ LOGE(mId << ": Error while suspending the domain:\n"
+ << libvirt::libvirtFormatError());
throw DomainOperationException();
}
+
+ LOGD(mId << ": Paused");
}
{
assert(mDom);
+ LOGD(mId << ": Resuming...");
if (!isPaused()) {
+ LOGD(mId << ": Is not paused - nothing to do...");
return;
}
if (virDomainResume(mDom.get()) < 0) {
- LOGE("Error while resumming the domain:\n"
- << libvirt::libvirtFormatError(mId));
+ LOGE(mId << ": Error while resuming the domain:\n"
+ << libvirt::libvirtFormatError());
throw DomainOperationException();
}
+
+ LOGD(mId << ": Resumed");
}
int state;
if (virDomainGetState(mDom.get(), &state, NULL, 0)) {
- LOGE("Error whilte getting the domain's state:\n"
- << libvirt::libvirtFormatError(mId));
+ LOGE(mId << ": Error while getting the domain's state:\n"
+ << libvirt::libvirtFormatError());
throw DomainOperationException();
}
{
switch (sched) {
case SchedulerLevel::FOREGROUND:
+ LOGD(mId << ": Setting SchedulerLevel::FOREGROUND");
setSchedulerParams(DEFAULT_CPU_SHARES,
DEFAULT_VCPU_PERIOD_MS,
mConfig.cpuQuotaForeground);
break;
case SchedulerLevel::BACKGROUND:
+ LOGD(mId << ": Setting SchedulerLevel::BACKGROUND");
setSchedulerParams(DEFAULT_CPU_SHARES,
DEFAULT_VCPU_PERIOD_MS,
mConfig.cpuQuotaBackground);
virTypedParamsAddLLong(¶msTmp, &numParamsBuff, &maxParams, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA, vcpuQuota);
if (virDomainSetSchedulerParameters(mDom.get(), params.get(), numParamsBuff) < 0) {
- LOGE("Error whilte setting the domain's scheduler params:\n"
- << libvirt::libvirtFormatError(mId));
+ LOGE(mId << ": Error while setting the domain's scheduler params:\n"
+ << libvirt::libvirtFormatError());
throw DomainOperationException();
}
}
std::unique_ptr<char, void(*)(void*)> type(virDomainGetSchedulerType(mDom.get(), &numParamsBuff), free);
if (type == NULL || numParamsBuff <= 0 || strcmp(type.get(), "posix") != 0) {
- LOGE("Error while getting the domain's scheduler type:\n"
- << libvirt::libvirtFormatError(mId));
+ LOGE(mId << ": Error while getting the domain's scheduler type:\n"
+ << libvirt::libvirtFormatError());
throw DomainOperationException();
}
std::unique_ptr<virTypedParameter[]> params(new virTypedParameter[numParamsBuff]);
if (virDomainGetSchedulerParameters(mDom.get(), params.get(), &numParamsBuff) < 0) {
- LOGE("Error while getting the domain's scheduler params:\n"
- << libvirt::libvirtFormatError(mId));
+ LOGE(mId << ": Error while getting the domain's scheduler params:\n"
+ << libvirt::libvirtFormatError());
throw DomainOperationException();
}
numParamsBuff,
VIR_DOMAIN_SCHEDULER_VCPU_QUOTA,
"a) <= 0) {
- LOGE("Error while getting the domain's scheduler quota param:\n"
- << libvirt::libvirtFormatError(mId));
+ LOGE(mId << ": Error while getting the domain's scheduler quota param:\n"
+ << libvirt::libvirtFormatError());
throw DomainOperationException();
}
ContainersManager::ContainersManager(const std::string& managerConfigPath)
{
+ LOGD("Instantiating ContainersManager object...");
mConfig.parseFile(managerConfigPath);
for (auto& containerConfig : mConfig.containerConfigs) {
containerConfigPath = utils::createFilePath(baseConfigPath, "/", containerConfig);
}
- LOGT("Creating Container " << containerConfigPath);
+ LOGD("Creating Container " << containerConfigPath);
std::unique_ptr<Container> c(new Container(containerConfigPath));
std::string id = c->getId();
mContainers.emplace(id, std::move(c));
}
+
+ LOGD("ContainersManager object instantiated");
}
ContainersManager::~ContainersManager()
{
+ LOGD("Destroying ContainersManager object...");
try {
stopAll();
} catch (ServerException& e) {
LOGE("Failed to stop all of the containers");
}
+ LOGD("ContainersManager object destroyed");
}
ContainerMap::mapped_type& foregroundContainer = mContainers.at(containerId);
for (auto& container : mContainers) {
+ LOGD(container.second->getId() << ": being sent to background");
container.second->goBackground();
}
mConfig.foregroundId = foregroundContainer->getId();
+ LOGD(mConfig.foregroundId << ": being sent to foreground");
foregroundContainer->goForeground();
}