diff --git a/Cargo.lock b/Cargo.lock index f77cb44537..3141067775 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,9 +23,9 @@ checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217" [[package]] name = "aho-corasick" -version = "0.7.13" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" +checksum = "b476ce7103678b0c6d3d395dbbae31d48ff910bd28be979ba5d48c6351131d0d" dependencies = [ "memchr", ] @@ -149,7 +149,7 @@ checksum = "b246867b8b3b6ae56035f1eb1ed557c1d8eae97f0d53696138a50fa0e3a3b8c0" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -186,12 +186,12 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.51" +version = "0.3.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec1931848a574faa8f7c71a12ea00453ff5effbb5f51afe7f77d7a48cace6ac1" +checksum = "707b586e0e2f247cbde68cdd2c3ce69ea7b7be43e1c5b426e37c9319c4b9838e" dependencies = [ "addr2line", - "cfg-if", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object", @@ -218,7 +218,7 @@ checksum = "4c07087f3d5731bf3fb375a81841b99597e25dc11bd3bc72d16d43adf6624a6e" dependencies = [ "bitflags", "cexpr", - "cfg-if", + "cfg-if 0.1.10", "clang-sys", "clap", "env_logger", @@ -265,7 +265,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" dependencies = [ - "block-padding", + "block-padding 0.1.5", "byte-tools", "byteorder", "generic-array 0.12.3", @@ -281,22 +281,22 @@ dependencies = [ ] [[package]] -name = "block-cipher-trait" -version = "0.6.2" +name = "block-cipher" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" +checksum = "f337a3e6da609650eb74e02bc9fac7b735049f7623ab12f2e4c719316fcc7e80" dependencies = [ - "generic-array 0.12.3", + "generic-array 0.14.4", ] [[package]] name = "block-modes" -version = "0.3.3" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31aa8410095e39fdb732909fb5730a48d5bd7c2e3cd76bd1b07b3dbea130c529" +checksum = "0c9b14fd8a4739e6548d4b6018696cf991dcf8c6effd9ef9eb33b29b8a650972" dependencies = [ - "block-cipher-trait", - "block-padding", + "block-cipher", + "block-padding 0.2.1", ] [[package]] @@ -308,6 +308,12 @@ dependencies = [ "byte-tools", ] +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + [[package]] name = "bson" version = "1.1.0" @@ -400,9 +406,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef611cc68ff783f18535d77ddd080185275713d852c4f5cbb6122c462a7a825c" +checksum = "ed67cbde08356238e75fc4656be4749481eeffb09e19f320a25237d5221c985d" [[package]] name = "cexpr" @@ -419,6 +425,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "chrono" version = "0.4.19" @@ -649,7 +661,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "crossbeam-utils", "maybe-uninit", ] @@ -661,7 +673,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" dependencies = [ "autocfg 1.0.1", - "cfg-if", + "cfg-if 0.1.10", "lazy_static", ] @@ -675,6 +687,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "crypto-mac" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58bcd97a54c7ca5ce2f6eb16f6bede5b0ab5f0055fedc17d2f0b4466e21671ca" +dependencies = [ + "generic-array 0.14.4", + "subtle", +] + [[package]] name = "csv" version = "1.1.3" @@ -730,18 +752,18 @@ checksum = "3df5480412da86cdf5d6b7f3b682422c84359ff7399aa658df1d15ee83244b1d" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] name = "des" -version = "0.3.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74ba5f1b5aee9772379c2670ba81306e65a93c0ee3caade7a1d22b188d88a3af" +checksum = "e084b5048dec677e6c9f27d7abc551dde7d127cf4127fea82323c98a30d7fa0d" dependencies = [ - "block-cipher-trait", + "block-cipher", "byteorder", - "opaque-debug 0.2.3", + "opaque-debug 0.3.0", ] [[package]] @@ -806,7 +828,7 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "dirs-sys", ] @@ -833,7 +855,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f69635ffdfbaea44241d7cca30a5e3a2e1c892613a6a8ad8ef03deeb6803480" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "socket2", "winapi 0.3.9", @@ -888,7 +910,7 @@ version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a51b8cf747471cb9499b6d59e59b0444f4c90eba8968c4e44874e92b5b64ace2" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", ] [[package]] @@ -940,7 +962,7 @@ dependencies = [ "proc-macro-error", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -1062,7 +1084,7 @@ dependencies = [ "derive_utils", "find-crate", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -1091,7 +1113,7 @@ dependencies = [ "proc-macro-hack", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -1169,7 +1191,18 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee8025cf36f917e6a52cce185b7c7177689b838b7ec138364e50cc2277a56cf4" +dependencies = [ + "cfg-if 0.1.10", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] @@ -1286,7 +1319,17 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" dependencies = [ - "crypto-mac", + "crypto-mac 0.8.0", + "digest 0.9.0", +] + +[[package]] +name = "hmac" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "deae6d9dbb35ec2c502d62b8f7b1c000a0822c3b0794ba36b3149c0a1c840dff" +dependencies = [ + "crypto-mac 0.9.1", "digest 0.9.0", ] @@ -1507,7 +1550,7 @@ dependencies = [ "iml-util", "iml-wire-types", "inotify", - "insta 1.0.0", + "insta 1.1.0", "lazy_static", "libc", "liblustreapi", @@ -1520,7 +1563,7 @@ dependencies = [ "serde", "serde_json", "spinners", - "stream-cancel 0.6.1", + "stream-cancel 0.6.2", "strfmt", "structopt", "tempfile", @@ -1712,7 +1755,7 @@ dependencies = [ "iml-service-queue", "iml-tracing", "iml-wire-types", - "insta 1.0.0", + "insta 1.1.0", "lazy_static", "regex", "serde", @@ -1763,7 +1806,7 @@ dependencies = [ "iml-tracing", "iml-wire-types", "indicatif", - "insta 1.0.0", + "insta 1.1.0", "lazy_static", "number-formatter", "prettytable-rs", @@ -1959,6 +2002,18 @@ dependencies = [ "url", ] +[[package]] +name = "iml-state-machine" +version = "0.1.0" +dependencies = [ + "futures", + "iml-wire-types", + "petgraph", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "iml-stats" version = "0.4.0" @@ -2070,6 +2125,7 @@ dependencies = [ "iml-manager-env", "iml-postgres", "iml-rabbit", + "iml-state-machine", "iml-tracing", "iml-wire-types", "serde", @@ -2126,9 +2182,9 @@ dependencies = [ [[package]] name = "influx_db_client" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39a1922c4401619e9e67144b494966f1313d24b9d0feba24729e10dd4d835086" +checksum = "20f7ba194095b44d05d7d2907fb3a04e7ea7ae1591cdd41fe800e555e51903c4" dependencies = [ "bytes", "futures", @@ -2187,9 +2243,9 @@ dependencies = [ [[package]] name = "insta" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3463f26c58ee98b72e4eae1a6b4c28bc3320ab69d4836b55162362c2ec63fa6" +checksum = "e7e7528a20113cf7ca90eddfc2439c608188b6eafc0613964da2bd140c92acec" dependencies = [ "console 0.12.0", "difference", @@ -2205,7 +2261,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63312a18f7ea8760cdd0a7c5aac1a619752a246b833545e3e36d1f81f7cd9e66" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", ] [[package]] @@ -2250,7 +2306,7 @@ dependencies = [ [[package]] name = "juniper" version = "0.14.2" -source = "git+https://github.com/graphql-rust/juniper#f914322ef44eab706fb3d5d4a4b3e7022f47ab86" +source = "git+https://github.com/graphql-rust/juniper#c964fd805c8c9909d662a722532558cf7fad69a3" dependencies = [ "async-trait", "bson", @@ -2270,12 +2326,12 @@ dependencies = [ [[package]] name = "juniper_codegen" version = "0.14.2" -source = "git+https://github.com/graphql-rust/juniper#f914322ef44eab706fb3d5d4a4b3e7022f47ab86" +source = "git+https://github.com/graphql-rust/juniper#c964fd805c8c9909d662a722532558cf7fad69a3" dependencies = [ "proc-macro-error", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -2318,7 +2374,7 @@ checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616" dependencies = [ "arrayvec", "bitflags", - "cfg-if", + "cfg-if 0.1.10", "ryu", "static_assertions", ] @@ -2341,11 +2397,11 @@ dependencies = [ [[package]] name = "libloading" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2443d8f0478b16759158b2f66d525991a05491138bc05814ef52a250148ef4f9" +checksum = "3557c9384f7f757f6d139cd3a4c62ef4e850696c16bf27924a5538c8a09717a1" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "winapi 0.3.9", ] @@ -2355,7 +2411,7 @@ version = "0.4.0" dependencies = [ "errno", "libc", - "libloading 0.6.3", + "libloading 0.6.4", "liblustreapi-types", "thiserror", "tracing", @@ -2400,7 +2456,7 @@ version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", ] [[package]] @@ -2507,7 +2563,7 @@ version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "fuchsia-zircon", "fuchsia-zircon-sys", "iovec", @@ -2638,7 +2694,7 @@ version = "0.2.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "winapi 0.3.9", ] @@ -2720,9 +2776,9 @@ checksum = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a" [[package]] name = "object" -version = "0.20.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" +checksum = "37fd5004feb2ce328a52b0b3d01dbf4ffff72583493900ed15f22d4111c51693" [[package]] name = "once_cell" @@ -2749,7 +2805,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 0.1.10", "foreign-types", "lazy_static", "libc", @@ -2777,16 +2833,17 @@ dependencies = [ [[package]] name = "p12" -version = "0.1.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14e9eb95896174110548df49573a1512e0c02f43ea2b1b2b963b946abd759e27" +checksum = "18d9bbc57ec03c625d98cf72abe80d5b6ac4e3b5c4fe6e68150be8778da9c7a0" dependencies = [ - "block-cipher-trait", "block-modes", "des", + "getrandom 0.2.0", + "hmac 0.9.0", "lazy_static", "rc2", - "ring", + "sha-1 0.9.1", "yasna", ] @@ -2807,7 +2864,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "cloudabi 0.1.0", "instant", "libc", @@ -2857,7 +2914,7 @@ dependencies = [ "pest_meta", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -2901,22 +2958,22 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.26" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13fbdfd6bdee3dc9be46452f86af4a4072975899cf8592466668620bebfbcc17" +checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "0.4.26" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c82fb1329f632c3552cf352d14427d57a511b1cf41db93b3a7d77906a82dcc8e" +checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -2944,9 +3001,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "postgres-protocol" @@ -2958,7 +3015,7 @@ dependencies = [ "byteorder", "bytes", "fallible-iterator", - "hmac", + "hmac 0.8.1", "md5", "memchr", "rand 0.7.3", @@ -3012,7 +3069,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", "version_check 0.9.2", ] @@ -3145,7 +3202,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.15", "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", @@ -3193,7 +3250,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.15", ] [[package]] @@ -3287,12 +3344,12 @@ dependencies = [ [[package]] name = "rc2" -version = "0.3.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "039209d71774c9b2ae967ffb66b73ed253b3c384c198ec0d620fdd5369c78e5e" +checksum = "1a067463a4086ea7aab0cc815bbb0c8d473798657643734850bd0c6660846643" dependencies = [ - "block-cipher-trait", - "opaque-debug 0.2.3", + "block-cipher", + "opaque-debug 0.3.0", ] [[package]] @@ -3316,16 +3373,16 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" dependencies = [ - "getrandom", + "getrandom 0.1.15", "redox_syscall", "rust-argon2", ] [[package]] name = "regex" -version = "1.3.9" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" +checksum = "8963b85b8ce3074fecffde43b4b0dded83ce2f367dc8d363afc56679f3ee820b" dependencies = [ "aho-corasick", "memchr", @@ -3345,9 +3402,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" +checksum = "8cab7a364d15cde1e505267766a2d3c4e22a843e1a601f0fa7564c0f82ced11c" [[package]] name = "remove_dir_all" @@ -3427,9 +3484,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +checksum = "b2610b7f643d18c87dff3b489950269617e6601a51f1f05aa5daefee36f64f0b" [[package]] name = "rustc_version" @@ -3585,29 +3642,29 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5" +checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8" +checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] name = "serde_json" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a230ea9107ca2220eea9d46de97eddcb04cd00e92d13dda78e478dd33fa82bd4" +checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95" dependencies = [ "indexmap", "itoa", @@ -3623,7 +3680,7 @@ checksum = "2dc6b7951b17b051f3210b063f12cc17320e2fe30ae05b0fe2a3abb068551c76" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -3669,7 +3726,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "170a36ea86c864a3f16dd2687712dd6646f7019f301e57537c7f4dc9f5916770" dependencies = [ "block-buffer 0.9.0", - "cfg-if", + "cfg-if 0.1.10", "cpuid-bool", "digest 0.9.0", "opaque-debug 0.3.0", @@ -3688,7 +3745,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2933378ddfeda7ea26f48c555bdad8bb446bf8a3d17832dc83e380d444cfb8c1" dependencies = [ "block-buffer 0.9.0", - "cfg-if", + "cfg-if 0.1.10", "cpuid-bool", "digest 0.9.0", "opaque-debug 0.3.0", @@ -3753,7 +3810,7 @@ version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "redox_syscall", "winapi 0.3.9", @@ -3828,7 +3885,7 @@ dependencies = [ "futures-util", "hashbrown 0.8.2", "hex", - "hmac", + "hmac 0.8.1", "itoa", "libc", "log", @@ -3872,7 +3929,7 @@ dependencies = [ "sha2", "sqlx-core", "sqlx-rt", - "syn 1.0.42", + "syn 1.0.44", "url", ] @@ -3889,9 +3946,9 @@ dependencies = [ [[package]] name = "standback" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33a71ea1ea5f8747d1af1979bfb7e65c3a025a70609f04ceb78425bc5adad8e6" +checksum = "f4e0831040d2cf2bdfd51b844be71885783d489898a192f254ae25d57cce725c" dependencies = [ "version_check 0.9.2", ] @@ -3926,7 +3983,7 @@ dependencies = [ "quote 1.0.7", "serde", "serde_derive", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -3942,7 +3999,7 @@ dependencies = [ "serde_derive", "serde_json", "sha1", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -3965,9 +4022,9 @@ dependencies = [ [[package]] name = "stream-cancel" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c701433009034f047e385aa930890e6c1d717c7e6374bbd9b81795dee55aff72" +checksum = "fcbeca004dfaec7b6fd818d8ae6359eaea21770d134f137c4cb8fb5fa92b5a33" dependencies = [ "futures-core", "futures-util", @@ -4012,9 +4069,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.18" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33f6461027d7f08a13715659b2948e1602c31a3756aeae9378bfe7518c72e82" +checksum = "126d630294ec449fae0b16f964e35bf3c74f940da9dca17ee9b905f7b3112eb8" dependencies = [ "clap", "lazy_static", @@ -4023,15 +4080,15 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.11" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c92e775028122a4b3dd55d58f14fc5120289c69bee99df1d117ae30f84b225c9" +checksum = "65e51c492f9e23a220534971ff5afc14037289de430e3c83f9daf6a1b6ae91e8" dependencies = [ "heck", "proc-macro-error", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -4069,9 +4126,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.42" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c51d92969d209b54a98397e1b91c8ae82d8c87a7bb87df0b29aa2ad81454228" +checksum = "e03e57e4fcbfe7749842d53e24ccb9aa12b7252dbe5e91d2acad31834c8b8fdd" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", @@ -4089,11 +4146,11 @@ dependencies = [ [[package]] name = "tcp-stream" -version = "0.20.3" +version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d147f992a9942eb288eb52f58ba1868eee976d4983f2013867fde3736c52d0c" +checksum = "f34bbc13eef7fd9522e3f08538480f7762d6dd72b111f62b2bc8b185a5d982bd" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "mio 0.7.3", "p12", "rustls-connector", @@ -4115,7 +4172,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", "rand 0.7.3", "redox_syscall", @@ -4165,9 +4222,9 @@ dependencies = [ [[package]] name = "termios" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0fcee7b24a25675de40d5bb4de6e41b0df07bc9856295e7e2b3a3600c400c2" +checksum = "411c5bf740737c7918b8b1fe232dca4dc9f8e754b8ad5e20966814001ed0ac6b" dependencies = [ "libc", ] @@ -4198,7 +4255,7 @@ checksum = "cae2447b6282786c3493999f40a9be2a6ad20cb8bd268b0a0dbf5a065535c0ab" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -4257,7 +4314,7 @@ dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", "standback", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -4308,7 +4365,7 @@ checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -4415,9 +4472,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" +checksum = "75cf45bb0bef80604d001caaec0d09da99611b3c0fd39d3080468875cdb65645" dependencies = [ "serde", ] @@ -4434,7 +4491,7 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "log", "pin-project-lite", "tracing-attributes", @@ -4449,7 +4506,7 @@ checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -4494,9 +4551,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82bb5079aa76438620837198db8a5c529fb9878c730bc2b28179b0241cf04c10" +checksum = "4ef0a5e15477aa303afbfac3a44cba9b6430fdaad52423b1e6c0dbbe28c3eedd" dependencies = [ "ansi_term 0.12.1", "chrono", @@ -4508,6 +4565,7 @@ dependencies = [ "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", "tracing-serde", @@ -4639,7 +4697,7 @@ checksum = "c2e7e85a0596447f0f2ac090e16bc4c516c6fe91771fb0c0ccf7fa3dae896b9c" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", ] [[package]] @@ -4774,7 +4832,7 @@ version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "serde", "serde_json", "wasm-bindgen-macro", @@ -4791,7 +4849,7 @@ dependencies = [ "log", "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", "wasm-bindgen-shared", ] @@ -4801,7 +4859,7 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "js-sys", "wasm-bindgen", "web-sys", @@ -4825,7 +4883,7 @@ checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", - "syn 1.0.42", + "syn 1.0.44", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4844,7 +4902,7 @@ dependencies = [ "base64", "bytes", "futures", - "insta 1.0.0", + "insta 1.1.0", "quick-xml 0.19.0", "reqwest", "serde", diff --git a/Cargo.toml b/Cargo.toml index bde8e28997..e484846fa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ members = [ 'iml-services/iml-snapshot', 'iml-services/iml-stats', 'iml-sfa', + 'iml-state-machine', 'iml-system-test-utils', 'iml-systemd', 'iml-task-runner', diff --git a/chroma-manager.conf.template b/chroma-manager.conf.template index 7256e34705..c898b8e42d 100644 --- a/chroma-manager.conf.template +++ b/chroma-manager.conf.template @@ -250,7 +250,7 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_set_header Connection ''; - proxy_pass {{WARP_DRIVE_PROXY_PASS}}; + proxy_pass {{WARP_DRIVE_PROXY_PASS}}/messaging; } location /mailbox { diff --git a/iml-state-machine/Cargo.toml b/iml-state-machine/Cargo.toml new file mode 100644 index 0000000000..3821ccd1ef --- /dev/null +++ b/iml-state-machine/Cargo.toml @@ -0,0 +1,13 @@ +[package] +authors = ["IML Team "] +edition = "2018" +name = "iml-state-machine" +version = "0.1.0" + +[dependencies] +futures = "0.3" +iml-wire-types = {path = "../iml-wire-types", version = "0.4"} +petgraph = "0.5" +serde = {version = "1", features = ["derive"]} +serde_json = "1" +thiserror = "1.0" diff --git a/iml-state-machine/README.md b/iml-state-machine/README.md new file mode 100644 index 0000000000..d34fe2fcfd --- /dev/null +++ b/iml-state-machine/README.md @@ -0,0 +1,27 @@ +# IML State Machine Model + +``` + ┌────────────────────────────────────────────┐ + │ │ + │ Client mount │ + │ │ + │ │ + └────────────────────────────────────────────┘ + │ + │ + │ + │ + │ + ┌───────Depends on─────┴────────Depends On─────────┐ + │ │ + │ │ + │ │ + │ │ + ▼ ▼ +┌────────────────────────────────────────────┐ ┌────────────────────────────────────────────┐ +│ │ │ │ +│ LNet │ │ Filesystem │ +│ │ │ │ +│ │ │ │ +└────────────────────────────────────────────┘ └────────────────────────────────────────────┘ +``` diff --git a/iml-state-machine/src/lib.rs b/iml-state-machine/src/lib.rs new file mode 100644 index 0000000000..6a85fa44f1 --- /dev/null +++ b/iml-state-machine/src/lib.rs @@ -0,0 +1,160 @@ +// Copyright (c) 2020 DDN. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +mod snapshot; + +use futures::{stream, StreamExt}; +use iml_wire_types::{ + state_machine::Transition, + warp_drive::{Cache, RecordId}, +}; +use petgraph::{ + algo::astar, + graph::{DiGraph, NodeIndex}, + prelude::*, + Direction, +}; +use std::collections::HashSet; + +trait GraphExt { + fn find_node_idx(&self, x: &N) -> Option; +} + +impl GraphExt for Graph { + fn find_node_idx(&self, x: &N) -> Option { + self.node_indices().find(|i| &self[*i] == x) + } +} + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("State Not Found")] + NotFound, +} + +pub fn get_available_transitions(id: RecordId, cache: &Cache) -> Option> { + match id { + RecordId::Snapshot(id) => { + let snap = cache.snapshot.get(&id)?; + + let (g, node_idx) = snapshot::get_graph_state(&snap)?; + + let g2 = get_directed_subgraph(&g, node_idx, Direction::Outgoing); + + let xs: HashSet<_> = g2 + .raw_edges() + .iter() + .map(|x| Transition::Snapshot(x.weight)) + .collect(); + + Some(xs) + } + _ => None, + } +} + +pub fn get_transition_path(id: RecordId, cache: &Cache, x: Transition) -> Option> { + match (id, x) { + (RecordId::Snapshot(id), Transition::Snapshot(x)) => { + let snap = cache.snapshot.get(&id)?; + + let (g, node_idx) = snapshot::get_graph_state(&snap)?; + + let xs = astar( + &g, + node_idx, + |finish| { + g.edges_directed(finish, Direction::Incoming) + .any(|edge| edge.weight() == &x) + }, + |_| 1, + |_| 0, + )? + .1; + + let xs = xs.iter().zip(xs.iter().skip(1)).collect::>(); + + let mut out = vec![]; + + for (a, b) in xs { + let e = g.find_edge(*a, *b)?; + + let edge = *&g[e]; + + out.push(Transition::Snapshot(edge)); + } + + Some(out) + } + _ => None, + } +} + +async fn run_transition( + id: RecordId, + cache: &Cache, + x: Transition, +) -> Option, Error>> { + match (id, x) { + (RecordId::Snapshot(id), Transition::Snapshot(t)) => { + let xs = get_transition_path(RecordId::Snapshot(id), cache, x)?; + + let snap = cache.snapshot.get(&id)?; + + let xs = stream::iter(xs) + .fold(vec![], |mut acc, x| async move { + let r = snapshot::update(snap, t).await; + + acc.push(r); + + acc + }) + .await; + } + _ => {} + } + + None +} + +fn get_directed_subgraph( + graph: &DiGraph, + root: NodeIndex, + dir: petgraph::Direction, +) -> DiGraph { + let mut subgraph = DiGraph::new(); + let mut dfs = Dfs::new(&graph, root); + let mut nodes = std::collections::HashMap::new(); + + while let Some(node) = dfs.next(&graph) { + let mut neighbors = graph.neighbors_directed(node, dir).detach(); + + while let Some(edge) = neighbors.next_edge(&graph) { + let (g_from, g_to) = graph.edge_endpoints(edge).unwrap(); + + if g_to == root { + continue; + } + + if !nodes.contains_key(&g_from.index()) { + let n = subgraph.add_node(*&graph[g_from]); + nodes.insert(g_from.index(), n); + } + + if !nodes.contains_key(&g_to.index()) { + let n = subgraph.add_node(*&graph[g_to]); + nodes.insert(g_to.index(), n); + } + + let s_from = nodes.get(&g_from.index()).unwrap(); + let s_to = nodes.get(&g_to.index()).unwrap(); + + let edge = *&graph[edge]; + + subgraph.add_edge(*s_from, *s_to, edge); + } + } + + subgraph +} diff --git a/iml-state-machine/src/lnet.rs b/iml-state-machine/src/lnet.rs new file mode 100644 index 0000000000..db76238b82 --- /dev/null +++ b/iml-state-machine/src/lnet.rs @@ -0,0 +1,88 @@ +// Copyright (c) 2020 DDN. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +use futures::{Future, FutureExt}; +use petgraph::graph::DiGraph; +use std::{ io, pin::Pin}; + +pub enum LnetStates { + Unconfigured, + Unloaded, + Down, + Up, +} + +impl Default for LnetStates { + fn default() -> Self { + Self::Unconfigured + } +} + +impl LnetStates { + fn step(self, next: &Self) { + match (self, next) { + (Self::Unconfigured, Self::Unloaded) => {} + (Self::Unloaded, Self::Down) => {} + (Self::Down, Self::Up) => {} + (Self::Up, Self::Down) => {} + (Self::Down, Self::Unloaded) => {} + (Self::Unloaded, Self::Unconfigured) => {} + _ => {} + }; + } +} + +async fn configure() -> Result<(), io::Error> { + Ok(()) +} + +async fn load() -> Result<(), io::Error> { + Ok(()) +} + +async fn start() -> Result<(), io::Error> { + Ok(()) +} + +async fn stop() -> Result<(), io::Error> { + Ok(()) +} + +async fn unload() -> Result<(), io::Error> { + Ok(()) +} + +async fn unconfigure() -> Result<(), io::Error> { + Ok(()) +} + +type BoxedFuture = Pin> + Send>>; + +type Transition = Box BoxedFuture + Send + Sync>; + +fn mk_transition(f: fn() -> Fut) -> Transition +where + Fut: Future> + Send + 'static, +{ + Box::new(move || f().boxed()) +} + +fn build_graph() -> DiGraph:: { + let mut deps = DiGraph::::new(); + + let unconfigured = deps.add_node(LnetStates::Unconfigured); + let unloaded = deps.add_node(LnetStates::Unloaded); + let down = deps.add_node(LnetStates::Down); + let up = deps.add_node(LnetStates::Up); + + deps.add_edge(unconfigured, unloaded, mk_transition(configure)); + deps.add_edge(unloaded, down, mk_transition(load)); + deps.add_edge(down, up, mk_transition(start)); + deps.add_edge(up, down, mk_transition(stop)); + deps.add_edge(down, unloaded, mk_transition(unload)); + deps.add_edge(unloaded, unconfigured, mk_transition(unconfigure)); + + deps + +} diff --git a/iml-state-machine/src/snapshot.rs b/iml-state-machine/src/snapshot.rs new file mode 100644 index 0000000000..05c50868e0 --- /dev/null +++ b/iml-state-machine/src/snapshot.rs @@ -0,0 +1,53 @@ +// Copyright (c) 2020 DDN. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +use crate::{Error, GraphExt}; +use futures::{Future, FutureExt}; +use iml_wire_types::{ + snapshot::SnapshotRecord, + state_machine::snapshot::{State, Transition}, + warp_drive::Cache, +}; +use petgraph::{graph::DiGraph, graph::NodeIndex, graphmap::DiGraphMap, Graph}; + +pub async fn update(x: &SnapshotRecord, t: Transition) { + match t { + Transition::Mount => {} + Transition::Unmount => {} + Transition::Remove => {} + } +} + +pub fn get_state(x: &SnapshotRecord) -> State { + if x.mounted == Some(true) { + State::Mounted + } else if x.mounted == Some(false) { + State::Unmounted + } else { + State::Unmounted + } +} + +pub fn get_graph_state(x: &SnapshotRecord) -> Option<(DiGraph, NodeIndex)> { + let state = get_state(x); + + let g = build_graph(); + + g.find_node_idx(&state).map(move |x| (g, x)) +} + +pub fn build_graph() -> DiGraph { + let mut deps = DiGraph::::new(); + + let unmounted = deps.add_node(State::Unmounted); + let mounted = deps.add_node(State::Mounted); + let removed = deps.add_node(State::Removed); + + deps.add_edge(unmounted, mounted, Transition::Mount); + deps.add_edge(mounted, unmounted, Transition::Unmount); + deps.add_edge(unmounted, removed, Transition::Remove); + deps.add_edge(mounted, removed, Transition::Remove); + + deps +} diff --git a/iml-warp-drive/Cargo.toml b/iml-warp-drive/Cargo.toml index 3c622af970..9b70698155 100644 --- a/iml-warp-drive/Cargo.toml +++ b/iml-warp-drive/Cargo.toml @@ -11,6 +11,7 @@ iml-manager-client = {path = "../iml-manager-client", version = "0.4"} iml-manager-env = {path = "../iml-manager-env", version = "0.4"} iml-postgres = {path = "../iml-postgres", version = "0.4"} iml-rabbit = {path = "../iml-rabbit", version = "0.4"} +iml-state-machine = {path = "../iml-state-machine", version = "0.1"} iml-tracing = {version = "0.3", path = "../iml-tracing"} iml-wire-types = {path = "../iml-wire-types", version = "0.4", features = ["postgres-interop"]} serde = {version = "1", features = ["derive"]} diff --git a/iml-warp-drive/src/lib.rs b/iml-warp-drive/src/lib.rs index 6f281ca962..9ebedb81d9 100644 --- a/iml-warp-drive/src/lib.rs +++ b/iml-warp-drive/src/lib.rs @@ -7,7 +7,9 @@ pub mod db_record; pub mod error; pub mod listen; pub mod locks; +pub mod messaging; pub mod request; +pub mod state_machine; pub mod users; pub use db_record::*; diff --git a/iml-warp-drive/src/locks.rs b/iml-warp-drive/src/locks.rs index 92369940f7..df996e128a 100644 --- a/iml-warp-drive/src/locks.rs +++ b/iml-warp-drive/src/locks.rs @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. use crate::request::Request; -use futures::{Stream, TryStreamExt}; +use futures::{lock::Mutex, Stream, TryStreamExt}; use im::{HashMap, HashSet}; use iml_rabbit::{ basic_consume, basic_publish, bind_queue, declare_transient_exchange, declare_transient_queue, @@ -11,6 +11,9 @@ use iml_rabbit::{ Queue, }; use iml_wire_types::{LockAction, LockChange, ToCompositeId}; +use std::sync::Arc; + +pub type SharedLocks = Arc>; /// Declares the exchange for rpc comms async fn declare_rpc_exchange(c: &Channel) -> Result<(), ImlRabbitError> { diff --git a/iml-warp-drive/src/main.rs b/iml-warp-drive/src/main.rs index 019d1e1431..dd43697a58 100644 --- a/iml-warp-drive/src/main.rs +++ b/iml-warp-drive/src/main.rs @@ -8,15 +8,13 @@ use iml_postgres::get_db_pool; use iml_warp_drive::{ cache::{populate_from_api, populate_from_db, SharedCache}, error, listen, - locks::{self, create_locks_consumer, Locks}, + locks::{self, create_locks_consumer, SharedLocks}, users, }; use iml_wire_types::warp_drive::{Cache, Message}; use std::sync::Arc; use warp::Filter; -type SharedLocks = Arc>; - #[tokio::main] async fn main() -> Result<(), Box> { iml_tracing::init(); @@ -138,42 +136,21 @@ async fn main() -> Result<(), Box> { }), ); - // GET -> messages stream - let routes = warp::get() - .and(warp::any().map(move || Arc::clone(&user_state2))) - .and(warp::any().map(move || Arc::clone(&lock_state2))) - .and(warp::any().map(move || Arc::clone(&api_cache_state2))) - .and_then( - |users: users::SharedUsers, locks: SharedLocks, api_cache: SharedCache| { - tracing::debug!("Inside user route"); - - async move { - // reply using server-sent events - let stream = users::user_connected( - users, - locks.lock().await.clone(), - api_cache.lock().await.clone(), - ) - .await; - - Ok::<_, error::ImlWarpDriveError>(warp::sse::reply( - warp::sse::keep_alive().stream(stream), - )) - } - .map_err(warp::reject::custom) - }, - ) - .with(warp::log("iml-warp-drive::api")); - let addr = iml_manager_env::get_warp_drive_addr(); tracing::info!("Listening on {}", addr); - let (_, fut) = warp::serve(routes).bind_with_graceful_shutdown( - addr, - tokio_runtime_shutdown::when_finished(&valve) - .then(move |_| users::disconnect_all_users(user_state3)), - ); + let messaging_route = + iml_warp_drive::messaging::route(user_state2, Arc::clone(&api_cache_state2), lock_state2); + + let state_machine_routes = iml_warp_drive::state_machine::route(api_cache_state2); + + let (_, fut) = warp::serve(messaging_route.or(state_machine_routes)) + .bind_with_graceful_shutdown( + addr, + tokio_runtime_shutdown::when_finished(&valve) + .then(move |_| users::disconnect_all_users(user_state3)), + ); fut.await; diff --git a/iml-warp-drive/src/messaging.rs b/iml-warp-drive/src/messaging.rs new file mode 100644 index 0000000000..12b7db81d4 --- /dev/null +++ b/iml-warp-drive/src/messaging.rs @@ -0,0 +1,41 @@ +// Copyright (c) 2020 DDN. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +use crate::{cache, error, locks::SharedLocks, users}; +use futures::TryFutureExt; +use std::sync::Arc; +use warp::Filter; + +pub fn route( + user_state: users::SharedUsers, + api_cache_state: cache::SharedCache, + lock_state: SharedLocks, +) -> impl Filter + Clone { + warp::path("messaging") + .and(warp::get()) + .and(warp::any().map(move || Arc::clone(&user_state))) + .and(warp::any().map(move || Arc::clone(&lock_state))) + .and(warp::any().map(move || Arc::clone(&api_cache_state))) + .and_then( + |users: users::SharedUsers, locks: SharedLocks, api_cache: cache::SharedCache| { + tracing::debug!("Inside messaging route"); + + async move { + // reply using server-sent events + let stream = users::user_connected( + users, + locks.lock().await.clone(), + api_cache.lock().await.clone(), + ) + .await; + + Ok::<_, error::ImlWarpDriveError>(warp::sse::reply( + warp::sse::keep_alive().stream(stream), + )) + } + .map_err(warp::reject::custom) + }, + ) + .with(warp::log("iml-warp-drive::messaging")) +} diff --git a/iml-warp-drive/src/state_machine.rs b/iml-warp-drive/src/state_machine.rs new file mode 100644 index 0000000000..6dd9f88519 --- /dev/null +++ b/iml-warp-drive/src/state_machine.rs @@ -0,0 +1,40 @@ +// Copyright (c) 2020 DDN. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +use crate::cache; +use iml_wire_types::{state_machine::Transition, warp_drive::RecordId}; +use std::sync::Arc; +use warp::Filter; + +pub fn route( + shared_cache: cache::SharedCache, +) -> impl Filter + Clone { + let route = warp::path("state_machine").and(warp::any().map(move || Arc::clone(&shared_cache))); + let route2 = route.clone(); + + let r = route + .and(warp::path("get_transition")) + .and(warp::path::end()) + .and(warp::post()) + .and(warp::body::json()) + .and_then( + |shared_cache: cache::SharedCache, record_id: RecordId| async move { + tracing::debug!("Inside state_machine route"); + + let cache = shared_cache.lock().await; + + let t = iml_state_machine::get_available_transitions(record_id, &cache); + + Ok::<_, warp::Rejection>(warp::reply::json(&t)) + }, + ); + + route2.and(warp::path("get_transition_path")).and(warp::path::end()).and(warp::post()).and(warp::body::json()).and_then(|shared_cache: cache::SharedCache, (record_id, transition): (RecordId, Transition)| async move { + let cache = shared_cache.lock().await; + + let t = iml_state_machine::get_transition_path(record_id, &cache, transition); + + Ok::<_, warp::Rejection>(warp::reply::json(&t)) + }).or(r) +} diff --git a/iml-wire-types/src/lib.rs b/iml-wire-types/src/lib.rs index e39feaa4c4..a0436ff871 100644 --- a/iml-wire-types/src/lib.rs +++ b/iml-wire-types/src/lib.rs @@ -8,6 +8,7 @@ pub mod graphql_duration; pub mod high_availability; pub mod sfa; pub mod snapshot; +pub mod state_machine; pub mod warp_drive; use chrono::{DateTime, Utc}; diff --git a/iml-wire-types/src/state_machine.rs b/iml-wire-types/src/state_machine.rs new file mode 100644 index 0000000000..c75a78a2d2 --- /dev/null +++ b/iml-wire-types/src/state_machine.rs @@ -0,0 +1,46 @@ +// Copyright (c) 2020 DDN. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Copy, Eq, PartialEq, Hash)] +pub enum Transition { + Snapshot(snapshot::Transition), +} + +#[derive(Debug, Clone, Copy)] +pub enum State { + Snapshot(snapshot::State), +} + +pub mod snapshot { + #[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] + pub enum State { + Unknown, + Unmounted, + Mounted, + Removed, + } + + impl Default for State { + fn default() -> Self { + Self::Unknown + } + } + + #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Copy, PartialEq, Eq, Hash)] + pub enum Transition { + Mount, + Unmount, + Remove, + } + + impl Transition { + pub fn description(&self) -> &str { + match self { + Self::Mount => "Mount snapshot", + Self::Unmount => "Unmount snapshot", + Self::Remove => "Remove snapshot", + } + } + } +} diff --git a/migrations/20201005192806_state_machine.sql b/migrations/20201005192806_state_machine.sql new file mode 100644 index 0000000000..78ca5993e8 --- /dev/null +++ b/migrations/20201005192806_state_machine.sql @@ -0,0 +1,11 @@ +CREATE TYPE machine_state AS ENUM ('progress', 'failed', 'complete', 'cancelled'); + +CREATE TABLE IF NOT EXISTS command ( + id serial PRIMARY KEY, + start_time TIMESTAMP WITH TIME ZONE NOT NULL, + end_time TIMESTAMP WITH TIME ZONE, + state: machine_state NOT NULL, + message: TEXT NOT NULL, +); + +CREATE TABLE IF NOT EXISTS transition (id serial PRIMARY KEY,); \ No newline at end of file