diff --git a/Cargo.lock b/Cargo.lock index f7faa7d..e214a92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,14 +5,14 @@ dependencies = [ "atomicwrites 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)", - "iron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "kite 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kite_rocksdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "maplit 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "persistent 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "roaring 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "router 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket_codegen 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket_contrib 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", "slog 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-term 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -60,6 +60,14 @@ dependencies = [ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "base64" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bitflags" version = "0.4.0" @@ -75,6 +83,11 @@ name = "byteorder" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "byteorder" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "cfg-if" version = "0.1.0" @@ -89,17 +102,9 @@ dependencies = [ "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "conduit-mime-types" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "cookie" -version = "0.2.5" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", @@ -133,15 +138,6 @@ name = "dtoa" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "error" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "error-chain" version = "0.2.2" @@ -158,14 +154,6 @@ dependencies = [ "rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "hpack" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "httparse" version = "1.2.1" @@ -173,19 +161,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hyper" -version = "0.9.18" +version = "0.10.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", - "solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", - "traitobject 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -201,23 +188,6 @@ dependencies = [ "unicode-normalization 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "iron" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "conduit-mime-types 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "error 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "modifier 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "isatty" version = "0.1.3" @@ -274,11 +244,6 @@ name = "language-tags" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "lazy_static" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "libc" version = "0.2.20" @@ -315,17 +280,20 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "mime" -version = "0.2.2" +name = "memchr" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "modifier" -version = "0.1.0" +name = "mime" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "nix" @@ -406,14 +374,6 @@ name = "num-traits" version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "num_cpus" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "num_cpus" version = "1.2.1" @@ -422,23 +382,6 @@ dependencies = [ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "persistent" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "iron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "plugin" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "quote" version = "0.3.15" @@ -477,26 +420,53 @@ dependencies = [ ] [[package]] -name = "rocksdb" -version = "0.6.1" +name = "rocket" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", - "librocksdb-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.10 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "state 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "term-painter 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "yansi 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "route-recognizer" -version = "0.1.11" +name = "rocket_codegen" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "yansi 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] -name = "router" -version = "0.2.0" +name = "rocket_contrib" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rocksdb" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "iron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "route-recognizer 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", + "librocksdb-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -579,13 +549,9 @@ dependencies = [ ] [[package]] -name = "solicit" -version = "0.4.4" +name = "state" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "hpack 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "syn" @@ -613,6 +579,23 @@ dependencies = [ "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "term" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "term-painter" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "term 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "time" version = "0.1.36" @@ -625,8 +608,8 @@ dependencies = [ ] [[package]] -name = "traitobject" -version = "0.0.1" +name = "toml" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -639,14 +622,6 @@ name = "typeable" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "typemap" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unsafe-any 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "unicase" version = "1.4.0" @@ -678,14 +653,6 @@ name = "unicode-xid" version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "unsafe-any" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "url" version = "1.4.0" @@ -703,6 +670,11 @@ dependencies = [ "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "version_check" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "void" version = "1.0.2" @@ -718,45 +690,47 @@ name = "winapi-build" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "yansi" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [metadata] "checksum ansi_term 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "30275ad0ad84ec1c06dde3b3f7d23c6006b7d76d61a85e7060b426b747eff70d" "checksum atomicwrites 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c4328d3fa4af4aedc582587976a0f74decc73f90ea7cae3d757c0535f983d16f" "checksum backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "346d7644f0b5f9bc73082d3b2236b69a05fd35cce0cfa3724e184e6a5c9e2a2f" "checksum backtrace-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a81b49c3aa114aa4d951a12d9e32e27809405c369efef2a75aac70efb1176fae" +"checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" "checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" +"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" "checksum chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9213f7cd7c27e95c2b57c49f0e69b1ea65b27138da84a170133fd21b07659c00" -"checksum conduit-mime-types 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "95ca30253581af809925ef68c2641cc140d6183f43e12e0af4992d53768bd7b8" -"checksum cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0e3d6405328b6edb412158b3b7710e2634e23f3614b9bb1c412df7952489a626" +"checksum cookie 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30b3493e12a550c2f96be785088d1da8d93189e7237c8a8d0d871bc9070334c3" "checksum crossbeam 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0c5ea215664ca264da8a9d9c3be80d2eaf30923c259d03e870388eb927508f97" "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" "checksum deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1614659040e711785ed8ea24219140654da1729f3ec8a47a9719d041112fe7bf" "checksum dtoa 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5edd69c67b2f8e0911629b7e6b8a34cb3956613cd7c6e6414966dee349c2db4f" -"checksum error 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "a6e606f14042bb87cc02ef6a14db6c90ab92ed6f62d87e69377bc759fd7987cc" "checksum error-chain 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9f138f617e9d48b8e36278b886a09b244faf77e6e72ed6cf77784ae2880752b" "checksum gcc 0.3.43 (registry+https://github.com/rust-lang/crates.io-index)" = "c07c758b972368e703a562686adb39125707cc1ef3399da8c019fc6c2498a75d" -"checksum hpack 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d2da7d3a34cf6406d9d700111b8eafafe9a251de41ae71d8052748259343b58" "checksum httparse 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a6e7a63e511f9edffbab707141fbb8707d1a3098615fb2adbd5769cdfcc9b17d" -"checksum hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)" = "1b9bf64f730d6ee4b0528a5f0a316363da9d8104318731509d4ccc86248f82b3" +"checksum hyper 0.10.10 (registry+https://github.com/rust-lang/crates.io-index)" = "36e108e0b1fa2d17491cbaac4bc460dc0956029d10ccf83c913dd0e5db3e7f07" "checksum idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1053236e00ce4f668aeca4a769a09b3bf5a682d802abd6f3cb39374f6b162c11" -"checksum iron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9fb1b2d809f84bf347e472d5758762b5c804e0c622970235f156d82673e4d334" "checksum isatty 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fa500db770a99afe2a0f2229be2a3d09c7ed9d7e4e8440bf71253141994e240f" "checksum itoa 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91fd9dc2c587067de817fec4ad355e3818c3d893a78cab32a0a474c7a15bb8d5" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum kite 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c220369dc57aec3f7528ddc4ce1e5844eba52bf2275c73f9da96b221b7e009ca" "checksum kite_rocksdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "27e521b0880605137ea3748fbc62007283c399b8a29a53aa086649ef069dee5e" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" -"checksum lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417" "checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5" "checksum librocksdb-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "de6d1da80770cac6d6b4a9bea6b3dad98aeb5ccabe0f5b4647781c61bcddf554" "checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054" "checksum make-cmd 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8ca8afbe8af1785e09636acb5a41e08a765f5f0340568716c18a8700ba3c0d3" "checksum maplit 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "be384c560e0c3ad868b590ffb88d2c0a1effde6f59885234e4ea811c1202bfea" "checksum matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efd7622e3022e1a6eaa602c4cea8912254e5582c9c692e9167714182244801b1" +"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" "checksum mime 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5c93a4bd787ddc6e7833c519b73a50883deb5863d76d9b71eb8216fb7f94e66" -"checksum modifier 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "41f5c9112cb662acd3b204077e0de5bc66305fa8df65c8019d5adb10e9ab6e58" "checksum nix 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0d95c5fa8b641c10ad0b8887454ebaafa3c92b5cd5350f8fc693adafd178e7b" "checksum num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "bde7c03b09e7c6a301ee81f6ddf66d7a28ec305699e3d3b056d2fc56470e3120" "checksum num-bigint 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "88b14378471f7c2adc5262f05b4701ef53e8da376453a8d8fee48e51db745e49" @@ -765,18 +739,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c" "checksum num-rational 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "54ff603b8334a72fbb27fe66948aac0abaaa40231b3cecd189e76162f6f38aaf" "checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c" -"checksum num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "cee7e88156f3f9e19bdd598f8d6c9db7bf4078f99f8381f43a55b09648d1a6e3" "checksum num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a225d1e2717567599c24f88e49f00856c6e825a12125181ee42c4257e3688d39" -"checksum persistent 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0c0aea7e6e026f9090c56aa7cda9d4ad6f182c717f0640cb03beace1f75a43d2" -"checksum plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a6a0dc3910bc8db877ffed8e457763b317cf880df4ae19109b9f77d277cf6e0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" "checksum rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50c575b58c2b109e2fbc181820cbe177474f35610ff9e357dc75f6bac854ffbf" "checksum redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd35cc9a8bdec562c757e3d43c1526b5c6d2653e23e2315065bc25556550753" "checksum roaring 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "49f087f5cff16d9cf1dda4ead1751b9f376717e857ac3137985cf0342eb24bad" +"checksum rocket 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3817ed527a346be15d3c4f97e791c7534ae9ddbe516b464644fd36bc9bd0bd47" +"checksum rocket_codegen 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ea317297ec507c56a95c9fe2a521f935216068495979816e9345d8e78e6be685" +"checksum rocket_contrib 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "7acc89f77714753d197f818bf27e1f4168d11acd2459e6c7649961f3de55284a" "checksum rocksdb 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6fcf135d961bde8008459803efcb50c6a688c11236869807b5f2e9d3ba88f8ff" -"checksum route-recognizer 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "4f0a750d020adb1978f5964ea7bca830585899b09da7cbb3f04961fc2400122d" -"checksum router 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff665ba113dc57ef54604ded19375c5ddd23ec44b550a3667c595205b5f98b42" "checksum rustc-demangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1430d286cadb237c17c885e25447c982c97113926bb579f4379c0eca8d9586dc" "checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b" "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" @@ -787,23 +759,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum serde_json 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cf37ce931677e98b4fa5e6469aaa3ab4b6228309ea33b1b22d3ec055adfc4515" "checksum slog 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bf6e3c7d56c5f03d81ea1e0713b7fd5b64ea69b9036d627c1c3a11c1fa039314" "checksum slog-term 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02b2ec893fc0eff72bbf20e3f568d2a46e65bd832aef11e8603817be64d2c539" -"checksum solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "172382bac9424588d7840732b250faeeef88942e37b6e35317dce98cafdd75b2" +"checksum state 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "70c8d8cb4ad5c5e81546ccc23bf48f4c8100568a9756f1a5f0ea7d1641576a0a" "checksum syn 0.11.9 (registry+https://github.com/rust-lang/crates.io-index)" = "480c834701caba3548aa991e54677281be3a5414a9d09ddbdf4ed74a569a9d19" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6" +"checksum term 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d168af3930b369cfe245132550579d47dfd873d69470755a19c2c6568dbbd989" +"checksum term-painter 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ab900bf2f05175932b13d4fc12f8ff09ef777715b04998791ab2c930841e496b" "checksum time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "211b63c112206356ef1ff9b19355f43740fc3f85960c598a93d3a3d3ba7beade" -"checksum traitobject 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "07eaeb7689bb7fca7ce15628319635758eda769fed481ecfe6686ddef2600616" +"checksum toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" -"checksum typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6" "checksum unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "13a5906ca2b98c799f4b1ab4557b76367ebd6ae5ef14930ec841c74aed5f3764" "checksum unicode-bidi 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b61814f3e7fd0e0f15370f767c7c943e08bc2e3214233ae8f88522b334ceb778" "checksum unicode-normalization 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5e94e9f6961090fcc75180629c4ef33e5310d6ed2c0dd173f4ca63c9043b669e" "checksum unicode-segmentation 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c3bc443ded17b11305ffffe6b37e2076f328a5a8cb6aa877b1b98f77699e98b5" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" -"checksum unsafe-any 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b351086021ebc264aea3ab4f94d61d889d98e5e9ec2d985d993f50133537fd3a" "checksum url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5ba8a749fb4479b043733416c244fa9d1d3af3d7c23804944651c8a448cb87e" "checksum uuid 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a9ff57156caf7e22f37baf3c9d8f6ce8194842c23419dafcb0716024514d162" +"checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" +"checksum yansi 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b731f15b7c13b4988f2836d88ce92b699c72dbc0178cf9d7c3ecad0d8fd1c902" diff --git a/Cargo.toml b/Cargo.toml index ab91569..79c8979 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,9 @@ path = "src/rusticsearch/main.rs" [dependencies] kite = "0.1.0" kite_rocksdb = "0.1.0" -iron = "0.4.0" -router = "0.2.0" -persistent = "0.2.0" +rocket = "0.2" +rocket_contrib = "0.2" +rocket_codegen = "0.2" url = "1.1.1" log = "0.3.6" unicode-segmentation = "0.1.2" diff --git a/src/rusticsearch/api/alias.rs b/src/rusticsearch/api/alias.rs new file mode 100644 index 0000000..79cbdc9 --- /dev/null +++ b/src/rusticsearch/api/alias.rs @@ -0,0 +1,90 @@ +use std::collections::HashMap; +use std::sync::Arc; + +use serde_json::Value; +use rocket::State; +use rocket_contrib::JSON; + +use system::System; + + +#[get("/_alias/")] +pub fn get_global(alias_name: &str, system: State>) -> Option> { + // Lock cluster metadata + let cluster_metadata = system.metadata.read().unwrap(); + + // Find alias + let mut found_aliases = HashMap::new(); + + for index_ref in cluster_metadata.names.find(alias_name) { + let index = match cluster_metadata.indices.get(&index_ref) { + Some(index) => index, + None => continue, + }; + + let mut inner_map = HashMap::new(); + let mut inner_inner_map = HashMap::new(); + inner_inner_map.insert(alias_name, HashMap::::new()); + inner_map.insert("aliases".to_owned(), inner_inner_map); + found_aliases.insert(index.canonical_name().clone(), inner_map); + } + + if !found_aliases.is_empty() { + Some(JSON(json!(found_aliases))) + } else { + None + } +} + + +#[allow(unused_variables)] +#[get("//_alias")] +pub fn get_list(index_name: &str, system: State>) -> JSON { + // TODO + + JSON(json!({})) +} + + +#[get("//_alias/")] +pub fn get(index_name: &str, alias_name: &str, system: State>) -> Option> { + // Lock cluster metadata + let cluster_metadata = system.metadata.read().unwrap(); + + // Get index + let index_ref = match cluster_metadata.names.find_canonical(index_name) { + Some(index_ref) => index_ref, + None => return None, + }; + + // Find alias + if cluster_metadata.names.iter_index_aliases(index_ref).any(|name| name == alias_name) { + Some(JSON(json!({}))) + } else { + None + } +} + + +#[put("//_alias/")] +pub fn put(index_selector: &str, alias_name: &str, system: State>) -> JSON { + // Lock cluster metadata + let mut cluster_metadata = system.metadata.write().unwrap(); + + // Insert alias into names registry + let index_refs = cluster_metadata.names.find(index_selector); + match cluster_metadata.names.insert_or_replace_alias(alias_name.to_string(), index_refs) { + Ok(true) => { + system.log.info("[api] created alias", b!("index" => index_selector, "alias" => alias_name)); + } + Ok(false) => { + system.log.info("[api] updated alias", b!("index" => index_selector, "alias" => alias_name)); + } + Err(_) => { + // TODO + return JSON(json!({"acknowledged": false})); + } + } + + JSON(json!({"acknowledged": true})) +} diff --git a/src/rusticsearch/api/alias_api.rs b/src/rusticsearch/api/alias_api.rs deleted file mode 100644 index e426f76..0000000 --- a/src/rusticsearch/api/alias_api.rs +++ /dev/null @@ -1,97 +0,0 @@ -use std::collections::HashMap; - -use api::persistent; -use api::iron::prelude::*; -use api::iron::status; -use api::router::Router; -use api::utils::json_response; - - -pub fn view_get_global_alias(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref alias_name = read_path_parameter!(req, "alias").unwrap_or(""); - - // Lock cluster metadata - let cluster_metadata = system.metadata.read().unwrap(); - - // Find alias - let mut found_aliases = HashMap::new(); - - for index_ref in cluster_metadata.names.find(alias_name) { - let index = match cluster_metadata.indices.get(&index_ref) { - Some(index) => index, - None => continue, - }; - - let mut inner_map = HashMap::new(); - let mut inner_inner_map = HashMap::new(); - inner_inner_map.insert(alias_name, HashMap::::new()); - inner_map.insert("aliases".to_owned(), inner_inner_map); - found_aliases.insert(index.canonical_name().clone(), inner_map); - } - - if !found_aliases.is_empty() { - return Ok(json_response(status::Ok, json!(found_aliases))); - } else { - return Ok(json_response(status::NotFound, json!({}))); - } -} - - -pub fn view_get_alias_list(_req: &mut Request) -> IronResult { - // let ref system = get_system!(req); - // let ref index_name = read_path_parameter!(req, "index").unwrap_or(""); - - // TODO - - return Ok(json_response(status::Ok, json!({}))); -} - -pub fn view_get_alias(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref index_name = read_path_parameter!(req, "index").unwrap_or(""); - let ref alias_name = read_path_parameter!(req, "alias").unwrap_or(""); - - // Lock cluster metadata - let cluster_metadata = system.metadata.read().unwrap(); - - // Get index - let index_ref = match cluster_metadata.names.find_canonical(index_name) { - Some(index_ref) => index_ref, - None => return Ok(json_response(status::NotFound, json!({}))), - }; - - // Find alias - if cluster_metadata.names.iter_index_aliases(index_ref).any(|name| &name == alias_name) { - return Ok(json_response(status::Ok, json!({}))); - } else { - return Ok(json_response(status::NotFound, json!({}))); - } -} - - -pub fn view_put_alias(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref index_selector = read_path_parameter!(req, "index").unwrap_or(""); - let ref alias_name = read_path_parameter!(req, "alias").unwrap_or(""); - - // Lock cluster metadata - let mut cluster_metadata = system.metadata.write().unwrap(); - - // Insert alias into names registry - let index_refs = cluster_metadata.names.find(*index_selector); - match cluster_metadata.names.insert_or_replace_alias(alias_name.to_string(), index_refs) { - Ok(true) => { - system.log.info("[api] created alias", b!("index" => *index_selector, "alias" => *alias_name)); - } - Ok(false) => { - system.log.info("[api] updated alias", b!("index" => *index_selector, "alias" => *alias_name)); - } - Err(_) => { - // TODO - return Ok(json_response(status::Ok, json!({"acknowledged": false}))); - } - } - - Ok(json_response(status::Ok, json!({"acknowledged": true}))) -} diff --git a/src/rusticsearch/api/bulk_api.rs b/src/rusticsearch/api/bulk.rs similarity index 72% rename from src/rusticsearch/api/bulk_api.rs rename to src/rusticsearch/api/bulk.rs index e45d4c2..81c69bd 100644 --- a/src/rusticsearch/api/bulk_api.rs +++ b/src/rusticsearch/api/bulk.rs @@ -5,21 +5,24 @@ use serde_json; use document::DocumentSource; -use api::persistent; -use api::iron::prelude::*; -use api::iron::status; -use api::utils::{json_response}; +use std::sync::Arc; +use serde_json::Value; +use rocket::State; +use rocket::Data; +use rocket_contrib::JSON; -pub fn view_post_bulk(req: &mut Request) -> IronResult { - let ref system = get_system!(req); +use system::System; + +#[post("/_bulk", data = "")] +pub fn bulk(data: Data, system: State>) -> Option> { // Lock cluster metedata let cluster_metadata = system.metadata.read().unwrap(); // Load data from body let mut payload = String::new(); - req.body.read_to_string(&mut payload).unwrap(); + data.open().read_to_string(&mut payload).unwrap(); let mut items = Vec::new(); @@ -34,7 +37,13 @@ pub fn view_post_bulk(req: &mut Request) -> IronResult { } // Parse action line - let action_json = parse_json!(&action_line.unwrap()); + let action_json: Value = match serde_json::from_str(&action_line.unwrap()) { + Ok(data) => data, + Err(_) => { + // TODO: Don't stop the bulk upload here + return None; + } + }; // Check action // Action should be an object with only one key, the key name indicates the action and @@ -54,7 +63,13 @@ pub fn view_post_bulk(req: &mut Request) -> IronResult { match action_name.as_ref() { "index" => { let doc_line = payload_lines.next(); - let doc_json = parse_json!(&doc_line.unwrap());; + let doc_json: Value = match serde_json::from_str(&doc_line.unwrap()) { + Ok(data) => data, + Err(_) => { + // TODO: Don't stop the bulk upload here + return None; + } + }; // Find index let index = get_index_or_404!(cluster_metadata, doc_index); @@ -65,7 +80,8 @@ pub fn view_post_bulk(req: &mut Request) -> IronResult { let mapping = match index_metadata.mappings.get(doc_type) { Some(mapping) => mapping, None => { - return Ok(json_response(status::NotFound, json!({"message": "Mapping not found"}))); + // TODO: Don't stop the bulk upload here + return None; } }; @@ -91,9 +107,8 @@ pub fn view_post_bulk(req: &mut Request) -> IronResult { } } - return Ok(json_response(status::Ok, - json!({ - "took": items.len(), - "items": items, - }))); + Some(JSON(json!({ + "took": items.len(), + "items": items, + }))) } diff --git a/src/rusticsearch/api/document.rs b/src/rusticsearch/api/document.rs new file mode 100644 index 0000000..fb0ac89 --- /dev/null +++ b/src/rusticsearch/api/document.rs @@ -0,0 +1,99 @@ +use std::sync::Arc; + +use serde_json::Value; +use rocket::State; +use rocket_contrib::JSON; + +use system::System; +use document::DocumentSource; + + +#[allow(unused_variables)] +#[get("///")] +pub fn get(index_name: &str, mapping_name: &str, doc_key: &str, system: State>) -> Option> { + // Get index + let cluster_metadata = system.metadata.read().unwrap(); + let index = get_index_or_404!(cluster_metadata, index_name); + let index_metadata = index.metadata.read().unwrap(); + + // Check that the mapping exists + if !index_metadata.mappings.contains_key(mapping_name) { + return None; + } + + // Find document + /* + let index_reader = index.store.reader(); + let doc = match index_reader.get_document_by_key(doc_key) { + Some(doc) => doc, + None => { + return Ok(json_response(status::NotFound, "{\"message\": \"Document not found\"}")); + } + }; + */ + + + // Build JSON document + // TODO: This is probably completely wrong + // let json_object = BTreeMap::new(); + // FIXME: for (field_name, field_value) in doc.fields.iter() { + // FIXME: json_object.insert(field_name.clone(), Json::Array(field_value.iter().map(|v| v.term.as_json()).collect::>())); + // FIXME: } + + Some(JSON(json!({}))) +} + + +#[put("///", data = "")] +pub fn put(index_name: &str, mapping_name: &str, doc_key: &str, data: JSON, system: State>) -> Option> { + // Get index + let cluster_metadata = system.metadata.read().unwrap(); + let index = get_index_or_404!(cluster_metadata, index_name); + let index_metadata = index.metadata.read().unwrap(); + + let doc = { + // Find mapping + let mapping = match index_metadata.mappings.get(mapping_name) { + Some(mapping) => mapping, + None => { + return None; + } + }; + + // Create document + let document_source = DocumentSource { + key: doc_key, + data: data.as_object().unwrap(), + }; + document_source.prepare(mapping).unwrap() + }; + + index.store.insert_or_update_document(&doc).unwrap(); + + // TODO: {"_index":"wagtail","_type":"searchtests_searchtest","_id":"searchtests_searchtest:5378","_version":1,"created":true} + Some(JSON(json!({}))) +} + + +#[delete("///")] +pub fn delete(index_name: &str, mapping_name: &str, doc_key: &str, system: State>) -> Option> { + // Get index + let cluster_metadata = system.metadata.read().unwrap(); + let index = get_index_or_404!(cluster_metadata, index_name); + let index_metadata = index.metadata.read().unwrap(); + + // Check that the mapping exists + if !index_metadata.mappings.contains_key(mapping_name) { + return None; + } + + // Make sure the document exists + if !index.store.reader().contains_document_key(doc_key) { + return None; + } + + // Delete document + index.store.remove_document_by_key(doc_key).unwrap(); + + Some(JSON(json!({}))) +} diff --git a/src/rusticsearch/api/document_api.rs b/src/rusticsearch/api/document_api.rs deleted file mode 100644 index 0226162..0000000 --- a/src/rusticsearch/api/document_api.rs +++ /dev/null @@ -1,117 +0,0 @@ -use std::io::Read; - -use serde_json; - -use document::DocumentSource; - -use api::persistent; -use api::iron::prelude::*; -use api::iron::status; -use api::router::Router; -use api::utils::json_response; - - -pub fn view_get_doc(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref index_name = read_path_parameter!(req, "index").unwrap_or(""); - let ref mapping_name = read_path_parameter!(req, "mapping").unwrap_or(""); - // let ref doc_key = read_path_parameter!(req, "doc").unwrap_or(""); - - // Get index - let cluster_metadata = system.metadata.read().unwrap(); - let index = get_index_or_404!(cluster_metadata, *index_name); - let index_metadata = index.metadata.read().unwrap(); - - // Check that the mapping exists - if !index_metadata.mappings.contains_key(*mapping_name) { - return Ok(json_response(status::NotFound, json!({"message": "Mapping not found"}))); - } - - // Find document - /* - let index_reader = index.store.reader(); - let doc = match index_reader.get_document_by_key(doc_key) { - Some(doc) => doc, - None => { - return Ok(json_response(status::NotFound, "{\"message\": \"Document not found\"}")); - } - }; - */ - - - // Build JSON document - // TODO: This is probably completely wrong - // let json_object = BTreeMap::new(); - // FIXME: for (field_name, field_value) in doc.fields.iter() { - // FIXME: json_object.insert(field_name.clone(), Json::Array(field_value.iter().map(|v| v.term.as_json()).collect::>())); - // FIXME: } - - return Ok(json_response(status::Ok, json!({}))); -} - - -pub fn view_put_doc(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref index_name = read_path_parameter!(req, "index").unwrap_or(""); - let ref mapping_name = read_path_parameter!(req, "mapping").unwrap_or(""); - let ref doc_key = read_path_parameter!(req, "doc").unwrap_or(""); - - // Get index - let cluster_metadata = system.metadata.read().unwrap(); - let index = get_index_or_404!(cluster_metadata, *index_name); - let index_metadata = index.metadata.read().unwrap(); - - let doc = { - // Find mapping - let mapping = match index_metadata.mappings.get(*mapping_name) { - Some(mapping) => mapping, - None => { - return Ok(json_response(status::NotFound, json!({"message": "Mapping not found"}))); - } - }; - - // Create document - if let Some(data) = json_from_request_body!(req) { - let document_source = DocumentSource { - key: doc_key, - data: data.as_object().unwrap(), - }; - document_source.prepare(mapping).unwrap() - } else { - return Ok(json_response(status::NotFound, json!({"message": "No data"}))); - } - }; - - index.store.insert_or_update_document(&doc).unwrap(); - - // TODO: {"_index":"wagtail","_type":"searchtests_searchtest","_id":"searchtests_searchtest:5378","_version":1,"created":true} - return Ok(json_response(status::Ok, json!({}))); -} - - -pub fn view_delete_doc(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref index_name = read_path_parameter!(req, "index").unwrap_or(""); - let ref mapping_name = read_path_parameter!(req, "mapping").unwrap_or(""); - let ref doc_key = read_path_parameter!(req, "doc").unwrap_or(""); - - // Get index - let cluster_metadata = system.metadata.read().unwrap(); - let index = get_index_or_404!(cluster_metadata, *index_name); - let index_metadata = index.metadata.read().unwrap(); - - // Check that the mapping exists - if !index_metadata.mappings.contains_key(*mapping_name) { - return Ok(json_response(status::NotFound, json!({"message": "Mapping not found"}))); - } - - // Make sure the document exists - if !index.store.reader().contains_document_key(doc_key) { - return Ok(json_response(status::NotFound, json!({"message": "Document not found"}))); - } - - // Delete document - index.store.remove_document_by_key(doc_key).unwrap(); - - return Ok(json_response(status::Ok, json!({}))); -} diff --git a/src/rusticsearch/api/index_api.rs b/src/rusticsearch/api/index.rs similarity index 67% rename from src/rusticsearch/api/index_api.rs rename to src/rusticsearch/api/index.rs index 6576ba2..22a6d5b 100644 --- a/src/rusticsearch/api/index_api.rs +++ b/src/rusticsearch/api/index.rs @@ -1,29 +1,24 @@ use std::fs; -use std::io::Read; +use std::sync::Arc; -use serde_json; +use serde_json::Value; use serde_json::value::ToJson; use kite_rocksdb::RocksDBIndexStore; use uuid::Uuid; +use rocket::State; +use rocket_contrib::JSON; +use system::System; use index::Index; use index::metadata::IndexMetadata; use index::metadata::parse::parse as parse_index_metadata; -use api::persistent; -use api::iron::prelude::*; -use api::iron::status; -use api::router::Router; -use api::utils::json_response; - - -pub fn view_get_index(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref index_name = read_path_parameter!(req, "index").unwrap_or(""); +#[get("/")] +pub fn get(index_name: &str, system: State>) -> Option> { // Get index let cluster_metadata = system.metadata.read().unwrap(); - let index = get_index_or_404!(cluster_metadata, *index_name); + let index = get_index_or_404!(cluster_metadata, index_name); // Serialise index metadata let json = { @@ -31,21 +26,17 @@ pub fn view_get_index(req: &mut Request) -> IronResult { match index_metadata.to_json() { Ok(json) => json, Err(_) => { - return Ok(json_response(status::InternalServerError, json!({ - "message": "unable to serialise index metadata" - }))); + return Some(JSON(json!({"message": "unable to serialise index metadata"}))); // TODO 500 error } } }; - return Ok(json_response(status::Ok, json)); + Some(JSON(json)) } -pub fn view_put_index(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref index_name = read_path_parameter!(req, "index").unwrap_or(""); - +#[put("/", data = "")] +pub fn put(index_name: &str, data: JSON, system: State>) -> JSON { // Lock cluster metadata let mut cluster_metadata = system.metadata.write().unwrap(); @@ -57,16 +48,16 @@ pub fn view_put_index(req: &mut Request) -> IronResult { // Update existing index // TODO - system.log.info("[api] updated index", b!("index" => *index_name)); + system.log.info("[api] updated index", b!("index" => index_name)); } None => { // Load metadata let mut metadata = IndexMetadata::default(); - match json_from_request_body!(req).map(|data| parse_index_metadata(&mut metadata, data)) { - Some(Ok(())) | None => {} - Some(Err(_)) => { - // TODO: better error - return Ok(json_response(status::BadRequest, json!({"message": "Couldn't parse index settings"}))); + + match parse_index_metadata(&mut metadata, data.into_inner()) { + Ok(()) => {} + Err(_) => { + return JSON(json!({"message": "Couldn't parse index settings"})); // TODO 400 error } } @@ -86,26 +77,24 @@ pub fn view_put_index(req: &mut Request) -> IronResult { // Register canonical name cluster_metadata.names.insert_canonical(index_name.clone().to_owned(), index_ref).unwrap(); - system.log.info("[api] created index", b!("index" => *index_name)); + system.log.info("[api] created index", b!("index" => index_name)); } } - return Ok(json_response(status::Ok, json!({"acknowledged": true}))); + JSON(json!({"acknowledged": true})) } -pub fn view_delete_index(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref index_selector = read_path_parameter!(req, "index").unwrap_or(""); - +#[delete("/")] +pub fn delete(index_selector: &str, system: State>) -> Option> { // Lock cluster metadata let mut cluster_metadata = system.metadata.write().unwrap(); // Make sure the index exists - get_index_or_404!(cluster_metadata, *index_selector); + get_index_or_404!(cluster_metadata, index_selector); // Remove indices - for index_ref in cluster_metadata.names.find(*index_selector) { + for index_ref in cluster_metadata.names.find(index_selector) { // Get the index name let index_name = { if let Some(index) = cluster_metadata.indices.get(&index_ref) { @@ -146,18 +135,17 @@ pub fn view_delete_index(req: &mut Request) -> IronResult { } } - return Ok(json_response(status::Ok, json!({"acknowledged": true}))); + Some(JSON(json!({"acknowledged": true}))) } -pub fn view_post_refresh_index(_req: &mut Request) -> IronResult { - // let ref system = get_system!(req); - // let ref index_name = read_path_parameter!(req, "index").unwrap_or(""); - +#[allow(unused_variables)] +#[post("//_refresh")] +pub fn refresh(index_name: &str) -> Option> { // Lock index array // TODO // let mut indices = system.indices.write().unwrap(); // TODO: {"_shards":{"total":10,"successful":5,"failed":0}} - return Ok(json_response(status::Ok, json!({"acknowledged": true}))); + Some(JSON(json!({"acknowledged": true}))) } diff --git a/src/rusticsearch/api/mapping_api.rs b/src/rusticsearch/api/mapping.rs similarity index 68% rename from src/rusticsearch/api/mapping_api.rs rename to src/rusticsearch/api/mapping.rs index 97fc37b..4926ef1 100644 --- a/src/rusticsearch/api/mapping_api.rs +++ b/src/rusticsearch/api/mapping.rs @@ -1,55 +1,38 @@ -use std::io::Read; use std::collections::HashMap; +use std::sync::Arc; -use serde_json; use kite::schema::{FieldType, FieldFlags, FIELD_INDEXED, FIELD_STORED}; +use serde_json::Value; +use rocket::State; +use rocket_contrib::JSON; +use system::System; use mapping::{self, MappingProperty}; use mapping::parse::parse as parse_mapping; -use api::persistent; -use api::iron::prelude::*; -use api::iron::status; -use api::router::Router; -use api::utils::json_response; - - -pub fn view_put_mapping(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref index_name = read_path_parameter!(req, "index").unwrap_or(""); - let ref mapping_name = read_path_parameter!(req, "mapping").unwrap_or(""); +#[put("//_mapping/", data = "")] +pub fn put(index_name: &str, mapping_name: &str, data: JSON, system: State>) -> Option> { // Lock cluster metadata let mut cluster_metadata = system.metadata.write().unwrap(); // Get index - let mut index = get_index_or_404_mut!(cluster_metadata, *index_name); - - // Load data from body - let data = json_from_request_body!(req); - - let data = match data { - Some(data) => data, - None => { - // TODO: Better error - return Ok(json_response(status::BadRequest, json!({"acknowledged": false}))); - } - }; + let mut index = get_index_or_404_mut!(cluster_metadata, index_name); - let data = data.as_object().unwrap().get(*mapping_name).unwrap(); + let data = data.as_object().unwrap().get(mapping_name).unwrap(); // Insert mapping let mapping_builder = match parse_mapping(&data) { Ok(mapping_builder) => mapping_builder, Err(_) => { // TODO: Better error - return Ok(json_response(status::BadRequest, json!({"acknowledged": false}))); + return Some(JSON(json!({"acknowledged": false}))); // TODO 400 error } }; let mut index_metadata = index.metadata.write().unwrap(); let mut mapping = mapping_builder.build(&index_metadata); debug!("{:#?}", mapping); - let is_updating = index_metadata.mappings.contains_key(*mapping_name); + let is_updating = index_metadata.mappings.contains_key(mapping_name); // Find list of new fields that need to be added to the store let new_fields = { @@ -86,7 +69,7 @@ pub fn view_put_mapping(req: &mut Request) -> IronResult { } else { // Conflict! // TODO: Better error - return Ok(json_response(status::BadRequest, json!({"acknowledged": false}))); + return Some(JSON(json!({"acknowledged": false}))); // TODO 400 error } } @@ -101,7 +84,7 @@ pub fn view_put_mapping(req: &mut Request) -> IronResult { for (field_name, (field_type, field_flags)) in new_fields { let indexed_yesno = if field_flags.contains(FIELD_INDEXED) { "yes" } else { "no" }; let stored_yesno = if field_flags.contains(FIELD_STORED) { "yes" } else { "no" }; - system.log.info("[api] adding field", b!("index" => *index_name, "field" => field_name, "type" => format!("{:?}", field_type), "indexed" => indexed_yesno, "stored" => stored_yesno)); + system.log.info("[api] adding field", b!("index" => index_name, "field" => field_name, "type" => format!("{:?}", field_type), "indexed" => indexed_yesno, "stored" => stored_yesno)); index.store.add_field(field_name, field_type, field_flags).unwrap(); } @@ -123,10 +106,10 @@ pub fn view_put_mapping(req: &mut Request) -> IronResult { if is_updating { // TODO: New mapping should be merged with existing one - system.log.info("[api] updated mapping", b!("index" => *index_name, "mapping" => *mapping_name)); + system.log.info("[api] updated mapping", b!("index" => index_name, "mapping" => mapping_name)); } else { - system.log.info("[api] created mapping", b!("index" => *index_name, "mapping" => *mapping_name)); + system.log.info("[api] created mapping", b!("index" => index_name, "mapping" => mapping_name)); } - return Ok(json_response(status::Ok, json!({"acknowledged": true}))); + Some(JSON(json!({"acknowledged": true}))) } diff --git a/src/rusticsearch/api/mod.rs b/src/rusticsearch/api/mod.rs index 929ceb2..0b121da 100644 --- a/src/rusticsearch/api/mod.rs +++ b/src/rusticsearch/api/mod.rs @@ -1,89 +1,60 @@ -extern crate iron; -extern crate router; -extern crate persistent; - -#[macro_use] -mod utils; -mod search_api; -mod alias_api; -mod document_api; -mod index_api; -mod mapping_api; -mod bulk_api; +#[macro_use] mod utils; +mod index; +mod alias; +mod mapping; +mod document; +mod bulk; +mod search; use std::sync::Arc; -use api::iron::prelude::*; -use api::iron::status; -use api::iron::typemap::Key; -use api::router::Router; -use api::utils::json_response; +use serde_json::Value; + +use rocket; +use rocket::config::{ConfigBuilder, Environment}; +use rocket_contrib::JSON; -use system::System; use VERSION; +use system::System; -fn view_home(_: &mut Request) -> IronResult { - Ok(json_response(status::Ok, json!({ +#[get("/")] +fn root() -> JSON { + JSON(json!({ "cluster_name": "rusticsearch", "version": { "number": VERSION } - }))) -} - - -fn get_router() -> Router { - router!(get "/" => view_home, - get "/:index/_count" => search_api::view_count, - post "/:index/_count" => search_api::view_count, - get "/:index/_search" => search_api::view_search, - post "/:index/_search" => search_api::view_search, - get "/_alias/:alias" => alias_api::view_get_global_alias, - get "/:index/_alias" => alias_api::view_get_alias_list, - get "/:index/_alias/:alias" => alias_api::view_get_alias, - put "/:index/_alias/:alias" => alias_api::view_put_alias, - get "/:index/:mapping/:doc" => document_api::view_get_doc, - put "/:index/:mapping/:doc" => document_api::view_put_doc, - delete "/:index/:mapping/:doc" => document_api::view_delete_doc, - get "/:index" => index_api::view_get_index, - put "/:index" => index_api::view_put_index, - delete "/:index" => index_api::view_delete_index, - post "/:index/_refresh" => index_api::view_post_refresh_index, - put "/:index/_mapping/:mapping" => mapping_api::view_put_mapping, - post "/_bulk" => bulk_api::view_post_bulk) -} - - -// The "Context" struct just wraps Arc so we can put it into chain.link() -// Workaround for: https://github.com/iron/persistent/issues/55 - -struct Context { - system: Arc, -} - - -impl Context { - fn new(system: Arc) -> Context { - Context { - system: system, - } - } -} - - -impl Key for Context { - type Value = Context; + })) } pub fn api_main(system: Arc) { - let router = get_router(); - let mut chain = Chain::new(router); - chain.link(persistent::Read::::both(Context::new(system.clone()))); - system.log.info("[api] listening", b!("scheme" => "http", "address" => "localhost", "port" => 9200)); - - if let Err(error) = Iron::new(chain).http("localhost:9200") { - system.log.critical("[api] unable to start api server", b!("error" => format!("{}", error))); - } + let config = ConfigBuilder::new(Environment::Development) + .address("127.0.0.1") + .port(9200) + .workers(4) + .finalize() + .unwrap(); + rocket::custom(config, true) + .mount("/", routes![ + root, + index::get, + index::put, + index::delete, + index::refresh, + alias::get_global, + alias::get_list, + alias::get, + alias::put, + mapping::put, + document::get, + document::put, + document::delete, + bulk::bulk, + search::count, + search::search, + ]) + .manage(system) + .launch(); } diff --git a/src/rusticsearch/api/search.rs b/src/rusticsearch/api/search.rs new file mode 100644 index 0000000..19798d2 --- /dev/null +++ b/src/rusticsearch/api/search.rs @@ -0,0 +1,139 @@ +use std::collections::BTreeMap; +use std::sync::Arc; + +use serde_json::Value; +use rocket::State; +use rocket_contrib::JSON; +use kite::document::DocRef; +use kite::collectors::top_score::TopScoreCollector; +use kite::collectors::total_count::TotalCountCollector; + +use system::System; +use query_parser::{QueryBuildContext, parse as parse_query}; + + +#[post("//_count", data = "")] +pub fn count(index_name: &str, query_json: JSON, system: State>) -> Option> { + // Get index + let cluster_metadata = system.metadata.read().unwrap(); + let index = get_index_or_404!(cluster_metadata, index_name); + let index_reader = index.store.reader(); + let index_metadata = index.metadata.read().unwrap(); + + let count = { + // Parse query + let query = parse_query(query_json.as_object().unwrap().get("query").unwrap()); + debug!("{:#?}", query); + + match query { + Ok(query) => { + let mut collector = TotalCountCollector::new(); + index_reader.search(&mut collector, &query.build(&QueryBuildContext::new().set_index_metadata(&index_metadata).no_score(), &index_reader.schema())).unwrap(); + collector.get_total_count() + } + Err(_) => { + // TODO: What specifically is bad about the Query? + return Some(JSON(json!({"message": "Query error"}))); // TODO 400 error + } + } + }; + + Some(JSON(json!({"count": count}))) +} + + +#[derive(Debug, FromForm)] +pub struct SearchParams { + pub from: usize, + pub size: usize, + pub fields: Option, + // terminate_after + // explain + // version + // timeout + // fielddata_fields + // track_scores + // stats + // suggest_field +} + +impl Default for SearchParams { + fn default() -> SearchParams { + SearchParams { + from: 0, + size: 10, + fields: None, + } + } +} + + +#[post("//_search?", data = "")] +pub fn search(index_name: &str, params: SearchParams, query_json: JSON, system: State>) -> Option> { + // Get index + let cluster_metadata = system.metadata.read().unwrap(); + let index = get_index_or_404!(cluster_metadata, index_name); + let index_reader = index.store.reader(); + let index_metadata = index.metadata.read().unwrap(); + + // Parse query + let query = parse_query(query_json.as_object().unwrap().get("query").unwrap()); + debug!("{:#?}", query); + + match query { + Ok(query) => { + let mut fields = Vec::new(); + if let Some(value) = params.fields { + for field_name in value.split(",") { + let field_ref = match index_reader.schema().get_field_by_name(field_name) { + Some(field_ref) => field_ref, + None => { + warn!("unknown field {:?}", field_name); + continue; + } + }; + + fields.push((field_name.to_owned(), field_ref)); + } + } + + + // Do the search + let mut collector = TopScoreCollector::new(params.from + params.size); + index_reader.search(&mut collector, &query.build(&QueryBuildContext::new().set_index_metadata(&index_metadata), &index_reader.schema())).unwrap(); + + // Convert hits into JSON + let mut hits = Vec::new(); + for doc_match in collector.into_sorted_vec().iter().skip(params.from) { + let mut field_values = BTreeMap::new(); + + for &(ref field_name, field_ref) in fields.iter() { + let value = match index_reader.read_stored_field(field_ref, DocRef::from_u64(doc_match.doc_id())) { + Ok(Some(value)) => vec![value], + Ok(None) => vec![], + Err(_) => vec![], + }; + + field_values.insert(field_name.clone(), value); + } + + hits.push(json!({ + "_score": doc_match.score().unwrap(), + "fields": field_values, + })); + } + + // TODO: {"took":5,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":4,"max_score":1.0,"hits":[{"_index":"wagtail","_type":"searchtests_searchtest_searchtests_searchtestchild","_id":"searchtests_searchtest:5380","_score":1.0,"fields":{"pk":["5380"]}},{"_index":"wagtail","_type":"searchtests_searchtest","_id":"searchtests_searchtest:5379","_score":1.0,"fields":{"pk":["5379"]}}]}} + Some(JSON(json!({ + "hits": { + "total": hits.len(), + "hits": hits + } + }))) + } + Err(_) => { + // TODO: What specifically is bad about the Query? + Some(JSON(json!({"message": "Query error"}))) // TODO 400 error + } + } +} diff --git a/src/rusticsearch/api/search_api.rs b/src/rusticsearch/api/search_api.rs deleted file mode 100644 index 63b9ba8..0000000 --- a/src/rusticsearch/api/search_api.rs +++ /dev/null @@ -1,164 +0,0 @@ -use std::io::Read; -use std::collections::BTreeMap; - -use serde_json; -use url::form_urlencoded; -use kite::document::DocRef; -use kite::query::Query; -use kite::collectors::top_score::TopScoreCollector; -use kite::collectors::total_count::TotalCountCollector; - -use query_parser::{QueryBuildContext, parse as parse_query}; - -use api::persistent; -use api::iron::prelude::*; -use api::iron::status; -use api::router::Router; -use api::utils::json_response; - - -pub fn view_count(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref index_name = read_path_parameter!(req, "index").unwrap_or(""); - - // Get index - let cluster_metadata = system.metadata.read().unwrap(); - let index = get_index_or_404!(cluster_metadata, *index_name); - let index_reader = index.store.reader(); - let index_metadata = index.metadata.read().unwrap(); - - let count = match json_from_request_body!(req) { - Some(query_json) => { - // Parse query - let query = parse_query(query_json.as_object().unwrap().get("query").unwrap()); - debug!("{:#?}", query); - - match query { - Ok(query) => { - let mut collector = TotalCountCollector::new(); - index_reader.search(&mut collector, &query.build(&QueryBuildContext::new().set_index_metadata(&index_metadata).no_score(), &index_reader.schema())).unwrap(); - collector.get_total_count() - } - Err(_) => { - // TODO: What specifically is bad about the Query? - let mut response = Response::with((status::BadRequest, - "{\"message\": \"Query error\"}")); - response.headers.set_raw("Content-Type", vec![b"application/json".to_vec()]); - return Ok(response); - } - } - } - None => { - let mut collector = TotalCountCollector::new(); - index_reader.search(&mut collector, &Query::new_all()).unwrap(); - collector.get_total_count() - } - }; - - return Ok(json_response(status::Ok, json!({"count": count}))); -} - - -pub fn view_search(req: &mut Request) -> IronResult { - let ref system = get_system!(req); - let ref index_name = read_path_parameter!(req, "index").unwrap_or(""); - - // Get index - let cluster_metadata = system.metadata.read().unwrap(); - let index = get_index_or_404!(cluster_metadata, *index_name); - let index_reader = index.store.reader(); - let index_metadata = index.metadata.read().unwrap(); - - match json_from_request_body!(req) { - Some(query_json) => { - // Parse query - let query = parse_query(query_json.as_object().unwrap().get("query").unwrap()); - debug!("{:#?}", query); - - match query { - Ok(query) => { - let mut from = 0; - let mut size = 10; - let mut fields = Vec::new(); - - // TODO: Rewrite this - if let Some(ref url_query) = req.url.query() { - for (key, value) in form_urlencoded::parse(url_query.as_bytes()) { - match key.as_ref() { - "from" => { - from = value.as_ref().parse().expect("need a number"); - } - "size" => { - size = value.as_ref().parse().expect("need a number"); - } - "fields" => { - for field_name in value.split(",") { - let field_ref = match index_reader.schema().get_field_by_name(field_name) { - Some(field_ref) => field_ref, - None => { - warn!("unknown field {:?}", field_name); - continue; - } - }; - - fields.push((field_name.to_owned(), field_ref)); - } - } - // terminate_after - // explain - // version - // timeout - // fielddata_fields - // track_scores - // stats - // suggest_field - _ => warn!("unrecognised GET parameter {:?}", key), - } - } - } - - // Do the search - let mut collector = TopScoreCollector::new(from + size); - index_reader.search(&mut collector, &query.build(&QueryBuildContext::new().set_index_metadata(&index_metadata), &index_reader.schema())).unwrap(); - - // Convert hits into JSON - let mut hits = Vec::new(); - for doc_match in collector.into_sorted_vec().iter().skip(from) { - let mut field_values = BTreeMap::new(); - - for &(ref field_name, field_ref) in fields.iter() { - let value = match index_reader.read_stored_field(field_ref, DocRef::from_u64(doc_match.doc_id())) { - Ok(Some(value)) => vec![value], - Ok(None) => vec![], - Err(_) => vec![], - }; - - field_values.insert(field_name.clone(), value); - } - - hits.push(json!({ - "_score": doc_match.score().unwrap(), - "fields": field_values, - })); - } - - // TODO: {"took":5,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":4,"max_score":1.0,"hits":[{"_index":"wagtail","_type":"searchtests_searchtest_searchtests_searchtestchild","_id":"searchtests_searchtest:5380","_score":1.0,"fields":{"pk":["5380"]}},{"_index":"wagtail","_type":"searchtests_searchtest","_id":"searchtests_searchtest:5379","_score":1.0,"fields":{"pk":["5379"]}}]}} - Ok(json_response(status::Ok, - json!({ - "hits": { - "total": hits.len(), - "hits": hits - }}))) - } - Err(_) => { - // TODO: What specifically is bad about the Query? - let mut response = Response::with((status::BadRequest, - "{\"message\": \"Query error\"}")); - response.headers.set_raw("Content-Type", vec![b"application/json".to_vec()]); - Ok(response) - } - } - } - None => Ok(json_response(status::BadRequest, json!({"message": "Missing query"}))), - } -} diff --git a/src/rusticsearch/api/utils.rs b/src/rusticsearch/api/utils.rs index 94a9c7d..9e2556e 100644 --- a/src/rusticsearch/api/utils.rs +++ b/src/rusticsearch/api/utils.rs @@ -1,52 +1,16 @@ -use serde_json; - -use api::iron::prelude::*; -use api::iron::status; - - -macro_rules! get_system { - ($req: expr) => {{ - use api::Context; - - $req.get::>().unwrap().system.clone() - }} -} - - -macro_rules! read_path_parameter { - ($req: expr, $name: expr) => {{ - $req.extensions.get::().unwrap().find($name) - }} -} - - -pub fn json_response(status: status::Status, content: serde_json::Value) -> Response { - let mut response = Response::with((status, format!("{}", content))); - response.headers.set_raw("Content-Type", vec![b"application/json".to_vec()]); - response -} - - -pub fn index_not_found_response() -> Response { - json_response(status::NotFound, json!({"message": "Index not found"})) -} - - macro_rules! get_index_or_404 { ($cluster_metadata: expr, $index_name: expr) => {{ - use api::utils::index_not_found_response; - let index_ref = match $cluster_metadata.names.find_canonical($index_name) { Some(index_ref) => index_ref, None => { - return Ok(index_not_found_response()); + return None; } }; match $cluster_metadata.indices.get(&index_ref) { Some(index) => index, None => { - return Ok(index_not_found_response()); + return None; } } }} @@ -55,51 +19,18 @@ macro_rules! get_index_or_404 { macro_rules! get_index_or_404_mut { ($cluster_metadata: expr, $index_name: expr) => {{ - use api::utils::index_not_found_response; - let index_ref = match $cluster_metadata.names.find_canonical($index_name) { Some(index_ref) => index_ref, None => { - return Ok(index_not_found_response()); + return None; } }; match $cluster_metadata.indices.get_mut(&index_ref) { Some(index) => index, None => { - return Ok(index_not_found_response()); + return None; } } }} } - - -macro_rules! parse_json { - ($string: expr) => {{ - use api::utils::json_response; - - let value: serde_json::Value = match serde_json::from_str($string) { - Ok(data) => data, - Err(_) => { - return Ok(json_response(status::BadRequest, json!({"message": "Couldn't parse JSON"}))); - } - }; - - value - }} -} - - -macro_rules! json_from_request_body { - ($req: expr) => {{ - // Read request body to a string - let mut payload = String::new(); - $req.body.read_to_string(&mut payload).unwrap(); - - if !payload.is_empty() { - Some(parse_json!(&payload)) - } else { - None - } - }} -} diff --git a/src/rusticsearch/main.rs b/src/rusticsearch/main.rs index 4510fb7..62897ef 100644 --- a/src/rusticsearch/main.rs +++ b/src/rusticsearch/main.rs @@ -1,8 +1,12 @@ +#![feature(custom_derive)] +#![feature(plugin)] +#![plugin(rocket_codegen)] + extern crate kite; extern crate kite_rocksdb; +extern crate rocket; +extern crate rocket_contrib; extern crate chrono; -#[macro_use] -extern crate router; extern crate url; #[macro_use] extern crate log;