Skip to content

Allow updating Object Storage Details #10551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@
@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;


/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
Expand All @@ -61,6 +73,24 @@
return url;
}

public String getProviderName() {
return providerName;
}

Check warning on line 78 in api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmd.java#L76-L78

Added lines #L76 - L78 were not covered by tests

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;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand All @@ -69,7 +99,7 @@
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 @@
return driver.listBuckets(objectStoreVO.getId());
}

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

Check warning on line 166 in engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/store/ObjectStoreImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/store/ObjectStoreImpl.java#L164-L166

Added lines #L164 - L166 were not covered by tests

/*
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 @@
return bucketsList;
}

@Override
public void verifyServiceConnectivity(long storeId) {

Check warning on line 142 in plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/driver/CephObjectStoreDriverImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/driver/CephObjectStoreDriverImpl.java#L142

Added line #L142 was not covered by tests
// ideally just ping the storage using credentials. listBuckets() for now.
listBuckets(storeId);
}

Check warning on line 145 in plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/driver/CephObjectStoreDriverImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/object/ceph/src/main/java/org/apache/cloudstack/storage/datastore/driver/CephObjectStoreDriverImpl.java#L144-L145

Added lines #L144 - L145 were not covered by tests

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