Skip to content

Commit 9d260cb

Browse files
author
YangSen-qn
committed
pfop support template
1 parent 980a1c6 commit 9d260cb

File tree

6 files changed

+132
-9
lines changed

6 files changed

+132
-9
lines changed

src/main/java/com/qiniu/media/apis/ApiPfop.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static class Request extends Api.Request {
6262
/**
6363
* 数据处理命令列表,以 `;` 分隔,可以指定多个数据处理命令
6464
*/
65-
private String fops;
65+
private String fops = null;
6666

6767
/**
6868
* 处理结果通知接收 URL
@@ -84,22 +84,36 @@ public static class Request extends Api.Request {
8484
*/
8585
private String pipeline = null;
8686

87+
/**
88+
* 工作流模板 ID
89+
*/
90+
private String workflowTemplateId = null;
91+
8792
/**
8893
* 请求构造函数
8994
*
9095
* @param urlPrefix 请求 scheme + host 【可选】
9196
* 若为空则会直接从 HostProvider 中获取
9297
* @param bucketName 空间名称 【必须】
9398
* @param objectName 对象名称 【必须】
94-
* @param fops 数据处理命令列表,以 `;` 分隔,可以指定多个数据处理命令 【必须】
9599
*/
96-
public Request(String urlPrefix, String bucketName, String objectName, String fops) {
100+
public Request(String urlPrefix, String bucketName, String objectName) {
97101
super(urlPrefix);
98102
this.setMethod(MethodType.POST);
99103
this.setAuthType(AuthTypeQiniu);
100104
this.bucketName = bucketName;
101105
this.objectName = objectName;
106+
}
107+
108+
/**
109+
* 设置参数【可选】
110+
*
111+
* @param fops 数据处理命令列表,以 `;` 分隔,可以指定多个数据处理命令
112+
* @return Request
113+
*/
114+
public Request setFops(String fops) {
102115
this.fops = fops;
116+
return this;
103117
}
104118

105119
/**
@@ -146,6 +160,17 @@ public Request setPipeline(String pipeline) {
146160
return this;
147161
}
148162

163+
/**
164+
* 设置参数【可选】
165+
*
166+
* @param workflowTemplateId 工作流模板 ID
167+
* @return Request
168+
*/
169+
public Request setWorkflowTemplateId(String workflowTemplateId) {
170+
this.workflowTemplateId = workflowTemplateId;
171+
return this;
172+
}
173+
149174
@Override
150175
protected void prepareToRequest() throws QiniuException {
151176
if (this.bucketName == null) {
@@ -154,9 +179,6 @@ protected void prepareToRequest() throws QiniuException {
154179
if (this.objectName == null) {
155180
throw new QiniuException(new NullPointerException("objectName can't empty"));
156181
}
157-
if (this.fops == null) {
158-
throw new QiniuException(new NullPointerException("fops can't empty"));
159-
}
160182

161183
super.prepareToRequest();
162184
}
@@ -184,7 +206,9 @@ protected void buildBodyInfo() throws QiniuException {
184206
StringMap fields = new StringMap();
185207
fields.put("bucket", this.bucketName);
186208
fields.put("key", this.objectName);
187-
fields.put("fops", this.fops);
209+
if (this.fops != null) {
210+
fields.put("fops", this.fops);
211+
}
188212
if (this.notifyUrl != null) {
189213
fields.put("notifyURL", this.notifyUrl);
190214
}
@@ -197,6 +221,9 @@ protected void buildBodyInfo() throws QiniuException {
197221
if (this.pipeline != null) {
198222
fields.put("pipeline", this.pipeline);
199223
}
224+
if (this.workflowTemplateId != null) {
225+
fields.put("workflowTemplateID", this.workflowTemplateId);
226+
}
200227
this.setFormBody(fields);
201228

202229
super.buildBodyInfo();

src/main/java/com/qiniu/media/apis/ApiPrefop.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ public static final class PfopTask {
287287
@SerializedName("pipeline")
288288
private String pipeline;
289289

290+
/**
291+
* 如果没有,则表示通过 `api+fops` 命令提交的任务,否则遵循规则 `<source>: <source_id>`,其中 `<source>` 当前可选 `workflow` 或 `trigger`
292+
*/
293+
@SerializedName("taskFrom")
294+
private String taskFrom;
295+
290296
/**
291297
* 云处理请求的请求 ID
292298
*/
@@ -371,6 +377,16 @@ public String getPipeline() {
371377
return this.pipeline;
372378
}
373379

380+
/**
381+
* 获取变量值
382+
* 如果没有,则表示通过 `api+fops` 命令提交的任务,否则遵循规则 `<source>: <source_id>`,其中 `<source>` 当前可选 `workflow` 或 `trigger`
383+
*
384+
* @return taskFrom
385+
*/
386+
public String getTaskFrom() {
387+
return this.taskFrom;
388+
}
389+
374390
/**
375391
* 获取变量值
376392
* 云处理请求的请求 ID

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,30 @@ public String pfop(String bucket, String key, String fops) throws QiniuException
8383
* @param bucket 空间名
8484
* @param key 文件名
8585
* @param fops fops指令,如果有多个指令,需要使用分号(;)进行拼接,例如 avthumb/mp4/xxx|saveas/xxx;vframe/jpg/xxx|saveas/xxx
86-
* @param params notifyURL、force、pipeline、type等参数
86+
* @param params notifyURL、force、pipeline、type、persistentWorkflowTemplateID等参数
8787
* @return persistentId 请求返回的任务ID,可以根据该ID查询任务状态
8888
* @throws QiniuException 触发失败异常,包含错误响应等信息
8989
* <a href="http://developer.qiniu.com/dora/api/persistent-data-processing-pfop"> 相关链接 </a>
9090
*/
9191
public String pfop(String bucket, String key, String fops, StringMap params) throws QiniuException {
92+
if (params == null) {
93+
params = new StringMap();
94+
}
95+
params.put("fops", fops);
96+
return pfop(bucket, key, params);
97+
}
98+
99+
/**
100+
* 发送请求对空间中的文件进行持久化处理
101+
*
102+
* @param bucket 空间名
103+
* @param key 文件名
104+
* @param params notifyURL、force、pipeline、type、fops、persistentWorkflowTemplateID 等参数
105+
* @return persistentId 请求返回的任务ID,可以根据该ID查询任务状态
106+
* @throws QiniuException 触发失败异常,包含错误响应等信息
107+
* <a href="http://developer.qiniu.com/dora/api/persistent-data-processing-pfop"> 相关链接 </a>
108+
*/
109+
public String pfop(String bucket, String key, StringMap params) throws QiniuException {
92110
Integer force = null;
93111
if (params.get("force") != null) {
94112
if (params.get("force") instanceof Integer) {
@@ -121,9 +139,27 @@ public String pfop(String bucket, String key, String fops, StringMap params) thr
121139
throw QiniuException.unrecoverable("type type error, should be Integer");
122140
}
123141
}
142+
String fops = null;
143+
if (params.get("fops") != null) {
144+
if (params.get("fops") instanceof String) {
145+
fops = (String) params.get("fops");
146+
} else {
147+
throw QiniuException.unrecoverable("fops type error, should be String");
148+
}
149+
}
150+
String workflowTemplateID = null;
151+
if (params.get("persistentWorkflowTemplateID") != null) {
152+
if (params.get("persistentWorkflowTemplateID") instanceof String) {
153+
workflowTemplateID = (String) params.get("persistentWorkflowTemplateID");
154+
} else {
155+
throw QiniuException.unrecoverable("persistentWorkflowTemplateID type error, should be String");
156+
}
157+
}
124158

125159
String url = configuration.apiHost(auth.accessKey, bucket);
126-
ApiPfop.Request request = new ApiPfop.Request(url, bucket, key, fops)
160+
ApiPfop.Request request = new ApiPfop.Request(url, bucket, key)
161+
.setFops(fops)
162+
.setWorkflowTemplateId(workflowTemplateID)
127163
.setPipeline(pipeline)
128164
.setForce(force)
129165
.setNotifyUrl(notifyUrl)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public class OperationStatus {
3030
*/
3131
public String inputBucket;
3232

33+
/***
34+
* taskFrom
35+
* 1. 如果没有 taskFrom, 则表示是通过 api+fops命令 提交的任务, 否则见 2
36+
* 2. taskFrom 字段规则: <source>: <source_id>,其中 source 当前可选: workflow|trigger
37+
**/
38+
public String taskFrom;
39+
3340
/**
3441
* 云处理操作的处理队列
3542
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public final class Auth {
5252
"persistentOps",
5353
"persistentNotifyUrl",
5454
"persistentPipeline",
55+
"persistentWorkflowTemplateID",
5556

5657
"deleteAfterDays",
5758
"fileType",

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.qiniu.storage.Configuration;
99
import com.qiniu.storage.Region;
1010
import com.qiniu.util.Auth;
11+
import com.qiniu.util.StringMap;
1112
import com.qiniu.util.StringUtils;
1213
import com.qiniu.util.UrlSafeBase64;
1314
import org.junit.jupiter.api.Tag;
@@ -169,4 +170,39 @@ void testPfopWithType() {
169170
assertTrue(ResCode.find(ex.code(), ResCode.getPossibleResCode(612)));
170171
}
171172
}
173+
174+
@Test
175+
@Tag("IntegrationTest")
176+
void testPfopWithTemplate() {
177+
try {
178+
Auth auth = TestConfig.testAuth;
179+
Map<String, Region> bucketKeyMap = new HashMap<String, Region>();
180+
TestConfig.TestFile[] files = TestConfig.getTestFileArray();
181+
for (TestConfig.TestFile testFile : files) {
182+
bucketKeyMap.put(testFile.getBucketName(), testFile.getRegion());
183+
}
184+
185+
String templateId = "java-sdk-test-template";
186+
for (Map.Entry<String, Region> entry : bucketKeyMap.entrySet()) {
187+
String bucket = entry.getKey();
188+
Region region = entry.getValue();
189+
190+
Configuration cfg = new Configuration(region);
191+
OperationManager operationManager = new OperationManager(auth, cfg);
192+
StringMap params = new StringMap();
193+
params.put("persistentWorkflowTemplateID", templateId);
194+
String jobID = operationManager.pfop(bucket, TestConfig.testMp4FileKey, params);
195+
196+
OperationStatus status = operationManager.prefop(bucket, jobID);
197+
assertNotNull(status, "1. prefop type error");
198+
assertNotNull(status.creationDate, "1. prefop type error");
199+
assertTrue(status.code == 0 || status.code == 1 || status.code == 3, "2. prefop type error");
200+
assertNotNull(status.taskFrom, "34. prefop type error");
201+
}
202+
203+
} catch (QiniuException ex) {
204+
ex.printStackTrace();
205+
assertTrue(ResCode.find(ex.code(), ResCode.getPossibleResCode(612)));
206+
}
207+
}
172208
}

0 commit comments

Comments
 (0)