DatabaseCampaign: abstract campain for interaction with MySQL Database

The DatabaseCampaign interacts with the MySQL tables that are created
by the import-trace and prune-trace tools. It does offer all
unfinished experiment pilots from the database to the
fail-clients. Those clients send back a (by the experiment) defined
protobuf message as a result. The custom protobuf message does have to
need the form:

   import "DatabaseCampaignMessage.proto";

   message ExperimentMsg {
       required DatabaseCampaignMessage fsppilot = 1;

       repeated group Result = 2 {
          // custom fields
          required int32 bitoffset = 1;
          optional int32 result = 2;
       }
   }

The DatabaseCampaignMessage is the pilot identifier from the
database. For each of the repeated result entries a row in a table is
allocated. The structure of this table is constructed (by protobuf
reflection) from the description of the message. Each field in the
Result group becomes a column in the result table. For the given
example it would be:

    CREATE TABLE result_ExperimentMessage(
           pilot_id INT,
           bitoffset INT NOT NULL,
           result INT,
           PRIMARY_KEY(pilot_id)
    )

Change-Id: I28fb5488e739d4098b823b42426c5760331027f8
This commit is contained in:
Christian Dietrich
2013-03-25 16:04:05 +01:00
parent 59e5fd3169
commit f18cddc63c
25 changed files with 1161 additions and 119 deletions

View File

@ -0,0 +1,66 @@
#ifndef __CPN_DATABASE_CAMPAIGN_H__
#define __CPN_DATABASE_CAMPAIGN_H__
#include "util/Database.hpp"
#include "util/DatabaseProtobufAdapter.hpp"
#include "comm/DatabaseCampaignMessage.pb.h"
#include "Campaign.hpp"
#include "comm/ExperimentData.hpp"
#include <google/protobuf/message.h>
namespace fail {
/**
* \class Campaign
*
* Interface for a generic database driven campaign. It uses the
* results from mysql tables that are genrated by the import-trace and
* prune-trace.
*/
class DatabaseCampaign : public Campaign {
Database *db; // !< The database connection object
DatabaseProtobufAdapter db_connect;
int variant_id; // !< Which variant do we work on (from CMDLINE)
int fspmethod_id; // !< Which fspmethod should be put out to the clients
void collect_result_thread();
int sent_pilots;
public:
DatabaseCampaign() {};
/**
* Defines the campaign. In the DatabaseCampaign the database
* connection is done
* @return \c true if the campaign was successful, \c false otherwise
*/
virtual bool run();
/**
* Callback function that can be used to add command line options
* to the campaign
*/
virtual bool cb_commandline_init() { return true; }
/**
* Callback to the campagin to get the result message descriptor
*/
virtual const google::protobuf::Descriptor * cb_result_message() = 0;
/**
* Callback that gets a DatabaseExperimentData instance, that is
* filled with a concrete experiment pilot from the database. The
* application should wrap the DatabaseCampaignMessage pilot into
* a custom message and give it to the campainmanager.
*/
virtual void cb_send_pilot(DatabaseCampaignMessage pilot) = 0;
};
}
#endif