Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zorba Server #202

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,58 @@
#This file is generated by https://github.com/wcandillon/zorba-circleci-tpl
machine:
post:
- sudo add-apt-repository -y ppa:fcavalieri/zorba
- sudo add-apt-repository -y ppa:fcavalieri/sausalito
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fcavalieri why do you had these repositories?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there are custom packages that need to be installed to make some
modules work

On Thu, Nov 19, 2015 at 2:31 PM, William Candillon <notifications@github.com

wrote:

In circle.yml
#202 (comment):

@@ -1,23 +1,58 @@
#This file is generated by https://github.com/wcandillon/zorba-circleci-tpl
machine:
post:

    • sudo add-apt-repository -y ppa:fcavalieri/zorba
    • sudo add-apt-repository -y ppa:fcavalieri/sausalito

@fcavalieri https://github.com/fcavalieri why do you had these
repositories?


Reply to this email directly or view it on GitHub
https://github.com/28msec/zorba/pull/202/files#r45339961.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to create the multithreaded testrunner

On Thu, Nov 19, 2015 at 2:40 PM, Federico Cavalieri <
federico.cavalieri@28msec.com> wrote:

Because there are custom packages that need to be installed to make some
modules work

On Thu, Nov 19, 2015 at 2:31 PM, William Candillon <
notifications@github.com> wrote:

In circle.yml
#202 (comment):

@@ -1,23 +1,58 @@
#This file is generated by https://github.com/wcandillon/zorba-circleci-tpl
machine:
post:

    • sudo add-apt-repository -y ppa:fcavalieri/zorba
    • sudo add-apt-repository -y ppa:fcavalieri/sausalito

@fcavalieri https://github.com/fcavalieri why do you had these
repositories?


Reply to this email directly or view it on GitHub
https://github.com/28msec/zorba/pull/202/files#r45339961.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And in zorba server also for the mongodb driver

On Thu, Nov 19, 2015 at 2:41 PM, Federico Cavalieri <
federico.cavalieri@28msec.com> wrote:

And to create the multithreaded testrunner

On Thu, Nov 19, 2015 at 2:40 PM, Federico Cavalieri <
federico.cavalieri@28msec.com> wrote:

Because there are custom packages that need to be installed to make some
modules work

On Thu, Nov 19, 2015 at 2:31 PM, William Candillon <
notifications@github.com> wrote:

In circle.yml
#202 (comment):

@@ -1,23 +1,58 @@
#This file is generated by https://github.com/wcandillon/zorba-circleci-tpl
machine:
post:

    • sudo add-apt-repository -y ppa:fcavalieri/zorba
    • sudo add-apt-repository -y ppa:fcavalieri/sausalito

@fcavalieri https://github.com/fcavalieri why do you had these
repositories?


Reply to this email directly or view it on GitHub
https://github.com/28msec/zorba/pull/202/files#r45339961.

