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);
}
}
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);
}
}
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) + ']');
}
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;
}
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;
}
Aggregations