Search in sources :

Example 11 with DistributedSystemMXBean

use of org.apache.geode.management.DistributedSystemMXBean in project geode by apache.

the class DistributedSystemStatsDUnitTest method testDistributedSystemStats.

@Test
public void testDistributedSystemStats() throws Exception {
    this.managerVM.invoke("verifyMBeans", () -> {
        DistributedSystemMXBean distributedSystemMXBean = awaitDistributedSystemMXBean();
        // next block awaits all memberMXBeanName to refresh (getLastUpdateTime)
        SystemManagementService service = this.managementTestRule.getSystemManagementService();
        Set<DistributedMember> otherMemberSet = this.managementTestRule.getOtherNormalMembers();
        assertEquals(3, otherMemberSet.size());
        for (DistributedMember member : otherMemberSet) {
            MemberMXBean memberMXBean = awaitMemberMXBeanProxy(member);
            ObjectName memberMXBeanName = service.getMemberMBeanName(member);
            long lastRefreshTime = service.getLastUpdateTime(memberMXBeanName);
            await().until(() -> assertTrue(service.getLastUpdateTime(memberMXBeanName) > lastRefreshTime));
        }
    // TODO: add assertions for distributedSystemMXBean stats?
    });
}
Also used : DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) DistributedMember(org.apache.geode.distributed.DistributedMember) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) MemberMXBean(org.apache.geode.management.MemberMXBean) ObjectName(javax.management.ObjectName) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 12 with DistributedSystemMXBean

use of org.apache.geode.management.DistributedSystemMXBean in project geode by apache.

the class CreateAlterDestroyRegionCommands method validateRegionFunctionArgs.

