Skip to content

Commit

Permalink
go/control/api: Add bundle status to GetStatus output
Browse files Browse the repository at this point in the history
  • Loading branch information
peternose committed Dec 7, 2024
1 parent 0317959 commit 5ac1055
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
36 changes: 36 additions & 0 deletions go/control/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
"github.com/oasisprotocol/oasis-core/go/common/errors"
"github.com/oasisprotocol/oasis-core/go/common/node"
"github.com/oasisprotocol/oasis-core/go/common/version"
"github.com/oasisprotocol/oasis-core/go/config"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
p2p "github.com/oasisprotocol/oasis-core/go/p2p/api"
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
block "github.com/oasisprotocol/oasis-core/go/roothash/api/block"
"github.com/oasisprotocol/oasis-core/go/runtime/bundle/component"
storage "github.com/oasisprotocol/oasis-core/go/storage/api"
upgrade "github.com/oasisprotocol/oasis-core/go/upgrade/api"
commonWorker "github.com/oasisprotocol/oasis-core/go/worker/common/api"
Expand Down Expand Up @@ -85,6 +87,9 @@ type Status struct {
// Runtimes is the status overview for each runtime supported by the node.
Runtimes map[common.Namespace]RuntimeStatus `json:"runtimes,omitempty"`

// Bundles is the status overview of known runtime bundles.
Bundles []BundleStatus `json:"bundles,omitempty"`

// Registration is the node's registration status.
Registration *RegistrationStatus `json:"registration,omitempty"`

Expand Down Expand Up @@ -188,6 +193,37 @@ type RuntimeStatus struct {
Provisioner string `json:"provisioner,omitempty"`
}

// BundleStatus is the per-runtime bundle status overview.
type BundleStatus struct {
// Name is the optional human readable runtime name.
Name string `json:"name,omitempty"`

// ID is the runtime identifier.
ID common.Namespace `json:"id"`

// Components contains statuses of the runtime components.
Components []ComponentStatus `json:"components,omitempty"`
}

// ComponentStatus is the component status overview.
type ComponentStatus struct {
// Kind is the component kind.
Kind component.Kind `json:"kind"`

// Name is the name of the component.
Name string `json:"name,omitempty"`

// Version is the component version.
Version version.Version `json:"version,omitempty"`

// Detached specifies whether the component was in a detached bundled.
Detached bool `json:"detached,omitempty"`

// Disabled specifies whether the component is disabled by default
// and needs to be explicitly enabled via node configuration to be used.
Disabled bool `json:"disabled,omitempty"`
}

// SeedStatus is the status of the seed node.
type SeedStatus struct {
// ChainContext is the chain domain separation context.
Expand Down
41 changes: 41 additions & 0 deletions go/oasis-node/cmd/node/node_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ func (n *Node) GetStatus(ctx context.Context) (*control.Status, error) {
return nil, fmt.Errorf("failed to get runtime status: %w", err)
}

bundles, err := n.getBundleStatus()
if err != nil {
return nil, fmt.Errorf("failed to get bundle status: %w", err)
}

kms, err := n.getKeymanagerStatus()
if err != nil {
return nil, fmt.Errorf("failed to get key manager worker status: %w", err)
Expand Down Expand Up @@ -165,6 +170,7 @@ func (n *Node) GetStatus(ctx context.Context) (*control.Status, error) {
Consensus: cs,
LightClient: lcs,
Runtimes: runtimes,
Bundles: bundles,
Keymanager: kms,
Registration: rs,
PendingUpgrades: pendingUpgrades,
Expand Down Expand Up @@ -347,6 +353,41 @@ func (n *Node) getRuntimeStatus(ctx context.Context) (map[common.Namespace]contr
return runtimes, nil
}

func (n *Node) getBundleStatus() ([]control.BundleStatus, error) {
bundleRegistry := n.RuntimeRegistry.GetBundleRegistry()
manifests := bundleRegistry.GetManifests()
bundles := make([]control.BundleStatus, 0, len(manifests))

for _, manifest := range manifests {
explodedComponents, err := bundleRegistry.GetComponents(manifest.ID, manifest.GetVersion())
if err != nil {
return nil, err
}

components := make([]control.ComponentStatus, 0, len(explodedComponents))
for _, comp := range explodedComponents {
component := control.ComponentStatus{
Kind: comp.Kind,
Name: comp.Name,
Version: comp.Version,
Detached: comp.Detached,
Disabled: comp.Disabled,
}
components = append(components, component)
}

bundle := control.BundleStatus{
Name: manifest.Name,
ID: manifest.ID,
Components: components,
}

bundles = append(bundles, bundle)
}

return bundles, nil
}

func (n *Node) getKeymanagerStatus() (*keymanagerWorker.Status, error) {
if n.KeymanagerWorker == nil || !n.KeymanagerWorker.Enabled() {
return nil, nil
Expand Down
18 changes: 18 additions & 0 deletions go/runtime/bundle/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ func (m *Manifest) GetComponentByID(id component.ID) *Component {
return nil
}

// GetVersion returns the runtime version.
func (m *Manifest) GetVersion() version.Version {
// We also support legacy manifests which define version at the top-level.
for _, comp := range m.Components {
if !comp.ID().IsRONL() {
continue
}

if comp.Version.ToU64() > m.Version.ToU64() {
return comp.Version
}

break
}

return m.Version
}

// SGXMetadata is the SGX specific manifest metadata.
type SGXMetadata struct {
// Executable is the name of the SGX enclave executable file.
Expand Down
8 changes: 8 additions & 0 deletions go/runtime/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type Registry interface {

// FinishInitialization finalizes setup for all runtimes.
FinishInitialization() error

// GetBundleRegistry returns the bundle registry.
GetBundleRegistry() bundle.Registry
}

// Runtime is the running node's supported runtime interface.
Expand Down Expand Up @@ -626,6 +629,11 @@ func (r *runtimeRegistry) FinishInitialization() error {
return nil
}

// GetBundleRegistry implements Registry.
func (r *runtimeRegistry) GetBundleRegistry() bundle.Registry {
return r.bundleRegistry
}

// Name implements BackgroundService.
func (r *runtimeRegistry) Name() string {
return "runtime registry"
Expand Down

0 comments on commit 5ac1055

Please sign in to comment.