Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
cluster.rs.html -- source
[go: Go Back, main page]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2018 Grove Enterprises LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use etcd::Client as EtcdClient;
use etcd::kv::KeyValueInfo;
use etcd::{kv, Response};
use tokio_core::reactor::Core;

/// Retrieve a list of DataFusion worker endpoints from etcd
pub fn get_worker_list(etcd_address: &str) -> Result<Vec<String>, String> {
    // create futures event loop
    let mut core = Core::new().unwrap();
    let handle = core.handle();

    // get list of workers from etcd
    let endpoints = &[etcd_address];

    match EtcdClient::new(&handle, endpoints, None) {
        Ok(etcd) => match core.run(kv::get(
            &etcd,
            "/datafusion/workers/",
            kv::GetOptions::default(),
        )) {
            Ok(Response { ref data, .. }) => match data {
                &KeyValueInfo { ref node, .. } => match &node.nodes {
                    &Some(ref workers) => {
                        Ok(workers.iter().flat_map(|w| w.value.clone()).collect())
                    }
                    _ => Ok(vec![]),
                },
            },
            Err(e) => Err(format!("Etcd request failed ({:?}): {:?}", endpoints, e)),
        },
        Err(e) => Err(format!("Etcd connection failed ({:?}): {:?}", endpoints, e)),
    }
}