private void validateRegionFunctionArgs(InternalCache cache, RegionFunctionArgs regionFunctionArgs) {
    if (regionFunctionArgs.getRegionPath() == null) {
        throw new IllegalArgumentException(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH);
    }
    ManagementService managementService = ManagementService.getExistingManagementService(cache);
    DistributedSystemMXBean dsMBean = managementService.getDistributedSystemMXBean();
    String useAttributesFrom = regionFunctionArgs.getUseAttributesFrom();
    if (useAttributesFrom != null && !useAttributesFrom.isEmpty() && regionExists(cache, useAttributesFrom)) {
        if (!regionExists(cache, useAttributesFrom)) {
            // check already done in createRegion !!!
            throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH_FOR_0_REGIONPATH_1_NOT_FOUND, new Object[] { CliStrings.CREATE_REGION__USEATTRIBUTESFROM, useAttributesFrom }));
        }
        if (!regionFunctionArgs.isSetUseAttributesFrom() || regionFunctionArgs.getRegionAttributes() == null) {
            throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__COULD_NOT_RETRIEVE_REGION_ATTRS_FOR_PATH_0_VERIFY_REGION_EXISTS, useAttributesFrom));
        }
    }
    if (regionFunctionArgs.hasPartitionAttributes()) {
        RegionFunctionArgs.PartitionArgs partitionArgs = regionFunctionArgs.getPartitionArgs();
        String colocatedWith = partitionArgs.getPrColocatedWith();
        if (colocatedWith != null && !colocatedWith.isEmpty()) {
            String[] listAllRegionPaths = dsMBean.listAllRegionPaths();
            String foundRegionPath = null;
            for (String regionPath : listAllRegionPaths) {
                if (regionPath.equals(colocatedWith)) {
                    foundRegionPath = regionPath;
                    break;
                }
            }
            if (foundRegionPath == null) {
                throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH_FOR_0_REGIONPATH_1_NOT_FOUND, new Object[] { CliStrings.CREATE_REGION__COLOCATEDWITH, colocatedWith }));
            }
            ManagementService mgmtService = ManagementService.getExistingManagementService(cache);
            DistributedRegionMXBean distributedRegionMXBean = mgmtService.getDistributedRegionMXBean(foundRegionPath);
            String regionType = distributedRegionMXBean.getRegionType();
            if (!(DataPolicy.PARTITION.toString().equals(regionType) || DataPolicy.PERSISTENT_PARTITION.toString().equals(regionType))) {
                throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__COLOCATEDWITH_REGION_0_IS_NOT_PARTITIONEDREGION, new Object[] { colocatedWith }));
            }
        }
        if (partitionArgs.isSetPRLocalMaxMemory()) {
            int prLocalMaxMemory = partitionArgs.getPrLocalMaxMemory();
            if (prLocalMaxMemory < 0) {
                throw new IllegalArgumentException(LocalizedStrings.AttributesFactory_PARTITIONATTRIBUTES_LOCALMAXMEMORY_MUST_NOT_BE_NEGATIVE.toLocalizedString());
            }
        }
        if (partitionArgs.isSetPRTotalMaxMemory()) {
            long prTotalMaxMemory = partitionArgs.getPrTotalMaxMemory();
            if (prTotalMaxMemory <= 0) {
                throw new IllegalArgumentException(LocalizedStrings.AttributesFactory_TOTAL_SIZE_OF_PARTITION_REGION_MUST_BE_0.toLocalizedString());
            }
        }
        if (partitionArgs.isSetPRRedundantCopies()) {
            int prRedundantCopies = partitionArgs.getPrRedundantCopies();
            switch(prRedundantCopies) {
                case 0:
                case 1:
                case 2:
                case 3:
                    break;
                default:
                    throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__REDUNDANT_COPIES_SHOULD_BE_ONE_OF_0123, new Object[] { prRedundantCopies }));
            }
        }
    }
    String keyConstraint = regionFunctionArgs.getKeyConstraint();
    if (keyConstraint != null && !isClassNameValid(keyConstraint)) {
        throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_KEYCONSTRAINT_0_IS_INVALID, new Object[] { keyConstraint }));
    }
    String valueConstraint = regionFunctionArgs.getValueConstraint();
    if (valueConstraint != null && !isClassNameValid(valueConstraint)) {
        throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_VALUECONSTRAINT_0_IS_INVALID, new Object[] { valueConstraint }));
    }
    Set<String> cacheListeners = regionFunctionArgs.getCacheListeners();
    if (cacheListeners != null && !cacheListeners.isEmpty()) {
        for (String cacheListener : cacheListeners) {
            if (!isClassNameValid(cacheListener)) {
                throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELISTENER_0_IS_INVALID, new Object[] { cacheListener }));
            }
        }
    }
    String cacheLoader = regionFunctionArgs.getCacheLoader();
    if (cacheLoader != null && !isClassNameValid(cacheLoader)) {
        throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHELOADER_0_IS_INVALID, new Object[] { cacheLoader }));
    }
    String cacheWriter = regionFunctionArgs.getCacheWriter();
    if (cacheWriter != null && !isClassNameValid(cacheWriter)) {
        throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_CLASSNAME_FOR_CACHEWRITER_0_IS_INVALID, new Object[] { cacheWriter }));
    }
    Set<String> gatewaySenderIds = regionFunctionArgs.getGatewaySenderIds();
    if (gatewaySenderIds != null && !gatewaySenderIds.isEmpty()) {
        String[] gatewaySenders = dsMBean.listGatewaySenders();
        if (gatewaySenders.length == 0) {
            throw new IllegalArgumentException(CliStrings.CREATE_REGION__MSG__NO_GATEWAYSENDERS_IN_THE_SYSTEM);
        } else {
            List<String> gatewaySendersList = new ArrayList<>(Arrays.asList(gatewaySenders));
            gatewaySenderIds = new HashSet<>(gatewaySenderIds);
            gatewaySenderIds.removeAll(gatewaySendersList);
            if (!gatewaySenderIds.isEmpty()) {
                throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_GATEWAYSENDER_ID_UNKNOWN_0, new Object[] { gatewaySenderIds }));
            }
        }
    }
    if (regionFunctionArgs.isSetConcurrencyLevel()) {
        int concurrencyLevel = regionFunctionArgs.getConcurrencyLevel();
        if (concurrencyLevel < 0) {
            throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_POSITIVE_INT_FOR_CONCURRENCYLEVEL_0_IS_NOT_VALID, new Object[] { concurrencyLevel }));
        }
    }
    String diskStore = regionFunctionArgs.getDiskStore();
    if (diskStore != null) {
        RegionShortcut regionShortcut = regionFunctionArgs.getRegionShortcut();
        if (regionShortcut != null && !PERSISTENT_OVERFLOW_SHORTCUTS.contains(regionShortcut)) {
            String subMessage = LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString();
            String message = subMessage + ". " + CliStrings.format(CliStrings.CREATE_REGION__MSG__USE_ONE_OF_THESE_SHORTCUTS_0, new Object[] { String.valueOf(PERSISTENT_OVERFLOW_SHORTCUTS) });
            throw new IllegalArgumentException(message);
        }
        RegionAttributes<?, ?> regionAttributes = regionFunctionArgs.getRegionAttributes();
        if (regionAttributes != null && !regionAttributes.getDataPolicy().withPersistence()) {
            String subMessage = LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString();
            String message = subMessage + ". " + CliStrings.format(CliStrings.CREATE_REGION__MSG__USE_ATTRIBUTES_FROM_REGION_0_IS_NOT_WITH_PERSISTENCE, new Object[] { String.valueOf(regionFunctionArgs.getUseAttributesFrom()) });
            throw new IllegalArgumentException(message);
        }
        if (!diskStoreExists(cache, diskStore)) {
            throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_DISKSTORE_UNKNOWN_DISKSTORE_0, new Object[] { diskStore }));
        }
    }
    RegionFunctionArgs.ExpirationAttrs entryExpirationIdleTime = regionFunctionArgs.getEntryExpirationIdleTime();
    RegionFunctionArgs.ExpirationAttrs entryExpirationTTL = regionFunctionArgs.getEntryExpirationTTL();
    RegionFunctionArgs.ExpirationAttrs regionExpirationIdleTime = regionFunctionArgs.getRegionExpirationIdleTime();
    RegionFunctionArgs.ExpirationAttrs regionExpirationTTL = regionFunctionArgs.getRegionExpirationTTL();
    if ((!regionFunctionArgs.isSetStatisticsEnabled() || !regionFunctionArgs.isStatisticsEnabled()) && (entryExpirationIdleTime != null || entryExpirationTTL != null || regionExpirationIdleTime != null || regionExpirationTTL != null)) {
        String message = LocalizedStrings.AttributesFactory_STATISTICS_MUST_BE_ENABLED_FOR_EXPIRATION.toLocalizedString();
        throw new IllegalArgumentException(message + ".");
    }
    boolean compressorFailure = false;
    if (regionFunctionArgs.isSetCompressor()) {
        String compressorClassName = regionFunctionArgs.getCompressor();
        Object compressor = null;
        try {
            Class<?> compressorClass = ClassPathLoader.getLatest().forName(compressorClassName);
            compressor = compressorClass.newInstance();
        } catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) {
            compressorFailure = true;
        }
        if (compressorFailure || !(compressor instanceof Compressor)) {
            throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__INVALID_COMPRESSOR, new Object[] { regionFunctionArgs.getCompressor() }));
        }
    }
    if (regionFunctionArgs.hasPartitionAttributes()) {
        if (regionFunctionArgs.isPartitionResolverSet()) {
            String partitionResolverClassName = regionFunctionArgs.getPartitionResolver();
            try {
                Class<PartitionResolver> resolverClass = (Class<PartitionResolver>) ClassPathLoader.getLatest().forName(partitionResolverClassName);
                PartitionResolver partitionResolver = resolverClass.newInstance();
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                throw new IllegalArgumentException(CliStrings.format(CliStrings.CREATE_REGION__MSG__INVALID_PARTITION_RESOLVER, new Object[] { regionFunctionArgs.getCompressor() }), e);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) RegionShortcut(org.apache.geode.cache.RegionShortcut) ManagementService(org.apache.geode.management.ManagementService) RegionFunctionArgs(org.apache.geode.management.internal.cli.functions.RegionFunctionArgs) Compressor(org.apache.geode.compression.Compressor) PartitionResolver(org.apache.geode.cache.PartitionResolver) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) ConverterHint(org.apache.geode.management.cli.ConverterHint) DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean)

