Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for pfop workflow template #435

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 7.14.0 (2024-10-16)
* 对象存储,持久化处理支持工作流模版

## 7.13.0 (2024-09-05)
* 对象存储,验证回调方法新增支持 Qiniu 签名
* 对象存储,调整查询空间区域域名顺序与默认空间管理域名
Expand Down
3 changes: 2 additions & 1 deletion src/Qiniu/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,11 @@ public function uploadToken($bucket, $key = null, $expires = 3600, $policy = nul
'fsizeMin',
'fsizeLimit',

'persistentOps',
'persistentOps', // 与 persistentWorkflowTemplateID 二选一
'persistentNotifyUrl',
'persistentPipeline',
'persistentType', // 为 `1` 时开启闲时任务
'persistentWorkflowTemplateID', // 与 persistentOps 二选一

'deleteAfterDays',
'fileType',
Expand Down
2 changes: 1 addition & 1 deletion src/Qiniu/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

final class Config
{
const SDK_VER = '7.13.0';
const SDK_VER = '7.14.0';

const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改

Expand Down
9 changes: 6 additions & 3 deletions src/Qiniu/Processing/PersistentFop.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,22 @@ public function __construct($auth, $config = null, $proxy = null, $proxy_auth =
public function execute(
$bucket,
$key,
$fops,
$fops = null,
$pipeline = null,
$notify_url = null,
$force = false,
$type = null
$type = null,
$workflow_template_id = null
) {
if (is_array($fops)) {
$fops = implode(';', $fops);
}
$params = array('bucket' => $bucket, 'key' => $key, 'fops' => $fops);
$params = array('bucket' => $bucket, 'key' => $key);
\Qiniu\setWithoutEmpty($params, 'fops', $fops);
\Qiniu\setWithoutEmpty($params, 'pipeline', $pipeline);
\Qiniu\setWithoutEmpty($params, 'notifyURL', $notify_url);
\Qiniu\setWithoutEmpty($params, 'type', $type);
\Qiniu\setWithoutEmpty($params, 'workflowTemplateID', $workflow_template_id);
if ($force) {
$params['force'] = 1;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Qiniu/Storage/ArgusManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function censorStatus($jobid)
$url = $scheme . Config::ARGUS_HOST . "/v3/jobs/video/$jobid";
$response = $this->get($url);
if (!$response->ok()) {
print("statusCode: " . $response->statusCode);
return array(null, new Error($url, $response));
}
return array($response->json(), null);
Expand Down Expand Up @@ -118,7 +117,6 @@ private function post($url, $body)
$headers['Content-Type'] = 'application/json';
$ret = Client::post($url, $body, $headers, $this->proxy->makeReqOpt());
if (!$ret->ok()) {
print("statusCode: " . $ret->statusCode);
return array(null, new Error($url, $ret));
}
$r = ($ret->body === null) ? array() : $ret->json();
Expand Down
148 changes: 117 additions & 31 deletions tests/Qiniu/Tests/PfopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,34 @@

use PHPUnit\Framework\TestCase;

use Qiniu\Auth;
use Qiniu\Processing\PersistentFop;
use Qiniu\Storage\UploadManager;
use Qiniu\Region;
use Qiniu\Config;

//use Qiniu\Region;
//use Qiniu\Config;

class PfopTest extends TestCase
{
/**
* @var Auth
*/
private static $testAuth;

private static $bucketName;

/**
* @beforeClass
*/
public static function prepareEnvironment()
{
global $bucketName;
global $testAuth;

self::$bucketName = $bucketName;
self::$testAuth = $testAuth;
}

private static function getConfig()
{
// use this func to test in test env
Expand Down Expand Up @@ -52,7 +73,7 @@ public function testPfopExecuteAndStatusWithMultipleFops()
$this->assertNull($error);
}

private function pfopTypeTestData()
private function pfopOptionsTestData()
{
return array(
array(
Expand All @@ -69,66 +90,123 @@ private function pfopTypeTestData()
),
array(
'type' => 2
),
array(
'workflowTemplateID' => 'test-workflow'
)
);
}

public function testPfopWithIdleTimeType()
public function testPfopExecuteWithOptions()
{
global $testAuth;

$bucket = 'testres';
$key = 'sintel_trailer.mp4';
$persistentEntry = \Qiniu\entry($bucket, 'test-pfop-type_1');
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry;
$pfop = new PersistentFop($testAuth, self::getConfig());
$bucket = self::$bucketName;
$key = 'qiniu.png';
$pfop = new PersistentFop(self::$testAuth, self::getConfig());

$testCases = $this->pfopTypeTestData();
$testCases = $this->pfopOptionsTestData();

foreach ($testCases as $testCase) {
$workflowTemplateID = null;
$type = null;

if (array_key_exists('workflowTemplateID', $testCase)) {
$workflowTemplateID = $testCase['workflowTemplateID'];
}
if (array_key_exists('type', $testCase)) {
$type = $testCase['type'];
}

if ($workflowTemplateID) {
$fops = null;
} else {
$persistentEntry = \Qiniu\entry(
$bucket,
implode(
'_',
array(
'test-pfop/test-pfop-by-api',
'type',
$type
)
)
);
$fops = 'avinfo|saveas/' . $persistentEntry;
}
list($id, $error) = $pfop->execute(
$bucket,
$key,
$fops,
null,
null,
false,
$testCase['type']
$type,
$workflowTemplateID
);

if (in_array($testCase['type'], array(null, 0, 1))) {
if (in_array($type, array(null, 0, 1))) {
$this->assertNull($error);
list($status, $error) = $pfop->status($id);
$this->assertNotNull($status);
$this->assertNull($error);
if ($testCase['type'] == 1) {
if ($type == 1) {
$this->assertEquals(1, $status['type']);
}
if ($workflowTemplateID) {
// assertStringContainsString when PHPUnit >= 8.0
$this->assertTrue(
strpos(
$status['taskFrom'],
$workflowTemplateID
) !== false
);
}
$this->assertNotEmpty($status['creationDate']);
} else {
$this->assertNotNull($error);
}
}
}


public function testPfopByUploadPolicy()
public function testPfopWithUploadPolicy()
{
global $testAuth;
$bucket = 'testres';
$key = 'sintel_trailer.mp4';
$persistentEntry = \Qiniu\entry($bucket, 'test-pfop-type_1');
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry;
$bucket = self::$bucketName;
$testAuth = self::$testAuth;
$key = 'test-pfop/upload-file';

$testCases = $this->pfopTypeTestData();
$testCases = $this->pfopOptionsTestData();

foreach ($testCases as $testCase) {
$workflowTemplateID = null;
$type = null;

if (array_key_exists('workflowTemplateID', $testCase)) {
$workflowTemplateID = $testCase['workflowTemplateID'];
}
if (array_key_exists('type', $testCase)) {
$type = $testCase['type'];
}

$putPolicy = array(
'persistentOps' => $fops,
'persistentType' => $testCase['type']
'persistentType' => $type
);
if ($workflowTemplateID) {
$putPolicy['persistentWorkflowTemplateID'] = $workflowTemplateID;
} else {
$persistentEntry = \Qiniu\entry(
$bucket,
implode(
'_',
array(
'test-pfop/test-pfop-by-upload',
'type',
$type
)
)
);
$putPolicy['persistentOps'] = 'avinfo|saveas/' . $persistentEntry;
}

if ($testCase['type'] == null) {
if ($type == null) {
unset($putPolicy['persistentType']);
}

Expand All @@ -148,7 +226,7 @@ public function testPfopByUploadPolicy()
true
);

if (in_array($testCase['type'], array(null, 0, 1))) {
if (in_array($type, array(null, 0, 1))) {
$this->assertNull($error);
$this->assertNotEmpty($ret['persistentId']);
$id = $ret['persistentId'];
Expand All @@ -162,19 +240,27 @@ public function testPfopByUploadPolicy()

$this->assertNotNull($status);
$this->assertNull($error);
if ($testCase['type'] == 1) {
if ($type == 1) {
$this->assertEquals(1, $status['type']);
}
if ($workflowTemplateID) {
// assertStringContainsString when PHPUnit >= 8.0
$this->assertTrue(
strpos(
$status['taskFrom'],
$workflowTemplateID
) !== false
);
}
$this->assertNotEmpty($status['creationDate']);
}
}

public function testMkzip()
{
global $testAuth;
$bucket = 'phpsdk';
$bucket = self::$bucketName;
$key = 'php-logo.png';
$pfop = new PersistentFop($testAuth, null);
$pfop = new PersistentFop(self::$testAuth, null);

$url1 = 'http://phpsdk.qiniudn.com/php-logo.png';
$url2 = 'http://phpsdk.qiniudn.com/php-sdk.html';
Expand Down
Loading