Skip to content

Commit 1644642

Browse files
committed
object store: Introduce BucketTO
Introduce the BucketTO to pass to the drivers. This replaces just passing the bucket's name. Some upcoming drivers require more information then just the bucket name to perform their actions, for example they require the access and secret key which belong to the account of this bucket.
1 parent 4d370a3 commit 1644642

8 files changed

Lines changed: 121 additions & 72 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.agent.api.to;
18+
19+
import org.apache.cloudstack.storage.object.Bucket;
20+
21+
public final class BucketTO {
22+
23+
private String name;
24+
25+
public BucketTO(Bucket bucket) {
26+
this.name = bucket.getName();
27+
}
28+
29+
public BucketTO(String name) {
30+
this.name = name;
31+
}
32+
33+
public String getName() {
34+
return this.name;
35+
}
36+
}

engine/api/src/main/java/org/apache/cloudstack/storage/object/ObjectStoreEntity.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.cloudstack.storage.object;
2020

21+
import com.cloud.agent.api.to.BucketTO;
2122
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
2223

2324
import java.util.List;
@@ -30,19 +31,19 @@ public interface ObjectStoreEntity extends DataStore, ObjectStore {
3031

3132
boolean createUser(long accountId);
3233

33-
boolean deleteBucket(String name);
34+
boolean deleteBucket(BucketTO bucket);
3435

35-
boolean setBucketEncryption(String name);
36+
boolean setBucketEncryption(BucketTO bucket);
3637

37-
boolean deleteBucketEncryption(String name);
38+
boolean deleteBucketEncryption(BucketTO bucket);
3839

39-
boolean setBucketVersioning(String name);
40+
boolean setBucketVersioning(BucketTO bucket);
4041

41-
boolean deleteBucketVersioning(String name);
42+
boolean deleteBucketVersioning(BucketTO bucket);
4243

43-
void setBucketPolicy(String name, String policy);
44+
void setBucketPolicy(BucketTO bucket, String policy);
4445

45-
void setQuota(String name, int quota);
46+
void setQuota(BucketTO bucket, int quota);
4647

4748
Map<String, Long> getAllBucketsUsage();
4849
}

engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/store/ObjectStoreImpl.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.cloudstack.storage.object.store;
2020

21+
import com.cloud.agent.api.to.BucketTO;
2122
import com.cloud.agent.api.to.DataStoreTO;
2223
import org.apache.cloudstack.storage.object.Bucket;
2324
import com.cloud.storage.DataStoreRole;
@@ -109,38 +110,38 @@ public Bucket createBucket(Bucket bucket, boolean objectLock) {
109110
}
110111