Example 13 with DistributedSystemMXBean

use of org.apache.geode.management.DistributedSystemMXBean in project geode by apache.

the class CreateAlterDestroyRegionCommands method isClusterWideSameConfig.

private static boolean isClusterWideSameConfig(InternalCache cache, String regionPath) {
    ManagementService managementService = ManagementService.getExistingManagementService(cache);
    DistributedSystemMXBean dsMXBean = managementService.getDistributedSystemMXBean();
    Set<DistributedMember> allMembers = CliUtil.getAllNormalMembers(cache);
    RegionAttributesData regionAttributesToValidateAgainst = null;
    for (DistributedMember distributedMember : allMembers) {
        ObjectName regionObjectName;
        try {
            regionObjectName = dsMXBean.fetchRegionObjectName(CliUtil.getMemberNameOrId(distributedMember), regionPath);
            RegionMXBean regionMBean = managementService.getMBeanInstance(regionObjectName, RegionMXBean.class);
            RegionAttributesData regionAttributes = regionMBean.listRegionAttributes();
            if (regionAttributesToValidateAgainst == null) {
                regionAttributesToValidateAgainst = regionAttributes;
            } else if (!(regionAttributesToValidateAgainst.getScope().equals(regionAttributes.getScope()) || regionAttributesToValidateAgainst.getDataPolicy().equals(regionAttributes.getDataPolicy()))) {
                return false;
            }
        } catch (Exception e) {
        // ignore
        }
    }
    return true;
}
Also used : DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) ManagementService(org.apache.geode.management.ManagementService) RegionAttributesData(org.apache.geode.management.RegionAttributesData) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) RegionMXBean(org.apache.geode.management.RegionMXBean) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName)

