mirror of
https://github.com/OpenNebula/one.git
synced 2025-04-02 10:50:07 +03:00
F #4809: Add zone server list to zone data
This commit is contained in:
parent
e1cb2c928a
commit
d03ed15889
@ -22,6 +22,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class ZoneServers;
|
||||
|
||||
/**
|
||||
* The Zone class.
|
||||
*/
|
||||
@ -45,25 +47,28 @@ public:
|
||||
int from_xml(const string &xml_str);
|
||||
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Friends
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
friend class ZonePool;
|
||||
|
||||
// *************************************************************************
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// *************************************************************************
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
Zone(int id, Template* zone_template);
|
||||
|
||||
~Zone();
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
// -------------------------------------------------------------------------
|
||||
// Zone servers
|
||||
// -------------------------------------------------------------------------
|
||||
Template servers_template;
|
||||
|
||||
ZoneServers * servers;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// DataBase implementation (Private)
|
||||
// -------------------------------------------------------------------------
|
||||
static const char * db_names;
|
||||
|
||||
static const char * db_bootstrap;
|
||||
|
175
include/ZoneServer.h
Normal file
175
include/ZoneServer.h
Normal file
@ -0,0 +1,175 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2016, 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 ZONE_SERVER_H_
|
||||
#define ZONE_SERVER_H_
|
||||
|
||||
#include <queue>
|
||||
#include <set>
|
||||
|
||||
#include "ExtendedAttribute.h"
|
||||
|
||||
/**
|
||||
* The VirtualMachine DISK attribute
|
||||
*/
|
||||
class ZoneServer : public ExtendedAttribute
|
||||
{
|
||||
public:
|
||||
ZoneServer(VectorAttribute *va, int id):ExtendedAttribute(va, id){};
|
||||
|
||||
virtual ~ZoneServer(){};
|
||||
|
||||
int init(string& error)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_id() const
|
||||
{
|
||||
return ExtendedAttribute::get_id();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set of Zone servers
|
||||
*/
|
||||
class ZoneServers : public ExtendedAttributeSet
|
||||
{
|
||||
public:
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Constructor and Initialization functions */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/**
|
||||
* Creates the ZoneServers set from a zone template with SERVER=[...]
|
||||
* attributes
|
||||
* @param tmpl template with SERVER
|
||||
*/
|
||||
ZoneServers(Template * tmpl):ExtendedAttributeSet(false), next_id(-1)
|
||||
{
|
||||
std::vector<VectorAttribute *> vas;
|
||||
|
||||
tmpl->get(SERVER_NAME, vas);
|
||||
|
||||
init_attribute_map(SERVER_ID_NAME, vas);
|
||||
|
||||
for ( zone_iterator it = begin() ; it != end() ; ++it )
|
||||
{
|
||||
string error;
|
||||
|
||||
int i = (*it)->get_id();
|
||||
|
||||
if ( i > next_id )
|
||||
{
|
||||
next_id = i;
|
||||
}
|
||||
|
||||
(*it)->init(error);
|
||||
}
|
||||
|
||||
next_id += 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an empty zone server set
|
||||
*/
|
||||
ZoneServers():ExtendedAttributeSet(false){};
|
||||
|
||||
virtual ~ZoneServers(){};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Iterators */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
class ZoneIterator : public AttributeIterator
|
||||
{
|
||||
public:
|
||||
ZoneIterator():AttributeIterator(){};
|
||||
ZoneIterator(const AttributeIterator& dit):AttributeIterator(dit){};
|
||||
virtual ~ZoneIterator(){};
|
||||
|
||||
ZoneServer * operator*() const
|
||||
{
|
||||
return static_cast<ZoneServer *>(map_it->second);
|
||||
}
|
||||
};
|
||||
|
||||
ZoneIterator begin()
|
||||
{
|
||||
ZoneIterator it(ExtendedAttributeSet::begin());
|
||||
return it;
|
||||
}
|
||||
|
||||
ZoneIterator end()
|
||||
{
|
||||
ZoneIterator it(ExtendedAttributeSet::end());
|
||||
return it;
|
||||
}
|
||||
|
||||
typedef class ZoneIterator zone_iterator;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* ZoneServer interface */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/**
|
||||
* Returns the SERVER attribute for a zone server
|
||||
* @param disk_id of the DISK
|
||||
* @return pointer to the attribute ir null if not found
|
||||
*/
|
||||
ZoneServer * get_server(int id) const
|
||||
{
|
||||
return static_cast<ZoneServer *>(get_attribute(id));
|
||||
}
|
||||
|
||||
int add_server(VectorAttribute * va, string& error)
|
||||
{
|
||||
ZoneServer * server = new ZoneServer(va, next_id);
|
||||
|
||||
if ( server->init(error) != 0 )
|
||||
{
|
||||
delete server;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
add_attribute(server, next_id);
|
||||
|
||||
next_id += 1;
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
ExtendedAttribute * attribute_factory(VectorAttribute * va, int id) const
|
||||
{
|
||||
return new ZoneServer(va, id);
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
static const char * SERVER_NAME; //"SERVER"
|
||||
|
||||
static const char * SERVER_ID_NAME; //"ID"
|
||||
|
||||
int next_id;
|
||||
};
|
||||
|
||||
#endif /*ZONE_SERVER_H_*/
|
||||
|
@ -15,6 +15,7 @@
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
#include "Zone.h"
|
||||
#include "ZoneServer.h"
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
@ -28,11 +29,16 @@ const char * Zone::db_bootstrap = "CREATE TABLE IF NOT EXISTS zone_pool ("
|
||||
"gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, "
|
||||
"UNIQUE(name))";
|
||||
|
||||
const char * ZoneServers::SERVER_NAME = "SERVER";
|
||||
|
||||
const char * ZoneServers::SERVER_ID_NAME = "ID";
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Zone::Zone(int id, Template* zone_template):
|
||||
PoolObjectSQL(id, ZONE, "", -1, -1, "", "", table)
|
||||
PoolObjectSQL(id, ZONE, "", -1, -1, "", "", table), servers_template(
|
||||
false, '=', "SERVER_POOL"), servers(0)
|
||||
{
|
||||
if (zone_template != 0)
|
||||
{
|
||||
@ -50,6 +56,8 @@ Zone::Zone(int id, Template* zone_template):
|
||||
Zone::~Zone()
|
||||
{
|
||||
delete obj_template;
|
||||
|
||||
delete servers;
|
||||
};
|
||||
|
||||
/* ************************************************************************ */
|
||||
@ -63,9 +71,9 @@ int Zone::insert(SqlDB *db, string& error_str)
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------
|
||||
// Check default attributes
|
||||
// ---------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
erase_template_attribute("NAME", name);
|
||||
|
||||
@ -82,9 +90,11 @@ int Zone::insert(SqlDB *db, string& error_str)
|
||||
goto error_endpoint;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
remove_template_attribute("SERVER");
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Insert the Zone
|
||||
// ------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
rc = insert_replace(db, false, error_str);
|
||||
|
||||
@ -192,14 +202,17 @@ error_common:
|
||||
|
||||
string& Zone::to_xml(string& xml) const
|
||||
{
|
||||
ostringstream oss;
|
||||
string template_xml;
|
||||
ostringstream oss;
|
||||
|
||||
string template_xml;
|
||||
string server_xml;
|
||||
|
||||
oss <<
|
||||
"<ZONE>" <<
|
||||
"<ID>" << oid << "</ID>" <<
|
||||
"<NAME>" << name << "</NAME>" <<
|
||||
obj_template->to_xml(template_xml) <<
|
||||
servers_template.to_xml(server_xml) <<
|
||||
"</ZONE>";
|
||||
|
||||
xml = oss.str();
|
||||
@ -207,8 +220,8 @@ string& Zone::to_xml(string& xml) const
|
||||
return xml;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Zone::from_xml(const string& xml)
|
||||
{
|
||||
@ -222,7 +235,9 @@ int Zone::from_xml(const string& xml)
|
||||
rc += xpath(oid, "/ZONE/ID", -1);
|
||||
rc += xpath(name,"/ZONE/NAME", "not_found");
|
||||
|
||||
// Get associated classes
|
||||
// -------------------------------------------------------------------------
|
||||
// Zone template
|
||||
// -------------------------------------------------------------------------
|
||||
ObjectXML::get_nodes("/ZONE/TEMPLATE", content);
|
||||
|
||||
if (content.empty())
|
||||
@ -230,12 +245,26 @@ int Zone::from_xml(const string& xml)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Template contents
|
||||
rc += obj_template->from_xml_node(content[0]);
|
||||
|
||||
ObjectXML::free_nodes(content);
|
||||
content.clear();
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Zone Server template
|
||||
// -------------------------------------------------------------------------
|
||||
ObjectXML::get_nodes("/ZONE/SERVER_POOL", content);
|
||||
|
||||
if (content.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc += servers_template.from_xml_node(content[0]);
|
||||
|
||||
ObjectXML::free_nodes(content);
|
||||
content.clear();
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
return -1;
|
||||
@ -245,11 +274,13 @@ int Zone::from_xml(const string& xml)
|
||||
set_user(0,"");
|
||||
set_group(0,"");
|
||||
|
||||
servers = new ZoneServers(&servers_template);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Zone::post_update_template(string& error)
|
||||
{
|
||||
@ -261,8 +292,10 @@ int Zone::post_update_template(string& error)
|
||||
replace_template_attribute("ENDPOINT", "-");
|
||||
}
|
||||
|
||||
remove_template_attribute("SERVER");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
Loading…
x
Reference in New Issue
Block a user