Skip to content

Commit

Permalink
feat(eventing): nexus child events
Browse files Browse the repository at this point in the history
Signed-off-by: Vandana Varakantham <[email protected]>
  • Loading branch information
datacore-vvarakantham committed Nov 10, 2023
1 parent 49495cc commit a07260e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions io-engine/src/eventing/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod nexus_child_events;
pub(crate) mod nexus_events;
mod pool_events;
mod replica_events;
Expand Down
41 changes: 41 additions & 0 deletions io-engine/src/eventing/nexus_child_events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use events_api::event::{
EventAction,
EventCategory,
EventMessage,
EventMeta,
EventSource,
};

use mayastor_api::v1::nexus::{AddChildNexusRequest, RemoveChildNexusRequest};

use crate::{core::MayastorEnvironment, eventing::Event};

// Nexus child added event message.
impl Event for AddChildNexusRequest {
fn event(&self, event_action: EventAction) -> EventMessage {
let event_source = EventSource::new(
MayastorEnvironment::global_or_default().node_name,
).with_nexus_child_data(&self.uri);
EventMessage {
category: EventCategory::Nexus as i32,
action: event_action as i32,
target: self.uuid.clone(),
metadata: Some(EventMeta::from_source(event_source)),
}
}
}

// Nexus child removed event message.
impl Event for RemoveChildNexusRequest {
fn event(&self, event_action: EventAction) -> EventMessage {
let event_source = EventSource::new(
MayastorEnvironment::global_or_default().node_name,
).with_nexus_child_data(&self.uri);
EventMessage {
category: EventCategory::Nexus as i32,
action: event_action as i32,
target: self.uuid.clone(),
metadata: Some(EventMeta::from_source(event_source)),
}
}
}
6 changes: 6 additions & 0 deletions io-engine/src/grpc/v1/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,14 @@ impl NexusRpc for NexusService {
let ctx = GrpcClientContext::new(&request, function_name!());
let args = request.into_inner();

let event = args.event(EventAction::AddChild);

self.serialized(ctx, args.uuid.clone(), false, async move {
let rx = rpc_submit::<_, _, nexus::Error>(async move {
trace!("{:?}", args);
let nexus = nexus_add_child(&args).await?;
info!("Added child to nexus {}", args.uuid);
event.generate();
Ok(nexus)
})?;

Expand All @@ -588,6 +591,8 @@ impl NexusRpc for NexusService {
let ctx = GrpcClientContext::new(&request, function_name!());
let args = request.into_inner();

let event = args.clone().event(EventAction::RemoveChild);

self.serialized(ctx, args.uuid.clone(), false, async move {
let rx = rpc_submit::<_, _, nexus::Error>(async move {
trace!("{:?}", args);
Expand All @@ -601,6 +606,7 @@ impl NexusRpc for NexusService {
"Removed child {} from nexus {}",
args.uri, args.uuid
);
event.generate();
}
Ok(nexus_lookup(&args.uuid)?.into_grpc().await)
})?;
Expand Down

0 comments on commit a07260e

Please sign in to comment.