Skip to content

Commit

Permalink
feat(docs): update docs
Browse files Browse the repository at this point in the history
Updates the docs. See details in [workflow run].
[Workflow Run]: https://github.com/pluto-lang/website/actions/runs/7750987168
------
*Automatically created via the 'update-docs' workflow*
  • Loading branch information
actions-user committed Feb 2, 2024
1 parent 4f69fc6 commit 280c0c5
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pages/dev_guide/extend-sdk.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export interface Queue extends IResource, IQueueClient, IQueueInfra {}

In the `src/clients/aws` directory of `@plutolang/pluto`, create an `snsQueue.ts` file. The file and the class it contains are usually named after the component and the type.

In this file, the `SNSQueue` class implements the `IQueueClient` interface using the AWS SDK. When calling the `PublishCommand` in the aws-sdk, the ARN of the SNS topic needs to be specified. Here, the ARN is constructed by concatenating the required parameters obtained from the environment variables, which are set in the aws `runtime.ts` of `@plutolang/pluto-infra`.
In this file, the `SNSQueue` class implements the `IQueueClient` interface using the AWS SDK. When calling the `PublishCommand` in the aws-sdk, the ARN of the SNS topic needs to be specified. Here, the ARN is constructed by concatenating the required parameters obtained from the environment variables, which are set in the `queue.sns.ts` of `@plutolang/pluto-infra`.

_Currently, there is no effective solution on how to transfer the information generated during compilation to the runtime for effective use._

Expand Down
4 changes: 2 additions & 2 deletions pages/dev_guide/extend-sdk.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ export interface Queue extends IResource, IQueueClient, IQueueInfra {}

### 创建 客户端 实现类

`@plutolang/pluto` 的 src/clients/aws 目录下,创建一个 `snsQueue.ts` 文件,文件与包含的类名通常以 组件名 + 类型名 来命名。
`@plutolang/pluto``src/clients/aws` 目录下,创建一个 `snsQueue.ts` 文件,文件与包含的类名通常以 组件名 + 类型名 来命名。

该文件主要通过使用 AWS SDK 实现 `IQueueClient` 接口,在使用 aws-sdk 调用 `PublishCommand` 时需要指定 SNS 主题的 ARN,这里采用拼接的方式构建 ARN,其中依赖的参数信息从环境变量获得,而环境变量在 `@plutolang/pluto-infra` 的 aws `runtime.ts` 设定
该文件主要通过使用 AWS SDK 实现 `IQueueClient` 接口,在使用 aws-sdk 调用 `PublishCommand` 时需要指定 SNS 主题的 ARN,这里采用拼接的方式构建 ARN,其中依赖的参数信息从环境变量获得,而环境变量在 `@plutolang/pluto-infra` `queue.sns.ts` 的适配函数中设定

