Skip to content

Commit 0623008

Browse files
author
吴炳亨
authored
Merge pull request #173 from NigelWu95/dev
Dev
2 parents 2851f7a + 08fe511 commit 0623008

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+851
-531
lines changed

README.md

+17-12
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ maven 引入:
2828
<dependency>
2929
<groupId>com.qiniu</groupId>
3030
<artifactId>qsuits</artifactId>
31-
<version>4.31</version>
31+
<version>4.40</version>
3232
</dependency>
3333
```
3434
**务必使用最新版本**
@@ -124,19 +124,23 @@ indexes=0,1,2
124124
#### 2. 输出结果持久化
125125
对数据源输出(列举)结果进行持久化操作(目前支持写入到本地文件),持久化选项:
126126
`save-path=` 表示保存结果的文件路径
127-
`save-tag=` 保存路径文件名包含的标签,默认为空
128127
`save-format=` 结果保存格式(json/tab),默认为 tab
129128
`save-separator=` 结果保存分隔符,结合 save-format=tab 默认使用 "\t" 分隔
130-
`save-total=` 是否保存数据源的完整输出结果,用于在设置过滤器的情况下选择是否保留原始数据。如 bucket 的 list 操作需要在列举出结果之后再针对字段
131-
进行过滤,save-total=true 则表示保存列举出来的完整数据,而过滤的结果会单独保存,如果只需要过滤之后的数据,则设置 save-total=false。file 源时
132-
默认不保存原始输出数据,list 源默认保存原始输出数据。
133-
**--** 所有持久化参数均为可选参数,未设置的情况下保留所有字段:key、hash、fsize、putTime、mimeType、type、status、endUser,可选择去除某些
134-
字段,每一行信息以 json 格式保存在 ./result 路径(当前路径下新建 result 文件夹)下。详细参数见 [持久化配置](docs/resultsave.md)
135-
**持久化结果的文件名为 "\<source-name\>\<save-tag\>_success/error_\<order\>.txt":
136-
(1)list 源 =》 "bucketlist\<save-tag\>_success/error_\<order\>.txt"
137-
(2)file 源 =》 "fileinput\<save-tag\>_success/error_\<order\>.txt"
138-
如果设置了过滤参数,则过滤到的结果文件名为 "filter\<save-tag\>_success/error_\<order\>.txt",process 过程保存的结果为文件为
139-
"\<process\>\<save-tag\>_success/error_\<order\>.txt"**
129+
`save-total=` 是否保存数据源的完整输出结果,用于在设置过滤器的情况下选择是否保留原始数据,如 bucket 的 list 操作需要在列举出结果之后再针对字段
130+
进行过滤,save-total=true 则表示保存列举出来的完整数据,而过滤的结果会单独保存,如果只需要过滤之后的数据,则设置 save-total=false。
131+
**默认情况:**
132+
(1)file 源时默认如果存在 process 或者 filter 设置则为 false,反之则为 true(说明可能是单纯格式转换)。
133+
(2)list 源时如果无 process 则为 true,如果存在 process 且包含 filter 设置时为 false,既存在 process 同时包含 filter 设置时为 true。
134+
135+
*--* 所有持久化参数均为可选参数,未设置的情况下保留所有字段:key,hash,fsize,putTime,mimeType,type,status,md5,endUser,可通过rm-fields
136+
选择去除某些字段,每一行信息以 json 格式保存在 ./result 路径(当前路径下新建 result 文件夹)下。详细参数见 [持久化配置](docs/resultsave.md)
137+
**持数据源久化结果的文件名为 "\<source-name\>_success/error_\<order\>.txt":
138+
(1)list 源 =》 "bucketlist_success/error_\<order\>.txt"
139+
(2)file 源 =》 "fileinput_success/error_\<order\>.txt"
140+
如果设置了过滤参数,则过滤到的结果文件名为 "filter_success/error_\<order\>.txt",process 过程保存的结果为文件为
141+
"\<process\>_success/error_\<order\>.txt"**
142+
**process 结果的文件名为:<process>_success/error_\<order\>.txt 及 <process>_need_retry_\<order\>.txt,error 的结果表明无法成功
143+
处理,可能需要确认所有错误数据和原因,need_retry 的结果为需要重试的记录,包含错误信息**
140144

141145
### 5 处理过程
142146
处理过程表示对由数据源输入的每一条记录进行处理,所有处理结果保存在 save-path 路径下,具体处理过程由处理类型参数指定,如 **process=type/status
@@ -161,6 +165,7 @@ indexes=0,1,2
161165
`process=qhash` 表示查询资源的 qhash [qhash 配置](docs/qhash.md)
162166
`process=privateurl` 表示对私有空间资源进行私有签名 [privateurl 配置](docs/privateurl.md)
163167
`process=pfopcmd` 表示根据音视频资源的 avinfo 信息来生成转码指令 [pfopcmd 配置](docs/pfopcmd.md)
168+
`process=exportts` 表示对 m3u8 的资源进行读取导出其中的 ts 文件列表 [exportts 配置](docs/exportts.md)
164169

165170
### 补充
166171
1. 命令行方式与配置文件方式不可同时使用,指定 -config=<path> 或使用 qiniu.properties 时,需要将所有参数设置在该配置文件中。

docs/asyncfetch.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ url-index=
1717
add-prefix=
1818
rm-prefix=
1919
host=
20-
md5-index=
20+
indexes=
2121
callback-url=
2222
callback-body=
2323
callback-body-type=

docs/datasource.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,29 @@
99
```
1010
source-type=list/file (v.2.11 及以上版本也可以使用 source=list/file,或者不设置该参数)
1111
path=
12-
threads=30
12+
indexes=key,hash,fsize
1313
unit-len=10000
14+
threads=30
1415
```
1516
|参数名|参数值及类型 |含义|
1617
|-----|-------|-----|
1718
|source-type/source| 字符串 file/list | 选择从[本地路径文件中读取]还是从[七牛空间列举]资源列表|
1819
|path| 输入源路径字符串| 资源列表路径,file源时填写本地文件或者目录路径,list源时可填写"qiniu://\<bucket\>"|
19-
|threads| 整型数| 表示预期最大线程数,若实际得到的文件数或列举前缀数小于该值时以实际数目为准|
20+
|indexes| 字符串列表| 资源元信息字段索引(下标),设置输入行对应的元信息字段下标|
2021
|unit-len| 整型数字| 表示一次读取的文件个数(读取或列举长度,默认值 10000),对应与读取文件时每次处理的行数或者列举请求时设置的 limit 参数|
22+
|threads| 整型数| 表示预期最大线程数,若实际得到的文件数或列举前缀数小于该值时以实际数目为准|
23+
24+
#### # 关于 indexes 索引
25+
indexes 指输入行中包含的资源元信息字段的映射关系,指定索引的顺序为 key,hash,fsize,putTime,mimeType,type,status,md5,endUser,即存储文件
26+
的信息字段,顺序固定。
27+
**默认情况:**
28+
(1)当数据源为file 时,默认情况下,程序只从输入行中读取 key 字段数据,parse=tab/csv 时索引为 0,parse=json 时索引为 "key",需要指定更多字
29+
段时可设置为数字:0,1,2,3 等或者 json 的 key 名称列表,长度不超过 9,长度表明取对应顺序的前几个字段,当 parse=tab 时索引必须均为整数,如果输入
30+
行中本身只包含部分字段,则可以在缺少字段的顺序位置用 -1 索引表示,表示跳过该顺序对应的字段,例如原输入行中不包含 mimeType 和 type 字段,则可以设
31+
置 indexes =0,1,2,3,-1,-1,6。
32+
(2)当数据源为 list 时,也可以设置该参数,用于指定下一步 process 操作所需要的字段,默认情况下包含 key 的下标,如果存在 process 操作则自动根据
33+
过滤设置的字段进行添加,无 process 的情况下包含全部下标:key,hash,fsize,putTime,mimeType,type,status,md5,endUser,如过自行设置则字段为
34+
也为这其中的一个或几个(因为必须和对象的变量名称一致),需要跳过的字段设置为 -1 即可,按照顺序依次解析所有字段
2135

2236
### 1. list 源可选参数
2337
```
@@ -85,19 +99,11 @@ prefix-right=
8599
```
86100
parse=
87101
separator=
88-
indexes=0,1,2
89102
```
90103
|参数名|参数值及类型 |含义|
91104
|-----|-------|-----|
92105
|parse| 字符串 json/tab/csv| 数据行格式,json 表示使用 json 解析,tab 表示使用分隔符(默认 "\t")分割解析,csv 表示使用 "," 分割解析|
93106
|separator| 字符串| 当 parse=tab 时,可另行指定该参数为格式分隔符来分析字段|
94-
|indexes| 字符串列表| 资源元信息字段索引(下标),设置输入行对应的元信息字段下标,默认只有 key 的下标,parse=tab/csv 时为 "0",parse=json 时默认为 "key"|
95-
96-
#### # 关于 indexes 索引
97-
indexes 指输入行中包含的资源元信息字段的映射关系,指定索引的顺序为 key,hash,fsize,putTime,mimeType,type,status,endUser,默认情况下,程
98-
序只从输入行中读取 key 字段数据,parse=tab/csv 时索引为 0,parse=json 时索引为 "key",需要指定更多字段时可设置为数字: 0,1,2,3 等或者 json
99-
的 key 名称列表,长度不超过 8,长度表明取对应顺序的前几个字段。当 parse-type=tab 时索引必须均为整数,如果输入行中本身只包含部分字段,则可以在缺
100-
少字段的顺序位置用 -1 索引表示,表示跳过该顺序对应的字段,例如原输入行中不包含 mimeType 和 type 字段,则可以设置 indexes =0,1,2,3,-1,-1,6。
101107

