Skip to content

Commit

Permalink
go/runtime/host: Add GetActiveVersion to Runtime interface
Browse files Browse the repository at this point in the history
  • Loading branch information
peternose committed Jan 23, 2024
1 parent e3a60f5 commit 8d1c466
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .changelog/5535.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/runtime/host: Add GetActiveVersion to Runtime interface
3 changes: 3 additions & 0 deletions go/runtime/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type Runtime interface {
// ID is the runtime identifier.
ID() common.Namespace

// GetActiveVersion retrieves the version of the currently active runtime.
GetActiveVersion() (*version.Version, error)

// GetInfo retrieves the runtime information.
GetInfo(ctx context.Context) (*protocol.RuntimeInfoResponse, error)

Expand Down
6 changes: 6 additions & 0 deletions go/runtime/host/loadbalance/loadbalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/logging"
"github.com/oasisprotocol/oasis-core/go/common/node"
"github.com/oasisprotocol/oasis-core/go/common/pubsub"
"github.com/oasisprotocol/oasis-core/go/common/version"
"github.com/oasisprotocol/oasis-core/go/runtime/host"
"github.com/oasisprotocol/oasis-core/go/runtime/host/protocol"
)
Expand Down Expand Up @@ -49,6 +50,11 @@ func (lb *lbRuntime) GetInfo(ctx context.Context) (*protocol.RuntimeInfoResponse
return lb.instances[0].GetInfo(ctx)
}

// Implements host.Runtime.
func (lb *lbRuntime) GetActiveVersion() (*version.Version, error) {
return lb.instances[0].GetActiveVersion()
}

// Implements host.Runtime.
func (lb *lbRuntime) GetCapabilityTEE() (*node.CapabilityTEE, error) {
// TODO: This won't work when registration of all client runtimes is required.
Expand Down
5 changes: 5 additions & 0 deletions go/runtime/host/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func (r *runtime) GetInfo(context.Context) (*protocol.RuntimeInfoResponse, error
}, nil
}

// Implements host.Runtime.
func (r *runtime) GetActiveVersion() (*version.Version, error) {
return nil, nil
}

// Implements host.Runtime.
func (r *runtime) GetCapabilityTEE() (*node.CapabilityTEE, error) {
return nil, nil
Expand Down
11 changes: 11 additions & 0 deletions go/runtime/host/multi/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ func (agg *Aggregate) getActiveHost() (*aggregatedHost, error) {
return agg.active, nil
}

// GetActiveVersion implements host.Runtime.
func (agg *Aggregate) GetActiveVersion() (*version.Version, error) {
agg.l.RLock()
defer agg.l.RUnlock()

if agg.active == nil {
return nil, ErrNoActiveVersion
}
return &agg.active.version, nil
}

// GetInfo implements host.Runtime.
func (agg *Aggregate) GetInfo(ctx context.Context) (*protocol.RuntimeInfoResponse, error) {
active, err := agg.getActiveHost()
Expand Down
16 changes: 16 additions & 0 deletions go/runtime/host/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ type sandboxedRuntime struct {
notifyUpdateCapabilityTEECh chan struct{}
capabilityTEE *node.CapabilityTEE

rtVersion *version.Version

logger *logging.Logger
}

Expand All @@ -133,6 +135,17 @@ func (r *sandboxedRuntime) ID() common.Namespace {
return r.id
}

// GetInfo implements host.Runtime.
func (r *sandboxedRuntime) GetActiveVersion() (*version.Version, error) {
r.RLock()
defer r.RUnlock()

if r.conn == nil {
return nil, errRuntimeNotReady
}
return r.rtVersion, nil
}

// Implements host.Runtime.
func (r *sandboxedRuntime) GetInfo(ctx context.Context) (*protocol.RuntimeInfoResponse, error) {
conn, err := r.getConnection(ctx)
Expand Down Expand Up @@ -418,6 +431,7 @@ func (r *sandboxedRuntime) startProcess() (err error) {
r.Lock()
r.conn = pc
r.capabilityTEE = ev.CapabilityTEE
r.rtVersion = rtVersion
r.Unlock()

// Notify subscribers that a runtime has been started.
Expand Down Expand Up @@ -462,6 +476,7 @@ func (r *sandboxedRuntime) handleAbortRequest(rq *abortRequest) error {
r.Lock()
r.conn = nil
r.capabilityTEE = nil
r.rtVersion = nil
r.Unlock()

// Notify subscribers that the runtime has stopped.
Expand Down Expand Up @@ -570,6 +585,7 @@ func (r *sandboxedRuntime) manager() {
r.Lock()
r.conn = nil
r.capabilityTEE = nil
r.rtVersion = nil
r.Unlock()

// Notify subscribers that the runtime has stopped.
Expand Down
13 changes: 13 additions & 0 deletions go/runtime/registry/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ func (n *RuntimeHostNode) WaitHostedRuntime(ctx context.Context) (host.RichRunti
return n.GetHostedRuntime(), nil
}

// GetHostedRuntimeActiveVersion returns the version of the active runtime.
func (n *RuntimeHostNode) GetHostedRuntimeActiveVersion() (*version.Version, error) {
n.Lock()
agg := n.agg
n.Unlock()

if agg == nil {
return nil, fmt.Errorf("runtime not available")
}

return agg.GetActiveVersion()
}

// GetHostedRuntimeCapabilityTEE returns the CapabilityTEE for the active runtime version.
func (n *RuntimeHostNode) GetHostedRuntimeCapabilityTEE() (*node.CapabilityTEE, error) {
n.Lock()
Expand Down

0 comments on commit 8d1c466

Please sign in to comment.