Search in sources :

Example 1 with IgniteIllegalStateException

use of org.apache.ignite.IgniteIllegalStateException in project ignite by apache.

the class IgnitionEx method grid.

/**
     * Gets an named grid instance. If grid name is {@code null} or empty string,
     * then default no-name grid will be returned. Note that caller of this method
     * should not assume that it will return the same instance every time.
     * <p>
     * Note that Java VM can run multiple grid instances and every grid instance (and its
     * node) can belong to a different grid. Grid name defines what grid a particular grid
     * instance (and correspondingly its node) belongs to.
     *
     * @param name Grid name to which requested grid instance belongs to. If {@code null},
     *      then grid instance belonging to a default no-name grid will be returned.
     * @return An instance of named grid. This method never returns
     *      {@code null}.
     * @throws IgniteIllegalStateException Thrown if default grid was not properly
     *      initialized or grid instance was stopped or was not started.
     */
public static Ignite grid(@Nullable String name) throws IgniteIllegalStateException {
    IgniteNamedInstance grid = name != null ? grids.get(name) : dfltGrid;
    Ignite res;
    if (grid == null || (res = grid.grid()) == null)
        throw new IgniteIllegalStateException("Ignite instance with provided name doesn't exist. " + "Did you call Ignition.start(..) to start an Ignite instance? [name=" + name + ']');
    return res;
}
Also used : Ignite(org.apache.ignite.Ignite) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException)

Example 2 with IgniteIllegalStateException

use of org.apache.ignite.IgniteIllegalStateException in project ignite by apache.

the class GridBinaryMarshaller method threadLocalContext.

/**
     * @return Thread-bound context.
     */
public static BinaryContext threadLocalContext() {
    BinaryContext ctx = GridBinaryMarshaller.BINARY_CTX.get();
    if (ctx == null) {
        IgniteKernal ignite = IgnitionEx.localIgnite();
        IgniteCacheObjectProcessor proc = ignite.context().cacheObjects();
        if (proc instanceof CacheObjectBinaryProcessorImpl)
            return ((CacheObjectBinaryProcessorImpl) proc).binaryContext();
        else
            throw new IgniteIllegalStateException("Ignite instance must be started with " + BinaryMarshaller.class.getName() + " [name=" + ignite.name() + ']');
    }
    return ctx;
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException)

Example 3 with IgniteIllegalStateException

use of org.apache.ignite.IgniteIllegalStateException in project ignite by apache.

the class TcpDiscoverySelfTest method waitNodeStop.

/**
     * @param nodeName Node name.
     * @throws Exception If failed.
     */
private void waitNodeStop(final String nodeName) throws Exception {
    boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            try {
                Ignition.ignite(nodeName);
                return false;
            } catch (IgniteIllegalStateException ignored) {
                return true;
            }
        }
    }, 30_000);
    if (!wait)
        U.dumpThreads(log);
    assertTrue("Failed to wait for node stop.", wait);
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException)

Example 4 with IgniteIllegalStateException

use of org.apache.ignite.IgniteIllegalStateException 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 5 with IgniteIllegalStateException

use of org.apache.ignite.IgniteIllegalStateException in project ignite by apache.

the class IgnitionEx method gridx.

/**
     * Gets grid instance without waiting its initialization.
     *
     * @param name Grid name.
     * @return Grid instance.
     */
public static IgniteKernal gridx(@Nullable String name) {
    IgniteNamedInstance grid = name != null ? grids.get(name) : dfltGrid;
    IgniteKernal res;
    if (grid == null || (res = grid.gridx()) == null)
        throw new IgniteIllegalStateException("Ignite instance with provided name doesn't exist. " + "Did you call Ignition.start(..) to start an Ignite instance? [name=" + name + ']');
    return res;
}
Also used : IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException)

Aggregations

IgniteIllegalStateException (org.apache.ignite.IgniteIllegalStateException)6 Ignite (org.apache.ignite.Ignite)3 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 IgniteException (org.apache.ignite.IgniteException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1 CacheObjectBinaryProcessorImpl (org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl)1 IgniteCacheObjectProcessor (org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor)1 GridSpringResourceContext (org.apache.ignite.internal.processors.resource.GridSpringResourceContext)1 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)1