-
Notifications
You must be signed in to change notification settings - Fork 22
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
fcavalieri
wants to merge
24
commits into
master
Choose a base branch
from
feature-zorba-server
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Zorba Server #202
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d592e09
Zorba Server skeleton, with main query execution
fcavalieri fede53b
Create evaluate.yml
5cf5673
Delete evaluate.yml
69d7ef1
Skeleton of execution with modules
fcavalieri 13529ed
Refined query execution
fcavalieri 81a6d7d
Use original uri as first in the mapped uri list
fcavalieri 8467fc1
Polishing
fcavalieri ef4bd2c
Polishing
fcavalieri b333571
Polishing
fcavalieri 355af19
Test driver
fcavalieri 7de0843
Fixed content-type detection
fcavalieri c33fe5c
Excluded .. test
fcavalieri ca1046f
Added tests
fcavalieri 1b19455
Removed debug code
fcavalieri 85d95fc
Removed unnecessary server dependencies
fcavalieri 6c2c7c3
Install server dependencies
fcavalieri 98de75a
Update circle.yml
fcavalieri 4b227f3
Update circle.yml
fcavalieri 49960c5
Update circle.yml
fcavalieri 1657b84
Update circle.yml
fcavalieri 44bdd3e
Update circle.yml
fcavalieri 0da827a
Added nginx test configuration
fcavalieri 047e62f
Update circle.yml
fcavalieri 542e0ef
Update circle.yml
fcavalieri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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: