Skip to content

Commit

Permalink
expose container deploy status and node cpu usage
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Dec 4, 2018
1 parent cde52c9 commit af9c7d5
Show file tree
Hide file tree
Showing 9 changed files with 617 additions and 458 deletions.
601 changes: 319 additions & 282 deletions rpc/gen/core.pb.go

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions rpc/gen/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ message Node {
string endpoint = 2;
string podname = 3;
map<string, int32> cpu = 4;
int64 memory = 5;
string info = 6;
double cpu_used= 5;
int64 memory = 6;
bool available = 7;
map<string, string> labels = 8;
int64 init_memory = 9;
map<string, int32> init_cpu = 10;
string info = 11;
}

message Nodes {
Expand All @@ -125,6 +128,7 @@ message Container {
map<string, string> publish = 10;
string image = 11;
bytes inspect = 12;
bytes status_data = 13;
}

message ContainerDeployedOptions {
Expand Down
373 changes: 225 additions & 148 deletions rpc/gen/core_pb2.py

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions rpc/gen/core_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def __init__(self, channel):
request_serializer=core__pb2.GetPodOptions.SerializeToString,
response_deserializer=core__pb2.Pod.FromString,
)
self.GetPodResource = channel.unary_unary(
'/pb.CoreRPC/GetPodResource',
request_serializer=core__pb2.GetPodOptions.SerializeToString,
response_deserializer=core__pb2.PodResource.FromString,
)
self.AddNode = channel.unary_unary(
'/pb.CoreRPC/AddNode',
request_serializer=core__pb2.AddNodeOptions.SerializeToString,
Expand Down Expand Up @@ -94,11 +99,6 @@ def __init__(self, channel):
request_serializer=core__pb2.ContainerDeployedOptions.SerializeToString,
response_deserializer=core__pb2.Empty.FromString,
)
self.GetPodResource = channel.unary_unary(
'/pb.CoreRPC/GetPodResource',
request_serializer=core__pb2.GetPodOptions.SerializeToString,
response_deserializer=core__pb2.PodResource.FromString,
)
self.Copy = channel.unary_stream(
'/pb.CoreRPC/Copy',
request_serializer=core__pb2.CopyOptions.SerializeToString,
Expand Down Expand Up @@ -183,6 +183,13 @@ def GetPod(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def GetPodResource(self, request, context):
# missing associated documentation comment in .proto file
pass
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def AddNode(self, request, context):
# missing associated documentation comment in .proto file
pass
Expand Down Expand Up @@ -267,13 +274,6 @@ def ContainerDeployed(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def GetPodResource(self, request, context):
# missing associated documentation comment in .proto file
pass
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def Copy(self, request, context):
# missing associated documentation comment in .proto file
pass
Expand Down Expand Up @@ -367,6 +367,11 @@ def add_CoreRPCServicer_to_server(servicer, server):
request_deserializer=core__pb2.GetPodOptions.FromString,
response_serializer=core__pb2.Pod.SerializeToString,
),
'GetPodResource': grpc.unary_unary_rpc_method_handler(
servicer.GetPodResource,
request_deserializer=core__pb2.GetPodOptions.FromString,
response_serializer=core__pb2.PodResource.SerializeToString,
),
'AddNode': grpc.unary_unary_rpc_method_handler(
servicer.AddNode,
request_deserializer=core__pb2.AddNodeOptions.FromString,
Expand Down Expand Up @@ -427,11 +432,6 @@ def add_CoreRPCServicer_to_server(servicer, server):
request_deserializer=core__pb2.ContainerDeployedOptions.FromString,
response_serializer=core__pb2.Empty.SerializeToString,
),
'GetPodResource': grpc.unary_unary_rpc_method_handler(
servicer.GetPodResource,
request_deserializer=core__pb2.GetPodOptions.FromString,
response_serializer=core__pb2.PodResource.SerializeToString,
),
'Copy': grpc.unary_stream_rpc_method_handler(
servicer.Copy,
request_deserializer=core__pb2.CopyOptions.FromString,
Expand Down
20 changes: 12 additions & 8 deletions rpc/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ func toRPCNode(ctx context.Context, n *types.Node) *pb.Node {
}

return &pb.Node{
Name: n.Name,
Endpoint: n.Endpoint,
Podname: n.Podname,
Available: n.Available,
Cpu: toRPCCPUMap(n.CPU),
Memory: n.MemCap,
Labels: n.Labels,
Info: nodeInfo,
Name: n.Name,
Endpoint: n.Endpoint,
Podname: n.Podname,
Cpu: toRPCCPUMap(n.CPU),
CpuUsed: n.CPUUsage,
Memory: n.MemCap,
Available: n.Available,
Labels: n.Labels,
InitCpu: toRPCCPUMap(n.InitCPU),
InitMemory: n.InitMemCap,
Info: nodeInfo,
}
}

Expand Down Expand Up @@ -348,5 +351,6 @@ func toRPCContainer(ctx context.Context, c *types.Container) (*pb.Container, err
Image: info.Config.Image,
Labels: info.Config.Labels,
Inspect: bytes,
StatusData: c.StatusData,
}, nil
}
12 changes: 12 additions & 0 deletions store/etcdv3/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ func (m *Mercury) bindNodeMeta(ctx context.Context, container *types.Container)
return nil, err
}

appname, entrypoint, _, err := utils.ParseContainerName(container.Name)
if err != nil {
return nil, err
}

key := filepath.Join(containerDeployPrefix, appname, entrypoint, node.Name, container.ID)
ev, err := m.GetOne(ctx, key)
if err != nil {
return nil, err
}

container.StatusData = ev.Value
container.Engine = node.Engine
container.HostIP = node.GetIP()
return container, nil
Expand Down
24 changes: 24 additions & 0 deletions store/etcdv3/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,28 @@ func TestContainer(t *testing.T) {
}
}()
assert.NoError(t, m.RemoveContainer(ctx, container))
// bindNodeMeta
testC := &types.Container{
Podname: "t",
Nodename: "x",
}
// failed by GetNode
_, err = m.bindNodeMeta(ctx, testC)
assert.Error(t, err)
testC.Nodename = nodename
testC.Podname = podname
// failed by ParseContainerName
_, err = m.bindNodeMeta(ctx, testC)
assert.Error(t, err)
// failed by GetOne
testC.Name = name
_, err = m.bindNodeMeta(ctx, testC)
assert.Error(t, err)
// correct
testC.ID = ID
key := filepath.Join(containerDeployPrefix, appname, entrypoint, nodename, ID)
_, err = m.Put(ctx, key, "")
assert.NoError(t, err)
_, err = m.bindNodeMeta(ctx, testC)
assert.NoError(t, err)
}
1 change: 1 addition & 0 deletions types/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Container struct {
Hook *Hook `json:"hook"`
Privileged bool `json:"privileged"`
SoftLimit bool `json:"softlimit"`
StatusData []byte `json:"-"`
Engine engineapi.APIClient `json:"-"`
HostIP string `json:"-"`
}
Expand Down
2 changes: 1 addition & 1 deletion types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ type Node struct {
Name string `json:"name"`
Endpoint string `json:"endpoint"`
Podname string `json:"podname"`
Available bool `json:"available"`
CPU CPUMap `json:"cpu"`
CPUUsage float64 `json:"cpuusage"`
MemCap int64 `json:"memcap"`
Available bool `json:"available"`
Labels map[string]string `json:"labels"`
InitCPU CPUMap `json:"init_cpu"`
InitMemCap int64 `json:"init_memcap"`
Expand Down

0 comments on commit af9c7d5

Please sign in to comment.