```typescript
import { SNSClient, PublishCommand } from "@aws-sdk/client-sns";
Expand Down
99 changes: 99 additions & 0 deletions pages/documentation/concepts/arch-ref.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
title: Architecture Reference
date: 2024-02-01
---

# Architecture Reference

The Architecture Reference (hereafter referred to as Arch Ref) is a product of the [deducer](./deducer.en.md). It represents the architecture of an application mapped to the cloud, including the cloud BaaS resource instances that the application needs to create, the event handling functions of the resource instances, and the relationships between the resource instances.

Users can understand the architecture of the application from the Arch Ref and confirm whether the architecture meets their expectations. Pluto will automatically create cloud BaaS and FaaS resource instances based on the content of the Arch Ref, with minimized permission configuration.

## Components

The Arch Ref consists of three parts: resource instances, compute closures, and resource relationships. The following diagram shows the composition of the Arch Ref:

![The composition of Arch Ref](../../../public/assets/arch-ref-composition.png)

### Resource Instances

A Resource Instance is a cloud resource instance that the application needs to create. It includes information such as the instance's ID, type, name, and parameters.

_Note: The name and ID here may not match the ID generated at runtime, as the ID is also generated based on the resource name. During the deduction phase, the resource name corresponds to the variable name of the resource object, while the name of the resource object at runtime is determined by the parameters given by the user. For example, `router = new Router("name")`, in the generated Arch Ref, the name is router, but at runtime, the resource name will be name._

### Compute Closures

A Compute Closure is typically an event handling function of a resource instance, such as a Queue subscriber or a Router path handling function. It includes the closure's ID and path information.

The path information is the folder path where the closure is located after export, relative to the root directory of the application. If it's a TypeScript application, the compute closure folder is a Node.js module, containing an `index.ts` file and an `index.js` file generated by esbuild compilation and packaging. The `default` function exported in this module is the event handling function defined by the user.

### Resource Relationships

A Resource Relationship represents the relationship between resource instances, including the actor of the relationship, the type, operation, and parameters.

The actor could be a resource instance or a compute closure. If it's a resource instance, the corresponding relationship type should be `Create`, and the corresponding operation should belong to the [Infra API](./sdk.zh-CN.md) of that resource type, indicating that the resource instance has called an Infra API to create another resource instance or compute closure. If it's a compute closure, the corresponding relationship type should be `MethodCall` or `PropertyAccess`, indicating that a Client API method or property of a resource instance has been called in the compute closure.

The `Create` relationship guides Pluto to create and associate resource instances at compile time, the `MethodCall` relationship guides Pluto to configure appropriate permissions for the FaaS instance to which the compute closure belongs at compile time, and the `PropertyAccess` relationship guides Pluto to configure appropriate environment variables for the FaaS instance to which the compute closure belongs at compile time, enabling it to access the properties of the resource instance at runtime.

<!--
```plantuml
@startuml
class Architecture {
+resources: Resource[]
+closures: Closure[]
+relationships: Relationship[]
+addResource(resource: Resource): void
+findResource(resourceId: string): Resource | undefined
+addClosure(closure: Closure): void
+findClosure(closureId: string): Closure | undefined
+findResourceOrClosure(entityId: string): Resource | Closure | undefined
+addRelationship(relationship: Relationship): void
+topoSort(): (Resource | Closure | Relationship)[]
}
class Resource {
+id: string
+name: string
+type: string
+parameters: Parameter[]
}
class Closure {
+id: string
+path: string
}
class Relationship {
+from: IDWithType
+to: IDWithType[]
+type: "Create" | "MethodCall" | "PropertyAccess"
+operation: string
+parameters: Parameter[]
}
class Parameter {
+index: string
+name: string
+type: "closure" | "text"
+value: string
}
class IDWithType {
+id: string
+type: "closure" | "resource"
}
' Relationships
Architecture "1" *-- "*" Resource : contains
Architecture "1" *-- "*" Closure : contains
Architecture "1" *-- "*" Relationship : contains
Resource "1" *-- "*" Parameter : contains
Relationship "1" *-- "*" Parameter : contains
Relationship "1" *-- "*" IDWithType : contains
@enduml
```
-->
99 changes: 99 additions & 0 deletions pages/documentation/concepts/arch-ref.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
title: 参考架构
date: 2024-02-01
---

# 参考架构

参考架构(Architecture Reference,下称 Arch Ref)是[推导器](./deducer.zh-CN.md)的产出,体现了应用程序映射到云上的架构,包括应用需要创建的云 BaaS 资源实例、资源实例的事件处理函数,以及资源实例之间的关系。

用户可以从 Arch Ref 中了解应用程序的架构,并确认架构是否符合预期。Pluto 会根据 Arch Ref 的内容,自动创建云上 BaaS、FaaS 资源实例,并最小化权限配置。

## 构成

Arch Ref 包含资源实例、计算闭包、资源关系三个部分,下图为 Arch Ref 的构成:

![The composition of Arch Ref](../../../public/assets/arch-ref-composition.png)

### 资源实例

资源实例(Resource Instance)是应用程序需要创建的云资源实例,包括资源实例的 ID、类型、名称、参数等信息。

_目前,这里的名称与 ID 可能与运行时生成的 ID 不相符,因为,ID 同样根据资源名生成,在推导阶段,资源名称对应资源对象的变量名,而运行时资源对象的名字则根据用户给定的参数确定,参数与变量名可能不同,导致推导阶段的 ID 与运行时的 ID 不同。例如:`router = new Router("name")`,在生成的 Arch Ref 中,名称为 router,在运行时,资源名称将是 name。_

### 计算闭包

计算闭包(Compute Closure)通常是资源实例的事件处理函数,如 Queue 的订阅者、Router 的路径处理函数等,包括闭包的 ID、路径信息。

其中,路径信息为闭包导出后所处的文件夹路径,为相对于应用程序根目录的相对路径。如果是 TypeScript 应用程序,计算闭包文件夹是一个 Node.js 模块,包含一个 `index.ts` 文件,和使用 esbuild 编译打包生成的 `index.js`,在该模块中,导出的 `default` 函数即为用户定义的事件处理函数。

### 资源关系

资源关系(Relationship)表示资源实例之间的关系,包括关系的作用方、类型、操作、参数等信息。

作用方可能是资源实例或计算闭包。如果是资源实例,其对应的关系类型应该是 `Create`,对应操作应该属于该资源类型的 [Infra API](./sdk.zh-CN.md),表示资源实例调用了某个 Infra API 创建了另一个资源实例或计算闭包。如果是计算闭包,其对应的关系类型应该是 `MethodCall``PropertyAccess`,表示在该计算闭包中调用了某个资源实例的 Client API 方法或属性。

`Create` 关系指导 Pluto 在编译时创建与关联资源实例,`MethodCall` 关系指导 Pluto 在编译时给计算闭包所属的 FaaS 实例配置合理的权限,`PropertyAccess` 关系指导 Pluto 在编译时给计算闭包所属的 FaaS 实例配置合理的环境变量,使其在运行时可以访问到资源实例的属性。

<!--
```plantuml
@startuml
class Architecture {
+resources: Resource[]
+closures: Closure[]
+relationships: Relationship[]
+addResource(resource: Resource): void
+findResource(resourceId: string): Resource | undefined
+addClosure(closure: Closure): void
+findClosure(closureId: string): Closure | undefined
+findResourceOrClosure(entityId: string): Resource | Closure | undefined
+addRelationship(relationship: Relationship): void
+topoSort(): (Resource | Closure | Relationship)[]
}
class Resource {
+id: string
+name: string
+type: string
+parameters: Parameter[]
}
class Closure {
+id: string
+path: string
}
class Relationship {
+from: IDWithType
+to: IDWithType[]
+type: "Create" | "MethodCall" | "PropertyAccess"
+operation: string
+parameters: Parameter[]
}
class Parameter {
+index: string
+name: string
+type: "closure" | "text"
+value: string
}
class IDWithType {
+id: string
+type: "closure" | "resource"
}
' Relationships
Architecture "1" *-- "*" Resource : contains
Architecture "1" *-- "*" Closure : contains
Architecture "1" *-- "*" Relationship : contains
Resource "1" *-- "*" Parameter : contains
Relationship "1" *-- "*" Parameter : contains
Relationship "1" *-- "*" IDWithType : contains
@enduml
```
-->
7 changes: 2 additions & 5 deletions pages/documentation/concepts/sdk.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

The above class diagram illustrates the inheritance relationship between types in the SDK using a message queue as an example. In this diagram, the message queue is ultimately implemented using AWS SNS.

In Pluto, there are two types of SDKs related to the cloud platform. These two SDKs each include multiple runtime implementations. They are:
In Pluto, there are two categories of SDKs related to the cloud platform. These include: 1) Functions supported by resource components at runtime, and 2) Methods for associating resource components. Each of these SDKs includes multiple runtime implementations.

1. Client SDK:
- Defines two types of methods:
1. Functions supported by resource components at runtime.
2. Methods for associating resource components.
- SDKs based on resource components implement the first type of methods. These methods typically encapsulate the functionality supported by BaaS components at runtime. For example, the `push` method in `pluto.SNSQueue` wraps the `PublishCommand` of SNS and is called by Lambda during runtime.
2. Infrastructure SDK (Infra SDK):
- Implements the second type of above methods based on the IaC SDK.
Expand All @@ -20,7 +17,7 @@ The `@plutolang/base` library contains three basic interfaces:

1. **IResource**: Indicates that the class or interface is related to cloud resources. During compilation, whether an instantiated object's type implements this interface is used to determine if it is a cloud resource.
2. **FnResource**: Indicates that the class or interface is related to FaaS resources. During compilation, whether a function type inherits this interface is used to determine if the function is an instance of FaaS resource.
3. **ResourceInfra**: This interface must be implemented by infrastructure implementation classes. It is used to complete the creation of infrastructure components.
3. **IResourceInfra**: This interface must be implemented by infrastructure implementation classes. It is used to complete the creation of infrastructure components.
- `get name()`: Retrieves the basic name of the resource object, which may be different from the name of the created resource instance.
- `getPermission()`: Generates the necessary permissions for calling specific operations on itself.
- `postProcess()`: Some operations need to be performed only after all configuration processes are completed. These operations are placed in this function. For example, AWS ApiGateway needs to configure Deployment and Stage after setting up all routes.
Expand Down
5 changes: 2 additions & 3 deletions pages/documentation/concepts/sdk.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

上方类图以消息队列为例展示 SDK 中类的继承关系,该图中消息队列最终使用 AWS SNS 实现。

在 Pluto 中与云平台相关的有两类 SDK,这两类 SDK 都包含多种运行时的实现,他们分别是:
在 Pluto 中与云平台相关的有两类 SDK,分别包含两类方法 1)资源组件在运行时支持的功能;2)资源组件间的关联方法。这两类 SDK 都包含多种运行时的实现,他们分别是:

- 客户端 SDK(Client SDK):
- 定义两类方法 1)资源组件在运行时支持的功能;2)资源组件间的关联方法。
- 基于资源组件的 SDK 对第一类方法进行实现,这类方法通常为 BaaS 组件在运行时支持的功能方法,例如将 SNS 的 `PublishCommand` 封装在 `pluto.SNSQueue``push` 方法中,并由 Lambda 在运行过程中调用。
- 基础设施 SDK(Infra SDK):基于 IaC SDK 对第二类方法进行实现。
- 在构造方法中完成资源创建的过程,例如在 `pluto-infra.SNSQueue` 中进行 AWS SNS 组件的定义。
Expand All @@ -17,7 +16,7 @@

- **IResource**:表明该类或接口与云资源相关,在编译时,通过查看开发者实例化对象的类型是否实现该接口来判断是否是云资源。
- **FnResource**:表明该类或接口与 FaaS 资源相关,在编译时,通过查看函数类型是否继承该接口来判断该函数是否是 FaaS 资源实例。
- **ResourceInfra**:基础设施实现类时必须实现的接口,用于完成基础设施组件的创建。
- **IResourceInfra**:基础设施实现类时必须实现的接口,用于完成基础设施组件的创建。
- `get name()`:获取资源对象的基本名称,可能与创建的资源实例的名称不同。
- `getPermission()`: 用于生成调用自身特定操作时所需的权限。
- `postProcess()`: 存在某些操作需要待所有配置过程完成后再开始进行,将该类操作放置在函数中。例如,AWS 的 ApiGateway 需要在配置完所有路由后,再配置 Deployment 和 Stage。
Expand Down
8 changes: 3 additions & 5 deletions pages/documentation/concepts/simulator.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ The capability provided externally is the Infra type of the resource, but what i
1. Build the arch topology.
2. Iterate through the resources, load dependencies, and create client instances based on the resource type and parameters.
3. Iterate through the relationships and add Event Handlers to the "from" resources.
5. The test command notifies the simulator to invoke the corresponding function based on the test function's ID and retrieves the execution result.
1. Find the instance object of the function based on its ID.
2. Invoke the invoke method of the function object.
1. Invoke creates a VM sandbox and executes the function.
2. The resource objects that the function depends on are all Proxy objects.
5. The test command communicates with the corresponding tester instance within the simulator, identified by the tester's ID. It triggers the test case and retrieves the execution result.
1. Tester instance find the compute closure based on test case information.
2. Invoke the compute closure.
6. The test command displays the test results.
8 changes: 3 additions & 5 deletions pages/documentation/concepts/simulator.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ Simulator 根据 Arch Ref 的 resource 列表依次构建每一个 BaaS 组件
1. 构建 arch 拓扑
2. 遍历 resources,加载依赖库,根据 resource 的 type 及 参数 创建 client 实例对象
3. 遍历 relationships,给 from 资源添加 Event Handler
5. test command 根据 test 函数的 id 通知 simulator 调用执行相应函数,并获取执行结果
1. 根据 函数 ID 找到 函数 的实例对象
2. 执行函数对象的 invoke 方法
1. invoke 创建 VM 沙盒,执行函数
2. 函数依赖的资源对象都为 Proxy 对象
5. test command 根据 tester 实例的 id 通知 simulator 中相应 tester 实例调用执行相应测试用例,并获取执行结果
1. tester 示例根据用例名称找到相应的计算闭包
2. 执行相应的计算闭包
6. test command 展示测试结果
Loading

0 comments on commit 280c0c5

Please sign in to comment.