pub struct ServiceInstance {
pub service_name: String,
pub spec: ServiceSpec,
/* private fields */
}Expand description
Service instance manages a single service’s containers
Fields§
§service_name: String§spec: ServiceSpecImplementations§
Source§impl ServiceInstance
impl ServiceInstance
Sourcepub fn new(
service_name: String,
spec: ServiceSpec,
runtime: Arc<dyn Runtime + Send + Sync>,
overlay_manager: Option<Arc<RwLock<OverlayManager>>>,
) -> Self
pub fn new( service_name: String, spec: ServiceSpec, runtime: Arc<dyn Runtime + Send + Sync>, overlay_manager: Option<Arc<RwLock<OverlayManager>>>, ) -> Self
Create a new service instance
Sourcepub fn with_proxy(
service_name: String,
spec: ServiceSpec,
runtime: Arc<dyn Runtime + Send + Sync>,
overlay_manager: Option<Arc<RwLock<OverlayManager>>>,
proxy_manager: Arc<ProxyManager>,
) -> Self
pub fn with_proxy( service_name: String, spec: ServiceSpec, runtime: Arc<dyn Runtime + Send + Sync>, overlay_manager: Option<Arc<RwLock<OverlayManager>>>, proxy_manager: Arc<ProxyManager>, ) -> Self
Create a new service instance with proxy manager for health-aware load balancing
Sourcepub fn set_node_id(&mut self, node_id: u64)
pub fn set_node_id(&mut self, node_id: u64)
Set the local cluster node id. Used by ServiceManager to thread
Cluster::node_id() down to container construction so new
ContainerIds carry the owning node identity. Defaults to 0 (the
single-node sentinel) when unset.
Sourcepub fn role_for_replica(&self, replica_idx: u32) -> String
pub fn role_for_replica(&self, replica_idx: u32) -> String
Derive the replica group role for a 1-based replica_idx.
When spec.replica_groups is unset, returns "default" (the implicit
single-group case). Otherwise walks groups in declaration order,
accumulating each group’s count until replica_idx falls within the
current group’s range, and returns that group’s role.
Replicas beyond the declared total fall back to "default".
Sourcepub fn with_dns(self, dns_server: Arc<DnsServer>) -> Self
pub fn with_dns(self, dns_server: Arc<DnsServer>) -> Self
Builder method to add DNS server for service discovery
Sourcepub fn set_dns_server(&mut self, dns_server: Arc<DnsServer>)
pub fn set_dns_server(&mut self, dns_server: Arc<DnsServer>)
Set the DNS server for service discovery
Sourcepub fn set_proxy_manager(&mut self, proxy_manager: Arc<ProxyManager>)
pub fn set_proxy_manager(&mut self, proxy_manager: Arc<ProxyManager>)
Set the proxy manager for health-aware load balancing
Sourcepub fn set_health_states(
&mut self,
states: Arc<RwLock<HashMap<String, HealthState>>>,
)
pub fn set_health_states( &mut self, states: Arc<RwLock<HashMap<String, HealthState>>>, )
Set the shared health states map so health callbacks can bridge state back to ServiceManager
Sourcepub async fn last_pulled_digest(&self) -> Option<String>
pub async fn last_pulled_digest(&self) -> Option<String>
Get the last observed image digest (after the most recent successful
pull). Returns None when no pull has happened yet, when the runtime
does not expose digests, or when no matching ImageInfo was found.
Sourcepub async fn scale_to(&self, replicas: u32) -> Result<()>
pub async fn scale_to(&self, replicas: u32) -> Result<()>
Scale to the desired number of replicas
This method uses short-lived locks to avoid blocking concurrent operations. I/O operations (pull, create, start, stop, remove) are performed without holding the containers lock to allow other operations to proceed.
§Errors
Returns an error if image pull, container creation, or container lifecycle operations fail.
Sourcepub async fn replica_count(&self) -> usize
pub async fn replica_count(&self) -> usize
Get current number of replicas
Sourcepub async fn container_ids(&self) -> Vec<ContainerId>
pub async fn container_ids(&self) -> Vec<ContainerId>
Get all container IDs
Sourcepub async fn container_infos(&self) -> Vec<ContainerInfo>
pub async fn container_infos(&self) -> Vec<ContainerInfo>
Get per-container info (id, image, state, pid, overlay IP) for every live container in this instance.
Surfaces the REAL image reference each container was created from and its
REAL lifecycle state (lowercased via ContainerState::as_str) so the
API/ps no longer reports a hardcoded "running" with no image.
Sourcepub fn containers(&self) -> &RwLock<HashMap<ContainerId, Container>>
pub fn containers(&self) -> &RwLock<HashMap<ContainerId, Container>>
Get read access to the containers map
This allows callers to access container overlay IPs and other metadata without copying the entire map.
Sourcepub fn has_overlay_manager(&self) -> bool
pub fn has_overlay_manager(&self) -> bool
Check if this service instance has an overlay manager configured
Sourcepub fn has_proxy_manager(&self) -> bool
pub fn has_proxy_manager(&self) -> bool
Check if this service instance has a proxy manager configured
Sourcepub fn proxy_manager(&self) -> Option<&Arc<ProxyManager>>
pub fn proxy_manager(&self) -> Option<&Arc<ProxyManager>>
Get the proxy manager for this instance, if configured.
Sourcepub fn has_dns_server(&self) -> bool
pub fn has_dns_server(&self) -> bool
Check if this service instance has a DNS server configured
Auto Trait Implementations§
impl !Freeze for ServiceInstance
impl !RefUnwindSafe for ServiceInstance
impl !UnwindSafe for ServiceInstance
impl Send for ServiceInstance
impl Sync for ServiceInstance
impl Unpin for ServiceInstance
impl UnsafeUnpin for ServiceInstance
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Requestimpl<T> OptionalSend for T
impl<T> OptionalSync for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn propagate_header(self, header: HeaderName) -> PropagateHeader<Self>where
Self: Sized,
fn propagate_header(self, header: HeaderName) -> PropagateHeader<Self>where
Self: Sized,
Source§fn add_extension<T>(self, value: T) -> AddExtension<Self, T>where
Self: Sized,
fn add_extension<T>(self, value: T) -> AddExtension<Self, T>where
Self: Sized,
Source§fn map_request_body<F>(self, f: F) -> MapRequestBody<Self, F>where
Self: Sized,
fn map_request_body<F>(self, f: F) -> MapRequestBody<Self, F>where
Self: Sized,
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Source§fn compression(self) -> Compression<Self>where
Self: Sized,
fn compression(self) -> Compression<Self>where
Self: Sized,
Source§fn decompression(self) -> Decompression<Self>where
Self: Sized,
fn decompression(self) -> Decompression<Self>where
Self: Sized,
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
Source§fn sensitive_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>where
Self: Sized,
fn sensitive_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>where
Self: Sized,
Source§fn sensitive_request_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<Self>where
Self: Sized,
fn sensitive_request_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<Self>where
Self: Sized,
Source§fn sensitive_response_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveResponseHeaders<Self>where
Self: Sized,
fn sensitive_response_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveResponseHeaders<Self>where
Self: Sized,
Source§fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Source§fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Source§fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
Source§fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Source§fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Source§fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
Source§fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
Source§fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
x-request-id as the header name. Read moreSource§fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
Source§fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
x-request-id as the header name. Read moreSource§fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
500 Internal Server responses. Read moreSource§fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
413 Payload Too Large responses. Read more