Commit Graph

1483 Commits

Author SHA1 Message Date
Amnon Heiman
ff6d48bb27 adding swagger code generation to configure 2015-03-30 15:38:41 +03:00
Amnon Heiman
b93dcf3dbd json adding the swagger code generation
This takes the json2code perl script from the osv and pass it with small
adaptation.

It takes a swagger definition file and creates a hh file from it with
the following code support.

Api opperations are translated to path_description with a name that
determine by their nick name.

Moduls are defined as json object with the same name.

Enums are defined as enum class, a string to enum function is defined
for any query enum parameters.

For enums that are part of a json object a conversion function is
defined so enum of a different type can be assigned to the target enum
as long as it has the same enum values.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Amnon Heiman
f2147e7490 Http adding the json path
Json path are used when parsing the swagger files. Each path represent
an operation in the swagger files.

They are used to simplified setting a handler or a function to a path.

For example: the code generation would define a json_path like:

path_description hello_world("/hello/world",GET,"hello_world", {},{});

Now to define the handler that would use hello_world, you can simply do:

hello_world.set(r,
            [](const_req req) {
               return "hello world";
});

When r is a reference to a route object.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Amnon Heiman
f6d253b713 request return http as the protocol name 2015-03-30 15:38:41 +03:00
Amnon Heiman
2ff0f41cfb http adding file handler
File handlers support reading local file and return it as the result
for the http request.

There are two kind of handler, a file handler will return a specific
file when called. A directory handler expect to find a path parameter
called 'path' and would concatinate this parameter to the direcoty path.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Amnon Heiman
cb535f1fa9 Add file_type method to the reactor
This method check the file type and retrun an optional value, if the
file does not exists no value is return.

On other errors an exception will be thrown.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Amnon Heiman
6512d7f7fb http support query parameter and url encoding
Http url encode query parameters by adding a question mark after the uri
with pairs of key=value items.

All values in the url are url decoded.

This add the url encoding and query parameters support

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Amnon Heiman
be33b31ae2 Httpd Adding function handlers
Most of the time, implementing an http handler consist of a small amount
of logic.

Function handlers are a simplified way of adding such a logic, they
accept a lambda expression of various types and eliminate the need to
create a type for the handlers.

The prefered way of creating a handler is by using the
json_request_function, it would use auto-boxing to return a json object.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Amnon Heiman
950d921df3 Http server handlers to use future
The http server handlers can sometimes need to perform async operation,
specifically, when reading files from the disk.  To support async
behavior the handlers handle function will return a future, that will be
propagate back, when the future will be ready it will return the reply
to be sent.

When switching from direct function call to future, there is also a need
to switch from references to pointers.

Note that while the request will be discarded, the reply will be
propagate back via the future to the caller.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Amnon Heiman
c420b75e26 remove leading spaces from headers 2015-03-30 15:38:41 +03:00
Amnon Heiman
0faf9cbb56 Adding back, find_last_of and append to sstring
This adds the back method that return a reference or const reference to
the last char in an sstring.

find_last_of, which return the index of the last occurance of a char in
the string.

And append with append C string to a string.

The logic and definition are similiar to the std::string.

Note that following the std::string definition, calling back on an empty
string is forbiden and the results are undefined.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
2015-03-30 15:38:41 +03:00
Paweł Dziepak
d3504f90a9 memory: fix trimming of allocated spans
Trimmers may request buffers smaller than n_pages, the original value
passed to allocate_large_and_trim(). That's why t.nr_page should be
used as a final size of the allocated span.

Another issue with the handling of span trimming is the order of operations
when pages from the beginning of the buffer are trimmed. In such case
span is updated to point to the actual beginning of the requested buffer,
but afterwards it is used to retrieve span->span_size value which is expected
to be the size of the originally allocated page span. Because the span
pointer was changed the value is invalid and the trimming doesn't free
all trimmed pages.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>
2015-03-30 14:21:36 +03:00
Avi Kivity
7cf25ce492 distributed: fix use-after-move
distributed::stop() passes the pointer to the instance being destroyed
by reference, in an attempt to keep things clean (by nulling the pointer
after deleting it).  This is illegal, however, since the lambda is moved
in the bowels of submit_to().  In release mode this is optimized away so
the code works, but in debug mode it leads to a crash.

Fix by capturing by value instead (could also have been fixed by switching
the enclosing capture to a reference).

Credit to Gleb for identifying the problem.
2015-03-30 11:18:16 +03:00
Shlomi Livne
cbf972c135 tests: set BOOST_TEST_SUITE to the test file name instead of the generic "seastar-tests"
Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
2015-03-29 11:54:01 +03:00
Shlomi Livne
514bead08b tests: Fix output bug in test.py
The change to add a timeout to test.py introduced a bug that caused
thestdout,stderr not to be printed in case of an error. This patch fixes
this bug.

