-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCreateBucketRequest.java
More file actions
executable file
·259 lines (224 loc) · 9.81 KB
/
CreateBucketRequest.java
File metadata and controls
executable file
·259 lines (224 loc) · 9.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
* Copyright (c) 2015, EMC Corporation.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* + Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* + The name of EMC Corporation may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.emc.object.s3.request;
import com.emc.object.Method;
import com.emc.object.s3.S3Constants;
import com.emc.object.s3.bean.AccessControlList;
import com.emc.object.s3.bean.CannedAcl;
import com.emc.object.s3.bean.MetadataSearchKey;
import com.emc.object.util.RestUtil;
import java.util.List;
import java.util.Map;
/**
* Encapsulates parameters for a create bucket request.
*/
public class CreateBucketRequest extends AbstractBucketRequest {
private CannedAcl cannedAcl;
private AccessControlList acl;
private String vPoolId;
private Boolean fileSystemEnabled;
private Boolean fileSystemEnabledOnADO;
private Boolean staleReadAllowed;
private Boolean encryptionEnabled;
private Long retentionPeriod;
private String metadataSearchKeys;
private boolean objectLockEnabled = false;
public CreateBucketRequest(String bucketName) {
super(Method.PUT, bucketName, "", null);
}
@Override
public Map<String, List<Object>> getHeaders() {
Map<String, List<Object>> headers = super.getHeaders();
if (cannedAcl != null) RestUtil.putSingle(headers, S3Constants.AMZ_ACL, cannedAcl.getHeaderValue());
if (acl != null) headers.putAll(acl.toHeaders());
if (vPoolId != null) RestUtil.putSingle(headers, RestUtil.EMC_VPOOL, vPoolId);
if (fileSystemEnabled != null) RestUtil.putSingle(headers, RestUtil.EMC_FS_ENABLED, fileSystemEnabled);
if (fileSystemEnabledOnADO != null) {
RestUtil.putSingle(headers, RestUtil.EMC_FS_ENABLED, fileSystemEnabledOnADO);
RestUtil.add(headers, RestUtil.EMC_TSO_READONLY, Boolean.TRUE);
}
if (staleReadAllowed != null) RestUtil.putSingle(headers, RestUtil.EMC_STALE_READ_ALLOWED, staleReadAllowed);
if (encryptionEnabled != null) RestUtil.putSingle(headers, RestUtil.EMC_ENCRYPTION_ENABLED, encryptionEnabled);
if (retentionPeriod != null) RestUtil.putSingle(headers, RestUtil.EMC_RETENTION_PERIOD, retentionPeriod);
if (metadataSearchKeys != null) RestUtil.putSingle(headers, RestUtil.EMC_METADATA_SEARCH, metadataSearchKeys);
if (objectLockEnabled) RestUtil.putSingle(headers, S3Constants.AMZ_BUCKET_OBJECT_LOCK_ENABLED, objectLockEnabled);
return headers;
}
public CannedAcl getCannedAcl() {
return cannedAcl;
}
public void setCannedAcl(CannedAcl cannedAcl) {
this.cannedAcl = cannedAcl;
}
public AccessControlList getAcl() {
return acl;
}
public void setAcl(AccessControlList acl) {
this.acl = acl;
}
public String getvPoolId() {
return vPoolId;
}
public void setvPoolId(String vPoolId) {
this.vPoolId = vPoolId;
}
public Boolean getFileSystemEnabled() {
return fileSystemEnabled;
}
public Boolean getFileSystemEnabledOnADO() {
return fileSystemEnabledOnADO;
}
/**
* Sets whether the bucket can be access via filesystem (i.e. HDFS). This will enable some internal semantics for
* directories and may affect other features (i.e.
* {@link com.emc.object.s3.S3Client#setBucketStaleReadAllowed(String, boolean) TSO support})
*/
public void setFileSystemEnabled(Boolean fileSystemEnabled) {
if(this.fileSystemEnabledOnADO != null) this.fileSystemEnabledOnADO = null;
this.fileSystemEnabled = fileSystemEnabled;
}
/**
* Sets whether the bucket can be access via filesystem (i.e. HDFS) using ADO semantics.
* This will enable some internal semantics for directories and may affect other features (i.e.
* {@link com.emc.object.s3.S3Client#setBucketStaleReadAllowed(String, boolean) TSO support})
* Note that this will override any existing file system enabled setting.
*/
public void setFileSystemEnabledOnADO(Boolean fileSystemEnabledOnADO) {
if(this.fileSystemEnabled != null) this.fileSystemEnabled = null;
this.fileSystemEnabledOnADO = fileSystemEnabledOnADO;
}
public Boolean getStaleReadAllowed() {
return staleReadAllowed;
}
/**
* Sets whether stale reads are allowed on the bucket
*
* @see com.emc.object.s3.S3Client#setBucketStaleReadAllowed(String, boolean)
*/
public void setStaleReadAllowed(Boolean staleReadAllowed) {
this.staleReadAllowed = staleReadAllowed;
}
public Boolean getEncryptionEnabled() {
return encryptionEnabled;
}
/**
* Enables transparent server-side encryption (D@RE) on the bucket. This can only be enabled at create time
*/
public void setEncryptionEnabled(Boolean encryptionEnabled) {
this.encryptionEnabled = encryptionEnabled;
}
public Long getRetentionPeriod() {
return retentionPeriod;
}
/**
* Enables a default retention period that will be applied to all objects created in the bucket
*
* @param retentionPeriod The default number of seconds each object will be in retention after creation
*/
public void setRetentionPeriod(Long retentionPeriod) {
this.retentionPeriod = retentionPeriod;
}
/**
* Assigns a list of system- and user-metadata keynames that can be used later in bucket searches
* for the purpose of filtering object lists based querying these keys.
*
* @param metadataSearchKeys The set of keys to index.
*/
public void setMetadataSearchKeys(List<MetadataSearchKey> metadataSearchKeys) {
StringBuilder sb = new StringBuilder();
for(MetadataSearchKey key : metadataSearchKeys) {
if(sb.length() > 0) sb.append(',');
sb.append(key.getName()).append(';').append(key.getDatatype());
}
this.metadataSearchKeys = sb.toString();
}
public boolean getObjectLockEnabled() { return objectLockEnabled; }
/**
* Sets whether S3 Object Lock will be enabled for the new bucket.
*/
public void setObjectLockEnabled(boolean objectLockEnabled) {
this.objectLockEnabled = objectLockEnabled;
}
public CreateBucketRequest withCannedAcl(CannedAcl cannedAcl) {
setCannedAcl(cannedAcl);
return this;
}
public CreateBucketRequest withAcl(AccessControlList acl) {
setAcl(acl);
return this;
}
public CreateBucketRequest withVPoolId(String vPoolId) {
setvPoolId(vPoolId);
return this;
}
/**
* Sets whether the bucket can be accessed via a filesystem (i.e. HDFS) and returns this request object.
*
* This will enable some internal semantics for directories and may affect other features.
* Note that this will override any existing file system enabled with ADO setting.
*
* @param fileSystemEnabled Whether to enable filesystem access on the bucket of non-ADO enabled namespace
* @return this request object
*/
public CreateBucketRequest withFileSystemEnabled(boolean fileSystemEnabled) {
setFileSystemEnabled(fileSystemEnabled);
return this;
}
/**
* Sets whether the bucket can be accessed via a filesystem (i.e. HDFS) using ADO semantics and returns this request object.
*
* This will enable some internal semantics for directories and may affect other features.
* Note that this will override any existing file system enabled setting.
*
* @param fileSystemEnabledOnADO Whether to enable filesystem access via ADO semantics on the bucket of ADO enabled namespace
* @return this request object
*/
public CreateBucketRequest withFileSystemEnabledOnADO(boolean fileSystemEnabledOnADO) {
setFileSystemEnabledOnADO(fileSystemEnabledOnADO);
return this;
}
public CreateBucketRequest withStaleReadAllowed(boolean staleReadAllowed) {
setStaleReadAllowed(staleReadAllowed);
return this;
}
public CreateBucketRequest withEncryptionEnabled(Boolean encryptionEnabled) {
setEncryptionEnabled(encryptionEnabled);
return this;
}
public CreateBucketRequest withRetentionPeriod(long retentionPeriod) {
setRetentionPeriod(retentionPeriod);
return this;
}
public CreateBucketRequest withMetadataSearchKeys(List<MetadataSearchKey> metadataSearchKeys) {
setMetadataSearchKeys(metadataSearchKeys);
return this;
}
public CreateBucketRequest withObjectLockEnabled(boolean objectLockEnabled) {
setObjectLockEnabled(objectLockEnabled);
return this;
}
}