Skip to content

Commit ff27ab5

Browse files
author
YangSen-qn
committed
Merge branch 'master' into code-gen
# Conflicts: # src/main/java/com/qiniu/storage/Api.java
2 parents 63fad41 + 7239d04 commit ff27ab5

File tree

5 files changed

+87
-10
lines changed

5 files changed

+87
-10
lines changed

src/main/java/com/qiniu/processing/OperationManager.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public String pfop(String bucket, String key, String fops) throws QiniuException
8080
* @param bucket 空间名
8181
* @param key 文件名
8282
* @param fops fops指令,如果有多个指令,需要使用分号(;)进行拼接,例如 avthumb/mp4/xxx|saveas/xxx;vframe/jpg/xxx|saveas/xxx
83-
* @param params notifyURL、force、pipeline 等参数
83+
* @param params notifyURL、force、pipeline、type等参数
8484
* @return persistentId 请求返回的任务ID,可以根据该ID查询任务状态
8585
* @throws QiniuException 触发失败异常,包含错误响应等信息
8686
* <a href="http://developer.qiniu.com/dora/api/persistent-data-processing-pfop"> 相关链接 </a>
@@ -154,8 +154,34 @@ public String pfop(String bucket, String key, String fops, String pipeline, bool
154154
*/
155155
public String pfop(String bucket, String key, String fops, String pipeline, String notifyURL, boolean force)
156156
throws QiniuException {
157-
StringMap params = new StringMap().putNotEmpty("pipeline", pipeline).
158-
putNotEmpty("notifyURL", notifyURL).putWhen("force", 1, force);
157+
StringMap params = new StringMap()
158+
.putNotEmpty("pipeline", pipeline)
159+
.putNotEmpty("notifyURL", notifyURL)
160+
.putWhen("force", 1, force);
161+
return pfop(bucket, key, fops, params);
162+
}
163+
164+
/**
165+
* 发送请求对空间中的文件进行持久化处理
166+
*
167+
* @param bucket 空间名
168+
* @param key 文件名
169+
* @param fops fop指令
170+
* @param pipeline 持久化数据处理队列名称
171+
* @param notifyURL 处理结果通知地址,任务完成后自动以POST方式将处理结果提交到指定的地址
172+
* @param type 任务类型,0:非闲时任务,1:闲时任务
173+
* @param force 用于对同一个指令进行强制处理时指定,一般用于覆盖空间已有文件或者重试失败的指令
174+
* @return persistentId 请求返回的任务ID,可以根据该ID查询任务状态
175+
* @throws QiniuException 触发失败异常,包含错误响应等信息
176+
* <a href="http://developer.qiniu.com/dora/api/persistent-data-processing-pfop"> 相关链接 </a>
177+
*/
178+
public String pfop(String bucket, String key, String fops, String pipeline, String notifyURL, String type, boolean force)
179+
throws QiniuException {
180+
StringMap params = new StringMap()
181+
.putNotEmpty("type", type)
182+
.putNotEmpty("pipeline", pipeline)
183+
.putNotEmpty("notifyURL", notifyURL)
184+
.putWhen("force", 1, force);
159185
return pfop(bucket, key, fops, params);
160186
}
161187

src/main/java/com/qiniu/processing/OperationStatus.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,49 @@ public class OperationStatus {
99
* 持久化处理的进程ID,即 persistentId
1010
*/
1111
public String id;
12+
1213
/**
1314
* 状态码 0 成功,1 等待处理,2 正在处理,3 处理失败,4 通知提交失败
1415
*/
1516
public int code;
17+
1618
/**
1719
* 与状态码相对应的详细描述
1820
*/
1921
public String desc;
22+
2023
/**
2124
* 处理源文件的文件名
2225
*/
2326
public String inputKey;
27+
2428
/**
2529
* 处理源文件所在的空间名
2630
*/
2731
public String inputBucket;
32+
2833
/**
2934
* 云处理操作的处理队列
3035
*/
3136
public String pipeline;
37+
3238
/**
3339
* 云处理请求的请求id,主要用于七牛技术人员的问题排查
3440
*/
3541
public String reqid;
42+
43+
/**
44+
* 是否是闲时任务
45+
* 0:非闲时任务
46+
* 1:显示任务
47+
*/
48+
public String type;
49+
50+
/**
51+
* 任务创建时间
52+
*/
53+
public String creationDate;
54+
3655
/**
3756
* 云处理操作列表,包含每个云处理操作的状态信息
3857
*/

src/main/java/com/qiniu/storage/Api.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ private static okhttp3.MultipartBody createFormRequestBody(MultipartBody formBod
12511251
}
12521252

12531253
final okhttp3.MultipartBody.Builder b = new okhttp3.MultipartBody.Builder();
1254-
if (StringUtils.isNullOrEmpty(formBody.name)) {
1254+
if (!StringUtils.isNullOrEmpty(formBody.name)) {
12551255
b.addFormDataPart(formBody.name, formBody.fileName, body);
12561256
}
12571257

@@ -1299,17 +1299,17 @@ private MultipartBody(String name, String fileName, StringMap fields, File body,
12991299

13001300
private void setupBody() throws QiniuException {
13011301
okhttp3.MultipartBody formBody = createFormRequestBody(this);
1302-
Buffer buffer = new Buffer();
1303-
try {
1304-
formBody.writeTo(buffer);
1305-
} catch (IOException e) {
1306-
throw QiniuException.unrecoverable(e);
1307-
}
13081302

13091303
// 只有使用 bytesBody 和 fileBody 都没有时才会处理,其他不处理
13101304
// bytes 用作签名,Multipart 不做签名
13111305
// bytes
13121306
if (this.bytesBody == null && this.fileBody == null) {
1307+
Buffer buffer = new Buffer();
1308+
try {
1309+
formBody.writeTo(buffer);
1310+
} catch (IOException e) {
1311+
throw QiniuException.unrecoverable(e);
1312+
}
13131313
this.bytes = buffer.readByteArray();
13141314
}
13151315

src/main/java/com/qiniu/util/Auth.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public final class Auth {
4848
"fsizeMin",
4949
"trafficLimit",
5050

51+
"persistentType",
5152
"persistentOps",
5253
"persistentNotifyUrl",
5354
"persistentPipeline",

src/test/java/test/com/qiniu/processing/PfopTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.qiniu.processing.OperationStatus;
88
import com.qiniu.storage.Configuration;
99
import com.qiniu.storage.Region;
10+
import com.qiniu.util.Auth;
1011
import com.qiniu.util.StringUtils;
1112
import com.qiniu.util.UrlSafeBase64;
1213
import org.junit.jupiter.api.Tag;
@@ -138,4 +139,34 @@ private void testPfopIsSuccess(String jobid) {
138139
assertEquals(0, status.code);
139140
}
140141

142+
@Test
143+
@Tag("IntegrationTest")
144+
void testPfopA() {
145+
try {
146+
Auth auth = TestConfig.testAuth;
147+
Map<String, Region> bucketKeyMap = new HashMap<String, Region>();
148+
TestConfig.TestFile[] files = TestConfig.getTestFileArray();
149+
for (TestConfig.TestFile testFile : files) {
150+
bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion());
151+
}
152+
for (Map.Entry<String, Region> entry : bucketKeyMap.entrySet()) {
153+
String bucket = entry.getKey();
154+
Region region = entry.getValue();
155+
156+
Configuration cfg = new Configuration(region);
157+
OperationManager operationManager = new OperationManager(auth, cfg);
158+
String jobID = operationManager.pfop(bucket, TestConfig.testMp4FileKey, "avinfo", "", "", "1", true);
159+
160+
OperationStatus status = operationManager.prefop(bucket, jobID);
161+
assertNotNull(status, "1. prefop type error");
162+
assertNotNull(status.creationDate, "1. prefop type error");
163+
assertTrue(status.code == 0 || status.code == 1 || status.code == 3, "2. prefop type error");
164+
assertEquals("1", status.type, "3. prefop type error");
165+
}
166+
167+
} catch (QiniuException ex) {
168+
ex.printStackTrace();
169+
assertTrue(ResCode.find(ex.code(), ResCode.getPossibleResCode(612)));
170+
}
171+
}
141172
}

0 commit comments

Comments
 (0)