2016-03-08 18:38:51 +03:00
/* -------------------------------------------------------------------------- */
2018-01-02 20:27:37 +03:00
/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */
2016-03-08 18:38:51 +03:00
/* */
/* 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_UPDATE_DB_H
# define REQUEST_MANAGER_UPDATE_DB_H
# include "Request.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class RequestManagerUpdateDB : public Request
{
protected :
2017-05-07 22:52:34 +03:00
RequestManagerUpdateDB ( const string & name ) : Request ( name , " A:sis " ,
2016-03-08 18:38:51 +03:00
" Updates the DB object from a XML document " )
{
auth_op = AuthRequest : : MANAGE ;
} ;
virtual ~ RequestManagerUpdateDB ( ) { } ;
2017-05-23 14:31:18 +03:00
/* ---------------------------------------------------------------------- */
2016-03-08 18:38:51 +03:00
2017-05-23 14:31:18 +03:00
virtual void request_execute ( xmlrpc_c : : paramList const & pl ,
RequestAttributes & att )
2016-03-08 18:38:51 +03:00
{
int oid = xmlrpc_c : : value_int ( pl . getInt ( 1 ) ) ;
std : : string xml = xmlrpc_c : : value_string ( pl . getString ( 2 ) ) ;
2018-05-23 15:42:57 +03:00
if ( ! att . is_oneadmin ( ) )
2016-03-08 18:38:51 +03:00
{
failure_response ( AUTHORIZATION , att ) ;
return ;
}
2017-05-23 14:31:18 +03:00
ErrorCode ec = request_execute ( oid , xml , att ) ;
if ( ec = = SUCCESS )
{
success_response ( oid , att ) ;
}
else
{
failure_response ( ec , att ) ;
}
}
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
ErrorCode request_execute ( int oid , const std : : string & xml ,
RequestAttributes & att )
{
2018-03-18 01:31:52 +03:00
PoolObjectSQL * object = pool - > get ( oid ) ;
2016-03-08 18:38:51 +03:00
if ( object = = 0 )
{
att . resp_id = oid ;
2017-05-23 14:31:18 +03:00
return NO_EXISTS ;
2016-03-08 18:38:51 +03:00
}
string old_xml ;
object - > to_xml ( old_xml ) ;
if ( object - > from_xml ( xml ) ! = 0 )
{
object - > from_xml ( old_xml ) ;
2017-05-23 14:31:18 +03:00
object - > unlock ( ) ;
2016-03-08 18:38:51 +03:00
att . resp_msg = " Cannot update object from XML " ;
2017-05-23 14:31:18 +03:00
return INTERNAL ;
2016-03-08 18:38:51 +03:00
}
if ( object - > get_oid ( ) ! = oid )
{
object - > from_xml ( old_xml ) ;
2017-05-23 14:31:18 +03:00
object - > unlock ( ) ;
2016-03-08 18:38:51 +03:00
att . resp_msg = " Consistency check failed " ;
2017-05-23 14:31:18 +03:00
return INTERNAL ;
2016-03-08 18:38:51 +03:00
}
pool - > update ( object ) ;
object - > unlock ( ) ;
2017-05-23 14:31:18 +03:00
return SUCCESS ;
2016-03-08 18:38:51 +03:00
}
} ;
2017-05-23 14:31:18 +03:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
2016-03-08 18:38:51 +03:00
class MarketPlaceAppUpdateDB : public RequestManagerUpdateDB
{
public :
2017-05-07 22:52:34 +03:00
MarketPlaceAppUpdateDB ( ) : RequestManagerUpdateDB ( " one.marketapp.updatedb " )
2016-03-08 18:38:51 +03:00
{
auth_object = PoolObjectSQL : : MARKETPLACEAPP ;
pool = Nebula : : instance ( ) . get_apppool ( ) ;
}
~ MarketPlaceAppUpdateDB ( ) { } ;
} ;
2017-05-23 14:31:18 +03:00
/* -------------------------------------------------------------------------- */
2016-03-08 18:38:51 +03:00
class MarketPlaceUpdateDB : public RequestManagerUpdateDB
{
public :
2017-05-07 22:52:34 +03:00
MarketPlaceUpdateDB ( ) : RequestManagerUpdateDB ( " one.market.updatedb " )
2016-03-08 18:38:51 +03:00
{
auth_object = PoolObjectSQL : : MARKETPLACE ;
pool = Nebula : : instance ( ) . get_marketpool ( ) ;
}
~ MarketPlaceUpdateDB ( ) { } ;
} ;
2017-05-23 14:31:18 +03:00
/* -------------------------------------------------------------------------- */
class ZoneUpdateDB : public RequestManagerUpdateDB
{
public :
ZoneUpdateDB ( ) : RequestManagerUpdateDB ( " one.zone.updatedb " )
{
auth_object = PoolObjectSQL : : ZONE ;
pool = Nebula : : instance ( ) . get_zonepool ( ) ;
}
~ ZoneUpdateDB ( ) { } ;
virtual void request_execute ( xmlrpc_c : : paramList const & pl ,
RequestAttributes & att )
{
int oid = xmlrpc_c : : value_int ( pl . getInt ( 1 ) ) ;
std : : string xml = xmlrpc_c : : value_string ( pl . getString ( 2 ) ) ;
2018-05-23 15:42:57 +03:00
if ( ! att . is_oneadmin ( ) )
2017-05-23 14:31:18 +03:00
{
failure_response ( AUTHORIZATION , att ) ;
return ;
}
ErrorCode ec = RequestManagerUpdateDB : : request_execute ( oid , xml , att ) ;
if ( ec = = SUCCESS )
{
std : : vector < int > zids ;
success_response ( oid , att ) ;
}
else
{
failure_response ( ec , att ) ;
}
}
} ;
2016-03-08 18:38:51 +03:00
# endif /* REQUEST_MANAGER_UPDATE_DB_H */