- sudo apt-get update -qq
# - sudo apt-get install -f
- sudo apt-get purge "libmagick*"
- sudo apt-get purge "libboost*"
- sudo apt-get purge "texlive*"
- sudo apt-get purge "flex"
- sudo apt-get purge "libfl-dev"
- sudo apt-get install distcc lib64z1 lib64z1-dev uuid-dev libxerces-c-dev graphviz libboost-filesystem-dev libgeos++-dev imagemagick libmagick++-dev libmagickwand-dev libfop-java libpdfbox-java libtidy-dev libjempbox-java libfontbox-java libarchive-dev libmysqlclient-dev openjdk-6-jdk libaccess-bridge-java-jni libxslt-dev libcurl4-openssl-dev libxerces-c-dev doxygen libedit-dev libkvutils-dev
- sudo locale-gen de_DE && sudo locale-gen de_DE.UTF-8 && sudo locale-gen fr_FR && sudo locale-gen fr_FR.UTF-8 && sudo update-locale
#Core
- sudo apt-get install build-essential cmake libxml2-dev libicu-dev libxerces-c-dev libcurl4-openssl-dev uuid-dev libxslt-dev
#Parser
- sudo apt-get install m4
- wget http://launchpadlibrarian.net/160037457/bison_3.0.2.dfsg-2_amd64.deb
- wget http://launchpadlibrarian.net/160037458/libbison-dev_3.0.2.dfsg-2_amd64.deb
- sudo dpkg -i libbison-dev_3.0.2.dfsg-2_amd64.deb bison_3.0.2.dfsg-2_amd64.deb
- sudo sed -i.bak s/STARTDISTCC=\"false\"/STARTDISTCC=\"true\"/g /etc/default/distcc
- sudo /etc/init.d/distcc start
#Lexer
- wget https://launchpad.net/ubuntu/+source/flex/2.5.39-8/+build/6118519/+files/libfl-dev_2.5.39-8_amd64.deb
- wget https://launchpad.net/ubuntu/+source/flex/2.5.39-8/+build/6118519/+files/flex_2.5.39-8_amd64.deb
- sudo dpkg -i libfl-dev_2.5.39-8_amd64.deb flex_2.5.39-8_amd64.deb
#Documentation
- sudo apt-get install doxygen texlive
#Test Driver
- sudo apt-get install libboost-filesystem-dev
#External modules extra repositories
- sudo apt-get install python-software-properties
- sudo add-apt-repository --yes ppa:fcavalieri/zorba
- sudo wget -O/etc/apt/sources.list.d/couchbase.list http://packages.couchbase.com/ubuntu/couchbase-ubuntu1204.list
- wget http://packages.couchbase.com/ubuntu/couchbase.key
- sudo apt-key add couchbase.key
- sudo apt-get update
#External modules dependencies
- sudo apt-get install libarchive-dev
- sudo apt-get install graphviz-dev
- sudo apt-get install openjdk-7-jdk
- wget http://download.oracle.com/otn-pub/otn_software/nosql-database/kv-c-driver_3.3.5-0_amd64.deb
- sudo dpkg -i kv-c-driver_3.3.5-0_amd64.deb
- sudo apt-get install libfontbox-java libjempbox-java libpdfbox-java libcommons-logging-java
- sudo apt-get install libtidy-dev
- sudo apt-get install libc-client2007e-dev=8:2007e-1~dfsg-3.2ubuntu1zorba2
- sudo apt-get install libsqlite3-dev
- sudo apt-get install libcouchbase-dev
- sudo apt-get install libmagick++-dev
- sudo apt-get install libgeos++-dev
- sudo apt-get install xmlbeans
- sudo apt-get install libfop-java libcommons-logging-java
- sudo locale-gen de_DE && sudo locale-gen de_DE.UTF-8 && sudo locale-gen fr_FR && sudo locale-gen fr_FR.UTF-8 && sudo update-locale
#Zorba Server
- sudo apt-get install nginx spawn-fcgi libfcgi-dev
#DistCC
- sudo apt-get install distcc lib64z1 lib64z1-dev
- sudo sed -i.bak s/STARTDISTCC=\"false\"/STARTDISTCC=\"true\"/g /etc/default/distcc
- sudo /etc/init.d/distcc start
environment:
ZORBA_SRC_DIR: /home/ubuntu/zorba
ZORBA_BUILD_DIR: /home/ubuntu/zorba/build
Expand All @@ -34,6 +69,9 @@ dependencies:
- mkdir -p "${ZORBA_BUILD_DIR}"
test:
pre:
- sudo nginx -c "${ZORBA_SRC_DIR}/src/server/tests/nginx/nginx.conf"
- spawn-fcgi -p 8000 -n "${ZORBA_BUILD_DIR}/src/server/zorba-server":
background: true
- case $CIRCLE_NODE_INDEX in 0) cd "${ZORBA_BUILD_DIR}" && CC="distcc gcc" CXX="distcc c++" cmake -DZORBA_MODULES_DIR="${ZORBA_MODULE_DIR}" -DZORBA_XQUERYX:BOOL=1 -DZORBA_TEST_XQUERYX:BOOL=1 -DZORBA_WITH_BIG_INTEGER=1 -DCMAKE_BUILD_TYPE=Release -DZORBA_TEST_PLAN_SERIALIZATION:BOOL=1 -DZORBATEST_USE_MT_XQTS:BOOL=1 "${ZORBA_SRC_DIR}" && make -j8 && bash "${ZORBA_SRC_DIR}/import_tests.sh" && make fots-activate-sets && cd "${ZORBA_SRC_DIR}" && tar -cf build.tar build ;; esac:
parallel: true
- case $CIRCLE_NODE_INDEX in 1) cd "${ZORBA_SRC_DIR}" && scp -r ubuntu@node0:/home/ubuntu/zorba/build.tar . && tar -xvf build.tar && bash "${ZORBA_SRC_DIR}/import_tests.sh" && cd "${ZORBA_BUILD_DIR}" && make fots-activate-sets ;; 2) cd "${ZORBA_SRC_DIR}" && scp -r ubuntu@node0:/home/ubuntu/zorba/build.tar . && tar -xvf build.tar && bash "${ZORBA_SRC_DIR}/import_tests.sh" && cd "${ZORBA_BUILD_DIR}" && make fots-activate-sets ;; 3) cd "${ZORBA_SRC_DIR}" && scp -r ubuntu@node0:/home/ubuntu/zorba/build.tar . && tar -xvf build.tar && bash "${ZORBA_SRC_DIR}/import_tests.sh" && cd "${ZORBA_BUILD_DIR}" && make fots-activate-sets ;; esac:
Expand Down
68 changes: 68 additions & 0 deletions cmake_modules/FindFCGI.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2015 Federico Cavalieri.
#
# Licensed 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.
#
# - Try to find libfcgi
#
# Once done this will define
#
# FCGI_FOUND - system has libfcgi
# FCGI_INCLUDE_DIR - the libfcgi include directory
# FCGI_LIBRARIES - Link these to use libfcgi
#

