pub async fn cluster_add_handler(
    request: Json<ClusterNodeRequest>,
    cluster_state: Extension<ClusterRef>,
) -> Result<Json<Value>, ClusterError> {
    let req: ClusterNodeRequest = request.0;
    let cluster: ClusterRef = cluster_state.0;
    log::info!("Cluster add node: {:?}", req);
    return match cluster
        .add_node(&req.name.clone(), req.priority, &req.address)
        .await
    {
        Ok(_) => match cluster.get_node_by_name(req.clone().name) {
            Ok(node) => {
                log::info!("Successfully added node: {:?}", req);
                Ok(Json(json!(node)))
            }
            Err(_) => {
                log::error!("Cannot find {:?} in current cluster configuration", req);
                Err(ClusterError::Add)
            }
        },
        Err(_) => {
            log::error!("Cannot add {:?} in current cluster", req);
            Err(ClusterError::Add)
        }
    };
}
// POST /v1/cluster/list
// create node depends on json context in http body
// request: the request body contains node message(name, ip address, priority)
// cluster_state: the shared in memory state which store all nodes known to current node
// return: return node information when add success
POST /v1/cluster/list
create node depends on json context in http body
request: the request body contains node message(name, ip address, priority)
cluster_state: the shared in memory state which store all nodes known to current node
return: return node information when add success
POST / v1 / cluster / list create node depends on json context in http body request : the request body contains node message ( name ip address priority ) cluster_state : the shared in memory state which store all nodes known to current node return : return node information when add success
pub async fn cluster_add_handler(
    request: Json<ClusterNodeRequest>,
    cluster_state: Extension<ClusterRef>,
) -> Result<Json<Value>, ClusterError> {
    let req: ClusterNodeRequest = request.0;
    let cluster: ClusterRef = cluster_state.0;
    log::info!("Cluster add node: {:?}", req);
    return match cluster
        .add_node(&req.name.clone(), req.priority, &req.address)
        .await
    {
        Ok(_) => match cluster.get_node_by_name(req.clone().name) {
            Ok(node) => {
                log::info!("Successfully added node: {:?}", req);
                Ok(Json(json!(node)))
            }
            Err(_) => {
                log::error!("Cannot find {:?} in current cluster configuration", req);
                Err(ClusterError::Add)
            }
        },
        Err(_) => {
            log::error!("Cannot add {:?} in current cluster", req);
            Err(ClusterError::Add)
        }
    };
}
pub async fn cluster_add_handler ( request : Json < ClusterNodeRequest > , cluster_state : Extension < ClusterRef > , ) -> Result < Json < Value > , ClusterError > { let req : ClusterNodeRequest = request . 0 ; let cluster : ClusterRef = cluster_state . 0 ; log :: info ! ( " " req ) ; return match cluster . add_node ( & req . name . clone ( ) , req . priority , & req . address ) . await { Ok ( _ ) => match cluster . get_node_by_name ( req . clone ( ) . name ) { Ok ( node ) => { log :: info ! ( " " req ) ; Ok ( Json ( json ! ( node ) ) ) } Err ( _ ) => { log :: error ! ( " " req ) ; Err ( ClusterError :: Add ) } } , Err ( _ ) => { log :: error ! ( " " req ) ; Err ( ClusterError :: Add ) } } ; }
POST /v1/cluster/list
create node depends on json context in http body
request: the request body contains node message(name, ip address, priority)
cluster_state: the shared in memory state which store all nodes known to current node
return: return node information when add success
POST / v1 / cluster / list create node depends on json context in http body request : the request body contains node message ( name ip address priority ) cluster_state : the shared in memory state which store all nodes known to current node return : return node information when add success
request
Json<ClusterNodeRequest>
cluster_state
Extension<ClusterRef>
request
Json<ClusterNodeRequest>
cluster_state
Extension<ClusterRef>