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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations