Search in sources :

Example 1 with GemFireDeadlockDetector

use of org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector in project geode by apache.

the class ShowDeadlockDUnitTest method testNoDeadlock.

@Test
public void testNoDeadlock() throws Exception {
    GemFireDeadlockDetector detect = new GemFireDeadlockDetector();
    assertEquals(null, detect.find().findCycle());
    File outputFile = new File(temporaryFolder.getRoot(), "dependency.txt");
    String showDeadlockCommand = new CommandStringBuilder(CliStrings.SHOW_DEADLOCK).addOption(CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE, outputFile.getName()).toString();
    Result result = new CommandProcessor().createCommandStatement(showDeadlockCommand, Collections.emptyMap()).process();
    String commandOutput = getResultAsString(result);
    assertEquals(true, result.hasIncomingFiles());
    assertEquals(true, result.getStatus().equals(Status.OK));
    assertEquals(true, commandOutput.startsWith(CliStrings.SHOW_DEADLOCK__NO__DEADLOCK));
    result.saveIncomingFiles(temporaryFolder.getRoot().getAbsolutePath());
    assertTrue(outputFile.exists());
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) GemFireDeadlockDetector(org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) File(java.io.File) Result(org.apache.geode.management.cli.Result) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with GemFireDeadlockDetector

use of org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector in project geode by apache.

the class MiscellaneousCommands method showDeadlock.

@CliCommand(value = CliStrings.SHOW_DEADLOCK, help = CliStrings.SHOW_DEADLOCK__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result showDeadlock(@CliOption(key = CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE, help = CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE__HELP, mandatory = true) String filename) {
    Result result = null;
    try {
        if (!filename.endsWith(".txt")) {
            return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENSION, ".txt"));
        }
        InternalCache cache = getCache();
        Set<DistributedMember> allMembers = CliUtil.getAllMembers(cache);
        GemFireDeadlockDetector gfeDeadLockDetector = new GemFireDeadlockDetector(allMembers);
        DependencyGraph dependencyGraph = gfeDeadLockDetector.find();
        Collection<Dependency> deadlock = dependencyGraph.findCycle();
        DependencyGraph deepest = null;
        if (deadlock == null) {
            deepest = dependencyGraph.findLongestCallChain();
            if (deepest != null) {
                deadlock = deepest.getEdges();
            }
        }
        Set<Dependency> dependencies = (Set<Dependency>) dependencyGraph.getEdges();
        InfoResultData resultData = ResultBuilder.createInfoResultData();
        if (deadlock != null) {
            if (deepest != null) {
                resultData.addLine(CliStrings.SHOW_DEADLOCK__DEEPEST_FOUND);
            } else {
                resultData.addLine(CliStrings.SHOW_DEADLOCK__DEADLOCK__DETECTED);
            }
            resultData.addLine(DeadlockDetector.prettyFormat(deadlock));
        } else {
            resultData.addLine(CliStrings.SHOW_DEADLOCK__NO__DEADLOCK);
        }
        resultData.addAsFile(filename, DeadlockDetector.prettyFormat(dependencies), MessageFormat.format(CliStrings.SHOW_DEADLOCK__DEPENDENCIES__REVIEW, filename), false);
        result = ResultBuilder.buildResult(resultData);
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.SHOW_DEADLOCK__ERROR + " : " + e.getMessage());
    }
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InfoResultData(org.apache.geode.management.internal.cli.result.InfoResultData) GemFireDeadlockDetector(org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) DependencyGraph(org.apache.geode.distributed.internal.deadlock.DependencyGraph) Dependency(org.apache.geode.distributed.internal.deadlock.Dependency) TimeoutException(java.util.concurrent.TimeoutException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) FunctionException(org.apache.geode.cache.execute.FunctionException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) NetstatFunctionResult(org.apache.geode.management.internal.cli.functions.NetstatFunction.NetstatFunctionResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

GemFireDeadlockDetector (org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector)2 Result (org.apache.geode.management.cli.Result)2 File (java.io.File)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 DataFormatException (java.util.zip.DataFormatException)1 FunctionException (org.apache.geode.cache.execute.FunctionException)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 Dependency (org.apache.geode.distributed.internal.deadlock.Dependency)1 DependencyGraph (org.apache.geode.distributed.internal.deadlock.DependencyGraph)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 GfshParseResult (org.apache.geode.management.internal.cli.GfshParseResult)1 NetstatFunctionResult (org.apache.geode.management.internal.cli.functions.NetstatFunction.NetstatFunctionResult)1 CommandProcessor (org.apache.geode.management.internal.cli.remote.CommandProcessor)1 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)1 InfoResultData (org.apache.geode.management.internal.cli.result.InfoResultData)1