Skip to content

Commit d32ffad

Browse files
committed
refactor(grpc): drop empty messages for google.protobuf.Empty
Remove the empty StopVmResponse and ListVmsRequest messages; StopVm now returns google.protobuf.Empty and ListVms takes it. Codec/server updated to use Google.Protobuf.Empty. protoc resolves the well-known import with no extra include path.
1 parent fa7d349 commit d32ffad

4 files changed

Lines changed: 20 additions & 17 deletions

File tree

docs/grpc.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ create, stop, locate, and list microVMs.
88
> **v0 -- unstable.** The contract may change without notice during early
99
> development. Pin to a commit if you depend on it.
1010
11+
## VMs
12+
13+
With `Hyper` running, you can create a new `gRPC` client:
14+
15+
```python
16+
```
17+
1118
## The contract
1219

1320
The service is `hyper.grpc.v0.Hyper`, defined in

lib/hyper/grpc/codec.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ defmodule Hyper.Grpc.Codec do
88
or a `GRPC.RPCError` for the server to raise.
99
"""
1010

11+
alias Google.Protobuf.Empty
12+
1113
alias Hyper.Grpc.V0.{
1214
CreateVmRequest,
1315
CreateVmResponse,
1416
GetVmResponse,
1517
ListVmsResponse,
16-
StopVmResponse,
1718
Vm
1819
}
1920

@@ -84,8 +85,8 @@ defmodule Hyper.Grpc.Codec do
8485
def to_grpc({:vms, vms}),
8586
do: %ListVmsResponse{vms: Enum.map(vms, &vm/1)}
8687

87-
@spec to_grpc(:stopped) :: StopVmResponse.t()
88-
def to_grpc(:stopped), do: %StopVmResponse{}
88+
@spec to_grpc(:stopped) :: Empty.t()
89+
def to_grpc(:stopped), do: %Empty{}
8990

9091
@spec to_grpc({:error, term()}) :: GRPC.RPCError.t()
9192
def to_grpc({:error, reason}), do: rpc_error(reason)

lib/hyper/grpc/server.ex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ defmodule Hyper.Grpc.Server do
1212

1313
use GRPC.Server, service: Hyper.Grpc.V0.Hyper.Service
1414

15+
alias Google.Protobuf.Empty
1516
alias Hyper.Grpc.Codec
1617

1718
alias Hyper.Grpc.V0.{
1819
CreateVmRequest,
1920
CreateVmResponse,
2021
GetVmRequest,
2122
GetVmResponse,
22-
ListVmsRequest,
2323
ListVmsResponse,
24-
StopVmRequest,
25-
StopVmResponse
24+
StopVmRequest
2625
}
2726

2827
@spec create_vm(CreateVmRequest.t(), GRPC.Server.Stream.t()) :: CreateVmResponse.t()
@@ -39,7 +38,7 @@ defmodule Hyper.Grpc.Server do
3938
end
4039
end
4140

42-
@spec stop_vm(StopVmRequest.t(), GRPC.Server.Stream.t()) :: StopVmResponse.t()
41+
@spec stop_vm(StopVmRequest.t(), GRPC.Server.Stream.t()) :: Empty.t()
4342
def stop_vm(%StopVmRequest{vm_id: vm_id}, _stream) do
4443
Hyper.Node.FireVMM.State.stop(vm_id)
4544
Codec.to_grpc(:stopped)
@@ -55,8 +54,8 @@ defmodule Hyper.Grpc.Server do
5554
end
5655
end
5756

58-
@spec list_vms(ListVmsRequest.t(), GRPC.Server.Stream.t()) :: ListVmsResponse.t()
59-
def list_vms(%ListVmsRequest{}, _stream) do
57+
@spec list_vms(Empty.t(), GRPC.Server.Stream.t()) :: ListVmsResponse.t()
58+
def list_vms(%Empty{}, _stream) do
6059
Codec.to_grpc({:vms, Hyper.Cluster.Routing.all()})
6160
end
6261
end

proto/hyper/grpc/v0/hyper.proto

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ syntax = "proto3";
1414

1515
package hyper.grpc.v0;
1616

17+
import "google/protobuf/empty.proto";
18+
1719
// The VM lifecycle service.
1820
//
1921
// Errors are returned as standard gRPC statuses (see each RPC). Beyond the ones
@@ -40,7 +42,7 @@ service Hyper {
4042
// Errors:
4143
// NOT_FOUND -- no VM with this `vm_id` is running in the cluster.
4244
// UNAVAILABLE -- the VM's host node is unreachable.
43-
rpc StopVm(StopVmRequest) returns (StopVmResponse);
45+
rpc StopVm(StopVmRequest) returns (google.protobuf.Empty);
4446

4547
// Locate a microVM: report the cluster node it currently runs on.
4648
//
@@ -49,7 +51,7 @@ service Hyper {
4951
rpc GetVm(GetVmRequest) returns (GetVmResponse);
5052

5153
// List every microVM currently known to the cluster, across all nodes.
52-
rpc ListVms(ListVmsRequest) returns (ListVmsResponse);
54+
rpc ListVms(google.protobuf.Empty) returns (ListVmsResponse);
5355
}
5456

5557
// A fixed (vCPU, memory, disk) size, like a cloud instance class. Each step up
@@ -111,9 +113,6 @@ message StopVmRequest {
111113
string vm_id = 1;
112114
}
113115

114-
// Result of a successful StopVm. Intentionally empty.
115-
message StopVmResponse {}
116-
117116
// Request to locate a VM.
118117
message GetVmRequest {
119118
// The id of the VM to look up.
@@ -129,9 +128,6 @@ message GetVmResponse {
129128
string node = 2;
130129
}
131130

132-
// Request to list all VMs. Intentionally empty.
133-
message ListVmsRequest {}
134-
135131
// Result of ListVms.
136132
message ListVmsResponse {
137133
// Every VM known to the cluster, in no particular order.

0 commit comments

Comments
 (0)