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