http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/Rebus/ServiceImpl/Client.cs ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/Rebus/ServiceImpl/Client.cs b/depends/thirdparty/thrift/contrib/Rebus/ServiceImpl/Client.cs new file mode 100644 index 0000000..2408041 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/Rebus/ServiceImpl/Client.cs @@ -0,0 +1,157 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +using Rebus; +using Rebus.Configuration; +using Rebus.Messages; +using Rebus.RabbitMQ; +using System; +using System.Collections.Generic; +using System.IO; +using Thrift.Protocol; +using Thrift.Transport; + +/* + * The client emits calls to BasicMathServers + * + * The client implements the BasicMathClient service. + * If the server has processed our request, we get the results back through this service + */ + +namespace RebusSample.Client +{ + + // handler to be registered with Rebus + class MathResponseCallHandler : IHandleMessages<MathResponseCall> + { + public void Handle(MathResponseCall message) + { + // Thrift protocol/transport stack + var stm = new MemoryStream(message.rawBytes); + var trns = new TStreamTransport(stm, null); + var prot = new TBinaryProtocol(trns); + + // create a processor and let him handle the call + var hndl = new MathResponsesHandler(); + var proc = new BasicMathClient.Processor(hndl); + proc.Process(prot, null); // oneway only + } + } + + + // serves incoming responses with calculation results + internal class MathResponsesHandler : BasicMathClient.Iface + { + public void FourResults(int added, int multiplied, int subtracted, int divided) + { + Console.WriteLine("added = {0}", added); + Console.WriteLine("multiplied= {0}", multiplied); + Console.WriteLine("subtracted = {0}", subtracted); + Console.WriteLine("divided = {0}", divided); + + PingAndDoAnotherCalculation(); + } + + + public void ThreeResults(int added, int multiplied, int subtracted) + { + Console.WriteLine("added = {0}", added); + Console.WriteLine("multiplied= {0}", multiplied); + Console.WriteLine("subtracted = {0}", subtracted); + Console.WriteLine("DIV/0 error during division"); + + PingAndDoAnotherCalculation(); + } + + + public void Pong(long value) + { + var latency = DateTime.Now.Ticks - value; + Console.WriteLine("Ping took {0} ms", new DateTime(latency).Millisecond); + } + + + private void PingAndDoAnotherCalculation() + { + var random = new Random(); + var client = new MathRequestClient("localhost"); + client.Ping(DateTime.Now.Ticks); + client.DoTheMath(random.Next(), random.Next()); + } + } + + + // provides the client-side interface for calculation requests + internal class MathRequestClient : BasicMathServer.Iface + { + private BuiltinContainerAdapter MQAdapter; + + + public MathRequestClient(string server) + { + MQAdapter = new BuiltinContainerAdapter(); + Configure.With(MQAdapter) + .Transport(t => t.UseRabbitMqInOneWayMode("amqp://" + server)) // we need send only + .MessageOwnership(o => o.FromRebusConfigurationSection()) + .CreateBus().Start(); + } + + + public void SerializeThriftCall(Action<BasicMathServer.Iface> action) + { + // Thrift protocol/transport stack + var stm = new MemoryStream(); + var trns = new TStreamTransport(null, stm); + var prot = new TBinaryProtocol(trns); + + // serialize the call into a bunch of bytes + var client = new BasicMathServer.Client(prot); + if( action != null) + action(client); + else + throw new ArgumentException("action must not be null"); + + // make sure everything is written to the MemoryStream + trns.Flush(); + + // send the message + var msg = new MathRequestCall() { rawBytes = stm.ToArray() }; + MQAdapter.Bus.Send(msg); + } + + + public void Ping(long value) + { + SerializeThriftCall(client => + { + client.Ping(value); + }); + } + + + public void DoTheMath( int arg1, int arg2) + { + SerializeThriftCall(client => + { + client.DoTheMath(arg1, arg2); + }); + } + } +} +
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/Rebus/ServiceImpl/Server.cs ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/Rebus/ServiceImpl/Server.cs b/depends/thirdparty/thrift/contrib/Rebus/ServiceImpl/Server.cs new file mode 100644 index 0000000..149d513 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/Rebus/ServiceImpl/Server.cs @@ -0,0 +1,143 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +using Rebus; +using Rebus.Configuration; +using Rebus.Messages; +using Rebus.RabbitMQ; +using System; +using System.Collections.Generic; +using System.IO; +using Thrift.Protocol; +using Thrift.Transport; + +/* + * The server implements the BasicMathServer service . + * All results are sent back to the client via the BasicMathClient service + */ + + +namespace RebusSample.Server +{ + // handler to be registered with Rebus + class MathRequestCallHandler : IHandleMessages<MathRequestCall> + { + public void Handle(MathRequestCall message) + { + // Thrift protocol/transport stack + var stm = new MemoryStream(message.rawBytes); + var trns = new TStreamTransport(stm, null); + var prot = new TBinaryProtocol(trns); + + // create a processor and let him handle the call + var hndl = new MathRequestsHandler(); + var proc = new BasicMathServer.Processor(hndl); + proc.Process(prot, null); // oneway only + } + } + + + // serves incoming calculation requests + internal class MathRequestsHandler : BasicMathServer.Iface + { + public void Ping(long value) + { + var client = new MathResponseClient("localhost"); + client.Pong(value); + } + + + public void DoTheMath(int arg1, int arg2) + { + var client = new MathResponseClient("localhost"); + if( arg2 != 0) + client.FourResults( arg1+arg2, arg1*arg2, arg1-arg2, arg1/arg2); + else + client.ThreeResults( arg1+arg2, arg1*arg2, arg1-arg2); + } + } + + + // provides the client-side interface for calculation responses + internal class MathResponseClient : BasicMathClient.Iface + { + private BuiltinContainerAdapter MQAdapter; + + + public MathResponseClient(string server) + { + MQAdapter = new BuiltinContainerAdapter(); + Configure.With(MQAdapter) + .Transport(t => t.UseRabbitMqInOneWayMode("amqp://" + server)) // we need send only + .MessageOwnership(o => o.FromRebusConfigurationSection()) + .CreateBus().Start(); + } + + + public void SerializeThriftCall(Action<BasicMathClient.Iface> action) + { + // Thrift protocol/transport stack + var stm = new MemoryStream(); + var trns = new TStreamTransport(null, stm); + var prot = new TBinaryProtocol(trns); + + // serialize the call into a bunch of bytes + var client = new BasicMathClient.Client(prot); + if (action != null) + action(client); + else + throw new ArgumentException("action must not be null"); + + // make sure everything is written to the MemoryStream + trns.Flush(); + + // send the message + var msg = new MathResponseCall() { rawBytes = stm.ToArray() }; + MQAdapter.Bus.Send(msg); + } + + + public void Pong(long value) + { + SerializeThriftCall(client => + { + client.Pong(value); + }); + } + + + public void ThreeResults(int added, int multiplied, int suctracted) + { + SerializeThriftCall(client => + { + client.ThreeResults(added, multiplied, suctracted); + }); + } + + + public void FourResults(int added, int multiplied, int suctracted, int divided) + { + SerializeThriftCall(client => + { + client.FourResults(added, multiplied, suctracted, divided); + }); + } + } +} + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/Rebus/sample.thrift ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/Rebus/sample.thrift b/depends/thirdparty/thrift/contrib/Rebus/sample.thrift new file mode 100644 index 0000000..785e2d3 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/Rebus/sample.thrift @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + + +service BasicMathServer { + oneway void DoTheMath( 1: i32 arg1, 2: i32 arg2) + oneway void Ping(1: i64 value) +} + +service BasicMathClient { + oneway void ThreeResults( 1 : i32 added, 2 : i32 multiplied, 3 : i32 subtracted); + oneway void FourResults( 1 : i32 added, 2 : i32 multiplied, 3 : i32 subtracted, 4 : i32 divided); + oneway void Pong(1: i64 value) +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/Stomp/README.md ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/Stomp/README.md b/depends/thirdparty/thrift/contrib/Stomp/README.md new file mode 100644 index 0000000..2e5f21c --- /dev/null +++ b/depends/thirdparty/thrift/contrib/Stomp/README.md @@ -0,0 +1,18 @@ +Sample code for STOMP-based Thrift clients and/or servers. + +Although the sample Thrift STOMP Transport is written in +Delphi/Pascal, it can easily serve as a starting point for +similar implementations in other languages. + +STOMP is a protocol widely supported by many messaging systems, +such as Apache ActiveMQ, RabbitMQ and many others. In particular, +it can be used to communicate with Service-Bus products like Rebus +or NServiceBus, when running against a STOMP-capable MQ system. + +A prerequisite for this sample is the Delphi STOMP Adapter written +by Daniele Teti (http://www.danieleteti.it/stomp-client), currently +hosted at Google Code (http://code.google.com/p/delphistompclient). + +At the time of writing, the STOMP adapter does not fully support +binary data. Please check whether this has been fixed, otherwise +you have to use the JSON protocol (or to fix it on your own). http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/Stomp/Thrift.Transport.STOMP.pas ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/Stomp/Thrift.Transport.STOMP.pas b/depends/thirdparty/thrift/contrib/Stomp/Thrift.Transport.STOMP.pas new file mode 100644 index 0000000..7dfb376 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/Stomp/Thrift.Transport.STOMP.pas @@ -0,0 +1,200 @@ +(* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + *) + +unit Thrift.Transport.STOMP; + +interface + +uses + Classes,Windows, SysUtils, + Thrift, + Thrift.Transport, + Thrift.Protocol, + Thrift.Stream, + StompClient, + StompTypes; + +type + TStompTransportImpl = class( TStreamTransportImpl) + strict private + FData : TStringStream; + FServer : string; + FOutQueue : string; + FStompCli : IStompClient; + protected + function GetIsOpen: Boolean; override; + function Peek: Boolean; override; + public + constructor Create( const aServerAndPort, aOutQueue : string); + destructor Destroy; override; + + procedure Open(); override; + procedure Close(); override; + procedure Flush; override; + end; + + + TStompServerTransportImpl = class( TServerTransportImpl) + strict private + FServer : string; + FInQueue : string; + FClient : IStompClient; + protected + procedure Listen; override; + procedure Close; override; + function Accept( const fnAccepting: TProc): ITransport; override; + public + constructor Create( const aServerAndPort, aInQueue : string); + destructor Destroy; override; + end; + + +const + QUEUE_PREFIX = '/queue/'; + TOPIC_PREFIX = '/topic/'; + EXCHANGE_PREFIX = '/exchange/'; + + +implementation + + + +constructor TStompTransportImpl.Create( const aServerAndPort, aOutQueue : string); +var adapter : IThriftStream; +begin + FData := TStringStream.Create; + FServer := aServerAndPort; + FOutQueue := aOutQueue; + + adapter := TThriftStreamAdapterDelphi.Create( FData, FALSE); + inherited Create( nil, adapter); // output only +end; + + +destructor TStompTransportImpl.Destroy; +begin + inherited Destroy; + FreeAndNil( FData); + FStompCli := nil; +end; + + +function TStompTransportImpl.GetIsOpen: Boolean; +begin + result := (FStompCli <> nil); +end; + + +function TStompTransportImpl.Peek: Boolean; +begin + result := FALSE; // output only +end; + + +procedure TStompTransportImpl.Open; +begin + if FStompCli <> nil + then raise TTransportException.Create( TTransportException.TExceptionType.AlreadyOpen, 'already open') + else FStompCli := StompUtils.NewStomp( FServer); +end; + + +procedure TStompTransportImpl.Close; +begin + FStompCli := nil; + FData.Clear; +end; + + +procedure TStompTransportImpl.Flush; +begin + if FStompCli = nil + then raise TTransportException.Create( TTransportException.TExceptionType.NotOpen, 'not open'); + + FStompCli.Send( FOutQueue, FData.DataString); + FData.Clear; +end; + + +//--- TStompServerTransportImpl -------------------------------------------- + + +constructor TStompServerTransportImpl.Create( const aServerAndPort, aInQueue : string); +begin + inherited Create; + FServer := aServerAndPort; + FInQueue := aInQueue; +end; + + +destructor TStompServerTransportImpl.Destroy; +begin + try + Close; + finally + inherited Destroy; + end; +end; + + +procedure TStompServerTransportImpl.Listen; +begin + FClient := StompUtils.NewStomp(FServer); + FClient.Subscribe( FInQueue); +end; + + +procedure TStompServerTransportImpl.Close; +begin + if FClient <> nil then begin + FClient.Unsubscribe( FInQueue); + FClient := nil; + end; +end; + + +function TStompServerTransportImpl.Accept( const fnAccepting: TProc): ITransport; +var frame : IStompFrame; + adapter : IThriftStream; + stream : TStringStream; +begin + if FClient = nil + then raise TTransportException.Create( TTransportException.TExceptionType.NotOpen, + 'Not connected.'); + + if Assigned(fnAccepting) + then fnAccepting(); + + try + frame := FClient.Receive(MAXINT); + if frame = nil then Exit(nil); + + stream := TStringStream.Create( frame.GetBody); + adapter := TThriftStreamAdapterDelphi.Create( stream, TRUE); + result := TStreamTransportImpl.Create( adapter, nil); + + except + on E: Exception + do raise TTransportException.Create( E.ToString ); + end; +end; + + +end. + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/Vagrantfile ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/Vagrantfile b/depends/thirdparty/thrift/contrib/Vagrantfile new file mode 100644 index 0000000..d9a908d --- /dev/null +++ b/depends/thirdparty/thrift/contrib/Vagrantfile @@ -0,0 +1,133 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +$build_and_test = <<SCRIPT +echo "Provisioning system to compile and test Apache Thrift." + +# Create swap space +sudo fallocate -l 2G /swapfile +sudo chmod 600 /swapfile +sudo mkswap /swapfile +sudo swapon /swapfile +sudo swapon -s + +# Update the system +sudo DEBIAN_FRONTEND=noninteractive apt-get update -qq -y +sudo DEBIAN_FRONTEND=noninteractive apt-get upgrade -qq -y + +# Install Dependencies +# --- +# General dependencies +sudo apt-get install -qq automake libtool flex bison pkg-config g++ libssl-dev make libqt4-dev git debhelper + +# C++ dependencies +sudo apt-get install -qq libboost-dev libboost-test-dev libboost-program-options-dev libboost-filesystem-dev libboost-system-dev libevent-dev + +# Java dependencies +sudo apt-get install -qq ant openjdk-7-jdk maven + +# Python dependencies +sudo apt-get install -qq python-all python-all-dev python-all-dbg python-setuptools python-support + +# Ruby dependencies +sudo apt-get install -qq ruby ruby-dev +sudo gem install bundler rake + +# Perl dependencies +sudo apt-get install -qq libbit-vector-perl libclass-accessor-class-perl + +# Php dependencies +sudo apt-get install -qq php5 php5-dev php5-cli php-pear re2c + +# GlibC dependencies +sudo apt-get install -qq libglib2.0-dev + +# Erlang dependencies +sudo apt-get install -qq erlang-base erlang-eunit erlang-dev + +# GO dependencies +echo "golang-go golang-go/dashboard boolean false" | debconf-set-selections +sudo apt-get -y install -qq golang golang-go + +# Haskell dependencies +sudo apt-get install -qq ghc cabal-install libghc-binary-dev libghc-network-dev libghc-http-dev libghc-hashable-dev libghc-unordered-containers-dev libghc-vector-dev +sudo cabal update + +# Lua dependencies +sudo apt-get install -qq lua5.2 lua5.2-dev + +# Node.js dependencies +sudo apt-get install -qq nodejs nodejs-dev nodejs-legacy npm + +# CSharp +sudo apt-get install -qq mono-gmcs mono-devel mono-xbuild mono-complete libmono-system-web2.0-cil +sudo apt-get install -qq mingw32 mingw32-binutils mingw32-runtime nsis + +# D dependencies +sudo wget http://master.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list +sudo apt-get update && sudo apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring && sudo apt-get update +sudo apt-get install -qq xdg-utils dmd-bin + +# Customize the system +# --- +# Default java to latest 1.7 version +update-java-alternatives -s java-1.7.0-openjdk-amd64 + +# PHPUnit package broken in ubuntu. see https://bugs.launchpad.net/ubuntu/+source/phpunit/+bug/701544 +sudo apt-get upgrade pear +sudo pear channel-discover pear.phpunit.de +sudo pear channel-discover pear.symfony.com +sudo pear channel-discover components.ez.no +sudo pear update-channels +sudo pear upgrade-all +sudo pear install --alldeps phpunit/PHPUnit + +date > /etc/vagrant.provisioned + +# Start the source build +# --- +echo "Starting Apache Thrift build..." +cd /thrift +sh bootstrap.sh +sh configure +make +make check +echo "Finished building Apache Thrift." + +SCRIPT + +Vagrant.configure("2") do |config| + # Ubuntu 14.04 LTS (Trusty Tahr) + config.vm.box = "trusty64" + config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" + + config.vm.synced_folder "../", "/thrift" + + config.vm.provider :virtualbox do |vbox| + vbox.customize ["modifyvm", :id, "--memory", "1024"] + vbox.customize ["modifyvm", :id, "--cpus", "2"] + vbox.customize ["modifyvm", :id, "--rtcuseutc", "on"] + end + + # Run the build script to configure the system + config.vm.provision :shell, :inline => $build_and_test +end http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/async-test/aggr.thrift ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/async-test/aggr.thrift b/depends/thirdparty/thrift/contrib/async-test/aggr.thrift new file mode 100644 index 0000000..c016a65 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/async-test/aggr.thrift @@ -0,0 +1,8 @@ +exception Error { + 1: string desc; +} + +service Aggr { + void addValue(1: i32 value); + list<i32> getValues() throws (1: Error err); +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/async-test/test-leaf.py ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/async-test/test-leaf.py b/depends/thirdparty/thrift/contrib/async-test/test-leaf.py new file mode 100755 index 0000000..8b7c3e3 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/async-test/test-leaf.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +import sys +import time +from thrift.transport import TTransport +from thrift.transport import TSocket +from thrift.protocol import TBinaryProtocol +from thrift.server import THttpServer +from aggr import Aggr + +class AggrHandler(Aggr.Iface): + def __init__(self): + self.values = [] + + def addValue(self, value): + self.values.append(value) + + def getValues(self, ): + time.sleep(1) + return self.values + +processor = Aggr.Processor(AggrHandler()) +pfactory = TBinaryProtocol.TBinaryProtocolFactory() +THttpServer.THttpServer(processor, ('', int(sys.argv[1])), pfactory).serve() http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/async-test/test-server.cpp ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/async-test/test-server.cpp b/depends/thirdparty/thrift/contrib/async-test/test-server.cpp new file mode 100644 index 0000000..b304e1b --- /dev/null +++ b/depends/thirdparty/thrift/contrib/async-test/test-server.cpp @@ -0,0 +1,97 @@ +#include <tr1/functional> +#include <thrift/protocol/TBinaryProtocol.h> +#include <thrift/async/TAsyncProtocolProcessor.h> +#include <thrift/async/TEvhttpServer.h> +#include <thrift/async/TEvhttpClientChannel.h> +#include "Aggr.h" + +using std::tr1::bind; +using std::tr1::placeholders::_1; + +using apache::thrift::TException; +using apache::thrift::protocol::TBinaryProtocolFactory; +using apache::thrift::protocol::TProtocolFactory; +using apache::thrift::async::TEvhttpServer; +using apache::thrift::async::TAsyncProcessor; +using apache::thrift::async::TAsyncBufferProcessor; +using apache::thrift::async::TAsyncProtocolProcessor; +using apache::thrift::async::TAsyncChannel; +using apache::thrift::async::TEvhttpClientChannel; + +class AggrAsyncHandler : public AggrCobSvIf { + protected: + struct RequestContext { + std::tr1::function<void(std::vector<int32_t> const& _return)> cob; + std::vector<int32_t> ret; + int pending_calls; + }; + + public: + AggrAsyncHandler() + : eb_(NULL) + , pfact_(new TBinaryProtocolFactory()) + { + leaf_ports_.push_back(8081); + leaf_ports_.push_back(8082); + } + + void addValue(std::tr1::function<void()> cob, const int32_t value) { + // Silently drop writes to the aggrgator. + return cob(); + } + + void getValues(std::tr1::function<void( + std::vector<int32_t> const& _return)> cob, + std::tr1::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob) { + RequestContext* ctx = new RequestContext(); + ctx->cob = cob; + ctx->pending_calls = leaf_ports_.size(); + for (std::vector<int>::iterator it = leaf_ports_.begin(); + it != leaf_ports_.end(); ++it) { + boost::shared_ptr<TAsyncChannel> channel( + new TEvhttpClientChannel( + "localhost", "/", "127.0.0.1", *it, eb_)); + AggrCobClient* client = new AggrCobClient(channel, pfact_.get()); + client->getValues(std::tr1::bind(&AggrAsyncHandler::clientReturn, this, ctx, _1)); + } + } + + void setEventBase(struct event_base* eb) { + eb_ = eb; + } + + void clientReturn(RequestContext* ctx, AggrCobClient* client) { + ctx->pending_calls -= 1; + + try { + std::vector<int32_t> subret; + client->recv_getValues(subret); + ctx->ret.insert(ctx->ret.end(), subret.begin(), subret.end()); + } catch (TException& exn) { + // TODO: Log error + } + + delete client; + + if (ctx->pending_calls == 0) { + ctx->cob(ctx->ret); + delete ctx; + } + } + + protected: + struct event_base* eb_; + std::vector<int> leaf_ports_; + boost::shared_ptr<TProtocolFactory> pfact_; +}; + + +int main() { + boost::shared_ptr<AggrAsyncHandler> handler(new AggrAsyncHandler()); + boost::shared_ptr<TAsyncProcessor> proc(new AggrAsyncProcessor(handler)); + boost::shared_ptr<TProtocolFactory> pfact(new TBinaryProtocolFactory()); + boost::shared_ptr<TAsyncBufferProcessor> bufproc(new TAsyncProtocolProcessor(proc, pfact)); + boost::shared_ptr<TEvhttpServer> server(new TEvhttpServer(bufproc, 8080)); + handler->setEventBase(server->getEventBase()); + server->serve(); +} http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/LICENSE ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/LICENSE b/depends/thirdparty/thrift/contrib/fb303/LICENSE new file mode 100644 index 0000000..4eacb64 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/LICENSE @@ -0,0 +1,16 @@ +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/Makefile.am ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/Makefile.am b/depends/thirdparty/thrift/contrib/fb303/Makefile.am new file mode 100644 index 0000000..e773e52 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/Makefile.am @@ -0,0 +1,46 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +@GLOBAL_HEADER_MK@ + +@PRODUCT_MK@ + +SUBDIRS = . + +if WITH_CPP +SUBDIRS += cpp +endif + +if WITH_JAVA +SUBDIRS += java +endif + +if WITH_PHP +SUBDIRS += php +endif + +if WITH_PYTHON +SUBDIRS += py +endif + +BUILT_SOURCES = + +clean-local: clean-common + +@GLOBAL_FOOTER_MK@ http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/README.md ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/README.md b/depends/thirdparty/thrift/contrib/fb303/README.md new file mode 100644 index 0000000..8ade560 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/README.md @@ -0,0 +1,37 @@ +Project FB303: The Facebook Bassline +------------------------------------ + +* Curious about the 303? * +http://en.wikipedia.org/wiki/Roland_TB-303 + +* Why the name? * +The TB303 makes bass lines. +.Bass is what lies underneath any strong tune. +..fb303 is the shared root of all thrift services. +...fb303 => FacebookBase303. + +* How do I use this? * +Take a look at the examples to see how your backend project can +and should inherit from this service. + +* What does it provide? * +A standard interface to monitoring, dynamic options and configuration, +uptime reports, activity, etc. + +* I want more. * +Think carefully first about whether the functionality you are going to add +belongs here or in your application. If it can be abstracted and is generally +useful, then it probably belongs somewhere in the fb303 tree. Keep in mind, +not every product has to use ALL the functionality of fb303, but every product +CANNOT use functionality that is NOT in fb303. + +* Is this open source? * +Yes. fb303 is distributed under the Thrift Software License. See the +LICENSE file for more details. + +* Installation * +fb303 is configured/built/installed similar to Thrift. See the README +in the Thrift root directory for more information. + +* Who wrote this README? * [email protected] http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/TClientInfo.cpp ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/TClientInfo.cpp b/depends/thirdparty/thrift/contrib/fb303/TClientInfo.cpp new file mode 100644 index 0000000..1fc6612 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/TClientInfo.cpp @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +#include <thrift/server/TClientInfo.h> + +namespace apache { namespace thrift { namespace server { + +using namespace apache::thrift; +using namespace apache::thrift::transport; + +TClientInfoConnection::TClientInfoConnection() { + call_[kNameLen - 1] = '\0'; // insure NUL terminator is there + eraseAddr(); + eraseCall(); +} + +void TClientInfoConnection::recordAddr(const sockaddr* addr) { + eraseAddr(); + initTime(); + ncalls_ = 0; + if (addr != NULL) { + if (addr->sa_family == AF_INET) { + memcpy((void*)&addr_.ipv4, (const void *)addr, sizeof(sockaddr_in)); + } + else if (addr->sa_family == AF_INET6) { + memcpy((void*)&addr_.ipv6, (const void *)addr, sizeof(sockaddr_in6)); + } + } +} + +void TClientInfoConnection::eraseAddr() { + addr_.ipv4.sin_family = AF_UNSPEC; +} + +const char* TClientInfoConnection::getAddr(char* buf, int len) const { + switch (addr_.ipv4.sin_family) { + case AF_INET: + return inet_ntop(AF_INET, &addr_.ipv4.sin_addr, buf, len); + case AF_INET6: + return inet_ntop(AF_INET6, &addr_.ipv6.sin6_addr, buf, len); + default: + return NULL; + } +} + +void TClientInfoConnection::recordCall(const char* name) { + strncpy(call_, name, kNameLen - 1); // NUL terminator set in constructor + ncalls_++; +} + +void TClientInfoConnection::eraseCall() { + call_[0] = '\0'; +} + +const char* TClientInfoConnection::getCall() const { + if (call_[0] == '\0') { + return NULL; + } + return call_; +} + +void TClientInfoConnection::getTime(timespec* time) const { + *time = time_; +} + +uint64_t TClientInfoConnection::getNCalls() const { + return ncalls_; +} + +void TClientInfoConnection::initTime() { + clock_gettime(CLOCK_REALTIME, &time_); +} + + +TClientInfoConnection* TClientInfo::getConnection(int fd, bool grow) { + if (fd < 0 || (!grow && fd >= info_.size())) { + return NULL; + } + return &info_[fd]; +} + +size_t TClientInfo::size() const { + return info_.size(); +} + +void* TClientInfoServerHandler::createContext(boost::shared_ptr<TProtocol> input, + boost::shared_ptr<TProtocol> output) { + (void)input; + (void)output; + return (void*) new Connect(&clientInfo_); +} + +void TClientInfoServerHandler::deleteContext(void* connectionContext, + boost::shared_ptr<TProtocol> input, + boost::shared_ptr<TProtocol> output) { + Connect* call = static_cast<Connect*>(connectionContext); + if (call->callInfo_) { + call->callInfo_->eraseCall(); + } + delete call; +} + +void TClientInfoServerHandler::processContext(void* connectionContext, + shared_ptr<TTransport> transport) { + Connect* call = static_cast<Connect*>(connectionContext); + if (call->callInfo_ == NULL) { + if (typeid(*(transport.get())) == typeid(TSocket)) { + TSocket* tsocket = static_cast<TSocket*>(transport.get()); + int fd = tsocket->getSocketFD(); + if (fd < 0) { + return; + } + call->callInfo_ = call->clientInfo_->getConnection(fd, true); + assert(call->callInfo_ != NULL); + socklen_t len; + call->callInfo_->recordAddr(tsocket->getCachedAddress(&len)); + } + } +} + +void TClientInfoServerHandler::getStatsStrings(vector<string>& result) { + result.clear(); + timespec now; + clock_gettime(CLOCK_REALTIME, &now); + + for (int i = 0; i < clientInfo_.size(); ++i) { + TClientInfoConnection* info = clientInfo_.getConnection(i, false); + const char* callStr = info->getCall(); + if (callStr == NULL) { + continue; + } + + char addrBuf[INET6_ADDRSTRLEN]; + const char* addrStr = info->getAddr(addrBuf, sizeof addrBuf); + if (addrStr == NULL) { + // cerr << "no addr!" << endl; + continue; + } + + timespec start; + info->getTime(&start); + double secs = (double)(now.tv_sec - start.tv_sec) + (now.tv_nsec - start.tv_nsec)*0.000000001; + + char buf[256]; + snprintf(buf, sizeof buf, "%d %s %s %.3f %llu", i, addrStr, callStr, secs, + (uint64_t)info->getNCalls()); + + result.push_back(buf); + } +} + +void* TClientInfoCallHandler::getContext(const char* fn_name, void* serverContext) { + if (serverContext) { + TClientInfoConnection* callInfo = static_cast<TClientInfoServerHandler::Connect*>(serverContext)->callInfo_; + if (callInfo != NULL) { + callInfo->recordCall(fn_name); + } + } + return NULL; +} + +} } } // namespace apache::thrift::server http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/TClientInfo.h ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/TClientInfo.h b/depends/thirdparty/thrift/contrib/fb303/TClientInfo.h new file mode 100644 index 0000000..6668c19 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/TClientInfo.h @@ -0,0 +1,320 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 _FACEBOOK_THRIFT_SERVER_TCLIENTINFO_H_ +#define _FACEBOOK_THRIFT_SERVER_TCLIENTINFO_H_ 1 + +// for inet_ntop -- +#include <arpa/inet.h> +#include <thrift/server/TServer.h> +#include <thrift/transport/TSocket.h> +#include <thrift/concurrency/Mutex.h> + +namespace apache { namespace thrift { namespace server { + +using namespace apache::thrift; +using namespace apache::thrift::transport; +using namespace apache::thrift::concurrency; +using boost::shared_ptr; +using std::string; +using std::vector; + +/** + * StableVector -- a minimal vector class where growth is automatic and + * vector elements never move as the vector grows. Allocates new space + * as needed, but does not copy old values. + * + * A level vector stores a list of storage vectors containing the actual + * elements. Levels are added as needed, doubling in size each time. + * Locking is only done when a level is added. Access is amortized + * constant time. + */ +template <typename T> +class StableVector { + /// The initial allocation as an exponent of 2 + static const uint32_t kInitialSizePowOf2 = 10; + /// The initial allocation size + static const uint32_t kInitialVectorSize = 1 << kInitialSizePowOf2; + /// This bound is guaranteed not to be exceeded on 64-bit archs + static const int kMaxLevels = 64; + + /// Values are kept in one or more of these + typedef vector<T> Vect; + /// One or more value vectors are kept in one of these + typedef vector<Vect*> LevelVector; + + Mutex mutex_; + /// current size + size_t size_; + _Atomic_word vectLvl_; + LevelVector vects_; + + public: + /** + * Constructor -- initialize the level vector and allocate the + * initial storage vector + */ + StableVector() + : size_(0) + , vectLvl_(0) { + vects_.reserve(kMaxLevels); + Vect* storageVector(new Vect(1 << kInitialSizePowOf2)); + vects_.push_back(storageVector); + } + + private: + /** + * make sure the requested number of storage levels have been allocated. + */ + void expand(uint32_t level) { + // we need the guard to insure that we only allocate once. + Guard g(mutex_); + while (level > vectLvl_) { + Vect* levelVect(new Vect(1 << (vectLvl_ + kInitialSizePowOf2))); + vects_.push_back(levelVect); + // we need to make sure this is done after levelVect is inserted + // (what we want is effectively a memory barrier here). + __gnu_cxx::__atomic_add(&vectLvl_, 1); + } + } + + /** + * Given an index, determine which level and element of that level is + * required. Grows if needed. + */ + void which(uint32_t n, uint32_t* vno, uint32_t* idx) { + if (n >= size_) { + size_ = n + 1; + } + if (n < kInitialVectorSize) { + *idx = n; + *vno = 0; + } else { + uint32_t upper = n >> kInitialSizePowOf2; + *vno = CHAR_BIT*sizeof(upper) - __builtin_clz(upper); + *idx = n - (1 << (*vno + kInitialSizePowOf2 - 1)); + if (*vno > vectLvl_) { + expand(*vno); + } + } + } + + public: + /** + * Given an index, return a reference to that element, perhaps after + * allocating additional space. + * + * @param n a positive integer + */ + T& operator[](uint32_t n) { + uint32_t vno; + uint32_t idx; + which(n, &vno, &idx); + return (*vects_[vno])[idx]; + } + + /** + * Return the present size of the vector. + */ + size_t size() const { return size_; } +}; + + +/** + * This class embodies the representation of a single connection during + * processing. We'll keep one of these per file descriptor in TClientInfo. + */ +class TClientInfoConnection { + public: + const static int kNameLen = 32; + + private: + typedef union IPAddrUnion { + sockaddr_in ipv4; + sockaddr_in6 ipv6; + }; + + char call_[kNameLen]; ///< The name of the thrift call + IPAddrUnion addr_; ///< The client's IP address + timespec time_; ///< Time processing started + uint64_t ncalls_; ///< # of calls processed + + public: + /** + * Constructor; insure that no client address or thrift call name is + * represented. + */ + TClientInfoConnection(); + + /** + * A connection has been made; record its address. Since this is the + * first we'll know of a connection we start the timer here as well. + */ + void recordAddr(const sockaddr* addr); + + /** + * Mark the address as empty/unknown. + */ + void eraseAddr(); + + /** + * Return a string representing the present address, or NULL if none. + * Copies the string into the buffer provided. + */ + const char* getAddr(char* buf, int len) const; + + /** + * A call has been made on this connection; record its name. Since this is + * called for every thrift call processed, we also do our call count here. + */ + void recordCall(const char* name); + + /** + * Invoked when processing has ended to clear the call name. + */ + void eraseCall(); + + /** + * Return as string the thrift call either currently being processed or + * most recently processed if the connection is still open for additional + * calls. Returns NULL if a call hasn't been made yet or processing + * has ended. + */ + const char* getCall() const; + + /** + * Get the timespec for the start of this connection (specifically, when + * recordAddr() was first called). + */ + void getTime(timespec* time) const; + + /** + * Return the number of calls made on this connection. + */ + uint64_t getNCalls() const; + + private: + void initTime(); +}; + + +/** + * Store for info about a server's clients -- specifically, the client's IP + * address and the call it is executing. This information is indexed by + * socket file descriptor and in the present implementation is updated + * asynchronously, so it may only approximate reality. + */ +class TClientInfo { + private: + StableVector<TClientInfoConnection> info_; + + public: + /** + * Return the info object for a given file descriptor. If "grow" is true + * extend the info vector if required (such as for a file descriptor not seen + * before). If "grow" is false and the info vector isn't large enough, + * or if "fd" is negative, return NULL. + */ + TClientInfoConnection* getConnection(int fd, bool grow); + + size_t size() const; +}; + +/** + * This derivation of TServerEventHandler encapsulates the main status vector + * and provides context to the server's processing loop via overrides. + * Together with TClientInfoCallHandler (derived from TProcessorEventHandler) + * it integrates client info collection into the server. + */ +class TClientInfoServerHandler : public TServerEventHandler { + private: + TClientInfo clientInfo_; + + public: + /** + * One of these is constructed for each open connection/descriptor and links + * to both the status vector (clientInfo_) and that descriptor's entry + * within it. + */ + struct Connect { + TClientInfo* clientInfo_; + TClientInfoConnection* callInfo_; + + explicit Connect(TClientInfo* clientInfo) + : clientInfo_(clientInfo) + , callInfo_(NULL) { + } + }; + + /** + * Generate processor context; we don't know what descriptor we belong to + * yet -- we'll get hooked up in contextProcess(). + */ + void* createContext(boost::shared_ptr<TProtocol> input, + boost::shared_ptr<TProtocol> output); + + /** + * Mark our slot as unused and delete the context created in createContext(). + */ + void deleteContext(void* processorContext, + boost::shared_ptr<TProtocol> input, + boost::shared_ptr<TProtocol> output); + + /** + * Called in the processing loop just before the server invokes the + * processor itself, on the first call we establish which descriptor + * we correspond to and set it to that socket's peer IP address. This + * also has the side effect of initializing call counting and connection + * timing. We won't know which call we're handling until the handler + * first gets called in TClientInfoCallHandler::getContext(). + */ + void processContext(void* processorContext, + shared_ptr<TTransport> transport); + + /** + * Get status report for server in the form of a vector of strings. + * Each active client appears as one string in the format: + * + * FD IPADDR CALLNAME DURATION NCALLS + * + * where "FD" is the file descriptor for the client's socket, "IPADDR" + * is the IP address (as reported by accept()), "CALLNAME" is the + * current or most recent Thrift function name, "DURATION" is the + * duration of the connection, while NCALLS is the number of Thrift + * calls made since the connection was made. A single space separates + * fields. + */ + void getStatsStrings(vector<string>& result); +}; + +/** + * This class derives from TProcessorEventHandler to gain access to the + * function name for the current Thrift call. We need two versions of + * this -- TClientInfoCallStatsHandler is the other -- since in the latter + * case we pass through to TFunctionStatHandler to perform Thrift call + * stats. + */ +class TClientInfoCallHandler : public TProcessorEventHandler { + public: + virtual void* getContext(const char* fn_name, void* serverContext); +}; + +} } } // namespace apache::thrift::server + +#endif // !_FACEBOOK_THRIFT_SERVER_TCLIENTINFO_H_ http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_boost_base.m4 ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_boost_base.m4 b/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_boost_base.m4 new file mode 100644 index 0000000..e56bb73 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_boost_base.m4 @@ -0,0 +1,198 @@ +##### http://autoconf-archive.cryp.to/ax_boost_base.html +# +# SYNOPSIS +# +# AX_BOOST_BASE([MINIMUM-VERSION]) +# +# DESCRIPTION +# +# Test for the Boost C++ libraries of a particular version (or newer) +# +# If no path to the installed boost library is given the macro +# searchs under /usr, /usr/local, /opt and /opt/local and evaluates +# the $BOOST_ROOT environment variable. Further documentation is +# available at <http://randspringer.de/boost/index.html>. +# +# This macro calls: +# +# AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS) +# +# And sets: +# +# HAVE_BOOST +# +# LAST MODIFICATION +# +# 2007-07-28 +# +# COPYLEFT +# +# Copyright (c) 2007 Thomas Porschberg <[email protected]> +# +# Copying and distribution of this file, with or without +# modification, are permitted in any medium without royalty provided +# the copyright notice and this notice are preserved. + +AC_DEFUN([AX_BOOST_BASE], +[ +AC_ARG_WITH([boost], + AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost (default is yes) - it is possible to specify the root directory for boost (optional)]), + [ + if test "$withval" = "no"; then + want_boost="no" + elif test "$withval" = "yes"; then + want_boost="yes" + ac_boost_path="" + else + want_boost="yes" + ac_boost_path="$withval" + fi + ], + [want_boost="yes"]) + +if test "x$want_boost" = "xyes"; then + boost_lib_version_req=ifelse([$1], ,1.20.0,$1) + boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'` + boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'` + boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'` + boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` + if test "x$boost_lib_version_req_sub_minor" = "x" ; then + boost_lib_version_req_sub_minor="0" + fi + WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor` + AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req) + succeeded=no + + dnl first we check the system location for boost libraries + dnl this location ist chosen if boost libraries are installed with the --layout=system option + dnl or if you install boost with RPM + if test "$ac_boost_path" != ""; then + BOOST_LDFLAGS="-L$ac_boost_path/lib" + BOOST_CPPFLAGS="-I$ac_boost_path/include" + else + for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do + if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then + BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib" + BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include" + break; + fi + done + fi + + CPPFLAGS_SAVED="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + + LDFLAGS_SAVED="$LDFLAGS" + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_LANG_PUSH(C++) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + @%:@include <boost/version.hpp> + ]], [[ + #if BOOST_VERSION >= $WANT_BOOST_VERSION + // Everything is okay + #else + # error Boost version is too old + #endif + ]])],[ + AC_MSG_RESULT(yes) + succeeded=yes + found_system=yes + ],[ + ]) + AC_LANG_POP([C++]) + + + + dnl if we found no boost with system layout we search for boost libraries + dnl built and installed without the --layout=system option or for a staged(not installed) version + if test "x$succeeded" != "xyes"; then + _version=0 + if test "$ac_boost_path" != ""; then + BOOST_LDFLAGS="-L$ac_boost_path/lib" + if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then + for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do + _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` + V_CHECK=`expr $_version_tmp \> $_version` + if test "$V_CHECK" = "1" ; then + _version=$_version_tmp + fi + VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` + BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE" + done + fi + else + for ac_boost_path in /usr /usr/local /opt /opt/local ; do + if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then + for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do + _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` + V_CHECK=`expr $_version_tmp \> $_version` + if test "$V_CHECK" = "1" ; then + _version=$_version_tmp + best_path=$ac_boost_path + fi + done + fi + done + + VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` + BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE" + BOOST_LDFLAGS="-L$best_path/lib" + + if test "x$BOOST_ROOT" != "x"; then + if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then + version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'` + stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'` + stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'` + V_CHECK=`expr $stage_version_shorten \>\= $_version` + if test "$V_CHECK" = "1" ; then + AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT) + BOOST_CPPFLAGS="-I$BOOST_ROOT" + BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib" + fi + fi + fi + fi + + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_LANG_PUSH(C++) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + @%:@include <boost/version.hpp> + ]], [[ + #if BOOST_VERSION >= $WANT_BOOST_VERSION + // Everything is okay + #else + # error Boost version is too old + #endif + ]])],[ + AC_MSG_RESULT(yes) + succeeded=yes + found_system=yes + ],[ + ]) + AC_LANG_POP([C++]) + fi + + if test "$succeeded" != "yes" ; then + if test "$_version" = "0" ; then + AC_MSG_ERROR([[We could not detect the boost libraries (version $boost_lib_version_req_shorten or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost for more documentation.]]) + else + AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).]) + fi + else + AC_SUBST(BOOST_CPPFLAGS) + AC_SUBST(BOOST_LDFLAGS) + AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available]) + fi + + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" +fi + +]) http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_cxx_compile_stdcxx_11.m4 ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_cxx_compile_stdcxx_11.m4 b/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_cxx_compile_stdcxx_11.m4 new file mode 100644 index 0000000..a4c9189 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_cxx_compile_stdcxx_11.m4 @@ -0,0 +1,134 @@ +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++11 +# standard; if necessary, add switches to CXXFLAGS to enable support. +# +# The first argument, if specified, indicates whether you insist on an +# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. +# -std=c++11). If neither is specified, you get whatever works, with +# preference for an extended mode. +# +# The second argument, if specified 'mandatory' or if left unspecified, +# indicates that baseline C++11 support is required and that the macro +# should error out if no mode with that support is found. If specified +# 'optional', then configuration proceeds regardless, after defining +# HAVE_CXX11 if and only if a supporting mode is found. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik <[email protected]> +# Copyright (c) 2012 Zack Weinberg <[email protected]> +# Copyright (c) 2013 Roy Stogner <[email protected]> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 3 + +m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [ + template <typename T> + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check<check<bool>> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check<int> check_type; + check_type c; + check_type&& cr = static_cast<check_type&&>(c); + + auto d = a; +]) + +AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl + m4_if([$1], [], [], + [$1], [ext], [], + [$1], [noext], [], + [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl + m4_if([$2], [], [ax_cxx_compile_cxx11_required=true], + [$2], [mandatory], [ax_cxx_compile_cxx11_required=true], + [$2], [optional], [ax_cxx_compile_cxx11_required=false], + [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])dnl + AC_LANG_PUSH([C++])dnl + ac_success=no + AC_CACHE_CHECK(whether $CXX supports C++11 features by default, + ax_cv_cxx_compile_cxx11, + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [ax_cv_cxx_compile_cxx11=yes], + [ax_cv_cxx_compile_cxx11=no])]) + if test x$ax_cv_cxx_compile_cxx11 = xyes; then + ac_success=yes + fi + + m4_if([$1], [noext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=gnu++11; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + ac_success=yes + break + fi + done + fi]) + + m4_if([$1], [ext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=c++11; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, + $cachevar, + [ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXXFLAGS="$ac_save_CXXFLAGS"]) + if eval test x\$$cachevar = xyes; then + CXXFLAGS="$CXXFLAGS $switch" + ac_success=yes + break + fi + done + fi]) + AC_LANG_POP([C++]) + if test x$ax_cxx_compile_cxx11_required = xtrue; then + if test x$ac_success = xno; then + AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) + fi + else + if test x$ac_success = xno; then + HAVE_CXX11=0 + AC_MSG_NOTICE([No compiler with C++11 support was found]) + else + HAVE_CXX11=1 + AC_DEFINE(HAVE_CXX11,1, + [define if the compiler supports basic C++11 syntax]) + fi + + AC_SUBST(HAVE_CXX11) + fi +]) + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_javac_and_java.m4 ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_javac_and_java.m4 b/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_javac_and_java.m4 new file mode 100644 index 0000000..581b450 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_javac_and_java.m4 @@ -0,0 +1,121 @@ +dnl @synopsis AX_JAVAC_AND_JAVA +dnl @synopsis AX_CHECK_JAVA_CLASS(CLASSNAME) +dnl +dnl Test for the presence of a JDK, and (optionally) specific classes. +dnl +dnl If "JAVA" is defined in the environment, that will be the only +dnl java command tested. Otherwise, a hard-coded list will be used. +dnl Similarly for "JAVAC". +dnl +dnl AX_JAVAC_AND_JAVA does not currently support testing for a particular +dnl Java version, testing for only one of "java" and "javac", or +dnl compiling or running user-provided Java code. +dnl +dnl After AX_JAVAC_AND_JAVA runs, the shell variables "success" and +dnl "ax_javac_and_java" are set to "yes" or "no", and "JAVAC" and +dnl "JAVA" are set to the appropriate commands. +dnl +dnl AX_CHECK_JAVA_CLASS must be run after AX_JAVAC_AND_JAVA. +dnl It tests for the presence of a class based on a fully-qualified name. +dnl It sets the shell variable "success" to "yes" or "no". +dnl +dnl @category Java +dnl @version 2009-02-09 +dnl @license AllPermissive +dnl +dnl Copyright (C) 2009 David Reiss +dnl Copying and distribution of this file, with or without modification, +dnl are permitted in any medium without royalty provided the copyright +dnl notice and this notice are preserved. + + +AC_DEFUN([AX_JAVAC_AND_JAVA], + [ + + dnl Hard-coded default commands to test. + JAVAC_PROGS="javac,jikes,gcj -C" + JAVA_PROGS="java,kaffe" + + dnl Allow the user to specify an alternative. + if test -n "$JAVAC" ; then + JAVAC_PROGS="$JAVAC" + fi + if test -n "$JAVA" ; then + JAVA_PROGS="$JAVA" + fi + + AC_MSG_CHECKING(for javac and java) + + echo "public class configtest_ax_javac_and_java { public static void main(String args@<:@@:>@) { } }" > configtest_ax_javac_and_java.java + success=no + oIFS="$IFS" + + IFS="," + for JAVAC in $JAVAC_PROGS ; do + IFS="$oIFS" + + echo "Running \"$JAVAC configtest_ax_javac_and_java.java\"" >&AS_MESSAGE_LOG_FD + if $JAVAC configtest_ax_javac_and_java.java >&AS_MESSAGE_LOG_FD 2>&1 ; then + + IFS="," + for JAVA in $JAVA_PROGS ; do + IFS="$oIFS" + + echo "Running \"$JAVA configtest_ax_javac_and_java\"" >&AS_MESSAGE_LOG_FD + if $JAVA configtest_ax_javac_and_java >&AS_MESSAGE_LOG_FD 2>&1 ; then + success=yes + break 2 + fi + + done + + fi + + done + + rm -f configtest_ax_javac_and_java.java configtest_ax_javac_and_java.class + + if test "$success" != "yes" ; then + AC_MSG_RESULT(no) + JAVAC="" + JAVA="" + else + AC_MSG_RESULT(yes) + fi + + ax_javac_and_java="$success" + + ]) + + +AC_DEFUN([AX_CHECK_JAVA_CLASS], + [ + AC_MSG_CHECKING(for Java class [$1]) + + echo "import $1; public class configtest_ax_javac_and_java { public static void main(String args@<:@@:>@) { } }" > configtest_ax_javac_and_java.java + + echo "Running \"$JAVAC configtest_ax_javac_and_java.java\"" >&AS_MESSAGE_LOG_FD + if $JAVAC configtest_ax_javac_and_java.java >&AS_MESSAGE_LOG_FD 2>&1 ; then + AC_MSG_RESULT(yes) + success=yes + else + AC_MSG_RESULT(no) + success=no + fi + + rm -f configtest_ax_javac_and_java.java configtest_ax_javac_and_java.class + ]) + + +AC_DEFUN([AX_CHECK_ANT_VERSION], + [ + AC_MSG_CHECKING(for ant version > $2) + ANT_VALID=`expr $($1 -version 2>/dev/null | sed -n 's/.*version \(@<:@0-9\.@:>@*\).*/\1/p') \>= $2` + if test "x$ANT_VALID" = "x1" ; then + AC_MSG_RESULT(yes) + else + AC_MSG_RESULT(no) + ANT="" + fi + ]) + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_thrift_internal.m4 ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_thrift_internal.m4 b/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_thrift_internal.m4 new file mode 100644 index 0000000..8c0e3cb --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/aclocal/ax_thrift_internal.m4 @@ -0,0 +1,28 @@ +dnl @synopsis AX_THRIFT_GEN(SHORT_LANGUAGE, LONG_LANGUAGE, DEFAULT) +dnl @synopsis AX_THRIFT_LIB(SHORT_LANGUAGE, LONG_LANGUAGE, DEFAULT) +dnl +dnl Allow a particular language generator to be disabled. +dnl Allow a particular language library to be disabled. +dnl +dnl These macros have poor error handling and are poorly documented. +dnl They are intended only for internal use by the Thrift compiler. +dnl +dnl @version 2008-02-20 +dnl @license AllPermissive +dnl +dnl Copyright (C) 2009 David Reiss +dnl Copying and distribution of this file, with or without modification, +dnl are permitted in any medium without royalty provided the copyright +dnl notice and this notice are preserved. + +AC_DEFUN([AX_THRIFT_LIB], + [ + AC_ARG_WITH($1, + AC_HELP_STRING([--with-$1], [build the $2 library @<:@default=$3@:>@]), + [with_$1="$withval"], + [with_$1=$3] + ) + have_$1=no + dnl What we do here is going to vary from library to library, + dnl so we can't really generalize (yet!). + ]) http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/bootstrap.sh ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/bootstrap.sh b/depends/thirdparty/thrift/contrib/fb303/bootstrap.sh new file mode 100755 index 0000000..3cbeddb --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/bootstrap.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +# To be safe include -I flag +aclocal -I ./aclocal +automake -a +autoconf +./configure --config-cache $* http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/configure.ac ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/configure.ac b/depends/thirdparty/thrift/contrib/fb303/configure.ac new file mode 100644 index 0000000..73b35ba --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/configure.ac @@ -0,0 +1,164 @@ +# Autoconf input file +# $Id$ + +# AC - autoconf +# FB - facebook + +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +######################################################################### +# DO NOT TOUCH EXCEPT TO CHANGE REV# IN AC_INIT + +AC_PREREQ(2.52) +AC_INIT([libfb303],[20080209]) +#AC_CONFIG_AUX_DIR([/usr/share/automake-1.9]) +# To install locally +FB_INITIALIZE([localinstall]) +AC_PREFIX_DEFAULT([/usr/local]) + +############################################################################ +# User Configurable. Change With CAUTION! +# User can include custom makefile rules. Uncomment and update only <name> in PRODUCT_MK. +# Include where appropriate in any Makefile.am as @PRODUCT_MK@ + +#PRODUCT_MK="include ${EXTERNAL_PATH}/shared/build/<name>.mk" + +# Default path to external Facebook components and shared build toools I.e fb303 etc. +# To point to other locations set environment variable EXTERNAL_PATH. +# To change the current default you must change bootstrap.sh. +FB_WITH_EXTERNAL_PATH([`pwd`]) + +AC_ARG_VAR([PY_PREFIX], [Prefix for installing Python modules. + (Normal --prefix is ignored for Python because + Python has different conventions.) + Default = "/usr"]) +AS_IF([test "x$PY_PREFIX" = x], [PY_PREFIX="/usr"]) + +########################################################################## +# User Configurable + +# Pre-defined macro to set opt build mode. Run with --disable-shared option to turn off optimization. +FB_ENABLE_DEFAULT_OPT_BUILD + +# Predefined macro to set static library mode. Run with --disable-static option to turn off static lib mode. +FB_ENABLE_DEFAULT_STATIC + +# Personalized feature generator. Creates defines/conditionals and --enable --disable command line options. +# FB_ENABLE_FEATURE([FEATURE], [feature]) OR FB_ENABLE_FEATURE([FEATURE], [feature], [\"<value>\"]) + +# Example: Macro supplies -DFACEBOOK at compile time and "if FACEBOOK endif" capabilities. + +# Personalized path generator Sets default paths. Provides --with-xx=DIR options. +# FB_WITH_PATH([<var>_home], [<var>path], [<default location>] + +# Example: sets $(thrift_home) variable with default path set to /usr/local. +FB_WITH_PATH([thrift_home], [thriftpath], [/usr/local]) + +AX_CXX_COMPILE_STDCXX_11([noext]) +AX_THRIFT_LIB(cpp, [C++], yes) +have_cpp=no +if test "$with_cpp" = "yes"; then + # Require boost 1.40.0 or later + AX_BOOST_BASE([1.40.0]) + if test "x$succeeded" = "xyes"; then + have_cpp="yes" + fi +fi +AM_CONDITIONAL([WITH_CPP], [test "$have_cpp" = "yes"]) + +AX_THRIFT_LIB(java, [Java], yes) +if test "$with_java" = "yes"; then + AX_JAVAC_AND_JAVA + AC_PATH_PROG([ANT], [ant]) + AX_CHECK_ANT_VERSION($ANT, 1.7) + AC_SUBST(CLASSPATH) + AC_SUBST(ANT_FLAGS) + if test "x$JAVAC" != "x" && test "x$JAVAC" != "x" && test "x$ANT" != "x" ; then + have_java="yes" + fi +fi +AM_CONDITIONAL(WITH_JAVA, [test "$have_java" = "yes"]) + +AX_THRIFT_LIB(php, [PHP], yes) +if test "$with_php" = "yes"; then + AC_PATH_PROG([PHP], [php]) + if test "x$PHP" != "x" && test "x$PHP" != "x:" ; then + have_php="yes" + fi +fi +AM_CONDITIONAL(WITH_PHP, [test "$have_php" = "yes"]) + +AX_THRIFT_LIB(python, [Python], yes) +if test "$with_python" = "yes"; then + AM_PATH_PYTHON(2.4,, :) + if test "x$PYTHON" != "x" && test "x$PYTHON" != "x:" ; then + have_python="yes" + fi +fi +AM_CONDITIONAL(WITH_PYTHON, [test "$have_python" = "yes"]) + +# Generates Makefile from Makefile.am. Modify when new subdirs are added. +# Change Makefile.am also to add subdirectly. +AC_CONFIG_FILES(Makefile cpp/Makefile py/Makefile) + +# Check for headers +AC_CHECK_HEADERS([inttypes.h]) +AC_CHECK_HEADERS([netinet/in.h]) + +############################################################################ +# DO NOT TOUCH. + +AC_SUBST(PRODUCT_MK) +AC_OUTPUT + +############################################################################# +######### FINISH ############################################################ + +echo "EXTERNAL_PATH $EXTERNAL_PATH" +echo +echo "Building C++ Library ......... : $have_cpp" +echo "Building Java Library ........ : $have_java" +echo "Building Python Library ...... : $have_python" +echo "Building PHP Library ......... : $have_php" + + +# +# NOTES FOR USER +# Short cut to create conditional flags. +#enable_facebook="yes" +#AM_CONDITIONAL([FACEBOOK], [test "$enable_facebook" = yes]) +#enable_hdfs="yes" +#AM_CONDITIONAL([HDFS], [test "$enable_hdfs" = yes]) + +# Enable options with --enable and --disable configurable. +#AC_MSG_CHECKING([whether to enable FACEBOOK]) +#FACEBOOK="" +#AC_ARG_ENABLE([facebook], +# [ --enable-facebook Enable facebook.], +# [ +# ENABLE_FACEBOOK=$enableval +# ], +# [ +# ENABLE_FACEBOOK="no" +# ] +#) +#AM_CONDITIONAL([FACEBOOK], [test "$ENABLE_FACEBOOK" = yes]) +#AC_MSG_RESULT($ENABLE_FACEBOOK) + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/cpp/FacebookBase.cpp ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/cpp/FacebookBase.cpp b/depends/thirdparty/thrift/contrib/fb303/cpp/FacebookBase.cpp new file mode 100644 index 0000000..3c56975 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/cpp/FacebookBase.cpp @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +#include "FacebookBase.h" + +using namespace facebook::fb303; +using apache::thrift::concurrency::Guard; + +FacebookBase::FacebookBase(std::string name) : + name_(name) { + aliveSince_ = (int64_t) time(NULL); +} + +inline void FacebookBase::getName(std::string& _return) { + _return = name_; +} + +void FacebookBase::setOption(const std::string& key, const std::string& value) { + Guard g(optionsLock_); + options_[key] = value; +} + +void FacebookBase::getOption(std::string& _return, const std::string& key) { + Guard g(optionsLock_); + _return = options_[key]; +} + +void FacebookBase::getOptions(std::map<std::string, std::string> & _return) { + Guard g(optionsLock_); + _return = options_; +} + +int64_t FacebookBase::incrementCounter(const std::string& key, int64_t amount) { + counters_.acquireRead(); + + // if we didn't find the key, we need to write lock the whole map to create it + ReadWriteCounterMap::iterator it = counters_.find(key); + if (it == counters_.end()) { + counters_.release(); + counters_.acquireWrite(); + + // we need to check again to make sure someone didn't create this key + // already while we released the lock + it = counters_.find(key); + if(it == counters_.end()){ + counters_[key].value = amount; + counters_.release(); + return amount; + } + } + + it->second.acquireWrite(); + int64_t count = it->second.value + amount; + it->second.value = count; + it->second.release(); + counters_.release(); + return count; +} + +int64_t FacebookBase::setCounter(const std::string& key, int64_t value) { + counters_.acquireRead(); + + // if we didn't find the key, we need to write lock the whole map to create it + ReadWriteCounterMap::iterator it = counters_.find(key); + if (it == counters_.end()) { + counters_.release(); + counters_.acquireWrite(); + counters_[key].value = value; + counters_.release(); + return value; + } + + it->second.acquireWrite(); + it->second.value = value; + it->second.release(); + counters_.release(); + return value; +} + +void FacebookBase::getCounters(std::map<std::string, int64_t>& _return) { + // we need to lock the whole thing and actually build the map since we don't + // want our read/write structure to go over the wire + counters_.acquireRead(); + for(ReadWriteCounterMap::iterator it = counters_.begin(); + it != counters_.end(); ++it) + { + _return[it->first] = it->second.value; + } + counters_.release(); +} + +int64_t FacebookBase::getCounter(const std::string& key) { + int64_t rv = 0; + counters_.acquireRead(); + ReadWriteCounterMap::iterator it = counters_.find(key); + if (it != counters_.end()) { + it->second.acquireRead(); + rv = it->second.value; + it->second.release(); + } + counters_.release(); + return rv; +} + +inline int64_t FacebookBase::aliveSince() { + return aliveSince_; +} + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/cpp/FacebookBase.h ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/cpp/FacebookBase.h b/depends/thirdparty/thrift/contrib/fb303/cpp/FacebookBase.h new file mode 100644 index 0000000..2159c95 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/cpp/FacebookBase.h @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 _FACEBOOK_TB303_FACEBOOKBASE_H_ +#define _FACEBOOK_TB303_FACEBOOKBASE_H_ 1 + +#include "FacebookService.h" + +#include <thrift/server/TServer.h> +#include <thrift/concurrency/Mutex.h> + +#include <time.h> +#include <string> +#include <map> + +namespace facebook { namespace fb303 { + +using apache::thrift::concurrency::Mutex; +using apache::thrift::concurrency::ReadWriteMutex; +using apache::thrift::server::TServer; + +struct ReadWriteInt : ReadWriteMutex {int64_t value;}; +struct ReadWriteCounterMap : ReadWriteMutex, + std::map<std::string, ReadWriteInt> {}; + +/** + * Base Facebook service implementation in C++. + * + */ +class FacebookBase : virtual public FacebookServiceIf { + protected: + FacebookBase(std::string name); + virtual ~FacebookBase() {} + + public: + void getName(std::string& _return); + virtual void getVersion(std::string& _return) { _return = ""; } + + virtual fb_status getStatus() = 0; + virtual void getStatusDetails(std::string& _return) { _return = ""; } + + void setOption(const std::string& key, const std::string& value); + void getOption(std::string& _return, const std::string& key); + void getOptions(std::map<std::string, std::string> & _return); + + int64_t aliveSince(); + + virtual void reinitialize() {} + + virtual void shutdown() { + if (server_.get() != NULL) { + server_->stop(); + } + } + + int64_t incrementCounter(const std::string& key, int64_t amount = 1); + int64_t setCounter(const std::string& key, int64_t value); + + void getCounters(std::map<std::string, int64_t>& _return); + int64_t getCounter(const std::string& key); + + /** + * Set server handle for shutdown method + */ + void setServer(boost::shared_ptr<TServer> server) { + server_ = server; + } + + void getCpuProfile(std::string& _return, int32_t durSecs) { _return = ""; } + + private: + + std::string name_; + int64_t aliveSince_; + + std::map<std::string, std::string> options_; + Mutex optionsLock_; + + ReadWriteCounterMap counters_; + + boost::shared_ptr<TServer> server_; + +}; + +}} // facebook::tb303 + +#endif // _FACEBOOK_TB303_FACEBOOKBASE_H_ http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/fb303/cpp/Makefile.am ---------------------------------------------------------------------- diff --git a/depends/thirdparty/thrift/contrib/fb303/cpp/Makefile.am b/depends/thirdparty/thrift/contrib/fb303/cpp/Makefile.am new file mode 100644 index 0000000..748d329 --- /dev/null +++ b/depends/thirdparty/thrift/contrib/fb303/cpp/Makefile.am @@ -0,0 +1,84 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +@GLOBAL_HEADER_MK@ + +@PRODUCT_MK@ + + +# User specified path variables set in configure.ac. +# thrift_home +# +THRIFT = $(thrift_home)/bin/thrift + +# User defined conditionals and conditonal statements set up in configure.ac. +if DEBUG + DEBUG_CPPFLAGS = -DDEBUG_TIMING +endif + +# Set common flags recognized by automake. +# DO NOT USE CPPFLAGS, CXXFLAGS, CFLAGS, LDFLAGS here! Set in configure.ac and|or override on command line. +# USE flags AM_CXXFLAGS, AM_CFLAGS, AM_CPPFLAGS, AM_LDFLAGS, LDADD in this section. + +AM_CPPFLAGS = -I.. +AM_CPPFLAGS += -Igen-cpp +AM_CPPFLAGS += -I$(thrift_home)/include/thrift +AM_CPPFLAGS += $(BOOST_CPPFLAGS) +AM_CPPFLAGS += $(FB_CPPFLAGS) $(DEBUG_CPPFLAGS) + +# GENERATE BUILD RULES +# Set Program/library specific flags recognized by automake. +# Use <progname|libname>_<FLAG> to set prog / lib specific flag s +# foo_CXXFLAGS foo_CPPFLAGS foo_LDFLAGS foo_LDADD + +fb303_lib = gen-cpp/FacebookService.cpp gen-cpp/fb303_constants.cpp gen-cpp/fb303_types.cpp FacebookBase.cpp ServiceTracker.cpp + +# Static -- multiple libraries can be defined +if STATIC +lib_LIBRARIES = libfb303.a +libfb303_a_SOURCES = $(fb303_lib) +INTERNAL_LIBS = libfb303.a +endif + +# Shared -- multiple libraries can be defined +if SHARED +shareddir = $(prefix)/lib +shared_PROGRAMS = libfb303.so +libfb303_so_SOURCES = $(fb303_lib) +libfb303_so_CXXFLAGS = $(SHARED_CXXFLAGS) +libfb303_so_LDFLAGS = $(SHARED_LDFLAGS) +INTERNAL_LIBS = libfb303.so +endif + +# Set up Thrift specific activity here. +# We assume that a <name>+types.cpp will always be built from <name>.thrift. +$(eval $(call thrift_template,.,../if/fb303.thrift,-I $(thrift_home)/share --gen cpp:pure_enums )) + +include_fb303dir = $(includedir)/thrift/fb303 +include_fb303_HEADERS = FacebookBase.h ServiceTracker.h gen-cpp/FacebookService.h gen-cpp/fb303_constants.h gen-cpp/fb303_types.h + +include_fb303ifdir = $(prefix)/share/fb303/if +include_fb303if_HEADERS = ../if/fb303.thrift + +BUILT_SOURCES = thriftstyle + +# Add to pre-existing target clean +clean-local: clean-common + +@GLOBAL_FOOTER_MK@
