1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00
one/include/InformationManager.h

164 lines
4.5 KiB
C
Raw Normal View History

/* -------------------------------------------------------------------------- */
2020-04-30 16:00:02 +03:00
/* Copyright 2002-2020, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#ifndef INFORMATION_MANAGER_H_
#define INFORMATION_MANAGER_H_
#include "DriverManager.h"
#include "ActionManager.h"
#include "ProtocolMessages.h"
2020-05-15 17:15:52 +03:00
#include "RaftManager.h"
class HostPool;
class Host;
class VirtualMachinePool;
class InformationManager :
public DriverManager<Driver<im_msg_t>>,
public ActionListener
{
public:
InformationManager(
HostPool * _hpool,
VirtualMachinePool * _vmpool,
const std::string& mad_location)
: DriverManager(mad_location)
, hpool(_hpool)
, vmpool(_vmpool)
{
am.addListener(this);
}
~InformationManager() = default;
/**
* This functions starts the associated listener thread, and creates a
* new thread for the Information Manager. This thread will wait in
* an action loop till it receives ACTION_FINALIZE.
* @return 0 on success.
*/
int start();
/**
* Join the action loop thread
*/
void join_thread()
{
return im_thread.join();
};
/**
*
*/
void finalize()
{
am.finalize();
};
/**
* Sends a STOPMONITR command to the associated driver and host
* @param hid the host id
* @param name of the host
* @param im_mad the driver name
*/
void stop_monitor(int hid,
const std::string& name,
const std::string& im_mad);
/**
* Starts the monitor process on the host
* @param host to monitor
* @param update_remotes to copy the monitor probes to the host
* @return 0 on success
*/
int start_monitor(Host * host, bool update_remotes);
/**
* Send host info to monitor
*/
void update_host(Host *host);
/**
* Send host delete message to monitor
*/
void delete_host(int hid);
2020-05-15 17:15:52 +03:00
/**
* Set raft status, send info to monitor daemon
*/
void raft_status(RaftManager::State raft);
protected:
/**
* Received undefined message -> print error
*/
static void _undefined(std::unique_ptr<im_msg_t> msg);
/**
* Message HOST_STATE update from monitor
*/
void _host_state(std::unique_ptr<im_msg_t> msg);
/**
2020-04-23 21:07:16 +03:00
* Message HOST_SYSTEM update from monitor
*/
void _host_system(std::unique_ptr<im_msg_t> msg);
/**
* Message VM_STATE from monitor
*/
void _vm_state(std::unique_ptr<im_msg_t> msg);
private:
/**
* Thread for the Information Manager
*/
std::thread im_thread;
/**
* Pointer to the Host Pool
*/
HostPool * hpool;
/**
* Pointer to the Host Pool
*/
VirtualMachinePool * vmpool;
/**
* Action engine for the Manager
*/
ActionManager am;
/**
* Default timeout to wait for Information Driver (monitord)
*/
static const int drivers_timeout = 10;
// ------------------------------------------------------------------------
// ActioListener Interface
// ------------------------------------------------------------------------
void finalize_action(const ActionRequest& ar) override
{
NebulaLog::log("InM",Log::INFO,"Stopping Information Manager...");
stop(drivers_timeout);
};
};
#endif /*VIRTUAL_MACHINE_MANAGER_H*/