Skip to content

Commit

Permalink
Disk store rest api (apache#5)
Browse files Browse the repository at this point in the history
* Updating assembly validation txt
Trying to remove disk store folders after test

* Attempt to clear out disk dirs between runs

* Added temporary folder and forced disk dirs to use the absolute path

* Added tests for groups
Prevent removal of disk store from specific groups to be consistent with region api
  • Loading branch information
jhuynh1 authored and jmelchio committed Jun 25, 2020
1 parent 7e5dc04 commit 5f98828
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.commons.lang3.StringUtils;

import org.apache.geode.internal.cache.DiskStoreMonitor;
import org.apache.geode.management.configuration.AbstractConfiguration;
import org.apache.geode.management.configuration.DiskStore;
import org.apache.geode.management.internal.CacheElementOperation;

Expand All @@ -39,6 +40,16 @@ public void validate(CacheElementOperation operation, DiskStore config)
case UPDATE:
checkRequiredItems(config);
checkValueRanges(config);
break;
case DELETE:
validateDelete(config);
}
}

private void validateDelete(AbstractConfiguration config) {
if (StringUtils.isNotBlank(config.getGroup())) {
throw new IllegalArgumentException(
"Group is an invalid option when deleting disk store.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.UnaryOperator;

import org.junit.After;
import org.junit.Before;
Expand All @@ -37,6 +39,7 @@
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.WebApplicationContext;

import org.apache.geode.cache.configuration.CacheConfig;
import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.management.api.ClusterManagementException;
Expand Down Expand Up @@ -80,7 +83,7 @@ public class CreateDiskStoreDUnitTest {
private MemberVM server;

@Before
public void before() {
public void before() throws Exception {
cluster.setSkipLocalDistributedSystemCleanup(true);
webContext = new LocatorWebContext(webApplicationContext);
client = new ClusterManagementServiceBuilder().setTransport(
Expand All @@ -94,16 +97,20 @@ public void before() {
public void after() {
// for the test to be run multiple times, we need to clean out the cluster config
InternalConfigurationPersistenceService cps = getLocator().getConfigurationPersistenceService();
cps.updateCacheConfig("cluster", config -> {
UnaryOperator<CacheConfig> mutator = config -> {
config.getDiskStores().clear();
return config;
});
};

cps.updateCacheConfig("cluster", mutator);
cps.updateCacheConfig("SameGroup", mutator);
cps.updateCacheConfig("OtherGroup", mutator);
if (server != null) {
server.stop(true);
}
}

private DiskStore createDiskStoreConfigObject(String diskStoreName) {
private DiskStore createDiskStoreConfigObject(String diskStoreName) throws IOException {
DiskStore diskStore = new DiskStore();
diskStore.setName(diskStoreName);
DiskDir diskDir = new DiskDir(
Expand Down Expand Up @@ -255,7 +262,7 @@ public void destroyingDiskStoreBeforeDiskStoresActuallyCreatedShouldSucceed() {
}

@Test
public void listDiskStoresShouldReturnAllConfiguredDiskStores() {
public void listDiskStoresShouldReturnAllConfiguredDiskStores() throws Exception {
assertThatThrownBy(() -> client.get(diskStore)).isInstanceOf(ClusterManagementException.class)
.hasMessageContaining("ENTITY_NOT_FOUND");

Expand All @@ -265,9 +272,8 @@ public void listDiskStoresShouldReturnAllConfiguredDiskStores() {
assertThat(client.list(new DiskStore()).getResult().size()).isEqualTo(3);
}


@Test
public void listDiskStoresShouldReturnNonDeletedDiskStores() {
public void listDiskStoresShouldReturnNonDeletedDiskStores() throws Exception {
assertThatThrownBy(() -> client.get(diskStore)).isInstanceOf(ClusterManagementException.class)
.hasMessageContaining("ENTITY_NOT_FOUND");

Expand Down Expand Up @@ -300,4 +306,41 @@ public void cannotRemoveDiskstoreWhileUsedByRegion() {
ClusterManagementRealizationResult deleteResult = client.delete(diskStore);
assertThat(deleteResult.isSuccessful()).isTrue();
}

@Test
public void createDiskStoreOnGroupShouldOnlyExecuteOnServersInThatGroup() throws Exception {
assertThatThrownBy(() -> client.get(diskStore)).isInstanceOf(ClusterManagementException.class)
.hasMessageContaining("ENTITY_NOT_FOUND");

server = cluster.startServerVM(1, "OtherGroup", webContext.getLocator().getPort());

diskStore.setGroup("SameGroup");
ClusterManagementRealizationResult createResult = client.create(diskStore);
assertThat(createResult.getMemberStatuses().size()).isEqualTo(0);
assertThat(client.list(new DiskStore()).getResult().size()).isEqualTo(1);
}

@Test
public void deleteDiskStoreShouldThrowExceptionIfGroupSpecified() throws Exception {
assertThatThrownBy(() -> client.get(diskStore)).isInstanceOf(ClusterManagementException.class)
.hasMessageContaining("ENTITY_NOT_FOUND");

server = cluster.startServerVM(1, "SameGroup", webContext.getLocator().getPort());
diskStore.setGroup("SameGroup");
client.create(diskStore);

assertThatThrownBy(() -> client.delete(diskStore))
.hasMessageContaining(
"ILLEGAL_ARGUMENT: Group is an invalid option when deleting disk store");
}

@Test
public void createDiskStoreByGroupShouldSucceed() throws Exception {
assertThatThrownBy(() -> client.get(diskStore)).isInstanceOf(ClusterManagementException.class)
.hasMessageContaining("ENTITY_NOT_FOUND");

diskStore.setGroup("SameGroup");
client.create(diskStore);
assertThat(client.list(new DiskStore()).getResult().size()).isEqualTo(1);
}
}

0 comments on commit 5f98828

Please sign in to comment.