102108

103109
## 命令行方式

docs/exportts.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 导出 ts 列表操作
2+
3+
## 简介
4+
对 m3u8 的资源链接进行读取导出其中的 ts 文件列表。
5+
6+
## 配置文件选项
7+
8+
### 配置参数
9+
```
10+
process=exportts
11+
domain=
12+
protocol=
13+
url-index=
14+
rm-prefix=
15+
```
16+
|参数名|参数值及类型 | 含义|
17+
|-----|-------|-----|
18+
|process=exportts| 从 m3u8 导出 ts 时设置为exportts| 表示导出 ts 操作|
19+
|domain| 域名字符串| 用于拼接文件名生成链接的域名,数据源为 file 且指定 url-index 时无需设置|
20+
|protocol| http/https| 使用 http 还是 https 访问资源进行抓取(默认 http)|
21+
|url-index| 字符串| 通过 url 操作时需要设置的 url 索引(下标),需要手动指定才会进行解析|
22+
|rm-prefix| 字符串| 表示将得到的目标文件名去除存在的指定前缀后再进行exportts操作,用于输入的文件名可能比实际空间的文件名多了前缀的情况,如果设置了另外的 url-index 则该参数无效|
23+
24+
### 关于 url-index
25+
当使用 file 源且 parse=tab/csv 时下标必须为整数。url-index 表示输入行含 url 形式的源文件地址,未设置的情况下则使用 key 字段加上 domain 的
26+
方式访问源文件地址,key 下标用 indexes 参数设置。
27+
28+
## 命令行方式
29+
```
30+
-process=avinfo -domain= -protocol=
31+
```

