Search in sources :

Example 1 with GridSpringResourceContext

use of org.apache.ignite.internal.processors.resource.GridSpringResourceContext in project ignite by apache.

the class HadoopIgfsInProc method create.

/**
 * Creates instance of the HadoopIgfsInProcWithIgniteRefsCount by IGFS name, ignite client node is created
 * if necessary.
 *
 * @param igniteCfgPath Path to ignite configuration.
 * @param igfsName Target IGFS name.
 * @param log Log.
 * @param userName User name.
 * @return HadoopIgfsInProcWithIgniteRefsCount instance. {@code null} if the IGFS not fount in the current VM.
 * @throws IgniteCheckedException On error.
 */
public static HadoopIgfsInProc create(String igniteCfgPath, String igfsName, Log log, String userName) throws IgniteCheckedException {
    IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> cfgPair = IgnitionEx.loadConfiguration(igniteCfgPath);
    IgniteConfiguration cfg = cfgPair.get1();
    cfg.setClientMode(true);
    String nodeName = cfg.getIgniteInstanceName();
    synchronized (REF_CTR_MUX) {
        T2<Ignite, Boolean> startRes = IgnitionEx.getOrStart(cfg);
        boolean newNodeStarted = startRes.get2();
        if (newNodeStarted) {
            assert !REF_CTRS.containsKey(nodeName) : "The ignite instance already exists in the ref count map";
            REF_CTRS.put(nodeName, 0);
        }
        HadoopIgfsInProc hadoop = create0(startRes.get1(), igfsName, log, userName);
        if (hadoop == null) {
            if (newNodeStarted) {
                REF_CTRS.remove(nodeName);
                Ignition.stop(nodeName, true);
            }
            throw new HadoopIgfsCommunicationException("Ignite client node doesn't have IGFS with the " + "given name: " + igfsName);
        }
        return hadoop;
    }
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridSpringResourceContext(org.apache.ignite.internal.processors.resource.GridSpringResourceContext) Ignite(org.apache.ignite.Ignite)

Example 2 with GridSpringResourceContext

use of org.apache.ignite.internal.processors.resource.GridSpringResourceContext in project ignite by apache.

the class HadoopCommandLineTest method beforeTest.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTest() throws Exception {
    String cfgPath = "config/hadoop/default-config.xml";
    IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> tup = IgnitionEx.loadConfiguration(cfgPath);
    IgniteConfiguration cfg = tup.get1();
    // Avoid connecting to other nodes.
    cfg.setLocalHost("127.0.0.1");
    igfs = (IgfsEx) Ignition.start(cfg).fileSystem(igfsName);
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridSpringResourceContext(org.apache.ignite.internal.processors.resource.GridSpringResourceContext)

Example 3 with GridSpringResourceContext

use of org.apache.ignite.internal.processors.resource.GridSpringResourceContext in project ignite by apache.

the class ServletContextListenerStartup method contextInitialized.

/**
 * {@inheritDoc}
 */
@Override
public void contextInitialized(ServletContextEvent evt) {
    ServletContext ctx = evt.getServletContext();
    String cfgFile = ctx.getInitParameter(IGNITE_CFG_FILE_PATH_PARAM);
    Collection<IgniteConfiguration> cfgs;
    GridSpringResourceContext rsrcCtx = null;
    if (cfgFile != null) {
        URL cfgUrl = null;
        try {
            cfgUrl = evt.getServletContext().getResource("/META-INF/" + cfgFile);
        } catch (MalformedURLException ignored) {
        // Ignore, we still need to try with IGNITE_HOME.
        }
        if (cfgUrl == null)
            // Try with IGNITE_HOME and with context class loader.
            cfgUrl = U.resolveIgniteUrl(cfgFile);
        if (cfgUrl == null)
            throw new IgniteException("Failed to find Spring configuration file (path provided should be " + "either absolute, relative to IGNITE_HOME, or relative to META-INF folder): " + cfgFile);
        IgniteBiTuple<Collection<IgniteConfiguration>, ? extends GridSpringResourceContext> t;
        try {
            t = IgnitionEx.loadConfigurations(cfgUrl);
        } catch (IgniteCheckedException e) {
            throw new IgniteException("Failed to load Ignite configuration.", e);
        }
        cfgs = t.get1();
        rsrcCtx = t.get2();
        if (cfgs.isEmpty())
            throw new IgniteException("Can't find grid factory configuration in: " + cfgUrl);
    } else
        cfgs = Collections.<IgniteConfiguration>singleton(new IgniteConfiguration());
    try {
        assert !cfgs.isEmpty();
        for (IgniteConfiguration cfg : cfgs) {
            assert cfg != null;
            Ignite ignite;
            synchronized (ServletContextListenerStartup.class) {
                try {
                    ignite = G.ignite(cfg.getIgniteInstanceName());
                } catch (IgniteIllegalStateException ignored) {
                    ignite = IgnitionEx.start(new IgniteConfiguration(cfg), rsrcCtx);
                }
            }
            // Check if grid is not null - started properly.
            if (ignite != null)
                igniteInstanceNames.add(ignite.name());
        }
    } catch (IgniteCheckedException e) {
        // Stop started grids only.
        for (String name : igniteInstanceNames) G.stop(name, true);
        throw new IgniteException("Failed to start Ignite.", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteException(org.apache.ignite.IgniteException) GridSpringResourceContext(org.apache.ignite.internal.processors.resource.GridSpringResourceContext) ServletContext(javax.servlet.ServletContext) Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite)

Example 4 with GridSpringResourceContext

use of org.apache.ignite.internal.processors.resource.GridSpringResourceContext in project ignite by apache.

the class IgniteHadoopFileSystemClientBasedOpenTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> cfgPair = IgnitionEx.loadConfiguration(cfgPath(getTestIgniteInstanceIndex(gridName)));
    IgniteConfiguration cfg = cfgPair.get1();
    cfg.setIgniteInstanceName(gridName);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridSpringResourceContext(org.apache.ignite.internal.processors.resource.GridSpringResourceContext)

Example 5 with GridSpringResourceContext

use of org.apache.ignite.internal.processors.resource.GridSpringResourceContext in project ignite by apache.

the class PlatformIgnition method start.

/**
 * Start Ignite node in platform mode.
 *
 * @param springCfgPath Spring configuration path.
 * @param igniteInstanceName Ignite instance name.
 * @param factoryId Factory ID.
 * @param envPtr Environment pointer.
 * @param dataPtr Optional pointer to additional data required for startup.
 */
public static synchronized void start(@Nullable String springCfgPath, @Nullable String igniteInstanceName, int factoryId, long envPtr, long dataPtr) {
    if (envPtr <= 0)
        throw new IgniteException("Environment pointer must be positive.");
    ClassLoader oldClsLdr = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(PlatformProcessor.class.getClassLoader());
    try {
        PlatformBootstrap bootstrap = bootstrap(factoryId);
        // This should be done before Spring XML initialization so that redirected stream is picked up.
        bootstrap.init(dataPtr);
        IgniteBiTuple<IgniteConfiguration, GridSpringResourceContext> cfg = configuration(springCfgPath);
        if (igniteInstanceName != null)
            cfg.get1().setIgniteInstanceName(igniteInstanceName);
        else
            igniteInstanceName = cfg.get1().getIgniteInstanceName();
        PlatformProcessor proc = bootstrap.start(cfg.get1(), cfg.get2(), envPtr);
        PlatformProcessor old = instances.put(igniteInstanceName, proc);
        assert old == null;
    } finally {
        Thread.currentThread().setContextClassLoader(oldClsLdr);
    }
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteException(org.apache.ignite.IgniteException) GridSpringResourceContext(org.apache.ignite.internal.processors.resource.GridSpringResourceContext)

Aggregations

IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 GridSpringResourceContext (org.apache.ignite.internal.processors.resource.GridSpringResourceContext)6 Ignite (org.apache.ignite.Ignite)3 IgniteException (org.apache.ignite.IgniteException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Collection (java.util.Collection)1 ServletContext (javax.servlet.ServletContext)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteIllegalStateException (org.apache.ignite.IgniteIllegalStateException)1 IgniteClient (org.apache.ignite.client.IgniteClient)1 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)1