Skip to content

Commit

Permalink
bit less overengineered
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Jul 26, 2024
1 parent 3f3a18d commit d63ceb9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
32 changes: 11 additions & 21 deletions sled-agent/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,8 @@ pub enum Error {
#[error("Instance dropped our request")]
RequestDropped(#[from] oneshot::error::RecvError),

#[error(transparent)]
Terminating(#[from] Terminating),
}

#[derive(thiserror::Error, Debug)]
#[error("Instance is terminating")]
pub struct Terminating(());

impl From<Terminating> for ManagerError {
fn from(t: Terminating) -> Self {
Self::Instance(t.into())
}
#[error("Instance is terminating")]
Terminating,
}

// Issues read-only, idempotent HTTP requests at propolis until it responds with
Expand Down Expand Up @@ -501,30 +491,30 @@ impl InstanceRunner {
// instead of bailing out, since we still need to drain the rest of
// the queue,
let _ = match request {
RequestZoneBundle { tx } => {
tx.send(Err(Terminating(()).into())).map_err(|_| ())
}
RequestZoneBundle { tx } => tx
.send(Err(BundleError::InstanceTerminating))
.map_err(|_| ()),
GetFilesystemPool { tx } => tx.send(None).map_err(|_| ()),
CurrentState { tx } => {
tx.send(self.current_state()).map_err(|_| ())
}
PutState { tx, .. } => {
tx.send(Err(Terminating(()).into())).map_err(|_| ())
tx.send(Err(Error::Terminating.into())).map_err(|_| ())
}
PutMigrationIds { tx, .. } => {
tx.send(Err(Terminating(()).into())).map_err(|_| ())
tx.send(Err(Error::Terminating.into())).map_err(|_| ())
}
Terminate { tx, .. } => {
tx.send(Err(Terminating(()).into())).map_err(|_| ())
tx.send(Err(Error::Terminating.into())).map_err(|_| ())
}
IssueSnapshotRequest { tx, .. } => {
tx.send(Err(Terminating(()).into())).map_err(|_| ())
tx.send(Err(Error::Terminating.into())).map_err(|_| ())
}
AddExternalIp { tx, .. } => {
tx.send(Err(Terminating(()).into())).map_err(|_| ())
tx.send(Err(Error::Terminating.into())).map_err(|_| ())
}
DeleteExternalIp { tx, .. } => {
tx.send(Err(Terminating(()).into())).map_err(|_| ())
tx.send(Err(Error::Terminating.into())).map_err(|_| ())
}
};
}
Expand Down
16 changes: 9 additions & 7 deletions sled-agent/src/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ impl From<Error> for dropshot::HttpError {
// Progenitor client error it gets back.
HttpError::from(omicron_error)
}
crate::instance::Error::Terminating(t) => {
crate::instance::Error::Terminating => {
HttpError::for_client_error(
Some(NO_SUCH_INSTANCE.to_string()),
http::StatusCode::GONE,
t.to_string(),
instance_error.to_string(),
)
}
e => HttpError::for_internal_error(e.to_string()),
Expand All @@ -239,11 +239,13 @@ impl From<Error> for dropshot::HttpError {
| BundleError::InvalidCleanupPeriod => {
HttpError::for_bad_request(None, inner.to_string())
}
BundleError::Terminating(t) => HttpError::for_client_error(
Some(NO_SUCH_INSTANCE.to_string()),
http::StatusCode::GONE,
t.to_string(),
),
BundleError::InstanceTerminating => {
HttpError::for_client_error(
Some(NO_SUCH_INSTANCE.to_string()),
http::StatusCode::GONE,
inner.to_string(),
)
}
_ => HttpError::for_internal_error(err.to_string()),
},
e => HttpError::for_internal_error(e.to_string()),
Expand Down
4 changes: 2 additions & 2 deletions sled-agent/src/zone_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,8 @@ pub enum BundleError {
#[error("Failed to get ZFS property value")]
GetProperty(#[from] GetValueError),

#[error(transparent)]
Terminating(#[from] crate::instance::Terminating),
#[error("Instance is terminating")]
InstanceTerminating,
}

// Helper function to write an array of bytes into the tar archive, with
Expand Down

0 comments on commit d63ceb9

Please sign in to comment.