docs/resultsave.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rm-fields=
2121
|save-total| true/false| 用于选择是否直接保存数据源完整输出结果,针对存在下一步处理过程时是否需要保存原始数据,如列举空间文件并修改文件类型时是否保存完整的列举结果,或者存在过滤条件时是否保存过滤之前的结果|
2222
|rm-fields| 字符串列表| 保存结果中去除的字段,为输入行中的实际,用 "," 做分隔,如 key,hash,表明从结果中去除 key 和 hash 字段再进行保存,不填表示所有字段均保留|
2323

24-
**rm-fields 对应的字段名列表应为资源元信息字段 keyhashfsizeputTimemimeTypetypestatus、endUser 加上自定义的字段名中的一个或几个。**
24+
**rm-fields 对应的字段名列表应为资源元信息字段 key,hash,fsize,putTime,mimeType,type,status,md5endUser 加上自定义的字段名中的一个或几个。**
2525

2626
## 命令行方式
2727
```

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.qiniu</groupId>
88
<artifactId>qsuits</artifactId>
9-
<version>4.31</version>
9+
<version>4.40</version>
1010
<name>qsuits</name>
1111
<description>qiniu-suits is a efficient tools for qiniu api implemented by java8.</description>
1212
<url>https://github.com/NigelWu95/qiniu-suits-java</url>

src/main/java/com/qiniu/convert/FileInfoToMap.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
package com.qiniu.convert;
22

3+
import com.qiniu.interfaces.ILineParser;
34
import com.qiniu.interfaces.ITypeConvert;
45
import com.qiniu.storage.model.FileInfo;
56
import com.qiniu.util.LineUtils;
67

8+
import java.io.IOException;
79
import java.util.*;
810
import java.util.stream.Collectors;
911

1012
public class FileInfoToMap implements ITypeConvert<FileInfo, Map<String, String>> {
1113

14+
private ILineParser<FileInfo> lineParser;
1215
private List<String> errorList = new ArrayList<>();
1316

17+
public FileInfoToMap(Map<String, String> indexMap) {
18+
this.lineParser = line -> LineUtils.getItemMap(line, indexMap);
19+
}
20+
21+
public Map<String, String> convertToV(FileInfo line) throws IOException {
22+
return lineParser.getItemMap(line);
23+
}
24+
1425
public List<Map<String, String>> convertToVList(List<FileInfo> lineList) {
1526
if (lineList == null || lineList.size() == 0) return new ArrayList<>();
1627
return lineList.stream()
1728
.map(fileInfo -> {
1829
try {
19-
return LineUtils.getItemMap(fileInfo);
30+
return lineParser.getItemMap(fileInfo);
2031
} catch (Exception e) {
2132
errorList.add(String.valueOf(fileInfo) + "\t" + e.getMessage());
2233
return null;

src/main/java/com/qiniu/convert/FileInfoToString.java

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public FileInfoToString(String format, String separator, List<String> rmFields)
2727
}
2828
}
2929

30+
public String convertToV(FileInfo line) throws IOException {
31+
return stringFormatter.toFormatString(line);
32+
}
33+
3034
public List<String> convertToVList(List<FileInfo> lineList) {
3135
if (lineList == null || lineList.size() == 0) return new ArrayList<>();
3236
return lineList.stream()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.qiniu.convert;
2+
3+
import com.google.gson.JsonObject;
4+
import com.qiniu.interfaces.IStringFormat;
5+
import com.qiniu.interfaces.ITypeConvert;
6+
import com.qiniu.util.LineUtils;
7+
8+
import java.io.IOException;
9+
import java.util.*;
10+
import java.util.stream.Collectors;
11+
12+
public class JsonToString implements ITypeConvert<JsonObject, String> {
13+
14+
private IStringFormat<JsonObject> stringFormatter;
15+
private List<String> errorList = new ArrayList<>();
16+
17+
public JsonToString(String format, String separator, List<String> rmFields) throws IOException {
18+
// 将 file info 的字段逐一进行获取是为了控制输出字段的顺序
19+
if ("json".equals(format)) {
20+
stringFormatter = JsonObject::toString;
21+
} else if ("csv".equals(format)) {
22+
stringFormatter = line -> LineUtils.toFormatString(line, ",", rmFields);
23+
} else if ("tab".equals(format)) {
24+
stringFormatter = line -> LineUtils.toFormatString(line, separator, rmFields);
25+
} else {
26+
throw new IOException("please check your format for map to string.");
27+
}
28+
}
29+
30+
public String convertToV(JsonObject line) throws IOException {
31+
return stringFormatter.toFormatString(line);
32+
}
33+
34+
public List<String> convertToVList(List<JsonObject> lineList) {
35+
if (lineList == null || lineList.size() == 0) return new ArrayList<>();
36+
return lineList.stream()
37+
.map(line -> {
38+
try {
39+
return stringFormatter.toFormatString(line);
40+
} catch (IOException e) {
41+
errorList.add(String.valueOf(line) + "\t" + e.getMessage());
42+
return null;
43+
}
44+
})
45+
.filter(Objects::nonNull)
46+
.collect(Collectors.toList());
47+
}
48+
49+
public List<String> getErrorList() {
50+
return errorList;
51+
}
52+
53+
public List<String> consumeErrorList() {
54+
List<String> errors = new ArrayList<>();
55+
Collections.addAll(errors, new String[errorList.size()]);
56+
Collections.copy(errors, errorList);
57+
errorList.clear();
58+
return errors;
59+
}
60+
}

src/main/java/com/qiniu/convert/LineToMap.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public LineToMap(String parseType, String separator, Map<String, String> indexMa
2525
}
2626
}
2727

28+
public Map<String, String> convertToV(String line) throws IOException {
29+
return lineParser.getItemMap(line);
30+
}
31+
2832
public List<Map<String, String>> convertToVList(List<String> lineList) {
2933
if (lineList == null || lineList.size() == 0) return new ArrayList<>();
3034
return lineList.stream()

src/main/java/com/qiniu/convert/MapToString.java

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public MapToString(String format, String separator, List<String> rmFields) throw
2626
}
2727
}
2828

29+
public String convertToV(Map<String, String> line) throws IOException {
30+
return stringFormatter.toFormatString(line);
31+
}
32+
2933
public List<String> convertToVList(List<Map<String, String>> lineList) {
3034
if (lineList == null || lineList.size() == 0) return new ArrayList<>();
3135
return lineList.stream()

0 commit comments

Comments
 (0)