Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 66659cc

Browse files
author
jofriedm-msft
authored
Merge pull request #98 from wastore/tierchangetime
Last modified tier change time support
2 parents 23a1b4e + 3033bcf commit 66659cc

File tree

9 files changed

+89
-7
lines changed

9 files changed

+89
-7
lines changed

ChangeLog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2017.XX.XX Version X.X.X
2+
* Added support for the last time the tier was modified.
3+
14
2017.10.06 Version 6.0.0
25
* Added support for taking a snapshot of a share.
36
* IOExceptions wrapping StorageExceptions will now contain the StorageException message in the outer exception.

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,22 +1946,38 @@ public void testCloudBlockBlobUploadStandardTier() throws StorageException, IOEx
19461946
final String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlob");
19471947
final CloudBlockBlob blob = this.container.getBlockBlobReference(blobName);
19481948
blob.uploadText("text");
1949+
blob.downloadAttributes();
1950+
assertNotNull(blob.getProperties().getStandardBlobTier());
1951+
assertNull(blob.getProperties().getPremiumPageBlobTier());
1952+
assertTrue(blob.getProperties().isBlobTierInferred());
1953+
1954+
CloudBlockBlob listBlob = (CloudBlockBlob)this.container.listBlobs().iterator().next();
1955+
assertNotNull(listBlob.getProperties().getStandardBlobTier());
1956+
assertNull(listBlob.getProperties().getPremiumPageBlobTier());
1957+
assertTrue(listBlob.getProperties().isBlobTierInferred());
19491958

19501959
blob.uploadStandardBlobTier(standardBlobTier);
19511960
assertEquals(standardBlobTier, blob.getProperties().getStandardBlobTier());
19521961
assertNull(blob.getProperties().getPremiumPageBlobTier());
19531962
assertNull(blob.getProperties().getRehydrationStatus());
1963+
assertFalse(blob.getProperties().isBlobTierInferred());
1964+
assertNull(blob.getProperties().getTierChangeTime());
19541965

19551966
CloudBlockBlob blob2 = this.container.getBlockBlobReference(blobName);
19561967
blob2.downloadAttributes();
19571968
assertEquals(standardBlobTier, blob2.getProperties().getStandardBlobTier());
19581969
assertNull(blob2.getProperties().getPremiumPageBlobTier());
19591970
assertNull(blob2.getProperties().getRehydrationStatus());
1971+
assertFalse(blob2.getProperties().isBlobTierInferred());
1972+
assertNotNull(blob2.getProperties().getTierChangeTime());
19601973

19611974
CloudBlockBlob blob3 = (CloudBlockBlob)this.container.listBlobs().iterator().next();
19621975
assertEquals(standardBlobTier, blob3.getProperties().getStandardBlobTier());
19631976
assertNull(blob3.getProperties().getPremiumPageBlobTier());
19641977
assertNull(blob3.getProperties().getRehydrationStatus());
1978+
assertNull(blob3.getProperties().isBlobTierInferred());
1979+
assertNotNull(blob3.getProperties().getTierChangeTime());
1980+
assertEquals(blob2.getProperties().getTierChangeTime(), blob3.getProperties().getTierChangeTime());
19651981

19661982
blob.deleteIfExists();
19671983
}
@@ -1984,32 +2000,38 @@ public void testCloudBlockBlobRehydrateBlob() throws StorageException, IOExcepti
19842000
assertNull(blobRef1.getProperties().getRehydrationStatus());
19852001
assertEquals(StandardBlobTier.ARCHIVE, blobRef1.getProperties().getStandardBlobTier());
19862002
assertNull(blobRef1.getProperties().getPremiumPageBlobTier());
2003+
assertNull(blobRef1.getProperties().getTierChangeTime());
19872004

19882005
blob.downloadAttributes();
19892006
assertEquals(RehydrationStatus.PENDING_TO_COOL, blob.getProperties().getRehydrationStatus());
19902007
assertEquals(StandardBlobTier.ARCHIVE, blob.getProperties().getStandardBlobTier());
19912008
assertNull(blob.getProperties().getPremiumPageBlobTier());
2009+
assertNotNull(blob.getProperties().getTierChangeTime());
19922010

