mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-09 14:03:20 +09:00
feature #4217: Implements monitor action for marketplace. Sample monitor
driver for http marketplace
This commit is contained in:
1 parent
eeb7c01ac0
commit
3bb13e106a
7 files changed
+162
-66
No files matched your search
@@ -82,16 +82,9 @@ public:
|
||||
|
||||
/**
|
||||
* Set monitor information for the MarketPlace
|
||||
* @param total_mb
|
||||
* @param free_mb
|
||||
* @param used_mb
|
||||
* @param data template with monitor information
|
||||
*/
|
||||
void update_monitor(long long total, long long free, long long used)
|
||||
{
|
||||
total_mb = total;
|
||||
free_mb = free;
|
||||
used_mb = used;
|
||||
}
|
||||
void update_monitor(const Template& data);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -1211,7 +1211,6 @@ DATASTORE_DRIVER_DEV_SCRIPTS="src/datastore_mad/remotes/dev/cp \
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
MARKETPLACE_DRIVER_HTTP_SCRIPTS="src/market_mad/remotes/http/import \
|
||||
src/market_mad/remotes/http/export \
|
||||
src/market_mad/remotes/http/delete \
|
||||
src/market_mad/remotes/http/monitor"
|
||||
|
||||
|
||||
@@ -281,10 +281,10 @@ int MarketPlace::from_xml(const std::string &xml_str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------- */
|
||||
/* --------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int MarketPlace::post_update_template(string& error)
|
||||
int MarketPlace::post_update_template(std::string& error)
|
||||
{
|
||||
std::string new_market_mad;
|
||||
|
||||
@@ -300,3 +300,13 @@ int MarketPlace::post_update_template(string& error)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void MarketPlace::update_monitor(const Template& data)
|
||||
{
|
||||
data.get("TOTAL_MB", total_mb);
|
||||
data.get("FREE_MB", free_mb);
|
||||
data.get("USED_MB", used_mb);
|
||||
}
|
||||
|
||||
@@ -56,100 +56,91 @@ void MarketPlaceManagerDriver::monitor(int oid, const std::string& msg) const
|
||||
/* ************************************************************************** */
|
||||
/* MAD Interface */
|
||||
/* ************************************************************************** */
|
||||
/*
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/*
|
||||
static void monitor_action(istringstream& is,
|
||||
DatastorePool* dspool,
|
||||
int id,
|
||||
const string& result)
|
||||
|
||||
static void monitor_action(
|
||||
std::istringstream& is,
|
||||
MarketPlacePool * marketpool,
|
||||
MarketPlaceManager * marketm,
|
||||
int id,
|
||||
const std::string& result)
|
||||
{
|
||||
string dsinfo64;
|
||||
string *dsinfo = 0;
|
||||
std::string info64;
|
||||
std::string* info = 0;
|
||||
|
||||
ostringstream oss;
|
||||
std::ostringstream oss;
|
||||
|
||||
getline (is, dsinfo64);
|
||||
getline (is, info64);
|
||||
|
||||
if (is.fail())
|
||||
{
|
||||
oss << "Error monitoring datastore " << id << ". Bad monitor data: "
|
||||
<< dsinfo64;
|
||||
oss << "Error monitoring marketplace " << id << ". Bad monitor data: "
|
||||
<< info64;
|
||||
|
||||
NebulaLog::log("ImM", Log::ERROR, oss);
|
||||
NebulaLog::log("MKP", Log::ERROR, oss);
|
||||
return;
|
||||
}
|
||||
|
||||
dsinfo = one_util::base64_decode(dsinfo64);
|
||||
info = one_util::base64_decode(info64);
|
||||
|
||||
if (dsinfo == 0)
|
||||
if (info == 0)
|
||||
{
|
||||
oss << "Error monitoring datastore " << id << ". Bad monitor data: "
|
||||
<< dsinfo64;
|
||||
oss << "Error monitoring marketplace " << id << ". Bad monitor data: "
|
||||
<< info64;
|
||||
|
||||
NebulaLog::log("ImM", Log::ERROR, oss);
|
||||
NebulaLog::log("MKP", Log::ERROR, oss);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result != "SUCCESS")
|
||||
{
|
||||
oss << "Error monitoring datastore " << id << ": " << *dsinfo;
|
||||
NebulaLog::log("ImM", Log::ERROR, oss);
|
||||
oss << "Error monitoring datastore " << id << ": " << *info;
|
||||
NebulaLog::log("MKP", Log::ERROR, oss);
|
||||
|
||||
delete dsinfo;
|
||||
delete info;
|
||||
return;
|
||||
}
|
||||
|
||||
Template monitor_data;
|
||||
|
||||
char* error_msg;
|
||||
int rc = monitor_data.parse(*dsinfo, &error_msg);
|
||||
char * error_msg;
|
||||
int rc = monitor_data.parse(*info, &error_msg);
|
||||
|
||||
delete info;
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
oss << "Error parsing datastore information: " << error_msg
|
||||
<< ". Monitoring information: " << endl << *dsinfo;
|
||||
oss << "Error parsing marketplace information: " << error_msg
|
||||
<< ". Monitoring information: " << endl << *info;
|
||||
|
||||
NebulaLog::log("ImM", Log::ERROR, oss);
|
||||
NebulaLog::log("MKP", Log::ERROR, oss);
|
||||
|
||||
delete dsinfo;
|
||||
free(error_msg);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
delete dsinfo;
|
||||
std::string name;
|
||||
MarketPlace * market = marketpool->get(id, true);
|
||||
|
||||
float total, free, used;
|
||||
string ds_name;
|
||||
|
||||
monitor_data.get("TOTAL_MB", total);
|
||||
monitor_data.get("FREE_MB", free);
|
||||
monitor_data.get("USED_MB", used);
|
||||
|
||||
Datastore * ds = dspool->get(id, true);
|
||||
|
||||
if (ds == 0 )
|
||||
if (market == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ds_name = ds->get_name();
|
||||
name = market->get_name();
|
||||
|
||||
ds->update_monitor(total, free, used);
|
||||
market->update_monitor(monitor_data);
|
||||
|
||||
dspool->update(ds);
|
||||
marketpool->update(market);
|
||||
|
||||
ds->unlock();
|
||||
market->unlock();
|
||||
|
||||
oss << "Datastore " << ds_name << " (" << id << ") successfully monitored.";
|
||||
|
||||
oss << "Marketplace " << name << " (" << id << ") successfully monitored.";
|
||||
|
||||
NebulaLog::log("ImM", Log::DEBUG, oss);
|
||||
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Helper functions for failure and error conditions */
|
||||
@@ -446,7 +437,7 @@ void MarketPlaceManagerDriver::protocol(const string& message) const
|
||||
}
|
||||
else if (action == "MONITOR")
|
||||
{
|
||||
return;
|
||||
monitor_action(is, marketpool, marketm, id, result);
|
||||
}
|
||||
else if (action == "LOG")
|
||||
{
|
||||
|
||||
@@ -45,7 +45,6 @@ class MarketPlaceDriver < OpenNebulaDriver
|
||||
# Market Driver Protocol constants
|
||||
ACTION = {
|
||||
:import => "IMPORT",
|
||||
:export => "EXPORT",
|
||||
:delete => "DELETE",
|
||||
:log => "LOG",
|
||||
:monitor => "MONITOR"
|
||||
@@ -63,7 +62,6 @@ class MarketPlaceDriver < OpenNebulaDriver
|
||||
:retries => 0,
|
||||
:local_actions => {
|
||||
ACTION[:import] => nil,
|
||||
ACTION[:export] => nil,
|
||||
ACTION[:delete] => nil,
|
||||
ACTION[:log] => nil,
|
||||
ACTION[:monitor] => nil
|
||||
@@ -87,7 +85,6 @@ class MarketPlaceDriver < OpenNebulaDriver
|
||||
@one = OpenNebula::Client.new()
|
||||
|
||||
register_action(ACTION[:import].to_sym, method("import"))
|
||||
register_action(ACTION[:export].to_sym, method("export"))
|
||||
register_action(ACTION[:delete].to_sym, method("delete"))
|
||||
register_action(ACTION[:monitor].to_sym,method("monitor"))
|
||||
end
|
||||
@@ -185,7 +182,7 @@ class MarketPlaceDriver < OpenNebulaDriver
|
||||
mp_mad = xml['MARKETPLACE/MARKET_MAD']
|
||||
|
||||
if mp_mad.nil?
|
||||
failure(:import, id, "Wrong driver message format")
|
||||
failure(:delete, id, "Wrong driver message format")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -198,7 +195,23 @@ class MarketPlaceDriver < OpenNebulaDriver
|
||||
# Monitor the marketplace. It gathers information about usage and app status
|
||||
############################################################################
|
||||
def monitor(id, drv_message)
|
||||
send_message(ACTION[:export], RESULT[:failure], id, "Not implemented")
|
||||
xml = decode(drv_message)
|
||||
|
||||
if xml.nil?
|
||||
failure(:monitor, id, "Cannot decode driver message")
|
||||
return
|
||||
end
|
||||
|
||||
mp_mad = xml['MARKETPLACE/MARKET_MAD']
|
||||
|
||||
if mp_mad.nil?
|
||||
failure(:monitor, id, "Wrong driver message format")
|
||||
return
|
||||
end
|
||||
|
||||
rc, info = do_action(id,mp_mad,nil,:monitor,"#{drv_message} #{id}",true)
|
||||
|
||||
send_message(ACTION[:monitor], rc, id, info)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Whitespace-only changes.
Regular → Executable
+90
@@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2015, 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
###############################################################################
|
||||
# This script is used to monitor the free and used space of a marketplace
|
||||
###############################################################################
|
||||
|
||||
# -------- Set up the environment to source common tools & conf ------------
|
||||
|
||||
if [ -z "${ONE_LOCATION}" ]; then
|
||||
LIB_LOCATION=/usr/lib/one
|
||||
else
|
||||
LIB_LOCATION=$ONE_LOCATION/lib
|
||||
fi
|
||||
|
||||
. $LIB_LOCATION/sh/scripts_common.sh
|
||||
|
||||
DRIVER_PATH=$(dirname $0)
|
||||
source ${DRIVER_PATH}/../../datastore/libfs.sh
|
||||
|
||||
UTILS_PATH="${DRIVER_PATH}/../../datastore"
|
||||
|
||||
# -------- Get arguments from OpenNebula core ------------
|
||||
|
||||
DRV_ACTION=$1
|
||||
ID=$2
|
||||
|
||||
XPATH="$UTILS_PATH/xpath.rb -b $DRV_ACTION"
|
||||
|
||||
unset i XPATH_ELEMENTS
|
||||
|
||||
while IFS= read -r -d '' element; do
|
||||
XPATH_ELEMENTS[i++]="$element"
|
||||
done < <($XPATH /MARKET_DRIVER_ACTION_DATA/MARKETPLACE/TEMPLATE/BRIDGE_LIST \
|
||||
/MARKET_DRIVER_ACTION_DATA/MARKETPLACE/TEMPLATE/PUBLIC_DIR)
|
||||
unset i
|
||||
|
||||
BRIDGE_LIST="${XPATH_ELEMENTS[i++]}"
|
||||
PUBLIC_DIR="${XPATH_ELEMENTS[i++]}"
|
||||
|
||||
# ------------ Compute datastore usage -------------
|
||||
|
||||
MONITOR_SCRIPT=$(cat <<EOF
|
||||
USED_MB=\$(df -B1M -P ${PUBLIC_DIR} 2>/dev/null | tail -n 1 | awk '{print \$3}')
|
||||
TOTAL_MB=\$(df -B1M -P ${PUBLIC_DIR} 2>/dev/null | tail -n 1 | awk '{print \$2}')
|
||||
FREE_MB=\$(df -B1M -P ${PUBLIC_DIR} 2>/dev/null | tail -n 1 | awk '{print \$4}')
|
||||
|
||||
if [ -z "\$USED_MB" -o -z "\$TOTAL_MB" -o -z "\$FREE_MB" ]; then
|
||||
msg="Empty value found"
|
||||
echo "\$msg: USED_MB=\$USED_MB, TOTAL_MB=\$TOTAL_MB, FREE_MB=\$FREE_MB"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "USED_MB=\$USED_MB"
|
||||
echo "FREE_MB=\$FREE_MB"
|
||||
echo "TOTAL_MB=\$TOTAL_MB"
|
||||
EOF
|
||||
)
|
||||
|
||||
if [ -n "$BRIDGE_LIST" ]; then
|
||||
HOST=`get_destination_host`
|
||||
MONITOR_DATA=$(ssh_monitor_and_log "$HOST" "$MONITOR_SCRIPT" "Remote monitor script" 2>&1)
|
||||
else
|
||||
MONITOR_DATA=$(monitor_and_log "$MONITOR_SCRIPT" "Monitor script" 2>&1)
|
||||
fi
|
||||
|
||||
MONITOR_STATUS=$?
|
||||
|
||||
if [ "$MONITOR_STATUS" = "0" ]; then
|
||||
echo "$MONITOR_DATA" | tr ' ' '\n'
|
||||
exit 0
|
||||
else
|
||||
echo "$MONITOR_DATA"
|
||||
exit $MONITOR_STATUS
|
||||
fi
|
||||
Reference in new issue
Block a user