Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public BlobDownloadDetails() { }
public Azure.Storage.Blobs.Models.LeaseStatus LeaseStatus { get { throw null; } }
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } }
public string ObjectReplicationDestinationPolicy { get { throw null; } }
public System.Collections.Generic.IDictionary<string, System.Collections.Generic.IDictionary<string, string>> ObjectReplicationSourceProperties { get { throw null; } }
public System.Collections.Generic.IList<Azure.Storage.Blobs.Models.ObjectReplicationPolicy> ObjectReplicationSourceProperties { get { throw null; } }
public long TagCount { get { throw null; } }
public string VersionId { get { throw null; } }
}
Expand Down Expand Up @@ -684,7 +684,7 @@ public BlobProperties() { }
public Azure.Storage.Blobs.Models.LeaseStatus LeaseStatus { get { throw null; } }
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } }
public string ObjectReplicationDestinationPolicy { get { throw null; } }
public System.Collections.Generic.IDictionary<string, System.Collections.Generic.IDictionary<string, string>> ObjectReplicationSourceProperties { get { throw null; } }
public System.Collections.Generic.IList<Azure.Storage.Blobs.Models.ObjectReplicationPolicy> ObjectReplicationSourceProperties { get { throw null; } }
public long TagCount { get { throw null; } }
public string VersionId { get { throw null; } }
}
Expand Down Expand Up @@ -806,7 +806,7 @@ public static partial class BlobsModelFactory
public static Azure.Storage.Blobs.Models.BlobLease BlobLease(Azure.ETag eTag, System.DateTimeOffset lastModified, string leaseId) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static Azure.Storage.Blobs.Models.BlobProperties BlobProperties(System.DateTimeOffset lastModified, Azure.Storage.Blobs.Models.LeaseDurationType leaseDuration, Azure.Storage.Blobs.Models.LeaseState leaseState, Azure.Storage.Blobs.Models.LeaseStatus leaseStatus, long contentLength, string destinationSnapshot, Azure.ETag eTag, byte[] contentHash, string contentEncoding, string contentDisposition, string contentLanguage, bool isIncrementalCopy, string cacheControl, Azure.Storage.Blobs.Models.CopyStatus copyStatus, long blobSequenceNumber, System.Uri copySource, string acceptRanges, string copyProgress, int blobCommittedBlockCount, string copyId, bool isServerEncrypted, string copyStatusDescription, string encryptionKeySha256, System.DateTimeOffset copyCompletedOn, string accessTier, Azure.Storage.Blobs.Models.BlobType blobType, bool accessTierInferred, System.Collections.Generic.IDictionary<string, string> metadata, string archiveStatus, System.DateTimeOffset createdOn, System.DateTimeOffset accessTierChangedOn, string contentType) { throw null; }
public static Azure.Storage.Blobs.Models.BlobProperties BlobProperties(System.DateTimeOffset lastModified, Azure.Storage.Blobs.Models.LeaseStatus leaseStatus, long contentLength, string contentType, Azure.ETag eTag, Azure.Storage.Blobs.Models.LeaseState leaseState, string contentEncoding, string contentDisposition, string contentLanguage, string cacheControl, long blobSequenceNumber, Azure.Storage.Blobs.Models.LeaseDurationType leaseDuration, string acceptRanges, string destinationSnapshot, int blobCommittedBlockCount, bool isIncrementalCopy, bool isServerEncrypted, Azure.Storage.Blobs.Models.CopyStatus copyStatus, string encryptionKeySha256, System.Uri copySource, string encryptionScope, string copyProgress, string accessTier, string copyId, bool accessTierInferred, string copyStatusDescription, string archiveStatus, System.DateTimeOffset copyCompletedOn, System.DateTimeOffset accessTierChangedOn, Azure.Storage.Blobs.Models.BlobType blobType, string versionId, System.Collections.Generic.IDictionary<string, System.Collections.Generic.IDictionary<string, string>> objectReplicationSourceProperties, bool isCurrentVersion, string objectReplicationDestinationPolicy, long tagCount, System.Collections.Generic.IDictionary<string, string> metadata, System.DateTimeOffset expiresOn, System.DateTimeOffset createdOn, bool isSealed, byte[] contentHash) { throw null; }
public static Azure.Storage.Blobs.Models.BlobProperties BlobProperties(System.DateTimeOffset lastModified, Azure.Storage.Blobs.Models.LeaseStatus leaseStatus, long contentLength, string contentType, Azure.ETag eTag, Azure.Storage.Blobs.Models.LeaseState leaseState, string contentEncoding, string contentDisposition, string contentLanguage, string cacheControl, long blobSequenceNumber, Azure.Storage.Blobs.Models.LeaseDurationType leaseDuration, string acceptRanges, string destinationSnapshot, int blobCommittedBlockCount, bool isIncrementalCopy, bool isServerEncrypted, Azure.Storage.Blobs.Models.CopyStatus copyStatus, string encryptionKeySha256, System.Uri copySource, string encryptionScope, string copyProgress, string accessTier, string copyId, bool accessTierInferred, string copyStatusDescription, string archiveStatus, System.DateTimeOffset copyCompletedOn, System.DateTimeOffset accessTierChangedOn, Azure.Storage.Blobs.Models.BlobType blobType, string versionId, System.Collections.Generic.IList<Azure.Storage.Blobs.Models.ObjectReplicationPolicy> objectReplicationSourceProperties, bool isCurrentVersion, string objectReplicationDestinationPolicy, long tagCount, System.Collections.Generic.IDictionary<string, string> metadata, System.DateTimeOffset expiresOn, System.DateTimeOffset createdOn, bool isSealed, byte[] contentHash) { throw null; }
public static Azure.Storage.Blobs.Models.BlobQueryError BlobQueryError(string name = null, string description = null, bool isFatal = false, long position = (long)0) { throw null; }
public static Azure.Storage.Blobs.Models.BlobServiceStatistics BlobServiceStatistics(Azure.Storage.Blobs.Models.BlobGeoReplication geoReplication = null) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
Expand All @@ -818,6 +818,8 @@ public static partial class BlobsModelFactory
public static Azure.Storage.Blobs.Models.BlockList BlockList(System.Collections.Generic.IEnumerable<Azure.Storage.Blobs.Models.BlobBlock> committedBlocks = null, System.Collections.Generic.IEnumerable<Azure.Storage.Blobs.Models.BlobBlock> uncommittedBlocks = null) { throw null; }
public static Azure.Storage.Blobs.Models.FilterBlobItem FilterBlobItem(string name, string containerName, string tagValue) { throw null; }
public static Azure.Storage.Blobs.Models.FilterBlobSegment FilterBlobSegment(string serviceEndpoint, string where, System.Collections.Generic.IEnumerable<Azure.Storage.Blobs.Models.FilterBlobItem> blobs, string nextMarker = null) { throw null; }
public static Azure.Storage.Blobs.Models.ObjectReplicationPolicy ObjectReplicationPolicy(string policyId, System.Collections.Generic.IList<Azure.Storage.Blobs.Models.ObjectReplicationRule> rules) { throw null; }
public static Azure.Storage.Blobs.Models.ObjectReplicationRule ObjectReplicationRule(string ruleId, Azure.Storage.Blobs.Models.ObjectReplicationStatus replicationStatus) { throw null; }
public static Azure.Storage.Blobs.Models.PageBlobInfo PageBlobInfo(Azure.ETag eTag, System.DateTimeOffset lastModified, long blobSequenceNumber) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static Azure.Storage.Blobs.Models.PageInfo PageInfo(Azure.ETag eTag, System.DateTimeOffset lastModified, byte[] contentHash, byte[] contentCrc64, long blobSequenceNumber, string encryptionKeySha256) { throw null; }
Expand Down Expand Up @@ -1034,6 +1036,24 @@ public enum ListContainersIncludeType
Metadata = 0,
Deleted = 1,
}
public partial class ObjectReplicationPolicy
{
internal ObjectReplicationPolicy() { }
public string PolicyId { get { throw null; } }
public System.Collections.Generic.IList<Azure.Storage.Blobs.Models.ObjectReplicationRule> Rules { get { throw null; } }
}
public partial class ObjectReplicationRule
{
internal ObjectReplicationRule() { }
public Azure.Storage.Blobs.Models.ObjectReplicationStatus ReplicationStatus { get { throw null; } }
public string RuleId { get { throw null; } }
}
[System.FlagsAttribute]
public enum ObjectReplicationStatus
{
Complete = 0,
Failed = 1,
}
public partial class PageBlobInfo
{
internal PageBlobInfo() { }
Expand Down
47 changes: 28 additions & 19 deletions sdk/storage/Azure.Storage.Blobs/src/BlobExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ internal static BlobProperties ToBlobProperties(this BlobPropertiesInternal prop
CreatedOn = properties.CreatedOn,
Metadata = properties.Metadata,
ObjectReplicationDestinationPolicy = properties.ObjectReplicationPolicyId,
ObjectReplicationSourceProperties = BlobExtensions.ParseObjectReplicationIds(properties.ObjectReplicationRules),
ObjectReplicationSourceProperties =
properties.ObjectReplicationRules?.Count > 0
? BlobExtensions.ParseObjectReplicationIds(properties.ObjectReplicationRules)
: null,
BlobType = properties.BlobType,
CopyCompletedOn = properties.CopyCompletedOn,
CopyStatusDescription = properties.CopyStatusDescription,
Expand Down Expand Up @@ -157,40 +160,46 @@ internal static BlobProperties ToBlobProperties(this BlobPropertiesInternal prop
/// </param>
/// <returns>
/// If the blob has object replication policy(s) applied and is the source blob, this method will return a
/// dictionary of policy Ids, with a dictionary of rules and replication status for each policy
/// (As each policy id, could have multiple rule ids).
/// List of <see cref="ObjectReplicationPolicy"/>, which contains the Policy ID and the respective
/// rule(s) and replication status(s) for each policy.
/// If the blob has object replication policy applied and is the destination blob,
/// this method will return default as the policy id should be set in ObjectReplicationDestinationPolicy
/// (e.g. <see cref="BlobProperties.ObjectReplicationDestinationPolicy"/>,<see cref="BlobDownloadDetails.ObjectReplicationDestinationPolicy"/>).
/// Otherwise null will be returned.
/// </returns>
internal static IDictionary<string, IDictionary<string, string>> ParseObjectReplicationIds(this IDictionary<string, string> OrIds)
internal static IList<ObjectReplicationPolicy> ParseObjectReplicationIds(this IDictionary<string, string> OrIds)
{
if (OrIds == null)
{
return null;
}
// If the dictionary is empty or it contains a key with policy id, we are not required to do any parsing since
// If the dictionary contains a key with policy id, we are not required to do any parsing since
// the policy id should already be stored in the ObjectReplicationDestinationPolicy.
if (OrIds.Count == 0 ||
(OrIds.Count > 0 &&
(OrIds.First().Key == "policy-id")))
if (OrIds.First().Key == "policy-id")
{
return default;
}
IDictionary<string, IDictionary<string, string>> OrProperties = new Dictionary<string, IDictionary<string, string>>();
List <ObjectReplicationPolicy> OrProperties = new List<ObjectReplicationPolicy>();
foreach (KeyValuePair<string, string> status in OrIds)
{
string[] ParsedIds = status.Key.Split('_');
if (OrProperties.ContainsKey(ParsedIds[0]))
int policyIndex = OrProperties.FindIndex(policy => policy.PolicyId == ParsedIds[0]);
if (policyIndex > -1)
{
OrProperties[ParsedIds[0]].Add(ParsedIds[1], status.Value);
OrProperties[policyIndex].Rules.Add(new ObjectReplicationRule
{
RuleId = ParsedIds[1],
ReplicationStatus = (ObjectReplicationStatus) Enum.Parse(typeof(ObjectReplicationStatus), status.Value, true)
});
}
else
{
IDictionary<string, string> NewRuleStatus = new Dictionary<string, string>();
NewRuleStatus.Add(ParsedIds[1], status.Value);
OrProperties.Add(ParsedIds[0], NewRuleStatus);
IList<ObjectReplicationRule> NewRuleStatus = new List<ObjectReplicationRule>();
NewRuleStatus.Add(new ObjectReplicationRule
{
RuleId = ParsedIds[1],
ReplicationStatus = (ObjectReplicationStatus)Enum.Parse(typeof(ObjectReplicationStatus), status.Value, true)
});
OrProperties.Add(new ObjectReplicationPolicy()
{
PolicyId = ParsedIds[0],
Rules = NewRuleStatus
});
}
}
return OrProperties;
Expand Down
7 changes: 5 additions & 2 deletions sdk/storage/Azure.Storage.Blobs/src/Models/BlobInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ internal BlobDownloadInfo(FlattenedDownloadProperties flattened)
_flattened = flattened;
Details = new BlobDownloadDetails() {
_flattened = flattened,
ObjectReplicationSourceProperties = BlobExtensions.ParseObjectReplicationIds(flattened.ObjectReplicationRules)
ObjectReplicationSourceProperties =
flattened.ObjectReplicationRules?.Count > 0
? BlobExtensions.ParseObjectReplicationIds(flattened.ObjectReplicationRules)
: null
};
}

Expand Down Expand Up @@ -244,7 +247,7 @@ public partial class BlobDownloadDetails
/// <summary>
/// x-ms-or
/// </summary>
public IDictionary<string, IDictionary<string, string>> ObjectReplicationSourceProperties { get; internal set; }
public IList<ObjectReplicationPolicy> ObjectReplicationSourceProperties { get; internal set; }

/// <summary>
/// Object Replication Policy Id. This value is only set when the policy id
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/Azure.Storage.Blobs/src/Models/BlobProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public partial class BlobProperties
/// <summary>
/// Parsed Object Replication Policy Id, Rule Id(s) and status of the source blob.
/// </summary>
public IDictionary<string, IDictionary<string, string>> ObjectReplicationSourceProperties { get; internal set; }
public IList<ObjectReplicationPolicy> ObjectReplicationSourceProperties { get; internal set; }

/// <summary>
/// The blob's type.
Expand Down Expand Up @@ -255,7 +255,7 @@ public partial class BlobProperties
public BlobProperties()
{
Metadata = new Dictionary<string, string>(System.StringComparer.OrdinalIgnoreCase);
ObjectReplicationSourceProperties = new Dictionary<string, IDictionary<string, string>>(StringComparer.OrdinalIgnoreCase);
ObjectReplicationSourceProperties = new List<ObjectReplicationPolicy>();
}
}
}
26 changes: 25 additions & 1 deletion sdk/storage/Azure.Storage.Blobs/src/Models/BlobsModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static BlobProperties BlobProperties(
DateTimeOffset accessTierChangedOn,
BlobType blobType,
string versionId,
IDictionary<string, IDictionary<string, string>> objectReplicationSourceProperties,
IList<ObjectReplicationPolicy> objectReplicationSourceProperties,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add this to BlobDownloadDetails's factory.

bool isCurrentVersion,
string objectReplicationDestinationPolicy,
long tagCount,
Expand Down Expand Up @@ -510,5 +510,29 @@ public static BlobQueryError BlobQueryError(
IsFatal = isFatal,
Position = position
};

/// <summary>
/// Creates a new ObjectReplicationPolicy instance for mocking.
/// </summary>
public static ObjectReplicationPolicy ObjectReplicationPolicy(
string policyId,
IList<ObjectReplicationRule> rules)
=> new ObjectReplicationPolicy
{
PolicyId = policyId,
Rules = rules
};

/// <summary>
/// Creates a new ObjectReplicationRule instance for mocking.
/// </summary>
public static ObjectReplicationRule ObjectReplicationRule(
string ruleId,
ObjectReplicationStatus replicationStatus)
=> new ObjectReplicationRule
{
RuleId = ruleId,
ReplicationStatus = replicationStatus
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Text;

namespace Azure.Storage.Blobs.Models
{
/// <summary>
/// Contains Object Replication Policy ID and the respective list of
/// <see cref="ObjectReplicationRule"/>(s). This is used when retrieving the
/// Object Replication Properties on the source blob. The policy id for the
/// destination blob is set in ObjectReplicationDestinationPolicy of the respective
/// method responses. (e.g. <see cref="BlobProperties.ObjectReplicationDestinationPolicy"/>,
/// <see cref="BlobDownloadDetails.ObjectReplicationDestinationPolicy"/>).
/// </summary>
public class ObjectReplicationPolicy
{
internal ObjectReplicationPolicy() { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have a SomethingFactory class where customers can create these for test purposes. We should add ORS entities there as well to factory method for the type enclosing them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amnguye you can add methods to create ObjectReplicationPolicy and ObjectReplicationRule in the BlobsModelFactory.

/// <summary>
/// The Object Replication Policy ID.
/// </summary>
public string PolicyId { get; internal set; }
/// <summary>
/// The Rule ID(s) and respective Replication Status(s) that are under
/// the Policy ID.
/// </summary>
public IList<ObjectReplicationRule> Rules { get; internal set; }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Text;

namespace Azure.Storage.Blobs.Models
{
/// <summary>
/// Contains the Object Replication Rule ID and Replication Status(
/// <see cref="ObjectReplicationStatus"/>) of a blob.
/// There can be more than one <see cref="ObjectReplicationRule"/> under a
/// <see cref="ObjectReplicationPolicy"/>. Object Replication Rule IDs
/// </summary>
public class ObjectReplicationRule
{
internal ObjectReplicationRule() { }
/// <summary>
/// The Object Replication Rule ID.
/// </summary>
public string RuleId { get; internal set; }
/// <summary>
/// The Replication Status. See <see cref="ObjectReplicationStatus"/>.
/// </summary>
public ObjectReplicationStatus ReplicationStatus { get; internal set; }
}

/// <summary>
/// Specifies the Replication Status of a blob. This is used when a storage account
/// has Object Replication Policy(s) applied. See <see cref="ObjectReplicationPolicy"/>
/// and <see cref="ObjectReplicationRule"/>.
/// </summary>
[Flags]
public enum ObjectReplicationStatus
{
/// <summary>
/// Object Replication to the
/// destination completed.
/// </summary>
Complete = 0,

/// <summary>
/// Object Replication to the
/// destination container failed.
/// </summary>
Failed = 1
}
}
Loading