use of org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException in project geode by apache.
the class DiskStoreCommands method getDiskStoreDescription.
protected DiskStoreDetails getDiskStoreDescription(final String memberName, final String diskStoreName) {
// may throw a
final DistributedMember member = getMember(getCache(), memberName);
// MemberNotFoundException
final ResultCollector<?, ?> resultCollector = getMembersFunctionExecutor(Collections.singleton(member)).setArguments(diskStoreName).execute(new DescribeDiskStoreFunction());
final Object result = ((List<?>) resultCollector.getResult()).get(0);
if (result instanceof DiskStoreDetails) {
// disk store details in hand...
return (DiskStoreDetails) result;
} else if (result instanceof DiskStoreNotFoundException) {
// bad disk store name...
throw (DiskStoreNotFoundException) result;
} else {
// unknown and unexpected return type...
final Throwable cause = (result instanceof Throwable ? (Throwable) result : null);
if (isLogging()) {
if (cause != null) {
getGfsh().logSevere(String.format("Exception (%1$s) occurred while executing '%2$s' on member (%3$s) with disk store (%4$s).", ClassUtils.getClassName(cause), CliStrings.DESCRIBE_DISK_STORE, memberName, diskStoreName), cause);
} else {
getGfsh().logSevere(String.format("Received an unexpected result of type (%1$s) while executing '%2$s' on member (%3$s) with disk store (%4$s).", ClassUtils.getClassName(result), CliStrings.DESCRIBE_DISK_STORE, memberName, diskStoreName), null);
}
}
throw new RuntimeException(CliStrings.format(CliStrings.UNEXPECTED_RETURN_TYPE_EXECUTING_COMMAND_ERROR_MESSAGE, ClassUtils.getClassName(result), CliStrings.DESCRIBE_DISK_STORE), cause);
}
}
use of org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException in project geode by apache.
the class DescribeDiskStoreFunction method execute.
public void execute(final FunctionContext context) {
Cache cache = getCache();
try {
if (cache instanceof InternalCache) {
InternalCache gemfireCache = (InternalCache) cache;
DistributedMember member = gemfireCache.getMyId();
String diskStoreName = (String) context.getArguments();
String memberId = member.getId();
String memberName = member.getName();
DiskStore diskStore = gemfireCache.findDiskStore(diskStoreName);
if (diskStore != null) {
DiskStoreDetails diskStoreDetails = new DiskStoreDetails(diskStore.getDiskStoreUUID(), diskStore.getName(), memberId, memberName);
diskStoreDetails.setAllowForceCompaction(diskStore.getAllowForceCompaction());
diskStoreDetails.setAutoCompact(diskStore.getAutoCompact());
diskStoreDetails.setCompactionThreshold(diskStore.getCompactionThreshold());
diskStoreDetails.setMaxOplogSize(diskStore.getMaxOplogSize());
diskStoreDetails.setQueueSize(diskStore.getQueueSize());
diskStoreDetails.setTimeInterval(diskStore.getTimeInterval());
diskStoreDetails.setWriteBufferSize(diskStore.getWriteBufferSize());
diskStoreDetails.setDiskUsageWarningPercentage(diskStore.getDiskUsageWarningPercentage());
diskStoreDetails.setDiskUsageCriticalPercentage(diskStore.getDiskUsageCriticalPercentage());
setDiskDirDetails(diskStore, diskStoreDetails);
setRegionDetails(gemfireCache, diskStore, diskStoreDetails);
setCacheServerDetails(gemfireCache, diskStore, diskStoreDetails);
setGatewayDetails(gemfireCache, diskStore, diskStoreDetails);
setPdxSerializationDetails(gemfireCache, diskStore, diskStoreDetails);
setAsyncEventQueueDetails(gemfireCache, diskStore, diskStoreDetails);
context.getResultSender().lastResult(diskStoreDetails);
} else {
context.getResultSender().sendException(new DiskStoreNotFoundException(String.format("A disk store with name (%1$s) was not found on member (%2$s).", diskStoreName, memberName)));
}
}
} catch (Exception e) {
logger.error("Error occurred while executing 'describe disk-store': {}!", e.getMessage(), e);
context.getResultSender().sendException(e);
}
}
use of org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException in project geode by apache.
the class DiskStoreCommandsJUnitTest method testGetDiskStoreDescriptionThrowsDiskStoreNotFoundException.
@Test(expected = DiskStoreNotFoundException.class)
public void testGetDiskStoreDescriptionThrowsDiskStoreNotFoundException() {
final String diskStoreName = "mockDiskStore";
final String memberId = "mockMember";
final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
final DistributedMember mockMember = mockContext.mock(DistributedMember.class, "DistributedMember");
final Execution mockFunctionExecutor = mockContext.mock(Execution.class, "Function Executor");
mockContext.checking(new Expectations() {
{
oneOf(mockMember).getName();
will(returnValue(null));
oneOf(mockMember).getId();
will(returnValue(memberId));
oneOf(mockFunctionExecutor).setArguments(with(equal(diskStoreName)));
will(returnValue(mockFunctionExecutor));
oneOf(mockFunctionExecutor).execute(with(aNonNull(DescribeDiskStoreFunction.class)));
will(throwException(new DiskStoreNotFoundException("expected")));
}
});
final DiskStoreCommands commands = createDiskStoreCommands(mockCache, mockMember, mockFunctionExecutor);
try {
commands.getDiskStoreDescription(memberId, diskStoreName);
} catch (DiskStoreNotFoundException expected) {
assertEquals("expected", expected.getMessage());
throw expected;
}
}
Aggregations