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