Search in sources :

Example 81 with CacheClosedException

use of org.apache.geode.cache.CacheClosedException in project geode by apache.

the class DestroyIndexFunction method execute.

@Override
public void execute(FunctionContext context) {
    IndexInfo indexInfo = (IndexInfo) context.getArguments();
    String memberId = null;
    try {
        Cache cache = CacheFactory.getAnyInstance();
        memberId = cache.getDistributedSystem().getDistributedMember().getId();
        QueryService queryService = cache.getQueryService();
        String indexName = indexInfo.getIndexName();
        String regionPath = indexInfo.getRegionPath();
        XmlEntity xmlEntity = new XmlEntity(CacheXml.REGION, "name", regionPath, CacheXml.INDEX, "name", indexName);
        if (regionPath != null && !regionPath.isEmpty()) {
            Region<?, ?> region = cache.getRegion(regionPath);
            if (region != null) {
                if (indexName == null || indexName.isEmpty()) {
                    queryService.removeIndexes(region);
                    context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity));
                } else {
                    Index index = queryService.getIndex(region, indexName);
                    if (index != null) {
                        queryService.removeIndex(index);
                        context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity));
                    } else {
                        context.getResultSender().lastResult(new CliFunctionResult(memberId, false, CliStrings.format(CliStrings.DESTROY_INDEX__INDEX__NOT__FOUND, indexName)));
                    }
                }
            } else {
                context.getResultSender().lastResult(new CliFunctionResult(memberId, false, CliStrings.format(CliStrings.DESTROY_INDEX__REGION__NOT__FOUND, regionPath)));
            }
        } else {
            if (indexName == null || indexName.isEmpty()) {
                queryService.removeIndexes();
                context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity));
            } else {
                if (removeIndexByName(indexName, queryService)) {
                    context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity));
                } else {
                    context.getResultSender().lastResult(new CliFunctionResult(memberId, false, CliStrings.format(CliStrings.DESTROY_INDEX__INDEX__NOT__FOUND, indexName)));
                }
            }
        }
    } catch (CacheClosedException e) {
        context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage()));
    } catch (Exception e) {
        context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage()));
    }
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) QueryService(org.apache.geode.cache.query.QueryService) Index(org.apache.geode.cache.query.Index) IndexInfo(org.apache.geode.management.internal.cli.domain.IndexInfo) CacheClosedException(org.apache.geode.cache.CacheClosedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) Cache(org.apache.geode.cache.Cache)

Example 82 with CacheClosedException

use of org.apache.geode.cache.CacheClosedException in project geode by apache.

the class UndeployFunction method execute.

