2015-12-13 18:17:29 +01:00
/* -------------------------------------------------------------------------- */
2022-04-07 19:49:58 +02:00
/* Copyright 2002-2022, OpenNebula Project, OpenNebula Systems */
2015-12-13 18:17:29 +01: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 MARKETPLACE_MANAGER_H_
# define MARKETPLACE_MANAGER_H_
2020-06-29 12:14:00 +02:00
# include "ProtocolMessages.h"
# include "DriverManager.h"
2020-07-24 16:00:59 +02:00
# include "Listener.h"
2015-12-13 18:17:29 +01:00
2021-05-21 23:25:37 +02:00
# include <atomic>
2015-12-14 16:47:33 +01:00
class MarketPlacePool ;
class MarketPlaceAppPool ;
2015-12-19 22:35:09 +01:00
class ImagePool ;
class DatastorePool ;
class ImageManager ;
2017-04-28 22:46:37 +02:00
class RaftManager ;
2015-12-13 18:17:29 +01:00
2020-07-24 16:00:59 +02:00
class MarketPlaceManager : public DriverManager < Driver < market_msg_t > >
2015-12-13 18:17:29 +01:00
{
public :
2015-12-14 16:47:33 +01:00
/**
2015-12-18 12:07:21 +01:00
* Inititalizes the Marketplace manager :
* @ param t , timer_period to wake up the manger to perform actions
* @ param m , monitor_period to monitor marketplaces
* @ param mad , list of drivers for the manager
2015-12-14 16:47:33 +01:00
*/
2020-06-29 12:14:00 +02:00
MarketPlaceManager ( time_t t , time_t m , const std : : string & _mad_location ) ;
2015-12-18 12:07:21 +01:00
2020-07-24 16:00:59 +02:00
~ MarketPlaceManager ( ) = default ;
2015-12-14 16:47:33 +01:00
2015-12-19 22:35:09 +01:00
/**
* Initializes internal pointers to other managers . Must be called when
* all the other managers exist in Nebula : : instance
*/
void init_managers ( ) ;
2015-12-13 18:17:29 +01:00
/**
2020-07-24 16:00:59 +02:00
* This functions starts the associated timer thread and drivers .
2015-12-13 18:17:29 +01:00
* @ return 0 on success .
*/
int start ( ) ;
/**
2020-07-24 16:00:59 +02:00
* Stops timer and drivers
2015-12-13 18:17:29 +01:00
*/
2020-07-24 16:00:59 +02:00
void finalize ( )
2015-12-13 18:17:29 +01:00
{
2021-05-21 23:25:37 +02:00
terminate = true ;
2020-07-24 16:00:59 +02:00
timer_thread . stop ( ) ;
DriverManager : : stop ( drivers_timeout ) ;
2015-12-13 18:17:29 +01:00
} ;
/**
2020-07-24 16:00:59 +02:00
* Loads the MarketPlace Driver defined in configuration file
* @ param _mads configuration of drivers
2015-12-13 18:17:29 +01:00
*/
2020-07-24 16:00:59 +02:00
int load_drivers ( const std : : vector < const VectorAttribute * > & _mads ) ;
2015-12-13 18:17:29 +01:00
/**
* Imports a new app into the marketplace . The marketplace app needs to
2015-12-19 22:35:09 +01:00
* include the ORIGIN_ID attribute so the driver can locate the app . An
2015-12-13 18:17:29 +01:00
* optional template maybe provided to export the app to a cloud .
* @ param appid of the app
* @ param market_data of the associated marketplace in XML format
* @ param error descrition
*
* @ return 0 on success
*/
2015-12-14 16:47:33 +01:00
int import_app ( int appid , const std : : string & market_data , std : : string & err ) ;
2015-12-13 18:17:29 +01:00
/**
* Exports the app to this cloud . If an APPTEMPLATE64 is provided associated
* objects can also be created .
* @ param appid of the app
* @ param market_data of the associated marketplace in XML format
* @ param error descrition
*
* @ return 0 on success
*/
2015-12-14 16:47:33 +01:00
int export_app ( int appid , const std : : string & market_data , std : : string & err ) ;
2015-12-13 18:17:29 +01:00
/**
* Deletes an app from the marketplace .
2015-12-21 13:23:22 +01:00
* @ param appid of the app
* @ param market_data of the associated marketplace in XML format
* @ param error descrition
2015-12-13 18:17:29 +01:00
*
* @ return 0 on success
*/
2015-12-21 13:23:22 +01:00
int delete_app ( int appid , const std : : string & market_data , std : : string & err ) ;
2015-12-13 18:17:29 +01:00
/**
* Trigger a monitor action for the marketplace .
* @ param ds_id id of the datastore to monitor
*/
void monitor_market ( int ds_id ) ;
2015-12-21 13:23:22 +01:00
/**
* Relsease resources locked by this app during the import phase
* @ param appid of the app
*/
void release_app_resources ( int appid ) ;
2015-12-13 18:17:29 +01:00
private :
/**
* Generic name for the marketplace driver
*/
static const char * market_driver_name ;
/**
2020-07-24 16:00:59 +02:00
* Timer action async execution
2015-12-13 18:17:29 +01:00
*/
2020-07-24 16:00:59 +02:00
Timer timer_thread ;
2015-12-13 18:17:29 +01:00
/**
* Timer period for the Image Manager .
*/
time_t timer_period ;
/**
* Marketplace monitor interval
*/
time_t monitor_period ;
/**
* Pointer to the marketplace pool
*/
2020-07-24 16:00:59 +02:00
MarketPlacePool * mppool = nullptr ;
2015-12-13 18:17:29 +01:00
/**
* Pointer to the app pool
*/
2020-07-24 16:00:59 +02:00
MarketPlaceAppPool * apppool = nullptr ;
2015-12-13 18:17:29 +01:00
2020-07-24 16:00:59 +02:00
/**
2015-12-19 22:35:09 +01:00
* Pointer to the image pool
*/
2020-07-24 16:00:59 +02:00
ImagePool * ipool = nullptr ;
2015-12-19 22:35:09 +01:00
2020-07-24 16:00:59 +02:00
/**
2015-12-19 22:35:09 +01:00
* Pointer to the image pool
*/
2020-07-24 16:00:59 +02:00
DatastorePool * dspool = nullptr ;
2015-12-19 22:35:09 +01:00
2020-07-24 16:00:59 +02:00
/**
* Pointer to the Image Manger
2017-04-28 22:46:37 +02:00
*/
2020-07-24 16:00:59 +02:00
ImageManager * imagem = nullptr ;
2017-04-28 22:46:37 +02:00
2015-12-13 18:17:29 +01:00
/**
2020-07-24 16:00:59 +02:00
* Pointer to the Raft Manger
2015-12-13 18:17:29 +01:00
*/
2020-07-24 16:00:59 +02:00
RaftManager * raftm = nullptr ;
2015-12-13 18:17:29 +01:00
2021-05-21 23:25:37 +02:00
/**
* Manager is terminating , do not execute any action
*/
std : : atomic < bool > terminate { false } ;
2015-12-13 18:17:29 +01:00
/**
* Returns a pointer to the marketplace driver .
* @ return the marketplace manager driver or 0 in not found
*/
2020-07-05 22:01:32 +02:00
const Driver < market_msg_t > * get ( ) const
2015-12-13 18:17:29 +01:00
{
2020-06-29 12:14:00 +02:00
return DriverManager : : get_driver ( market_driver_name ) ;
2020-07-24 16:00:59 +02:00
}
2015-12-13 18:17:29 +01:00
/**
* Formats an XML message for the MAD
*
* @ param app_data marketplace app XML representation
* @ param market_data marketplace XML representation
* @ param extra_data additional XML formatted data for the driver
*
* @ return the XML message
*/
2020-07-05 22:01:32 +02:00
static std : : string format_message (
2015-12-13 18:17:29 +01:00
const std : : string & app_data ,
const std : : string & market_data ,
const std : : string & extra_data ) ;
2017-02-03 14:19:15 +01:00
2020-06-29 12:14:00 +02:00
// -------------------------------------------------------------------------
// Protocol implementation, procesing messages from driver
// -------------------------------------------------------------------------
2020-07-02 22:42:10 +02:00
static void _undefined ( std : : unique_ptr < market_msg_t > msg ) ;
void _import ( std : : unique_ptr < market_msg_t > msg ) ;
void _delete ( std : : unique_ptr < market_msg_t > msg ) ;
void _monitor ( std : : unique_ptr < market_msg_t > msg ) ;
static void _log ( std : : unique_ptr < market_msg_t > msg ) ;
2020-06-29 12:14:00 +02:00
2017-02-03 14:19:15 +01:00
// -------------------------------------------------------------------------
// Action Listener interface
// -------------------------------------------------------------------------
2015-12-13 18:17:29 +01:00
/**
* This function is executed periodically to monitor marketplaces . .
*/
2020-07-24 16:00:59 +02:00
void timer_action ( ) ;
2017-02-03 14:19:15 +01:00
2020-06-29 12:14:00 +02:00
static const int drivers_timeout = 10 ;
2015-12-13 18:17:29 +01:00
} ;
# endif /*MARKETPLACE_MANAGER_H*/