Skip to content

Commit b8f1149

Browse files
authored
mgmt, storage enabling blob versioning (#29189)
* support toggling blob versioning * session records * change log * fix javadoc * optimize javadoc * changelog, optimize javadoc
1 parent e4b9f41 commit b8f1149

File tree

6 files changed

+340
-279
lines changed

6 files changed

+340
-279
lines changed

sdk/resourcemanager/azure-resourcemanager-storage/CHANGELOG.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
### Features Added
66

7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
7+
- Supported toggling blob versioning in `BlobServiceProperties`.
128

139
## 2.15.0 (2022-05-25)
1410

sdk/resourcemanager/azure-resourcemanager-storage/src/main/java/com/azure/resourcemanager/storage/implementation/BlobServicePropertiesImpl.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
import com.azure.resourcemanager.resources.fluentcore.model.implementation.CreatableUpdatableImpl;
77
import com.azure.resourcemanager.storage.StorageManager;
88
import com.azure.resourcemanager.storage.fluent.BlobServicesClient;
9+
import com.azure.resourcemanager.storage.fluent.models.BlobServicePropertiesInner;
910
import com.azure.resourcemanager.storage.models.BlobServiceProperties;
1011
import com.azure.resourcemanager.storage.models.CorsRule;
1112
import com.azure.resourcemanager.storage.models.CorsRules;
1213
import com.azure.resourcemanager.storage.models.DeleteRetentionPolicy;
13-
import com.azure.resourcemanager.storage.fluent.models.BlobServicePropertiesInner;
14+
import reactor.core.publisher.Mono;
1415

1516
import java.util.ArrayList;
1617
import java.util.List;
17-
import reactor.core.publisher.Mono;
1818

1919
class BlobServicePropertiesImpl
2020
extends CreatableUpdatableImpl<BlobServiceProperties, BlobServicePropertiesInner, BlobServicePropertiesImpl>
@@ -104,6 +104,11 @@ public String type() {
104104
return this.innerModel().type();
105105
}
106106

107+
@Override
108+
public Boolean isBlobVersioningEnabled() {
109+
return this.innerModel().isVersioningEnabled();
110+
}
111+
107112
@Override
108113
public BlobServicePropertiesImpl withExistingStorageAccount(String resourceGroupName, String accountName) {
109114
this.resourceGroupName = resourceGroupName;
@@ -155,4 +160,16 @@ public BlobServicePropertiesImpl withDeleteRetentionPolicyDisabled() {
155160
this.innerModel().withDeleteRetentionPolicy(new DeleteRetentionPolicy().withEnabled(false));
156161
return this;
157162
}
163+
164+
@Override
165+
public BlobServicePropertiesImpl withBlobVersioningEnabled() {
166+
this.innerModel().withIsVersioningEnabled(true);
167+
return this;
168+
}
169+
170+
@Override
171+
public BlobServicePropertiesImpl withBlobVersioningDisabled() {
172+
this.innerModel().withIsVersioningEnabled(false);
173+
return this;
174+
}
158175
}

sdk/resourcemanager/azure-resourcemanager-storage/src/main/java/com/azure/resourcemanager/storage/models/BlobServiceProperties.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public interface BlobServiceProperties
4141
/** @return the type value. */
4242
String type();
4343

44+
/** @return whether blob versioning is enabled */
45+
Boolean isBlobVersioningEnabled();
46+
4447
/** The entirety of the BlobServiceProperties definition. */
4548
interface Definition
4649
extends DefinitionStages.Blank, DefinitionStages.WithStorageAccount, DefinitionStages.WithCreate {
@@ -127,6 +130,17 @@ interface WithDeleteRetentionPolicy {
127130
WithCreate withDeleteRetentionPolicyDisabled();
128131
}
129132

133+
/** The stage of the blobserviceproperties definition allowing to enable/disable blob versioning. */
134+
interface WithBlobVersioning {
135+
/**
136+
* Enables blob versioning.
137+
* <p>When blob versioning is enabled, you can access earlier versions of a blob to recover your data
138+
* if it is modified or deleted.</p>
139+
* @return the next definition stage
140+
*/
141+
WithCreate withBlobVersioningEnabled();
142+
}
143+
130144
/**
131145
* The stage of the definition which contains all the minimum required inputs for the resource to be created
132146
* (via {@link WithCreate#create()}), but also allows for any other optional settings to be specified.
@@ -135,15 +149,17 @@ interface WithCreate
135149
extends Creatable<BlobServiceProperties>,
136150
DefinitionStages.WithCors,
137151
DefinitionStages.WithDefaultServiceVersion,
138-
DefinitionStages.WithDeleteRetentionPolicy {
152+
DefinitionStages.WithDeleteRetentionPolicy,
153+
DefinitionStages.WithBlobVersioning {
139154
}
140155
}
141156
/** The template for a BlobServiceProperties update operation, containing all the settings that can be modified. */
142157
interface Update
143158
extends Appliable<BlobServiceProperties>,
144159
UpdateStages.WithCors,
145160
UpdateStages.WithDefaultServiceVersion,
146-
UpdateStages.WithDeleteRetentionPolicy {
161+
UpdateStages.WithDeleteRetentionPolicy,
162+
UpdateStages.WithBlobVersioning {
147163
}
148164

149165
/** Grouping of BlobServiceProperties update stages. */
@@ -208,5 +224,28 @@ interface WithDeleteRetentionPolicy {
208224
*/
209225
Update withDeleteRetentionPolicyDisabled();
210226
}
227+
228+
/** The stage of the blobserviceproperties update allowing to enable/disable blob versioning. */
229+
interface WithBlobVersioning {
230+
/**
231+
* Enables blob versioning.
232+
* <p>When blob versioning is enabled, you can access earlier versions of a blob to recover your data
233+
* if it is modified or deleted.</p>
234+
* @return the next update stage
235+
*/
236+
Update withBlobVersioningEnabled();
237+
238+
/**
239+
* Disables blob versioning.
240+
* <p>After versioning is disabled, the first time you modify the blob with current version will result in
241+
* creating a new blob that has no version. All subsequent updates will go to this new blob and overwrite
242+
* its data without saving the previous state. All existing versions stay unaffected.</p>
243+
* <p>You can still list a blob's versions after versioning is disabled, or read or delete a specific
244+
* version of the blob using the version ID.
245+
* </p>
246+
* @return the next update stage
247+
*/
248+
Update withBlobVersioningDisabled();
249+
}
211250
}
212251
}

sdk/resourcemanager/azure-resourcemanager-storage/src/test/java/com/azure/resourcemanager/storage/StorageBlobServicesTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ public void canCreateBlobServices() {
4545
.define("blobServicesTest")
4646
.withExistingStorageAccount(storageAccount.resourceGroupName(), storageAccount.name())
4747
.withDeleteRetentionPolicyEnabled(5)
48+
.withBlobVersioningEnabled()
4849
.create();
4950

5051
Assertions.assertTrue(blobService.deleteRetentionPolicy().enabled());
5152
Assertions.assertEquals(5, blobService.deleteRetentionPolicy().days().intValue());
53+
Assertions.assertTrue(blobService.isBlobVersioningEnabled());
5254
}
5355

5456
@Test
@@ -69,10 +71,17 @@ public void canUpdateBlobServices() {
6971
.define("blobServicesTest")
7072
.withExistingStorageAccount(storageAccount.resourceGroupName(), storageAccount.name())
7173
.withDeleteRetentionPolicyEnabled(5)
74+
.withBlobVersioningEnabled()
7275
.create();
7376

74-
blobService.update().withDeleteRetentionPolicyDisabled().apply();
77+
Assertions.assertTrue(blobService.isBlobVersioningEnabled());
78+
79+
blobService.update()
80+
.withDeleteRetentionPolicyDisabled()
81+
.withBlobVersioningDisabled()
82+
.apply();
7583

7684
Assertions.assertFalse(blobService.deleteRetentionPolicy().enabled());
85+
Assertions.assertFalse(blobService.isBlobVersioningEnabled());
7786
}
7887
}

0 commit comments

Comments
 (0)