Skip to content

Commit

Permalink
[spr] initial version
Browse files Browse the repository at this point in the history
Created using spr 1.3.6-beta.1
  • Loading branch information
sunshowers committed Aug 10, 2024
1 parent 106003e commit 017ec26
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 75 deletions.
4 changes: 1 addition & 3 deletions sled-agent/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::instance_manager::{
Error as ManagerError, InstanceManagerServices, InstanceTicket,
};
use crate::metrics::MetricsRequestQueue;
use crate::nexus::NexusClientWithResolver;
use crate::params::ZoneBundleMetadata;
use crate::params::{InstanceExternalIpBody, ZoneBundleCause};
use crate::params::{
Expand Down Expand Up @@ -349,7 +348,7 @@ struct InstanceRunner {
running_state: Option<RunningState>,

// Connection to Nexus
nexus_client: NexusClientWithResolver,
nexus_client: nexus_client::Client,

// Storage resources
storage: StorageHandle,
Expand Down Expand Up @@ -528,7 +527,6 @@ impl InstanceRunner {
);

self.nexus_client
.client()
.cpapi_instances_put(
&self.id().into_untyped_uuid(),
&state.into(),
Expand Down
7 changes: 3 additions & 4 deletions sled-agent/src/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use crate::instance::propolis_zone_name;
use crate::instance::Instance;
use crate::metrics::MetricsRequestQueue;
use crate::nexus::NexusClientWithResolver;
use crate::params::InstanceExternalIpBody;
use crate::params::InstanceMetadata;
use crate::params::ZoneBundleMetadata;
Expand Down Expand Up @@ -74,7 +73,7 @@ pub enum Error {
}

pub(crate) struct InstanceManagerServices {
pub nexus_client: NexusClientWithResolver,
pub nexus_client: nexus_client::Client,
pub vnic_allocator: VnicAllocator<Etherstub>,
pub port_manager: PortManager,
pub storage: StorageHandle,
Expand Down Expand Up @@ -103,7 +102,7 @@ impl InstanceManager {
#[allow(clippy::too_many_arguments)]
pub fn new(
log: Logger,
nexus_client: NexusClientWithResolver,
nexus_client: nexus_client::Client,
etherstub: Etherstub,
port_manager: PortManager,
storage: StorageHandle,
Expand Down Expand Up @@ -422,7 +421,7 @@ struct InstanceManagerRunner {
terminate_tx: mpsc::UnboundedSender<InstanceDeregisterRequest>,
terminate_rx: mpsc::UnboundedReceiver<InstanceDeregisterRequest>,

nexus_client: NexusClientWithResolver,
nexus_client: nexus_client::Client,

// TODO: If we held an object representing an enum of "Created OR Running"
// instance, we could avoid the methods within "instance.rs" that panic
Expand Down
73 changes: 20 additions & 53 deletions sled-agent/src/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,29 @@ use tokio::sync::{broadcast, mpsc, oneshot, Notify};
use tokio::time::{interval, Duration, MissedTickBehavior};
use uuid::Uuid;

/// A thin wrapper over a progenitor-generated NexusClient.
///
/// Also attaches the "DNS resolver" for historical reasons.
#[derive(Clone)]
pub struct NexusClientWithResolver {
client: NexusClient,
pub(crate) fn make_nexus_client(
log: &Logger,
resolver: Arc<Resolver>,
) -> Result<NexusClient, ResolveError> {
make_nexus_client_with_port(log, resolver, NEXUS_INTERNAL_PORT)
}

impl NexusClientWithResolver {
pub fn new(
log: &Logger,
resolver: Arc<Resolver>,
) -> Result<Self, ResolveError> {
Ok(Self::new_from_resolver_with_port(
log,
resolver,
NEXUS_INTERNAL_PORT,
))
}

pub fn new_from_resolver_with_port(
log: &Logger,
resolver: Arc<Resolver>,
port: u16,
) -> Self {
let client = reqwest::ClientBuilder::new()
.dns_resolver(resolver.clone())
.build()
.expect("Failed to build client");

let dns_name = ServiceName::Nexus.srv_name();
Self {
client: NexusClient::new_with_client(
&format!("http://{dns_name}:{port}"),
client,
log.new(o!("component" => "NexusClient")),
),
resolver,
}
}

/// Access the progenitor-based Nexus Client.
pub fn client(&self) -> &NexusClient {
&self.client
}

/// Access the DNS resolver used by the Nexus Client.
///
/// WARNING: If you're using this resolver to access an IP address of
/// another service, be aware that it might change if that service moves
/// around! Be cautious when accessing and persisting IP addresses of other
/// services.
pub fn resolver(&self) -> &Arc<Resolver> {
&self.resolver
}
pub(crate) fn make_nexus_client_with_port(
log: &Logger,
resolver: Arc<Resolver>,
port: u16,
) -> Result<NexusClient, ResolveError> {
let client = reqwest::ClientBuilder::new()
.dns_resolver(resolver)
.build()
.expect("Failed to build client");

let dns_name = ServiceName::Nexus.srv_name();
Ok(NexusClient::new_with_client(
&format!("http://{dns_name}:{port}"),
client,
log.new(o!("component" => "NexusClient")),
))
}

pub fn d2n_params(
Expand Down
7 changes: 2 additions & 5 deletions sled-agent/src/probe_manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::metrics::MetricsRequestQueue;
use crate::nexus::NexusClientWithResolver;
use anyhow::{anyhow, Result};
use illumos_utils::dladm::Etherstub;
use illumos_utils::link::VnicAllocator;
Expand Down Expand Up @@ -54,7 +53,7 @@ struct RunningProbes {

pub(crate) struct ProbeManagerInner {
join_handle: Mutex<Option<JoinHandle<()>>>,
nexus_client: NexusClientWithResolver,
nexus_client: nexus_client::Client,
log: Logger,
sled_id: Uuid,
vnic_allocator: VnicAllocator<Etherstub>,
Expand All @@ -67,7 +66,7 @@ pub(crate) struct ProbeManagerInner {
impl ProbeManager {
pub(crate) fn new(
sled_id: Uuid,
nexus_client: NexusClientWithResolver,
nexus_client: nexus_client::Client,
etherstub: Etherstub,
storage: StorageHandle,
port_manager: PortManager,
Expand Down Expand Up @@ -248,7 +247,6 @@ impl ProbeManagerInner {
if n_added > 0 {
if let Err(e) = self
.nexus_client
.client()
.bgtask_activate(&BackgroundTasksActivateRequest {
bgtask_names: vec!["vpc_route_manager".into()],
})
Expand Down Expand Up @@ -439,7 +437,6 @@ impl ProbeManagerInner {
async fn target_state(self: &Arc<Self>) -> Result<HashSet<ProbeState>> {
Ok(self
.nexus_client
.client()
.probes_get(
&self.sled_id,
None, //limit
Expand Down
6 changes: 3 additions & 3 deletions sled-agent/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::http_entrypoints::api as http_api;
use super::sled_agent::SledAgent;
use crate::bootstrap::params::StartSledAgentRequest;
use crate::long_running_tasks::LongRunningTaskHandles;
use crate::nexus::NexusClientWithResolver;
use crate::nexus::make_nexus_client;
use crate::services::ServiceManager;
use internal_dns::resolver::Resolver;
use slog::Logger;
Expand Down Expand Up @@ -52,8 +52,8 @@ impl Server {
.map_err(|e| e.to_string())?,
);

let nexus_client = NexusClientWithResolver::new(&log, resolver)
.map_err(|e| e.to_string())?;
let nexus_client =
make_nexus_client(&log, resolver).map_err(|e| e.to_string())?;

let sled_agent = SledAgent::new(
&config,
Expand Down
12 changes: 5 additions & 7 deletions sled-agent/src/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use crate::instance_manager::InstanceManager;
use crate::long_running_tasks::LongRunningTaskHandles;
use crate::metrics::MetricsManager;
use crate::nexus::{
NexusClientWithResolver, NexusNotifierHandle, NexusNotifierInput,
NexusNotifierTask,
NexusNotifierHandle, NexusNotifierInput, NexusNotifierTask,
};
use crate::params::{
DiskStateRequested, InstanceExternalIpBody, InstanceHardware,
Expand Down Expand Up @@ -320,7 +319,7 @@ struct SledAgentInner {
services: ServiceManager,

// Connection to Nexus.
nexus_client: NexusClientWithResolver,
nexus_client: nexus_client::Client,

// A mechanism for notifiying nexus about sled-agent updates
nexus_notifier: NexusNotifierHandle,
Expand Down Expand Up @@ -365,7 +364,7 @@ impl SledAgent {
pub async fn new(
config: &Config,
log: Logger,
nexus_client: NexusClientWithResolver,
nexus_client: nexus_client::Client,
request: StartSledAgentRequest,
services: ServiceManager,
long_running_task_handles: LongRunningTaskHandles,
Expand Down Expand Up @@ -552,7 +551,7 @@ impl SledAgent {
let nexus_notifier_input = NexusNotifierInput {
sled_id: request.body.id,
sled_address: get_sled_address(request.body.subnet),
nexus_client: nexus_client.client().clone(),
nexus_client: nexus_client.clone(),
hardware: long_running_task_handles.hardware_manager.clone(),
vmm_reservoir_manager: vmm_reservoir_manager.clone(),
};
Expand Down Expand Up @@ -688,7 +687,6 @@ impl SledAgent {

self.inner
.nexus_client
.client()
.sled_firewall_rules_request(&sled_id)
.await
.map_err(|err| Error::FirewallRequest(err))?;
Expand Down Expand Up @@ -1074,7 +1072,7 @@ impl SledAgent {
) -> Result<(), Error> {
self.inner
.updates
.download_artifact(artifact, &self.inner.nexus_client.client())
.download_artifact(artifact, &self.inner.nexus_client)
.await?;
Ok(())
}
Expand Down

0 comments on commit 017ec26

Please sign in to comment.