org.apache.ignite.IgniteException Java Examples
The following examples show how to use
org.apache.ignite.IgniteException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RdbmsBenchmark.java From ignite with Apache License 2.0 | 6 votes |
/** * Set args to prepared upsert statement. * * @param stmt Statement. * @param newKey Key. * @param newVal Value. * @throws SQLException if failed. */ private static void setUpsertStatementArgs(PreparedStatement stmt, long newKey, long newVal) throws SQLException { switch (stmt.getConnection().getMetaData().getDatabaseProductName()) { case "H2": // No-op. break; case "Apache Ignite": // No-op. break; case "MySQL": case "PostgreSQL": stmt.setLong(3, newVal); break; default: throw new IgniteException("Unexpected database type [databaseProductName=" + stmt.getConnection().getMetaData().getDatabaseProductName() + ']'); } stmt.setLong(1, newKey); stmt.setLong(2, newVal); }
Example #2
Source File: IgniteCacheProxyImpl.java From ignite with Apache License 2.0 | 6 votes |
/** * @param keys Keys. * @return Values map. */ public Map<K, V> getAll(Collection<? extends K> keys) { IgniteInternalCache<K, V> delegate = getDelegateSafe(); try { if (isAsync()) { setFuture(delegate.getAllAsync(keys)); return null; } else return delegate.getAll(keys); } catch (IgniteCheckedException | IgniteException e) { throw cacheException(e); } }
Example #3
Source File: IgniteCacheProxyImpl.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public boolean replace(K key, V val) { IgniteInternalCache<K, V> delegate = getDelegateSafe(); try { if (isAsync()) { setFuture(delegate.replaceAsync(key, val)); return false; } else return delegate.replace(key, val); } catch (IgniteCheckedException | IgniteException e) { throw cacheException(e); } }
Example #4
Source File: GridAffinityProcessor.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public Map<ClusterNode, Collection<K>> mapKeysToNodes(@Nullable Collection<? extends K> keys) { ctx.gateway().readLock(); try { if (F.isEmpty(keys)) return Collections.emptyMap(); AffinityInfo affInfo = cache(); return affinityMap(affInfo, keys); } catch (IgniteCheckedException e) { throw new IgniteException(e); } finally { ctx.gateway().readUnlock(); } }
Example #5
Source File: StormStreamer.java From ignite with Apache License 2.0 | 6 votes |
/** * Starts streamer. * * @throws IgniteException If failed. */ @SuppressWarnings("unchecked") public void start() throws IgniteException { A.notNull(igniteConfigFile, "Ignite config file"); A.notNull(cacheName, "Cache name"); A.notNull(igniteTupleField, "Ignite tuple field"); setIgnite(StreamerContext.getIgnite()); final IgniteDataStreamer<K, V> dataStreamer = StreamerContext.getStreamer(); dataStreamer.autoFlushFrequency(autoFlushFrequency); dataStreamer.allowOverwrite(allowOverwrite); setStreamer(dataStreamer); log = getIgnite().log(); stopped = false; }
Example #6
Source File: IgniteMessagingImpl.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public IgniteFuture<UUID> remoteListenAsync(@Nullable Object topic, IgniteBiPredicate<UUID, ?> p) throws IgniteException { A.notNull(p, "p"); guard(); try { GridContinuousHandler hnd = new GridMessageListenHandler(topic, securityAwareBiPredicate(p)); return new IgniteFutureImpl<>(ctx.continuous().startRoutine(hnd, false, 1, 0, false, prj.predicate())); } catch (IgniteCheckedException e) { throw U.convertException(e); } finally { unguard(); } }
Example #7
Source File: PlatformDotNetConfigurationClosure.java From ignite with Apache License 2.0 | 6 votes |
/** * Sets binary config. * * @param igniteCfg Ignite config. * @param dotNetCfg .NET config. */ private void setBinaryConfiguration(IgniteConfiguration igniteCfg, PlatformDotNetConfigurationEx dotNetCfg) { // Check marshaller. Marshaller marsh = igniteCfg.getMarshaller(); if (marsh == null) { igniteCfg.setMarshaller(new BinaryMarshaller()); dotNetCfg.warnings(Collections.singleton("Marshaller is automatically set to " + BinaryMarshaller.class.getName() + " (other nodes must have the same marshaller type).")); } else if (!(marsh instanceof BinaryMarshaller)) throw new IgniteException("Unsupported marshaller (only " + BinaryMarshaller.class.getName() + " can be used when running Apache Ignite.NET): " + marsh.getClass().getName()); BinaryConfiguration bCfg = igniteCfg.getBinaryConfiguration(); }
Example #8
Source File: CacheEntryProcessorExample.java From ignite with Apache License 2.0 | 6 votes |
/** * Executes example. * * @param args Command line arguments, none required. * @throws IgniteException If example execution failed. */ public static void main(String[] args) throws IgniteException { try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { System.out.println(); System.out.println(">>> Entry processor example started."); // Auto-close cache at the end of the example. try (IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(CACHE_NAME)) { // Demonstrates usage of EntryProcessor.invoke(...) method. populateEntriesWithInvoke(cache); // Demonstrates usage of EntryProcessor.invokeAll(...) method. incrementEntriesWithInvokeAll(cache); } finally { // Distributed cache could be removed from cluster only by #destroyCache() call. ignite.destroyCache(CACHE_NAME); } } }
Example #9
Source File: TxLog.java From ignite with Apache License 2.0 | 6 votes |
/** * @param ctx Checkpoint context. * @throws IgniteCheckedException If failed. */ private void saveReuseListMetadata(Context ctx) throws IgniteCheckedException { Executor executor = ctx.executor(); if (executor == null) reuseList.saveMetadata(IoStatisticsHolderNoOp.INSTANCE); else { executor.execute(() -> { try { reuseList.saveMetadata(IoStatisticsHolderNoOp.INSTANCE); } catch (IgniteCheckedException e) { throw new IgniteException(e); } }); } }
Example #10
Source File: SplitterUtils.java From ignite with Apache License 2.0 | 6 votes |
/** * @param el Element. * @param paramsCnt Number of parameters. * @param paramIdxs Parameter indexes. */ private static void findParams(@Nullable GridSqlAst el, int paramsCnt, TreeSet<Integer> paramIdxs) { if (el == null) return; if (el instanceof GridSqlParameter) { // H2 Supports queries like "select ?5" but first 4 non-existing parameters are need to be set to any value. // Here we will set them to NULL. final int idx = ((GridSqlParameter)el).index(); if (paramsCnt <= idx) throw new IgniteException("Invalid number of query parameters. " + "Cannot find " + idx + " parameter."); paramIdxs.add(idx); } else if (el instanceof GridSqlSubquery) findParamsQuery(((GridSqlSubquery)el).subquery(), paramsCnt, paramIdxs); else { for (int i = 0; i < el.size(); i++) findParams(el.child(i), paramsCnt, paramIdxs); } }
Example #11
Source File: PlatformComputeBinarizableArgTask.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Nullable @Override public Object execute() { BinaryObjectEx arg0 = ((BinaryObjectEx)arg); BinaryType meta = ignite.binary().type(arg0.typeId()); if (meta == null) throw new IgniteException("Metadata doesn't exist."); if (meta.fieldNames() == null || !meta.fieldNames().contains("Field")) throw new IgniteException("Field metadata doesn't exist."); if (!F.eq("int", meta.fieldTypeName("Field"))) throw new IgniteException("Invalid field type: " + meta.fieldTypeName("Field")); if (meta.affinityKeyFieldName() != null) throw new IgniteException("Unexpected affinity key: " + meta.affinityKeyFieldName()); return arg0.field("field"); }
Example #12
Source File: GridAffinityProcessor.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public int[] primaryPartitions(ClusterNode n) { ctx.gateway().readLock(); try { Set<Integer> parts = cache().assignment().primaryPartitions(n.id()); return U.toIntArray(parts); } catch (IgniteCheckedException e) { throw new IgniteException(e); } finally { ctx.gateway().readUnlock(); } }
Example #13
Source File: DurableBackgroundTasksProcessor.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void onReadyForRead(ReadOnlyMetastorage metastorage) { synchronized (metaStorageMux) { if (durableBackgroundTasks.isEmpty()) { try { metastorage.iterate( STORE_DURABLE_BACKGROUND_TASK_PREFIX, (key, val) -> durableBackgroundTasks.put(key, (DurableBackgroundTask)val), true ); } catch (IgniteCheckedException e) { throw new IgniteException("Failed to iterate durable background tasks storage.", e); } } } }
Example #14
Source File: IgniteClusterImpl.java From ignite with Apache License 2.0 | 6 votes |
/** * Verifies all nodes in current cluster topology support BaselineTopology feature so compatibilityMode flag is * enabled to reset. * * @param discoCache */ private void verifyBaselineTopologySupport(DiscoCache discoCache) { if (discoCache.minimumServerNodeVersion().compareTo(MIN_BLT_SUPPORTING_VER) < 0) { SB sb = new SB("Cluster contains nodes that don't support BaselineTopology: ["); for (ClusterNode cn : discoCache.serverNodes()) { if (cn.version().compareTo(MIN_BLT_SUPPORTING_VER) < 0) sb .a("[") .a(cn.consistentId()) .a(":") .a(cn.version()) .a("], "); } sb.d(sb.length() - 2, sb.length()); throw new IgniteException(sb.a("]").toString()); } }
Example #15
Source File: GridServiceProcessor.java From ignite with Apache License 2.0 | 6 votes |
/** * Validates service configuration. * * @param c Service configuration. * @throws IgniteException If validation failed. */ private void validate(ServiceConfiguration c) throws IgniteException { IgniteConfiguration cfg = ctx.config(); DeploymentMode depMode = cfg.getDeploymentMode(); if (cfg.isPeerClassLoadingEnabled() && (depMode == PRIVATE || depMode == ISOLATED)) throw new IgniteException("Cannot deploy services in PRIVATE or ISOLATED deployment mode: " + depMode); ensure(c.getName() != null, "getName() != null", null); ensure(c.getTotalCount() >= 0, "getTotalCount() >= 0", c.getTotalCount()); ensure(c.getMaxPerNodeCount() >= 0, "getMaxPerNodeCount() >= 0", c.getMaxPerNodeCount()); ensure(c.getService() != null, "getService() != null", c.getService()); ensure(c.getTotalCount() > 0 || c.getMaxPerNodeCount() > 0, "c.getTotalCount() > 0 || c.getMaxPerNodeCount() > 0", null); }
Example #16
Source File: ComputeBroadcastExample.java From ignite with Apache License 2.0 | 6 votes |
/** * Gather system info from all nodes and print it out. * * @param ignite Ignite instance. * @throws IgniteException if failed. */ private static void gatherSystemInfo(Ignite ignite) throws IgniteException { // Gather system info from all nodes. Collection<String> res = ignite.compute().broadcast(() -> { System.out.println(); System.out.println("Executing task on node: " + ignite.cluster().localNode().id()); return "Node ID: " + ignite.cluster().localNode().id() + "\n" + "OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch") + "\n" + "User: " + System.getProperty("user.name") + "\n" + "JRE: " + System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version"); }); // Print result. System.out.println(); System.out.println("Nodes system information:"); System.out.println(); res.forEach(r -> { System.out.println(r); System.out.println(); }); }
Example #17
Source File: IgniteClusterSnapshotSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** @throws Exception If fails. */ @Test public void testClusterSnapshotInMemoryFail() throws Exception { persistence = false; IgniteEx srv = startGrid(0); srv.cluster().state(ACTIVE); IgniteEx clnt = startClientGrid(1); IgniteFuture<?> fut = clnt.snapshot().createSnapshot(SNAPSHOT_NAME); assertThrowsAnyCause(log, fut::get, IgniteException.class, "Snapshots on an in-memory clusters are not allowed."); }
Example #18
Source File: GridPartitionedCacheJtaLookupClassNameSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** */ @Ignore("https://issues.apache.org/jira/browse/IGNITE-10723") @Test public void testIncompatibleTmLookup() { final IgniteEx ignite = grid(0); final CacheConfiguration cacheCfg = new CacheConfiguration(DEFAULT_CACHE_NAME); cacheCfg.setName("Foo"); cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); cacheCfg.setTransactionManagerLookupClassName(TestTmLookup2.class.getName()); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws IgniteException { ignite.createCache(cacheCfg); return null; } }, IgniteException.class, null); }
Example #19
Source File: AtomicDataStructureProxy.java From ignite with Apache License 2.0 | 6 votes |
/** * Checks removed status after fail. * * @param cause Initial exception. * @return Ignite runtime exception that corresponds the original {@code cause}. */ protected IgniteException checkRemovedAfterFail(Exception cause) { assert cause != null : "The original cause must not be null."; needCheckNotRemoved(); try { checkRemoved(); } catch (Exception e) { // The original exception should be returned. } if (cause instanceof IgniteCheckedException) return U.convertException((IgniteCheckedException) cause); else if (cause instanceof EntryProcessorException) return new IgniteException(cause.getMessage(), cause); else { assert cause instanceof IgniteException; return (IgniteException)cause; } }
Example #20
Source File: HadoopIgfsInProc.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public Boolean mkdirs(final IgfsPath path, final Map<String, String> props) throws IgniteCheckedException { try { IgfsUserContext.doAs(user, new IgniteOutClosure<Void>() { @Override public Void apply() { igfs.mkdirs(path, props); return null; } }); return true; } catch (IgniteException e) { throw new IgniteCheckedException(e); } catch (IllegalStateException ignored) { throw new HadoopIgfsCommunicationException("Failed to findIgfsAndCreate directory because Grid is stopping: " + path); } }
Example #21
Source File: ClientHttpTask.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected Collection<? extends ComputeJob> split(int gridSize, String arg) { try { JsonNode json = JSON_MAPPER.readTree(arg); List<String> list = null; if (json.isArray()) { list = new ArrayList<>(); for (JsonNode child : json) list.add(child.asText()); } return delegate.split(gridSize, list); } catch (IOException e) { throw new IgniteException(e); } }
Example #22
Source File: IgniteCacheDistributedPartitionQueryAbstractSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public int partition(Object key) { Integer regionId; if (key instanceof RegionKey) regionId = ((RegionKey)key).regionId; else if (key instanceof BinaryObject) { BinaryObject bo = (BinaryObject)key; regionId = bo.field("regionId"); } else throw new IgniteException("Unsupported key for region aware affinity"); List<Integer> range = REGION_TO_PART_MAP.get(regionId); Integer cnt = range.get(1); return U.safeAbs(key.hashCode() % cnt) + range.get(0); // Assign partition in region's range. }
Example #23
Source File: GridAffinityProcessor.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public int[] backupPartitions(ClusterNode n) { ctx.gateway().readLock(); try { Set<Integer> parts = cache().assignment().backupPartitions(n.id()); return U.toIntArray(parts); } catch (IgniteCheckedException e) { throw new IgniteException(e); } finally { ctx.gateway().readUnlock(); } }
Example #24
Source File: IgniteDynamicCacheConfigTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testDynamicCacheStartFromNotExistConfig() throws Exception { try { ignite(0).getOrCreateCache(load("config/cache.xml")); fail(); } catch (IgniteException ignored) { // No-op. } }
Example #25
Source File: IgfsJobImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public Object execute() { IgniteFileSystem fs = ignite.fileSystem(igfsName); try (IgfsInputStream in = fs.open(path)) { IgfsFileRange split = new IgfsFileRange(path, start, len); if (rslvr != null) { split = rslvr.resolveRecords(fs, in, split); if (split == null) { log.warning("No data found for split on local node after resolver is applied " + "[igfsName=" + igfsName + ", path=" + path + ", start=" + start + ", len=" + len + ']'); return null; } } in.seek(split.start()); return job.execute(fs, new IgfsFileRange(path, split.start(), split.length()), in); } catch (IOException e) { throw new IgniteException("Failed to execute IGFS job for file split [igfsName=" + igfsName + ", path=" + path + ", start=" + start + ", len=" + len + ']', e); } }
Example #26
Source File: HadoopIgfsSecondaryFileSystemDelegateImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void mkdirs(IgfsPath path, @Nullable Map<String, String> props) { try { if (!fileSystemForUser().mkdirs(convert(path), new HadoopIgfsProperties(props).permission())) throw new IgniteException("Failed to make directories [path=" + path + ", props=" + props + "]"); } catch (IOException e) { throw handleSecondaryFsError(e, "Failed to make directories [path=" + path + ", props=" + props + "]"); } }
Example #27
Source File: WalStateManager.java From ignite with Apache License 2.0 | 5 votes |
/** * @param cls Closure to execute with disabled WAL. * @throws IgniteCheckedException If execution failed. */ public void execute(IgniteRunnable cls) throws IgniteCheckedException { if (cls == null) throw new IgniteCheckedException("Task to execute is not specified."); if (metaStorage == null) throw new IgniteCheckedException("Meta storage is not ready."); writeMetaStoreDisableWALFlag(); dbMgr.waitForCheckpoint("Checkpoint before apply updates on recovery."); disableWAL(true); try { cls.run(); } catch (IgniteException e) { throw new IgniteCheckedException(e); } finally { disableWAL(false); dbMgr.waitForCheckpoint("Checkpoint after apply updates on recovery."); removeMetaStoreDisableWALFlag(); } }
Example #28
Source File: GridCacheTxNodeFailureSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackC) { GridIoMessage ioMsg = (GridIoMessage)msg; if (!bannedClasses.contains(ioMsg.message().getClass())) super.sendMessage(node, msg, ackC); }
Example #29
Source File: DemoCancellableTask.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public Object execute() throws IgniteException { try { Thread.sleep(1000 + rnd.nextInt(60000)); } catch (InterruptedException e) { // Restore interrupt status Thread.currentThread().interrupt(); throw new IgniteInterruptedException(e); } return null; }
Example #30
Source File: VisorScanQueryCancelTask.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected Void run(@Nullable VisorScanQueryCancelTaskArg arg) throws IgniteException { new QueryMXBeanImpl(ignite.context()) .cancelScan(arg.getOriginNodeId(), arg.getCacheName(), arg.getQueryId()); return null; }