Skip to content

Commit

Permalink
Merge branch 'master' of gitlab.ricebook.net:platform/core
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Sep 1, 2016
2 parents 2636ce9 + 39ec890 commit e177ca5
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 135 deletions.
4 changes: 4 additions & 0 deletions cluster/calcium/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (c *calcium) ListPodNodes(podname string) ([]*types.Node, error) {
return c.store.GetNodesByPod(podname)
}

func (c *calcium) ListPodNodeNames(podname string) ([]string, error) {
return c.store.GetNodeNamesByPod(podname)
}

func (c *calcium) GetContainer(id string) (*types.Container, error) {
return c.store.GetContainer(id)
}
Expand Down
1 change: 1 addition & 0 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Cluster interface {
AddNode(nodename, endpoint, podname, cafile, certfile, keyfile string, public bool) (*types.Node, error)
GetNode(podname, nodename string) (*types.Node, error)
ListPodNodes(podname string) ([]*types.Node, error)
ListPodNodeNames(podname string) ([]string, error)
GetContainer(id string) (*types.Container, error)
GetContainers(ids []string) ([]*types.Container, error)

Expand Down
17 changes: 17 additions & 0 deletions devtools/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ def get_pod_nodes(ctx, name):
click.echo(node)


@cli.command('pod:nodenames')
@click.argument('name')
@click.pass_context
def get_pod_node_names(ctx, name):
stub = _get_stub(ctx)
opts = pb.ListNodesOptions(podname=name)

try:
r = stub.ListPodNodeNames(opts, 5)
except AbortionError as e:
click.echo(click.style('abortion error: %s' % e.details, fg='red', bold=True))
ctx.exit(-1)

for name in r.names:
click.echo(name)


@cli.command('node:get')
@click.argument('podname')
@click.argument('nodename')
Expand Down
147 changes: 106 additions & 41 deletions devtools/core_pb2.py

Large diffs are not rendered by default.

234 changes: 140 additions & 94 deletions rpc/gen/core.pb.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions rpc/gen/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ service CoreRPC {
rpc AddNode(AddNodeOptions) returns (Node) {};
rpc GetNode(GetNodeOptions) returns (Node) {};
rpc ListPodNodes(ListNodesOptions) returns (Nodes) {};
rpc ListPodNodeNames(ListNodesOptions) returns (NodeNames) {};
rpc GetContainer(ContainerID) returns (Container) {};
rpc GetContainers(ContainerIDs) returns (Containers) {};

Expand Down Expand Up @@ -45,6 +46,10 @@ message Nodes {
repeated Node nodes = 1;
}

message NodeNames {
repeated string names = 1;
}

message Container {
string id = 1;
string podname = 2;
Expand Down
10 changes: 10 additions & 0 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func (v *virbranium) ListPodNodes(ctx context.Context, opts *pb.ListNodesOptions
return &pb.Nodes{Nodes: nodes}, nil
}

// ListPodNodes returns a list of node names for pod, only name!
func (v *virbranium) ListPodNodeNames(ctx context.Context, opts *pb.ListNodesOptions) (*pb.NodeNames, error) {
names, err := v.cluster.ListPodNodeNames(opts.Podname)
if err != nil {
return nil, err
}

return &pb.NodeNames{Names: names}, nil
}

// GetContainer
// More information will be shown
func (v *virbranium) GetContainer(ctx context.Context, id *pb.ContainerID) (*pb.Container, error) {
Expand Down
23 changes: 23 additions & 0 deletions store/etcd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,29 @@ func (k *krypton) GetNodesByPod(podname string) ([]*types.Node, error) {
return nodes, err
}

// only get names
// storage path in etcd is `/eru-core/pod/:podname/node`
func (k *krypton) GetNodeNamesByPod(podname string) ([]string, error) {
var (
names []string
err error
)

key := fmt.Sprintf(podNodesKey, podname)
resp, err := k.etcd.Get(context.Background(), key, nil)
if err != nil {
return names, err
}
if !resp.Node.Dir {
return nil, fmt.Errorf("Node storage path %q in etcd is not a directory", key)
}

for _, node := range resp.Node.Nodes {
names = append(names, utils.Tail(node.Key))
}
return names, err
}

// update a node, save it to etcd
// storage path in etcd is `/eru-core/pod/:podname/node/:nodename/info`
func (k *krypton) UpdateNode(node *types.Node) error {
Expand Down
1 change: 1 addition & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Store interface {
AddNode(name, endpoint, podname, cafile, certfile, keyfile string, public bool) (*types.Node, error)
GetNode(podname, nodename string) (*types.Node, error)
GetNodesByPod(podname string) ([]*types.Node, error)
GetNodeNamesByPod(podname string) ([]string, error)
GetAllNodes() ([]*types.Node, error)
UpdateNode(*types.Node) error
UpdateNodeCPU(podname, nodename string, cpu types.CPUMap, action string) error
Expand Down

0 comments on commit e177ca5

Please sign in to comment.