-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from aliyun/restorebuket
Supports IA/Archive in CreateBucket API and Restore API
- Loading branch information
Showing
28 changed files
with
486 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) Alibaba Cloud Computing | ||
* All rights reserved. | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.Net; | ||
using System.Threading; | ||
using Aliyun.OSS.Model; | ||
using Aliyun.OSS.Common; | ||
|
||
namespace Aliyun.OSS.Samples | ||
{ | ||
/// <summary> | ||
/// Sample usage of RestoreObject API | ||
/// </summary> | ||
public static class RestoreArchiveObjectSample | ||
{ | ||
static string accessKeyId = Config.AccessKeyId; | ||
static string accessKeySecret = Config.AccessKeySecret; | ||
static string endpoint = Config.Endpoint; | ||
static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); | ||
|
||
public static void RestoreArchiveObject(string bucketName, string key, bool waitUtilFinished = true, int maxWaitTimeInSeconds = 600) | ||
{ | ||
RestoreObjectResult result = client.RestoreObject(bucketName, key); | ||
if (result.HttpStatusCode != HttpStatusCode.Accepted || !waitUtilFinished) | ||
{ | ||
throw new OssException(result.RequestId + ", " + result.HttpStatusCode + " ,"); | ||
} | ||
|
||
while (maxWaitTimeInSeconds > 0) | ||
{ | ||
var meta = client.GetObjectMetadata(bucketName, key); | ||
string restoreStatus = meta.HttpMetadata["x-oss-restore"] as string; | ||
if (restoreStatus != null && restoreStatus.StartsWith("ongoing-request=\"false\"", StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
break; | ||
} | ||
|
||
Thread.Sleep(1000); | ||
maxWaitTimeInSeconds--; | ||
} | ||
|
||
if (maxWaitTimeInSeconds == 0) | ||
{ | ||
throw new TimeoutException(); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (C) Alibaba Cloud Computing | ||
* All rights reserved. | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Aliyun.OSS.Common.Communication; | ||
using Aliyun.OSS.Util; | ||
using Aliyun.OSS.Transform; | ||
using Aliyun.OSS.Properties; | ||
using Aliyun.OSS.Model; | ||
|
||
namespace Aliyun.OSS.Commands | ||
{ | ||
internal class RestoreObjectCommand : OssCommand<RestoreObjectResult> | ||
{ | ||
private string bucketName; | ||
private string key; | ||
|
||
protected override string Bucket | ||
{ | ||
get { | ||
return bucketName; | ||
} | ||
} | ||
|
||
protected override string Key | ||
{ | ||
get { | ||
return key; | ||
} | ||
} | ||
|
||
protected override HttpMethod Method | ||
{ | ||
get { return HttpMethod.Post; } | ||
} | ||
|
||
protected override IDictionary<string, string> Parameters | ||
{ | ||
get | ||
{ | ||
var parameters = new Dictionary<string, string>(); | ||
parameters[RequestParameters.SUBRESOURCE_RESTORE] = null; | ||
return parameters; | ||
} | ||
} | ||
|
||
private RestoreObjectCommand(IServiceClient client, Uri endpoint, ExecutionContext context, | ||
string bucketName, string key, IDeserializer<ServiceResponse, RestoreObjectResult> deserializer) | ||
: base(client, endpoint, context, deserializer) | ||
{ | ||
OssUtils.CheckBucketName(bucketName); | ||
OssUtils.CheckObjectKey(key); | ||
|
||
this.bucketName = bucketName; | ||
this.key = key; | ||
this.ParametersInUri = true; // in restore request, the parameter restore needs to be in uri | ||
} | ||
|
||
public static RestoreObjectCommand Create(IServiceClient client, Uri endpoint, | ||
ExecutionContext context, | ||
string bucketName, string key) | ||
{ | ||
return new RestoreObjectCommand(client, endpoint, context, bucketName, key, DeserializerFactory.GetFactory().CreateRestoreObjectResultDeserializer()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (C) Alibaba Cloud Computing | ||
* All rights reserved. | ||
* | ||
*/ | ||
using System; | ||
namespace Aliyun.OSS | ||
{ | ||
/// <summary> | ||
/// Storage class of OSS Bucket | ||
/// </summary> | ||
public enum StorageClass | ||
{ | ||
Standard, // Standard bucket | ||
IA, // Infrequent Access bucket | ||
Archive // Archive bucket | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (C) Alibaba Cloud Computing | ||
* All rights reserved. | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.Xml.Serialization; | ||
|
||
namespace Aliyun.OSS.Model | ||
{ | ||
[XmlRoot("CreateBucketConfiguration")] | ||
public class CreateBucketRequestModel | ||
{ | ||
[XmlElement("StorageClass")] | ||
public StorageClass StorageClass { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (C) Alibaba Cloud Computing | ||
* All rights reserved. | ||
* | ||
*/ | ||
|
||
using System; | ||
using System.Xml.Serialization; | ||
|
||
namespace Aliyun.OSS.Model | ||
{ | ||
public class RestoreObjectResult : GenericResult | ||
{ | ||
} | ||
} |
Oops, something went wrong.