"container/git@developer.sourcefind.cn:OpenDAS/dynamo.git" did not exist on "61af664b2cea35bb623a0f402a554c711084d08e"
Commit fd0bcfa2 authored by Ryan Olson's avatar Ryan Olson Committed by GitHub
Browse files

refactor: adding facades for runtimes (#187)

parent a52b3553
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
use crate::discovery::Lease; use crate::discovery::Lease;
use super::{error, transports::nats::Slug, DistributedRuntime, Result}; use super::{error, traits::*, transports::nats::Slug, DistributedRuntime, Result, Runtime};
use crate::pipeline::network::{ingress::push_endpoint::PushEndpoint, PushWorkHandler}; use crate::pipeline::network::{ingress::push_endpoint::PushEndpoint, PushWorkHandler};
use async_nats::{ use async_nats::{
...@@ -108,6 +108,18 @@ pub struct Component { ...@@ -108,6 +108,18 @@ pub struct Component {
namespace: String, namespace: String,
} }
impl DistributedRuntimeProvider for Component {
fn drt(&self) -> &DistributedRuntime {
&self.drt
}
}
impl RuntimeProvider for Component {
fn rt(&self) -> &Runtime {
self.drt.rt()
}
}
impl Component { impl Component {
pub fn etcd_path(&self) -> String { pub fn etcd_path(&self) -> String {
format!("{}/components/{}", self.namespace, self.name) format!("{}/components/{}", self.namespace, self.name)
...@@ -160,6 +172,18 @@ pub struct Endpoint { ...@@ -160,6 +172,18 @@ pub struct Endpoint {
name: String, name: String,
} }
impl DistributedRuntimeProvider for Endpoint {
fn drt(&self) -> &DistributedRuntime {
self.component.drt()
}
}
impl RuntimeProvider for Endpoint {
fn rt(&self) -> &Runtime {
self.component.rt()
}
}
impl Endpoint { impl Endpoint {
pub fn name(&self) -> &str { pub fn name(&self) -> &str {
&self.name &self.name
...@@ -206,6 +230,18 @@ pub struct Namespace { ...@@ -206,6 +230,18 @@ pub struct Namespace {
name: String, name: String,
} }
impl DistributedRuntimeProvider for Namespace {
fn drt(&self) -> &DistributedRuntime {
&self.runtime
}
}
impl RuntimeProvider for Namespace {
fn rt(&self) -> &Runtime {
self.runtime.rt()
}
}
impl Namespace { impl Namespace {
pub(crate) fn new(runtime: DistributedRuntime, name: String) -> Result<Self> { pub(crate) fn new(runtime: DistributedRuntime, name: String) -> Result<Self> {
Ok(NamespaceBuilder::default() Ok(NamespaceBuilder::default()
......
...@@ -41,7 +41,7 @@ impl EndpointConfigBuilder { ...@@ -41,7 +41,7 @@ impl EndpointConfigBuilder {
pub async fn start(self) -> Result<()> { pub async fn start(self) -> Result<()> {
let (endpoint, lease, handler) = self.build_internal()?.dissolve(); let (endpoint, lease, handler) = self.build_internal()?.dissolve();
let lease = lease.unwrap_or(endpoint.component.drt.primary_lease()); let lease = lease.unwrap_or(endpoint.drt().primary_lease());
tracing::debug!( tracing::debug!(
"Starting endpoint: {}", "Starting endpoint: {}",
......
...@@ -79,3 +79,23 @@ pub struct DistributedRuntime { ...@@ -79,3 +79,23 @@ pub struct DistributedRuntime {
// paths in etcd to a minimum. // paths in etcd to a minimum.
component_registry: component::Registry, component_registry: component::Registry,
} }
pub mod traits {
use super::*;
/// A trait for objects taht proivde access to the [Runtime]
pub trait RuntimeProvider {
fn rt(&self) -> &Runtime;
}
/// A trait for objects that provide access to the [DistributedRuntime].
pub trait DistributedRuntimeProvider {
fn drt(&self) -> &DistributedRuntime;
}
impl RuntimeProvider for DistributedRuntime {
fn rt(&self) -> &Runtime {
&self.runtime
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment