Skip to content

Commit

Permalink
Merge pull request #218 from asteris-llc/feature/flatten-details
Browse files Browse the repository at this point in the history
rpc: flatten details field
  • Loading branch information
BrianHicks authored Sep 7, 2016
2 parents f0e3a12 + bd655bf commit 59e3842
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 98 deletions.
9 changes: 2 additions & 7 deletions prettyprinters/graphviz/providers/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,10 @@ func (p RPCProvider) VertexGetLabel(e graphviz.GraphEntity) (pp.VisibleRenderabl
return pp.VisibleString(name), nil
}

var details []byte
if szd := val.GetDetails(); szd != nil {
details = szd.Value
}

switch val.Kind {
case "file.content":
var dest = new(content.Content)
if err := json.Unmarshal(details, dest); err != nil {
if err := json.Unmarshal(val.Details, dest); err != nil {
return nil, errors.Wrap(err, "could not unmarshal file content")
}

Expand All @@ -89,7 +84,7 @@ func (p RPCProvider) VertexGetLabel(e graphviz.GraphEntity) (pp.VisibleRenderabl

case "param":
var dest = new(param.Param)
if err := json.Unmarshal(details, dest); err != nil {
if err := json.Unmarshal(val.Details, dest); err != nil {
return nil, errors.Wrap(err, "could not unmarshal param")
}

Expand Down
9 changes: 3 additions & 6 deletions rpc/grapher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"github.com/asteris-llc/converge/load/registry"
"github.com/asteris-llc/converge/rpc/pb"
"github.com/golang/protobuf/ptypes/any"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -56,11 +55,9 @@ func (g *grapher) Graph(in *pb.LoadRequest, stream pb.Grapher_GraphServer) error

err = stream.Send(
pb.NewGraphComponent(&pb.GraphComponent_Vertex{
Id: vertex,
Kind: kind,
Details: &any.Any{
Value: vbytes,
},
Id: vertex,
Kind: kind,
Details: vbytes,
}),
)
if err != nil {
Expand Down
124 changes: 59 additions & 65 deletions rpc/pb/root.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions rpc/pb/root.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package pb;

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/any.proto";

message LoadRequest {
string location = 1;
Expand Down Expand Up @@ -94,8 +93,13 @@ service ResourceHost {
message GraphComponent {
message Vertex {
string id = 1;

// the kind of node, specified as the type used to create a node of this
// type in the Converge DSL
string kind = 2;
google.protobuf.Any details = 3;

// detailed fields of this node, serialized as JSON
bytes details = 3;
}

message Edge {
Expand Down
23 changes: 5 additions & 18 deletions rpc/pb/root.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,18 @@
"type": "object",
"properties": {
"details": {
"$ref": "#/definitions/protobufAny"
"type": "string",
"format": "byte",
"title": "detailed fields of this node, serialized as JSON"
},
"id": {
"type": "string",
"format": "string"
},
"kind": {
"type": "string",
"format": "string"
"format": "string",
"title": "the kind of node, specified as the type used to create a node of this\ntype in the Converge DSL"
}
}
},
Expand Down Expand Up @@ -294,22 +297,6 @@
}
}
},
"protobufAny": {
"type": "object",
"properties": {
"type_url": {
"type": "string",
"format": "string",
"description": "A URL/resource name whose content describes the type of the\nserialized protocol buffer message.\n\nFor URLs which use the scheme `http`, `https`, or no scheme, the\nfollowing restrictions and interpretations apply:\n\n* If no scheme is provided, `https` is assumed.\n* The last segment of the URL's path must represent the fully\n qualified name of the type (as in `path/google.protobuf.Duration`).\n The name should be in a canonical form (e.g., leading \".\" is\n not accepted).\n* An HTTP GET on the URL must yield a [google.protobuf.Type][]\n value in binary format, or produce an error.\n* Applications are allowed to cache lookup results based on the\n URL, or have them precompiled into a binary to avoid any\n lookup. Therefore, binary compatibility needs to be preserved\n on changes to types. (Use versioned type names to manage\n breaking changes.)\n\nSchemes other than `http`, `https` (or the empty scheme) might be\nused with implementation specific semantics."
},
"value": {
"type": "string",
"format": "byte",
"description": "Must be a valid serialized protocol buffer of the above specified type."
}
},
"description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }"
},
"protobufEmpty": {
"type": "object",
"description": "service Foo {\n rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);\n }\n\nThe JSON representation for `Empty` is empty JSON object `{}`.",
Expand Down

0 comments on commit 59e3842

Please sign in to comment.