@Override
public void execute(FunctionContext context) {
    // Declared here so that it's available when returning a Throwable
    String memberId = "";
    try {
        final Object[] args = (Object[]) context.getArguments();
        // Comma separated
        final String jarFilenameList = (String) args[0];
        InternalCache cache = getCache();
        final JarDeployer jarDeployer = ClassPathLoader.getLatest().getJarDeployer();
        DistributedMember member = cache.getDistributedSystem().getDistributedMember();
        memberId = member.getId();
        // If they set a name use it instead
        if (!member.getName().equals("")) {
            memberId = member.getName();
        }
        String[] undeployedJars = new String[0];
        if (jarFilenameList == null || jarFilenameList.equals("")) {
            final List<DeployedJar> jarClassLoaders = jarDeployer.findDeployedJars();
            undeployedJars = new String[jarClassLoaders.size() * 2];
            int index = 0;
            for (DeployedJar jarClassLoader : jarClassLoaders) {
                undeployedJars[index++] = jarClassLoader.getJarName();
                try {
                    undeployedJars[index++] = ClassPathLoader.getLatest().getJarDeployer().undeploy(jarClassLoader.getJarName());
                } catch (IllegalArgumentException iaex) {
                    // It's okay for it to have have been uneployed from this server
                    undeployedJars[index++] = iaex.getMessage();
                }
            }
        } else {
            List<String> undeployedList = new ArrayList<String>();
            StringTokenizer jarTokenizer = new StringTokenizer(jarFilenameList, ",");
            while (jarTokenizer.hasMoreTokens()) {
                String jarFilename = jarTokenizer.nextToken().trim();
                try {
                    undeployedList.add(jarFilename);
                    undeployedList.add(ClassPathLoader.getLatest().getJarDeployer().undeploy(jarFilename));
                } catch (IllegalArgumentException iaex) {
                    // It's okay for it to not have been deployed to this server
                    undeployedList.add(iaex.getMessage());
                }
            }
            undeployedJars = undeployedList.toArray(undeployedJars);
        }
        CliFunctionResult result = new CliFunctionResult(memberId, undeployedJars);
        context.getResultSender().lastResult(result);
    } catch (CacheClosedException cce) {
        CliFunctionResult result = new CliFunctionResult(memberId, false, null);
        context.getResultSender().lastResult(result);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        logger.error("Could not undeploy JAR file: {}", th.getMessage(), th);
        CliFunctionResult result = new CliFunctionResult(memberId, th, null);
        context.getResultSender().lastResult(result);
    }
}
Also used : DeployedJar(org.apache.geode.internal.DeployedJar) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheClosedException(org.apache.geode.cache.CacheClosedException) StringTokenizer(java.util.StringTokenizer) DistributedMember(org.apache.geode.distributed.DistributedMember) JarDeployer(org.apache.geode.internal.JarDeployer)

Example 83 with CacheClosedException

use of org.apache.geode.cache.CacheClosedException in project geode by apache.

the class ListAsyncEventQueuesFunction method execute.

@Override
public void execute(final FunctionContext context) {
    // Declared here so that it's available when returning a Throwable
    String memberId = "";
    try {
        Cache cache = CacheFactory.getAnyInstance();
        DistributedMember member = cache.getDistributedSystem().getDistributedMember();
        memberId = member.getId();
        // If they set a name use it instead
        if (!member.getName().equals("")) {
            memberId = member.getName();
        }
        Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues();
        AsyncEventQueueDetails[] asyncEventQueueDetails = new AsyncEventQueueDetails[asyncEventQueues.size()];
        int i = 0;
        for (AsyncEventQueue queue : asyncEventQueues) {
            AsyncEventListener listener = queue.getAsyncEventListener();
            Properties listenerProperties = new Properties();
            if (listener instanceof Declarable2) {
                listenerProperties = ((Declarable2) listener).getConfig();
            }
            asyncEventQueueDetails[i++] = new AsyncEventQueueDetails(queue.getId(), queue.getBatchSize(), queue.isPersistent(), queue.getDiskStoreName(), queue.getMaximumQueueMemory(), listener.getClass().getName(), listenerProperties);
        }
        CliFunctionResult result = new CliFunctionResult(memberId, asyncEventQueueDetails);
        context.getResultSender().lastResult(result);
    } catch (CacheClosedException cce) {
        CliFunctionResult result = new CliFunctionResult(memberId, false, null);
        context.getResultSender().lastResult(result);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        logger.error("Could not list async event queues: {}", th.getMessage(), th);
        CliFunctionResult result = new CliFunctionResult(memberId, th, null);
        context.getResultSender().lastResult(result);
    }
}
Also used : AsyncEventQueueDetails(org.apache.geode.management.internal.cli.domain.AsyncEventQueueDetails) Declarable2(org.apache.geode.internal.cache.xmlcache.Declarable2) CacheClosedException(org.apache.geode.cache.CacheClosedException) Properties(java.util.Properties) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) DistributedMember(org.apache.geode.distributed.DistributedMember) Cache(org.apache.geode.cache.Cache) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 84 with CacheClosedException

use of org.apache.geode.cache.CacheClosedException in project geode by apache.

