[Opennebula] Middleware interview driver

Source: Internet
Author: User

/*--------------------------------------------------------------------------*//* Copyright 2002-2014, Opennebula                                                                            Project (opennebula.org), c12g Labs *//* *//* Licensed under the Apache License, Version 2.0 (the "License"); You may *//* not use this file except in compliance with the License.                                                                            Obtain *//* a copy of the License at *//*                                 *//* http://www.apache.org/licenses/LICENSE-2.0 *//* *//* unless required by APPL           Icable law or agreed into writing, software *//* distributed under the License is distributed on a "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 mad_h_#define mad_h_# Include <pthread.h> #include <sys/types.h> #include <map> #include <string> #include < sstream> #include <unistd.h> #include "Log.h" using namespace std;/** * Base class to build specific middleware Acce SS Drivers (MAD). * This class provides generic MAD functionality. */class mad{protected:/** * The constructor initialize the class members but DOES not start the * driver.     A subsequent call to the start () method is needed. * @param userid User running this MAD * @param attrs configuration attributes for the driver * @param Sud o The driver is started through sudo if true */Mad (int userid, const map<string,string> &     Attrs, bool sudo): UID (userid),       Attributes (Attrs), sudo_execution (sudo), PID (-1) {};     /** * The destructor of the class finalizes the driver process, and all its * associated resources (i.e. pipes)    */virtual ~mad (); /** * Send a command to the driver * @param os an output string stream with the message, it must be * t     Erminated with the end of line character.        */void Write (ostringstream& os) const {string str;        const char * CSTR;        str = OS.STR ();        CStr = Str.c_str ();    :: Write (Nebula_mad_pipe, CStr, Str.size ());    };      /** * Send a driver_cancel command to the DRIVER * @param OID identifies the action (which associated with OID)        */void Driver_cancel (const int oid) const {Ostringstream OS;        Os << "Driver_cancel" << oid << Endl;    Write (OS);    };     /** * Sets the log message type as specify by the driver. * @pAram first character of the type String * @return the message type */Log::messagetype log_type (const char R        ) const {Log::messagetype lt;                Switch (r) {case ' E ': lt = log::error;            Break                Case ' I ': lt = log::info;            Break                Case ' D ': lt = Log::D ebug;            Break        Default:lt = Log::info;    } return lt;    }private:friend class Madmanager; /** * Communication pipe file descriptor.    Represents the MAD to nebula * Communication Stream (NEBULA&LT;-MAD) */int mad_nebula_pipe; /** * Communication pipe file descriptor.    Represents the nebula to MAD * Communication Stream (NEBULA-&GT;MAD) */int nebula_mad_pipe;    /** * User running this MAD as defined in the Upool DB */int uid; /** * Mad Configuration attributes (e.g. executable, attributes ...).     Attribute * names must be lowecase.    */map<string,string> attributes;     /** * True If the mad is to be executed through sudo, with the identity of the * Mad Owner (UID).    */bool Sudo_execution;     /** * Process ID of the running MAD.    */pid_t PID; /** * Starts the MAD. This function creates a new process, sets up the * communication pipes and sends the initialization command to the DR     Iver.    * @return 0 on Success */int start (); /** * Reloads the Driver:sends the Finalize command, "waits" for the * driver process and closes the Communicat Ion pipes. Then the driver was * started again by calling the start () function * @return 0 on Success */int Reload    ();      /** * Implements the driver specific protocol, this function should trigger * actions on the associated manager. * @param message THe string read from the driver */virtual void Protocol (const string& message) const = 0; /** * This function is called whenever the driver crashes.     This function * should perform the actions needed to recover the VMs. */virtual void recover () = 0;}; #endif/*mad_h_*/


The above class is the Opennebula middleware access-driven interface.

[Opennebula] Middleware interview driver

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.