Example 14 with DistributedSystemMXBean

use of org.apache.geode.management.DistributedSystemMXBean in project geode by apache.

the class CreateAlterDestroyRegionCommands method diskStoreExists.

private boolean diskStoreExists(InternalCache cache, String diskStoreName) {
    ManagementService managementService = ManagementService.getExistingManagementService(cache);
    DistributedSystemMXBean dsMXBean = managementService.getDistributedSystemMXBean();
    Map<String, String[]> diskstore = dsMXBean.listMemberDiskstore();
    Set<Entry<String, String[]>> entrySet = diskstore.entrySet();
    for (Entry<String, String[]> entry : entrySet) {
        String[] value = entry.getValue();
        if (CliUtil.contains(value, diskStoreName)) {
            return true;
        }
    }
    return false;
}
Also used : DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) Entry(java.util.Map.Entry) ManagementService(org.apache.geode.management.ManagementService)

Example 15 with DistributedSystemMXBean

use of org.apache.geode.management.DistributedSystemMXBean in project geode by apache.

the class CliUtil method getRegionAssociatedMembers.

/**
   * Returns a Set of DistributedMember for members that have the specified <code>region</code>.
   * <code>returnAll</code> indicates whether to return all members or only the first member we
   * find.
   *
   * @param region region path for which members that have this region are required
   * @param cache cache instance to use to find members
   * @param returnAll whether to return all members or only the first member we find. Returns all
   *        when <code>true</code>
   * @return a Set of DistributedMember for members that have the specified <code>region</code>.
   */
public static Set<DistributedMember> getRegionAssociatedMembers(final String region, final InternalCache cache, boolean returnAll) {
    if (region == null || region.isEmpty()) {
        return null;
    }
    ManagementService managementService = ManagementService.getExistingManagementService(cache);
    DistributedSystemMXBean distributedSystemMXBean = managementService.getDistributedSystemMXBean();
    Set<DistributedMember> matchedMembers = new HashSet<DistributedMember>();
    Set<DistributedMember> allClusterMembers = new HashSet<DistributedMember>();
    allClusterMembers.addAll(cache.getMembers());
    allClusterMembers.add(cache.getDistributedSystem().getDistributedMember());
    for (DistributedMember member : allClusterMembers) {
        try {
            if (distributedSystemMXBean.fetchRegionObjectName(CliUtil.getMemberNameOrId(member), region) != null) {
                matchedMembers.add(member);
            }
        } catch (Exception e) {
        // ignore for now
        }
    }
    return matchedMembers;
}
Also used : DistributedSystemMXBean(org.apache.geode.management.DistributedSystemMXBean) ManagementService(org.apache.geode.management.ManagementService) DistributedMember(org.apache.geode.distributed.DistributedMember) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CacheClosedException(org.apache.geode.cache.CacheClosedException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

DistributedSystemMXBean (org.apache.geode.management.DistributedSystemMXBean)22 ManagementService (org.apache.geode.management.ManagementService)15 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)8 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)5 ObjectName (javax.management.ObjectName)4 DistributedMember (org.apache.geode.distributed.DistributedMember)4 InternalCache (org.apache.geode.internal.cache.InternalCache)3 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2 MBeanServer (javax.management.MBeanServer)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 DistributedRegionMXBean (org.apache.geode.management.DistributedRegionMXBean)2 ConverterHint (org.apache.geode.management.cli.ConverterHint)2 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)2 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1