SunilKumarPradhan commented on code in PR #4490:
URL: https://github.com/apache/iggy/pull/4490#discussion_r4395817348


##########
foreign/python/src/cluster.rs:
##########
@@ -0,0 +1,220 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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 iggy::prelude::{
+    ClusterMetadata as RustClusterMetadata, ClusterNode as RustClusterNode,
+    TransportEndpoints as RustTransportEndpoints,
+};
+use pyo3::{
+    prelude::*,
+    types::{PyDict, PyString},
+};
+use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods};
+
+/// Python name and members of the node role enum. Each value is the lowercase
+/// name the server uses, so a role converts by its `as_ref()` string.
+pub const ROLE_ENUM: &str = "ClusterNodeRole";
+pub const ROLE_MEMBERS: [(&str, &str); 2] = [("LEADER", "leader"), 
("FOLLOWER", "follower")];
+
+/// Python name and members of the node status enum, keyed like the role enum.
+pub const STATUS_ENUM: &str = "ClusterNodeStatus";
+pub const STATUS_MEMBERS: [(&str, &str); 6] = [
+    ("HEALTHY", "healthy"),
+    ("STARTING", "starting"),
+    ("STOPPING", "stopping"),
+    ("UNREACHABLE", "unreachable"),
+    ("MAINTENANCE", "maintenance"),
+    ("UNKNOWN", "unknown"),
+];
+
+/// Adds `ClusterNodeRole` and `ClusterNodeStatus` to the module as str-backed
+/// `enum.Enum` types, the way `Durability` is exported, so `.name`, `.value`,
+/// and iteration work as the stub declares.
+pub fn register_enums(py: Python<'_>, module: &Bound<'_, PyModule>) -> 
PyResult<()> {
+    for (name, members) in [
+        (ROLE_ENUM, ROLE_MEMBERS.as_slice()),
+        (STATUS_ENUM, STATUS_MEMBERS.as_slice()),
+    ] {
+        let kwargs = PyDict::new(py);
+        kwargs.set_item("type", py.get_type::<PyString>())?;
+        kwargs.set_item("module", "apache_iggy")?;
+        let enumeration = py
+            .import("enum")?
+            .getattr("Enum")?
+            .call((name, members.to_vec()), Some(&kwargs))?;
+        module.add(name, enumeration)?;
+    }
+    Ok(())
+}
+
+/// Returns the member of the exported enum `name` whose value is `value`.
+fn enum_member<'py>(py: Python<'py>, name: &str, value: &str) -> 
PyResult<Bound<'py, PyAny>> {
+    py.import("apache_iggy")?.getattr(name)?.call1((value,))
+}
+
+/// Transport endpoints exposed by a cluster node.
+///
+/// A port of 0 means the node does not advertise that transport.
+#[gen_stub_pyclass]
+#[pyclass(frozen)]
+pub struct TransportEndpoints {
+    /// TCP port.
+    #[pyo3(get)]
+    pub tcp: u16,
+    /// QUIC port.
+    #[pyo3(get)]
+    pub quic: u16,
+    /// HTTP port.
+    #[pyo3(get)]
+    pub http: u16,
+    /// WebSocket port.
+    #[pyo3(get)]
+    pub websocket: u16,
+}
+
+impl From<&RustTransportEndpoints> for TransportEndpoints {
+    fn from(endpoints: &RustTransportEndpoints) -> Self {
+        Self {
+            tcp: endpoints.tcp,
+            quic: endpoints.quic,
+            http: endpoints.http,
+            websocket: endpoints.websocket,
+        }
+    }
+}
+
+#[gen_stub_pymethods]
+#[pymethods]
+impl TransportEndpoints {
+    fn __repr__(&self) -> String {
+        format!(
+            "TransportEndpoints(tcp={}, quic={}, http={}, websocket={})",
+            self.tcp, self.quic, self.http, self.websocket
+        )
+    }
+}
+
+/// A node in the cluster with its transport endpoints, role, and status.
+#[gen_stub_pyclass]
+#[pyclass]
+pub struct ClusterNode {

Review Comment:
   Yep , the ClusterNode had no replica_id , I have added it now , in my latest 
push, 
   
   **added a replica_id getter on ClusterNode that returns the u8.
   added it to __repr__: ClusterNode(replica_id=0, name=..., ...).
   added it to the generated .pyi stub.**
   test_get_cluster_metadata now asserts node.replica_id == 0 and checks it in 
the repr. 
   
   A non-clustered server reports itself as replica 0.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to