Commit b5ca3512 authored by Ryan Jackson's avatar Ryan Jackson

Change event scheduler to use xmlrpc-c library

Modify the event scheduler to use the BSD-licensed xmlrpc-c library
instead of the LGPL-licensed ulxmlrpcpp.
parent d30542c8
......@@ -20,7 +20,7 @@ endif
ifeq ($(SYSTEM),FreeBSD)
FBSDREL := $(shell uname -r | sed -e 's/\([^-][^-]*\)-.*/\1/')
FBSDMAJ := $(basename $(FBSDREL))
SUBDIRS += sched stated
SUBDIRS += sched new_sched stated
ifneq ($(FBSDMAJ),8)
# doesn't build right now due to API changes
SUBDIRS += delay-agent
......@@ -44,6 +44,7 @@ etc-subdir:
install:
@$(MAKE) -C lib install
@$(MAKE) -C sched install
@$(MAKE) -C new_sched install
@$(MAKE) -C tbgen install
@$(MAKE) -C stated install
@$(MAKE) -C linktest install
......@@ -57,6 +58,7 @@ control-install:
@$(MAKE) -C lib control-install
@$(MAKE) -C tbgen control-install
@$(MAKE) -C sched control-install
@$(MAKE) -C new_sched control-install
@$(MAKE) -C linktest control-install
@$(MAKE) -C program-agent control-install
@$(MAKE) -C proxy control-install
......
......@@ -7,7 +7,7 @@
SRCDIR = @srcdir@
TESTBED_SRCDIR = @top_srcdir@
OBJDIR = ../..
SUBDIR = event/sched
SUBDIR = event/new_sched
include $(OBJDIR)/Makeconf
......@@ -28,10 +28,10 @@ LDFLAGS += $(LDSTATIC)
DBLIBS = -L/usr/local/lib/mysql -lmysqlclient -lz
LIBS += -levent_r -ltb -lz
ULXRINC = -I/usr/local/include -I/usr/local/include/ulxmlrpcpp
CXXFLAGS += -pthread -O $(ULXRINC) -I$(OBJDIR) -I$(TESTBED_SRCDIR)/lib/libtb
XMLRPCINC = `xmlrpc-c-config c++2 client --cflags`
CXXFLAGS += -pthread -O $(XMLRPCINC) -I$(OBJDIR) -I$(TESTBED_SRCDIR)/lib/libtb
CXXFLAGS += -I$(SRCDIR)/../lib
ULXRLIBS = -L/usr/local/lib -lulsshxmlrpcpp -lulxmlrpcpp -lexpat
XMLRPCLIBS = `xmlrpc-c-config c++2 client --libs`
#
# XXX elvin-config adds -lc which is rather bogus, and messes up -pthread
......@@ -47,6 +47,7 @@ version.c: event-sched.c
echo >$@ "char build_info[] = \"Built on `date +%d-%b-%Y` by `id -nu`@`hostname | sed 's/\..*//'`:`pwd`\";"
OBJS = \
emulab_proxy.o \
console-agent.o \
error-record.o \
event-sched_rpc.o \
......@@ -61,13 +62,14 @@ OBJS = \
version.o
event-sched_rrpc: $(OBJS) event-sched.h ../lib/libevent.a
$(CXX) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(ULXRLIBS) $(LIBS)
$(CXX) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(XMLRPCLIBS) $(LIBS)
DEPS = \
console-agent.h error-record.h event-sched.h group-agent.h listNode.h \
local-agent.h node-agent.h rpc.h simulator-agent.h timeline-agent.h \
../lib/event.h
emulab_proxy.o: emulab_proxy.cc $(DEPS)
queue.o: queue.c $(DEPS)
listNode.o: listNode.c $(DEPS)
error-record.o: error-record.c $(DEPS)
......@@ -79,14 +81,14 @@ node-agent.o: node-agent.cc $(DEPS)
event-sched_rpc.o: event-sched.c $(DEPS)
$(CC) $(CFLAGS) -DRPC -c -o $@ $<
rpc.o: rpc.cc rpc.h event-sched.h
$(CXX) $(CXXFLAGS) -DSSHRPC $(ULXRINC) -c $<
$(CXX) $(CXXFLAGS) -DSSHRPC $(XMLRPCINC) -c $<
rrpc.o: rpc.cc $(DEPS)
$(CXX) -g $(CXXFLAGS) -DSSLRPC $(ULXRINC) -c -o rrpc.o $<
$(CXX) -g $(CXXFLAGS) -DSSLRPC $(XMLRPCINC) -c -o rrpc.o $<
install: event-sched_rrpc
-mkdir -p $(INSTALL_DIR)/opsdir/sbin
$(INSTALL_PROGRAM) $< $(INSTALL_DIR)/opsdir/sbin/event-sched
$(INSTALL_PROGRAM) $< $(INSTALL_DIR)/opsdir/sbin/new-event-sched
-mkdir -p $(INSTALL_DIR)/opsdir/man/man8
$(INSTALL) -m 0644 $(SRCDIR)/event-sched.8 \
$(INSTALL_DIR)/opsdir/man/man8/event-sched.8
......@@ -95,7 +97,7 @@ install: event-sched_rrpc
$(INSTALL_DIR)/opsdir/bin/elog2xplot
control-install: event-sched_rrpc
$(INSTALL_PROGRAM) $< $(INSTALL_SBINDIR)/event-sched
$(INSTALL_PROGRAM) $< $(INSTALL_SBINDIR)/new-event-sched
# not a client thing
client:
......
/*
* emulab_proxy.cpp
*
* Copyright (c) 2004 The University of Utah and the Flux Group.
* All rights reserved.
*
* This file is licensed under the terms of the GNU Public License.
* See the file "license.terms" for restrictions on redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/client.hpp>
#include <assert.h>
#include <xmlrpc-c/girerr.hpp>
#include <map>
#include <iostream>
#include "emulab_proxy.h"
using namespace emulab;
/**
* The Emulab XML-RPC protocol version number.
*/
static const double PROTOCOL_VERSION = 0.1;
EmulabResponse::EmulabResponse(const er_code_t code,
const xmlrpc_c::value value,
const xmlrpc_c::value output)
: er_Code(code), er_Value(value), er_Output(output)
{
}
EmulabResponse::EmulabResponse(xmlrpc_c::value result)
{
std::map<std::string, xmlrpc_c::value> result_map;
std::map<std::string, xmlrpc_c::value>::iterator p;
if (!result.type() == xmlrpc_c::value::TYPE_STRUCT)
{
throw girerr::error("Invalid response from server");
}
result_map = (xmlrpc_c::value_struct)result;
/* Make sure the result has what we expect before */
p = result_map.find("code");
if (p == result_map.end()) {
throw girerr::error("Invalid response from server");
}
/* ... decoding its contents. */
this->er_Code = (er_code_t)(int)(xmlrpc_c::value_int)result_map["code"];
this->er_Value = result_map["value"];
this->er_Output = result_map["output"];
}
EmulabResponse::~EmulabResponse()
{
}
ServerProxy::ServerProxy(xmlrpc_c::clientXmlTransportPtr transport,
bool wbxml_mode,
const char *url)
{
this->transport = transport;
this->server_url = url;
}
ServerProxy::~ServerProxy()
{
}
xmlrpc_c::value ServerProxy::call(xmlrpc_c::rpcPtr rpc)
{
xmlrpc_c::client_xml client(this->transport);
xmlrpc_c::carriageParm_curl0 carriage_parm(this->server_url);
rpc->call(&client, &carriage_parm);
assert(rpc->isFinished());
/* This will throw an exception if the RPC call failed */
return rpc->getResult();
}
EmulabResponse ServerProxy::invoke(const char *method_name,
spa_attr_t tag,
...)
{
va_list args;
va_start(args, tag);
EmulabResponse retval = this->invoke(method_name, tag, args);
va_end(args);
return( retval );
}
EmulabResponse ServerProxy::invoke(const char *method_name,
spa_attr_t tag,
va_list args)
{
xmlrpc_c::paramList params;
std::map <std::string, xmlrpc_c::value> struct_data;
/* Iterate over the tag list to build the argument structure, */
while( tag != SPA_TAG_DONE )
{
std::string key;
key = std::string(va_arg(args, const char *));
switch( tag )
{
case SPA_Boolean:
struct_data[key] =
xmlrpc_c::value_boolean((bool)va_arg(args, int));
break;
case SPA_Integer:
struct_data[key] =
xmlrpc_c::value_int(va_arg(args, int));
break;
case SPA_Double:
struct_data[key] =
xmlrpc_c::value_double(va_arg(args, double));
break;
case SPA_String:
struct_data[key] =
xmlrpc_c::value_string(
std::string(va_arg(args, const char *)));
break;
default:
break;
}
tag = (spa_attr_t)va_arg(args, int);
}
/* ... add the parameters, and */
params.add(xmlrpc_c::value_double(PROTOCOL_VERSION));
params.add(xmlrpc_c::value_struct(struct_data));
xmlrpc_c::rpcPtr rpc(std::string(method_name), params);
/* ... call the method. */
return EmulabResponse(this->call(rpc));
}
/*
* emulab_proxy.h
*
* Copyright (c) 2004 The University of Utah and the Flux Group.
* All rights reserved.
*
* This file is licensed under the terms of the GNU Public License.
* See the file "license.terms" for restrictions on redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#ifndef emulab_proxy_h
#define emulab_proxy_h
#include <xmlrpc-c/base.hpp>
#include <stdarg.h>
#include <string>
#include <xmlrpc-c/client.hpp>
namespace emulab {
/**
* Response codes used by the Emulab server.
*/
typedef enum {
ERC_SUCCESS = 0, /**< Method completed successfully. */
ERC_BADARGS, /**< Bad arguments. */
ERC_ERROR, /**< There was an error while executing the method. */
ERC_FORBIDDEN, /**< You are forbidden from executing a method. */
ERC_BADVERSION, /**< The supplied version number was incorrect. */
ERC_SERVERERROR, /**< The server encountered an unrecoverable error. */
ERC_TOOBIG, /**< The request message is too large. */
ERC_REFUSED, /**< The server refused to execute the method.
(a temporary condition, retry later.) */
ERC_MAX
} er_code_t;
/**
* Class used to encode a standard response to a method.
*/
class EmulabResponse
{
public:
/**
* Empty constructor.
*/
explicit EmulabResponse() {};
/**
* Construct an EmulabResponse object with the given values.
*
* @param code The response code, indicates success or failure.
* @param value The result of executing the method.
* @param output The debugging output generated by the method.
*/
EmulabResponse(const er_code_t code,
const xmlrpc_c::value value,
const xmlrpc_c::value output);
/**
* Construct an EmulabResponse from a ulxmlrpcpp style response.
*
* @param result The response to turn into an EmulabResponse.
*/
EmulabResponse(xmlrpc_c::value result);
/**
* Destructor...
*/
virtual ~EmulabResponse();
/**
* @return The response code, indicates success or failure.
*/
er_code_t getCode() { return( this->er_Code ); };
/**
* @return The result of executing the method.
*/
xmlrpc_c::value getValue() { return( this->er_Value ); };
/**
* @return The debugging output generated by the method.
*/
xmlrpc_c::value_string getOutput() { return( (xmlrpc_c::value_string)this->er_Output ); };
/**
* @return True if this response indicates a successful method execution.
*/
bool isSuccess() { return( this->er_Code == ERC_SUCCESS ); };
private:
/**
* The response code, indicates success or failure.
*/
er_code_t er_Code;
/**
* The result of executing the method.
*/
xmlrpc_c::value er_Value;
/**
* The debugging output generated by the method.
*/
xmlrpc_c::value er_Output;
};
/**
* Attribute tags passed to ServerProxy::invoke.
*
* @sa emulab::ServerProxy
*/
typedef enum {
SPA_TAG_DONE, /**< Terminator tag. */
SPA_Boolean, /**< (const char *key, bool val) */
SPA_Integer, /**< (const char *key, int val) */
SPA_Double, /**< (const char *key, double val) */
SPA_String, /**< (const char *key, const char *val) */
} spa_attr_t;
class ServerProxy
{
public:
/**
* Construct ServerProxy with the given values.
*
* @param transport The transport to use when communicating with the server.
* @param wbxml_mode Indicate whether or not wbxml should be used.
* @param url The url to use.
*/
ServerProxy(xmlrpc_c::clientXmlTransportPtr transport,
bool wbxml_mode = false,
const char *url = "");
/**
* Destructor...
*/
virtual ~ServerProxy();
/**
* Invoke an Emulab method with the given parameters. The arguments are
* given in a tag list, where you specify the type, parameter name, and
* its value. For example, the following code would get the state of the
* experiment "bar" in project "foo":
*
* @code
* sp.invoke("state",
* SPA_String, "proj", "foo",
* SPA_String, "exp", "bar",
* SPA_TAG_DONE);
* @endcode
*
* @param method_name The name of the method to execute.
* @param tag The tag in the list.
*/
EmulabResponse invoke(const char *method_name, spa_attr_t tag, ...);
/**
* The va_list version of the invoke method.
*
* @param method_name The name of the method to execute.
* @param tag The tag in the list.
* @param args The rest of the tag list.
*/
virtual EmulabResponse invoke(const char *method_name,
spa_attr_t tag,
va_list args);
private:
xmlrpc_c::value call(xmlrpc_c::rpcPtr rpc);
xmlrpc_c::clientXmlTransportPtr transport;
std::string server_url;
};
}
#endif
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2004, 2005 University of Utah and the Flux Group.
* All rights reserved.
n * All rights reserved.
*/
#include "config.h"
......@@ -9,6 +9,7 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <cstring>
#include "systemf.h"
#include "rpc.h"
......@@ -165,7 +166,7 @@ static void dump_node_logs(int token, struct agent **agent_array, int aa_len,
FILE *file;
int lpc;
output = er->getOutput().c_str();
output = ((std::string)er->getOutput()).c_str();
for (lpc = 0; lpc < aa_len; lpc++) {
char filename[1024];
......
......@@ -20,6 +20,14 @@
#include <errno.h>
#include "event-sched.h"
#ifndef TIMEVAL_TO_TIMESPEC
#define TIMEVAL_TO_TIMESPEC(tv, ts) { \
(ts)->tv_sec = (tv)->tv_sec; \
(ts)->tv_nsec = (tv)->tv_usec * 1000; \
}
#endif
/* The size of the event queue (i.e., the number of events that can be
pending at any given time). */
#define EVENT_QUEUE_LENGTH (1024 * 32)
......
This diff is collapsed.
......@@ -11,32 +11,23 @@
#ifdef __cplusplus
#include <ulxmlrpcpp.h> // always first header
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/girerr.hpp>
#include <xmlrpc-c/client.hpp>
#include <iostream>
#include <ulxr_tcpip_connection.h> // first, don't move: msvc #include bug
#include <ulxr_ssl_connection.h>
#include <ulxr_http_protocol.h>
#include <ulxr_requester.h>
#include <ulxr_value.h>
#include <ulxr_except.h>
#include <emulab_proxy.h>
#include "emulab_proxy.h"
int RPC_invoke(char *method,
emulab::EmulabResponse *er_out,
emulab::spa_attr_t tag,
...);
struct rpc_conn_proto {
ulxr::Connection *conn;
ulxr::Protocol *proto;
};
struct r_rpc_data {
const char *certpath;
const char *host;
unsigned short port;
int refcount;
struct rpc_conn_proto conn_proto;
xmlrpc_c::clientXmlTransport *transport;
pthread_mutex_t mutex;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment