Search in sources :

Example 21 with ManagementService

use of org.apache.geode.management.ManagementService 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 22 with ManagementService

use of org.apache.geode.management.ManagementService 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 23 with ManagementService

use of org.apache.geode.management.ManagementService 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)

Example 24 with ManagementService

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

the class ClientCommands method listClient.

@CliCommand(value = CliStrings.LIST_CLIENTS, help = CliStrings.LIST_CLIENT__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_CLIENT })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listClient() {
    Result result = null;
    try {
        CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
        SectionResultData section = compositeResultData.addSection("section1");
        TabularResultData resultTable = section.addTable("TableForClientList");
        String headerText = "ClientList";
        resultTable = resultTable.setHeader(headerText);
        InternalCache cache = getCache();
        ManagementService service = ManagementService.getExistingManagementService(cache);
        ObjectName[] cacheServers = service.getDistributedSystemMXBean().listCacheServerObjectNames();
        if (cacheServers.length == 0) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_CLIENT_COULD_NOT_RETRIEVE_SERVER_LIST));
        }
        Map<String, List<String>> clientServerMap = new HashMap<String, List<String>>();
        for (ObjectName objName : cacheServers) {
            CacheServerMXBean serverMbean = service.getMBeanInstance(objName, CacheServerMXBean.class);
            String[] listOfClient = serverMbean.getClientIds();
            if (listOfClient == null || listOfClient.length == 0) {
                continue;
            }
            for (String clietName : listOfClient) {
                String serverDetails = "member=" + objName.getKeyProperty("member") + ",port=" + objName.getKeyProperty("port");
                if (clientServerMap.containsKey(clietName)) {
                    List<String> listServers = clientServerMap.get(clietName);
                    listServers.add(serverDetails);
                } else {
                    List<String> listServer = new ArrayList<String>();
                    listServer.add(serverDetails);
                    clientServerMap.put(clietName, listServer);
                }
            }
        }
        if (clientServerMap.size() == 0) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_COULD_NOT_RETRIEVE_CLIENT_LIST));
        }
        String memberSeparator = ";  ";
        Iterator<Entry<String, List<String>>> it = clientServerMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, List<String>> pairs = (Map.Entry<String, List<String>>) it.next();
            String client = (String) pairs.getKey();
            List<String> servers = (List<String>) pairs.getValue();
            StringBuilder serverListForClient = new StringBuilder();
            int serversSize = servers.size();
            int i = 0;
            for (String server : servers) {
                serverListForClient.append(server);
                if (i < serversSize - 1) {
                    serverListForClient.append(memberSeparator);
                }
                i++;
            }
            resultTable.accumulate(CliStrings.LIST_CLIENT_COLUMN_Clients, client);
            resultTable.accumulate(CliStrings.LIST_CLIENT_COLUMN_SERVERS, serverListForClient.toString());
        }
        result = ResultBuilder.buildResult(compositeResultData);
    } catch (Exception e) {
        LogWrapper.getInstance().warning("Error in list clients. stack trace" + CliUtil.stackTraceAsString(e));
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_CLIENT_COULD_NOT_RETRIEVE_CLIENT_LIST_0, e.getMessage()));
    }
    LogWrapper.getInstance().info("list client result " + result);
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) Result(org.apache.geode.management.cli.Result) ObjectName(javax.management.ObjectName) Entry(java.util.Map.Entry) ManagementService(org.apache.geode.management.ManagementService) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 25 with ManagementService

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

the class TestRemoteClusterDUnitTest method checkSenderMBean.

/**
   * Checks whether a GatewayReceiverMBean is created or not
   * 
   * @param vm reference to VM
   */
@SuppressWarnings("serial")
protected void checkSenderMBean(final VM vm, final String regionPath) {
    SerializableRunnable checkMBean = new SerializableRunnable("Check Sender MBean") {

        public void run() {
            Cache cache = GemFireCacheImpl.getInstance();
            ManagementService service = ManagementService.getManagementService(cache);
            GatewaySenderMXBean bean = service.getLocalGatewaySenderMXBean("pn");
            assertNotNull(bean);
            assertTrue(bean.isConnected());
            ObjectName regionBeanName = service.getRegionMBeanName(cache.getDistributedSystem().getDistributedMember(), "/" + regionPath);
            RegionMXBean rBean = service.getMBeanInstance(regionBeanName, RegionMXBean.class);
            assertTrue(rBean.isGatewayEnabled());
        }
    };
    vm.invoke(checkMBean);
}
Also used : ManagementService(org.apache.geode.management.ManagementService) RegionMXBean(org.apache.geode.management.RegionMXBean) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) GatewaySenderMXBean(org.apache.geode.management.GatewaySenderMXBean) Cache(org.apache.geode.cache.Cache) ObjectName(javax.management.ObjectName)

Aggregations

ManagementService (org.apache.geode.management.ManagementService)36 DistributedSystemMXBean (org.apache.geode.management.DistributedSystemMXBean)15 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)11 Cache (org.apache.geode.cache.Cache)8 InternalCache (org.apache.geode.internal.cache.InternalCache)8 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)8 DistributedRegionMXBean (org.apache.geode.management.DistributedRegionMXBean)7 DistributedMember (org.apache.geode.distributed.DistributedMember)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 ObjectName (javax.management.ObjectName)4 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)4 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)4 VM (org.apache.geode.test.dunit.VM)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Entry (java.util.Map.Entry)3 Properties (java.util.Properties)3 MalformedObjectNameException (javax.management.MalformedObjectNameException)3