Skip to content

Commit

Permalink
chore(bors): merge pull request openebs#714
Browse files Browse the repository at this point in the history
714: feat(eventing): state change events for node r=datacore-vvarakantham a=datacore-vvarakantham

Added node state change events.

Co-authored-by: Vandana Varakantham <[email protected]>
  • Loading branch information
mayastor-bors and datacore-vvarakantham committed Feb 15, 2024
2 parents 72cc1e1 + c1d0d1f commit b5eb259
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
30 changes: 29 additions & 1 deletion control-plane/agents/src/bin/core/node/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use crate::{
pool::wrapper::PoolWrapper,
NumRebuilds,
};
use agents::errors::SvcError;
use agents::{errors::SvcError, eventing::EventWithMeta};
use events_api::event::{EventAction, EventCategory, EventMessage, EventMeta, EventSource};
use grpc::operations::snapshot::SnapshotInfo;
use stor_port::{
transport_api::{Message, MessageId, ResourceKind},
Expand Down Expand Up @@ -409,6 +410,15 @@ impl NodeWrapper {
}

self.node_state.status = next;
self.event(
EventAction::StateChange,
event_meta(
self.id().to_string(),
previous.to_string(),
self.node_state.status.to_string(),
),
)
.generate();
if self.node_state.status == NodeStatus::Unknown {
self.watchdog_mut().disarm()
}
Expand Down Expand Up @@ -853,6 +863,24 @@ impl NodeWrapper {
}
}

// State change event for node
impl EventWithMeta for NodeWrapper {
fn event(&self, event_action: EventAction, meta: EventMeta) -> EventMessage {
EventMessage {
category: EventCategory::Node as i32,
action: event_action as i32,
target: self.id().to_string(),
metadata: Some(meta),
}
}
}

// Get event meta data for node state change event
fn event_meta(nodeid: String, previous: String, next: String) -> EventMeta {
let event_source = EventSource::new(nodeid).with_state_change_data(previous, next);
EventMeta::from_source(event_source)
}

/// Fetches node state from the dataplane.
#[derive(Debug, Clone)]
pub(crate) struct NodeStateFetcher {
Expand Down
2 changes: 1 addition & 1 deletion control-plane/agents/src/bin/ha/cluster/switchover.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{core_grpc, etcd::EtcdStore, nodes::NodeList};
use agents::Event;
use agents::eventing::Event;
use anyhow::anyhow;
use chrono::Utc;
use events_api::event::{
Expand Down
2 changes: 1 addition & 1 deletion control-plane/agents/src/bin/ha/node/detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
reporter::PathReporter,
Cli,
};
use agents::Event;
use agents::eventing::Event;
use events_api::event::{EventAction, EventCategory, EventMessage, EventMeta, EventSource};
use nvmeadm::nvmf_subsystem::Subsystem;
use std::{collections::HashMap, convert::From, rc::Rc, sync::Arc};
Expand Down
2 changes: 1 addition & 1 deletion control-plane/agents/src/bin/ha/node/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};
use agents::{
errors::{SvcError, SvcError::SubsystemNotFound},
EventWithMeta,
eventing::EventWithMeta,
};
use events_api::event::{EventAction, EventCategory, EventMessage, EventMeta, EventSource};
use grpc::{
Expand Down
19 changes: 19 additions & 0 deletions control-plane/agents/src/eventing/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use events_api::event::{EventAction, EventMessage, EventMeta};

/// Event trait definition for creating events.
pub trait Event {
/// Create event message.
fn event(&self, event_action: EventAction) -> EventMessage;
}

/// Event trait definition for creating events and adding meta data.
pub trait EventWithMeta {
/// Create event message with meta data.
fn event(&self, action: EventAction, meta: EventMeta) -> EventMessage;
}

/// A trait for generating event metadata.
pub trait EventMetaGen {
/// Create metadata to be included with the event.
fn meta(&self) -> EventMeta;
}
15 changes: 2 additions & 13 deletions control-plane/agents/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! It's meant to facilitate the creation of agents with a helper builder to
//! subscribe handlers for different message identifiers.
use events_api::event::{EventAction, EventMessage, EventMeta};
use futures::Future;
use grpc::tracing::OpenTelServer;
use snafu::Snafu;
Expand All @@ -14,6 +13,8 @@ use std::{net::SocketAddr, sync::Arc};
use stor_port::transport_api::ErrorChain;

mod common;
/// Event definitions.
pub mod eventing;

/// Agent level errors.
pub use common::errors;
Expand Down Expand Up @@ -172,15 +173,3 @@ impl<L> Service<L> {
configure(self).await
}
}

/// Event trait definition for creating events.
pub trait Event {
/// Create event message.
fn event(&self, event_action: EventAction) -> EventMessage;
}

/// Event trait definition for creating events and adding meta data.
pub trait EventWithMeta {
/// Create event message with meta data.
fn event(&self, action: EventAction, meta: EventMeta) -> EventMessage;
}

0 comments on commit b5eb259

Please sign in to comment.