IF (FCGI_INCLUDE_DIR AND FCGI_LIBRARIES)
# in cache already
SET (FCGI_FIND_QUIETLY TRUE)
ENDIF (FCGI_INCLUDE_DIR AND FCGI_LIBRARIES)

FIND_PATH(FCGI_INCLUDE_DIR fastcgi.h
/opt/local/include
/usr/local/include
/usr/include
)

FIND_LIBRARY(FCGI_LIBRARY
NAMES fcgi
PATHS /usr/lib
/usr/local/lib
/opt/local/lib
)

FIND_LIBRARY(FCGIPP_LIBRARY
NAMES fcgi++
PATHS /usr/lib
/usr/local/lib
/opt/local/lib
)

IF (FCGI_INCLUDE_DIR AND FCGI_LIBRARY AND FCGIPP_LIBRARY)
SET(FCGI_FOUND TRUE)
SET(FCGI_LIBRARIES ${FCGI_LIBRARY} ${FCGIPP_LIBRARY})
ELSE (FCGI_INCLUDE_DIR AND FCGI_LIBRARY AND FCGIPP_LIBRARY)
SET(FCGI_FOUND FALSE)
SET(FCGI_LIBRARIES)
ENDIF (FCGI_INCLUDE_DIR AND FCGI_LIBRARY AND FCGIPP_LIBRARY)

