diff --git a/nativeLib/edexBridge/.cproject b/nativeLib/edexBridge/.cproject index e46d10c81d..d6e0bcb04b 100644 --- a/nativeLib/edexBridge/.cproject +++ b/nativeLib/edexBridge/.cproject @@ -26,7 +26,7 @@ - + @@ -84,424 +84,424 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nativeLib/edexBridge/edexBridge.cpp b/nativeLib/edexBridge/edexBridge.cpp index 4433e2516b..29da5db4bc 100644 --- a/nativeLib/edexBridge/edexBridge.cpp +++ b/nativeLib/edexBridge/edexBridge.cpp @@ -3,21 +3,21 @@ * * Created on: Oct 8, 2009 * Author: brockwoo + * Updated on: June 21, 2013 (Re-written to work with the qpid messaging api) + * Author: bkowal */ -// START SNIPPET: demo - -#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include #include #include +#include #include #include #include @@ -26,8 +26,7 @@ #include #include -using namespace qpid::client; -using namespace qpid::framing; +using namespace qpid::messaging; using namespace std; class LdmProducer { @@ -35,23 +34,31 @@ private: Connection connection; Session session; + Sender sender; bool useTopic; bool sessionTransacted; bool isConnected; std::string brokerURI; int portNumber; + std::string username; + std::string password; list filenameList; list headerList; public: - LdmProducer(const std::string& brokerURI, int port = 5672, bool useTopic = - false, bool sessionTransacted = false) { + LdmProducer(const std::string& brokerURI, int port = 5672, + const std::string& username = "guest", + const std::string& password = "guest", + bool useTopic = false, bool sessionTransacted = false) + { this->useTopic = useTopic; this->sessionTransacted = sessionTransacted; this->brokerURI = brokerURI; this->isConnected = false; this->portNumber = port; + this->username = username; + this->password = password; } ~LdmProducer() { @@ -82,20 +89,19 @@ public: try { while (!this->filenameList.empty()) { Message message; - message.getDeliveryProperties().setRoutingKey( - "external.dropbox"); + fileLocation = this->filenameList.front(); fileHeader = this->headerList.front(); struct timeval tv; gettimeofday(&tv, NULL); - long long current = (((long long) tv.tv_sec) * 1000000 + uint64_t current = (((long long) tv.tv_sec) * 1000000 + ((long long) tv.tv_usec)) / 1000; - message.getDeliveryProperties().setDeliveryMode(PERSISTENT); - message.setData(fileLocation); - message.getHeaders().setString("header", fileHeader); - message.getHeaders().setInt64("enqueueTime", current); - session.messageTransfer(arg::content = message, - arg::destination = "amq.direct"); + message.setDurable(true); + message.setContent(fileLocation); + message.getProperties()["header"] = fileHeader; + message.getProperties()["enqueueTime"] = current; + + this->sender.send(message); this->filenameList.pop_front(); this->headerList.pop_front(); @@ -103,7 +109,6 @@ public: } } catch (const std::exception& error) { // Error occurred during communication. Clean up the connection and return the number of messages processed. - uerror(error.what()); cleanup(); } @@ -112,31 +117,94 @@ public: private: - void cleanup() { - cout << "Cleaning up\n"; + void cleanup() + { + unotice ("Cleaning up"); // Destroy resources. - try { - session.close(); - connection.close(); - } catch (const std::exception& error) { - this->isConnected = false; + if (this->sender != 0) + { + try + { + this->sender.close(); + this->sender = 0; + } + catch (const std::exception& error) + { + uwarn(error.what()); + } + } + + if (this->session != 0) + { + try + { + this->session.close(); + this->session = 0; + } + catch (const std::exception& error) + { + uwarn(error.what()); + } + } + + if (this->connection != 0) + { + try + { + this->connection.close(); + this->connection = 0; + } + catch (const std::exception& error) + { + uwarn(error.what()); + } } this->isConnected = false; } - bool connect() { - if (this->isConnected) { + bool connect() + { + if (this->isConnected) + { return this->isConnected; } - try { - this->connection.open(brokerURI, portNumber); - this->session = this->connection.newSession(); - session.queueDeclare(arg::queue = "external.dropbox", arg::durable=true); - session.exchangeBind(arg::exchange = "amq.direct", arg::queue - = "external.dropbox", arg::bindingKey = "external.dropbox"); + try + { + // initialize + this->connection = 0; + this->session = 0; + this->sender = 0; + + std::stringstream qpidURLBuilder; + qpidURLBuilder << "amqp:tcp:"; + qpidURLBuilder << this->brokerURI; + qpidURLBuilder << ":"; + qpidURLBuilder << this->portNumber; + std::string qpidURL = qpidURLBuilder.str(); + + std::stringstream connectionOptionsBuilder; + connectionOptionsBuilder << "{sasl-mechanism:PLAIN,username:"; + connectionOptionsBuilder << this->username; + connectionOptionsBuilder << ",password:"; + connectionOptionsBuilder << this->password; + connectionOptionsBuilder << "}"; + std::string connectionOptions = connectionOptionsBuilder.str(); + + this->connection = Connection(qpidURL, connectionOptions); + this->connection.open(); + + std::string address = "external.dropbox; {node:{type:queue,durable:true,x-bindings:" + "[{exchange:amq.direct,queue:external.dropbox,key:external.dropbox}]}}"; + + this->session = this->connection.createSession(); + this->sender = this->session.createSender(address); + this->isConnected = true; - } catch (const std::exception& error) { + } + catch (const std::exception& error) + { + uerror(error.what()); this->isConnected = false; } return this->isConnected; @@ -231,6 +299,8 @@ int main(int argc, char* argv[]) { int loggingToStdErr = 0; std::string brokerURI = "127.0.0.1"; int port = 5672; + std::string username = "guest"; + std::string password = "guest"; { extern char *optarg; @@ -281,7 +351,6 @@ int main(int argc, char* argv[]) { // createQueue to be used in both consumer an producer. //============================================================ bool useTopics = false; - //bool sessionTransacted = false; int shmid; int semid; @@ -309,7 +378,7 @@ int main(int argc, char* argv[]) { messageCursor = (edex_message *) shmat(shmid, (void *) 0, 0); - LdmProducer producer(brokerURI, port, useTopics); + LdmProducer producer(brokerURI, port, username, password, useTopics); for (;;) { if (hupped) { diff --git a/rpms/awips2.core/Installer.ldm/component.spec b/rpms/awips2.core/Installer.ldm/component.spec index ddc8f8ad40..b0afbddfc6 100644 --- a/rpms/awips2.core/Installer.ldm/component.spec +++ b/rpms/awips2.core/Installer.ldm/component.spec @@ -20,8 +20,9 @@ Vendor: Raytheon Packager: Bryan Kowal AutoReq: no -Requires: qpid-cpp-client-devel +Requires: awips2-qpid-lib Requires: zlib-devel +requires: awips2-python provides: awips2-ldm provides: awips2-base-component @@ -76,7 +77,7 @@ fi _ldm_destination=%{_build_root}/usr/local/ldm _ldm_destination_source=${_ldm_destination}/SOURCES -_NATIVELIB_PROJECTS=( 'edexBridge' 'decrypt_file' 'org.apache.qpid' ) +_NATIVELIB_PROJECTS=( 'edexBridge' 'decrypt_file' ) _RPM_directory=%{_baseline_workspace}/rpms _Installer_ldm=${_RPM_directory}/awips2.core/Installer.ldm @@ -271,28 +272,10 @@ if [ ${_myHost} != "cpsbn1" -a ${_myHost} != "cpsbn2" -a ${_myHost} != "dx1" -a fi popd > /dev/null 2>&1 -# extract qpid libraries; build decrypt_file & edexBridge +# build decrypt_file & edexBridge pushd . > /dev/null 2>&1 cd ${_ldm_dir}/SOURCES -# determine which lib directory to use -_arch=`uname -i` -_qpid_lib_dir="lib" -if [ "${_arch}" = "x86_64" ]; then - _qpid_lib_dir="lib64" -fi - -/bin/tar -xvf org.apache.qpid.tar org.apache.qpid/${_qpid_lib_dir}/* -if [ $? -ne 0 ]; then - echo "FATAL: failed to extract the qpid libraries!" - exit 1 -fi -cp -Pf org.apache.qpid/${_qpid_lib_dir}/* ${_ldm_root_dir}/lib -if [ $? -ne 0 ]; then - echo "FATAL: failed to copy the qpid libraries to the ldm lib directory." - exit 1 -fi - /bin/tar -xf decrypt_file.tar if [ $? -ne 0 ]; then echo "FATAL: failed to untar decrypt_file.tar!" @@ -337,10 +320,10 @@ export _current_dir=`pwd` su ldm -lc "cd ${_current_dir}; g++ edexBridge.cpp -I${_ldm_root_dir}/src/pqact \ -I${_ldm_root_dir}/include \ -I${_ldm_root_dir}/src \ - -I/usr/include/qpid \ + -I/awips2/qpid/include \ -L${_ldm_root_dir}/lib \ - -L%{_libdir} \ - -l ldm -l xml2 -l qpidclient -l qpidcommon -o edexBridge" > \ + -L/awips2/qpid/lib \ + -l ldm -l xml2 -l qpidclient -l qpidmessaging -l qpidcommon -l qpidtypes -o edexBridge" > \ edexBridge.log 2>&1 if [ $? -ne 0 ]; then echo "FATAL: failed to build edexBridge!" diff --git a/rpms/awips2.core/Installer.ldm/patch/ld.so.conf.d/awips2-ldm-i386.conf b/rpms/awips2.core/Installer.ldm/patch/ld.so.conf.d/awips2-ldm-i386.conf index 77daf2e3f7..2f07c6ab39 100644 --- a/rpms/awips2.core/Installer.ldm/patch/ld.so.conf.d/awips2-ldm-i386.conf +++ b/rpms/awips2.core/Installer.ldm/patch/ld.so.conf.d/awips2-ldm-i386.conf @@ -1 +1,3 @@ /usr/local/ldm/lib +/awips2/qpid/lib +/awips2/python/lib diff --git a/rpms/awips2.qpid/0.18/SPECS/qpid-lib.spec b/rpms/awips2.qpid/0.18/SPECS/qpid-lib.spec index 897f542bd4..bc14be38d6 100644 --- a/rpms/awips2.qpid/0.18/SPECS/qpid-lib.spec +++ b/rpms/awips2.qpid/0.18/SPECS/qpid-lib.spec @@ -69,7 +69,7 @@ if [ $? -ne 0 ]; then exit 1 fi -./configure --prefix=%{_qpid_build_loc}/awips2/qpid +./configure --prefix=%{_qpid_build_loc}/awips2/qpid --without-sasl if [ $? -ne 0 ]; then exit 1 fi @@ -119,4 +119,4 @@ rm -rf %{_qpid_build_loc} %dir /awips2/qpid/lib /awips2/qpid/lib/* %dir /awips2/qpid/include -/awips2/qpid/include/* \ No newline at end of file +/awips2/qpid/include/* diff --git a/rpms/build/common/rpms.sh b/rpms/build/common/rpms.sh index 588d40a0cd..7b319989a2 100644 --- a/rpms/build/common/rpms.sh +++ b/rpms/build/common/rpms.sh @@ -26,7 +26,7 @@ function buildQPID() return 1 fi - /bin/bash build.sh + /bin/bash build.sh 0.18 if [ $? -ne 0 ]; then echo "ERROR: Failed to build the qpid rpms." return 1 @@ -39,16 +39,9 @@ function buildQPID() exit 1 fi fi - if [ ! -d ${AWIPSII_TOP_DIR}/RPMS/i386 ]; then - mkdir -p ${AWIPSII_TOP_DIR}/RPMS/i386 - if [ $? -ne 0 ]; then - exit 1 - fi - fi - pushd . > /dev/null 2>&1 # Copy the 0.18 qpid rpms - cd 0.18/RPMS/noarch + cd ${WORKSPACE}/rpms/awips2.qpid/0.18/RPMS/noarch if [ $? -ne 0 ]; then echo "ERROR: Failed to build Qpid v0.18." return 1 @@ -57,79 +50,46 @@ function buildQPID() if [ $? -ne 0 ]; then return 1 fi - cd ../x86_64 - if [ $? -ne 0 ]; then - echo "ERROR: Failed to build Qpid v0.18 lib." - return 1 - fi - if [ ! -d ${AWIPSII_TOP_DIR}/RPMS/x86_64 ]; then - mkdir -p ${AWIPSII_TOP_DIR}/RPMS/x86_64 - if [ $? -ne 0 ]; then - exit 1 + + # determine which qpid libs we need to copy + _arch=`uname -i` + + if [ "${_arch}" = "x86_64" ]; then + if [ ! -d ${AWIPSII_TOP_DIR}/RPMS/x86_64 ]; then + mkdir -p ${AWIPSII_TOP_DIR}/RPMS/x86_64 + if [ $? -ne 0 ]; then + exit 1 + fi fi - fi - /bin/cp -v *.rpm ${AWIPSII_TOP_DIR}/RPMS/x86_64 - if [ $? -ne 0 ]; then - echo "ERROR: Failed to build Qpid v0.18 lib." - return 1 - fi - popd > /dev/null 2>&1 - pushd . > /dev/null 2>&1 - # Copy the 0.7 qpid rpms - cd 0.7/RPMS/i386 - if [ $? -ne 0 ]; then - echo "ERROR: Failed to build Qpid v0.7." - return 1 - fi - - # Copy the qpid rpms from the local build directory to the rpm - # "staging" directory. - /bin/cp -v awips2-qpid-client-0.7.946106-*.i386.rpm \ - ${AWIPSII_TOP_DIR}/RPMS/i386/ - if [ $? -ne 0 ]; then - return 1 - fi - /bin/cp -v awips2-qpid-server-0.7.946106-*.i386.rpm \ - ${AWIPSII_TOP_DIR}/RPMS/i386/ - if [ $? -ne 0 ]; then - return 1 - fi - /bin/cp -v awips2-qpid-server-store-0.7.946106-*.i386.rpm \ - ${AWIPSII_TOP_DIR}/RPMS/i386/ - if [ $? -ne 0 ]; then - return 1 - fi - - # if the -ade argument has been specified. Also copy the qpid - # devel rpms. - if [ "${1}" = "-ade" ]; then - /bin/cp -v awips2-qpid-client-devel-0.7.946106-*.i386.rpm \ - ${AWIPSII_TOP_DIR}/RPMS/i386/ + cd ${WORKSPACE}/rpms/awips2.qpid/0.18/RPMS/x86_64 + if [ $? -ne 0 ]; then + echo "ERROR: Failed to build Qpid v0.18." + return 1 + fi + /bin/cp -v *.rpm ${AWIPSII_TOP_DIR}/RPMS/x86_64 if [ $? -ne 0 ]; then return 1 fi - - /bin/cp -v awips2-qpid-client-devel-docs-0.7.946106-*.i386.rpm \ - ${AWIPSII_TOP_DIR}/RPMS/i386/ - if [ $? -ne 0 ]; then - return 1 + else + if [ ! -d ${AWIPSII_TOP_DIR}/RPMS/i386 ]; then + mkdir -p ${AWIPSII_TOP_DIR}/RPMS/i386 + if [ $? -ne 0 ]; then + exit 1 + fi fi - /bin/cp -v awips2-qpid-server-devel-0.7.946106-*.i386.rpm \ - ${AWIPSII_TOP_DIR}/RPMS/i386/ + cd ${WORKSPACE}/rpms/awips2.qpid/0.18/RPMS/i386 if [ $? -ne 0 ]; then + echo "ERROR: Failed to build Qpid v0.18." return 1 fi - - /bin/cp qpid-cpp-mrg-debuginfo-0.7.946106-*.i386.rpm \ - ${AWIPSII_TOP_DIR}/RPMS/i386/ + /bin/cp -v *.rpm ${AWIPSII_TOP_DIR}/RPMS/i386 if [ $? -ne 0 ]; then return 1 fi fi - popd > /dev/null 2>&1 popd > /dev/null 2>&1 return 0