Search in sources :

Example 11 with FileSystemXmlApplicationContext

use of org.springframework.context.support.FileSystemXmlApplicationContext in project ignite by apache.

the class GridJobLoadTest method startNode.

/**
     * Starts new grid node.
     *
     * @param igniteInstanceName name of new node.
     * @param springCfg file with spring configuration to use for this node.
     * @return a grid instance local to new node {@link org.apache.ignite.Ignition#start(org.apache.ignite.configuration.IgniteConfiguration)}.
     * @throws Exception if node run failed.
     */
protected Ignite startNode(String igniteInstanceName, File springCfg) throws Exception {
    assert springCfg != null;
    ListableBeanFactory springCtx = new FileSystemXmlApplicationContext("file:///" + springCfg.getAbsolutePath());
    Map cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
    assert cfgMap != null;
    assert !cfgMap.isEmpty();
    IgniteConfiguration cfg = (IgniteConfiguration) cfgMap.values().iterator().next();
    cfg.setIgniteInstanceName(igniteInstanceName + "-" + getNextNodeNum());
    return G.start(cfg);
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Map(java.util.Map) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Example 12 with FileSystemXmlApplicationContext

use of org.springframework.context.support.FileSystemXmlApplicationContext 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.
     */
@SuppressWarnings("unchecked")
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;
}
Also used : NullAppender(org.apache.log4j.varia.NullAppender) Appender(org.apache.log4j.Appender) MalformedURLException(java.net.MalformedURLException) NullAppender(org.apache.log4j.varia.NullAppender) ArrayList(java.util.ArrayList) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Collection(java.util.Collection) File(java.io.File) Map(java.util.Map) BeansException(org.springframework.beans.BeansException)

Example 13 with FileSystemXmlApplicationContext

use of org.springframework.context.support.FileSystemXmlApplicationContext 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.
     */
@SuppressWarnings("unchecked")
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;
}
Also used : NullAppender(org.apache.log4j.varia.NullAppender) Appender(org.apache.log4j.Appender) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) MalformedURLException(java.net.MalformedURLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) NullAppender(org.apache.log4j.varia.NullAppender) File(java.io.File) Map(java.util.Map) BeansException(org.springframework.beans.BeansException) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)

Example 14 with FileSystemXmlApplicationContext

use of org.springframework.context.support.FileSystemXmlApplicationContext in project ignite by apache.

the class GridSingleExecutionTest method getConfigurations.

/**
     * Initializes configurations.
     *
     * @param springCfgPath Configuration file path.
     * @param log Log file name.
     * @return List of configurations.
     * @throws IgniteCheckedException If failed..
     */
@SuppressWarnings("unchecked")
private static Iterable<IgniteConfiguration> getConfigurations(String springCfgPath, String log) 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()) {
        UUID nodeId = UUID.randomUUID();
        cfg.setNodeId(nodeId);
        cfg.setGridLogger(initLogger(log));
        res.add(cfg);
    }
    return res;
}
Also used : NullAppender(org.apache.log4j.varia.NullAppender) Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) RollingFileAppender(org.apache.log4j.RollingFileAppender) MalformedURLException(java.net.MalformedURLException) NullAppender(org.apache.log4j.varia.NullAppender) ArrayList(java.util.ArrayList) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Collection(java.util.Collection) UUID(java.util.UUID) File(java.io.File) Map(java.util.Map) BeansException(org.springframework.beans.BeansException)

Example 15 with FileSystemXmlApplicationContext

use of org.springframework.context.support.FileSystemXmlApplicationContext in project ignite by apache.

the class GridCacheAbstractLoadTest method configuration.

/**
     * Initializes configurations.
     *
     * @param springCfgPath Configuration file path.
     * @param log Log file name.
     * @return Configuration.
     * @throws IgniteCheckedException If fails.
     */
@SuppressWarnings("unchecked")
protected IgniteConfiguration configuration(String springCfgPath, String log) 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);
    else if (cfgMap.size() > 1)
        throw new IgniteCheckedException("More than one configuration provided for cache load test: " + cfgMap.values());
    IgniteConfiguration cfg = (IgniteConfiguration) cfgMap.values().iterator().next();
    cfg.setGridLogger(initLogger(log));
    cfg.getTransactionConfiguration().setDefaultTxIsolation(isolation);
    cfg.getTransactionConfiguration().setDefaultTxConcurrency(concurrency);
    return cfg;
}
Also used : NullAppender(org.apache.log4j.varia.NullAppender) Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) RollingFileAppender(org.apache.log4j.RollingFileAppender) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) MalformedURLException(java.net.MalformedURLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) NullAppender(org.apache.log4j.varia.NullAppender) File(java.io.File) Map(java.util.Map) BeansException(org.springframework.beans.BeansException)

Aggregations

FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)16 ApplicationContext (org.springframework.context.ApplicationContext)10 File (java.io.File)8 Map (java.util.Map)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 BeansException (org.springframework.beans.BeansException)5 MalformedURLException (java.net.MalformedURLException)4 ArrayList (java.util.ArrayList)4 Appender (org.apache.log4j.Appender)4 NullAppender (org.apache.log4j.varia.NullAppender)4 CommandLine (org.apache.commons.cli.CommandLine)3 CommandLineParser (org.apache.commons.cli.CommandLineParser)3 GnuParser (org.apache.commons.cli.GnuParser)3 Options (org.apache.commons.cli.Options)3 ParseException (org.apache.commons.cli.ParseException)3 URL (java.net.URL)2 Collection (java.util.Collection)2 ConsoleAppender (org.apache.log4j.ConsoleAppender)2 RollingFileAppender (org.apache.log4j.RollingFileAppender)2