IF (FCGI_FOUND)
IF (NOT FCGI_FIND_QUIETLY)
MESSAGE(STATUS "Found FCGI: ${FCGI_LIBRARIES}")
ENDIF (NOT FCGI_FIND_QUIETLY)
ELSE (FCGI_FOUND)
MESSAGE(STATUS "Could not find FCGI.")
IF (FCGI_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could NOT find FCGI library")
ENDIF (FCGI_FIND_REQUIRED)
ENDIF (FCGI_FOUND)

MARK_AS_ADVANCED(FCGI_INCLUDE_DIR FCGI_LIBRARY FCGIPP_LIBRARY FCGI_LIBRARIES)
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,8 @@ INSTALL(TARGETS ${ZORBA_LIBRARY_INSTALL_LIST}
LIBRARY DESTINATION lib${LIB_SUFFIX}
ARCHIVE DESTINATION lib
)

#
# Build the Zorba server
#
ADD_SUBDIRECTORY(server)
2 changes: 1 addition & 1 deletion src/context/default_uri_mappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ FileizeURIMapper::mapURI(
// If anything changed, return new URI and the original.
if (lChanged) {
lUri.set_path(lPath);
oUris.push_back(lUri.toString());
oUris.push_back(aUri);
oUris.push_back(lUri.toString());
}
}

Expand Down
76 changes: 76 additions & 0 deletions src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright 2015 Federico Cavalieri.
#
# Licensed 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.

#
# Check Zorba server prerequisites
#
MESSAGE (STATUS "")
MESSAGE (STATUS "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
MESSAGE (STATUS "Configuring optional component <server>")
MESSAGE (STATUS "-------------------------------------------------------------")
MESSAGE (STATUS "")

MESSAGE (STATUS "Looking for FCGI libraries...")
FIND_PACKAGE(FCGI)
IF(FCGI_FOUND)
SET (REQUIRED_LIBS ${FCGI_LIBRARIES})
MESSAGE(STATUS "Fcgi libraries: FOUND.")
ELSE(FCGI_FOUND)
MESSAGE(STATUS "Fcgi libraries: NOT FOUND. Server will not be built.")
ENDIF(FCGI_FOUND)

IF (FCGI_FOUND)
MESSAGE(STATUS "All required libraries have been found. Building server...")

INCLUDE_DIRECTORIES(AFTER ${CMAKE_SOURCE_DIR}/src/)
INCLUDE_DIRECTORIES(AFTER ${CMAKE_CURRENT_SOURCE_DIR})

INCLUDE("${CMAKE_SOURCE_DIR}/cmake_modules/ZorbaGenerateExe.cmake")

SET (SERVER_SRCS
server.cpp
request_handler.cpp

api/evaluation.cpp

io/request.cpp
io/response.cpp
io/response_iterator.cpp

exceptions/formatter.cpp
exceptions/server_exceptions.cpp

utils/debug.cpp
utils/JSONItems.cpp
)

ZORBA_GENERATE_EXE("zorba-server" "${SERVER_SRCS}" "${REQUIRED_LIBS}" "zorba-server" "bin")
ADD_SUBDIRECTORY("tests")

MESSAGE(STATUS "")
MESSAGE(STATUS "-------------------------------------------------------------")
MESSAGE(STATUS "Configuration SUCCEEDED for optional component <server>")
MESSAGE(STATUS "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
MESSAGE(STATUS "")

ELSE (FCGI_FOUND)
MESSAGE(STATUS "Some required libraries were not found. Server will not be built.")

MESSAGE(STATUS "")
MESSAGE(STATUS "-------------------------------------------------------------")
MESSAGE(STATUS "Configuration FAILED for optional component <server>")
MESSAGE(STATUS "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
MESSAGE(STATUS "")

ENDIF (FCGI_FOUND)
154 changes: 154 additions & 0 deletions src/server/api/evaluation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* Copyright 2015 Federico Cavalieri.
*
* Licensed 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 "zorba/module_info.h"

#include "exceptions/server_exceptions.h"
#include "io/response_iterator.h"
#include "request_handler.h"
#include "vector"
#include "string"

#include "evaluation.h"

namespace zorba
{
namespace server
{
namespace api
{

void Evaluation::handleRequest(const io::Request& aRequest, io::Response& aResponse)
{
const std::vector<std::string>& lRequestSegments = aRequest.getRequestURISegments();
if (lRequestSegments.size() == 2)
{
/*
* Request to /v1/evaluate
*/
if (aRequest.getRequestMethod() == "POST")
evaluate(aRequest, aResponse);
else
RequestHandler::throwInvalidMethod(aRequest, "POST");
}
else
{
RequestHandler::throwInvalidEndpoint(aRequest, "Valid request to the evaluate API are </v1/evaluate>.");
}
}

void Evaluation::evaluate(const io::Request& aRequest, io::Response& aResponse)
{
bool lStream = false;
aRequest.getQueryParameterAsBoolean("stream", lStream, false);

if (aRequest.getContentType() && io::ContentTypes::isX_WWW_FORM_URLENCODED(*aRequest.getContentType()))
{
std::string lSource;
aRequest.getQueryParameterAsString("query", lSource, true);
const std::vector<std::string>* lModules = aRequest.getQueryParameter("module");
doEvaluate(lSource, lModules, lStream, aResponse);
}
else
{
const std::string& lSource = aRequest.getBody();
doEvaluate(lSource, NULL, lStream, aResponse);
}
}

void Evaluation::doEvaluate(const std::string& aQuery,
const std::vector<std::string>* aModules,
bool aStream,
io::Response& aResponse)
{
RequestHandler& lRequestHandler = RequestHandler::getInstance();
XQuery_t lQuery;
if (aModules == NULL || aModules->size() == 0)
{
lQuery = lRequestHandler.getZorba().compileQuery(aQuery);
}
else
{
StaticContext_t lContext = lRequestHandler.getZorba().createStaticContext();
MapModuleURLResolver lResolver;
lContext->registerURLResolver(&lResolver);
for (std::vector<std::string>::const_iterator lIt = aModules->begin();
lIt != aModules->end();
++lIt)
{
lResolver.addModule(*lIt);
}
lQuery = lRequestHandler.getZorba().compileQuery(aQuery, lContext);
}

io::ResponseIterator* lRespIterator = new io::ResponseIterator(lQuery->iterator(), !aStream);
zorba::Iterator_t lZorbaIterator(lRespIterator);

if (lRespIterator->isEmpty())
{
aResponse.setStatus(204);
aResponse.sendHeaders();
}
else
{
aResponse.setContentType(lRespIterator->getContentType());
aResponse.sendHeaders();
lRespIterator->getSerializer()->serialize(lZorbaIterator, aResponse.getRawStream());
}
}

void MapModuleURLResolver::addModule(const std::string& aSource)
{
RequestHandler& lRequestHandler = RequestHandler::getInstance();
XQuery_t lQuery = lRequestHandler.getZorba().createQuery();
zorba::ModuleInfo_t lInfo;
std::istringstream lModuleStream(aSource);
lQuery->parse(lModuleStream, lInfo);
std::string lNamespace = lInfo->getTargetNamespace().str();

std::map<std::string, std::string>::const_iterator lIt =
theModules.find(lNamespace);
if (lIt != theModules.end())
{
throw exceptions::ServerException("Received two modules with the URI <" + lNamespace + ">.", 400);
}
theModules[lNamespace] = aSource;
}

void MapModuleURLResolver::releaseStream(std::istream* aStream)
{
delete aStream;
}

Resource* MapModuleURLResolver::resolveURL(
const String& aUrl,
EntityData const* aEntityData)
{
if (aEntityData->getKind() != EntityData::MODULE)
return NULL;
std::map<std::string, std::string>::const_iterator lIt =
theModules.find(aUrl.str());
if (lIt != theModules.end())
{
std::unique_ptr<std::istream> lModule(new std::istringstream(lIt->second));
return StreamResource::create(lModule.release(), &releaseStream);
}
else
return NULL;
}

}
}
}
Loading