Search in sources :

Example 36 with IgniteException

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

the class GridScheduleSelfTest method testInvalidPatterns.

/**
 * @throws Exception If failed.
 */
public void testInvalidPatterns() throws Exception {
    Runnable run = new Runnable() {

        @Override
        public void run() {
        // No-op.
        }
    };
    try {
        // Invalid delay.
        grid(0).scheduler().scheduleLocal(run, "{sdf, *} * * * * *").get();
        fail("IgniteException must have been thrown");
    } catch (IgniteException e) {
        info("Caught expected exception: " + e);
    }
    try {
        // Invalid delay.
        grid(0).scheduler().scheduleLocal(run, "{**, *} * * * * *").get();
        fail("IgniteException must have been thrown");
    } catch (IgniteException e) {
        info("Caught expected exception: " + e);
    }
    try {
        // Invalid number of executions.
        grid(0).scheduler().scheduleLocal(run, "{1, ghd} * * * * *").get();
        fail("IgniteException must have been thrown");
    } catch (IgniteException e) {
        info("Caught expected exception: " + e);
    }
    try {
        // Number of executions in pattern must be greater than zero or equal to "*".
        grid(0).scheduler().scheduleLocal(run, "{*, 0} * * * * *").get();
        fail("IgniteException must have been thrown");
    } catch (IgniteException e) {
        info("Caught expected exception: " + e);
    }
    try {
        // Invalid cron expression.
        grid(0).scheduler().scheduleLocal(run, "{2, 6} * * * * * * * * * *").get();
        fail("IgniteException must have been thrown");
    } catch (IgniteException e) {
        info("Caught expected exception: " + e);
    }
    try {
        // Invalid both delay and number of calls.
        grid(0).scheduler().scheduleLocal(run, "{-2, -6} * * * * *").get();
        fail("IgniteException must have been thrown");
    } catch (IgniteException e) {
        info("Caught expected exception: " + e);
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 37 with IgniteException

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

the class WebSessionFilter method updateAttributesV2.

/**
 * @param sesId Session ID.
 * @param ses Web session.
 */
public void updateAttributesV2(final String sesId, final WebSessionV2 ses) throws IOException {
    assert sesId != null;
    assert ses != null;
    final Map<String, byte[]> updatesMap = ses.binaryUpdatesMap();
    if (log.isDebugEnabled())
        log.debug("Session binary attributes updated [id=" + sesId + ", updates=" + updatesMap.keySet() + ']');
    try {
        for (int i = 0; i < retries; i++) {
            try {
                final IgniteCache<String, WebSessionEntity> cache0 = cacheWithExpiryPolicy(ses.getMaxInactiveInterval(), binaryCache);
                cache0.invoke(sesId, new WebSessionAttributeProcessor(updatesMap.isEmpty() ? null : updatesMap, ses.getLastAccessedTime(), ses.getMaxInactiveInterval(), ses.isMaxInactiveIntervalChanged()));
                break;
            } catch (CacheException | IgniteException | IllegalStateException e) {
                handleAttributeUpdateException(sesId, i, e);
            }
        }
    } catch (Exception e) {
        U.error(log, "Failed to update session V2 attributes [id=" + sesId + ']', e);
    }
}
Also used : CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) WebSessionAttributeProcessor(org.apache.ignite.internal.websession.WebSessionAttributeProcessor) ServletException(javax.servlet.ServletException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) WebSessionEntity(org.apache.ignite.internal.websession.WebSessionEntity)

Example 38 with IgniteException

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

the class IgniteIoTestAbstractBenchmark method setUp.

/**
 * {@inheritDoc}
 */
@Override
public void setUp(BenchmarkConfiguration cfg) throws Exception {
    super.setUp(cfg);
    ignite = (IgniteKernal) ignite();
    ClusterNode loc = ignite().cluster().localNode();
    Collection<ClusterNode> nodes = ignite().cluster().forServers().nodes();
    for (ClusterNode node : nodes) {
        if (!loc.equals(node))
            targetNodes.add(node);
    }
    if (targetNodes.isEmpty())
        throw new IgniteException("Failed to find remote server nodes [nodes=" + nodes + ']');
    BenchmarkUtils.println(cfg, "Initialized target nodes: " + F.nodeIds(targetNodes) + ']');
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteException(org.apache.ignite.IgniteException)

Example 39 with IgniteException

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

the class WebSessionFilter method doFilterV2.

/**
 * @param httpReq Request.
 * @param res Response.
 * @param chain Filter chain.
 * @return Session ID.
 * @throws IOException In case of I/O error.
 * @throws ServletException In case oif servlet error.
 * @throws CacheException In case of other error.
 */
private String doFilterV2(HttpServletRequest httpReq, ServletResponse res, FilterChain chain) throws IOException, ServletException, CacheException {
    WebSessionV2 cached = null;
    String sesId = httpReq.getRequestedSessionId();
    if (sesId != null) {
        sesId = transformSessionId(sesId);
        // Load from cache.
        for (int i = 0; i < retries; i++) {
            try {
                final WebSessionEntity entity = binaryCache.get(sesId);
                if (entity != null)
                    cached = new WebSessionV2(sesId, httpReq.getSession(false), false, ctx, entity, marshaller);
                break;
            } catch (CacheException | IgniteException | IllegalStateException e) {
                handleLoadSessionException(sesId, i, e);
            }
        }
        if (cached != null) {
            if (log.isDebugEnabled())
                log.debug("Using cached session for ID: " + sesId);
        } else // If not found - invalidate session and create new one.
        // Invalidate, because session might be removed from cache
        // according to expiry policy.
        {
            if (log.isDebugEnabled())
                log.debug("Cached session was invalidated and doesn't exist: " + sesId);
            final HttpSession ses = httpReq.getSession(false);
            if (ses != null) {
                try {
                    ses.invalidate();
                } catch (IllegalStateException ignore) {
                // Session was already invalidated.
                }
            }
            cached = createSessionV2(httpReq);
        }
    } else
        // No session was requested by the client, create new one and put in the request.
        cached = createSessionV2(httpReq);
    assert cached != null;
    sesId = cached.getId();
    httpReq = new RequestWrapperV2(httpReq, cached);
    chain.doFilter(httpReq, res);
    WebSessionV2 cachedNew = (WebSessionV2) httpReq.getSession(false);
    if (cachedNew != null && cachedNew.isValid())
        updateAttributesV2(cachedNew.getId(), cachedNew);
    return sesId;
}
Also used : CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) HttpSession(javax.servlet.http.HttpSession) WebSessionEntity(org.apache.ignite.internal.websession.WebSessionEntity)

Example 40 with IgniteException

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

the class WebSessionFilter method initCache.

/**
 * Init cache.
 */
@SuppressWarnings("unchecked")
void initCache() {
    cache = webSesIgnite.cache(cacheName);
    binaryCache = webSesIgnite.cache(cacheName);
    if (cache == null)
        throw new IgniteException("Cache for web sessions is not started (is it configured?): " + cacheName);
    CacheConfiguration cacheCfg = cache.getConfiguration(CacheConfiguration.class);
    if (cacheCfg.getWriteSynchronizationMode() == FULL_ASYNC)
        throw new IgniteException("Cache for web sessions cannot be in FULL_ASYNC mode: " + cacheName);
    if (!cacheCfg.isEagerTtl())
        throw new IgniteException("Cache for web sessions cannot operate with lazy TTL. " + "Consider setting eagerTtl to true for cache: " + cacheName);
    if (cacheCfg.getCacheMode() == LOCAL)
        U.quietAndWarn(webSesIgnite.log(), "Using LOCAL cache for web sessions caching " + "(this is only OK in test mode): " + cacheName);
    if (cacheCfg.getCacheMode() == PARTITIONED && cacheCfg.getAtomicityMode() != ATOMIC)
        U.quietAndWarn(webSesIgnite.log(), "Using " + cacheCfg.getAtomicityMode() + " atomicity for web sessions " + "caching (switch to ATOMIC mode for better performance)");
    txEnabled = cacheCfg.getAtomicityMode() == TRANSACTIONAL;
}
Also used : IgniteException(org.apache.ignite.IgniteException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

IgniteException (org.apache.ignite.IgniteException)498 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)160 Ignite (org.apache.ignite.Ignite)97 ClusterNode (org.apache.ignite.cluster.ClusterNode)54 ArrayList (java.util.ArrayList)52 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)45 CountDownLatch (java.util.concurrent.CountDownLatch)44 UUID (java.util.UUID)43 IOException (java.io.IOException)39 CacheException (javax.cache.CacheException)35 HashMap (java.util.HashMap)34 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)34 Transaction (org.apache.ignite.transactions.Transaction)34 List (java.util.List)24 CyclicBarrier (java.util.concurrent.CyclicBarrier)21 Map (java.util.Map)20 Collection (java.util.Collection)18 ClusterStartNodeResult (org.apache.ignite.cluster.ClusterStartNodeResult)18 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)18 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)17