Search in sources :

Example 11 with FunctionInvocationTargetException

use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.

the class MemberCommands method describeMember.

@CliCommand(value = { CliStrings.DESCRIBE_MEMBER }, help = CliStrings.DESCRIBE_MEMBER__HELP)
@CliMetaData(shellOnly = false, relatedTopic = CliStrings.TOPIC_GEODE_SERVER)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeMember(@CliOption(key = CliStrings.DESCRIBE_MEMBER__IDENTIFIER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.DESCRIBE_MEMBER__HELP, mandatory = true) String memberNameOrId) {
    Result result = null;
    try {
        DistributedMember memberToBeDescribed = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
        if (memberToBeDescribed != null) {
            // This information should be available through the MBeans too. We might not need
            // the function.
            // Yes, but then the command is subject to Mbean availability, which would be
            // affected once MBean filters are used.
            ResultCollector<?, ?> rc = CliUtil.executeFunction(getMemberInformation, null, memberToBeDescribed);
            ArrayList<?> output = (ArrayList<?>) rc.getResult();
            Object obj = output.get(0);
            if (obj != null && (obj instanceof MemberInformation)) {
                CompositeResultData crd = ResultBuilder.createCompositeResultData();
                MemberInformation memberInformation = (MemberInformation) obj;
                memberInformation.setName(memberToBeDescribed.getName());
                memberInformation.setId(memberToBeDescribed.getId());
                memberInformation.setHost(memberToBeDescribed.getHost());
                memberInformation.setProcessId("" + memberToBeDescribed.getProcessId());
                SectionResultData section = crd.addSection();
                section.addData("Name", memberInformation.getName());
                section.addData("Id", memberInformation.getId());
                section.addData("Host", memberInformation.getHost());
                section.addData("Regions", CliUtil.convertStringSetToString(memberInformation.getHostedRegions(), '\n'));
                section.addData("PID", memberInformation.getProcessId());
                section.addData("Groups", memberInformation.getGroups());
                section.addData("Used Heap", memberInformation.getHeapUsage() + "M");
                section.addData("Max Heap", memberInformation.getMaxHeapSize() + "M");
                String offHeapMemorySize = memberInformation.getOffHeapMemorySize();
                if (offHeapMemorySize != null && !offHeapMemorySize.isEmpty()) {
                    section.addData("Off Heap Size", offHeapMemorySize);
                }
                section.addData("Working Dir", memberInformation.getWorkingDirPath());
                section.addData("Log file", memberInformation.getLogFilePath());
                section.addData("Locators", memberInformation.getLocators());
                if (memberInformation.isServer()) {
                    SectionResultData clientServiceSection = crd.addSection();
                    List<CacheServerInfo> csList = memberInformation.getCacheServeInfo();
                    if (csList != null) {
                        Iterator<CacheServerInfo> iters = csList.iterator();
                        clientServiceSection.setHeader("Cache Server Information");
                        while (iters.hasNext()) {
                            CacheServerInfo cacheServerInfo = iters.next();
                            clientServiceSection.addData("Server Bind", cacheServerInfo.getBindAddress());
                            clientServiceSection.addData("Server Port", cacheServerInfo.getPort());
                            clientServiceSection.addData("Running", cacheServerInfo.isRunning());
                        }
                        clientServiceSection.addData("Client Connections", memberInformation.getClientCount());
                    }
                }
                result = ResultBuilder.buildResult(crd);
            } else {
                result = ResultBuilder.createInfoResult(CliStrings.format(CliStrings.DESCRIBE_MEMBER__MSG__INFO_FOR__0__COULD_NOT_BE_RETRIEVED, new Object[] { memberNameOrId }));
            }
        } else {
            result = ResultBuilder.createInfoResult(CliStrings.format(CliStrings.DESCRIBE_MEMBER__MSG__NOT_FOUND, new Object[] { memberNameOrId }));
        }
    } catch (CacheClosedException e) {
    } catch (FunctionInvocationTargetException e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) ArrayList(java.util.ArrayList) CacheClosedException(org.apache.geode.cache.CacheClosedException) CacheServerInfo(org.apache.geode.management.internal.cli.domain.CacheServerInfo) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) Result(org.apache.geode.management.cli.Result) MemberInformation(org.apache.geode.management.internal.cli.domain.MemberInformation) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 12 with FunctionInvocationTargetException

use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.

the class CommitFunction method execute.

