Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion api/src/main/java/com/cloud/server/ResourceTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public enum ResourceObjectType {
NetworkOffering(false, true),
VpcOffering(true, false),
Domain(false, false, true),
ObjectStore(false, false, true);
ObjectStore(false, true, true);


ResourceObjectType(boolean resourceTagsSupport, boolean resourceMetadataSupport) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
package org.apache.cloudstack.api.command.admin.storage;

import org.apache.cloudstack.storage.object.ObjectStore;

import java.util.HashMap;
import java.util.Map;

import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
Expand All @@ -41,9 +45,17 @@ public class UpdateObjectStoragePoolCmd extends BaseCmd {
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name for the object store")
private String name;

@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, description = "the object store provider name")
private String providerName;

@Parameter(name = ApiConstants.URL, type = CommandType.STRING, description = "the url for the object store")
private String url;

@Parameter(name = ApiConstants.DETAILS,
type = CommandType.MAP,
description = "the details for the object store. Example: details[0].key=accesskey&details[0].value=s389ddssaa&details[1].key=secretkey&details[1].value=8dshfsss")
private Map details;

@Parameter(name = ApiConstants.SIZE, type = CommandType.LONG, description = "the total size of the object store in GiB. Used for tracking capacity and sending alerts. Set to 0 to stop tracking.", since = "4.21")
private Long size;

Expand All @@ -63,6 +75,24 @@ public String getUrl() {
return url;
}

public String getProviderName() {
return providerName;
}

public Map<String, String> getDetails() {
Map<String, String> detailsMap = null;
if (details != null && !details.isEmpty()) {
detailsMap = new HashMap<>();
for (Object prop : details.values()) {
HashMap<String, String> detail = (HashMap<String, String>) prop;
String key = detail.get(ApiConstants.KEY);
String value = detail.get(ApiConstants.VALUE);
detailsMap.put(key, value);
}
}
return detailsMap;
}

Comment thread
DaanHoogland marked this conversation as resolved.
Outdated
public Long getSize() {
return size;
}
Expand All @@ -75,7 +105,7 @@ public Long getSize() {
public void execute() {
ObjectStore result = _storageService.updateObjectStore(getId(), this);

ObjectStoreResponse storeResponse = null;
ObjectStoreResponse storeResponse;
if (result != null) {
storeResponse = _responseGenerator.createObjectStoreResponse(result);
storeResponse.setResponseName(getCommandName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
package org.apache.cloudstack.api.command.admin.storage;

import com.cloud.storage.StorageService;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ResponseGenerator;
import org.apache.cloudstack.api.response.ObjectStoreResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.storage.object.ObjectStore;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
Expand All @@ -32,6 +34,9 @@
import org.mockito.Spy;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.HashMap;
import java.util.Map;

import static org.mockito.ArgumentMatchers.any;

public class UpdateObjectStoragePoolCmdTest {
Expand Down Expand Up @@ -83,4 +88,32 @@ public void testUpdateObjectStore() {
.updateObjectStore(1L, updateObjectStoragePoolCmd);
}

@Test
public void testGetDetailsNone() {
Assert.assertNull(updateObjectStoragePoolCmd.getDetails());
}

@Test
public void testGetDetails() {
// test setup
// Build the "details" Map which has the following format:
// {0={value=value0, key=key0}, 1={value=value1, key=key1}, ...}
Map<String, Object> details = new HashMap<>();
Map<String, String> map0 = new HashMap<>();
map0.put(ApiConstants.KEY, "key0");
map0.put(ApiConstants.VALUE, "value0");
details.put("0", map0);
Map<String, String> map1 = new HashMap<>();
map1.put(ApiConstants.KEY, "key1");
map1.put(ApiConstants.VALUE, "value1");
details.put("1", map1);
ReflectionTestUtils.setField(updateObjectStoragePoolCmd, "details", details);

// Test: getDetails() should return a simple map
Map<String, String> outDetails = updateObjectStoragePoolCmd.getDetails();
Assert.assertNotNull(outDetails);
Assert.assertEquals(2, outDetails.size());
Assert.assertEquals("value0", outDetails.get("key0"));
Assert.assertEquals("value1", outDetails.get("key1"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public interface ObjectStoreEntity extends DataStore, ObjectStore {

List<Bucket> listBuckets();

void verifyServiceConnectivity();

boolean createUser(long accountId);

boolean deleteBucket(BucketTO bucket);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public List<Bucket> listBuckets() {
return driver.listBuckets(objectStoreVO.getId());
}

@Override
public void verifyServiceConnectivity() {
driver.verifyServiceConnectivity(objectStoreVO.getId());
}

/*
Create user if not exists
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.amazonaws.services.s3.model.AccessControlList;
import com.amazonaws.services.s3.model.BucketPolicy;
import com.cloud.agent.api.to.BucketTO;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;

import java.util.List;
Expand All @@ -31,6 +32,13 @@ public interface ObjectStoreDriver extends DataStoreDriver {

List<Bucket> listBuckets(long storeId);

/**
* Verify Service Connectivity by testing the configuration.
* @param storeId identifies which store's configuration to verify.
* @throws CloudRuntimeException if there are any connectivity issues.
*/
void verifyServiceConnectivity(long storeId);

boolean deleteBucket(BucketTO bucket, long storeId);

AccessControlList getBucketAcl(BucketTO bucket, long storeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ public List<Bucket> listBuckets(long storeId) {
return bucketsList;
}

@Override
public void verifyServiceConnectivity(long storeId) {
// ideally just ping the storage using credentials. listBuckets() for now.
listBuckets(storeId);
}

@Override
public boolean deleteBucket(BucketTO bucket, long storeId) {
RgwAdmin rgwAdmin = getRgwAdminClient(storeId);
Expand Down
Loading
Loading