2016-03-08 18:38:51 +03:00
/* -------------------------------------------------------------------------- */
2016-05-04 13:33:23 +03:00
/* Copyright 2002-2016, 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 ( ) { } ;
/* -------------------------------------------------------------------- */
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 ) ) ;
if ( att . uid ! = UserPool : : ONEADMIN_ID )
{
failure_response ( AUTHORIZATION , att ) ;
return ;
}
PoolObjectSQL * object = pool - > get ( oid , true ) ;
if ( object = = 0 )
{
att . resp_id = oid ;
failure_response ( NO_EXISTS , att ) ;
return ;
}
string old_xml ;
object - > to_xml ( old_xml ) ;
if ( object - > from_xml ( xml ) ! = 0 )
{
object - > from_xml ( old_xml ) ;
att . resp_msg = " Cannot update object from XML " ;
failure_response ( INTERNAL , att ) ;
object - > unlock ( ) ;
return ;
}
if ( object - > get_oid ( ) ! = oid )
{
object - > from_xml ( old_xml ) ;
att . resp_msg = " Consistency check failed " ;
failure_response ( INTERNAL , att ) ;
object - > unlock ( ) ;
return ;
}
pool - > update ( object ) ;
object - > unlock ( ) ;
success_response ( oid , att ) ;
return ;
}
} ;
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 ( ) { } ;
} ;
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 ( ) { } ;
} ;
# endif /* REQUEST_MANAGER_UPDATE_DB_H */