use of javax.management.DynamicMBean in project ignite by apache.
the class IgniteClusterSnapshotRestoreMetricsTest method testRestoreSnapshotProgress.
/**
* @throws Exception If fails.
*/
@Test
public void testRestoreSnapshotProgress() throws Exception {
// Caches with differebt partition distribution.
CacheConfiguration<Integer, Object> ccfg1 = cacheConfig("cache1").setBackups(0);
CacheConfiguration<Integer, Object> ccfg2 = cacheConfig("cache2").setCacheMode(CacheMode.REPLICATED);
Ignite ignite = startGridsWithCache(DEDICATED_CNT, CACHE_KEYS_RANGE, key -> new Account(key, key), ccfg1, ccfg2);
ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get(TIMEOUT);
ignite.destroyCaches(F.asList(ccfg1.getName(), ccfg2.getName()));
awaitPartitionMapExchange();
// Add new empty node.
IgniteEx emptyNode = startGrid(DEDICATED_CNT);
resetBaselineTopology();
checkMetricsDefaults();
Set<String> grpNames = new HashSet<>(F.asList(ccfg1.getName(), ccfg2.getName()));
ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, grpNames);
for (Ignite grid : G.allGrids()) {
DynamicMBean mReg = metricRegistry(grid.name(), null, SNAPSHOT_RESTORE_METRICS);
String nodeNameMsg = "node=" + grid.name();
assertTrue(nodeNameMsg, GridTestUtils.waitForCondition(() -> getNumMetric("endTime", mReg) > 0, TIMEOUT));
int expParts = ((IgniteEx) grid).cachex(ccfg1.getName()).context().topology().localPartitions().size() + ((IgniteEx) grid).cachex(ccfg2.getName()).context().topology().localPartitions().size();
// Cache2 is replicated - the index partition is being copied (on snapshot data nodes).
if (!emptyNode.name().equals(grid.name()))
expParts += 1;
assertEquals(nodeNameMsg, SNAPSHOT_NAME, mReg.getAttribute("snapshotName"));
assertEquals(nodeNameMsg, "", mReg.getAttribute("error"));
assertFalse(nodeNameMsg, ((String) mReg.getAttribute("requestId")).isEmpty());
assertEquals(nodeNameMsg, expParts, getNumMetric("totalPartitions", mReg));
assertEquals(nodeNameMsg, expParts, getNumMetric("processedPartitions", mReg));
long startTime = getNumMetric("startTime", mReg);
long endTime = getNumMetric("endTime", mReg);
assertTrue(nodeNameMsg, startTime > 0);
assertTrue(nodeNameMsg, endTime >= startTime);
}
assertSnapshotCacheKeys(ignite.cache(ccfg1.getName()));
assertSnapshotCacheKeys(ignite.cache(ccfg2.getName()));
}
use of javax.management.DynamicMBean in project ignite by apache.
the class IgniteClusterSnapshotRestoreMetricsTest method testRestoreSnapshotError.
/**
* @throws Exception If fails.
*/
@Test
public void testRestoreSnapshotError() throws Exception {
dfltCacheCfg.setCacheMode(CacheMode.REPLICATED);
IgniteEx ignite = startGridsWithSnapshot(2, CACHE_KEYS_RANGE);
String failingFilePath = Paths.get(FilePageStoreManager.cacheDirName(dfltCacheCfg), PART_FILE_PREFIX + (dfltCacheCfg.getAffinity().partitions() / 2) + FILE_SUFFIX).toString();
FileIOFactory ioFactory = new RandomAccessFileIOFactory();
String testErrMsg = "Test exception";
ignite.context().cache().context().snapshotMgr().ioFactory((file, modes) -> {
FileIO delegate = ioFactory.create(file, modes);
if (file.getPath().endsWith(failingFilePath))
throw new RuntimeException(testErrMsg);
return delegate;
});
checkMetricsDefaults();
ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, null);
for (Ignite grid : G.allGrids()) {
DynamicMBean mReg = metricRegistry(grid.name(), null, SNAPSHOT_RESTORE_METRICS);
String nodeNameMsg = "node=" + grid.name();
assertTrue(nodeNameMsg, GridTestUtils.waitForCondition(() -> getNumMetric("endTime", mReg) > 0, TIMEOUT));
long startTime = getNumMetric("startTime", mReg);
long endTime = getNumMetric("endTime", mReg);
assertEquals(nodeNameMsg, SNAPSHOT_NAME, mReg.getAttribute("snapshotName"));
assertFalse(nodeNameMsg, ((String) mReg.getAttribute("requestId")).isEmpty());
assertTrue(nodeNameMsg, startTime > 0);
assertTrue(nodeNameMsg, endTime >= startTime);
assertTrue(nodeNameMsg, ((String) mReg.getAttribute("error")).contains(testErrMsg));
}
}
use of javax.management.DynamicMBean in project spring-framework by spring-projects.
the class MBeanExporter method registerBeanInstance.
/**
* Registers an existing MBean or an MBean adapter for a plain bean
* with the {@code MBeanServer}.
* @param bean the bean to register, either an MBean or a plain bean
* @param beanKey the key associated with this bean in the beans map
* @return the {@code ObjectName} under which the bean was registered
* with the {@code MBeanServer}
*/
private ObjectName registerBeanInstance(Object bean, String beanKey) throws JMException {
ObjectName objectName = getObjectName(bean, beanKey);
Object mbeanToExpose = null;
if (isMBean(bean.getClass())) {
mbeanToExpose = bean;
} else {
DynamicMBean adaptedBean = adaptMBeanIfPossible(bean);
if (adaptedBean != null) {
mbeanToExpose = adaptedBean;
}
}
if (mbeanToExpose != null) {
if (logger.isDebugEnabled()) {
logger.debug("Located MBean '" + beanKey + "': registering with JMX server as MBean [" + objectName + "]");
}
doRegister(mbeanToExpose, objectName);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Located managed bean '" + beanKey + "': registering with JMX server as MBean [" + objectName + "]");
}
ModelMBean mbean = createAndConfigureMBean(bean, beanKey);
doRegister(mbean, objectName);
injectNotificationPublisherIfNecessary(bean, mbean, objectName);
}
return objectName;
}
use of javax.management.DynamicMBean in project tomcat by apache.
the class Registry method registerComponent.
/**
* Register a component
*
* @param bean The bean
* @param oname The object name
* @param type The registry type
* @throws Exception Error registering component
*/
public void registerComponent(Object bean, ObjectName oname, String type) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Managed= " + oname);
}
if (bean == null) {
log.error(sm.getString("registry.nullBean", oname));
return;
}
try {
if (type == null) {
type = bean.getClass().getName();
}
ManagedBean managed = findManagedBean(null, bean.getClass(), type);
// The real mbean is created and registered
DynamicMBean mbean = managed.createMBean(bean);
if (getMBeanServer().isRegistered(oname)) {
if (log.isDebugEnabled()) {
log.debug("Unregistering existing component " + oname);
}
getMBeanServer().unregisterMBean(oname);
}
getMBeanServer().registerMBean(mbean, oname);
} catch (Exception ex) {
log.error(sm.getString("registry.registerError", oname), ex);
throw ex;
}
}
use of javax.management.DynamicMBean in project tomcat by apache.
the class BaseModelMBean method invoke.
/**
* Invoke a particular method on this MBean, and return any returned
* value.
*
* <p><strong>IMPLEMENTATION NOTE</strong> - This implementation will
* attempt to invoke this method on the MBean itself, or (if not
* available) on the managed resource object associated with this
* MBean.</p>
*
* @param name Name of the operation to be invoked
* @param params Array containing the method parameters of this operation
* @param signature Array containing the class names representing
* the signature of this operation
*
* @exception MBeanException if the initializer of an object
* throws an exception
* @exception ReflectionException if a Java reflection exception
* occurs when invoking a method
*/
@Override
public Object invoke(String name, Object[] params, String[] signature) throws MBeanException, ReflectionException {
if ((resource instanceof DynamicMBean) && !(resource instanceof BaseModelMBean)) {
return ((DynamicMBean) resource).invoke(name, params, signature);
}
// Validate the input parameters
if (name == null) {
throw new RuntimeOperationsException(new IllegalArgumentException(sm.getString("baseModelMBean.nullMethodName")), sm.getString("baseModelMBean.nullMethodName"));
}
if (log.isDebugEnabled()) {
log.debug("Invoke " + name);
}
Method method = managedBean.getInvoke(name, params, signature, this, resource);
// Invoke the selected method on the appropriate object
Object result = null;
try {
if (method.getDeclaringClass().isAssignableFrom(this.getClass())) {
result = method.invoke(this, params);
} else {
result = method.invoke(resource, params);
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
log.error(sm.getString("baseModelMBean.invokeError", name), t);
if (t == null) {
t = e;
}
if (t instanceof RuntimeException) {
throw new RuntimeOperationsException((RuntimeException) t, sm.getString("baseModelMBean.invokeError", name));
} else if (t instanceof Error) {
throw new RuntimeErrorException((Error) t, sm.getString("baseModelMBean.invokeError", name));
} else {
throw new MBeanException((Exception) t, sm.getString("baseModelMBean.invokeError", name));
}
} catch (Exception e) {
log.error(sm.getString("baseModelMBean.invokeError", name), e);
throw new MBeanException(e, sm.getString("baseModelMBean.invokeError", name));
}
// FIXME - should we validate the return type?
return result;
}
Aggregations