Search in sources :

Example 1 with DiskStoreNotFoundException

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);
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) DiskStoreNotFoundException(org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) DescribeDiskStoreFunction(org.apache.geode.management.internal.cli.functions.DescribeDiskStoreFunction)

Example 2 with DiskStoreNotFoundException

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);
    }
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) DistributedMember(org.apache.geode.distributed.DistributedMember) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) InternalCache(org.apache.geode.internal.cache.InternalCache) DiskStoreNotFoundException(org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException) DiskStoreNotFoundException(org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException) InternalCache(org.apache.geode.internal.cache.InternalCache) Cache(org.apache.geode.cache.Cache)

Example 3 with DiskStoreNotFoundException

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;
    }
}
Also used : Expectations(org.jmock.Expectations) Execution(org.apache.geode.cache.execute.Execution) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) DiskStoreNotFoundException(org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException) DescribeDiskStoreFunction(org.apache.geode.management.internal.cli.functions.DescribeDiskStoreFunction) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

DistributedMember (org.apache.geode.distributed.DistributedMember)3 DiskStoreNotFoundException (org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException)3 InternalCache (org.apache.geode.internal.cache.InternalCache)2 DiskStoreDetails (org.apache.geode.management.internal.cli.domain.DiskStoreDetails)2 DescribeDiskStoreFunction (org.apache.geode.management.internal.cli.functions.DescribeDiskStoreFunction)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Cache (org.apache.geode.cache.Cache)1 DiskStore (org.apache.geode.cache.DiskStore)1 Execution (org.apache.geode.cache.execute.Execution)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 AbstractExecution (org.apache.geode.internal.cache.execute.AbstractExecution)1 UnitTest (org.apache.geode.test.junit.categories.UnitTest)1 Expectations (org.jmock.Expectations)1 Test (org.junit.Test)1