From 3af1e895c7a8d0367c9ffda790f2ee3ce32bdbcf Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 18 Jan 2015 05:20:05 +0200 Subject: [PATCH 1/6] Updated SETUP contents, fixed CMAKE_INSTALL_PREFIX not affecting the install destination and added a WITHOUT_MAXADMIN flag. --- CMakeLists.txt | 11 +++++++++-- SETUP | 19 ++++++++----------- macros.cmake | 3 --- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0156fc6ed..63ea87811 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,12 @@ enable_testing() set_variables() set_maxscale_version() -set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "Prefix prepended to install directories." FORCE) +set(CMAKE_INSTALL_PREFIX "/usr/local/skysql/maxscale" CACHE PATH "Prefix prepended to install directories.") + +#for backwards compability with previous build, to be deprecated +if(INSTALL_DIR) + set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "Prefix prepended to install directories." FORCE) +endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/") @@ -100,7 +105,9 @@ add_subdirectory(utils) add_subdirectory(log_manager) add_subdirectory(query_classifier) add_subdirectory(server) -add_subdirectory(client) +if(NOT WITHOUT_MAXADMIN) + add_subdirectory(client) +endif() if(BUILD_RABBITMQ) find_package(RabbitMQ) add_subdirectory(rabbitmq_consumer) diff --git a/SETUP b/SETUP index c27c9a77c..4e51bef5d 100644 --- a/SETUP +++ b/SETUP @@ -8,29 +8,26 @@ in the README file and execute make install. Simply set the environment variable MAXSCALE_HOME to point to the MaxScale directory, found inside the path into which the files have been copied, -e.g. MAXSCALE_HOME=/usr/local/skysql/maxscale/MaxScale +e.g. MAXSCALE_HOME=/usr/local/skysql/maxscale Also you will need to optionaly set LD_LIBRARY_PATH to include the 'lib' folder, found inside the path into which the files have been copied, e.g. LD_LIBRARY_PATH=/usr/local/skysql/maxscale/lib -Because we need the libmysqld library for parsing we must create a -valid my.cnf file to enable the library to be used. Copy the my.cnf -to $MAXSCALE_HOME/mysql/my.cnf. - To start MaxScale execute the command 'maxscale' from the bin folder, -e.g. /usr/local/skysql/maxscale/bin/maxscale +e.g. /usr/local/skysql/maxscale/bin/maxscale or by using the +installed init.d script. Configuration -You need to edit the file MaxScale.cnf in $MAXSCALE_HOME/etc, you should -define the set of server definitions you require, with the addresses +You need to create and edit the file MaxScale.cnf in $MAXSCALE_HOME/etc. +You should define the set of server definitions you require, with the addresses and ports of those servers. Also define the listening ports for your various services. -In order to view the internal activity of the gateway you can telnet to +In order to view the internal activity of MaxScale you can telnet to the port defined for the telnet listener. Initially you may login with the user name of "admin" and the password "skysql". Once connected type help for an overview of the commands and help for the more -detailed help on commands. Use the add user command to add a new user, -this will also remove the admin/skysql user. +detailed help on commands. Use the 'add user' command to add a new user +which will also remove the admin/skysql user. diff --git a/macros.cmake b/macros.cmake index 8e3142d15..e3df7e2c5 100644 --- a/macros.cmake +++ b/macros.cmake @@ -17,9 +17,6 @@ endmacro() macro(set_variables) - # Installation directory - set(INSTALL_DIR "/usr/local/skysql/maxscale/" CACHE PATH "MaxScale installation directory.") - # Build type set(BUILD_TYPE "None" CACHE STRING "Build type, possible values are:None, Debug, DebugSymbols, Optimized.") From e79ea8bc3ebd92085395e69abc0c72a8923f5085 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 18 Jan 2015 05:29:37 +0200 Subject: [PATCH 2/6] Removed INSTALL_DIR due to bug 689 being fixed and updated README to use 'cmake -LH' instead of listing the variables. --- CMakeLists.txt | 6 ------ README | 22 ++-------------------- macros.cmake | 44 -------------------------------------------- 3 files changed, 2 insertions(+), 70 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 63ea87811..c1160bae0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,12 +9,6 @@ set_maxscale_version() set(CMAKE_INSTALL_PREFIX "/usr/local/skysql/maxscale" CACHE PATH "Prefix prepended to install directories.") -#for backwards compability with previous build, to be deprecated -if(INSTALL_DIR) - set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "Prefix prepended to install directories." FORCE) -endif() - - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/") project(MaxScale) diff --git a/README b/README index e29914819..d894bf1ec 100644 --- a/README +++ b/README @@ -169,27 +169,9 @@ The default values that CMake uses can be found in the 'macros.cmake' file. If you wish to change these, edit the 'macros.cmake' file or define the variables manually at configuration time. -All the variables that control the CMake build process: +To display all CMake variables with their descriptions: -INSTALL_DIR= Installation directory - -BUILD_TYPE= Type of the build. One of None, Debug, DebugSymbols, Optimized. (default None) - DebugSymbols enables debugging symbols, Debug enables debugging symbols and code, - Optimized builds an optimized version. - -INSTALL_SYSTEM_FILES=[Y|N] Install startup scripts and ld configuration files -EMBEDDED_LIB= Path to the embedded library location (libmysqld.a for static and libmysqld.so for dynamic) -MYSQL_DIR= Path to MySQL headers -ERRMSG= Path to errmsg.sys file -STATIC_EMBEDDED=[Y|N] Whether to link the static or the dynamic verson of the library -GCOV=[Y|N] Generate gcov output -OLEVEL=<0-3> Level of optimization -BUILD_TESTS=[Y|N] Build tests -DEBUG_OUTPUT=[Y|N] Produce debugging output when configuring CMake -RABBITMQ_LIBRARIES= Path to RabbitMQ-C libraries -RABBITMQ_HEADERS= Path to RabbitMQ-C headers -MYSQLCLIENT_LIBRARIES= Path to MySQL client libraries -MYSQLCLIENT_HEADERS= Path to MySQL client headers + cmake -LH \section Running Running MaxScale diff --git a/macros.cmake b/macros.cmake index e3df7e2c5..c1cc18c7d 100644 --- a/macros.cmake +++ b/macros.cmake @@ -212,53 +212,9 @@ debugmsg("Search returned: ${MYSQL_DIR_LOC}") unset(DEB_FNC) unset(RPM_FNC) - #Find the MySQL client library -# find_library(MYSQLCLIENT_LIBRARIES NAMES mysqlclient PATH_SUFFIXES mysql mariadb) -# if(${MYSQLCLIENT_LIBRARIES} MATCHES "NOTFOUND") -# set(MYSQLCLIENT_FOUND FALSE CACHE INTERNAL "") -# message(STATUS "Cannot find MySQL client library: Login tests disabled.") -# else() -# set(MYSQLCLIENT_FOUND TRUE CACHE INTERNAL "") -# message(STATUS "Found MySQL client library: ${MYSQLCLIENT_LIBRARIES}") -# endif() - #Check RabbitMQ headers and libraries if(BUILD_RABBITMQ) find_package(RabbitMQ) -# include(CheckCSourceCompiles) -# -# if(DEFINED RABBITMQ_LIB) -# find_library(RMQ_LIB rabbitmq PATHS ${RABBITMQ_LIB} NO_DEFAULT_PATH) -# else() -# find_library(RMQ_LIB rabbitmq) -# endif() -# if(RMQ_LIB MATCHES "NOTFOUND") -# set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") -# message(FATAL_ERROR "Cannot find RabbitMQ libraries, please define the path to the libraries with -DRABBITMQ_LIB=") -# else() -# set(RABBITMQ_LIB ${RMQ_LIB} CACHE PATH "Path to RabbitMQ libraries" FORCE) -# message(STATUS "Using RabbitMQ libraries found at: ${RABBITMQ_LIB}") -# endif() -# -# if(DEFINED RABBITMQ_HEADERS) -# find_file(RMQ_HEADERS amqp.h PATHS ${RABBITMQ_HEADERS} NO_DEFAULT_PATH) -# else() -# find_file(RMQ_HEADERS amqp.h) -# endif() -# if(RMQ_HEADERS MATCHES "NOTFOUND") -# set(DEPS_OK FALSE CACHE BOOL "If all the dependencies were found.") -# message(FATAL_ERROR "Cannot find RabbitMQ headers, please define the path to the headers with -DRABBITMQ_HEADERS=") -# else() -# set(RABBITMQ_HEADERS ${RMQ_HEADERS} CACHE PATH "Path to RabbitMQ headers" FORCE) -# message(STATUS "Using RabbitMQ headers found at: ${RABBITMQ_HEADERS}") -# endif() -# -# set(CMAKE_REQUIRED_INCLUDES ${RABBITMQ_HEADERS}) -# check_c_source_compiles("#include \n int main(){if(AMQP_DELIVERY_PERSISTENT){return 0;}return 1;}" HAVE_RMQ50) -# if(NOT HAVE_RMQ50) -# message(FATAL_ERROR "Old version of RabbitMQ-C library found. Version 0.5 or newer is required.") -# endif() -# endif() endmacro() From 66db37341d1a6eb57c401a054821187d5c693a06 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 18 Jan 2015 05:55:29 +0200 Subject: [PATCH 3/6] Updates all references to INSTALL_DIR with CMAKE_INSTALL_PREFIX. --- CMakeLists.txt | 6 +++--- README | 2 +- etc/init.d/maxscale.in | 2 +- etc/ubuntu/init.d/maxscale.in | 2 +- maxscale.conf.in | 4 ++-- server/core/gateway.c | 2 +- server/test/MaxScale_test.cnf | 2 -- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1160bae0..743c52736 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,13 +176,13 @@ endif() add_custom_target(buildtests - COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DBUILD_TYPE=Debug -DINSTALL_DIR=${CMAKE_BINARY_DIR} -DINSTALL_SYSTEM_FILES=N ${CMAKE_SOURCE_DIR} + COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DBUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DINSTALL_SYSTEM_FILES=N ${CMAKE_SOURCE_DIR} COMMAND make COMMENT "Building test suite..." VERBATIM ) add_custom_target(testall - COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DBUILD_TYPE=Debug -DINSTALL_DIR=${CMAKE_BINARY_DIR} -DINSTALL_SYSTEM_FILES=N ${CMAKE_SOURCE_DIR} + COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DBUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DINSTALL_SYSTEM_FILES=N ${CMAKE_SOURCE_DIR} COMMAND make install COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/server/test/MaxScale_test.cnf ${CMAKE_BINARY_DIR}/etc/MaxScale.cnf COMMAND /bin/sh -c "${CMAKE_BINARY_DIR}/bin/maxscale -c ${CMAKE_BINARY_DIR} &>/dev/null" @@ -216,7 +216,7 @@ endif() # Testall target with Valgrind if(VALGRIND_FOUND) add_custom_target(testall-valgrind - COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DBUILD_TYPE=Debug -DINSTALL_DIR=${CMAKE_BINARY_DIR} -DINSTALL_SYSTEM_FILES=N ${CMAKE_SOURCE_DIR} + COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DBUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DINSTALL_SYSTEM_FILES=N ${CMAKE_SOURCE_DIR} COMMAND make install COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/server/test/MaxScale_test.cnf ${CMAKE_BINARY_DIR}/etc/MaxScale.cnf COMMAND /bin/sh -c "valgrind --track-fds=yes --leak-check=full --show-leak-kinds=all --log-file=${CMAKE_BINARY_DIR}/valgrind.log ${CMAKE_BINARY_DIR}/bin/maxscale -c ${CMAKE_BINARY_DIR} &>/dev/null" diff --git a/README b/README index d894bf1ec..583f9d26a 100644 --- a/README +++ b/README @@ -153,7 +153,7 @@ package you are using. A version mismatch will cause the library to fail to initialise. By default, MaxScale installs to '/usr/local/skysql/maxscale' and places init.d scripts -and ldconfig files into their folders. Change the INSTALL_DIR variable to your desired +and ldconfig files into their folders. Change the CMAKE_INSTALL_PREFIX variable to your desired installation directory and set INSTALL_SYSTEM_FILES=N to prevent the init.d script and ldconfig file installation. diff --git a/etc/init.d/maxscale.in b/etc/init.d/maxscale.in index 00c9777aa..88f026e18 100755 --- a/etc/init.d/maxscale.in +++ b/etc/init.d/maxscale.in @@ -21,7 +21,7 @@ # MaxScale HOME, PIDFILE, LIB ############################################# -export MAXSCALE_HOME=@INSTALL_DIR@ +export MAXSCALE_HOME=@CMAKE_INSTALL_PREFIX@ export MAXSCALE_PIDFILE=$MAXSCALE_HOME/log/maxscale.pid export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MAXSCALE_HOME/lib diff --git a/etc/ubuntu/init.d/maxscale.in b/etc/ubuntu/init.d/maxscale.in index 3610b8fd9..269f88638 100755 --- a/etc/ubuntu/init.d/maxscale.in +++ b/etc/ubuntu/init.d/maxscale.in @@ -21,7 +21,7 @@ # MaxScale HOME, PIDFILE, LIB ############################################# -export MAXSCALE_HOME=@INSTALL_DIR@ +export MAXSCALE_HOME=@CMAKE_INSTALL_PREFIX@ export MAXSCALE_PIDFILE=$MAXSCALE_HOME/log/maxscale.pid export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MAXSCALE_HOME/lib diff --git a/maxscale.conf.in b/maxscale.conf.in index 0283479f1..d369e24ee 100644 --- a/maxscale.conf.in +++ b/maxscale.conf.in @@ -1,2 +1,2 @@ -@INSTALL_DIR@/modules -@INSTALL_DIR@/lib +@CMAKE_INSTALL_PREFIX@/modules +@CMAKE_INSTALL_PREFIX@/lib diff --git a/server/core/gateway.c b/server/core/gateway.c index a32c83a9a..2508ef78b 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -1096,7 +1096,7 @@ int main(int argc, char **argv) long_options, &option_index)) != -1) { bool succp = true; - + struct option* optr = long_options; switch (opt) { case 'd': /*< Debug mode, maxscale runs in this same process */ diff --git a/server/test/MaxScale_test.cnf b/server/test/MaxScale_test.cnf index a9bd3def7..aeaea2d69 100644 --- a/server/test/MaxScale_test.cnf +++ b/server/test/MaxScale_test.cnf @@ -26,7 +26,6 @@ passwd=maxpwd max_slave_connections=100% filters=Hint - [Read Connection Router] type=service router=readconnroute @@ -54,7 +53,6 @@ type=filter module=tee service=RW Split Hint Router - [Debug Interface] type=service router=debugcli From d4d9304dab8b37b06afd23c186667e6590a52467 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 18 Jan 2015 06:08:38 +0200 Subject: [PATCH 4/6] Removed unused values. --- server/core/gateway.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/core/gateway.c b/server/core/gateway.c index 2508ef78b..e882d6412 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -1096,7 +1096,7 @@ int main(int argc, char **argv) long_options, &option_index)) != -1) { bool succp = true; - struct option* optr = long_options; + switch (opt) { case 'd': /*< Debug mode, maxscale runs in this same process */ From b2505fd660fb019b6e4de6c99c309a4c825432ff Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 18 Jan 2015 06:24:51 +0200 Subject: [PATCH 5/6] Fix to bug 683: http://bugs.mariadb.com/show_bug.cgi?id=683 Added a check for MySQL version and a warning for the user about versions older than 5.5.40. --- FindMySQLConfig.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/FindMySQLConfig.cmake b/FindMySQLConfig.cmake index a20e6dc47..377ea2912 100644 --- a/FindMySQLConfig.cmake +++ b/FindMySQLConfig.cmake @@ -2,12 +2,19 @@ # The following variables are set: # MYSQLCONFIG_FOUND - System has MySQL and the tool was found # MYSQLCONFIG_EXECUTABLE - The MySQL configuration tool executable +# MYSQL_VERSION - The MySQL version number find_program(MYSQLCONFIG_EXECUTABLE mysql_config) if(MYSQLCONFIG_EXECUTABLE MATCHES "MYSQLCONFIG_EXECUTABLE-NOTFOUND") message(FATAL_ERROR "Cannot find mysql_config.") set(MYSQLCONFIG_FOUND FALSE CACHE INTERNAL "") unset(MYSQLCONFIG_EXECUTABLE) else() + execute_process(COMMAND ${MYSQLCONFIG_EXECUTABLE} --version OUTPUT_VARIABLE MYSQL_VERSION) + string(REPLACE "\n" "" MYSQL_VERSION ${MYSQL_VERSION}) message(STATUS "mysql_config found: ${MYSQLCONFIG_EXECUTABLE}") + message(STATUS "MySQL version: ${MYSQL_VERSION}") + if(MYSQL_VERSION VERSION_LESS 5.5.40) + message(WARNING "Required MySQL version is 5.5.40 or greater.") + endif() set(MYSQLCONFIG_FOUND TRUE CACHE INTERNAL "") endif() From d45cae2ee71f7ccde655a86b826fea998c9e1887 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Sun, 18 Jan 2015 12:34:32 +0200 Subject: [PATCH 6/6] Seaprated the RabbitMQ consumer from MaxScale's build system. --- rabbitmq_consumer/CMakeLists.txt | 70 +++++-- rabbitmq_consumer/COPYRIGHT | 20 ++ rabbitmq_consumer/LICENSE | 340 +++++++++++++++++++++++++++++++ rabbitmq_consumer/SETUP | 12 ++ rabbitmq_consumer/consumer.c | 18 +- 5 files changed, 438 insertions(+), 22 deletions(-) create mode 100644 rabbitmq_consumer/COPYRIGHT create mode 100644 rabbitmq_consumer/LICENSE create mode 100644 rabbitmq_consumer/SETUP diff --git a/rabbitmq_consumer/CMakeLists.txt b/rabbitmq_consumer/CMakeLists.txt index 20ab2a46e..170c19e01 100644 --- a/rabbitmq_consumer/CMakeLists.txt +++ b/rabbitmq_consumer/CMakeLists.txt @@ -1,19 +1,63 @@ -if(RABBITMQ_FOUND AND MYSQLCLIENT_FOUND) +cmake_minimum_required(VERSION 2.6) +include(../macros.cmake) +enable_testing() +set_variables() +set(CMAKE_INSTALL_PREFIX "/usr/local/skysql/rabbitmq-consumer" CACHE PATH "Prefix prepended to install directories.") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../") - include_directories(${MYSQLCLIENT_HEADERS}) - add_executable (consumer consumer.c) +project("RabbitMQ Consumer") - if(MYSQLCLIENT_FOUND) - target_link_libraries(consumer ${MYSQLCLIENT_LIBRARIES} rabbitmq inih) - elseif(MYSQLCLIENT_STATIC_FOUND) - target_link_libraries(consumer ${MYSQLCLIENT_STATIC_LIBRARIES} rabbitmq inih) + +find_package(RabbitMQ) +find_package(MySQLClient) + +set(CMAKE_C_FLAGS "-Wall -fPIC") +set(CMAKE_CXX_FLAGS "-Wall -fPIC") +include_directories(${MYSQLCLIENT_HEADERS}) +include_directories(inih) +add_subdirectory(inih) +add_executable (consumer consumer.c) + +if(MYSQLCLIENT_FOUND) + target_link_libraries(consumer ${MYSQLCLIENT_LIBRARIES} rabbitmq inih ssl crypt crypto dl z m pthread) +elseif(MYSQLCLIENT_STATIC_FOUND) + target_link_libraries(consumer ${MYSQLCLIENT_STATIC_LIBRARIES} rabbitmq inih ssl crypt crypto dl z m pthread) +endif() + +install(TARGETS consumer DESTINATION bin) +install(FILES consumer.cnf DESTINATION etc) + +if(${CMAKE_VERSION} VERSION_LESS 2.8.12) + message(WARNING "CMake version is ${CMAKE_VERSION}. Building of packages requires version 2.8.12 or greater.") +else() + # See if we are on a RPM-capable or DEB-capable system + find_program(RPMBUILD rpmbuild) + find_program(DEBBUILD dpkg-buildpackage) + set(CPACK_GENERATOR "TGZ") + if(NOT ( ${RPMBUILD} STREQUAL "RPMBUILD-NOTFOUND" ) ) + message(STATUS "Generating RPM packages") + set(CPACK_GENERATOR "${CPACK_GENERATOR};RPM") endif() - install(TARGETS consumer DESTINATION bin) - install(FILES consumer.cnf DESTINATION etc) - -else() - - message(FATAL_ERROR "Error: Can not find requred libraries and headers: librabbitmq libmysqlclient") + if(NOT ( ${DEBBUILD} STREQUAL "DEBBUILD-NOTFOUND" ) ) + set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB") + execute_process(COMMAND dpgk --print-architecture OUTPUT_VARIABLE DEB_ARCHITECTURE) + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DEB_ARCHITECTURE}) + set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) + message(STATUS "Generating DEB packages for ${DEB_ARCHITECTURE}") + endif() + set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "RabbitMQ Consumer") + set(CPACK_PACKAGE_VERSION_MAJOR "1") + set(CPACK_PACKAGE_VERSION_MINOR "0") + set(CPACK_PACKAGE_VERSION_PATCH "0") + set(CPACK_PACKAGE_CONTACT "MariaDB Corporation Ab") + set(CPACK_PACKAGE_FILE_NAME "rabbitmq-consumer-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") + set(CPACK_PACKAGE_NAME "rabbitmq-consumer") + set(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab") + set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") + set(CPACK_RPM_PACKAGE_NAME "rabbitmq-consumer") + set(CPACK_RPM_PACKAGE_VENDOR "MariaDB Corporation Ab") + set(CPACK_RPM_PACKAGE_LICENSE "GPLv2") + include(CPack) endif() diff --git a/rabbitmq_consumer/COPYRIGHT b/rabbitmq_consumer/COPYRIGHT new file mode 100644 index 000000000..83c3e4f14 --- /dev/null +++ b/rabbitmq_consumer/COPYRIGHT @@ -0,0 +1,20 @@ +This source code is distributed as part of MariaDB Corporation MaxScale. It is free +software: you can redistribute it and/or modify it under the terms of the +GNU General Public License as published by the Free Software Foundation, +version 2. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 51 +Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Copyright MariaDB Corporation Ab 2013 + +MariaDB Corporation Corporation Ab +Tekniikantie 12 +02150 Espoo +Finland diff --git a/rabbitmq_consumer/LICENSE b/rabbitmq_consumer/LICENSE new file mode 100644 index 000000000..3912109b5 --- /dev/null +++ b/rabbitmq_consumer/LICENSE @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/rabbitmq_consumer/SETUP b/rabbitmq_consumer/SETUP new file mode 100644 index 000000000..df2b55381 --- /dev/null +++ b/rabbitmq_consumer/SETUP @@ -0,0 +1,12 @@ +This is a fast guide to setting up the RabbitMQ Consumer. + +Configure CMake: + + cmake . + +Install: + + make install + +After installation configure the 'consumer.cnf' file. Refer to README for details +about the required values. diff --git a/rabbitmq_consumer/consumer.c b/rabbitmq_consumer/consumer.c index 75fedc786..7e9ba5ea3 100644 --- a/rabbitmq_consumer/consumer.c +++ b/rabbitmq_consumer/consumer.c @@ -115,7 +115,7 @@ int connectToServer(MYSQL* server) if(result==NULL){ - fprintf(out_fd,"Error: Could not connect to MySQL server: %s\n",mysql_error(server)); + fprintf(out_fd,"\33[31;1mError\33[0m: Could not connect to MySQL server: %s\n",mysql_error(server)); return 0; } @@ -134,18 +134,18 @@ int connectToServer(MYSQL* server) memset(qstr,0,bsz); sprintf(qstr,DB_DATABASE,c_inst->dbname); if(mysql_query(server,qstr)){ - fprintf(stderr,"Error: Could not send query MySQL server: %s\n",mysql_error(server)); + fprintf(stderr,"\33[31;1mError\33[0m: Could not send query MySQL server: %s\n",mysql_error(server)); } memset(qstr,0,bsz); sprintf(qstr,"USE %s;",c_inst->dbname); if(mysql_query(server,qstr)){ - fprintf(stderr,"Error: Could not send query MySQL server: %s\n",mysql_error(server)); + fprintf(stderr,"\33[31;1mError\33[0m: Could not send query MySQL server: %s\n",mysql_error(server)); } memset(qstr,0,bsz); sprintf(qstr,"%s",DB_TABLE); if(mysql_query(server,qstr)){ - fprintf(stderr,"Error: Could not send query MySQL server: %s\n",mysql_error(server)); + fprintf(stderr,"\33[31;1mError\33[0m: Could not send query MySQL server: %s\n",mysql_error(server)); } free(qstr); @@ -414,14 +414,14 @@ int main(int argc, char** argv) } if(amqp_socket_open(socket, c_inst->hostname, c_inst->port)){ - fprintf(stderr, "RabbitMQ Error: Cannot open socket.\n"); + fprintf(stderr, "\33[31;1mRabbitMQ Error\33[0m: Cannot open socket.\n"); goto error; } ret = amqp_login(conn, c_inst->vhost, 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, c_inst->user, c_inst->passwd); if(ret.reply_type != AMQP_RESPONSE_NORMAL){ - fprintf(stderr, "RabbitMQ Error: Cannot login to server.\n"); + fprintf(stderr, "\33[31;1mRabbitMQ Error\33[0m: Cannot login to server.\n"); goto error; } @@ -429,7 +429,7 @@ int main(int argc, char** argv) ret = amqp_get_rpc_reply(conn); if(ret.reply_type != AMQP_RESPONSE_NORMAL){ - fprintf(stderr, "RabbitMQ Error: Cannot open channel.\n"); + fprintf(stderr, "\33[31;1mRabbitMQ Error\33[0m: Cannot open channel.\n"); goto error; } @@ -458,7 +458,7 @@ int main(int argc, char** argv) if(sendMessage(&db_inst,reply)){ - fprintf(stderr,"RabbitMQ Error: Received malformed message.\n"); + fprintf(stderr,"\33[31;1mRabbitMQ Error\33[0m: Received malformed message.\n"); amqp_basic_reject(conn,channel,decoded->delivery_tag,0); amqp_destroy_message(reply); @@ -470,7 +470,7 @@ int main(int argc, char** argv) } }else{ - fprintf(stderr,"RabbitMQ Error: Received method from server: %s\n",amqp_method_name(frame.payload.method.id)); + fprintf(stderr,"\33[31;1mRabbitMQ Error\33[0m: Received method from server: %s\n",amqp_method_name(frame.payload.method.id)); all_ok = 0; goto error; }