Signed-off-by: Shlomi Livne <shlomi@cloudius-systems.com>
2015-03-26 13:27:49 +02:00
Marek Waszkiewicz
bf564b463a README: add xen-devel boost-devel for fedora 21 build instructions
Signed-off-by: Marek Waszkiewicz <marek.waszkiewicz77@gmail.com>
2015-03-26 09:33:03 +02:00
Gleb Natapov
937970ccd3 rpc: keep shared pointer to a client connection
Client connection may outlive its do_until() loop. Make connection
point shared to overcome this. If connection dies while async handler
is running it will not be deleted until the handler is executed.
2015-03-25 11:32:33 +02:00
Avi Kivity
4eff2e0db9 Merge branch 'tgrabiec/distributed' of github.com:cloudius-systems/seastar-dev
distributed::start() fix, from Tomasz.
2015-03-25 11:19:13 +02:00
Tomasz Grabiec
4dc8a6a09c test: distrubuted_test: Test that constructor arguments are copied on each core 2015-03-25 09:39:34 +01:00
Tomasz Grabiec
5133a0b2ab tests: distributed_test: Add missing start() invocation 2015-03-25 09:39:34 +01:00
Tomasz Grabiec
dc4eb7af2d tests: Rename map_reduce_test.cc to distributed_test.cc 2015-03-25 09:39:34 +01:00
Tomasz Grabiec
040f8ffcfb tests: Convert tabs to spaces 2015-03-25 09:39:34 +01:00
Tomasz Grabiec
8abd982ec9 distributed: Do not move arguments when passing to many cores 2015-03-25 09:39:34 +01:00
Raphael S. Carvalho
54875279f6 slab: fix comment
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-03-24 10:12:47 +02:00
Raphael S. Carvalho
087a34a544 slab: free slab page if page desc alloc failed
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-03-24 10:12:46 +02:00
Tomasz Grabiec
6692435757 core: Implement operator<< for smart pointers
It will allow to implement generic join(), which works with
sequences of things, and use it on std::vector<shared_ptr<printable>>
2015-03-23 11:49:18 +02:00
Avi Kivity
e8764371e7 Merge branch 'gleb/rpc' of github.com:cloudius-systems/seastar-dev
no_wait and client info support for rpc, from Gleb.
2015-03-22 16:35:00 +02:00
Gleb Natapov
406fbf76f7 rpc: add no_wait and client_info tests 2015-03-22 16:16:30 +02:00
Gleb Natapov
9f0900ee0f rpc: add logger and log exception in no_wait callback 2015-03-22 16:16:23 +02:00
Gleb Natapov
12885b924c rpc: add a possibly to pass client_info to an rpc handler
If rpc handler needs locally held information about rpc client that
making a call it may have client_info as a first parameter of rpc
handler. Rpc framework will pass it to the callback during invocation.
2015-03-22 16:16:17 +02:00
Gleb Natapov
7fe06f006e rpc: introduce rpc::no_wait
If registered callback returns rpc::no_wait a client will not wait
for remote function execution and will get immediately ready future.
2015-03-22 16:16:09 +02:00
Gleb Natapov
7f90c314da net: provide const versions of socket_address functions 2015-03-22 16:16:05 +02:00
Raphael S. Carvalho
6e049a4a98 tests: add test_fstream_unaligned testcase to fstream test
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2015-03-18 13:10:00 +02:00
Avi Kivity
6852f21463 future: mark state as invalid when moving away from *this
Avoid inconsistency between an future thinking it's an exception, while
the exception pointer is null.

Fixes smp_test.
2015-03-18 12:34:32 +02:00
Tomasz Grabiec
a7d6e22baf sstring: fix bounds checks in find()
'end' iterator was set past the end if pos != 0.
2015-03-17 15:37:54 +02:00
Avi Kivity
ceb4778ad2 Merge branch 'log-exceptions' 2015-03-16 10:14:23 +02:00
Nadav Har'El
c0d7e4e748 core: implement future<> sleep()
Seastar applications obviously cannot use the Posix sleep() function, or
the entire thread will block. This patch implements future<> sleep(duration)
where as expected, the future becomes ready when the given duration passes.

For example, one can do:

    sleep(1s).then([] { std::cout << "Done.\n"; });

This can be useful as an example of futures and continuations in the
Seastar tutorial, and people might find other uses for it.

This sleep() is implemented in terms of timer<>. sleep() is easier to use
and more aligned with the rest of Seastar (it uses then() for the
continuation instead of a set_callback() method). The downside of sleep()
compared to a timer is that it cannot be canceled once started.

