use of org.springframework.beans.BeansException in project ignite by apache.
the class GridRandomCommandLineLoader method getConfiguration.
/**
* Initializes configurations.
*
* @param springCfgPath Configuration file path.
* @param logCfgPath Log file name.
* @return List of configurations.
* @throws IgniteCheckedException If an error occurs.
*/
private static IgniteConfiguration getConfiguration(String springCfgPath, @Nullable String logCfgPath) throws IgniteCheckedException {
assert springCfgPath != null;
File path = GridTestUtils.resolveIgnitePath(springCfgPath);
if (path == null)
throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
if (!path.isFile())
throw new IgniteCheckedException("Provided file path is not a file: " + path);
// Add no-op logger to remove no-appender warning.
Appender app = new NullAppender();
Logger.getRootLogger().addAppender(app);
ApplicationContext springCtx;
try {
springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
} catch (BeansException | MalformedURLException e) {
throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
}
Map cfgMap;
try {
// Note: Spring is not generics-friendly.
cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
} catch (BeansException e) {
throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
}
if (cfgMap == null)
throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
// Remove previously added no-op logger.
Logger.getRootLogger().removeAppender(app);
if (cfgMap.size() != 1)
throw new IgniteCheckedException("Spring configuration file should contain exactly 1 grid configuration: " + path);
IgniteConfiguration cfg = (IgniteConfiguration) F.first(cfgMap.values());
assert cfg != null;
if (logCfgPath != null)
cfg.setGridLogger(new GridTestLog4jLogger(U.resolveIgniteUrl(logCfgPath)));
return cfg;
}
use of org.springframework.beans.BeansException in project ignite by apache.
the class GridVmNodesStarter method getConfigurations.
/**
* Initializes configurations.
*
* @param springCfgPath Configuration file path.
* @return List of configurations.
* @throws IgniteCheckedException If an error occurs.
*/
private static Iterable<IgniteConfiguration> getConfigurations(String springCfgPath) throws IgniteCheckedException {
File path = GridTestUtils.resolveIgnitePath(springCfgPath);
if (path == null)
throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
if (!path.isFile())
throw new IgniteCheckedException("Provided file path is not a file: " + path);
// Add no-op logger to remove no-appender warning.
Appender app = new NullAppender();
Logger.getRootLogger().addAppender(app);
ApplicationContext springCtx;
try {
springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
} catch (BeansException | MalformedURLException e) {
throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
}
Map cfgMap;
try {
// Note: Spring is not generics-friendly.
cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
} catch (BeansException e) {
throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
}
if (cfgMap == null)
throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
// Remove previously added no-op logger.
Logger.getRootLogger().removeAppender(app);
if (cfgMap.isEmpty())
throw new IgniteCheckedException("Can't find grid factory configuration in: " + path);
Collection<IgniteConfiguration> res = new ArrayList<>();
for (IgniteConfiguration cfg : (Collection<IgniteConfiguration>) cfgMap.values()) {
res.add(cfg);
cfg.setIgniteInstanceName(IGNITE_INSTANCE_NAME_PREF + gridCnt.incrementAndGet());
}
return res;
}
use of org.springframework.beans.BeansException in project ignite by apache.
the class IgniteCacheRandomOperationBenchmark method createAdditionalCaches.
/**
* Creates additional caches.
*
* @throws Exception If failed.
*/
private void createAdditionalCaches() throws Exception {
Map<String, CacheConfiguration> cfgMap;
try {
// Loading spring application context and getting all of the caches configurations in the map.
cfgMap = IgniteNode.loadConfiguration(args.configuration()).get2().getBeansOfType(CacheConfiguration.class);
} catch (BeansException e) {
throw new Exception("Failed to instantiate bean [type=" + CacheConfiguration.class + ", err=" + e.getMessage() + ']', e);
}
if (cfgMap == null || cfgMap.isEmpty())
throw new Exception("Failed to find cache configurations in: " + args.configuration());
// Getting cache configuration from the map using name specified in property file.
CacheConfiguration<Object, Object> ccfg = cfgMap.get(args.additionalCachesName());
if (ccfg == null)
throw new Exception("Failed to find cache configuration [cache=" + args.additionalCachesName() + ", cfg=" + args.configuration() + ']');
for (int i = 0; i < args.additionalCachesNumber(); i++) {
CacheConfiguration<Object, Object> newCfg = new CacheConfiguration<>(ccfg);
newCfg.setName("additional_" + args.additionalCachesName() + "_cache_" + i);
try {
ignite().createCache(newCfg);
} catch (CacheException e) {
BenchmarkUtils.error("Failed to create additional cache [ name = " + args.additionalCachesName() + ", err" + e.getMessage() + ']', e);
}
}
}
use of org.springframework.beans.BeansException in project ignite by apache.
the class IgniteNode method loadConfiguration.
/**
* @param springCfgPath Spring configuration file path.
* @return Tuple with grid configuration and Spring application context.
* @throws Exception If failed.
*/
public static IgniteBiTuple<IgniteConfiguration, ? extends ApplicationContext> loadConfiguration(String springCfgPath) throws Exception {
URL url;
try {
url = new URL(springCfgPath);
} catch (MalformedURLException e) {
url = IgniteUtils.resolveIgniteUrl(springCfgPath);
if (url == null)
throw new IgniteCheckedException("Spring XML configuration path is invalid: " + springCfgPath + ". Note that this path should be either absolute or a relative local file system path, " + "relative to META-INF in classpath or valid URL to IGNITE_HOME.", e);
}
GenericApplicationContext springCtx;
try {
springCtx = new GenericApplicationContext();
new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(url));
springCtx.refresh();
} catch (BeansException e) {
throw new Exception("Failed to instantiate Spring XML application context [springUrl=" + url + ", err=" + e.getMessage() + ']', e);
}
Map<String, IgniteConfiguration> cfgMap;
try {
cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
} catch (BeansException e) {
throw new Exception("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
}
if (cfgMap == null || cfgMap.isEmpty())
throw new Exception("Failed to find ignite configuration in: " + url);
return new IgniteBiTuple<>(cfgMap.values().iterator().next(), springCtx);
}
use of org.springframework.beans.BeansException in project CzechIdMng by bcvsolutions.
the class DatabaseTableMonitoringEvaluator method evaluate.
@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
String serviceName = getParameterConverter().toString(monitoring.getEvaluatorProperties(), PARAMETER_READ_SERVICE_BEAN_NAME);
Object bean;
try {
bean = context.getBean(serviceName);
if (bean == null || !(bean instanceof ReadDtoService<?, ?>)) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", serviceName));
}
} catch (BeansException ex) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", serviceName), ex);
}
//
ReadDtoService<?, ?> readService = (ReadDtoService<?, ?>) bean;
long treshold = getParameterConverter().toLong(monitoring.getEvaluatorProperties(), PARAMETER_THRESHOLD, DEFAULT_THRESHOLD);
long count = readService.count(null);
ResultModel resultModel = new DefaultResultModel(CoreResultCode.MONITORING_DATABASE_TABLE, ImmutableMap.of("tableName", String.valueOf(getTableName(readService)), "dtoName", String.valueOf(getDtoName(readService)), "count", Long.toString(count)));
IdmMonitoringResultDto result = new IdmMonitoringResultDto();
result.setValue(Long.toString(count));
result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
if (treshold < count) {
result.setLevel(NotificationLevel.WARNING);
}
//
return result;
}
Aggregations