mirror of
https://github.com/OpenNebula/one.git
synced 2025-08-24 17:49:28 +03:00
@ -30,6 +30,51 @@
|
||||
class MarketPlace : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
enum MarketPlaceState
|
||||
{
|
||||
ENABLED = 0, /**< Enabled */
|
||||
DISABLED = 1 /**< Disabled */
|
||||
};
|
||||
|
||||
/**
|
||||
* Functions to convert to/from string the MarketPlace states
|
||||
*/
|
||||
static int str_to_state(std::string& st, MarketPlaceState& state)
|
||||
{
|
||||
one_util::toupper(st);
|
||||
|
||||
state = ENABLED;
|
||||
|
||||
if ( st == "ENABLED" ) {
|
||||
state = ENABLED;
|
||||
} else if ( st == "DISABLED" ) {
|
||||
state = DISABLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static std::string state_to_str(MarketPlaceState state)
|
||||
{
|
||||
std::string st = "";
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ENABLED:
|
||||
st = "ENABLED";
|
||||
break;
|
||||
case DISABLED:
|
||||
st = "DISABLED";
|
||||
break;
|
||||
}
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
virtual ~MarketPlace() = default;
|
||||
|
||||
/**
|
||||
@ -67,6 +112,14 @@ public:
|
||||
return marketapps.del(id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes all apps images from the set.
|
||||
*/
|
||||
void clear_marketapps()
|
||||
{
|
||||
marketapps.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the Image IDs set
|
||||
*/
|
||||
@ -133,6 +186,26 @@ public:
|
||||
supported_actions.set(MarketPlaceApp::MONITOR);
|
||||
}
|
||||
|
||||
MarketPlaceState get_state() const
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable the MarketPlace
|
||||
*/
|
||||
void enable(bool enabled)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
state = ENABLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
friend class MarketPlacePool;
|
||||
@ -140,6 +213,12 @@ private:
|
||||
// *************************************************************************
|
||||
// MarketPlace Attributes
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* State of the marketplace
|
||||
*/
|
||||
MarketPlaceState state;
|
||||
|
||||
/**
|
||||
* Name of the marketplace driver used to import apps
|
||||
*/
|
||||
@ -148,22 +227,22 @@ private:
|
||||
/**
|
||||
* Total capacity in MB
|
||||
*/
|
||||
long long total_mb;
|
||||
long long total_mb;
|
||||
|
||||
/**
|
||||
* Available capacity in MB
|
||||
*/
|
||||
long long free_mb;
|
||||
long long free_mb;
|
||||
|
||||
/**
|
||||
* Used capacity in MB
|
||||
*/
|
||||
long long used_mb;
|
||||
long long used_mb;
|
||||
|
||||
/**
|
||||
* Zone where this market lives
|
||||
*/
|
||||
int zone_id;
|
||||
int zone_id;
|
||||
|
||||
/**
|
||||
* Supported actions on MarketPlaceApps
|
||||
|
39
include/RequestManagerMarketPlace.h
Normal file
39
include/RequestManagerMarketPlace.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2021, 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 REQUEST_MANAGER_MARKETPLACE_H
|
||||
#define REQUEST_MANAGER_MARKETPLACE_H
|
||||
|
||||
#include "Request.h"
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class MarketPlaceEnable: public Request
|
||||
{
|
||||
public:
|
||||
MarketPlaceEnable();
|
||||
|
||||
~MarketPlaceEnable() = default;
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
@ -35,7 +35,7 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Functions to convert to/from string the Host states
|
||||
* Functions to convert to/from string the Zone states
|
||||
*/
|
||||
static int str_to_state(std::string& st, ZoneState& state)
|
||||
{
|
||||
|
@ -38,6 +38,11 @@
|
||||
:size: 7
|
||||
:left: true
|
||||
|
||||
:STAT:
|
||||
:desc: Marketplace status
|
||||
:size: 4
|
||||
:left: true
|
||||
|
||||
:default:
|
||||
- :ID
|
||||
- :NAME
|
||||
@ -46,3 +51,4 @@
|
||||
- :APPS
|
||||
- :MAD
|
||||
- :ZONE
|
||||
- :STAT
|
||||
|
@ -36,6 +36,12 @@ class OneMarketPlaceHelper < OpenNebulaHelper::OneHelper
|
||||
"onemarket.yaml"
|
||||
end
|
||||
|
||||
def self.state_to_str(id)
|
||||
state_str = MarketPlace::MARKETPLACE_STATES[id.to_i]
|
||||
|
||||
MarketPlace::SHORT_MARKETPLACE_STATES[state_str]
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
@ -86,7 +92,11 @@ class OneMarketPlaceHelper < OpenNebulaHelper::OneHelper
|
||||
d["ZONE_ID"]
|
||||
end
|
||||
|
||||
default :ID, :NAME, :SIZE, :AVAIL, :APPS, :MAD, :ZONE
|
||||
column :STAT, 'Markeplace status', :left, :size => 4 do |d|
|
||||
OneMarketPlaceHelper.state_to_str(d['STATE'])
|
||||
end
|
||||
|
||||
default :ID, :NAME, :SIZE, :AVAIL, :APPS, :MAD, :ZONE, :STAT
|
||||
end
|
||||
|
||||
table
|
||||
@ -116,6 +126,7 @@ class OneMarketPlaceHelper < OpenNebulaHelper::OneHelper
|
||||
puts str % ["NAME", market.name]
|
||||
puts str % ["USER", market['UNAME']]
|
||||
puts str % ["GROUP", market['GNAME']]
|
||||
puts str % ["STATE", market.state_str]
|
||||
|
||||
puts str % ["MARKET_MAD", market['MARKET_MAD']]
|
||||
puts
|
||||
|
@ -199,4 +199,24 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
|
||||
enable_desc = <<-EOT.unindent
|
||||
Enables the marketplace
|
||||
EOT
|
||||
|
||||
command :enable, enable_desc, [:range, :marketplaceid_list] do
|
||||
helper.perform_actions(args[0], options, 'enabled') do |obj|
|
||||
obj.enable
|
||||
end
|
||||
end
|
||||
|
||||
disable_desc = <<-EOT.unindent
|
||||
Disables the marketplace. Remove all its apps.
|
||||
EOT
|
||||
|
||||
command :disable, disable_desc, [:range, :marketplaceid_list] do
|
||||
helper.perform_actions(args[0], options, 'disabled') do |obj|
|
||||
obj.disable
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -35,6 +35,7 @@ MarketPlace::MarketPlace(
|
||||
int umask,
|
||||
unique_ptr<MarketPlaceTemplate> mp_template):
|
||||
PoolObjectSQL(-1, MARKETPLACE, "", uid, gid, uname, gname, one_db::mp_table),
|
||||
state(ENABLED),
|
||||
market_mad(""),
|
||||
total_mb(0),
|
||||
free_mb(0),
|
||||
@ -266,6 +267,7 @@ std::string& MarketPlace::to_xml(std::string& xml) const
|
||||
"<UNAME>" << uname << "</UNAME>" <<
|
||||
"<GNAME>" << gname << "</GNAME>" <<
|
||||
"<NAME>" << name << "</NAME>" <<
|
||||
"<STATE>" << state << "</STATE>" <<
|
||||
"<MARKET_MAD>"<<one_util::escape_xml(market_mad)<<"</MARKET_MAD>"<<
|
||||
"<ZONE_ID>" <<one_util::escape_xml(zone_id)<<"</ZONE_ID>"<<
|
||||
"<TOTAL_MB>" << total_mb << "</TOTAL_MB>" <<
|
||||
@ -311,6 +313,7 @@ static void set_supported_actions(ActionSet<MarketPlaceApp::Action>& as,
|
||||
int MarketPlace::from_xml(const std::string &xml_str)
|
||||
{
|
||||
int rc = 0;
|
||||
int int_state = 0;
|
||||
std::vector<xmlNodePtr> content;
|
||||
|
||||
// Initialize the internal XML object
|
||||
@ -324,6 +327,9 @@ int MarketPlace::from_xml(const std::string &xml_str)
|
||||
rc += xpath(gname, "/MARKETPLACE/GNAME", "not_found");
|
||||
rc += xpath(name, "/MARKETPLACE/NAME", "not_found");
|
||||
|
||||
xpath(int_state, "/MARKETPLACE/STATE", 0);
|
||||
state = static_cast<MarketPlaceState>(int_state);
|
||||
|
||||
rc += xpath(market_mad, "/MARKETPLACE/MARKET_MAD", "not_found");
|
||||
rc += xpath(zone_id, "/MARKETPLACE/ZONE_ID", -1);
|
||||
|
||||
|
@ -219,7 +219,6 @@ void MarketPlaceManager::monitor_market(int mp_id)
|
||||
|
||||
if ( auto mp = mppool->get(mp_id) )
|
||||
{
|
||||
|
||||
mp_name = mp->get_name();
|
||||
|
||||
if ( !mp->is_action_supported(MarketPlaceApp::MONITOR) )
|
||||
@ -230,7 +229,8 @@ void MarketPlaceManager::monitor_market(int mp_id)
|
||||
return;
|
||||
}
|
||||
|
||||
if ( mp->get_zone_id() != Nebula::instance().get_zone_id() )
|
||||
if ( mp->get_zone_id() != Nebula::instance().get_zone_id() ||
|
||||
mp->get_state() == MarketPlace::DISABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -234,6 +234,11 @@ void MarketPlaceManager::_monitor(unique_ptr<market_msg_t> msg)
|
||||
|
||||
if ( auto market = mppool->get(id) )
|
||||
{
|
||||
if (market->get_state() == MarketPlace::DISABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
apps_mp = market->get_marketapp_ids();
|
||||
name = market->get_name();
|
||||
|
||||
|
@ -29,7 +29,15 @@ module OpenNebula
|
||||
:update => "market.update",
|
||||
:chown => "market.chown",
|
||||
:chmod => "market.chmod",
|
||||
:rename => "market.rename"
|
||||
:rename => "market.rename",
|
||||
:enable => "market.enable"
|
||||
}
|
||||
|
||||
MARKETPLACE_STATES=%w{ENABLED DISABLED}
|
||||
|
||||
SHORT_MARKETPLACE_STATES={
|
||||
"ENABLED" => "on",
|
||||
"DISABLED" => "off"
|
||||
}
|
||||
|
||||
# Creates a MarketPlace description with just its identifier
|
||||
@ -130,13 +138,33 @@ module OpenNebula
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def rename(name)
|
||||
return call(MARKETPLACE_METHODS[:rename], @pe_id, name)
|
||||
call(MARKETPLACE_METHODS[:rename], @pe_id, name)
|
||||
end
|
||||
|
||||
# Enables this marketplace
|
||||
def enable
|
||||
call(MARKETPLACE_METHODS[:enable], @pe_id, true)
|
||||
end
|
||||
|
||||
# Enables this marketplace
|
||||
def disable
|
||||
call(MARKETPLACE_METHODS[:enable], @pe_id, false)
|
||||
end
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# Helpers to get information
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
# Returns the state of the Zone (numeric value)
|
||||
def state
|
||||
self['STATE'].to_i
|
||||
end
|
||||
|
||||
# Returns the state of the Zone (string value)
|
||||
def state_str
|
||||
MARKETPLACE_STATES[state]
|
||||
end
|
||||
|
||||
# Returns whether or not the marketplace app with id 'id' is part of
|
||||
# this marketplace
|
||||
def contains(id)
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include "RequestManagerSecurityGroup.h"
|
||||
#include "RequestManagerVNTemplate.h"
|
||||
#include "RequestManagerHook.h"
|
||||
#include "RequestManagerMarketPlace.h"
|
||||
|
||||
#include "RequestManagerSystem.h"
|
||||
#include "RequestManagerProxy.h"
|
||||
@ -1060,6 +1061,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::method * market_chmod_pt;
|
||||
xmlrpc_c::method * market_chown_pt;
|
||||
xmlrpc_c::method * market_rename_pt;
|
||||
xmlrpc_c::method * market_enable_pt;
|
||||
|
||||
if (nebula.is_federation_slave())
|
||||
{
|
||||
@ -1068,6 +1070,7 @@ void RequestManager::register_xml_methods()
|
||||
market_chmod_pt = new RequestManagerProxy("one.market.chmod");
|
||||
market_chown_pt = new RequestManagerProxy("one.market.chown");
|
||||
market_rename_pt = new RequestManagerProxy("one.market.rename");
|
||||
market_enable_pt = new RequestManagerProxy("one.market.enable");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1076,6 +1079,7 @@ void RequestManager::register_xml_methods()
|
||||
market_chmod_pt = new MarketPlaceChmod();
|
||||
market_chown_pt = new MarketPlaceChown();
|
||||
market_rename_pt = new MarketPlaceRename();
|
||||
market_enable_pt = new MarketPlaceEnable();
|
||||
|
||||
xmlrpc_c::methodPtr market_updatedb(new MarketPlaceUpdateDB());
|
||||
xmlrpc_c::methodPtr market_allocatedb(new MarketPlaceAllocateDB());
|
||||
@ -1093,6 +1097,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr market_chmod(market_chmod_pt);
|
||||
xmlrpc_c::methodPtr market_chown(market_chown_pt);
|
||||
xmlrpc_c::methodPtr market_rename(market_rename_pt);
|
||||
xmlrpc_c::methodPtr market_enable(market_enable_pt);
|
||||
|
||||
xmlrpc_c::methodPtr market_info(new MarketPlaceInfo());
|
||||
xmlrpc_c::methodPtr marketpool_info(new MarketPlacePoolInfo());
|
||||
@ -1105,6 +1110,7 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
RequestManagerRegistry.addMethod("one.market.info", market_info);
|
||||
RequestManagerRegistry.addMethod("one.market.rename", market_rename);
|
||||
RequestManagerRegistry.addMethod("one.market.enable", market_enable);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.marketpool.info", marketpool_info);
|
||||
|
||||
|
115
src/rm/RequestManagerMarketPlace.cc
Normal file
115
src/rm/RequestManagerMarketPlace.cc
Normal file
@ -0,0 +1,115 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2021, 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManagerMarketPlace.h"
|
||||
#include "Nebula.h"
|
||||
#include "MarketPlaceManager.h"
|
||||
#include "MarketPlacePool.h"
|
||||
#include "MarketPlaceAppPool.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
MarketPlaceEnable::MarketPlaceEnable()
|
||||
: Request("one.market.enable", "A:sii", "Enable or disable MarketPlcae")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_marketpool();
|
||||
|
||||
auth_object = PoolObjectSQL::MARKETPLACE;
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void MarketPlaceEnable::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
bool enable_flag = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
std::set<int> apps;
|
||||
|
||||
if ( basic_authorization(id, att) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto market = pool->get<MarketPlace>(id))
|
||||
{
|
||||
if (enable_flag && market->get_state() == MarketPlace::ENABLED ||
|
||||
!enable_flag && market->get_state() == MarketPlace::DISABLED)
|
||||
{
|
||||
success_response(id, att);
|
||||
return;
|
||||
}
|
||||
|
||||
market->enable(enable_flag);
|
||||
|
||||
if (!enable_flag)
|
||||
{
|
||||
apps = market->get_marketapp_ids();
|
||||
market->clear_marketapps();
|
||||
}
|
||||
|
||||
pool->update(market.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
return;
|
||||
}
|
||||
|
||||
if (enable_flag)
|
||||
{
|
||||
auto mm = nd.get_marketm();
|
||||
mm->monitor_market(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
MarketPlaceAppPool * apppool = nd.get_apppool();
|
||||
|
||||
string app_error;
|
||||
|
||||
for (auto app_id : apps)
|
||||
{
|
||||
auto app = apppool->get(app_id);
|
||||
|
||||
if ( app == nullptr )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( apppool->drop(app.get(), app_error) != 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Cannot remove " << object_name(PoolObjectSQL::MARKETPLACEAPP)
|
||||
<< " " << app_id << ": " << app_error << ". ";
|
||||
|
||||
NebulaLog::warn("ReM", oss.str());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
success_response(id, att);
|
||||
}
|
@ -48,6 +48,7 @@ source_files=[
|
||||
'RequestManagerZone.cc',
|
||||
'RequestManagerDatastore.cc',
|
||||
'RequestManagerLock.cc',
|
||||
'RequestManagerMarketPlace.cc',
|
||||
'RequestManagerMarketPlaceApp.cc',
|
||||
'RequestManagerVirtualRouter.cc',
|
||||
'RequestManagerSecurityGroup.cc',
|
||||
|
Reference in New Issue
Block a user