use of org.apache.geode.management.ManagementException in project geode by apache.
the class MBeanProxyFactory method createProxy.
/**
* Creates a single proxy and adds a {@link ProxyInfo} to proxy repository
* {@link MBeanProxyInfoRepository}
*
* @param member {@link org.apache.geode.distributed.DistributedMember}
* @param objectName {@link javax.management.ObjectName} of the Bean
* @param monitoringRegion monitoring region containing the proxies
* @throws ManagementException
*/
public void createProxy(DistributedMember member, ObjectName objectName, Region<String, Object> monitoringRegion, Object newVal) {
try {
if (remoteFilterChain.isFiltered(objectName, member, "")) {
if (logger.isTraceEnabled()) {
logger.trace("Returning from filter");
}
return;
}
Class interfaceClass = ClassLoadUtil.classFromName(((FederationComponent) monitoringRegion.get(objectName.toString())).getMBeanInterfaceClass());
Object object = MBeanProxyInvocationHandler.newProxyInstance(member, monitoringRegion, objectName, interfaceClass);
jmxAdapter.registerMBeanProxy(object, objectName);
if (logger.isDebugEnabled()) {
logger.debug("Registered ObjectName : {}", objectName);
}
ProxyInfo proxyInfo = new ProxyInfo(interfaceClass, object, objectName);
proxyRepo.addProxyToRepository(member, proxyInfo);
service.afterCreateProxy(objectName, interfaceClass, object, (FederationComponent) newVal);
if (logger.isDebugEnabled()) {
logger.debug("Proxy Created for : {}", objectName);
}
} catch (ClassNotFoundException e) {
throw new ManagementException(e);
} catch (IntrospectionException e) {
throw new ManagementException(e);
} catch (ManagementException e) {
throw e;
}
}
use of org.apache.geode.management.ManagementException in project geode by apache.
the class LocalManager method startLocalManagement.
/**
* Managed Node side resources are created
*
* Management Region : its a Replicated NO_ACK region Notification Region : its a Replicated Proxy
* NO_ACK region
*/
private void startLocalManagement(Map<ObjectName, FederationComponent> federatedComponentMap) {
synchronized (this) {
if (repo.getLocalMonitoringRegion() != null) {
return;
} else {
ThreadFactory tf = new ThreadFactory() {
public Thread newThread(final Runnable command) {
final Runnable r = new Runnable() {
public void run() {
command.run();
}
};
final ThreadGroup group = LoggingThreadGroup.createThreadGroup(ManagementStrings.MANAGEMENT_TASK_THREAD_GROUP.toLocalizedString(), logger);
Thread thread = new Thread(group, r, ManagementStrings.MANAGEMENT_TASK.toLocalizedString());
thread.setDaemon(true);
return thread;
}
};
singleThreadFederationScheduler = Executors.newSingleThreadScheduledExecutor(tf);
if (logger.isDebugEnabled()) {
logger.debug("Creating Management Region :");
}
/*
* Sharing the same Internal Argument for both notification region and monitoring region
*/
InternalRegionArguments internalArgs = new InternalRegionArguments();
internalArgs.setIsUsedForMetaRegion(true);
// Create anonymous stats holder for Management Regions
final HasCachePerfStats monitoringRegionStats = new HasCachePerfStats() {
public CachePerfStats getCachePerfStats() {
return new CachePerfStats(cache.getDistributedSystem(), "managementRegionStats");
}
};
internalArgs.setCachePerfStatsHolder(monitoringRegionStats);
AttributesFactory<String, Object> monitorRegionAttributeFactory = new AttributesFactory<String, Object>();
monitorRegionAttributeFactory.setScope(Scope.DISTRIBUTED_NO_ACK);
monitorRegionAttributeFactory.setDataPolicy(DataPolicy.REPLICATE);
monitorRegionAttributeFactory.setConcurrencyChecksEnabled(false);
MonitoringRegionCacheListener localListener = new MonitoringRegionCacheListener(service);
monitorRegionAttributeFactory.addCacheListener(localListener);
RegionAttributes<String, Object> monitoringRegionAttrs = monitorRegionAttributeFactory.create();
AttributesFactory<NotificationKey, Notification> notificationRegionAttributeFactory = new AttributesFactory<NotificationKey, Notification>();
notificationRegionAttributeFactory.setScope(Scope.DISTRIBUTED_NO_ACK);
notificationRegionAttributeFactory.setDataPolicy(DataPolicy.EMPTY);
notificationRegionAttributeFactory.setConcurrencyChecksEnabled(false);
RegionAttributes<NotificationKey, Notification> notifRegionAttrs = notificationRegionAttributeFactory.create();
String appender = MBeanJMXAdapter.getUniqueIDForMember(cache.getDistributedSystem().getDistributedMember());
boolean monitoringRegionCreated = false;
boolean notifRegionCreated = false;
try {
repo.setLocalMonitoringRegion(cache.createVMRegion(ManagementConstants.MONITORING_REGION + "_" + appender, monitoringRegionAttrs, internalArgs));
monitoringRegionCreated = true;
} catch (TimeoutException e) {
throw new ManagementException(e);
} catch (RegionExistsException e) {
throw new ManagementException(e);
} catch (IOException e) {
throw new ManagementException(e);
} catch (ClassNotFoundException e) {
throw new ManagementException(e);
}
try {
repo.setLocalNotificationRegion(cache.createVMRegion(ManagementConstants.NOTIFICATION_REGION + "_" + appender, notifRegionAttrs, internalArgs));
notifRegionCreated = true;
} catch (TimeoutException e) {
throw new ManagementException(e);
} catch (RegionExistsException e) {
throw new ManagementException(e);
} catch (IOException e) {
throw new ManagementException(e);
} catch (ClassNotFoundException e) {
throw new ManagementException(e);
} finally {
if (!notifRegionCreated && monitoringRegionCreated) {
repo.getLocalMonitoringRegion().localDestroyRegion();
}
}
managementTask = new ManagementTask(federatedComponentMap);
// call run to get us initialized immediately with a sync call
managementTask.run();
// All local resources are created for the ManagementTask
// Now Management tasks can proceed.
int updateRate = cache.getInternalDistributedSystem().getConfig().getJmxManagerUpdateRate();
singleThreadFederationScheduler.scheduleAtFixedRate(managementTask, updateRate, updateRate, TimeUnit.MILLISECONDS);
if (logger.isDebugEnabled()) {
logger.debug("Management Region created with Name : {}", repo.getLocalMonitoringRegion().getName());
logger.debug("Notification Region created with Name : {}", repo.getLocalNotificationRegion().getName());
}
}
}
}
use of org.apache.geode.management.ManagementException in project geode by apache.
the class FederatingManager method startManagingActivity.
/**
* This method will be invoked when a node transitions from managed node to managing node This
* method will block for all GIIs to be completed But each GII is given a specific time frame.
* After that the task will be marked as cancelled.
*/
public void startManagingActivity() throws Exception {
final boolean isDebugEnabled = logger.isDebugEnabled();
Set<DistributedMember> members = cache.getDistributionManager().getOtherDistributionManagerIds();
Iterator<DistributedMember> it = members.iterator();
DistributedMember member;
final List<Callable<DistributedMember>> giiTaskList = new ArrayList<>();
List<Future<DistributedMember>> futureTaskList;
while (it.hasNext()) {
member = it.next();
giiTaskList.add(new GIITask(member));
}
try {
if (isDebugEnabled) {
logger.debug("Management Resource creation started : ");
}
futureTaskList = pooledMembershipExecutor.invokeAll(giiTaskList);
for (Future<DistributedMember> futureTask : futureTaskList) {
String memberId = null;
try {
DistributedMember returnedMember = futureTask.get();
if (returnedMember != null) {
memberId = returnedMember.getId();
}
if (futureTask.isDone()) {
if (isDebugEnabled) {
logger.debug("Monitoring Resource Created for : {}", memberId);
}
}
if (futureTask.isCancelled()) {
// Retry mechanism can be added here after discussions
if (isDebugEnabled) {
logger.debug("Monitoring resource Creation Failed for : {}", memberId);
}
}
} catch (ExecutionException e) {
if (isDebugEnabled) {
logger.debug("ExecutionException during Management GII: {}", e.getMessage(), e);
}
} catch (CancellationException e) {
if (isDebugEnabled) {
ManagementException mgEx = new ManagementException(e.fillInStackTrace());
logger.debug("InterruptedException while creating Monitoring resource with error : {}", mgEx.getMessage(), mgEx);
}
}
}
} catch (InterruptedException e) {
if (isDebugEnabled) {
ManagementException mgEx = new ManagementException(e.fillInStackTrace());
logger.debug("InterruptedException while creating Monitoring resource with error : ", mgEx.getMessage(), mgEx);
}
} finally {
if (isDebugEnabled) {
logger.debug("Management Resource creation completed");
}
}
}
use of org.apache.geode.management.ManagementException in project geode by apache.
the class FederatingManager method stopManagingActivity.
/**
* This method will be invoked whenever a member stops being a managing node. The exception
* Management exception has to be handled by the caller. *
*/
private void stopManagingActivity() {
try {
this.pooledMembershipExecutor.shutdownNow();
Iterator<DistributedMember> it = repo.getMonitoringRegionMap().keySet().iterator();
while (it.hasNext()) {
removeMemberArtifacts(it.next(), false);
}
} catch (Exception e) {
throw new ManagementException(e);
}
}
use of org.apache.geode.management.ManagementException in project geode by apache.
the class NotificationHub method addHubNotificationListener.
/**
* Adds a NotificationHubListener
*
* @param objectName
*/
public void addHubNotificationListener(String memberName, ObjectName objectName) {
try {
synchronized (listenerObjectMap) {
NotificationHubListener listener = listenerObjectMap.get(objectName);
if (listener == null) {
listener = new NotificationHubListener(objectName);
listener.incNumCounter();
mbeanServer.addNotificationListener(objectName, listener, null, null);
listenerObjectMap.put(objectName, listener);
} else {
listener.incNumCounter();
}
}
} catch (InstanceNotFoundException e) {
throw new ManagementException(e);
}
}
Aggregations