Java Code Examples for org.apache.ignite.configuration.IgniteConfiguration#getDiscoverySpi()
The following examples show how to use
org.apache.ignite.configuration.IgniteConfiguration#getDiscoverySpi() .
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: ZookeeperIpFinderTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Enhances the default configuration with the {#TcpDiscoveryZookeeperIpFinder}. * * @param igniteInstanceName Ignite instance name. * @return Ignite configuration. * @throws Exception If failed. */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration configuration = super.getConfiguration(igniteInstanceName); TcpDiscoverySpi tcpDisco = (TcpDiscoverySpi)configuration.getDiscoverySpi(); TcpDiscoveryZookeeperIpFinder zkIpFinder = new TcpDiscoveryZookeeperIpFinder(); zkIpFinder.setAllowDuplicateRegistrations(allowDuplicateRegistrations); // first node => configure with zkUrl; second node => configure with CuratorFramework; third and subsequent // shall be configured through system property if (igniteInstanceName.equals(getTestIgniteInstanceName(0))) zkIpFinder.setZkConnectionString(zkCluster.getConnectString()); else if (igniteInstanceName.equals(getTestIgniteInstanceName(1))) { zkIpFinder.setCurator(CuratorFrameworkFactory.newClient(zkCluster.getConnectString(), new ExponentialBackoffRetry(100, 5))); } tcpDisco.setIpFinder(zkIpFinder); return configuration; }
Example 2
Source File: GridDiscoveryManager.java From ignite with Apache License 2.0 | 6 votes |
/** * @param cfg Configuration. * @throws IgniteCheckedException If configuration is not valid. */ public static void initCommunicationErrorResolveConfiguration(IgniteConfiguration cfg) throws IgniteCheckedException { CommunicationFailureResolver rslvr = cfg.getCommunicationFailureResolver(); CommunicationSpi commSpi = cfg.getCommunicationSpi(); DiscoverySpi discoverySpi = cfg.getDiscoverySpi(); if (rslvr != null) { if (!supportsCommunicationErrorResolve(commSpi)) throw new IgniteCheckedException("CommunicationFailureResolver is configured, but CommunicationSpi does not support communication" + "problem resolve: " + commSpi.getClass().getName()); if (!supportsCommunicationErrorResolve(discoverySpi)) throw new IgniteCheckedException("CommunicationFailureResolver is configured, but DiscoverySpi does not support communication" + "problem resolve: " + discoverySpi.getClass().getName()); } else { if (supportsCommunicationErrorResolve(commSpi) && supportsCommunicationErrorResolve(discoverySpi)) cfg.setCommunicationFailureResolver(new DefaultCommunicationFailureResolver()); } }
Example 3
Source File: DistributedMetaStorageTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); cfg.setConsistentId(igniteInstanceName); cfg.setDataStorageConfiguration(new DataStorageConfiguration() .setDefaultDataRegionConfiguration(new DataRegionConfiguration() .setPersistenceEnabled(isPersistent()) ) .setWalSegments(3) .setWalSegmentSize(512 * 1024) ); DiscoverySpi discoSpi = cfg.getDiscoverySpi(); if (discoSpi instanceof TcpDiscoverySpi) ((TcpDiscoverySpi)discoSpi).setNetworkTimeout(1000); return cfg; }
Example 4
Source File: GridAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Optimizes configuration to achieve better test performance. * * @param cfg Configuration. * @return Optimized configuration (by modifying passed in one). * @throws IgniteCheckedException On error. */ protected IgniteConfiguration optimize(IgniteConfiguration cfg) throws IgniteCheckedException { if (cfg.getLocalHost() == null) { if (cfg.getDiscoverySpi() instanceof TcpDiscoverySpi) { cfg.setLocalHost("127.0.0.1"); if (((TcpDiscoverySpi)cfg.getDiscoverySpi()).getJoinTimeout() == 0) ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setJoinTimeout(10000); } else cfg.setLocalHost(getTestResources().getLocalHost()); } // Do not add redundant data if it is not needed. if (cfg.getIncludeProperties() == null) cfg.setIncludeProperties(); return cfg; }
Example 5
Source File: DynamicIndexAbstractConcurrentSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration commonConfiguration(int idx) throws Exception { IgniteConfiguration cfg = super.commonConfiguration(idx); TestTcpDiscoverySpi testSpi = new TestTcpDiscoverySpi(); if (cfg.getDiscoverySpi() instanceof TcpDiscoverySpi && ((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder() != null) testSpi.setIpFinder(((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder()); return cfg.setDiscoverySpi(testSpi); }
Example 6
Source File: IgniteTopologyValidatorGridSplitCacheTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); int idx = getTestIgniteInstanceIndex(gridName); Map<String, Object> userAttrs = new HashMap<>(4); int segment = idx % 2; userAttrs.put(DC_NODE_ATTR, segment); TcpDiscoverySpi disco = (TcpDiscoverySpi)cfg.getDiscoverySpi(); disco.setLocalPort(getDiscoPort(idx)); disco.setIpFinder(new TcpDiscoveryVmIpFinder().setAddresses(segmented() ? (segment == 0 ? SEG_FINDER_0 : SEG_FINDER_1) : SEG_FINDER_ALL)); if (idx != CONFIGLESS_GRID_IDX) { if (idx == RESOLVER_GRID_IDX) { userAttrs.put(ACTIVATOR_NODE_ATTR, "true"); } else cfg.setActiveOnStart(false); } cfg.setUserAttributes(userAttrs); cfg.setMemoryConfiguration(new MemoryConfiguration(). setDefaultMemoryPolicySize((50L << 20) + (100L << 20) * CACHES_CNT / GRID_CNT)); return cfg; }
Example 7
Source File: RebalanceWithDifferentThreadPoolSizeTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); TcpDiscoverySpi discoverySpi = (TcpDiscoverySpi)cfg.getDiscoverySpi(); discoverySpi.setIpFinder(ipFinder); cfg.setRebalanceThreadPoolSize(rebalancePoolSize); cfg.setCacheConfiguration(new CacheConfiguration(CACHE_NAME) .setRebalanceMode(CacheRebalanceMode.SYNC) // Wait reblance finish before node start .setAffinity(new RendezvousAffinityFunction(false, 32))); return cfg; }
Example 8
Source File: ServiceDeploymentOnClientDisconnectTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); cfg.setClientFailureDetectionTimeout(CLIENT_FAILURE_DETECTION_TIMEOUT); if (cfg.getDiscoverySpi() instanceof TcpDiscoverySpi) ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setClientReconnectDisabled(false); return cfg; }
Example 9
Source File: GridDiscoveryManagerAliveCacheSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); CacheConfiguration cCfg = defaultCacheConfiguration(); cCfg.setCacheMode(PARTITIONED); cCfg.setBackups(1); cCfg.setNearConfiguration(new NearCacheConfiguration()); cCfg.setRebalanceMode(SYNC); cCfg.setWriteSynchronizationMode(FULL_SYNC); TcpDiscoverySpi disc = (TcpDiscoverySpi)cfg.getDiscoverySpi(); if (clientMode && ((igniteInstanceName.charAt(igniteInstanceName.length() - 1) - '0') & 1) != 0) cfg.setClientMode(true); else cfg.setClientFailureDetectionTimeout(50000); disc.setAckTimeout(1000); disc.setSocketTimeout(1000); cfg.setCacheConfiguration(cCfg); cfg.setMetricsUpdateFrequency(500); return cfg; }
Example 10
Source File: IgniteNodeRunner.java From ignite with Apache License 2.0 | 5 votes |
/** * Reads configuration from given file and delete the file after. * * @param fileName File name. * @return Readed configuration. * @throws IOException If failed. * @see #storeToFile(IgniteConfiguration, boolean) * @throws IgniteCheckedException On error. */ private static IgniteConfiguration readCfgFromFileAndDeleteFile(String fileName) throws IOException, IgniteCheckedException { try (BufferedReader cfgReader = new BufferedReader(new FileReader(fileName))) { IgniteConfiguration cfg = (IgniteConfiguration)new XStream().fromXML(cfgReader); if (cfg.getMarshaller() == null) { Marshaller marsh = IgniteTestResources.getMarshaller(); cfg.setMarshaller(marsh); } X.println("Configured marshaller class: " + cfg.getMarshaller().getClass().getName()); if (cfg.getDiscoverySpi() == null) { TcpDiscoverySpi disco = new TcpDiscoverySpi(); disco.setIpFinder(GridCacheAbstractFullApiSelfTest.LOCAL_IP_FINDER); cfg.setDiscoverySpi(disco); } X.println("Configured discovery: " + cfg.getDiscoverySpi().getClass().getName()); return cfg; } finally { new File(fileName).delete(); } }
Example 11
Source File: TcpCommunicationSpiFreezingClientTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); cfg.setFailureDetectionTimeout(120000); cfg.setClientFailureDetectionTimeout(120000); TcpCommunicationSpi spi = new TcpCommunicationSpi(); spi.setConnectTimeout(3000); spi.setMaxConnectTimeout(6000); spi.setReconnectCount(3); spi.setIdleConnectionTimeout(100); spi.setSharedMemoryPort(-1); TcpDiscoverySpi discoSpi = (TcpDiscoverySpi)cfg.getDiscoverySpi(); discoSpi.setIpFinder(IP_FINDER); cfg.setCommunicationSpi(spi); cfg.setDiscoverySpi(discoSpi); cfg.setCacheConfiguration(new CacheConfiguration(DEFAULT_CACHE_NAME).setWriteSynchronizationMode(FULL_SYNC). setCacheMode(PARTITIONED).setAtomicityMode(ATOMIC)); return cfg; }
Example 12
Source File: TcpDiscoverySpiReconnectDelayTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Check that client restores connection after the given time, with the expected number of messages sent * and expected time elapsed. * @param numOfFailedRequests number of TcpDiscoveryJoinRequestMessage to be failed before succeed to connect. * @param reconnectDelay argument for {@link TcpDiscoverySpi#setReconnectDelay(int)} */ private void checkClientJoinAtStart(int numOfFailedRequests, int reconnectDelay) throws Exception { try ( Ignite ignite1 = G.start(getConfiguration("server", false, reconnectDelay)) ) { final CountDownLatch joinLatch = new CountDownLatch(1); ignite1.events().localListen(new IgnitePredicate<DiscoveryEvent>() { @Override public boolean apply(DiscoveryEvent evt) { info("Node1 event: " + evt); if (evt.type() == EVT_NODE_JOINED) joinLatch.countDown(); return true; } }, EVT_NODE_JOINED); IgniteConfiguration ignite2Cfg = getConfiguration("client", true, reconnectDelay); final AtomicInteger failJoinReq = ((FailingTcpDiscoverySpi)ignite2Cfg.getDiscoverySpi()).failJoinReq; failJoinReq.set(numOfFailedRequests); final long startTime = System.currentTimeMillis(); try (Ignite ignite2 = G.start(ignite2Cfg)) { assertTrue(joinLatch.await(EVT_TIMEOUT, MILLISECONDS)); long endTime = System.currentTimeMillis(); // Check topology. assertEquals(1L, ignite1.cluster().localNode().order()); assertEquals(2L, ignite2.cluster().localNode().order()); assertEquals(2L, ignite2.cluster().topologyVersion()); // Check connection time. // Total time should be at least the sum of all delays. long totalTime = endTime - startTime; long expTotalTime = numOfFailedRequests * reconnectDelay; assertTrue(totalTime >= expTotalTime); // Check number of messages. // If exactly numOfFailedRequests fail, counter will be at -1. // If unexpected additional requests are sent, counter will be <= -2. int cntr = failJoinReq.get(); int numOfMessages = numOfFailedRequests - cntr; int expNumOfMessages = numOfFailedRequests + 1; assertEquals("Unexpected number of messages", expNumOfMessages, numOfMessages); } } }
Example 13
Source File: IgniteCacheAbstractTest.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); ((TcpCommunicationSpi)cfg.getCommunicationSpi()).setSharedMemoryPort(-1); TcpDiscoverySpi disco = (TcpDiscoverySpi)cfg.getDiscoverySpi(); disco.setForceServerMode(true); if (isDebug()) disco.setAckTimeout(Integer.MAX_VALUE); MemoryEventStorageSpi evtSpi = new MemoryEventStorageSpi(); evtSpi.setExpireCount(100); cfg.setEventStorageSpi(evtSpi); cfg.setDiscoverySpi(disco); cfg.setCacheConfiguration(cacheConfiguration(igniteInstanceName)); return cfg; }
Example 14
Source File: GridCachePutAllFailoverSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); ((TcpCommunicationSpi)cfg.getCommunicationSpi()).setSharedMemoryPort(-1); cfg.setPeerClassLoadingEnabled(false); cfg.setDeploymentMode(DeploymentMode.CONTINUOUS); TcpDiscoverySpi discoverySpi = (TcpDiscoverySpi)cfg.getDiscoverySpi(); discoverySpi.setAckTimeout(60000); discoverySpi.setForceServerMode(true); cfg.setDiscoverySpi(discoverySpi); if (igniteInstanceName.startsWith("master")) { cfg.setUserAttributes(ImmutableMap.of("segment", "master")); // For sure. failoverSpi.setMaximumFailoverAttempts(100); cfg.setFailoverSpi(failoverSpi); } else if (igniteInstanceName.startsWith("worker")) { cfg.setUserAttributes(ImmutableMap.of("segment", "worker")); CacheConfiguration cacheCfg = defaultCacheConfiguration(); cacheCfg.setName("partitioned"); cacheCfg.setAtomicityMode(atomicityMode()); cacheCfg.setCacheMode(PARTITIONED); cacheCfg.setBackups(backups); cacheCfg.setNearConfiguration(nearEnabled ? new NearCacheConfiguration() : null); cacheCfg.setWriteSynchronizationMode(FULL_SYNC); cfg.setCacheConfiguration(cacheCfg); } else throw new IllegalStateException("Unexpected Ignite instance name: " + igniteInstanceName); return cfg; }
Example 15
Source File: IgnitionEx.java From ignite with Apache License 2.0 | 4 votes |
/** * Initialize default SPI implementations. * * @param cfg Ignite configuration. */ private void initializeDefaultSpi(IgniteConfiguration cfg) { if (cfg.getDiscoverySpi() == null) cfg.setDiscoverySpi(new TcpDiscoverySpi()); if (cfg.getDiscoverySpi() instanceof TcpDiscoverySpi) { TcpDiscoverySpi tcpDisco = (TcpDiscoverySpi)cfg.getDiscoverySpi(); if (tcpDisco.getIpFinder() == null) tcpDisco.setIpFinder(new TcpDiscoveryMulticastIpFinder()); } if (cfg.getCommunicationSpi() == null) cfg.setCommunicationSpi(new TcpCommunicationSpi()); if (cfg.getDeploymentSpi() == null) cfg.setDeploymentSpi(new LocalDeploymentSpi()); if (cfg.getEventStorageSpi() == null) cfg.setEventStorageSpi(new NoopEventStorageSpi()); if (cfg.getCheckpointSpi() == null) cfg.setCheckpointSpi(new NoopCheckpointSpi()); if (cfg.getCollisionSpi() == null) cfg.setCollisionSpi(new NoopCollisionSpi()); if (cfg.getFailoverSpi() == null) cfg.setFailoverSpi(new AlwaysFailoverSpi()); if (cfg.getLoadBalancingSpi() == null) cfg.setLoadBalancingSpi(new RoundRobinLoadBalancingSpi()); else { Collection<LoadBalancingSpi> spis = new ArrayList<>(); boolean dfltLoadBalancingSpi = false; for (LoadBalancingSpi spi : cfg.getLoadBalancingSpi()) { spis.add(spi); if (!dfltLoadBalancingSpi && spi instanceof RoundRobinLoadBalancingSpi) dfltLoadBalancingSpi = true; } // Add default load balancing SPI for internal tasks. if (!dfltLoadBalancingSpi) spis.add(new RoundRobinLoadBalancingSpi()); cfg.setLoadBalancingSpi(spis.toArray(new LoadBalancingSpi[spis.size()])); } if (cfg.getIndexingSpi() == null) cfg.setIndexingSpi(new NoopIndexingSpi()); if (cfg.getEncryptionSpi() == null) cfg.setEncryptionSpi(new NoopEncryptionSpi()); if (F.isEmpty(cfg.getMetricExporterSpi())) cfg.setMetricExporterSpi(new NoopMetricExporterSpi()); if (F.isEmpty(cfg.getSystemViewExporterSpi())) { if (IgniteComponentType.INDEXING.inClassPath()) { try { cfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi(), U.newInstance(SYSTEM_VIEW_SQL_SPI)); } catch (IgniteCheckedException e) { throw new IgniteException(e); } } else cfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi()); } }
Example 16
Source File: HadoopAbstractSelfTest.java From ignite with Apache License 2.0 | 3 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); cfg.setHadoopConfiguration(hadoopConfiguration(igniteInstanceName)); TcpCommunicationSpi commSpi = new TcpCommunicationSpi(); commSpi.setSharedMemoryPort(-1); cfg.setCommunicationSpi(commSpi); TcpDiscoverySpi discoSpi = (TcpDiscoverySpi)cfg.getDiscoverySpi(); discoSpi.setIpFinder(singleTestIpFinder); if (igfsEnabled()) cfg.setFileSystemConfiguration(igfsConfiguration()); if (restEnabled()) { ConnectorConfiguration clnCfg = new ConnectorConfiguration(); clnCfg.setPort(restPort++); cfg.setConnectorConfiguration(clnCfg); } cfg.setLocalHost("127.0.0.1"); cfg.setPeerClassLoadingEnabled(false); return cfg; }
Example 17
Source File: ClusterGroupHostsSelfTest.java From ignite with Apache License 2.0 | 3 votes |
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { Collection<String> hostNames = Arrays.asList("h_1", "h_2", "h_3"); IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); TcpDiscoverySpi disco = (TcpDiscoverySpi)cfg.getDiscoverySpi(); cfg.setDiscoverySpi(new CustomHostsTcpDiscoverySpi(hostNames).setIpFinder(disco.getIpFinder())); return cfg; }