mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-25 02:50:08 +03:00
parent
532228cb14
commit
83f61b02cc
@ -58,6 +58,15 @@ public:
|
||||
*/
|
||||
int dump_log(std::string &xml_log);
|
||||
|
||||
/**
|
||||
* Get the execution log using a given where clause
|
||||
* @param where_clause where cluase of the SQL query
|
||||
* @param xml_log execution records in XML format
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump_log(const std::string &where_clause, std::string &xml_log);
|
||||
|
||||
/**
|
||||
* Adds a new execution record to the hook
|
||||
* @param hkid the ID of the hook
|
||||
|
@ -35,7 +35,7 @@ protected:
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vrouterpool();
|
||||
pool = nd.get_hkpool();
|
||||
|
||||
auth_object = PoolObjectSQL::HOOK;
|
||||
};
|
||||
|
@ -600,4 +600,26 @@ public:
|
||||
~HookPoolInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HookLogInfo : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
HookLogInfo():
|
||||
RequestManagerPoolInfoFilter("one.hooklog.info",
|
||||
"Returns the hook pool log info",
|
||||
"A:siiii")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hkpool();
|
||||
auth_object = PoolObjectSQL::HOOK;
|
||||
};
|
||||
|
||||
~HookLogInfo(){};
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1761,7 +1761,8 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/opennebula/acl_pool.rb \
|
||||
src/oca/ruby/opennebula/vntemplate_pool.rb \
|
||||
src/oca/ruby/opennebula/vntemplate.rb \
|
||||
src/oca/ruby/opennebula/hook_pool.rb \
|
||||
src/oca/ruby/opennebula/hook.rb"
|
||||
src/oca/ruby/opennebula/hook.rb \
|
||||
src/oca/ruby/opennebula/hook_log.rb"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Common Cloud Files
|
||||
|
@ -93,6 +93,34 @@ int HookLog::_dump_log(int hkid, int exec_id, std::string &xml_log)
|
||||
return rc;
|
||||
}
|
||||
|
||||
int HookLog::dump_log(const std::string &where_clause, std::string &xml_log)
|
||||
{
|
||||
std::ostringstream cmd;
|
||||
|
||||
string_cb cb(1);
|
||||
|
||||
cmd << "SELECT body FROM "<< table;
|
||||
|
||||
if (!where_clause.empty())
|
||||
{
|
||||
cmd << " WHERE " << where_clause;
|
||||
}
|
||||
|
||||
cmd << " ORDER BY hkid DESC";
|
||||
|
||||
xml_log.append("<HOOKLOG>");
|
||||
|
||||
cb.set_callback(&xml_log);
|
||||
|
||||
int rc = db->exec_rd(cmd, &cb);
|
||||
|
||||
cb.unset_callback();
|
||||
|
||||
xml_log.append("</HOOKLOG>");
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HookLog::dump_log(int hkid, std::string &xml_log)
|
||||
|
@ -69,6 +69,7 @@ require 'opennebula/vntemplate'
|
||||
require 'opennebula/vntemplate_pool'
|
||||
require 'opennebula/hook'
|
||||
require 'opennebula/hook_pool'
|
||||
require 'opennebula/hook_log'
|
||||
|
||||
module OpenNebula
|
||||
|
||||
|
70
src/oca/ruby/opennebula/hook_log.rb
Normal file
70
src/oca/ruby/opennebula/hook_log.rb
Normal file
@ -0,0 +1,70 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2019, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'opennebula/xml_utils'
|
||||
|
||||
module OpenNebula
|
||||
|
||||
# Class representing the HookLog
|
||||
class HookLog < XMLPool
|
||||
|
||||
#######################################################################
|
||||
# Constants and Class attribute accessors
|
||||
#######################################################################
|
||||
|
||||
HOOK_LOG_METHODS = {
|
||||
:info => 'hooklog.info'
|
||||
}
|
||||
|
||||
ROOT_NAME = 'HOOKLOG'
|
||||
|
||||
#######################################################################
|
||||
# Class constructor & Methods
|
||||
#######################################################################
|
||||
|
||||
# +client+ a Client object that represents an XML-RPC connection
|
||||
def initialize(client)
|
||||
super(nil)
|
||||
|
||||
@client = client
|
||||
end
|
||||
|
||||
# Factory method to create HookLog objects
|
||||
def factory(element_xml)
|
||||
OpenNebula::HookLog.new(element_xml, @client)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# XML-RPC Methods for the HookLog object
|
||||
#######################################################################
|
||||
|
||||
def info(min_ts, max_ts, hook_id, rc)
|
||||
rc = @client.call(HOOK_LOG_METHODS[:info], min_ts, max_ts, hook_id, rc)
|
||||
|
||||
if !OpenNebula.is_error?(rc)
|
||||
initialize_xml(rc, ROOT_NAME)
|
||||
|
||||
rc = nil
|
||||
end
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
alias :info! info
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -583,6 +583,9 @@ void RequestManager::register_xml_methods()
|
||||
// Hook methods
|
||||
xmlrpc_c::methodPtr hook_retry(new HookRetry());
|
||||
|
||||
//HookLog methods
|
||||
xmlrpc_c::methodPtr hooklog_info(new HookLogInfo());
|
||||
|
||||
/* VM related methods */
|
||||
RequestManagerRegistry.addMethod("one.vm.deploy", vm_deploy);
|
||||
RequestManagerRegistry.addMethod("one.vm.action", vm_action);
|
||||
@ -1225,6 +1228,8 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.hook.retry", hook_retry);
|
||||
RequestManagerRegistry.addMethod("one.hookpool.info", hookpool_info);
|
||||
|
||||
/* Hook Log related methods */
|
||||
RequestManagerRegistry.addMethod("one.hooklog.info", hooklog_info);
|
||||
|
||||
/* System related methods */
|
||||
RequestManagerRegistry.addMethod("one.system.version", system_version);
|
||||
|
@ -629,3 +629,99 @@ void MarketPlacePoolInfo::request_execute(
|
||||
{
|
||||
dump(att, ALL, -1, -1, "", "");
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void HookLogInfo::request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int min_ts = xmlrpc_c::value_int(_paramList.getInt(1));
|
||||
int max_ts = xmlrpc_c::value_int(_paramList.getInt(2));
|
||||
int hook_id = xmlrpc_c::value_int(_paramList.getInt(3));
|
||||
int rc_hook = xmlrpc_c::value_int(_paramList.getInt(4));
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
HookLog* hklog = nd.get_hl();
|
||||
|
||||
PoolObjectAuth hk_perms;
|
||||
|
||||
ostringstream oss;
|
||||
bool empty = true;
|
||||
|
||||
int rc;
|
||||
|
||||
string dump_xml;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Check permissions */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
// TODO
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Build where clause */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
if (min_ts >= 0)
|
||||
{
|
||||
if (!empty)
|
||||
{
|
||||
oss << " AND ";
|
||||
}
|
||||
|
||||
oss << "timestamp > " << min_ts;
|
||||
empty = false;
|
||||
}
|
||||
if (max_ts >= 0)
|
||||
{
|
||||
if (!empty)
|
||||
{
|
||||
oss << " AND ";
|
||||
}
|
||||
|
||||
oss << "timestamp < " << max_ts;
|
||||
empty = false;
|
||||
}
|
||||
if (hook_id >= 0)
|
||||
{
|
||||
if (!empty)
|
||||
{
|
||||
oss << " AND ";
|
||||
}
|
||||
|
||||
oss << "hkid = " << hook_id;
|
||||
empty = false;
|
||||
}
|
||||
if (rc_hook == -1 || rc_hook == 1)
|
||||
{
|
||||
if (!empty)
|
||||
{
|
||||
oss << " AND ";
|
||||
}
|
||||
|
||||
if (rc_hook == -1)
|
||||
{
|
||||
oss << "rc <> 0";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "rc = 0";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
rc = hklog->dump_log(oss.str(), dump_xml);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
failure_response(INTERNAL, att);
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(dump_xml, att);
|
||||
|
||||
return;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user