Missing is still the gathering of workload data and the implementatin of the nice algorithm, but the framework is up and running
-# $Id: Makefile.am,v 1.7 2006-11-29 21:43:37 marc Exp $
+# $Id: Makefile.am,v 1.8 2007-01-02 15:35:36 marc Exp $
# This doesn't actually build anything, it just tests whether the
# configuration files here correspond with the schema.
xmlconfig = $(srcdir)/config-bytarget.xml \
$(srcdir)/config-local.xml \
+ $(srcdir)/config-load-balance.xml \
$(srcdir)/config-record-transform.xml \
$(srcdir)/config-shared1.xml \
$(srcdir)/config-simple-multi.xml \
--- /dev/null
+<?xml version="1.0"?>
+<metaproxy xmlns="http://indexdata.com/metaproxy" version="1.0">
+ <start route="start"/>
+ <routes>
+ <route id="start">
+ <filter type="frontend_net">
+ <threads>10</threads>
+ <port>@:9000</port>
+ </filter>
+ <filter type="virt_db">
+ <virtual>
+ <database>db9001</database>
+ <target>localhost:9001/Default</target>
+ </virtual>
+ <virtual>
+ <database>db9002</database>
+ <target>localhost:9002/Default</target>
+ </virtual>
+ <virtual>
+ <database>db9003</database>
+ <target>localhost:9003/Default</target>
+ </virtual>
+ <virtual>
+ <database>Default</database>
+ <target>localhost:9001/Default</target>
+ <target>localhost:9002/Default</target>
+ <target>localhost:9003/Default</target>
+ </virtual>
+ </filter>
+ <filter type="log">
+ <message>VIRT</message>
+ </filter>
+ <filter type="load_balance"/>
+ <filter type="log">
+ <message>LOAD</message>
+ </filter>
+ <filter type="backend_test"/>
+ <!--
+ <filter type="z3950_client">
+ <timeout>30</timeout>
+ </filter>
+ -->
+ <filter type="bounce"/>
+ </route>
+ </routes>
+</metaproxy>
-## $Id: Makefile.am,v 1.60 2006-12-28 14:59:44 marc Exp $
+## $Id: Makefile.am,v 1.61 2007-01-02 15:35:36 marc Exp $
MAINTAINERCLEANFILES = Makefile.in config.in config.hpp
filter_bounce.cpp filter_bounce.hpp \
filter_frontend_net.cpp filter_frontend_net.hpp \
filter_http_file.cpp filter_http_file.hpp \
+ filter_load_balance.cpp filter_load_balance.hpp \
filter_log.cpp filter_log.hpp \
filter_multi.cpp filter_multi.hpp \
filter_query_rewrite.cpp filter_query_rewrite.hpp \
-/* $Id: factory_static.cpp,v 1.14 2006-12-28 14:59:44 marc Exp $
+/* $Id: factory_static.cpp,v 1.15 2007-01-02 15:35:36 marc Exp $
Copyright (c) 2005-2006, Index Data.
See the LICENSE file for details
#include "filter_bounce.hpp"
#include "filter_frontend_net.hpp"
#include "filter_http_file.hpp"
+#include "filter_load_balance.hpp"
#include "filter_log.hpp"
#include "filter_multi.hpp"
#include "filter_query_rewrite.hpp"
&metaproxy_1_filter_bounce,
&metaproxy_1_filter_frontend_net,
&metaproxy_1_filter_http_file,
+ &metaproxy_1_filter_load_balance,
&metaproxy_1_filter_log,
&metaproxy_1_filter_multi,
&metaproxy_1_filter_query_rewrite,
--- /dev/null
+/* $Id: filter_load_balance.cpp,v 1.1 2007-01-02 15:35:36 marc Exp $
+ Copyright (c) 2005-2006, Index Data.
+
+ See the LICENSE file for details
+ */
+
+#include "config.hpp"
+#include "filter.hpp"
+#include "filter_load_balance.hpp"
+#include "package.hpp"
+#include "util.hpp"
+
+#include <boost/thread/mutex.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include <yaz/zgdu.h>
+
+#include <iostream>
+
+namespace mp = metaproxy_1;
+namespace yf = mp::filter;
+
+namespace metaproxy_1 {
+ namespace filter {
+ class LoadBalance::Impl {
+ public:
+ Impl();
+ ~Impl();
+ void process(metaproxy_1::Package & package);
+ void configure(const xmlNode * ptr);
+ private:
+ boost::mutex m_mutex;
+ };
+ }
+}
+
+// define Pimpl wrapper forwarding to Impl
+
+yf::LoadBalance::LoadBalance() : m_p(new Impl)
+{
+}
+
+yf::LoadBalance::~LoadBalance()
+{ // must have a destructor because of boost::scoped_ptr
+}
+
+void yf::LoadBalance::configure(const xmlNode *xmlnode)
+{
+ m_p->configure(xmlnode);
+}
+
+void yf::LoadBalance::process(mp::Package &package) const
+{
+ m_p->process(package);
+}
+
+
+// define Implementation stuff
+
+
+
+yf::LoadBalance::Impl::Impl()
+{
+}
+
+yf::LoadBalance::Impl::~Impl()
+{
+}
+
+void yf::LoadBalance::Impl::configure(const xmlNode *xmlnode)
+{
+}
+
+void yf::LoadBalance::Impl::process(mp::Package &package)
+{
+ Z_GDU *gdu_req = package.request().get();
+
+
+ // passing anything but z3950 packages
+ if (!gdu_req
+ || !(gdu_req->which == Z_GDU_Z3950))
+ {
+ package.move();
+ return;
+ }
+
+
+ // target selecting only on Z39.50 init request
+ if (gdu_req->u.z3950->which == Z_APDU_initRequest){
+
+ mp::odr odr_en(ODR_ENCODE);
+ Z_InitRequest *org_init = gdu_req->u.z3950->u.initRequest;
+
+ // extracting virtual hosts
+ std::list<std::string> vhosts;
+
+ mp::util::remove_vhost_otherinfo(&(org_init->otherInfo), vhosts);
+
+ //std::cout << "LoadBalance::Impl::process() vhosts: "
+ // << vhosts.size() << "\n";
+ //std::cout << "LoadBalance::Impl::process()" << *gdu_req << "\n";
+
+ // choosing one target according to load-balancing algorithm
+
+ if (vhosts.size()){
+ std::string target;
+
+ // getting timestamp for receiving of package
+ boost::posix_time::ptime receive_time
+ = boost::posix_time::microsec_clock::local_time();
+
+ // //<< receive_time << " "
+ // //<< to_iso_string(receive_time) << " "
+ //<< to_iso_extended_string(receive_time) << " "
+ // package.session().id();
+
+ { // scope for locking local target database
+ boost::mutex::scoped_lock scoped_lock(m_mutex);
+ target = *vhosts.begin();
+ }
+
+
+ // copying new target into init package
+ mp::util::set_vhost_otherinfo(&(org_init->otherInfo), odr_en, target);
+ package.request() = gdu_req;
+ }
+
+ }
+
+
+ // moving all Z39.50 package typess
+ package.move();
+
+
+
+ //boost::posix_time::ptime send_time
+ // = boost::posix_time::microsec_clock::local_time();
+
+ //boost::posix_time::time_duration duration = send_time - receive_time;
+
+
+ // { // scope for locking local target database
+ // boost::mutex::scoped_lock scoped_lock(m_mutex);
+ // target = *vhosts.begin();
+ // }
+
+
+}
+
+
+static mp::filter::Base* filter_creator()
+{
+ return new mp::filter::LoadBalance;
+}
+
+extern "C" {
+ struct metaproxy_1_filter_struct metaproxy_1_filter_load_balance = {
+ 0,
+ "load_balance",
+ filter_creator
+ };
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
--- /dev/null
+/* $Id: filter_load_balance.hpp,v 1.1 2007-01-02 15:35:36 marc Exp $
+ Copyright (c) 2005-2006, Index Data.
+
+ See the LICENSE file for details
+ */
+
+// Filter that does nothing. Use as load_balance for new filters
+#ifndef FILTER_LOAD_BALANCE_HPP
+#define FILTER_LOAD_BALANCE_HPP
+
+#include <boost/scoped_ptr.hpp>
+
+#include "filter.hpp"
+
+namespace metaproxy_1 {
+ namespace filter {
+ class LoadBalance : public Base {
+ class Impl;
+ boost::scoped_ptr<Impl> m_p;
+ public:
+ LoadBalance();
+ ~LoadBalance();
+ void process(metaproxy_1::Package & package) const;
+ void configure(const xmlNode * ptr);
+ };
+ }
+}
+
+extern "C" {
+ extern struct metaproxy_1_filter_struct metaproxy_1_filter_load_balance;
+}
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
-/* $Id: util.cpp,v 1.23 2006-10-04 14:04:00 marc Exp $
+/* $Id: util.cpp,v 1.24 2007-01-02 15:35:36 marc Exp $
Copyright (c) 2005-2006, Index Data.
See the LICENSE file for details
}
}
+void mp_util::set_vhost_otherinfo(
+ Z_OtherInformation **otherInformation, ODR odr,
+ const std::string vhost, const int cat)
+{
+ yaz_oi_set_string_oidval(otherInformation, odr,
+ VAL_PROXY, cat, vhost.c_str());
+}
+
void mp_util::split_zurl(std::string zurl, std::string &host,
std::list<std::string> &db)
{
-/* $Id: util.hpp,v 1.22 2006-10-04 14:04:00 marc Exp $
+/* $Id: util.hpp,v 1.23 2007-01-02 15:35:36 marc Exp $
Copyright (c) 2005-2006, Index Data.
See the LICENSE file for details
int remove_vhost_otherinfo(Z_OtherInformation **otherInformation,
std::list<std::string> &vhosts);
+ void set_vhost_otherinfo(Z_OtherInformation **otherInformation,
+ ODR odr,
+ const std::string vhost,
+ const int cat = 1 );
+
void set_vhost_otherinfo(Z_OtherInformation **otherInformation,
ODR odr,
const std::list<std::string> &vhosts);
# Metaproxy XML config file schemas
-# $Id: metaproxy.rnc,v 1.12 2006-12-28 14:59:44 marc Exp $
+# $Id: metaproxy.rnc,v 1.13 2007-01-02 15:35:36 marc Exp $
#
# Copyright (c) 2005-2006, Index Data.
#
| filter_bounce
| filter_frontend_net
| filter_http_file
+ | filter_load_balance
| filter_log
| filter_multi
| filter_query_rewrite
element mp:prefix { xsd:string }
}
+filter_load_balance =
+ attribute type { "load_balance" },
+ attribute id { xsd:NCName }?,
+ attribute name { xsd:NCName }?
+
filter_log =
attribute type { "log" },
attribute id { xsd:NCName }?,