Search in sources :

Example 6 with DistributedRegionMXBean

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();
    }
}
Also used : QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) StringTokenizer(java.util.StringTokenizer) DistributedMember(org.apache.geode.distributed.DistributedMember) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject)

Example 7 with DistributedRegionMXBean

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);
        }
    }
}
Also used : FederationComponent(org.apache.geode.management.internal.FederationComponent) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) ObjectName(javax.management.ObjectName)

Example 8 with DistributedRegionMXBean

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;
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) Iterator(java.util.Iterator) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean)

Example 9 with DistributedRegionMXBean

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;
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) Iterator(java.util.Iterator) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) HashSet(java.util.HashSet)

Example 10 with DistributedRegionMXBean

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;
}
Also used : DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) ConverterHint(org.apache.geode.management.cli.ConverterHint) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Aggregations

DistributedRegionMXBean (org.apache.geode.management.DistributedRegionMXBean)15 InternalCache (org.apache.geode.internal.cache.InternalCache)7 DistributedMember (org.apache.geode.distributed.DistributedMember)5 ManagementService (org.apache.geode.management.ManagementService)5 VM (org.apache.geode.test.dunit.VM)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 Cache (org.apache.geode.cache.Cache)3 ConverterHint (org.apache.geode.management.cli.ConverterHint)3 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)3 ManagerMXBean (org.apache.geode.management.ManagerMXBean)2 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)2 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)2 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)2 ErrorResultData (org.apache.geode.management.internal.cli.result.ErrorResultData)2 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)2 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2