use of org.apache.geode.management.DistributedRegionMXBean 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.management.DistributedRegionMXBean in project geode by apache.
the class DistributedSystemBridge method addRegion.
public void addRegion(ObjectName proxyName, RegionMXBean regionProxy, FederationComponent fedComp) {
String fullPath = proxyName.getKeyProperty("name");
ObjectName distributedRegionObjectName = MBeanJMXAdapter.getDistributedRegionMbeanNameInternal(fullPath);
synchronized (distrRegionMap) {
DistributedRegionBridge bridge = distrRegionMap.get(distributedRegionObjectName);
if (bridge != null) {
FederationComponent newObj = fedComp;
bridge.addProxyToMap(proxyName, regionProxy, newObj);
} else {
FederationComponent newObj = fedComp;
bridge = new DistributedRegionBridge(proxyName, regionProxy, newObj);
DistributedRegionMXBean mbean = new DistributedRegionMBean(bridge);
service.registerInternalMBean(mbean, distributedRegionObjectName);
distrRegionMap.put(distributedRegionObjectName, bridge);
}
}
}
use of org.apache.geode.management.DistributedRegionMXBean in project geode by apache.
the class DataCommands method getAssociatedMembers.
public DistributedMember getAssociatedMembers(String region, final InternalCache cache) {
DistributedRegionMXBean bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean(region);
DistributedMember member = null;
if (bean == null) {
return null;
}
String[] membersName = bean.getMembers();
Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache);
Iterator it = dsMembers.iterator();
boolean matchFound = false;
if (membersName.length > 1) {
while (it.hasNext() && !matchFound) {
DistributedMember dsmember = (DistributedMember) it.next();
for (String memberName : membersName) {
if (MBeanJMXAdapter.getMemberNameOrId(dsmember).equals(memberName)) {
member = dsmember;
matchFound = true;
break;
}
}
}
}
return member;
}
use of org.apache.geode.management.DistributedRegionMXBean in project geode by apache.
the class DataCommands method getRegionAssociatedMembers.
@SuppressWarnings("rawtypes")
public static Set<DistributedMember> getRegionAssociatedMembers(String region, final InternalCache cache, boolean returnAll) {
DistributedMember member;
if (StringUtils.isEmpty(region)) {
return null;
}
DistributedRegionMXBean bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean(region);
if (bean == null) {
// try with slash ahead
bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean(Region.SEPARATOR + region);
}
if (bean == null) {
return null;
}
String[] membersName = bean.getMembers();
Set<DistributedMember> dsMembers = cache.getMembers();
Set<DistributedMember> dsMembersWithThisMember = new HashSet<>();
dsMembersWithThisMember.addAll(dsMembers);
dsMembersWithThisMember.add(cache.getDistributedSystem().getDistributedMember());
Iterator it = dsMembersWithThisMember.iterator();
Set<DistributedMember> matchedMembers = new HashSet<>();
if (membersName.length > 0) {
while (it.hasNext()) {
DistributedMember dsmember = (DistributedMember) it.next();
for (String memberName : membersName) {
String name = MBeanJMXAdapter.getMemberNameOrId(dsmember);
if (name.equals(memberName)) {
member = dsmember;
matchedMembers.add(member);
if (!returnAll) {
return matchedMembers;
}
}
}
}
}
// try with function calls
if (matchedMembers.size() == 0) {
matchedMembers = CliUtil.getMembersForeRegionViaFunction(cache, region, true);
}
return matchedMembers;
}
use of org.apache.geode.management.DistributedRegionMXBean in project geode by apache.
the class CreateAlterDestroyRegionCommands method verifyDistributedRegionMbean.
public boolean verifyDistributedRegionMbean(InternalCache cache, String regionName) {
int federationInterval = cache.getInternalDistributedSystem().getConfig().getJmxManagerUpdateRate();
long timeEnd = System.currentTimeMillis() + federationInterval + 50;
for (; System.currentTimeMillis() <= timeEnd; ) {
try {
DistributedRegionMXBean bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean(regionName);
if (bean == null) {
bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean(Region.SEPARATOR + regionName);
}
if (bean != null) {
return true;
} else {
Thread.sleep(2);
}
} catch (Exception ignored) {
}
}
return false;
}
Aggregations