In this version, sleep() is implemented without shared_ptr, making the
implementation a tiny bit more efficient. There is still a heap allocation
(this is unavoidable because std::function requires a copyable type)
but no reference counting. Unfortunately, this requires us to use bare
"new" and "delete".

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-16 10:02:06 +02:00
Avi Kivity
facb2ffdc6 build: allow disabling debug info generation
Closes #37.
2015-03-16 07:53:54 +02:00
Avi Kivity
d2c0e485f8 posix: fix posix::recv return
Shuts up warning in gcc 5, and is aligned with the other methods.
2015-03-15 20:18:17 +02:00
Avi Kivity
24bc1b4126 build: improve seastar.pc generation
Generate at build time, so it gets rebuilt even if build/ is wiped out.
2015-03-15 18:13:29 +02:00
Nadav Har'El
25c37c92f5 core: fix engine_exit()
engine_exit() without a parameter is meant to do engine().exit(0).
We do this, but forget to return from this function, so after calling
engine().exit(0), it continued on and crashed.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-15 16:17:25 +02:00
Avi Kivity
f8c69904cd build: fix seastar.pc generation
Need to ensure the directory is there first.
2015-03-15 16:16:41 +02:00
Nadav Har'El
3578d3d016 build: make it easy to compile a Seastar-based project
This patch makes compiling a file "hello.cc" using seastar as simple as:

g++ `pkg-config --cflags --libs build/release/seastar.pc` hello.cc

Our current build system makes it very hard for users to build a project
*using* Seastar - basically requiring them to integrate their project into
the Seastar tree and its Makefile into our "ninja" framework.

This patch simplifies things considerably by doing two things:

First it builds an archive of all Seastar objects - build/$mode/libseastar.a.

But this in itself is not enough - the user wouldn't know how to use it
(currently, -Wl,--whole-archive is needed, unfortunately, because of reliance
of C++ static constructors), and will also need a long list of other
libraries, as wall as various definitions and include paths during compilation.

The solution is to use pkg-config, which has become the de-facto standard
method on Linux for makefiles to figure out how to compile with a certain
library. With this patch, someone can do this for example, to compile
tests/fileiotests.cc:

g++ `pkg-config --cflags --libs build/release/seastar.pc` tests/fileiotest.cc

Note how we have a different ".pc" file for each mode, with the appropriate
compile and link flags. A more eleborate example with separate compile and
link stages will use "pkg-config --cflags" on the compilation stage, and
"--libs" on the linking stage.

Eventually, we should have a "ninja install", which will install libseastar.a
and seastar.pc to their system-wide default location, and then the above
command line will become as simple as:

g++ `pkg-config --cflags --libs seastar` tests/fileiotest.cc

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-15 15:49:48 +02:00
Nadav Har'El
d1601b46f2 net: implement net::packed<> in terms of unaligned<>
The previous patch moved most of the functionality of net::packed<>
into a new template unaligned<> (in core/unaligned.hh). So in this
patch we implement net::packed<> in terms of unaligned<>. The former
is basically the same as the latter, with the addition of the
"adjust_endianness" feature that the networking code expects.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-15 15:45:14 +02:00
Nadav Har'El
1f8e0dbbab unaligned: new header file for unaligned access
This patch adds a new header file, "core/unaligned.hh", which defines a
new operation, unaligned_cast<T*>(p). This works exctly like
reinterpret_cast<T*>(p) except it is safe to use even when the address
of p is not a multiple of alignof(T).

A long comment in the header file explains why this unaligned_cast<>
is necessary on some esoteric architectures and to quiet gcc's
-fsanitize=alignment.

The header file also defines a new template for holding an unaligned
version of type - unaligned<T>. unaligned<T> is almost identical to our
existing net::packed<>, so the next patch will implement net::packed
in terms of unaligned<>.

The unaligned_cast<> and unaligned<> templates are of course generally
useful outside the network code, which is why I wanted them out of the
networking header files and namespace.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-15 15:44:56 +02:00
Avi Kivity
b968f80695 future: report abandoned failed futures
Report an abandoned future containing an exception, corresponding to
an uncaught exception in an ordinary program.
2015-03-15 15:44:08 +02:00
Avi Kivity
bd00d90806 Merge branch 'gleb/future' of github.com:cloudius-systems/seastar-dev
Future implementation cleanup, from Gleb.
2015-03-15 15:33:25 +02:00
Avi Kivity
d3acb5acc2 linecount: better error handling 2015-03-15 14:48:52 +02:00
Avi Kivity
0537a8ffe5 linecount: don't try to create the file.
It's read-only.
2015-03-15 14:48:31 +02:00
Gleb Natapov
c3ba8678e4 core: consolidate finally() implemetations 2015-03-15 14:44:58 +02:00