use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class IndexCommandsJUnitTest method testGetIndexListingReturnsFunctionInvocationTargetExceptionInResults.
@Test
public void testGetIndexListingReturnsFunctionInvocationTargetExceptionInResults() {
final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
final AbstractExecution mockFunctionExecutor = mockContext.mock(AbstractExecution.class, "Function Executor");
final ResultCollector mockResultCollector = mockContext.mock(ResultCollector.class, "ResultCollector");
final IndexDetails indexDetails = createIndexDetails("memberOne", "/Employees", "empIdIdx");
final List<IndexDetails> expectedIndexDetails = Arrays.asList(indexDetails);
final List<Object> results = new ArrayList<Object>(2);
results.add(CollectionUtils.asSet(indexDetails));
results.add(new FunctionInvocationTargetException("expected"));
mockContext.checking(new Expectations() {
{
oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class)));
will(returnValue(mockResultCollector));
oneOf(mockResultCollector).getResult();
will(returnValue(results));
}
});
final IndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
final List<IndexDetails> actualIndexDetails = commands.getIndexListing();
assertNotNull(actualIndexDetails);
assertEquals(expectedIndexDetails, actualIndexDetails);
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class LuceneIndexCommands method destroyIndex.
@CliCommand(value = LuceneCliStrings.LUCENE_DESTROY_INDEX, help = LuceneCliStrings.LUCENE_DESTROY_INDEX__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
public Result destroyIndex(@CliOption(key = LuceneCliStrings.LUCENE__INDEX_NAME, help = LuceneCliStrings.LUCENE_DESTROY_INDEX__NAME__HELP) final String indexName, @CliOption(key = LuceneCliStrings.LUCENE__REGION_PATH, mandatory = true, optionContext = ConverterHint.REGION_PATH, help = LuceneCliStrings.LUCENE_DESTROY_INDEX__REGION_HELP) final String regionPath) {
if (StringUtils.isBlank(regionPath) || regionPath.equals(Region.SEPARATOR)) {
return ResultBuilder.createInfoResult(CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__REGION_CANNOT_BE_EMPTY));
}
if (indexName != null && StringUtils.isEmpty(indexName)) {
return ResultBuilder.createInfoResult(CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__INDEX_CANNOT_BE_EMPTY));
}
this.securityService.authorizeRegionManage(regionPath);
Result result;
try {
List<CliFunctionResult> accumulatedResults = new ArrayList<>();
final XmlEntity xmlEntity = executeDestroyIndexFunction(accumulatedResults, indexName, regionPath);
result = getDestroyIndexResult(accumulatedResults, indexName, regionPath);
if (xmlEntity != null) {
persistClusterConfiguration(result, () -> {
// Delete the xml entity to remove the index(es) in all groups
getSharedConfiguration().deleteXmlEntity(xmlEntity, null);
});
}
} catch (FunctionInvocationTargetException ignore) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, LuceneCliStrings.LUCENE_DESTROY_INDEX));
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (IllegalArgumentException e) {
result = ResultBuilder.createInfoResult(e.getMessage());
} catch (Throwable t) {
t.printStackTrace();
SystemFailure.checkFailure();
getCache().getLogger().warning(LuceneCliStrings.LUCENE_DESTROY_INDEX__EXCEPTION_MESSAGE, t);
result = ResultBuilder.createGemFireErrorResult(t.getMessage());
}
return result;
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class LuceneIndexCommands method searchIndex.
@CliCommand(value = LuceneCliStrings.LUCENE_SEARCH_INDEX, help = LuceneCliStrings.LUCENE_SEARCH_INDEX__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
@ResourceOperation(resource = Resource.DATA, operation = Operation.WRITE)
public Result searchIndex(@CliOption(key = LuceneCliStrings.LUCENE__INDEX_NAME, mandatory = true, help = LuceneCliStrings.LUCENE_SEARCH_INDEX__NAME__HELP) final String indexName, @CliOption(key = LuceneCliStrings.LUCENE__REGION_PATH, mandatory = true, optionContext = ConverterHint.REGION_PATH, help = LuceneCliStrings.LUCENE_SEARCH_INDEX__REGION_HELP) final String regionPath, @CliOption(key = LuceneCliStrings.LUCENE_SEARCH_INDEX__QUERY_STRING, mandatory = true, help = LuceneCliStrings.LUCENE_SEARCH_INDEX__QUERY_STRING__HELP) final String queryString, @CliOption(key = LuceneCliStrings.LUCENE_SEARCH_INDEX__DEFAULT_FIELD, mandatory = true, help = LuceneCliStrings.LUCENE_SEARCH_INDEX__DEFAULT_FIELD__HELP) final String defaultField, @CliOption(key = LuceneCliStrings.LUCENE_SEARCH_INDEX__LIMIT, unspecifiedDefaultValue = "-1", help = LuceneCliStrings.LUCENE_SEARCH_INDEX__LIMIT__HELP) final int limit, @CliOption(key = LuceneCliStrings.LUCENE_SEARCH_INDEX__KEYSONLY, unspecifiedDefaultValue = "false", help = LuceneCliStrings.LUCENE_SEARCH_INDEX__KEYSONLY__HELP) boolean keysOnly) {
try {
LuceneQueryInfo queryInfo = new LuceneQueryInfo(indexName, regionPath, queryString, defaultField, limit, keysOnly);
int pageSize = Integer.MAX_VALUE;
searchResults = getSearchResults(queryInfo);
return displayResults(pageSize, keysOnly);
} catch (FunctionInvocationTargetException ignore) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, LuceneCliStrings.LUCENE_SEARCH_INDEX));
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (IllegalArgumentException e) {
return ResultBuilder.createInfoResult(e.getMessage());
} catch (Throwable t) {
SystemFailure.checkFailure();
getCache().getLogger().info(t);
return ResultBuilder.createGemFireErrorResult(String.format(LuceneCliStrings.LUCENE_SEARCH_INDEX__ERROR_MESSAGE, toString(t, isDebugging())));
}
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class FunctionStreamingResultCollector method memberDeparted.
@Override
public void memberDeparted(final InternalDistributedMember id, final boolean crashed) {
if (id != null) {
synchronized (this.members) {
if (removeMember(id, true)) {
FunctionInvocationTargetException fe;
if (execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) {
if (!this.fn.isHA()) {
// need to add LocalizedStrings messages
fe = new FunctionInvocationTargetException(LocalizedStrings.MemberMessage_MEMBERRESPONSE_GOT_MEMBERDEPARTED_EVENT_FOR_0_CRASHED_1.toLocalizedString(new Object[] { id, Boolean.valueOf(crashed) }), id);
} else {
fe = new InternalFunctionInvocationTargetException(LocalizedStrings.DistributionMessage_DISTRIBUTIONRESPONSE_GOT_MEMBERDEPARTED_EVENT_FOR_0_CRASHED_1.toLocalizedString(new Object[] { id, Boolean.valueOf(crashed) }), id);
if (execution.isClientServerMode()) {
if (this.userRC != null) {
this.endResultRecieved = false;
this.userRC.endResults();
this.userRC.clearResults();
}
} else {
if (removedNodes == null) {
removedNodes = new HashSet<InternalDistributedMember>();
}
removedNodes.add(id);
}
}
this.fites.add(fe);
} else {
fe = new FunctionInvocationTargetException(LocalizedStrings.MemberMessage_MEMBERRESPONSE_GOT_MEMBERDEPARTED_EVENT_FOR_0_CRASHED_1.toLocalizedString(new Object[] { id, Boolean.valueOf(crashed) }), id);
}
this.fites.add(fe);
}
}
// synchronized
checkIfDone();
}
}
use of org.apache.geode.cache.execute.FunctionInvocationTargetException in project geode by apache.
the class ExecuteRegionFunction65 method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection servConn, long start) throws IOException {
String regionName = null;
Object function = null;
Object args = null;
MemberMappedArgument memberMappedArg = null;
byte isReExecute = 0;
Set<Object> filter = null;
byte hasResult = 0;
int removedNodesSize = 0;
Set<Object> removedNodesSet = null;
int filterSize = 0, partNumber = 0;
CachedRegionHelper crHelper = servConn.getCachedRegionHelper();
byte functionState = 0;
try {
functionState = clientMessage.getPart(0).getSerializedForm()[0];
if (functionState != 1) {
hasResult = (byte) ((functionState & 2) - 1);
} else {
hasResult = functionState;
}
if (hasResult == 1) {
servConn.setAsTrue(REQUIRES_RESPONSE);
servConn.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
}
regionName = clientMessage.getPart(1).getString();
function = clientMessage.getPart(2).getStringOrObject();
args = clientMessage.getPart(3).getObject();
Part part = clientMessage.getPart(4);
if (part != null) {
Object obj = part.getObject();
if (obj instanceof MemberMappedArgument) {
memberMappedArg = (MemberMappedArgument) obj;
}
}
isReExecute = clientMessage.getPart(5).getSerializedForm()[0];
filterSize = clientMessage.getPart(6).getInt();
if (filterSize != 0) {
filter = new HashSet<Object>();
partNumber = 7;
for (int i = 0; i < filterSize; i++) {
filter.add(clientMessage.getPart(partNumber + i).getStringOrObject());
}
}
partNumber = 7 + filterSize;
removedNodesSize = clientMessage.getPart(partNumber).getInt();
if (removedNodesSize != 0) {
removedNodesSet = new HashSet<Object>();
partNumber = partNumber + 1;
for (int i = 0; i < removedNodesSize; i++) {
removedNodesSet.add(clientMessage.getPart(partNumber + i).getStringOrObject());
}
}
} catch (ClassNotFoundException exception) {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), exception);
if (hasResult == 1) {
writeChunkedException(clientMessage, exception, servConn);
servConn.setAsTrue(RESPONDED);
return;
}
}
if (function == null || regionName == null) {
String message = null;
if (function == null) {
message = LocalizedStrings.ExecuteRegionFunction_THE_INPUT_0_FOR_THE_EXECUTE_FUNCTION_REQUEST_IS_NULL.toLocalizedString("function");
}
if (regionName == null) {
message = LocalizedStrings.ExecuteRegionFunction_THE_INPUT_0_FOR_THE_EXECUTE_FUNCTION_REQUEST_IS_NULL.toLocalizedString("region");
}
logger.warn("{}: {}", servConn.getName(), message);
sendError(hasResult, clientMessage, message, servConn);
return;
}
Region region = crHelper.getRegion(regionName);
if (region == null) {
String message = LocalizedStrings.ExecuteRegionFunction_THE_REGION_NAMED_0_WAS_NOT_FOUND_DURING_EXECUTE_FUNCTION_REQUEST.toLocalizedString(regionName);
logger.warn("{}: {}", servConn.getName(), message);
sendError(hasResult, clientMessage, message, servConn);
return;
}
HandShake handShake = (HandShake) servConn.getHandshake();
int earlierClientReadTimeout = handShake.getClientReadTimeout();
handShake.setClientReadTimeout(0);
ServerToClientFunctionResultSender resultSender = null;
Function functionObject = null;
try {
if (function instanceof String) {
functionObject = FunctionService.getFunction((String) function);
if (functionObject == null) {
String message = LocalizedStrings.ExecuteRegionFunction_THE_FUNCTION_0_HAS_NOT_BEEN_REGISTERED.toLocalizedString(function);
logger.warn("{}: {}", servConn.getName(), message);
sendError(hasResult, clientMessage, message, servConn);
return;
} else {
byte functionStateOnServerSide = AbstractExecution.getFunctionState(functionObject.isHA(), functionObject.hasResult(), functionObject.optimizeForWrite());
if (logger.isDebugEnabled()) {
logger.debug("Function State on server side: {} on client: {}", functionStateOnServerSide, functionState);
}
if (functionStateOnServerSide != functionState) {
String message = LocalizedStrings.FunctionService_FUNCTION_ATTRIBUTE_MISMATCH_CLIENT_SERVER.toLocalizedString(function);
logger.warn("{}: {}", servConn.getName(), message);
sendError(hasResult, clientMessage, message, servConn);
return;
}
}
} else {
functionObject = (Function) function;
}
this.securityService.authorizeDataWrite();
// check if the caller is authorized to do this operation on server
AuthorizeRequest authzRequest = servConn.getAuthzRequest();
final String functionName = functionObject.getId();
final String regionPath = region.getFullPath();
ExecuteFunctionOperationContext executeContext = null;
if (authzRequest != null) {
executeContext = authzRequest.executeFunctionAuthorize(functionName, regionPath, filter, args, functionObject.optimizeForWrite());
}
// Construct execution
AbstractExecution execution = (AbstractExecution) FunctionService.onRegion(region);
ChunkedMessage m = servConn.getFunctionResponseMessage();
m.setTransactionId(clientMessage.getTransactionId());
resultSender = new ServerToClientFunctionResultSender65(m, MessageType.EXECUTE_REGION_FUNCTION_RESULT, servConn, functionObject, executeContext);
if (execution instanceof PartitionedRegionFunctionExecutor) {
execution = new PartitionedRegionFunctionExecutor((PartitionedRegion) region, filter, args, memberMappedArg, resultSender, removedNodesSet, false);
} else {
execution = new DistributedRegionFunctionExecutor((DistributedRegion) region, filter, args, memberMappedArg, resultSender);
}
if (isReExecute == 1) {
execution = execution.setIsReExecute();
}
if (logger.isDebugEnabled()) {
logger.debug("Executing Function: {} on Server: {} with Execution: {} functionState={} reexecute={} hasResult={}", functionObject.getId(), servConn, execution, functionState, isReExecute, hasResult);
}
if (hasResult == 1) {
if (function instanceof String) {
switch(functionState) {
case AbstractExecution.NO_HA_HASRESULT_NO_OPTIMIZEFORWRITE:
execution.execute((String) function, true, false, false).getResult();
break;
case AbstractExecution.HA_HASRESULT_NO_OPTIMIZEFORWRITE:
execution.execute((String) function, true, true, false).getResult();
break;
case AbstractExecution.HA_HASRESULT_OPTIMIZEFORWRITE:
execution.execute((String) function, true, true, true).getResult();
break;
case AbstractExecution.NO_HA_HASRESULT_OPTIMIZEFORWRITE:
execution.execute((String) function, true, false, true).getResult();
break;
}
} else {
execution.execute(functionObject).getResult();
}
} else {
if (function instanceof String) {
switch(functionState) {
case AbstractExecution.NO_HA_NO_HASRESULT_NO_OPTIMIZEFORWRITE:
execution.execute((String) function, false, false, false);
break;
case AbstractExecution.NO_HA_NO_HASRESULT_OPTIMIZEFORWRITE:
execution.execute((String) function, false, false, true);
break;
}
} else {
execution.execute(functionObject);
}
}
} catch (IOException ioe) {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), ioe);
final String message = LocalizedStrings.ExecuteRegionFunction_SERVER_COULD_NOT_SEND_THE_REPLY.toLocalizedString();
sendException(hasResult, clientMessage, message, servConn, ioe);
} catch (FunctionException fe) {
String message = fe.getMessage();
if (fe.getCause() instanceof FunctionInvocationTargetException) {
if (fe.getCause() instanceof InternalFunctionInvocationTargetException) {
// 4> in case of HA member departed
if (logger.isDebugEnabled()) {
logger.debug(LocalizedMessage.create(LocalizedStrings.ExecuteFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, new Object[] { function }), fe);
}
} else if (functionObject.isHA()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function + " :" + message));
} else {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), fe);
}
resultSender.setException(fe);
} else {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), fe);
sendException(hasResult, clientMessage, message, servConn, fe);
}
} catch (Exception e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), e);
String message = e.getMessage();
sendException(hasResult, clientMessage, message, servConn, e);
} finally {
handShake.setClientReadTimeout(earlierClientReadTimeout);
}
}
Aggregations