From d6c2a758b6490c699acb405b6c8e36d26f6a07cd Mon Sep 17 00:00:00 2001
From: yangpeng <183851063@qq.com>
Date: Mon, 27 Mar 2023 12:20:14 +0800
Subject: [PATCH] add reserved capacity api
---
samples/Bucket.php | 82 +++---
samples/BucketStat.php | 6 +
samples/ReservedCapacity.php | 274 ++++++++++++++++++
src/OSS/Core/OssUtil.php | 21 +-
src/OSS/Model/BucketInfo.php | 17 ++
src/OSS/Model/BucketStat.php | 70 +++++
src/OSS/Model/CreateReservedCapacity.php | 77 +++++
.../Model/ListBucketWithReservedCapacity.php | 51 ++++
src/OSS/Model/ListReservedCapacity.php | 47 +++
src/OSS/Model/ReservedCapacityRecord.php | 223 ++++++++++++++
src/OSS/Model/UpdateReservedCapacity.php | 89 ++++++
src/OSS/OssClient.php | 211 ++++++++++++--
src/OSS/Result/GetBucketInfoResult.php | 4 +-
src/OSS/Result/GetReservedCapacityResult.php | 24 ++
.../ListBucketWithReservedCapacityResult.php | 24 ++
src/OSS/Result/ListReservedCapacityResult.php | 24 ++
.../OSS/Tests/CreateReservedCapacityTest.php | 49 ++++
tests/OSS/Tests/GetBucketInfoResultTest.php | 105 +++++++
tests/OSS/Tests/GetBucketStatResultTest.php | 60 ++++
.../Tests/GetReservedCapacityResultTest.php | 77 +++++
...stBucketWithReservedCapacityResultTest.php | 60 ++++
.../Tests/ListReservedCapacityResultTest.php | 119 ++++++++
.../Tests/OssClientReservedCapacityTest.php | 131 +++++++++
.../OSS/Tests/UpdateReservedCapacityTest.php | 59 ++++
24 files changed, 1841 insertions(+), 63 deletions(-)
create mode 100644 samples/ReservedCapacity.php
create mode 100644 src/OSS/Model/CreateReservedCapacity.php
create mode 100644 src/OSS/Model/ListBucketWithReservedCapacity.php
create mode 100644 src/OSS/Model/ListReservedCapacity.php
create mode 100644 src/OSS/Model/ReservedCapacityRecord.php
create mode 100644 src/OSS/Model/UpdateReservedCapacity.php
create mode 100644 src/OSS/Result/GetReservedCapacityResult.php
create mode 100644 src/OSS/Result/ListBucketWithReservedCapacityResult.php
create mode 100644 src/OSS/Result/ListReservedCapacityResult.php
create mode 100644 tests/OSS/Tests/CreateReservedCapacityTest.php
create mode 100644 tests/OSS/Tests/GetBucketInfoResultTest.php
create mode 100644 tests/OSS/Tests/GetReservedCapacityResultTest.php
create mode 100644 tests/OSS/Tests/ListBucketWithReservedCapacityResultTest.php
create mode 100644 tests/OSS/Tests/ListReservedCapacityResultTest.php
create mode 100644 tests/OSS/Tests/OssClientReservedCapacityTest.php
create mode 100644 tests/OSS/Tests/UpdateReservedCapacityTest.php
diff --git a/samples/Bucket.php b/samples/Bucket.php
index a54b74e6..adcb4154 100644
--- a/samples/Bucket.php
+++ b/samples/Bucket.php
@@ -14,6 +14,17 @@
$ossClient->createBucket($bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
Common::println("bucket $bucket created");
+// Create a bucket under the reserved capacity
+$id = "a1b398e6-c4e5-481b-8638-*******";
+$options = array(
+ OssClient::OSS_STORAGE => OssClient::OSS_STORAGE_DEEPCOLDARCHIVE,
+ OssClient::OSS_REDUNDANCY => OssClient::OSS_REDUNDANCY_LRS,
+ OssClient::OSS_RESERVED_CAPACITY_ID => $id
+
+);
+$ossClient->createBucket($bucket, OssClient::OSS_ACL_TYPE_PRIVATE,$options);
+Common::println("bucket $bucket created");
+
// Check whether a bucket exists
$doesExist = $ossClient->doesBucketExist($bucket);
Common::println("bucket $bucket exist? " . ($doesExist ? "yes" : "no"));
@@ -34,6 +45,9 @@
Common::println("bucket storage class:".$info->getStorageClass()."\n");
Common::println("bucket extranet endpoint:".$info->getExtranetEndpoint()."\n");
Common::println("bucket intranet endpoint:".$info->getIntranetEndpoint()."\n");
+if ($info->getReservedCapacityInstanceId() != null){
+ Common::println("bucket reserved capacity instance id:".$info->getReservedCapacityInstanceId()."\n");
+}
// Get the bucket list
@@ -111,20 +125,23 @@ function doesBucketExist($ossClient, $bucket)
*/
function getBucketInfo($ossClient, $bucket)
{
- try {
- $info = $ossClient->getBucketInfo($bucket);
- printf("bucket name:%s\n", $info->getName());
- printf("bucket location:%s\n", $info->getLocation());
- printf("bucket creation time:%s\n", $info->getCreateDate());
- printf("bucket storage class:%s\n", $info->getStorageClass());
- printf("bucket extranet endpoint:%s\n", $info->getExtranetEndpoint());
- printf("bucket intranet endpoint:%s\n", $info->getIntranetEndpoint());
- } catch (OssException $e) {
- printf(__FUNCTION__ . ": FAILED\n");
- printf($e->getMessage() . "\n");
- return;
- }
- print(__FUNCTION__ . ": OK" . "\n");
+ try {
+ $info = $ossClient->getBucketInfo($bucket);
+ printf("bucket name:%s\n", $info->getName());
+ printf("bucket location:%s\n", $info->getLocation());
+ printf("bucket creation time:%s\n", $info->getCreateDate());
+ printf("bucket storage class:%s\n", $info->getStorageClass());
+ printf("bucket extranet endpoint:%s\n", $info->getExtranetEndpoint());
+ printf("bucket intranet endpoint:%s\n", $info->getIntranetEndpoint());
+ if ($info->getReservedCapacityInstanceId() != null){
+ Common::println("bucket reserved capacity instance id:".$info->getReservedCapacityInstanceId()."\n");
+ }
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+ print(__FUNCTION__ . ": OK" . "\n");
}
@@ -136,16 +153,15 @@ function getBucketInfo($ossClient, $bucket)
*/
function getBucketLocation($ossClient, $bucket)
{
- try {
- $regions = $ossClient->getBucketLocation($bucket);
- } catch (OssException $e) {
- printf(__FUNCTION__ . ": FAILED\n");
- printf($e->getMessage() . "\n");
- return;
- }
-
- print("bucket $bucket region: " .print_r($regions,true));
-
+ try {
+ $regions = $ossClient->getBucketLocation($bucket);
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+
+ print("bucket $bucket region: " .print_r($regions,true));
}
@@ -157,15 +173,15 @@ function getBucketLocation($ossClient, $bucket)
*/
function getBucketMeta($ossClient, $bucket)
{
- try {
- $metas = $ossClient->getBucketMeta($bucket);
- } catch (OssException $e) {
- printf(__FUNCTION__ . ": FAILED\n");
- printf($e->getMessage() . "\n");
- return;
- }
- print(__FUNCTION__ . ": OK" . "\n");
- print("bucket $bucket meta: " .print_r($metas,true));
+ try {
+ $metas = $ossClient->getBucketMeta($bucket);
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+ print(__FUNCTION__ . ": OK" . "\n");
+ print("bucket $bucket meta: " .print_r($metas,true));
}
/**
diff --git a/samples/BucketStat.php b/samples/BucketStat.php
index 43c03e65..ae9f549d 100644
--- a/samples/BucketStat.php
+++ b/samples/BucketStat.php
@@ -27,6 +27,9 @@
Common::println("Bucket ".$bucket." cold archive storage is:".$stat->getColdArchiveStorage().PHP_EOL);
Common::println("Bucket ".$bucket." cold archive real storage is:".$stat->getColdArchiveRealStorage().PHP_EOL);
Common::println("Bucket ".$bucket." cold archive object count is:".$stat->getColdArchiveObjectCount().PHP_EOL);
+Common::println("Bucket ".$bucket." deep cold archive storage is:".$stat->getDeepColdArchiveStorage().PHP_EOL);
+Common::println("Bucket ".$bucket." deep cold archive real storage is:".$stat->getDeepColdArchiveRealStorage().PHP_EOL);
+Common::println("Bucket ".$bucket." deep cold archive object count is:".$stat->getDeepColdArchiveObjectCount().PHP_EOL);
//******************************* For complete usage, see the following functions ****************************************************
getBucketStat($ossClient,$bucket);
@@ -61,5 +64,8 @@ function getBucketStat($ossClient, $bucket)
printf("Bucket ".$bucket." cold archive storage is:".$stat->getColdArchiveStorage().PHP_EOL);
printf("Bucket ".$bucket." cold archive real storage is:".$stat->getColdArchiveRealStorage().PHP_EOL);
printf("Bucket ".$bucket." cold archive object count is:".$stat->getColdArchiveObjectCount().PHP_EOL);
+ printf("Bucket ".$bucket." deep cold archive storage is:".$stat->getDeepColdArchiveStorage().PHP_EOL);
+ printf("Bucket ".$bucket." deep cold archive real storage is:".$stat->getDeepColdArchiveRealStorage().PHP_EOL);
+ printf("Bucket ".$bucket." deep cold archive object count is:".$stat->getDeepColdArchiveObjectCount().PHP_EOL);
print(__FUNCTION__ . ": OK" . "\n");
}
\ No newline at end of file
diff --git a/samples/ReservedCapacity.php b/samples/ReservedCapacity.php
new file mode 100644
index 00000000..171a6c07
--- /dev/null
+++ b/samples/ReservedCapacity.php
@@ -0,0 +1,274 @@
+createReservedCapacity($config);
+Common::println("Reserved Capacity Id:".$result['x-oss-reserved-capacity-id']);
+Common::println("Create Reserved Capacity Success");
+
+// Update Reserved Capacity
+$status = "Enabled";
+$reservedCapacity = 10240;
+$autoExpansionSize = 100;
+$autoExpansionMaxSize = 20480;
+$id = "61f545e1-10f5-4c65-********";
+$update = new UpdateReservedCapacity($status,$reservedCapacity,$autoExpansionSize,$autoExpansionMaxSize);
+$result = $ossClient->updateReservedCapacity($id,$update);
+Common::println("Reserved Capacity Id:".$result['x-oss-reserved-capacity-id']);
+Common::println("Update Reserved Capacity Success");
+
+// List Buckets Under The Reserved Capacity
+$id = "a1b398e6-c4e5-481b-8638-********";
+$result = $ossClient->listBucketWithReservedCapacity($id);
+Common::println("Reserved Capacity Id:" . $result->getInstanceId());
+if ($result->getBucketList() !== null) {
+ foreach ($result->getBucketList() as $bucket) {
+ Common::println("Reserved Capacity Bucket Name:" . $bucket);
+ }
+
+}
+
+
+// Get Reserved Capacity By Id
+$id = "Reserved-Capacity-Id";
+$record = $ossClient->getReservedCapacity($id);
+Common::println("Reserved Capacity Owner Id:".$record->getOwnerId());
+Common::println("Reserved Capacity Owner Display Name:".$record->getOwnerDisplayName());
+Common::println("Reserved Capacity Instance Id:".$record->getInstanceId());
+Common::println("Reserved Capacity Name:".$record->getName());
+Common::println("Reserved Capacity Region:".$record->getRegion());
+Common::println("Reserved Capacity Status:".$record->getStatus());
+Common::println("Reserved Capacity Data Redundancy Type:".$record->getDataRedundancyType());
+Common::println("Reserved Capacity:".$record->getReservedCapacity());
+if ($record->getAutoExpansionSize() != null){
+ Common::println("Reserved Capacity Auto Expansion Size:".$record->getAutoExpansionSize());
+}
+if ($record->getAutoExpansionMaxSize() !== null){
+ Common::println("Reserved Capacity Auto Expansion Max Size:".$record->getAutoExpansionMaxSize());
+}
+Common::println("Reserved Capacity Create Time:".$record->getCreateTime());
+if ($record->getLastModifyTime() !== null){
+ Common::println("Reserved Capacity Last Modify Time:".$record->getLastModifyTime());
+}
+if ($record->getEnableTime() !== null){
+ Common::println("Reserved Capacity Enable Time:".$record->getEnableTime());
+}
+
+// List Reserved Capacity
+$result = $ossClient->listReservedCapacity();
+if ($result->getReservedCapacityList() !== null) {
+ foreach ($result->getReservedCapacityList() as $record){
+ Common::println("Reserved Capacity Owner Id:".$record->getOwnerId());
+ Common::println("Reserved Capacity Owner Display Name:".$record->getOwnerDisplayName());
+ Common::println("Reserved Capacity Instance Id:".$record->getInstanceId());
+ Common::println("Reserved Capacity Name:".$record->getName());
+ Common::println("Reserved Capacity Region:".$record->getRegion());
+ Common::println("Reserved Capacity Status:".$record->getStatus());
+ Common::println("Reserved Capacity Data Redundancy Type:".$record->getDataRedundancyType());
+ Common::println("Reserved Capacity:".$record->getReservedCapacity());
+ if ($record->getAutoExpansionSize() != null){
+ Common::println("Reserved Capacity Auto Expansion Size:".$record->getAutoExpansionSize());
+ }
+ if ($record->getAutoExpansionMaxSize() !== null){
+ Common::println("Reserved Capacity Auto Expansion Max Size:".$record->getAutoExpansionMaxSize());
+ }
+ Common::println("Reserved Capacity Create Time:".$record->getCreateTime());
+ if ($record->getLastModifyTime() !== null){
+ Common::println("Reserved Capacity Last Modify Time:".$record->getLastModifyTime());
+ }
+ if ($record->getEnableTime() !== null){
+ Common::println("Reserved Capacity Enable Time:".$record->getEnableTime());
+ }
+ }
+}
+//******************************* For complete usage, see the following functions ****************************************************
+
+createReservedCapacity($ossClient);
+updateReservedCapacity($ossClient);
+listBucketWithReservedCapacity($ossClient);
+getReservedCapacity($ossClient);
+listReservedCapacity($ossClient);
+
+/**
+ * Create Reserved Capacity
+ *
+ * @param OssClient $ossClient OssClient instance
+ * @return null
+ * @throws RequestCore_Exception
+ */
+function createReservedCapacity($ossClient)
+{
+ try {
+ $name = "test-tc-demo";
+ $dataRedundancyType = "LRS";
+ $reservedCapacity = 10240;
+ $config = new CreateReservedCapacity($name,$dataRedundancyType,$reservedCapacity);
+ $result = $ossClient->createReservedCapacity($config);
+ Common::println("Reserved Capacity Id:".$result['x-oss-reserved-capacity-id']);
+ Common::println("Create Reserved Capacity Success");
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+ print(__FUNCTION__ . ": OK" . "\n");
+}
+
+
+/**
+ * Update Reserved Capacity By Id
+ *
+ * @param OssClient $ossClient OssClient instance
+ * @return null
+ * @throws RequestCore_Exception
+ */
+function updateReservedCapacity($ossClient)
+{
+ try {
+ $status = "Enabled";
+ $reservedCapacity = 10240;
+ $autoExpansionSize = 100;
+ $autoExpansionMaxSize = 20480;
+ $id = "Reserved-Capacity-Id";
+ $update = new UpdateReservedCapacity($status,$reservedCapacity,$autoExpansionSize,$autoExpansionMaxSize);
+ $result = $ossClient->updateReservedCapacity($id,$update);
+ Common::println("Reserved Capacity Id:".$result['x-oss-reserved-capacity-id']);
+ Common::println("Update Reserved Capacity Success");
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+ print(__FUNCTION__ . ": OK" . "\n");
+}
+
+
+/**
+ * Update Reserved Capacity By Id
+ *
+ * @param OssClient $ossClient OssClient instance
+ * @return null
+ * @throws RequestCore_Exception
+ */
+function listBucketWithReservedCapacity($ossClient)
+{
+ try {
+ $id = "a1b398e6-c4e5-481b-8638-********";
+ $result = $ossClient->listBucketWithReservedCapacity($id);
+ Common::println("Reserved Capacity Id:" . $result->getInstanceId());
+ if ($result->getBucketList() !== null) {
+ foreach ($result->getBucketList() as $bucket) {
+ Common::println("Reserved Capacity Bucket Name:" . $bucket);
+ }
+
+ }
+ Common::println("List Buckets With Reserved Capacity Success");
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+ print(__FUNCTION__ . ": OK" . "\n");
+}
+
+/**
+ * Get Reserved Capacity By Id
+ *
+ * @param OssClient $ossClient OssClient instance
+ * @return null
+ * @throws RequestCore_Exception
+ */
+function getReservedCapacity($ossClient)
+{
+ try {
+ $id = "Reserved-Capacity-Id";
+ $record = $ossClient->getReservedCapacity($id);
+ Common::println("Reserved Capacity Owner Id:".$record->getOwnerId());
+ Common::println("Reserved Capacity Owner Display Name:".$record->getOwnerDisplayName());
+ Common::println("Reserved Capacity Instance Id:".$record->getInstanceId());
+ Common::println("Reserved Capacity Name:".$record->getName());
+ Common::println("Reserved Capacity Region:".$record->getRegion());
+ Common::println("Reserved Capacity Status:".$record->getStatus());
+ Common::println("Reserved Capacity Data Redundancy Type:".$record->getDataRedundancyType());
+ Common::println("Reserved Capacity:".$record->getReservedCapacity());
+ if ($record->getAutoExpansionSize() != null){
+ Common::println("Reserved Capacity Auto Expansion Size:".$record->getAutoExpansionSize());
+ }
+ if ($record->getAutoExpansionMaxSize() !== null){
+ Common::println("Reserved Capacity Auto Expansion Max Size:".$record->getAutoExpansionMaxSize());
+ }
+ Common::println("Reserved Capacity Create Time:".$record->getCreateTime());
+ if ($record->getLastModifyTime() !== null){
+ Common::println("Reserved Capacity Last Modify Time:".$record->getLastModifyTime());
+ }
+ if ($record->getEnableTime() !== null){
+ Common::println("Reserved Capacity Enable Time:".$record->getEnableTime());
+ }
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+ print(__FUNCTION__ . ": OK" . "\n");
+}
+
+/**
+ * List Reserved Capacity By Id
+ *
+ * @param OssClient $ossClient OssClient instance
+ * @return null
+ * @throws RequestCore_Exception
+ */
+function listReservedCapacity($ossClient)
+{
+ try {
+ $result = $ossClient->listReservedCapacity();
+ if ($result->getReservedCapacityList() !== null) {
+ foreach ($result->getReservedCapacityList() as $record) {
+ Common::println("Reserved Capacity Owner Id:".$record->getOwnerId());
+ Common::println("Reserved Capacity Owner Display Name:".$record->getOwnerDisplayName());
+ Common::println("Reserved Capacity Instance Id:".$record->getInstanceId());
+ Common::println("Reserved Capacity Name:".$record->getName());
+ Common::println("Reserved Capacity Region:".$record->getRegion());
+ Common::println("Reserved Capacity Status:".$record->getStatus());
+ Common::println("Reserved Capacity Data Redundancy Type:".$record->getDataRedundancyType());
+ Common::println("Reserved Capacity:".$record->getReservedCapacity());
+ if ($record->getAutoExpansionSize() != null){
+ Common::println("Reserved Capacity Auto Expansion Size:".$record->getAutoExpansionSize());
+ }
+ if ($record->getAutoExpansionMaxSize() !== null){
+ Common::println("Reserved Capacity Auto Expansion Max Size:".$record->getAutoExpansionMaxSize());
+ }
+ Common::println("Reserved Capacity Create Time:".$record->getCreateTime());
+ if ($record->getLastModifyTime() !== null){
+ Common::println("Reserved Capacity Last Modify Time:".$record->getLastModifyTime());
+ }
+ if ($record->getEnableTime() !== null){
+ Common::println("Reserved Capacity Enable Time:".$record->getEnableTime());
+ }
+ }
+
+ }
+ } catch (OssException $e) {
+ printf(__FUNCTION__ . ": FAILED\n");
+ printf($e->getMessage() . "\n");
+ return;
+ }
+ print(__FUNCTION__ . ": OK" . "\n");
+}
\ No newline at end of file
diff --git a/src/OSS/Core/OssUtil.php b/src/OSS/Core/OssUtil.php
index 93e2f4ff..3ee415be 100644
--- a/src/OSS/Core/OssUtil.php
+++ b/src/OSS/Core/OssUtil.php
@@ -174,17 +174,28 @@ public static function startsWith($str, $findMe)
}
}
-
/**
* Generate the xml message of createBucketXmlBody.
*
- * @param string $storageClass
- * @return string
+ * @param null|string $storageClass
+ * @param null|string $reservedCapacityInstanceId
+ * @param null|string $dataRedundancyType
+ * @return bool|string
*/
- public static function createBucketXmlBody($storageClass)
+ public static function createBucketXmlBody($storageClass=null,$reservedCapacityInstanceId=null,$dataRedundancyType=null)
{
+ if (!isset($storageClass) && !isset($reservedCapacityInstanceId) && !isset($dataRedundancyType)) return '';
$xml = new \SimpleXMLElement('');
- $xml->addChild('StorageClass', $storageClass);
+ if (isset($storageClass)){
+ $xml->addChild('StorageClass', $storageClass);
+ }
+ if (isset($reservedCapacityInstanceId)){
+ $xml->addChild('ReservedCapacityInstanceId', $reservedCapacityInstanceId);
+ }
+ if (isset($dataRedundancyType)){
+ $xml->addChild('DataRedundancyType', $dataRedundancyType);
+ }
+
return $xml->asXML();
}
diff --git a/src/OSS/Model/BucketInfo.php b/src/OSS/Model/BucketInfo.php
index e211eed6..d4e754e3 100644
--- a/src/OSS/Model/BucketInfo.php
+++ b/src/OSS/Model/BucketInfo.php
@@ -94,6 +94,14 @@ public function getRegion()
{
return $this->region;
}
+
+ /**
+ * @return string
+ */
+ public function getReservedCapacityInstanceId()
+ {
+ return $this->reservedCapacityInstanceId;
+ }
/**
@@ -129,6 +137,10 @@ public function parseFromXmlNode($xml)
if (isset($xml->Region)) {
$this->region = strval($xml->Region);
}
+ if (isset($xml->ReservedCapacityInstanceId)) {
+ $this->reservedCapacityInstanceId = strval($xml->ReservedCapacityInstanceId);
+ }
+
}
/**
@@ -178,4 +190,9 @@ public function parseFromXmlNode($xml)
* @var string
*/
private $region;
+
+ /**
+ * @var string
+ */
+ private $reservedCapacityInstanceId;
}
\ No newline at end of file
diff --git a/src/OSS/Model/BucketStat.php b/src/OSS/Model/BucketStat.php
index 60c7e55c..f0109d79 100644
--- a/src/OSS/Model/BucketStat.php
+++ b/src/OSS/Model/BucketStat.php
@@ -170,6 +170,41 @@ public function getColdArchiveObjectCount()
return $this->coldArchiveObjectCount;
}
+ /**
+ * @return int
+ */
+ public function getReservedCapacityStorage() {
+ return $this->reservedCapacityStorage;
+ }
+
+ /**
+ * @return int
+ */
+ public function getReservedCapacityObjectCount() {
+ return $this->reservedCapacityObjectCount;
+ }
+
+ /**
+ * @return int
+ */
+ public function getDeepColdArchiveStorage() {
+ return $this->deepColdArchiveStorage;
+ }
+
+ /**
+ * @return int
+ */
+ public function getDeepColdArchiveRealStorage() {
+ return $this->deepColdArchiveRealStorage;
+ }
+
+ /**
+ * @return int
+ */
+ public function getDeepColdArchiveObjectCount() {
+ return $this->deepColdArchiveObjectCount;
+ }
+
/**
* Parse stat from the xml.
*
@@ -228,6 +263,21 @@ public function parseFromXml($strXml)
if (isset($xml->ColdArchiveObjectCount) ) {
$this->coldArchiveObjectCount = intval($xml->ColdArchiveObjectCount);
}
+ if (isset($xml->ReservedCapacityStorage) ) {
+ $this->reservedCapacityStorage = intval($xml->ReservedCapacityStorage);
+ }
+ if (isset($xml->ReservedCapacityObjectCount) ) {
+ $this->reservedCapacityObjectCount = intval($xml->ReservedCapacityObjectCount);
+ }
+ if (isset($xml->DeepColdArchiveStorage) ) {
+ $this->deepColdArchiveStorage = intval($xml->DeepColdArchiveStorage);
+ }
+ if (isset($xml->DeepColdArchiveRealStorage) ) {
+ $this->deepColdArchiveRealStorage = intval($xml->DeepColdArchiveRealStorage);
+ }
+ if (isset($xml->DeepColdArchiveObjectCount) ) {
+ $this->deepColdArchiveObjectCount = intval($xml->DeepColdArchiveObjectCount);
+ }
}
/**
@@ -328,4 +378,24 @@ public function parseFromXml($strXml)
*/
private $coldArchiveObjectCount;
+ /**
+ * @var int
+ */
+ private $reservedCapacityStorage;
+ /**
+ * @var int
+ */
+ private $reservedCapacityObjectCount;
+ /**
+ * @var int
+ */
+ private $deepColdArchiveStorage;
+ /**
+ * @var int
+ */
+ private $deepColdArchiveRealStorage;
+ /**
+ * @var int
+ */
+ private $deepColdArchiveObjectCount;
}
\ No newline at end of file
diff --git a/src/OSS/Model/CreateReservedCapacity.php b/src/OSS/Model/CreateReservedCapacity.php
new file mode 100644
index 00000000..6b107489
--- /dev/null
+++ b/src/OSS/Model/CreateReservedCapacity.php
@@ -0,0 +1,77 @@
+name = $name;
+ $this->dataRedundancyType = $dataRedundancyType;
+ $this->reservedCapacity = $reservedCapacity;
+ }
+
+ /**
+ * Parse ExtendWormConfig from the xml.
+ *
+ * @param string $strXml
+ * @throws OssException
+ * @return null
+ */
+ public function parseFromXml($strXml)
+ {
+ throw new OssException("Not implemented.");
+ }
+
+ /**
+ * Serialize the object into xml string.
+ *
+ * @return string
+ */
+ public function serializeToXml()
+ {
+ $xml = new \SimpleXMLElement('');
+ if (isset($this->name)){
+ $xml->addChild('Name', $this->name);
+ }
+ if (isset($this->dataRedundancyType)){
+ $xml->addChild('DataRedundancyType', $this->dataRedundancyType);
+ }
+ if (isset($this->reservedCapacity)){
+ $xml->addChild('ReservedCapacity', $this->reservedCapacity);
+ }
+ return $xml->asXML();
+ }
+
+ public function __toString()
+ {
+ return $this->serializeToXml();
+ }
+}
\ No newline at end of file
diff --git a/src/OSS/Model/ListBucketWithReservedCapacity.php b/src/OSS/Model/ListBucketWithReservedCapacity.php
new file mode 100644
index 00000000..83b75de6
--- /dev/null
+++ b/src/OSS/Model/ListBucketWithReservedCapacity.php
@@ -0,0 +1,51 @@
+InstanceId)) return;
+ if (isset($xml->InstanceId)){
+ $this->instanceId = strval($xml->InstanceId);
+ }
+ if (isset($xml->BucketList->Bucket)){
+ foreach ($xml->BucketList->Bucket as $bucket){
+ $this->bucketList[] = strval($bucket);
+ }
+ }
+ }
+
+ /**
+ * @return array
+ */
+ public function getBucketList(){
+ return $this->bucketList;
+ }
+
+ /**
+ * @return string
+ */
+ public function getInstanceId() {
+ return $this->instanceId;
+ }
+}
\ No newline at end of file
diff --git a/src/OSS/Model/ListReservedCapacity.php b/src/OSS/Model/ListReservedCapacity.php
new file mode 100644
index 00000000..d9cf5e42
--- /dev/null
+++ b/src/OSS/Model/ListReservedCapacity.php
@@ -0,0 +1,47 @@
+ReservedCapacityRecord)) return;
+ if (isset($xml->ReservedCapacityRecord)){
+ $this->parseReservedCapacity($xml->ReservedCapacityRecord);
+ }
+ }
+
+ /**
+ * @param $xmlReservedCapacityRecord
+ */
+ private function parseReservedCapacity($xmlReservedCapacityRecord){
+ if ($xmlReservedCapacityRecord){
+ foreach ($xmlReservedCapacityRecord as $record){
+ $reservedCapacity = new ReservedCapacityRecord();
+ $reservedCapacity->parseFromXmlObj($record);
+ $this->list[] = $reservedCapacity;
+ }
+ }
+ }
+
+ /**
+ * @return ReservedCapacityRecord[]
+ */
+ public function getReservedCapacityList(){
+ return $this->list;
+ }
+}
\ No newline at end of file
diff --git a/src/OSS/Model/ReservedCapacityRecord.php b/src/OSS/Model/ReservedCapacityRecord.php
new file mode 100644
index 00000000..1a4f4407
--- /dev/null
+++ b/src/OSS/Model/ReservedCapacityRecord.php
@@ -0,0 +1,223 @@
+parseFromXmlObj($xml);
+ }
+
+
+ /**
+ * @param $xml \SimpleXMLElement
+ */
+ public function parseFromXmlObj($xml)
+ {
+ if (isset($xml->InstanceId)){
+ $this->instanceId = strval($xml->InstanceId);
+ }
+ if (isset($xml->Name)){
+ $this->name = strval($xml->Name);
+ }
+ if (isset($xml->Owner)){
+ $this->parseOwner($xml->Owner);
+ }
+ if (isset($xml->Region)){
+ $this->region = strval($xml->Region);
+ }
+ if (isset($xml->Status)){
+ $this->status = strval($xml->Status);
+ }
+ if (isset($xml->DataRedundancyType)){
+ $this->dataRedundancyType = strval($xml->DataRedundancyType);
+ }
+ if (isset($xml->ReservedCapacity)){
+ $this->reservedCapacity = intval($xml->ReservedCapacity);
+ }
+ if (isset($xml->AutoExpansionSize)){
+ $this->autoExpansionSize = intval($xml->AutoExpansionSize);
+ }
+ if (isset($xml->AutoExpansionMaxSize)){
+ $this->autoExpansionMaxSize = intval($xml->AutoExpansionMaxSize);
+ }
+ if (isset($xml->CreateTime)){
+ $this->createTime = intval($xml->CreateTime);
+ }
+ if (isset($xml->LastModifyTime)){
+ $this->lastModifyTime = intval($xml->LastModifyTime);
+ }
+ if (isset($xml->EnableTime)){
+ $this->enableTime = intval($xml->EnableTime);
+ }
+ }
+
+ /**
+ * @param $xmlOwner \SimpleXMLElement
+ */
+ public function parseOwner($xmlOwner)
+ {
+ if (isset($xmlOwner->ID)){
+ $this->ownerId = strval($xmlOwner->ID);
+ }
+ if (isset($xmlOwner->DisplayName)){
+ $this->ownerDisplayName = strval($xmlOwner->DisplayName);
+ }
+ }
+
+ /**
+ * @return string
+ */
+ public function getInstanceId() {
+ return $this->instanceId;
+ }
+
+ /**
+ * @return string
+ */
+ public function getName() {
+ return $this->name;
+ }
+
+ /**
+ * @return string
+ */
+ public function getOwnerId() {
+ return $this->ownerId;
+ }
+
+ /**
+ * @return string
+ */
+ public function getOwnerDisplayName() {
+ return $this->ownerDisplayName;
+ }
+
+ /**
+ * @return string
+ */
+ public function getRegion() {
+ return $this->region;
+ }
+
+ /**
+ * @return string
+ */
+ public function getStatus() {
+ return $this->status;
+ }
+
+ /**
+ * @return string
+ */
+ public function getDataRedundancyType() {
+ return $this->dataRedundancyType;
+ }
+
+ /**
+ * @return int
+ */
+ public function getReservedCapacity() {
+ return $this->reservedCapacity;
+ }
+
+ /**
+ * @return int
+ */
+ public function getAutoExpansionSize() {
+ return $this->autoExpansionSize;
+ }
+
+ /**
+ * @return int
+ */
+ public function getAutoExpansionMaxSize() {
+ return $this->autoExpansionMaxSize;
+ }
+
+ /**
+ * @return int
+ */
+ public function getCreateTime() {
+ return $this->createTime;
+ }
+
+ /**
+ * @return int
+ */
+ public function getLastModifyTime() {
+ return $this->lastModifyTime;
+ }
+
+ /**
+ * @return int
+ */
+ public function getEnableTime() {
+ return $this->enableTime;
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/OSS/Model/UpdateReservedCapacity.php b/src/OSS/Model/UpdateReservedCapacity.php
new file mode 100644
index 00000000..164be326
--- /dev/null
+++ b/src/OSS/Model/UpdateReservedCapacity.php
@@ -0,0 +1,89 @@
+status = $status;
+ $this->reservedCapacity = $reservedCapacity;
+ $this->autoExpansionSize = $autoExpansionSize;
+ $this->autoExpansionMaxSize = $autoExpansionMaxSize;
+ }
+
+ /**
+ * Parse ExtendWormConfig from the xml.
+ *
+ * @param string $strXml
+ * @throws OssException
+ * @return null
+ */
+ public function parseFromXml($strXml)
+ {
+ throw new OssException("Not implemented.");
+ }
+
+ /**
+ * Serialize the object into xml string.
+ *
+ * @return string
+ */
+ public function serializeToXml()
+ {
+ $xml = new \SimpleXMLElement('');
+ if (isset($this->status)){
+ $xml->addChild('Status', $this->status);
+ }
+ if (isset($this->reservedCapacity)){
+ $xml->addChild('ReservedCapacity', $this->reservedCapacity);
+ }
+ if (isset($this->autoExpansionSize)){
+ $xml->addChild('AutoExpansionSize', $this->autoExpansionSize);
+ }
+ if (isset($this->autoExpansionMaxSize)){
+ $xml->addChild('AutoExpansionMaxSize', $this->autoExpansionMaxSize);
+ }
+ return $xml->asXML();
+ }
+
+
+ /**
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->serializeToXml();
+ }
+}
\ No newline at end of file
diff --git a/src/OSS/OssClient.php b/src/OSS/OssClient.php
index c9533448..194bb2df 100644
--- a/src/OSS/OssClient.php
+++ b/src/OSS/OssClient.php
@@ -9,14 +9,20 @@
use OSS\Http\RequestCore;
use OSS\Http\RequestCore_Exception;
use OSS\Http\ResponseCore;
+use OSS\Model\BucketInfo;
use OSS\Model\CorsConfig;
use OSS\Model\CnameConfig;
+use OSS\Model\ListBucketWithReservedCapacity;
+use OSS\Model\ListReservedCapacity;
use OSS\Model\LoggingConfig;
use OSS\Model\LiveChannelConfig;
use OSS\Model\LiveChannelInfo;
use OSS\Model\LiveChannelListInfo;
use OSS\Model\ObjectListInfoV2;
+use OSS\Model\CreateReservedCapacity;
+use OSS\Model\ReservedCapacityRecord;
use OSS\Model\StorageCapacityConfig;
+use OSS\Model\UpdateReservedCapacity;
use OSS\Result\AclResult;
use OSS\Result\BodyResult;
use OSS\Result\GetCorsResult;
@@ -24,17 +30,20 @@
use OSS\Result\GetLocationResult;
use OSS\Result\GetLoggingResult;
use OSS\Result\GetRefererResult;
+use OSS\Result\GetReservedCapacityResult;
use OSS\Result\GetStorageCapacityResult;
use OSS\Result\GetWebsiteResult;
use OSS\Result\GetCnameResult;
use OSS\Result\HeaderResult;
use OSS\Result\InitiateMultipartUploadResult;
use OSS\Result\ListBucketsResult;
+use OSS\Result\ListBucketWithReservedCapacityResult;
use OSS\Result\ListMultipartUploadResult;
use OSS\Model\ListMultipartUploadInfo;
use OSS\Result\ListObjectsResult;
use OSS\Result\ListObjectsV2Result;
use OSS\Result\ListPartsResult;
+use OSS\Result\ListReservedCapacityResult;
use OSS\Result\PutSetDeleteResult;
use OSS\Result\DeleteObjectsResult;
use OSS\Result\CopyObjectResult;
@@ -200,14 +209,20 @@ public function createBucket($bucket, $acl = self::OSS_ACL_TYPE_PRIVATE, $option
{
$this->precheckCommon($bucket, NULL, $options, false);
$options[self::OSS_BUCKET] = $bucket;
+ $options[self::OSS_CONTENT_TYPE] = 'application/xml';
$options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
$options[self::OSS_OBJECT] = '/';
$options[self::OSS_HEADERS] = array(self::OSS_ACL => $acl);
if (isset($options[self::OSS_STORAGE])) {
$this->precheckStorage($options[self::OSS_STORAGE]);
- $options[self::OSS_CONTENT] = OssUtil::createBucketXmlBody($options[self::OSS_STORAGE]);
- unset($options[self::OSS_STORAGE]);
}
+ if (isset($options[self::OSS_REDUNDANCY])) {
+ $this->precheckRedundancyType($options[self::OSS_REDUNDANCY]);
+ }
+ $options[self::OSS_CONTENT] = OssUtil::createBucketXmlBody($options[self::OSS_STORAGE],$options[self::OSS_RESERVED_CAPACITY_ID],$options[self::OSS_REDUNDANCY]);
+ unset($options[self::OSS_STORAGE]);
+ unset($options[self::OSS_RESERVED_CAPACITY_ID]);
+ unset($options[self::OSS_REDUNDANCY]);
$response = $this->auth($options);
$result = new PutSetDeleteResult($response);
return $result->getData();
@@ -1152,8 +1167,8 @@ public function getBucketStorageCapacity($bucket, $options = NULL)
*
* @param string $bucket bucket name
* @param array $options
- * @throws OssException
* @return BucketInfo
+ * @throws OssException|RequestCore_Exception
*/
public function getBucketInfo($bucket, $options = NULL)
{
@@ -2830,6 +2845,133 @@ public function generatePresignedUrl($bucket, $object, $expiration, $method = se
return $this->auth($options);
}
+ /**
+ * Create Reserved Capacity
+ *
+ * @param CreateReservedCapacity $create
+ * @param null|array $options
+ * @return null|array
+ * @throws OssException
+ * @throws RequestCore_Exception
+ */
+ public function createReservedCapacity($create,$options = NULL)
+ {
+ $this->precheckOptions($options);
+ $response = $this->createReservedCapacityXml("",$create->serializeToXml(),$options);
+ $result = new PutSetDeleteResult($response);
+ return $result->getData();
+ }
+
+ /**
+ * Update Reserved Capacity By Id
+ * @param string $id reserved capacity id
+ * @param UpdateReservedCapacity $update
+ * @param null|array $options
+ * @return ReservedCapacityRecord|null
+ * @throws OssException
+ * @throws RequestCore_Exception
+ */
+ public function updateReservedCapacity($id,$update,$options = NULL)
+ {
+ $this->precheckOptions($options);
+ $response = $this->createReservedCapacityXml($id,$update->serializeToXml(),$options);
+ $result = new PutSetDeleteResult($response);
+ return $result->getData();
+ }
+
+ /**
+ * Create or Update Reserved Capacity
+ * @param string $id reserved capacity id
+ * @param string $xmlData config in xml format
+ * @param null|array $options
+ * @return ResponseCore|string
+ * @throws OssException
+ * @throws RequestCore_Exception
+ */
+ public function createReservedCapacityXml($id,$xmlData,$options = NULL){
+ $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
+ $options[self::OSS_OBJECT] = '/';
+ $options[self::OSS_SUB_RESOURCE] = 'reservedCapacity';
+ if (!empty($id)){
+ $options[self::OSS_SUB_RESOURCE] .= "&x-oss-reserved-capacity-id=".$id;
+ }
+ $options[self::OSS_CONTENT] = $xmlData;
+ return $this->auth($options);
+ }
+
+ /**
+ * List Buckets Under the Reserved Capacity
+ * @param string $id
+ * @param null|array $options
+ * @return null|ListBucketWithReservedCapacity
+ * @throws OssException
+ * @throws RequestCore_Exception
+ */
+ public function listBucketWithReservedCapacity($id,$options = NULL)
+ {
+ $this->precheckOptions($options);
+ $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
+ $options[self::OSS_OBJECT] = '/';
+ $options[self::OSS_SUB_RESOURCE] = 'reservedCapacity';
+ if (!empty($id)){
+ $options[self::OSS_SUB_RESOURCE] .= "&x-oss-reserved-capacity-id=".$id;
+ }
+ $options[self::OSS_SUB_RESOURCE] .= "&comp=queryBucketList";
+ $response = $this->auth($options);
+ $result = new ListBucketWithReservedCapacityResult($response);
+ return $result->getData();
+ }
+
+ /**
+ * List Reserved Capacity
+ * @param null $options
+ * @return null|ListReservedCapacity
+ * @throws OssException
+ * @throws RequestCore_Exception
+ */
+
+ public function listReservedCapacity($options = NULL)
+ {
+ $this->precheckOptions($options);
+ $response = $this->getReservedCapacityXml("",$options);
+ $result = new ListReservedCapacityResult($response);
+ return $result->getData();
+ }
+
+ /**
+ * Get Reserved Capacity
+ * @param string $id reserved capacity id
+ * @param null|array $options
+ * @return ReservedCapacityRecord|null
+ * @throws OssException
+ * @throws RequestCore_Exception
+ */
+ public function getReservedCapacity($id,$options = NULL)
+ {
+ $this->precheckOptions($options);
+ $response = $this->getReservedCapacityXml($id,$options);
+ $result = new GetReservedCapacityResult($response);
+ return $result->getData();
+ }
+
+ /**
+ * Get or List Reserved Capacity
+ * @param string $id reserved capacity id
+ * @param null|array $options
+ * @return ResponseCore|string
+ * @throws OssException
+ * @throws RequestCore_Exception
+ */
+ public function getReservedCapacityXml($id,$options = NULL){
+ $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
+ $options[self::OSS_OBJECT] = '/';
+ $options[self::OSS_SUB_RESOURCE] = 'reservedCapacity';
+ if (!empty($id)){
+ $options[self::OSS_SUB_RESOURCE] .= "&x-oss-reserved-capacity-id=".$id;
+ }
+ return $this->auth($options);
+ }
+
/**
* validates options. Create a empty array if it's NULL.
*
@@ -2868,28 +3010,23 @@ private function precheckObject($object)
}
/**
- * 校验option restore
- *
- * @param string $restore
+ * @param $storage string
* @throws OssException
*/
private function precheckStorage($storage)
{
- if (is_string($storage)) {
- switch ($storage) {
- case self::OSS_STORAGE_ARCHIVE:
- return;
- case self::OSS_STORAGE_IA:
- return;
- case self::OSS_STORAGE_STANDARD:
- return;
- case self::OSS_STORAGE_COLDARCHIVE:
- return;
- default:
- break;
- }
+ $storageList = array(self::OSS_STORAGE_IA,self::OSS_STORAGE_STANDARD,self::OSS_STORAGE_COLDARCHIVE,self::OSS_STORAGE_RESERVEDCAPACITY,self::OSS_STORAGE_DEEPCOLDARCHIVE,self::OSS_STORAGE_ARCHIVE);
+ if (!in_array($storage,$storageList)){
+ throw new OssException('storage name is invalid');
+ }
+ }
+
+ private function precheckRedundancyType($redundancyType)
+ {
+ $redundancyTypeList = array(self::OSS_REDUNDANCY_LRS,self::OSS_REDUNDANCY_ZRS);
+ if (!in_array($redundancyType,$redundancyTypeList)){
+ throw new OssException('data redundancy type name is invalid');
}
- throw new OssException('storage name is invalid');
}
/**
@@ -3000,8 +3137,10 @@ private function getMimeType($object, $file = null)
private function auth($options)
{
OssUtil::validateOptions($options);
- //Validates bucket, not required for list_bucket
- $this->authPrecheckBucket($options);
+ if (!$this->checkSubResource($options)){
+ //Validates bucket, not required for list_bucket
+ $this->authPrecheckBucket($options);
+ }
//Validates object
$this->authPrecheckObject($options);
//object name encoding must be UTF-8
@@ -3234,6 +3373,21 @@ private function authPrecheckBucket($options)
}
}
+ /**
+ * Verify whether the sub source needs to be checked for buckets
+ * @param $options
+ * @return bool
+ */
+ private function checkSubResource($options)
+ {
+ foreach (self::$KEY_WORDS as $keyword) {
+ if (strpos($options[self::OSS_SUB_RESOURCE], $keyword) !== false) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
*
* Validates the object name--throw OssException if it's invalid.
@@ -3665,11 +3819,17 @@ public function setConnectTimeout($connectTimeout)
const OSS_REQUEST_ID = 'x-oss-request-id';
const OSS_INFO = 'info';
const OSS_STORAGE = 'storage';
+ const OSS_REDUNDANCY = 'redundancy-type';
+ const OSS_REDUNDANCY_LRS = 'LRS';
+ const OSS_REDUNDANCY_ZRS = 'ZRS';
+ const OSS_RESERVED_CAPACITY_ID = 'reserved-capacity-instance-id';
const OSS_RESTORE = 'restore';
const OSS_STORAGE_STANDARD = 'Standard';
const OSS_STORAGE_IA = 'IA';
const OSS_STORAGE_ARCHIVE = 'Archive';
const OSS_STORAGE_COLDARCHIVE = 'ColdArchive';
+ const OSS_STORAGE_DEEPCOLDARCHIVE = 'DeepColdArchive';
+ const OSS_STORAGE_RESERVEDCAPACITY = 'ReservedCapacity';
const OSS_TAGGING = 'tagging';
const OSS_WORM_ID = 'wormId';
const OSS_RESTORE_CONFIG = 'restore-config';
@@ -3708,6 +3868,9 @@ public function setConnectTimeout($connectTimeout)
const OSS_ACL_TYPE_PRIVATE = 'private';
const OSS_ACL_TYPE_PUBLIC_READ = 'public-read';
const OSS_ACL_TYPE_PUBLIC_READ_WRITE = 'public-read-write';
+
+
+
const OSS_ENCODING_TYPE = "encoding-type";
const OSS_ENCODING_TYPE_URL = "url";
@@ -3733,6 +3896,10 @@ public function setConnectTimeout($connectTimeout)
const OSS_OPTIONS_REQUEST_METHOD = 'Access-Control-Request-Method';
const OSS_OPTIONS_REQUEST_HEADERS = 'Access-Control-Request-Headers';
+ static $KEY_WORDS = array(
+ 'reservedCapacity'
+ );
+
//use ssl flag
private $useSSL = false;
private $maxRetries = 3;
diff --git a/src/OSS/Result/GetBucketInfoResult.php b/src/OSS/Result/GetBucketInfoResult.php
index ad55e95b..85f2f680 100644
--- a/src/OSS/Result/GetBucketInfoResult.php
+++ b/src/OSS/Result/GetBucketInfoResult.php
@@ -14,9 +14,7 @@
class GetBucketInfoResult extends Result
{
/**
- * Parse data from response
- *
- * @return string
+ * @return BucketInfo
* @throws OssException
*/
protected function parseDataFromResponse()
diff --git a/src/OSS/Result/GetReservedCapacityResult.php b/src/OSS/Result/GetReservedCapacityResult.php
new file mode 100644
index 00000000..c22d381c
--- /dev/null
+++ b/src/OSS/Result/GetReservedCapacityResult.php
@@ -0,0 +1,24 @@
+rawResponse->body;
+ if (empty($content)) {
+ throw new OssException("body is null");
+ }
+ $record = new ReservedCapacityRecord();
+ $record->parseFromXml($content);
+ return $record;
+ }
+}
\ No newline at end of file
diff --git a/src/OSS/Result/ListBucketWithReservedCapacityResult.php b/src/OSS/Result/ListBucketWithReservedCapacityResult.php
new file mode 100644
index 00000000..f843a559
--- /dev/null
+++ b/src/OSS/Result/ListBucketWithReservedCapacityResult.php
@@ -0,0 +1,24 @@
+rawResponse->body;
+ if (empty($content)) {
+ throw new OssException("body is null");
+ }
+ $list = new ListBucketWithReservedCapacity();
+ $list->parseFromXml($content);
+ return $list;
+ }
+}
\ No newline at end of file
diff --git a/src/OSS/Result/ListReservedCapacityResult.php b/src/OSS/Result/ListReservedCapacityResult.php
new file mode 100644
index 00000000..3b0f1484
--- /dev/null
+++ b/src/OSS/Result/ListReservedCapacityResult.php
@@ -0,0 +1,24 @@
+rawResponse->body;
+ if (empty($content)) {
+ throw new OssException("body is null");
+ }
+ $list = new ListReservedCapacity();
+ $list->parseFromXml($content);
+ return $list;
+ }
+}
\ No newline at end of file
diff --git a/tests/OSS/Tests/CreateReservedCapacityTest.php b/tests/OSS/Tests/CreateReservedCapacityTest.php
new file mode 100644
index 00000000..c5ec024c
--- /dev/null
+++ b/tests/OSS/Tests/CreateReservedCapacityTest.php
@@ -0,0 +1,49 @@
+
+
+your-rc-name
+LRS
+10240
+
+BBBB;
+
+ private $validXml1 = <<
+
+your-rc-name
+10240
+
+BBBB;
+
+
+ public function testParseValidXml()
+ {
+ $name = "your-rc-name";
+ $dataRedundancyType = "LRS";
+ $reservedCapacity = 10240;
+ $config = new CreateReservedCapacity($name,$dataRedundancyType,$reservedCapacity);
+ $this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($config->serializeToXml()));
+ }
+
+ public function testParseValidXml1()
+ {
+ $name = "your-rc-name";
+ $reservedCapacity = 10240;
+ $config = new CreateReservedCapacity($name,null,$reservedCapacity);
+ $this->assertEquals($this->cleanXml($this->validXml1), $this->cleanXml($config->serializeToXml()));
+ }
+
+ private function cleanXml($xml)
+ {
+ return str_replace("\n", "", str_replace("\r", "", $xml));
+ }
+}
diff --git a/tests/OSS/Tests/GetBucketInfoResultTest.php b/tests/OSS/Tests/GetBucketInfoResultTest.php
new file mode 100644
index 00000000..3643f085
--- /dev/null
+++ b/tests/OSS/Tests/GetBucketInfoResultTest.php
@@ -0,0 +1,105 @@
+
+
+
+
+ 2023-02-14T06:56:02.000Z
+ Disabled
+ LRS
+ 11.158.239.225
+ 11.158.239.225
+ oss-cn-hangzhou-pocarchive
+ mxx-testrc1
+ 7e6cb0c5-efaf-45f4-bc39-ab8e342cbf1c
+ ReservedCapacity
+ Disabled
+
+ 1422558957716563
+ 1422558957716563
+
+
+ private
+
+
+ None
+
+
+
+
+
+
+
+BBBB;
+
+ private $validXml1 = <<
+
+
+ Enabled
+ 2013-07-31T10:56:21.000Z
+ oss-cn-hangzhou.aliyuncs.com
+ oss-cn-hangzhou-internal.aliyuncs.com
+ oss-cn-hangzhou
+ Standard
+ Disabled
+ Disabled
+ oss-example
+ rg-aek27tc********
+
+ username
+ 27183473914****
+
+
+ private
+
+ test
+
+ examplebucket
+ log/
+
+
+
+BBBB;
+
+
+ public function testParseValidXml()
+ {
+ $response = new ResponseCore(array(), $this->validXml, 200);
+ $result = new GetBucketInfoResult($response);
+ $this->assertTrue($result->isOK());
+ $this->assertNotNull($result->getData());
+ $this->assertNotNull($result->getRawResponse());
+ $info = $result->getData();
+
+ $this->assertEquals($info->getName(),"mxx-testrc1");
+ $this->assertEquals($info->getLocation(),"oss-cn-hangzhou-pocarchive");
+ $this->assertEquals($info->getCreateDate(),"2023-02-14T06:56:02.000Z");
+ $this->assertEquals($info->getStorageClass(),"ReservedCapacity");
+ $this->assertEquals($info->getExtranetEndpoint(),"11.158.239.225");
+ $this->assertEquals($info->getIntranetEndpoint(),"11.158.239.225");
+ $this->assertEquals($info->getReservedCapacityInstanceId(),"7e6cb0c5-efaf-45f4-bc39-ab8e342cbf1c");
+ }
+
+
+ public function testParseValidXml1()
+ {
+ $response = new ResponseCore(array(), $this->validXml1, 200);
+ $result = new GetBucketInfoResult($response);
+ $this->assertTrue($result->isOK());
+ $this->assertNotNull($result->getData());
+ $this->assertNotNull($result->getRawResponse());
+ $info = $result->getData();
+
+ $this->assertNull($info->getReservedCapacityInstanceId());
+ }
+}
diff --git a/tests/OSS/Tests/GetBucketStatResultTest.php b/tests/OSS/Tests/GetBucketStatResultTest.php
index 74cb04ab..8c5a0c67 100644
--- a/tests/OSS/Tests/GetBucketStatResultTest.php
+++ b/tests/OSS/Tests/GetBucketStatResultTest.php
@@ -29,6 +29,33 @@ class GetBucketStatResultTest extends \PHPUnit\Framework\TestCase
360
36
+BBBB;
+
+ private $validXmlWithDeepColdArchive = <<
+
+ 1600
+ 230
+ 40
+ 4
+ 1643341269
+ 430
+ 66
+ 2359296
+ 360
+ 54
+ 2949120
+ 450
+ 74
+ 2359296
+ 360
+ 36
+ 450
+ 74
+ 2359296
+ 360
+ 36
+
BBBB;
private $invalidXml = <<assertEquals(36, $stat->getColdArchiveObjectCount());
}
+ public function testParseValidXmlWithDeepColdArchive()
+ {
+ $response = new ResponseCore(array(), $this->validXmlWithDeepColdArchive, 200);
+ $result = new GetBucketStatResult($response);
+ $this->assertTrue($result->isOK());
+ $this->assertNotNull($result->getData());
+ $this->assertNotNull($result->getRawResponse());
+ $stat = $result->getData();
+ $this->assertEquals(1600, $stat->getStorage());
+ $this->assertEquals(230, $stat->getObjectCount());
+ $this->assertEquals(40, $stat->getMultipartUploadCount());
+ $this->assertEquals(4, $stat->getLiveChannelCount());
+ $this->assertEquals(1643341269, $stat->getLastModifiedTime());
+ $this->assertEquals(430, $stat->getStandardStorage());
+ $this->assertEquals(66, $stat->getStandardObjectCount());
+ $this->assertEquals(2359296, $stat->getInfrequentAccessStorage());
+ $this->assertEquals(360, $stat->getInfrequentAccessRealStorage());
+ $this->assertEquals(54, $stat->getInfrequentAccessObjectCount());
+ $this->assertEquals(2949120, $stat->getArchiveStorage());
+ $this->assertEquals(450, $stat->getArchiveRealStorage());
+ $this->assertEquals(74, $stat->getArchiveObjectCount());
+ $this->assertEquals(2359296, $stat->getColdArchiveStorage());
+ $this->assertEquals(360, $stat->getColdArchiveRealStorage());
+ $this->assertEquals(36, $stat->getColdArchiveObjectCount());
+ $this->assertEquals(450, $stat->getReservedCapacityStorage());
+ $this->assertEquals(74, $stat->getReservedCapacityObjectCount());
+ $this->assertEquals(2359296, $stat->getDeepColdArchiveStorage());
+ $this->assertEquals(360, $stat->getDeepColdArchiveRealStorage());
+ $this->assertEquals(36, $stat->getDeepColdArchiveObjectCount());
+ }
+
+
+
public function testParseNullXml()
{
$response = new ResponseCore(array(), "", 200);
diff --git a/tests/OSS/Tests/GetReservedCapacityResultTest.php b/tests/OSS/Tests/GetReservedCapacityResultTest.php
new file mode 100644
index 00000000..4ecf9142
--- /dev/null
+++ b/tests/OSS/Tests/GetReservedCapacityResultTest.php
@@ -0,0 +1,77 @@
+
+
+dd67179e-77b7-415f-a571-e3396e926356
+test-rc1
+
+ut_test_put_bucket
+ut_test_put_bucket
+
+oss-cn-hangzhou
+Enabled
+LRS
+20480
+100
+20480
+1676106931
+1676224171
+0
+
+BBBB;
+
+ private $validXml1 = <<
+
+
+BBBB;
+
+
+ public function testParseValidXml()
+ {
+ $response = new ResponseCore(array(), $this->validXml, 200);
+ $result = new GetReservedCapacityResult($response);
+ $this->assertTrue($result->isOK());
+ $this->assertNotNull($result->getData());
+ $this->assertNotNull($result->getRawResponse());
+ $record = $result->getData();
+
+ $this->assertEquals($record->getOwnerId(),"ut_test_put_bucket");
+ $this->assertEquals($record->getOwnerDisplayName(),"ut_test_put_bucket");
+ $this->assertEquals($record->getInstanceId(),"dd67179e-77b7-415f-a571-e3396e926356");
+ $this->assertEquals($record->getName(),"test-rc1");
+ $this->assertEquals($record->getRegion(),"oss-cn-hangzhou");
+ $this->assertEquals($record->getStatus(),"Enabled");
+ $this->assertEquals($record->getDataRedundancyType(),"LRS");
+ $this->assertEquals($record->getReservedCapacity(),20480);
+ $this->assertEquals($record->getAutoExpansionSize(),100);
+ $this->assertEquals($record->getAutoExpansionMaxSize(),20480);
+ $this->assertEquals($record->getCreateTime(),1676106931);
+ $this->assertEquals($record->getLastModifyTime(),1676224171);
+ $this->assertEquals($record->getEnableTime(),0);
+ }
+
+
+ public function testParseValidXml1()
+ {
+ $response = new ResponseCore(array(), $this->validXml1, 200);
+ $result = new GetReservedCapacityResult($response);
+ $this->assertTrue($result->isOK());
+ $this->assertNotNull($result->getData());
+ $this->assertNotNull($result->getRawResponse());
+ $record = $result->getData();
+
+ $this->assertNull($record->getOwnerId());
+ $this->assertNull($record->getRegion());
+ $this->assertNull($record->getEnableTime());
+ }
+}
diff --git a/tests/OSS/Tests/ListBucketWithReservedCapacityResultTest.php b/tests/OSS/Tests/ListBucketWithReservedCapacityResultTest.php
new file mode 100644
index 00000000..03b96893
--- /dev/null
+++ b/tests/OSS/Tests/ListBucketWithReservedCapacityResultTest.php
@@ -0,0 +1,60 @@
+
+ dd67179e-77b7-415f-a571-e3396e926356
+
+ test-rc
+ mxx-test-rc
+
+
+BBBB;
+
+ private $validXml1 = <<
+
+dd67179e-77b7-415f-a571-e3396e926356
+
+BBBB;
+
+
+ public function testParseValidXml()
+ {
+ $response = new ResponseCore(array(), $this->validXml, 200);
+ $result = new ListBucketWithReservedCapacityResult($response);
+ $this->assertTrue($result->isOK());
+ $this->assertNotNull($result->getData());
+ $this->assertNotNull($result->getRawResponse());
+ $list = $result->getData();
+
+ $this->assertEquals($list->getInstanceId(),"dd67179e-77b7-415f-a571-e3396e926356");
+
+ $bucketList = $list->getBucketList();
+ $this->assertEquals($bucketList[0],"test-rc");
+ $this->assertEquals($bucketList[1],"mxx-test-rc");
+ }
+
+
+ public function testParseValidXml1()
+ {
+ $response = new ResponseCore(array(), $this->validXml1, 200);
+ $result = new ListBucketWithReservedCapacityResult($response);
+ $this->assertTrue($result->isOK());
+ $this->assertNotNull($result->getData());
+ $this->assertNotNull($result->getRawResponse());
+ $list = $result->getData();
+
+ $this->assertEquals($list->getInstanceId(),"dd67179e-77b7-415f-a571-e3396e926356");
+
+ $bucketList = $list->getBucketList();
+ $this->assertNull($bucketList);
+ }
+}
diff --git a/tests/OSS/Tests/ListReservedCapacityResultTest.php b/tests/OSS/Tests/ListReservedCapacityResultTest.php
new file mode 100644
index 00000000..3fdc578b
--- /dev/null
+++ b/tests/OSS/Tests/ListReservedCapacityResultTest.php
@@ -0,0 +1,119 @@
+
+
+
+ e72beabd-33ed-4c21-8069-0b6cf8a0dfc2
+ test-rc
+
+ ut_test_put_bucket
+ ut_test_put_bucket
+
+ oss-cn-hangzhou
+ Init
+ ZRS
+ 20480
+ 1676106871
+ 1676106871
+ 0
+
+
+ dd67179e-77b7-415f-a571-e3396e926356
+ test-rc1
+
+ ut_test_put_bucket
+ ut_test_put_bucket
+
+ oss-cn-hangzhou
+ Enabled
+ LRS
+ 20480
+ 1676106931
+ 1676224171
+ 0
+
+
+ db682d06-215a-4079-8022-31d1e0746b36
+ testrc1
+
+ ut_test_put_bucket
+ ut_test_put_bucket
+
+ oss-cn-hangzhou
+ Init
+ LRS
+ 10240
+ 1676221694
+ 1676221694
+ 0
+
+
+BBBB;
+
+ private $validXml1 = <<
+
+
+BBBB;
+
+
+ public function testParseValidXml()
+ {
+ $response = new ResponseCore(array(), $this->validXml, 200);
+ $result = new ListReservedCapacityResult($response);
+ $this->assertTrue($result->isOK());
+ $this->assertNotNull($result->getData());
+ $this->assertNotNull($result->getRawResponse());
+ $result1 = $result->getData();
+
+ $list = $result1->getReservedCapacityList();
+ $record = $list[0];
+ $this->assertEquals($record->getOwnerId(),"ut_test_put_bucket");
+ $this->assertEquals($record->getOwnerDisplayName(),"ut_test_put_bucket");
+ $this->assertEquals($record->getInstanceId(),"e72beabd-33ed-4c21-8069-0b6cf8a0dfc2");
+ $this->assertEquals($record->getName(),"test-rc");
+ $this->assertEquals($record->getRegion(),"oss-cn-hangzhou");
+ $this->assertEquals($record->getStatus(),"Init");
+ $this->assertEquals($record->getDataRedundancyType(),"ZRS");
+ $this->assertEquals($record->getCreateTime(),1676106871);
+ $this->assertEquals($record->getLastModifyTime(),1676106871);
+ $this->assertEquals($record->getEnableTime(),0);
+
+ $record1 = $list[1];
+ $this->assertEquals($record1->getOwnerId(),"ut_test_put_bucket");
+ $this->assertEquals($record1->getOwnerDisplayName(),"ut_test_put_bucket");
+ $this->assertEquals($record1->getInstanceId(),"dd67179e-77b7-415f-a571-e3396e926356");
+ $this->assertEquals($record1->getName(),"test-rc1");
+ $this->assertEquals($record1->getRegion(),"oss-cn-hangzhou");
+ $this->assertEquals($record1->getStatus(),"Enabled");
+ $this->assertEquals($record1->getDataRedundancyType(),"LRS");
+ $this->assertEquals($record->getReservedCapacity(),20480);
+ $this->assertNull($record->getAutoExpansionSize());
+ $this->assertNull($record->getAutoExpansionMaxSize());
+ $this->assertEquals($record1->getCreateTime(),1676106931);
+ $this->assertEquals($record1->getLastModifyTime(),1676224171);
+ $this->assertEquals($record1->getEnableTime(),0);
+ }
+
+
+ public function testParseValidXml1()
+ {
+ $response = new ResponseCore(array(), $this->validXml1, 200);
+ $result = new ListReservedCapacityResult($response);
+ $this->assertTrue($result->isOK());
+ $this->assertNotNull($result->getData());
+ $this->assertNotNull($result->getRawResponse());
+ $result1 = $result->getData();
+
+ $this->assertNull($result1->getReservedCapacityList());
+ }
+}
diff --git a/tests/OSS/Tests/OssClientReservedCapacityTest.php b/tests/OSS/Tests/OssClientReservedCapacityTest.php
new file mode 100644
index 00000000..21003979
--- /dev/null
+++ b/tests/OSS/Tests/OssClientReservedCapacityTest.php
@@ -0,0 +1,131 @@
+ossClient->createReservedCapacity($create);
+ $this->assertTrue(true);
+ } catch (OssException $e) {
+ printf($e->getMessage());
+ $this->assertTrue(false);
+ }
+
+ $id = $createRs['x-oss-reserved-capacity-id'];
+
+ try {
+ $status = "Enabled";
+ $reservedCapacity = 10240;
+ $autoExpansionSize = 100;
+ $autoExpansionMaxSize = 20480;
+ $update = new UpdateReservedCapacity($status,$reservedCapacity,$autoExpansionSize,$autoExpansionMaxSize);
+ $updateRs = $this->ossClient->updateReservedCapacity($id, $update);
+ $this->assertEquals($updateRs['x-oss-reserved-capacity-id'], $id);
+ } catch (OssException $e) {
+ printf($e->getMessage());
+ $this->assertTrue(false);
+ }
+
+ try {
+ $record = $this->ossClient->getReservedCapacity($id);
+ $this->assertEquals($record->getInstanceId(), $id);
+ $this->assertEquals($record->getStatus(), $status);
+ $this->assertEquals($record->getName(), $name);
+ $this->assertNotEmpty($record->getOwnerDisplayName());
+ $this->assertNotEmpty($record->getOwnerId());
+ $this->assertNotEmpty($record->getRegion());
+ $this->assertEquals($record->getDataRedundancyType(),$dataRedundancyType);
+ $this->assertEquals($record->getReservedCapacity(),$reservedCapacity);
+ $this->assertNotEmpty($record->getCreateTime());
+ $this->assertNotEmpty($record->getLastModifyTime());
+ $this->assertNotEmpty($record->getEnableTime());
+ $this->assertEquals($record->getAutoExpansionSize(), $autoExpansionSize);
+ $this->assertEquals($record->getAutoExpansionMaxSize(), $autoExpansionMaxSize);
+ } catch (OssException $e) {
+ printf($e->getMessage());
+ $this->assertTrue(false);
+ }
+
+ try {
+ $bucketList = $this->ossClient->listBucketWithReservedCapacity($id);
+ $this->assertEquals($bucketList->getInstanceId(), $id);
+ $this->assertNull($bucketList->getBucketList());
+ } catch (OssException $e) {
+ printf($e->getMessage());
+ $this->assertTrue(false);
+ }
+
+ try {
+ $list = $this->ossClient->listReservedCapacity();
+ $this->assertTrue(count($list->getReservedCapacityList()) > 0);
+ } catch (OssException $e) {
+ printf($e->getMessage());
+ $this->assertTrue(false);
+ }
+
+ try {
+ $options = array(
+ OssClient::OSS_STORAGE => OssClient::OSS_STORAGE_RESERVEDCAPACITY,
+ OssClient::OSS_REDUNDANCY => OssClient::OSS_REDUNDANCY_LRS,
+ OssClient::OSS_RESERVED_CAPACITY_ID => $id
+
+ );
+ $bucket = 'php-sdk-bucket-'. time();
+ $this->ossClient->createBucket($bucket, OssClient::OSS_ACL_TYPE_PRIVATE,$options);
+ $this->assertTrue(true);
+ } catch (OssException $e) {
+ printf($e->getMessage());
+ $this->assertTrue(false);
+ }
+
+ try {
+ $bucketList = $this->ossClient->listBucketWithReservedCapacity($id);
+ $this->assertEquals($bucketList->getInstanceId(), $id);
+ $this->assertTrue(count($bucketList->getBucketList()) == 1);
+ } catch (OssException $e) {
+ printf($e->getMessage());
+ $this->assertTrue(false);
+ }
+
+ try {
+ $bucketInfo = $this->ossClient->getBucketInfo($bucket);
+ $this->assertEquals($bucketInfo->getReservedCapacityInstanceId(), $id);
+ } catch (OssException $e) {
+ printf($e->getMessage());
+ $this->assertTrue(false);
+ }
+
+
+ try {
+ $bucketStat = $this->ossClient->getBucketStat($bucket);
+ $this->assertEquals($bucketStat->getReservedCapacityStorage(), 0);
+ $this->assertEquals($bucketStat->getReservedCapacityObjectCount(), 0);
+ $this->assertEquals($bucketStat->getDeepColdArchiveStorage(), 0);
+ $this->assertEquals($bucketStat->getDeepColdArchiveRealStorage(), 0);
+ $this->assertEquals($bucketStat->getDeepColdArchiveObjectCount(), 0);
+ } catch (OssException $e) {
+ printf($e->getMessage());
+ $this->assertTrue(false);
+ }
+
+
+
+ $this->ossClient->deleteBucket($bucket);
+
+
+ }
+}
diff --git a/tests/OSS/Tests/UpdateReservedCapacityTest.php b/tests/OSS/Tests/UpdateReservedCapacityTest.php
new file mode 100644
index 00000000..15094041
--- /dev/null
+++ b/tests/OSS/Tests/UpdateReservedCapacityTest.php
@@ -0,0 +1,59 @@
+
+
+Enabled
+10240
+100
+20480
+
+BBBB;
+
+ private $validXml1 = <<
+
+Enabled
+
+BBBB;
+
+ private $validXml2 = <<
+
+BBBB;
+
+ public function testParseValidXml()
+ {
+ $status = "Enabled";
+ $reservedCapacity = 10240;
+ $autoExpansionSize = 100;
+ $autoExpansionMaxSize = 20480;
+ $update = new UpdateReservedCapacity($status,$reservedCapacity,$autoExpansionSize,$autoExpansionMaxSize);
+ $this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($update->serializeToXml()));
+ }
+
+ public function testParseValidXml1()
+ {
+ $status = "Enabled";
+ $config = new UpdateReservedCapacity($status);
+ $this->assertEquals($this->cleanXml($this->validXml1), $this->cleanXml($config->serializeToXml()));
+ }
+
+ public function testParseValidXml2()
+ {
+ $config = new UpdateReservedCapacity();
+ $this->assertEquals($this->cleanXml($this->validXml2), $this->cleanXml($config->serializeToXml()));
+ }
+
+ private function cleanXml($xml)
+ {
+ return str_replace("\n", "", str_replace("\r", "", $xml));
+ }
+}