19932011
CloudBlockBlob blobRef2 = this.container.getBlockBlobReference(blobName2);
19942012
blobRef2.uploadStandardBlobTier(StandardBlobTier.HOT);
19952013
assertNull(blobRef2.getProperties().getRehydrationStatus());
19962014
assertEquals(StandardBlobTier.ARCHIVE, blobRef2.getProperties().getStandardBlobTier());
19972015
assertNull(blobRef2.getProperties().getPremiumPageBlobTier());
2016+
assertNull(blobRef2.getProperties().getTierChangeTime());
19982017

19992018
blob2.downloadAttributes();
20002019
assertEquals(RehydrationStatus.PENDING_TO_HOT, blob2.getProperties().getRehydrationStatus());
20012020
assertEquals(StandardBlobTier.ARCHIVE, blob2.getProperties().getStandardBlobTier());
20022021
assertNull(blob2.getProperties().getPremiumPageBlobTier());
2022+
assertNotNull(blob2.getProperties().getTierChangeTime());
20032023

20042024
Iterator it = this.container.listBlobs().iterator();
20052025
CloudBlockBlob listBlob = (CloudBlockBlob)it.next();
20062026
assertEquals(RehydrationStatus.PENDING_TO_COOL, listBlob.getProperties().getRehydrationStatus());
20072027
assertEquals(StandardBlobTier.ARCHIVE, listBlob.getProperties().getStandardBlobTier());
20082028
assertNull(listBlob.getProperties().getPremiumPageBlobTier());
2029+
assertNotNull(listBlob.getProperties().getTierChangeTime());
20092030

20102031
CloudBlockBlob listBlob2 = (CloudBlockBlob)it.next();
20112032
assertEquals(RehydrationStatus.PENDING_TO_HOT, listBlob2.getProperties().getRehydrationStatus());
20122033
assertEquals(StandardBlobTier.ARCHIVE, listBlob2.getProperties().getStandardBlobTier());
20132034
assertNull(listBlob2.getProperties().getPremiumPageBlobTier());
2035+
assertNotNull(listBlob2.getProperties().getTierChangeTime());
20142036
}
20152037
}

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudPageBlobTests.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ public void testCloudPageBlobSetPremiumBlobTierOnCreate() throws URISyntaxExcept
12521252
CloudPageBlob blob2 = container.getPageBlobReference(blobName);
12531253
blob2.downloadAttributes();
12541254
assertEquals(PremiumPageBlobTier.P4, blob2.getProperties().getPremiumPageBlobTier());
1255-
assertNull(blob2.getProperties().isBlobTierInferred());
1255+
assertFalse(blob2.getProperties().isBlobTierInferred());
12561256
assertNull(blob2.getProperties().getStandardBlobTier());
12571257
assertNull(blob2.getProperties().getRehydrationStatus());
12581258

@@ -1268,7 +1268,7 @@ public void testCloudPageBlobSetPremiumBlobTierOnCreate() throws URISyntaxExcept
12681268
CloudPageBlob blob3Ref = container.getPageBlobReference("blob3");
12691269
blob3Ref.downloadAttributes();
12701270
assertEquals(PremiumPageBlobTier.P6, blob3Ref.getProperties().getPremiumPageBlobTier());
1271-
assertNull(blob3Ref.getProperties().isBlobTierInferred());
1271+
assertFalse(blob3Ref.getProperties().isBlobTierInferred());
12721272

12731273
// Test upload from stream API
12741274
ByteArrayInputStream srcStream = new ByteArrayInputStream(buffer);
@@ -1282,7 +1282,7 @@ public void testCloudPageBlobSetPremiumBlobTierOnCreate() throws URISyntaxExcept
12821282
CloudPageBlob blob4Ref = container.getPageBlobReference("blob4");
12831283
blob4Ref.downloadAttributes();
12841284
assertEquals(PremiumPageBlobTier.P10, blob4Ref.getProperties().getPremiumPageBlobTier());
1285-
assertNull(blob4Ref.getProperties().isBlobTierInferred());
1285+
assertFalse(blob4Ref.getProperties().isBlobTierInferred());
12861286

