use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.
the class GemFireDeadlockDetector method find.
/**
* Find any deadlocks the exist in this distributed system.
*
* The deadlocks are returned as a list of dependencies. See {@link DeadlockDetector}
*/
public DependencyGraph find() {
final DeadlockDetector detector = new DeadlockDetector();
ResultCollector<HashSet<Dependency>, Serializable> collector = new ResultCollector<HashSet<Dependency>, Serializable>() {
public synchronized Serializable getResult() throws FunctionException {
return null;
}
public synchronized Serializable getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException {
return null;
}
public synchronized void addResult(DistributedMember memberID, HashSet<Dependency> resultOfSingleExecution) {
detector.addDependencies(resultOfSingleExecution);
}
public void endResults() {
}
public void clearResults() {
}
};
Execution execution;
if (targetMembers != null) {
execution = FunctionService.onMembers(targetMembers).withCollector(collector);
} else {
execution = FunctionService.onMembers().withCollector(collector);
}
((AbstractExecution) execution).setIgnoreDepartedMembers(true);
collector = execution.execute(new CollectDependencyFunction());
// Wait for results
collector.getResult();
return detector.getDependencyGraph();
}
use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testListIndexWithStats.
@Test
public void testListIndexWithStats() {
final InternalCache mockCache = mock(InternalCache.class, "InternalCache");
final String serverName = "mockServer";
final AbstractExecution mockFunctionExecutor = mock(AbstractExecution.class, "Function Executor");
final ResultCollector mockResultCollector = mock(ResultCollector.class, "ResultCollector");
final LuceneIndexStats mockIndexStats1 = getMockIndexStats(1, 10, 5, 1);
final LuceneIndexStats mockIndexStats2 = getMockIndexStats(2, 20, 10, 2);
final LuceneIndexStats mockIndexStats3 = getMockIndexStats(3, 30, 15, 3);
String[] searchableFields = { "field1", "field2", "field3" };
Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
fieldAnalyzers.put("field1", new StandardAnalyzer());
fieldAnalyzers.put("field2", new KeywordAnalyzer());
fieldAnalyzers.put("field3", null);
final LuceneIndexDetails indexDetails1 = createIndexDetails("memberFive", "/Employees", searchableFields, fieldAnalyzers, mockIndexStats1, true, serverName);
final LuceneIndexDetails indexDetails2 = createIndexDetails("memberSix", "/Employees", searchableFields, fieldAnalyzers, mockIndexStats2, true, serverName);
final LuceneIndexDetails indexDetails3 = createIndexDetails("memberTen", "/Employees", searchableFields, fieldAnalyzers, mockIndexStats3, true, serverName);
final List<Set<LuceneIndexDetails>> results = new ArrayList<>();
results.add(CollectionUtils.asSet(indexDetails2, indexDetails1, indexDetails3));
when(mockFunctionExecutor.execute(isA(LuceneListIndexFunction.class))).thenReturn(mockResultCollector);
when(mockResultCollector.getResult()).thenReturn(results);
final LuceneIndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
CommandResult result = (CommandResult) commands.listIndex(true);
TabularResultData data = (TabularResultData) result.getResultData();
assertEquals(Arrays.asList("memberFive", "memberSix", "memberTen"), data.retrieveAllValues("Index Name"));
assertEquals(Arrays.asList("/Employees", "/Employees", "/Employees"), data.retrieveAllValues("Region Path"));
assertEquals(Arrays.asList("[field1, field2, field3]", "[field1, field2, field3]", "[field1, field2, field3]"), data.retrieveAllValues("Indexed Fields"));
assertEquals(Arrays.asList("{field1=StandardAnalyzer, field2=KeywordAnalyzer}", "{field1=StandardAnalyzer, field2=KeywordAnalyzer}", "{field1=StandardAnalyzer, field2=KeywordAnalyzer}"), data.retrieveAllValues("Field Analyzer"));
assertEquals(Arrays.asList("1", "2", "3"), data.retrieveAllValues("Query Executions"));
assertEquals(Arrays.asList("10", "20", "30"), data.retrieveAllValues("Commits"));
assertEquals(Arrays.asList("5", "10", "15"), data.retrieveAllValues("Updates"));
assertEquals(Arrays.asList("1", "2", "3"), data.retrieveAllValues("Documents"));
}
use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.
the class CliUtil method executeFunction.
/***
* Executes a function with arguments on a set of members , ignores the departed members.
*
* @param function Function to be executed.
* @param args Arguments passed to the function, pass null if you wish to pass no arguments to the
* function.
* @param targetMembers Set of members on which the function is to be executed.
*
* @return ResultCollector
*/
public static ResultCollector<?, ?> executeFunction(final Function function, Object args, final Set<DistributedMember> targetMembers) {
Execution execution = null;
if (args != null) {
execution = FunctionService.onMembers(targetMembers).setArguments(args);
} else {
execution = FunctionService.onMembers(targetMembers);
}
((AbstractExecution) execution).setIgnoreDepartedMembers(true);
return execution.execute(function);
}
use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.
the class CliUtil method executeFunction.
/***
* Executes a function with arguments on a member , ignores the departed member.
*
* @param function Function to be executed
* @param args Arguments passed to the function, pass null if you wish to pass no arguments to the
* function.
* @param targetMember Member on which the function is to be executed.
* @return ResultCollector
*/
public static ResultCollector<?, ?> executeFunction(final Function function, Object args, final DistributedMember targetMember) {
Execution execution = null;
if (args != null) {
execution = FunctionService.onMember(targetMember).setArguments(args);
} else {
execution = FunctionService.onMember(targetMember);
}
((AbstractExecution) execution).setIgnoreDepartedMembers(true);
return execution.execute(function);
}
use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.
the class ExecuteRegionFunction 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;
Set filter = null;
byte hasResult = 0;
int filterSize = 0, partNumber = 0;
CachedRegionHelper crHelper = servConn.getCachedRegionHelper();
try {
hasResult = clientMessage.getPart(0).getSerializedForm()[0];
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;
}
}
filterSize = clientMessage.getPart(5).getInt();
if (filterSize != 0) {
filter = new HashSet();
partNumber = 6;
for (int i = 0; i < filterSize; i++) {
filter.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 {
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 ServerToClientFunctionResultSender(m, MessageType.EXECUTE_REGION_FUNCTION_RESULT, servConn, functionObject, executeContext);
if (execution instanceof PartitionedRegionFunctionExecutor) {
execution = new PartitionedRegionFunctionExecutor((PartitionedRegion) region, filter, args, memberMappedArg, resultSender, null, false);
} else {
execution = new DistributedRegionFunctionExecutor((DistributedRegion) region, filter, args, memberMappedArg, resultSender);
}
if (logger.isDebugEnabled()) {
logger.debug("Executing Function: {} on Server: {} with Execution: {}", functionObject.getId(), servConn, execution);
}
if (hasResult == 1) {
if (function instanceof String) {
execution.execute((String) function).getResult();
} else {
execution.execute(functionObject).getResult();
}
} else {
if (function instanceof String) {
execution.execute((String) function);
} 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 (InternalFunctionInvocationTargetException internalfunctionException) {
// 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 }), internalfunctionException);
}
final String message = internalfunctionException.getMessage();
sendException(hasResult, clientMessage, message, servConn, internalfunctionException);
} catch (FunctionException fe) {
logger.warn(LocalizedMessage.create(LocalizedStrings.ExecuteRegionFunction_EXCEPTION_ON_SERVER_WHILE_EXECUTIONG_FUNCTION_0, function), fe);
String message = fe.getMessage();
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