Skip to content

Commit

Permalink
Add or update some API docs
Browse files Browse the repository at this point in the history
Some functions were undocumented, some of them had wrong docs or
typos, some of them needed a small update in docs after the
reload-on-configuration-change work.

Signed-off-by: Lorenzo Manacorda <lorenzo@kinvolk.io>
  • Loading branch information
Lorenzo Manacorda authored and krnowak committed Nov 7, 2017
1 parent 469db98 commit 6c5b5e5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions components/sup/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ impl Manager {
}
}

// Creates a rumor for the specified service.
fn gossip_latest_service_rumor(&self, service: &Service) {
let mut incarnation = 1;
{
Expand Down
5 changes: 4 additions & 1 deletion components/sup/src/manager/service/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl Cfg {
/// Updates the service configuration with data from a census group if the census group has
/// newer data than the current configuration.
///
/// Returns true if the configuration was updated.
/// Returns `true` if the configuration was updated.
pub fn update(&mut self, census_group: &CensusGroup) -> bool {
match census_group.service_config {
Some(ref config) => {
Expand Down Expand Up @@ -351,6 +351,7 @@ impl Serialize for Cfg {
}

#[derive(Debug)]
/// Renders configuration templates into config files.
pub struct CfgRenderer(TemplateRenderer);

impl CfgRenderer {
Expand Down Expand Up @@ -388,6 +389,8 @@ impl CfgRenderer {
}

/// Compile and write all configuration files to the configuration directory.
///
/// Returns `true` if the configuration has changed.
pub fn compile(&self, pkg: &Pkg, ctx: &RenderContext) -> Result<bool> {
// JW TODO: This function is loaded with IO errors that will be converted a Supervisor
// error resulting in the end-user not knowing what the fuck happned at all. We need to go
Expand Down
2 changes: 2 additions & 0 deletions components/sup/src/manager/service/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ pub trait Hook: fmt::Debug + Sized {
fn new(service_group: &ServiceGroup, render_pair: RenderPair) -> Self;

/// Compile a hook into its destination service directory.
///
/// Returns `true` if the hook has changed.
fn compile(&self, service_group: &ServiceGroup, ctx: &RenderContext) -> Result<bool> {
let content = self.renderer().render(Self::file_name(), ctx)?;
if write_hook(&content, self.path())? {
Expand Down
31 changes: 21 additions & 10 deletions components/sup/src/manager/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ impl Service {
self.supervisor.state_entered
}

/// Performs updates and executes hooks.
///
/// Returns `true` if the service was updated.
pub fn tick(&mut self, census_ring: &CensusRing, launcher: &LauncherCli) -> bool {
if !self.initialized {
if !self.all_binds_satisfied(census_ring) {
Expand Down Expand Up @@ -409,10 +412,10 @@ impl Service {
self.supervisor.state == ProcessState::Down
}

/// Compares the current state of the service to the current state of the census ring and
/// re-renders all templatable content to disk.
/// Compares the current state of the service to the current state of the census ring and the
/// user-config, and re-renders all templatable content to disk.
///
/// Returns true if any modifications were made.
/// Returns `true` if any modifications were made.
fn update_templates(&mut self, census_ring: &CensusRing) -> bool {
let census_group = census_ring.census_group_for(&self.service_group).expect(
"Service update failed; unable to find own service group",
Expand Down Expand Up @@ -448,7 +451,7 @@ impl Service {
cfg_changed
}

/// Replace the package of the running service and restart it's system process.
/// Replace the package of the running service and restart its system process.
pub fn update_package(&mut self, package: PackageInstall, launcher: &LauncherCli) {
match Pkg::from_install(package) {
Ok(pkg) => {
Expand Down Expand Up @@ -503,7 +506,7 @@ impl Service {
rumor
}

/// Run initialization hook if present
/// Run initialization hook if present.
fn initialize(&mut self) {
if self.initialized {
return;
Expand All @@ -519,8 +522,7 @@ impl Service {
}
}

/// Run reconfigure hook if present. Return false if it is not present, to trigger default
/// restart behavior.
/// Run reconfigure hook if present.
fn reconfigure(&mut self) {
self.needs_reconfiguration = false;
if let Some(ref hook) = self.hooks.reconfigure {
Expand Down Expand Up @@ -603,6 +605,8 @@ impl Service {
}

/// Helper for compiling configuration templates into configuration files.
///
/// Returns true if the configuration has changed.
fn compile_configuration(&self, ctx: &RenderContext) -> bool {
match self.config_renderer.compile(&self.pkg, ctx) {
Ok(true) => {
Expand All @@ -622,6 +626,8 @@ impl Service {
/// Helper for compiling hook templates into hooks.
///
/// This function will also perform any necessary post-compilation tasks.
///
/// Returns `true` if any hooks have changed.
fn compile_hooks(&self, ctx: &RenderContext) -> bool {
let changed = self.hooks.compile(&self.service_group, ctx);
if let Some(err) = self.copy_run().err() {
Expand Down Expand Up @@ -680,13 +686,14 @@ impl Service {
if self.needs_reload || self.process_down() || self.needs_reconfiguration {
self.reload(launcher);
if self.needs_reconfiguration {
// NOTE this only runs the hook if it's defined
self.reconfigure()
}
}
}
}

/// Run file_updated hook if present
/// Run file_updated hook if present.
fn file_updated(&self) -> bool {
if self.initialized {
if let Some(ref hook) = self.hooks.file_updated {
Expand All @@ -700,9 +707,11 @@ impl Service {
false
}

/// Write service files from gossip data to disk.
/// Write service files from gossip data to disk under
/// [`svc_files_path()`](../../fs/fn.svc_files_path.html).
///
/// Returns true if a file was changed, added, or removed, and false if there were no updates.
/// Returns `true` if a file was changed, added, or removed, and
/// `false` if there were no updates.
fn update_service_files(&mut self, census_ring: &CensusRing) -> bool {
let census_group = census_ring.census_group_for(&self.service_group).expect(
"Service update service files failed; unable to find own service group",
Expand Down Expand Up @@ -763,11 +772,13 @@ impl Service {
self.cache_health_check(check_result);
}

// Returns `false` if the write fails.
fn cache_service_file(&mut self, service_file: &ServiceFile) -> bool {
let file = self.pkg.svc_files_path.join(&service_file.filename);
self.write_cache_file(file, &service_file.body)
}

// Returns `false` if the write fails.
fn write_cache_file<T>(&self, file: T, contents: &[u8]) -> bool
where
T: AsRef<Path>,
Expand Down
3 changes: 3 additions & 0 deletions components/sup/src/manager/service_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ enum FollowerState {
Updating(Receiver<PackageInstall>),
}

/// The ServiceUpdater is in charge of updating a Service when a more recent version of a package
/// has been published to a depot or installed to the local package cache.
/// To use an update strategy, the supervisor must be configured to watch a depot for new versions.
pub struct ServiceUpdater {
states: UpdaterStateList,
butterfly: butterfly::Server,
Expand Down

0 comments on commit 6c5b5e5

Please sign in to comment.