12871287
// Test upload from file API
12881288
File sourceFile = File.createTempFile("sourceFile", ".tmp");
@@ -1301,7 +1301,7 @@ public void testCloudPageBlobSetPremiumBlobTierOnCreate() throws URISyntaxExcept
13011301
CloudPageBlob blob5Ref = container.getPageBlobReference("blob5");
13021302
blob5Ref.downloadAttributes();
13031303
assertEquals(PremiumPageBlobTier.P20, blob5Ref.getProperties().getPremiumPageBlobTier());
1304-
assertNull(blob5Ref.getProperties().isBlobTierInferred());
1304+
assertFalse(blob5Ref.getProperties().isBlobTierInferred());
13051305
}
13061306
finally {
13071307
container.deleteIfExists();
@@ -1318,6 +1318,10 @@ public void testCloudPageBlobSetBlobTier() throws URISyntaxException, StorageExc
13181318
CloudPageBlob blob = container.getPageBlobReference(blobName);
13191319
blob.create(1024);
13201320
assertNull(blob.getProperties().isBlobTierInferred());
1321+
CloudPageBlob listBlob = (CloudPageBlob)container.listBlobs().iterator().next();
1322+
assertNull(listBlob.getProperties().getStandardBlobTier());
1323+
assertNotNull(listBlob.getProperties().getPremiumPageBlobTier());
1324+
13211325
blob.downloadAttributes();
13221326
assertTrue(blob.getProperties().isBlobTierInferred());
13231327
assertEquals(PremiumPageBlobTier.P10, blob.getProperties().getPremiumPageBlobTier());
@@ -1331,7 +1335,7 @@ public void testCloudPageBlobSetBlobTier() throws URISyntaxException, StorageExc
13311335
CloudPageBlob blob2 = container.getPageBlobReference(blobName);
13321336
blob2.downloadAttributes();
13331337
assertEquals(PremiumPageBlobTier.P40, blob2.properties.getPremiumPageBlobTier());
1334-
assertNull(blob2.getProperties().isBlobTierInferred());
1338+
assertFalse(blob2.getProperties().isBlobTierInferred());
13351339

13361340
boolean pageBlobWithTierFound = false;
13371341
for (ListBlobItem blobItem : container.listBlobs()) {
@@ -1404,7 +1408,7 @@ public void testCloudPageBlobSetBlobTierOnCopy() throws URISyntaxException, Stor
14041408
CloudPageBlob copyRef = container.getPageBlobReference("copy");
14051409
copyRef.downloadAttributes();
14061410
assertEquals(PremiumPageBlobTier.P30, copyRef.getProperties().getPremiumPageBlobTier());
1407-
assertNull(copyRef.getProperties().isBlobTierInferred());
1411+
assertFalse(copyRef.getProperties().isBlobTierInferred());
14081412

14091413
// copy where source does not have a tier
14101414
CloudPageBlob source2 = container.getPageBlobReference("source2");

microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,16 @@ public static class QueryConstants {
899899
*/
900900
public static final String ACCESS_TIER = "AccessTier";
901901

902+
/**
903+
* XML element for the access tier change time.
904+
*/
905+
public static final String ACCESS_TIER_CHANGE_TIME = "AccessTierChangeTime";
906+
907+
/**
908+
* XML element for access if the access tier is inferred.
909+
*/
910+
public static final String ACCESS_TIER_INFERRED = "AccessTierInferred";
911+
902912
/**
903913
* XML element for the archive status.
904914
*/

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
* Holds the Constants used for the Blob Service.
2121
*/
2222
final class BlobConstants {
23+
/**
24+
* The header that specifies the last time the tier was modified.
25+
*/
26+
public static final String ACCESS_TIER_CHANGE_TIME_HEADER = Constants.PREFIX_FOR_STORAGE_HEADER + "access-tier-change-time";
2327

2428
/**
2529
* The header that specifies the access tier header.

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobListHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.net.URI;
2020
import java.net.URISyntaxException;
2121
import java.text.ParseException;
22+
import java.util.Date;
2223
import java.util.HashMap;
2324
import java.util.Stack;
2425

@@ -348,6 +349,12 @@ else if (!standardBlobTier.equals(StandardBlobTier.UNKNOWN)) {
348349
}
349350
}
350351
}
352+
else if (Constants.ACCESS_TIER_INFERRED.equals(currentNode)) {
353+
this.properties.setBlobTierInferred(Boolean.parseBoolean(value));
354+
}
355+
else if (Constants.ACCESS_TIER_CHANGE_TIME.equals(currentNode)) {
356+
this.properties.setTierChangeTime(Utility.parseRFC1123DateFromStringInGMT(value));
357+
}
351358
else if (Constants.ARCHIVE_STATUS.equals(currentNode)) {
352359
this.properties.setRehydrationStatus(RehydrationStatus.parse(value));
353360
}

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobProperties.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ public final class BlobProperties {
132132
*/
133133
private Boolean isBlobTierInferredTier;
134134

135+
/**
136+
* Represents the last time the tier was changed.
137+
*/
138+
private Date tierChangeTime;
139+
135140
/**
136141
* Represents the rehydration status if the blob is being rehydrated.
137142
*/
@@ -174,6 +179,7 @@ public BlobProperties(final BlobProperties other) {
174179
this.serverEncrypted = other.serverEncrypted;
175180
this.standardBlobTier = other.standardBlobTier;
176181
this.rehydrationStatus = other.rehydrationStatus;
182+
this.tierChangeTime = other.tierChangeTime;
177183
}
178184

179185
/**
@@ -296,12 +302,19 @@ public Date getLastModified() {
296302
}
297303

298304
/**
299-
* Gets a value indicating if the tier of the premium page blob has been inferred.
305+
* Gets a value indicating if the tier of the blob has been inferred.
300306
*
301307
* @return A {@Link java.lang.Boolean} object which represents if the blob tier was inferred.
302308
*/
303309
public Boolean isBlobTierInferred() { return this.isBlobTierInferredTier; }
304310

311+
/**
312+
* Gets a value indicating the last time the tier was changed on the blob.
313+
*
314+
* @return A {@link java.util.Date} object which represents the last time the tier was changed.
315+
*/
316+
public Date getTierChangeTime() { return this.tierChangeTime; }
317+
305318
/**
306319
* Gets the lease status for the blob.
307320
*
@@ -596,6 +609,15 @@ protected void setBlobTierInferred(Boolean isBlobTierInferredTier) {
596609
this.isBlobTierInferredTier = isBlobTierInferredTier;
597610
}
598611

612+
/**
613+
* Sets the last time the tier was modified on the blob.
614+
* @param tierChangeTime
615+
* A {@link java.util.Date} which specifies the last time the tier was modified.
616+
*/
617+
protected void setTierChangeTime(Date tierChangeTime) {
618+
this.tierChangeTime = tierChangeTime;
619+
}
620+
599621
/**
600622
* Sets the rehydration status of the blob.
601623
* @param rehydrationStatus

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ else if (!standardBlobTier.equals(StandardBlobTier.UNKNOWN)) {
154154
if (!Utility.isNullOrEmpty(tierInferredString)) {
155155
properties.setBlobTierInferred(Boolean.parseBoolean(tierInferredString));
156156
}
157+
else if (properties.getPremiumPageBlobTier() != null || properties.getStandardBlobTier() != null) {
158+
properties.setBlobTierInferred(false);
159+
}
157160

158161
final String rehydrationStatusString = request.getHeaderField(BlobConstants.ARCHIVE_STATUS_HEADER);
159162
if (!Utility.isNullOrEmpty(rehydrationStatusString)) {
@@ -164,6 +167,11 @@ else if (!standardBlobTier.equals(StandardBlobTier.UNKNOWN)) {
164167
properties.setRehydrationStatus(null);
165168
}
166169

170+
final long tierChangeTime = request.getHeaderFieldDate(BlobConstants.ACCESS_TIER_CHANGE_TIME_HEADER, 0);
171+
if (tierChangeTime != 0) {
172+
properties.setTierChangeTime(new Date(tierChangeTime));
173+
}
174+
167175
final String incrementalCopyHeaderString =
168176
request.getHeaderField(Constants.HeaderConstants.INCREMENTAL_COPY);
169177
if (!Utility.isNullOrEmpty(incrementalCopyHeaderString)) {

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,7 +2626,9 @@ public Void preProcessResponse(CloudBlob blob, CloudBlobClient client, Operation
26262626

26272627
blob.updateEtagAndLastModifiedFromResponse(this.getConnection());
26282628
this.getResult().setRequestServiceEncrypted(BaseResponse.isServerRequestEncrypted(this.getConnection()));
2629+
26292630
blob.getProperties().setBlobTierInferred(false);
2631+
26302632
if (blob.getProperties().getBlobType() == BlobType.BLOCK_BLOB) {
26312633
// For standard accounts when rehydrating a blob from archive, the status code will be 202 instead of 200.
26322634
StandardBlobTier standardBlobTier = StandardBlobTier.parse(blobTierString);

0 commit comments

Comments
 (0)