Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental arr.ai package to prototype standard Sysl transformations. #946

Merged
merged 6 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions pkg/arrai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Sysl arr.ai (WIP)

This package contains experimental [arr.ai](https://github.com/arr-ai/arrai) code that operates on Sysl models. It seeks to:

* Demonstrate how to use arr.ai to work with Sysl models.
* Replicate `sysl`'s various commands in a more concise, functional style.
* Introduce new capabilities such as relational modelling and data flow analysis.

## Usage

To keep things simple and consistent, all scripts currently work with the same `model.sysl` spec. This spec will evolve over time to contain the full range of Sysl features and patterns to stress test the scripts.

To run the arr.ai scripts, install arr.ai and execute `arrai run [file]`. For example:

```bash
$ arrai run integration_diagram.arrai
```

Each script has an accompanying Markdown file describing the logic and output.

<!-- TODO(ladeo): Generate these Markdown files from the arr.ai sources. -->

## Development

Many of the scripts will start by importing `model.sysl` (assuming it's in the current working directory) like so:

```arrai
let sysl = //encoding.proto.decode(//encoding.proto.proto, //os.file('sysl.pb'));
let module = //encoding.proto.decode(sysl, 'Module' , //os.file('model.pb'));
...
```

If `model.sysl` is changed, `model.pb` must be regenerated like so:

```bash
$ sysl pb --mode=pb -o model.pb model.sysl
```

### Environment

To develop additional arr.ai scripts, you're encouraged to use Visual Studio Code with the `arrai` extension.

To speed up the edit/refresh cycle, install the [Save and Run](https://github.com/wk-j/vscode-save-and-run) extension and configure it with:

```json
"saveAndRun": {
"commands": [
{
"match": "\\.arrai$",
"cmd": "echo; arrai run ${file}",
"useShortcut": false,
"silent": false
}
]
}

This will make VS Code automatically run the script every time you save it.
23 changes: 23 additions & 0 deletions pkg/arrai/integration_diagram.arrai
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generates the PlantUML for an integration diagram of model.sysl.

let sysl = //encoding.proto.decode(//encoding.proto.proto, //os.file('sysl.pb'));
let flow = //encoding.proto.decode(sysl, 'Module' , //os.file('model.pb'));

# Transforms a module to an adjacency list of applications.
let toAdj = \m m.apps >>> \k \a
//seq.join('',
# Names of targets of call statements of endpoints of app.
(a.endpoints >> \e e.stmt >> \s s.@item.call?.target.part.@item.@item : '')
orderby .@value >> .@value
) where .@item != k && .@item count;

# Transforms an adjacency list of applications to a PlantUML integration diagram.
let toInt = \adj
$`@startuml
${
(adj >>> \k \v $`${v >> $`[${k}] --> [${.}]`::\n}`)
orderby .@ >> .@value
::\n}
@enduml`;

toInt(toAdj(flow))
18 changes: 18 additions & 0 deletions pkg/arrai/integration_diagram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Integration Diagram

Generates the PlantUML for an integration diagram of `model.sysl`.

```bash
$ arrai run integration_diagram.arrai
@startuml
[A] --> [Source]
[B] --> [Source]
[C] --> [A]
[C] --> [B]
[Client] --> [D]
[D] --> [A]
[D] --> [C]
@enduml
```

![Integration diagram](integration_diagram.svg)
32 changes: 32 additions & 0 deletions pkg/arrai/integration_diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions pkg/arrai/model.pb

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

34 changes: 34 additions & 0 deletions pkg/arrai/model.sysl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Source[~db]:
!type Foo:
x <: int

Read:
return x

A:
Fetch:
Source <- Read

B:
Fetch:
Source <- Read

C:
FetchA:
A <- Fetch

FetchB:
B <- Fetch

Fetch:
. <- FetchA
. <- FetchB

D:
Fetch:
A <- Fetch
C <- Fetch

Client:
Do:
D <- Fetch
Binary file added pkg/arrai/sysl.pb
Binary file not shown.