the class ListFunctionFunction method execute.

@Override
public void execute(FunctionContext context) {
    // Declared here so that it's available when returning a Throwable
    String memberId = "";
    try {
        final Object[] args = (Object[]) context.getArguments();
        final String stringPattern = (String) args[0];
        Cache cache = CacheFactory.getAnyInstance();
        DistributedMember member = cache.getDistributedSystem().getDistributedMember();
        memberId = member.getId();
        // If they set a name use it instead
        if (!member.getName().equals("")) {
            memberId = member.getName();
        }
        final Map<String, Function> functions = FunctionService.getRegisteredFunctions();
        CliFunctionResult result;
        if (stringPattern == null || stringPattern.isEmpty()) {
            result = new CliFunctionResult(memberId, functions.keySet().toArray(new String[0]));
        } else {
            Pattern pattern = Pattern.compile(stringPattern);
            List<String> resultList = new LinkedList<String>();
            for (String functionId : functions.keySet()) {
                Matcher matcher = pattern.matcher(functionId);
                if (matcher.matches()) {
                    resultList.add(functionId);
                }
            }
            result = new CliFunctionResult(memberId, resultList.toArray(new String[0]));
        }
        context.getResultSender().lastResult(result);
    } catch (CacheClosedException cce) {
        CliFunctionResult result = new CliFunctionResult(memberId, false, null);
        context.getResultSender().lastResult(result);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        logger.error("Could not list functions: {}", th.getMessage(), th);
        CliFunctionResult result = new CliFunctionResult(memberId, th, null);
        context.getResultSender().lastResult(result);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) CacheClosedException(org.apache.geode.cache.CacheClosedException) LinkedList(java.util.LinkedList) Function(org.apache.geode.cache.execute.Function) DistributedMember(org.apache.geode.distributed.DistributedMember) Cache(org.apache.geode.cache.Cache)

Example 85 with CacheClosedException

use of org.apache.geode.cache.CacheClosedException in project geode by apache.

the class GetRegionDescriptionFunction method execute.

@Override
public void execute(FunctionContext context) {
    String regionPath = (String) context.getArguments();
    try {
        Cache cache = CacheFactory.getAnyInstance();
        Region<?, ?> region = cache.getRegion(regionPath);
        if (region != null) {
            String memberName = cache.getDistributedSystem().getDistributedMember().getName();
            RegionDescriptionPerMember regionDescription = new RegionDescriptionPerMember(region, memberName);
            context.getResultSender().lastResult(regionDescription);
        } else {
            context.getResultSender().lastResult(null);
        }
    } catch (CacheClosedException e) {
        context.getResultSender().sendException(e);
    } catch (Exception e) {
        context.getResultSender().sendException(e);
    }
}
Also used : RegionDescriptionPerMember(org.apache.geode.management.internal.cli.domain.RegionDescriptionPerMember) CacheClosedException(org.apache.geode.cache.CacheClosedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) Cache(org.apache.geode.cache.Cache)

Aggregations

CacheClosedException (org.apache.geode.cache.CacheClosedException)95 Cache (org.apache.geode.cache.Cache)26 Test (org.junit.Test)21 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)20 FunctionException (org.apache.geode.cache.execute.FunctionException)20 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)20 CancelException (org.apache.geode.CancelException)18 Region (org.apache.geode.cache.Region)18 Host (org.apache.geode.test.dunit.Host)17 VM (org.apache.geode.test.dunit.VM)17 InternalCache (org.apache.geode.internal.cache.InternalCache)16 IgnoredException (org.apache.geode.test.dunit.IgnoredException)16 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)16 DistributedMember (org.apache.geode.distributed.DistributedMember)14 ReplyException (org.apache.geode.distributed.internal.ReplyException)14 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)12 Execution (org.apache.geode.cache.execute.Execution)11 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)11 HashMap (java.util.HashMap)10