plan.md 2.19 KB
Newer Older
Wei Shoulin's avatar
docs  
Wei Shoulin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# CSST-DFS 编排接口使用说明

## 概述

编排接口模块是 `csst_dfs_client.plan` ,用于与DFS(分布式文件系统)中的编排(plan)数据进行交互。该模块用于搜索、获取、写入和新建编排数据。

## 函数列表

1. **find**
   - 功能:根据给定的参数在DFS中搜索编排数据。
   - 参数:包括观测模式、观测ID、后端模块ID等。
   - 返回值:搜索结果对象。

2. **get_by_id**
   - 功能:通过编排ID获取对应的编排数据。
   - 参数:编排ID。
   - 返回值:查询结果对象。

3. **find_by_opid**
   - 功能:通过编排的opid查询对应的编排数据。
   - 参数:opid。
   - 返回值:查询结果对象。

4. **write_file**
   - 功能:将本地的JSON文件或JSON数据流写入DFS中。
   - 参数:本地文件路径或文件对象,以及其他可选的关键字参数。
   - 返回值:操作结果对象。

5. **new**
   - 功能:新建编排数据。
   - 参数:编排数据的字典表示。
   - 返回值:操作结果对象。

## 使用示例

以下是一些使用 `plan` 模块的示例代码。

### 1. 搜索编排数据

```python
from csst_dfs_client import plan

# 搜索编排数据
result = plan.find(mode='SCIENCE', backend='MSC', page=1, limit=10)
print(result)
```

### 2. 通过编排数据中的ID获取编排数据

```python
from csst_dfs_client import plan

# 通过编排ID获取编排数据
_id = 12345
result = plan.get_by_id(_id)
print(result)
```

### 3. 通过编排数据中的opid查询编排数据

```python
from csst_dfs_client import plan

# 通过opid查询编排数据
opid = 'some_opid'
result = plan.find_by_opid(opid)
print(result)
```

### 4. 批量写入编排的JSON数据到DFS

```python
from csst_dfs_client import plan

# 写入编排数据到DFS
local_file_path = '/path/to/your/plan_data.json'
result = plan.write_file(local_file_path)
print(result)
```

### 5. 写入单条编排数据

```python
from csst_dfs_client import plan

# 写入单条编排数据
plan_data = {
    'id': 67890,
    'opid': 'new_opid',
    'backend': 'MSC',
    # 其他编排数据字段
}
result = plan.new(plan_data)
print(result)
```

- [其他接口](./usage.md)