111112
@Override
112-
public boolean deleteBucket(String bucketName) {
113-
return driver.deleteBucket(bucketName, objectStoreVO.getId());
113+
public boolean deleteBucket(BucketTO bucket) {
114+
return driver.deleteBucket(bucket, objectStoreVO.getId());
114115
}
115116

116117
@Override
117-
public boolean setBucketEncryption(String bucketName) {
118-
return driver.setBucketEncryption(bucketName, objectStoreVO.getId());
118+
public boolean setBucketEncryption(BucketTO bucket) {
119+
return driver.setBucketEncryption(bucket, objectStoreVO.getId());
119120
}
120121

121122
@Override
122-
public boolean deleteBucketEncryption(String bucketName) {
123-
return driver.deleteBucketEncryption(bucketName, objectStoreVO.getId());
123+
public boolean deleteBucketEncryption(BucketTO bucket) {
124+
return driver.deleteBucketEncryption(bucket, objectStoreVO.getId());
124125
}
125126

126127
@Override
127-
public boolean setBucketVersioning(String bucketName) {
128-
return driver.setBucketVersioning(bucketName, objectStoreVO.getId());
128+
public boolean setBucketVersioning(BucketTO bucket) {
129+
return driver.setBucketVersioning(bucket, objectStoreVO.getId());
129130
}
130131

131132
@Override
132-
public boolean deleteBucketVersioning(String bucketName) {
133-
return driver.deleteBucketVersioning(bucketName, objectStoreVO.getId());
133+
public boolean deleteBucketVersioning(BucketTO bucket) {
134+
return driver.deleteBucketVersioning(bucket, objectStoreVO.getId());
134135
}
135136

136137
@Override
137-
public void setBucketPolicy(String bucketName, String policy) {
138-
driver.setBucketPolicy(bucketName, policy, objectStoreVO.getId());
138+
public void setBucketPolicy(BucketTO bucket, String policy) {
139+
driver.setBucketPolicy(bucket, policy, objectStoreVO.getId());
139140
}
140141

141142
@Override
142-
public void setQuota(String bucketName, int quota) {
143-
driver.setBucketQuota(bucketName, objectStoreVO.getId(), quota);
143+
public void setQuota(BucketTO bucket, int quota) {
144+
driver.setBucketQuota(bucket, objectStoreVO.getId(), quota);
144145
}
145146

146147
@Override

engine/storage/src/main/java/org/apache/cloudstack/storage/object/ObjectStoreDriver.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.amazonaws.services.s3.model.AccessControlList;
2222
import com.amazonaws.services.s3.model.BucketPolicy;
23+
import com.cloud.agent.api.to.BucketTO;
2324
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
2425

2526
import java.util.List;
@@ -30,30 +31,30 @@ public interface ObjectStoreDriver extends DataStoreDriver {
3031

3132
List<Bucket> listBuckets(long storeId);
3233

33-
boolean deleteBucket(String bucketName, long storeId);
34+
boolean deleteBucket(BucketTO bucket, long storeId);
3435

35-
AccessControlList getBucketAcl(String bucketName, long storeId);
36+
AccessControlList getBucketAcl(BucketTO bucket, long storeId);
3637

37-
void setBucketAcl(String bucketName, AccessControlList acl, long storeId);
38+
void setBucketAcl(BucketTO bucket, AccessControlList acl, long storeId);
3839

39-
void setBucketPolicy(String bucketName, String policyType, long storeId);
40+
void setBucketPolicy(BucketTO bucket, String policyType, long storeId);
4041

41-
BucketPolicy getBucketPolicy(String bucketName, long storeId);
42+
BucketPolicy getBucketPolicy(BucketTO bucket, long storeId);
4243

43-
void deleteBucketPolicy(String bucketName, long storeId);
44+
void deleteBucketPolicy(BucketTO bucket, long storeId);
4445

4546
boolean createUser(long accountId, long storeId);
4647

47-
boolean setBucketEncryption(String bucketName, long storeId);
48+
boolean setBucketEncryption(BucketTO bucket, long storeId);
4849

49-
boolean deleteBucketEncryption(String bucketName, long storeId);
50+
boolean deleteBucketEncryption(BucketTO bucket, long storeId);
5051

5152

52-
boolean setBucketVersioning(String bucketName, long storeId);
53+
boolean setBucketVersioning(BucketTO bucket, long storeId);
5354

54-
boolean deleteBucketVersioning(String bucketName, long storeId);
55+
boolean deleteBucketVersioning(BucketTO bucket, long storeId);
5556

56-
void setBucketQuota(String bucketName, long storeId, long size);
57+
void setBucketQuota(BucketTO bucket, long storeId, long size);
5758

5859
Map<String, Long> getAllBucketsUsage(long storeId);
5960
}

plugins/storage/object/minio/src/main/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImpl.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import com.amazonaws.services.s3.model.AccessControlList;
4444
import com.amazonaws.services.s3.model.BucketPolicy;
45+
import com.cloud.agent.api.to.BucketTO;
4546
import com.cloud.agent.api.to.DataStoreTO;
4647
import com.cloud.storage.BucketVO;
4748
import com.cloud.storage.dao.BucketDao;
@@ -182,7 +183,8 @@ public List<Bucket> listBuckets(long storeId) {
182183
}
183184

184185
@Override
185-
public boolean deleteBucket(String bucketName, long storeId) {
186+
public boolean deleteBucket(BucketTO bucket, long storeId) {
187+
String bucketName = bucket.getName();
186188
MinioClient minioClient = getMinIOClient(storeId);
187189
try {
188190
if(!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) {
@@ -201,17 +203,18 @@ public boolean deleteBucket(String bucketName, long storeId) {
201203
}
202204

203205
@Override
204-
public AccessControlList getBucketAcl(String bucketName, long storeId) {
206+
public AccessControlList getBucketAcl(BucketTO bucket, long storeId) {
205207
return null;
206208
}
207209

208210
@Override
209-
public void setBucketAcl(String bucketName, AccessControlList acl, long storeId) {
211+
public void setBucketAcl(BucketTO bucket, AccessControlList acl, long storeId) {
210212

211213
}
212214

213215
@Override
214-
public void setBucketPolicy(String bucketName, String policy, long storeId) {
216+
public void setBucketPolicy(BucketTO bucket, String policy, long storeId) {
217+
String bucketName = bucket.getName();
215218
String privatePolicy = "{\"Version\":\"2012-10-17\",\"Statement\":[]}";
216219

217220
StringBuilder builder = new StringBuilder();
@@ -251,12 +254,12 @@ public void setBucketPolicy(String bucketName, String policy, long storeId) {
251254
}
252255

253256
@Override
254-
public BucketPolicy getBucketPolicy(String bucketName, long storeId) {
257+
public BucketPolicy getBucketPolicy(BucketTO bucket, long storeId) {
255258
return null;
256259
}
257260

258261
@Override
259-
public void deleteBucketPolicy(String bucketName, long storeId) {
262+
public void deleteBucketPolicy(BucketTO bucket, long storeId) {
260263

261264
}
262265

@@ -326,11 +329,11 @@ public boolean createUser(long accountId, long storeId) {
326329
}
327330

328331
@Override
329-
public boolean setBucketEncryption(String bucketName, long storeId) {
332+
public boolean setBucketEncryption(BucketTO bucket, long storeId) {
330333
MinioClient minioClient = getMinIOClient(storeId);
331334
try {
332335
minioClient.setBucketEncryption(SetBucketEncryptionArgs.builder()
333-
.bucket(bucketName)
336+
.bucket(bucket.getName())
334337
.config(SseConfiguration.newConfigWithSseS3Rule())
335338
.build()
336339
);
@@ -341,11 +344,11 @@ public boolean setBucketEncryption(String bucketName, long storeId) {
341344
}
342345

343346
@Override
344-
public boolean deleteBucketEncryption(String bucketName, long storeId) {
347+
public boolean deleteBucketEncryption(BucketTO bucket, long storeId) {
345348
MinioClient minioClient = getMinIOClient(storeId);
346349
try {
347350
minioClient.deleteBucketEncryption(DeleteBucketEncryptionArgs.builder()
348-
.bucket(bucketName)
351+
.bucket(bucket.getName())
349352
.build()
350353
);
351354
} catch (Exception e) {
@@ -355,11 +358,11 @@ public boolean deleteBucketEncryption(String bucketName, long storeId) {
355358
}
356359

357360
@Override
358-
public boolean setBucketVersioning(String bucketName, long storeId) {
361+
public boolean setBucketVersioning(BucketTO bucket, long storeId) {
359362
MinioClient minioClient = getMinIOClient(storeId);
360363
try {
361364
minioClient.setBucketVersioning(SetBucketVersioningArgs.builder()
362-
.bucket(bucketName)
365+
.bucket(bucket.getName())
363366
.config(new VersioningConfiguration(VersioningConfiguration.Status.ENABLED, null))
364367
.build()
365368
);
@@ -370,11 +373,11 @@ public boolean setBucketVersioning(String bucketName, long storeId) {
370373
}
371374

372375
@Override
373-
public boolean deleteBucketVersioning(String bucketName, long storeId) {
376+
public boolean deleteBucketVersioning(BucketTO bucket, long storeId) {
374377
MinioClient minioClient = getMinIOClient(storeId);
375378
try {
376379
minioClient.setBucketVersioning(SetBucketVersioningArgs.builder()
377-
.bucket(bucketName)
380+
.bucket(bucket.getName())
378381
.config(new VersioningConfiguration(VersioningConfiguration.Status.SUSPENDED, null))
379382
.build()
380383
);
@@ -385,11 +388,11 @@ public boolean deleteBucketVersioning(String bucketName, long storeId) {
385388
}
386389

387390
@Override
388-
public void setBucketQuota(String bucketName, long storeId, long size) {
391+
public void setBucketQuota(BucketTO bucket, long storeId, long size) {
389392

390393
MinioAdminClient minioAdminClient = getMinIOAdminClient(storeId);
391394
try {
392-
minioAdminClient.setBucketQuota(bucketName, size, QuotaUnit.GB);
395+
minioAdminClient.setBucketQuota(bucket.getName(), size, QuotaUnit.GB);
393396
} catch (Exception e) {
394397
throw new CloudRuntimeException(e);
395398
}

plugins/storage/object/minio/src/test/java/org/apache/cloudstack/storage/datastore/driver/MinIOObjectStoreDriverImplTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.cloudstack.storage.datastore.db.ObjectStoreDetailsDao;
3838
import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO;
3939
import org.apache.cloudstack.storage.object.Bucket;
40+
import com.cloud.agent.api.to.BucketTO;
4041
import org.junit.Before;
4142
import org.junit.Test;
4243
import org.junit.runner.RunWith;
@@ -120,10 +121,11 @@ public void testCreateBucket() throws Exception {
120121
@Test
121122
public void testDeleteBucket() throws Exception {
122123
String bucketName = "test-bucket";
124+
BucketTO bucket = new BucketTO(bucketName);
123125
doReturn(minioClient).when(minioObjectStoreDriverImpl).getMinIOClient(anyLong());
124126
when(minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())).thenReturn(true);
125127
doNothing().when(minioClient).removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
126-
boolean success = minioObjectStoreDriverImpl.deleteBucket(bucketName, 1L);
128+
boolean success = minioObjectStoreDriverImpl.deleteBucket(bucket, 1L);
127129
assertTrue(success);
128130
verify(minioClient, times(1)).bucketExists(any());
129131
verify(minioClient, times(1)).removeBucket(any());

0 commit comments

Comments
 (0)