Skip to content

Commit

Permalink
Breaking changes! see CHANGELOG.md for details
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasepe committed Jun 15, 2020
1 parent cd8535c commit 1c6621c
Show file tree
Hide file tree
Showing 178 changed files with 1,293 additions and 592 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.0] - 2020-06-15
### Added
- new component _Block Storage_ (kind: `bst`)
- new component _Object Storage_ (kind: `ost`)
- new component _File Storage_ (kind: `fst`)
- new component _RDBMS_ (kind: `rdb`)
- new component _No SQL_ (kind: `doc`)
- new component _Caching_ (kind: `mem`)
- new commandline flag `--impl=[aws,gcp,azure]` to auto fill components implementations according to the specified provider

### Changed
- autogenerated id prefix now is equal to the _kind_ value (see [./README.md](README.md)) **breaking change**
- modified YAML schema
- connection info (see [./README.md](README.md)) **breaking change**
- modified YAML schema

### Removed
- generic html component

## [0.4.0] - 2020-06-11
### Added
Expand Down
79 changes: 36 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Component struct {
ID string `yaml:"id,omitempty"` // optional - autogenerated if omitted (read more for details...)
Kind string `yaml:"kind"` // required - see the table below
Label string `yaml:"label,omitempty"` // optional - works only for: 'queue', 'service', 'storage', 'function', 'database', 'client'
Provider string `yaml:"provider,omitempty"` // optional - you can use this to specify the cloud provider
Outline string `yaml:"outline,omitempty"` // optional - you can use this to groups some components
Impl string `yaml:"impl,omitempty"` // optional - you can use this to specify the implementation
FillColor string `yaml:"fillColor,omitempty"` // optional - the hex code for the background color
FontColor string `yaml:"fontColor,omitempty"` // optional - the hex code for the foreground color
Expand All @@ -62,27 +62,38 @@ Eventually you can describe...

Below is a list of all the components currently implemented.

| Component | Kind | YAML | Output |
|:----------------------|:------------|:--------------------------------------------------------------|:---------------------------------:|
| **Client** | `client` | 👉 [examples/client.yml](./examples/client.yml) | ![](./examples/client.png) |
| **Microservice** | `service` | 👉 [examples/service.yml](./examples/service.yml) | ![](./examples/service.png) |
| **Gateway** | `gateway` | 👉 [examples/gateway.yml](./examples/gateway.yml) | ![](./examples/gateway.png) |
| **Firewall** | `waf` | 👉 [examples/waf.yml](./examples/waf.yml) | ![](./examples/waf.png) |
| **Container Service** | `cos` | 👉 [examples/waf.yml](./examples/cos.yml) | ![](./examples/cos.png) |
| **Message Broker** | `broker` | 👉 [examples/broker.yml](./examples/broker.yml) | ![](./examples/broker.png) |
| **Queue Service** | `queue` | 👉 [examples/queue.yml](./examples/queue.yml) | ![](./examples/queue.png) |
| **Object Storage** | `storage` | 👉 [examples/storage.yml](./examples/storage.yml) | ![](./examples/storage.png) |
| **Function** | `function` | 👉 [examples/function.yml](./examples/function.yml) | ![](./examples/function.png) |
| **Database** | `database` | 👉 [examples/database.yml](./examples/database.yml) | ![](./examples/database.png) |
| **Load Balancer** | `balancer` | 👉 [examples/balancer.yml](./examples/balancer.yml) | ![](./examples/balancer.png) |
| **CDN** | `cdn` | 👉 [examples/cdn.yml](./examples/cdn.yml) | ![](./examples/cdn.png) |
| **DNS** | `dns` | 👉 [examples/dns.yml](./examples/dns.yml) | ![](./examples/dns.png) |
| **Custom Html** | `html` | 👉 [examples/custom_image.yml](./examples/custom_image.yml) | ![](./examples/custom_image.png) |

For custom HTML components (_kind: html_) only these tags are supported:

- `<b>`, `<br/>`, `<font>`, `<hr>`, `<i>`, `<img> (in <td>…</td> only)`
- `<o>`, `<s>`, `<sub>`, `<sup>`, `<table>`, `<tr>`, `<u>`
| Component | Kind | YAML | Output |
|:---------------------|:------|:--------------------------------------------|:------------------------:|
| **Client** | `cli` | 👉 [examples/cli.yml](./examples/cli.yml) | ![](./examples/cli.png) |
| **Microservice** | `ser` | 👉 [examples/ser.yml](./examples/ser.yml) | ![](./examples/ser.png) |
| **API Gateway** | `gtw` | 👉 [examples/gtw.yml](./examples/gtw.yml) | ![](./examples/gtw.png) |
| **Firewall** | `waf` | 👉 [examples/waf.yml](./examples/waf.yml) | ![](./examples/waf.png) |
| **K8s Engine** | `kub` | 👉 [examples/kub.yml](./examples/kub.yml) | ![](./examples/kub.png) |
| **Pub / Sub** | `msg` | 👉 [examples/msg.yml](./examples/msg.yml) | ![](./examples/msg.png) |
| **Queue** | `que` | 👉 [examples/que.yml](./examples/que.yml) | ![](./examples/que.png) |
| **Function** | `fun` | 👉 [examples/fun.yml](./examples/fun.yml) | ![](./examples/fun.png) |
| **Relational DB** | `rdb` | 👉 [examples/rdb.yml](./examples/rdb.yml) | ![](./examples/rdb.png) |
| **Document DB** | `doc` | 👉 [examples/doc.yml](./examples/doc.yml) | ![](./examples/doc.png) |
| **Caching** | `mem` | 👉 [examples/mem.yml](./examples/mem.yml) | ![](./examples/mem.png) |
| **Load Balancer** | `lba` | 👉 [examples/lba.yml](./examples/lba.yml) | ![](./examples/lba.png) |
| **CDN** | `cdn` | 👉 [examples/cdn.yml](./examples/cdn.yml) | ![](./examples/cdn.png) |
| **DNS** | `dns` | 👉 [examples/dns.yml](./examples/dns.yml) | ![](./examples/dns.png) |
| **Block Store** | `bst` | 👉 [examples/bst.yml](./examples/bst.yml) | ![](./examples/bst.png) |
| **Object Store** | `ost` | 👉 [examples/ost.yml](./examples/ost.yml) | ![](./examples/ost.png) |
| **File Store** | `fst` | 👉 [examples/fst.yml](./examples/fst.yml) | ![](./examples/fst.png) |

## Auto filling the component implementation

Leave the `impl` fields empty and run [draft](https://github.com/lucasepe/draft/releases/latest) with the `-impl` flag to let [draft](https://github.com/lucasepe/draft/releases/latest) found the implementation by provider.

| example command | output |
|:------------------------------------------------------------------------------|:------------------------------:|
| <code>draft -impl aws ./examples/dns.yml &#124; dot -Tpng > test.png</code> | ![](./examples/dns_aws.png) |
| <code>draft -impl azure ./examples/dns.yml &#124; dot -Tpng > test.png<code> | ![](./examples/dns_azure.png) |
| <code>draft -impl gcp ./examples/kub.yml &#124; dot -Tpng > test.png<code> | ![](./examples/kub_gcp.png) |
| <code>draft -impl aws ./examples/kub.yml &#124; dot -Tpng > test.png<code> | ![](./examples/kub_aws.png) |

... and so on for each kind of component!

### Notes about a component `id`

Expand All @@ -94,23 +105,7 @@ For custom HTML components (_kind: html_) only these tags are supported:
An auto-generated component `id` has a prefix and a sequential number

- the prefix is related to the component `kind`

| a kind of... | will generate an `id` prefix with... | example |
|:-------------|:-------------------------------------|:-----------------|
| `client` | cl | _cl1, cl2,..._ |
| `service` | ms | _ms1, ms2,..._ |
| `gateway` | gt | _gt1, gt2,..._ |
| `gateway` | waf | _waf1, waf2,..._ |
| `broker` | br | _br1, br2,..._ |
| `queue` | qs | _qs1, qs2,..._ |
| `storage` | st | _st1, st2,..._ |
| `function` | fn | _fn1, fn2,..._ |
| `database` | db | _db1, db2,..._ |
| `balancer` | lb | _lb1, lb2,..._ |
| `cdn` | cn | _cn1, cn2,..._ |
| `dns` | dn | _dn1, dn2,..._ |
| `html` | htm | _htm1, htm2,..._ |
| `cos` | cos | _cos1, cos2,..._ |
- examples _waf1, ..., wafN_ or _ser1, ..., serN_ etc.

## Connections

Expand All @@ -122,11 +117,9 @@ A `connection` has the following properties:

```go
type Connection struct {
Origin struct {
ComponentID string `yaml:"componentId"`
} `yaml:"origin"`
Origin string `yaml:"origin"`
Targets []struct {
ComponentID string `yaml:"componentId"`
ID string `yaml:"id"`
Label string `yaml:"label,omitempty"`
Color string `yaml:"color,omitempty"`
Dashed bool `yaml:"dashed,omitempty"`
Expand Down
50 changes: 0 additions & 50 deletions broker.go

This file was deleted.

40 changes: 0 additions & 40 deletions broker_test.go

This file was deleted.

55 changes: 55 additions & 0 deletions bst.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package draft

import (
"fmt"
"strings"

"github.com/emicklei/dot"
"github.com/lucasepe/draft/pkg/cluster"
"github.com/lucasepe/draft/pkg/node"
)

type bst struct {
seq int16
}

func (rcv *bst) nextID() string {
rcv.seq++
return fmt.Sprintf("bst%d", rcv.seq)
}

func (rcv *bst) sketch(graph *dot.Graph, comp Component) {
id := comp.ID
if strings.TrimSpace(comp.ID) == "" {
id = rcv.nextID()
}

fillColor := comp.FillColor
if strings.TrimSpace(comp.FillColor) == "" {
fillColor = "#606f5cff"
}

label := strings.Replace(`<table border="0" cellspacing="4" cellpadding="4">
<tr>
<td border="1" bgcolor="{{BGCOLOR}}" width="30"></td>
<td border="1" bgcolor="{{BGCOLOR}}"></td>
</tr>
<tr>
<td border="1" bgcolor="{{BGCOLOR}}" width="30"></td>
<td border="1" bgcolor="{{BGCOLOR}}"></td>
</tr>
</table>`, "{{BGCOLOR}}", fillColor, -1)

cl := cluster.New(graph, id, cluster.BottomTop(comp.BottomTop()), cluster.Label(comp.Impl))
guessImpl(&comp, cl)

node.New(cl, id,
node.Label(label, true),
node.FontColor("#000000ff"),
node.FontSize(7),
node.FillColor("transparent"),
// ^^^ hack to set a transparent background
// color since we will use the HTML table.
node.Shape("plain"),
)
}
18 changes: 9 additions & 9 deletions balancer_test.go → bst_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
"github.com/emicklei/dot"
)

func TestLoadBalancerComponentNextID(t *testing.T) {
func TestBlockStorageNextID(t *testing.T) {
tests := []struct {
want string
}{
{"lb1"},
{"lb2"},
{"lb3"},
{"lb4"},
{"bst1"},
{"bst2"},
{"bst3"},
{"bst4"},
}

s := balancer{}
s := bst{}

for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
Expand All @@ -27,11 +27,11 @@ func TestLoadBalancerComponentNextID(t *testing.T) {
}
}

func TestLoadBalancerComponent(t *testing.T) {
want := `label="LB",shape="Mdiamond",style="filled"`
func TestBlockStorageShape(t *testing.T) {
want := `label=<<table border="0" cellspacing="4" cellpadding="4"><tr> <td border="1" bgcolor="#606f5cff" width="30"></td> <td border="1" bgcolor="#606f5cff"></td></tr><tr> <td border="1" bgcolor="#606f5cff" width="30"></td> <td border="1" bgcolor="#606f5cff"></td></tr></table>>`
g := dot.NewGraph(dot.Directed)

sketcher := balancer{}
sketcher := bst{}
sketcher.sketch(g, Component{})

if got := flatten(g.String()); !verify(got, want) {
Expand Down
10 changes: 6 additions & 4 deletions cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type cdn struct {

func (rcv *cdn) nextID() string {
rcv.seq++
return fmt.Sprintf("cn%d", rcv.seq)
return fmt.Sprintf("cdn%d", rcv.seq)
}

func (rcv *cdn) sketch(graph *dot.Graph, comp Component) {
Expand All @@ -25,12 +25,14 @@ func (rcv *cdn) sketch(graph *dot.Graph, comp Component) {
}

cl := cluster.New(graph, id, cluster.BottomTop(comp.BottomTop()), cluster.Label(comp.Impl))
guessImpl(&comp, cl)

el := node.New(cl, id,
node.Label("CDN", false),
node.FontColor(comp.FontColor, "#000000ff"),
node.FillColor(comp.FillColor, "#47df9aff"),
node.Label("<b>CDN</b>", true),
node.FontColor("#000000ff"),
node.FillColor("#47df9aff"),
node.Shape("Mcircle"),
)
el.Attr("height", "0.5")
el.Attr("color", "#f5f5f5ff")
}
14 changes: 7 additions & 7 deletions cdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"github.com/emicklei/dot"
)

func TestCDNComponentNextID(t *testing.T) {
func TestCDNCNextID(t *testing.T) {
tests := []struct {
want string
}{
{"cn1"},
{"cn2"},
{"cn3"},
{"cn4"},
{"cdn1"},
{"cdn2"},
{"cdn3"},
{"cdn4"},
}

s := cdn{}
Expand All @@ -27,8 +27,8 @@ func TestCDNComponentNextID(t *testing.T) {
}
}

func TestCDNComponent(t *testing.T) {
want := `label="CDN",shape="Mcircle",style="filled"`
func TestCDNShape(t *testing.T) {
want := `shape="Mcircle",style="filled"`
g := dot.NewGraph(dot.Directed)

sketcher := cdn{}
Expand Down
Loading

0 comments on commit 1c6621c

Please sign in to comment.