public void execute(FunctionContext context) {
    Cache cache = CacheFactory.getAnyInstance();
    TXId txId = null;
    try {
        txId = (TXId) context.getArguments();
    } catch (ClassCastException e) {
        logger.info("CommitFunction should be invoked with a TransactionId as an argument i.e. setArguments(txId).execute(function)");
        throw e;
    }
    DistributedMember member = txId.getMemberId();
    Boolean result = false;
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (cache.getDistributedSystem().getDistributedMember().equals(member)) {
        if (isDebugEnabled) {
            logger.debug("CommitFunction: for transaction: {} committing locally", txId);
        }
        CacheTransactionManager txMgr = cache.getCacheTransactionManager();
        if (txMgr.tryResume(txId)) {
            if (isDebugEnabled) {
                logger.debug("CommitFunction: resumed transaction: {}", txId);
            }
            txMgr.commit();
            result = true;
        }
    } else {
        ArrayList args = new ArrayList();
        args.add(txId);
        args.add(NestedTransactionFunction.COMMIT);
        Execution ex = FunctionService.onMember(member).setArguments(args);
        if (isDebugEnabled) {
            logger.debug("CommitFunction: for transaction: {} executing NestedTransactionFunction on member: {}", txId, member);
        }
        try {
            List list = (List) ex.execute(new NestedTransactionFunction()).getResult();
            result = (Boolean) list.get(0);
        } catch (FunctionException fe) {
            if (fe.getCause() instanceof FunctionInvocationTargetException) {
                throw new TransactionDataNodeHasDepartedException("Could not commit on member:" + member);
            } else {
                throw fe;
            }
        }
    }
    if (isDebugEnabled) {
        logger.debug("CommitFunction: for transaction: {} returning result: {}", txId, result);
    }
    context.getResultSender().lastResult(result);
}
Also used : ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException) Execution(org.apache.geode.cache.execute.Execution) TXId(org.apache.geode.internal.cache.TXId) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ArrayList(java.util.ArrayList) List(java.util.List) Cache(org.apache.geode.cache.Cache)

Example 13 with FunctionInvocationTargetException

use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.

the class MemberFunctionExecutionDUnitTest method testOnMembersWithoutCache.

@Test
public void testOnMembersWithoutCache() throws Exception {
    DistributedMember member1Id = (DistributedMember) member1.invoke(new SerializableCallable() {

        @Override
        public Object call() {
            disconnectFromDS();
            return getSystem().getDistributedMember();
        }
    });
    member2.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            getSystem();
            ResultCollector<?, ?> rc = FunctionService.onMember(member1Id).execute(new FunctionAdapter() {

                @Override
                public String getId() {
                    return getClass().getName();
                }

                @Override
                public void execute(FunctionContext context) {
                    // This will throw an exception because the cache is not yet created.
                    CacheFactory.getAnyInstance();
                }
            });
            try {
                rc.getResult(30, TimeUnit.SECONDS);
                fail("Should have seen an exception");
            } catch (Exception e) {
                if (!(e.getCause() instanceof FunctionInvocationTargetException)) {
                    Assert.fail("failed", e);
                }
            }
        }
    });
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) ResultCollector(org.apache.geode.cache.execute.ResultCollector) FunctionContext(org.apache.geode.cache.execute.FunctionContext) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 14 with FunctionInvocationTargetException

use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testP2PMemberFailure.

@Test
public void testP2PMemberFailure() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final String regionName = getName();
    initVM(vm0, "g0,mg", regionName, false);
    initVM(vm1, "g1", regionName, false);
    initVM(vm2, "g0,g1,g2", regionName, false);
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            DistributedSystem ds = getSystem();
            Execution e1 = FunctionService.onMembers("g1");
            ArrayList<String> args = new ArrayList<String>();
            args.add("shutdown");
            e1 = e1.setArguments(args);
            try {
                e1.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof FunctionInvocationTargetException);
            }
            return null;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) Host(org.apache.geode.test.dunit.Host) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Execution(org.apache.geode.cache.execute.Execution) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 15 with FunctionInvocationTargetException

use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testP2POneMemberFailure.

@Test
public void testP2POneMemberFailure() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final String regionName = getName();
    initVM(vm0, "g0,mg", regionName, false);
    initVM(vm1, "g1", regionName, false);
    initVM(vm2, "g0,g1,g2", regionName, false);
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            DistributedSystem ds = getSystem();
            Execution e1 = FunctionService.onMembers("g1");
            ArrayList<String> args = new ArrayList<String>();
            args.add("shutdown");
            args.add("g2");
            e1 = e1.setArguments(args);
            try {
                e1.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof FunctionInvocationTargetException);
            }
            return null;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) Host(org.apache.geode.test.dunit.Host) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Execution(org.apache.geode.cache.execute.Execution) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)36 ArrayList (java.util.ArrayList)20 FunctionException (org.apache.geode.cache.execute.FunctionException)19 CacheClosedException (org.apache.geode.cache.CacheClosedException)16 ResultCollector (org.apache.geode.cache.execute.ResultCollector)13 Execution (org.apache.geode.cache.execute.Execution)11 Region (org.apache.geode.cache.Region)10 List (java.util.List)9 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)9 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)9 IOException (java.io.IOException)8 HashSet (java.util.HashSet)8 DistributedMember (org.apache.geode.distributed.DistributedMember)8 CliMetaData (org.apache.geode.management.cli.CliMetaData)8 Result (org.apache.geode.management.cli.Result)7 IgnoredException (org.apache.geode.test.dunit.IgnoredException)7 AbstractExecution (org.apache.geode.internal.cache.execute.AbstractExecution)6 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)6 Test (org.junit.Test)6 CliCommand (org.springframework.shell.core.annotation.CliCommand)6