use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class QueryDataFunction method queryData.
public static Object queryData(final String query, final String members, final int limit, final boolean zipResult, final int queryResultSetLimit, final int queryCollectionsDepth) throws Exception {
if (query == null || query.isEmpty()) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__QUERY_EMPTY.toLocalizedString()).toString();
}
Set<DistributedMember> inputMembers = null;
if (StringUtils.isNotBlank(members)) {
inputMembers = new HashSet<>();
StringTokenizer st = new StringTokenizer(members, ",");
while (st.hasMoreTokens()) {
String member = st.nextToken();
DistributedMember distributedMember = BeanUtilFuncs.getDistributedMemberByNameOrId(member);
inputMembers.add(distributedMember);
if (distributedMember == null) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__INVALID_MEMBER.toLocalizedString(member)).toString();
}
}
}
InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
try {
SystemManagementService service = (SystemManagementService) ManagementService.getExistingManagementService(cache);
Set<String> regionsInQuery = compileQuery(cache, query);
// Validate region existence
if (regionsInQuery.size() > 0) {
for (String regionPath : regionsInQuery) {
DistributedRegionMXBean regionMBean = service.getDistributedRegionMXBean(regionPath);
if (regionMBean == null) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND.toLocalizedString(regionPath)).toString();
} else {
Set<DistributedMember> associatedMembers = DataCommands.getRegionAssociatedMembers(regionPath, cache, true);
if (inputMembers != null && inputMembers.size() > 0) {
if (!associatedMembers.containsAll(inputMembers)) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND_ON_MEMBERS.toLocalizedString(regionPath)).toString();
}
}
}
}
} else {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__INVALID_QUERY.toLocalizedString("Region mentioned in query probably missing /")).toString();
}
// Validate
if (regionsInQuery.size() > 1 && inputMembers == null) {
for (String regionPath : regionsInQuery) {
DistributedRegionMXBean regionMBean = service.getDistributedRegionMXBean(regionPath);
if (regionMBean.getRegionType().equals(DataPolicy.PARTITION.toString()) || regionMBean.getRegionType().equals(DataPolicy.PERSISTENT_PARTITION.toString())) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__JOIN_OP_EX.toLocalizedString()).toString();
}
}
}
String randomRegion = regionsInQuery.iterator().next();
Set<DistributedMember> associatedMembers = // First
DataCommands.getQueryRegionsAssociatedMembers(regionsInQuery, cache, false);
if (associatedMembers != null && associatedMembers.size() > 0) {
Object[] functionArgs = new Object[6];
if (inputMembers != null && inputMembers.size() > 0) {
// on input
// members
functionArgs[DISPLAY_MEMBERWISE] = true;
functionArgs[QUERY] = query;
functionArgs[REGION] = randomRegion;
functionArgs[LIMIT] = limit;
functionArgs[QUERY_RESULTSET_LIMIT] = queryResultSetLimit;
functionArgs[QUERY_COLLECTIONS_DEPTH] = queryCollectionsDepth;
return callFunction(functionArgs, inputMembers, zipResult);
} else {
// Query on any random member
functionArgs[DISPLAY_MEMBERWISE] = false;
functionArgs[QUERY] = query;
functionArgs[REGION] = randomRegion;
functionArgs[LIMIT] = limit;
functionArgs[QUERY_RESULTSET_LIMIT] = queryResultSetLimit;
functionArgs[QUERY_COLLECTIONS_DEPTH] = queryCollectionsDepth;
return callFunction(functionArgs, associatedMembers, zipResult);
}
} else {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__REGIONS_NOT_FOUND.toLocalizedString(regionsInQuery.toString())).toString();
}
} catch (QueryInvalidException qe) {
return new JsonisedErrorMessage(ManagementStrings.QUERY__MSG__INVALID_QUERY.toLocalizedString(qe.getMessage())).toString();
}
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class CliUtil method findMembers.
/**
* Finds all Servers which belong to the given arrays of groups or members. Does not include
* locators.
*/
public static Set<DistributedMember> findMembers(String[] groups, String[] members) {
InternalCache cache = getInternalCache();
Set<DistributedMember> allNormalMembers = getAllNormalMembers(cache);
return findMembers(allNormalMembers, groups, members);
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class GeodeRedisServer method initializeRedis.
private void initializeRedis() {
synchronized (this.cache) {
Region<ByteArrayWrapper, ByteArrayWrapper> stringsRegion;
Region<ByteArrayWrapper, HyperLogLogPlus> hLLRegion;
Region<String, RedisDataType> redisMetaData;
InternalCache gemFireCache = (InternalCache) cache;
try {
if ((stringsRegion = cache.getRegion(STRING_REGION)) == null) {
RegionFactory<ByteArrayWrapper, ByteArrayWrapper> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
stringsRegion = regionFactory.create(STRING_REGION);
}
if ((hLLRegion = cache.getRegion(HLL_REGION)) == null) {
RegionFactory<ByteArrayWrapper, HyperLogLogPlus> regionFactory = gemFireCache.createRegionFactory(this.DEFAULT_REGION_TYPE);
hLLRegion = regionFactory.create(HLL_REGION);
}
if ((redisMetaData = cache.getRegion(REDIS_META_DATA_REGION)) == null) {
AttributesFactory af = new AttributesFactory();
af.addCacheListener(metaListener);
af.setDataPolicy(DataPolicy.REPLICATE);
InternalRegionArguments ira = new InternalRegionArguments().setInternalRegion(true).setIsUsedForMetaRegion(true);
redisMetaData = gemFireCache.createVMRegion(REDIS_META_DATA_REGION, af.create(), ira);
}
} catch (IOException | ClassNotFoundException e) {
// only if loading snapshot, not here
InternalGemFireError assErr = new InternalGemFireError(LocalizedStrings.GemFireCache_UNEXPECTED_EXCEPTION.toLocalizedString());
assErr.initCause(e);
throw assErr;
}
this.regionCache = new RegionProvider(stringsRegion, hLLRegion, redisMetaData, expirationFutures, expirationExecutor, this.DEFAULT_REGION_TYPE);
redisMetaData.put(REDIS_META_DATA_REGION, RedisDataType.REDIS_PROTECTED);
redisMetaData.put(HLL_REGION, RedisDataType.REDIS_PROTECTED);
redisMetaData.put(STRING_REGION, RedisDataType.REDIS_PROTECTED);
}
checkForRegions();
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class InternalLocator method startCache.
private void startCache(DistributedSystem ds) {
InternalCache internalCache = GemFireCacheImpl.getInstance();
if (internalCache == null) {
logger.info("Creating cache for locator.");
this.myCache = (InternalCache) new CacheFactory(ds.getProperties()).create();
internalCache = this.myCache;
} else {
logger.info("Using existing cache for locator.");
((InternalDistributedSystem) ds).handleResourceEvent(ResourceEvent.LOCATOR_START, this);
}
startJmxManagerLocationService(internalCache);
startSharedConfigurationService(internalCache);
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class InternalDataSerializer method readPdxSerializable.
private static Object readPdxSerializable(final DataInput in) throws IOException, ClassNotFoundException {
int len = in.readInt();
int typeId = in.readInt();
InternalCache internalCache = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.");
PdxType pdxType = internalCache.getPdxRegistry().getType(typeId);
if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
logger.trace(LogMarker.SERIALIZER, "readPdxSerializable pdxType={}", pdxType);
}
if (pdxType == null) {
throw new IllegalStateException("Unknown pdx type=" + typeId);
}
DMStats dmStats = getDMStats(internalCache);
dmStats.incPdxDeserialization(len + 9);
// check if PdxInstance needs to be returned.
if (pdxType.getNoDomainClass() || internalCache.getPdxReadSerializedByAnyGemFireServices()) {
dmStats.incPdxInstanceCreations();
return new PdxInstanceImpl(pdxType, in, len);
} else {
PdxReaderImpl pdxReader = new PdxReaderImpl(pdxType, in, len);
return pdxReader.getObject();
}
}
Aggregations