Connecting to existing grid

classic Classic list List threaded Threaded
7 messages Options
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Connecting to existing grid

asked by mike charnoky

I have a very basic question, I must be missing something very obvious here: If I start an Ignite node/grid using ./bin/ignite.sh, then how do I create a client that connects to this existing node/grid without creating a grid locally via Ignite.start()? At the end of the day, I would like to get a handle for an IgniteCache on a remote node.

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Connecting to existing grid

commented by dmitriy setrakyan

You can start a cluster member as a client by not specifying cache in configuration, or specifying cache in CLIENT_ONLY or NEAR_ONLY modes. See more documentation here: Cache Distribution Modes.

In the 1.0 release, which is coming up shortly, you will not have to use CacheDistributionMode any more and will be able to specify explicitly clients and servers.

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Connecting to existing grid

commented by mike charnoky

Thanks for the quick response Dmitriy, I guess that operation wasn't so obvious. Glad that you are adding functionality to make this operation simpler. I was finally able to get a simple example working in this mode with an IgniteCache<String, String>. My goal was to connect to a grid over the network without the use of config files, so I used the TcpDiscoverySpi. However, when I tried to use my own custom Serializable keys/value, the following error was logged from the server node:

[10:46:04,525][SEVERE][ignite-#19%sys-null%][GridCacheIoManager] Failed to process message (note that distributed services do not support peer class loading, if you deploy distributed service you should have all required classes in CLASSPATH on all nodes in topology) [senderId=6e0c6104-3c92-4ed8-8548-e3636ce1859c, err=Failed to load class [name=MyKey, ctx={}]]

Does the server really need to have access to all the classes that will be stored in caches? I've never seen this sort of requirement for other data grid products like Infinispan or Hazelcast. Is there an easy way to manage this dependency?

Here is the code I am using to create a simple client, obtain a reference to a cache, then do a simple put() and get(). Note that the server is running using default-config.xml.

String cacheId = "partitioned";
TcpDiscoverySpi spi = new TcpDiscoverySpi();
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
ipFinder.setAddresses(Arrays.asList("192.168.1.50"));
spi.setIpFinder(ipFinder);
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setDiscoverySpi(spi);
CacheConfiguration<MyKey, MyValue> cacheCfg = new CacheConfiguration<MyKey, MyValue>();
cacheCfg.setName(cacheId);
// Required to fix "Cache mode mismatch" exception
cacheCfg.setCacheMode(CacheMode.PARTITIONED);
// Run local node as client only
cacheCfg.setDistributionMode(CacheDistributionMode.CLIENT_ONLY);
cfg.setCacheConfiguration(cacheCfg);
Ignite ignite = Ignition.start(cfg);
IgniteCache<MyKey, MyValue> cache = ignite.jcache(cacheId);    
MyKey key = new MyKey("customer1", "value1");
MyValue val = new MyValue("data1", "data2");
cache.put(key, val);
MyValue val2 = cache.get(key);


-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Connecting to existing grid

commented by mike charnoky

I figured out how to get past the classloading hurdle via the info from the Zero-Deployment docs

I got the example to work by setting <property name="peerClassLoadingEnabled" value="true"/> in the server config and setting igniteConfiguration.setPeerClassLoadingEnabled(true); in the client code.

Though, the documentation discourages this practice. Is there a recommended practice for distributing class files to a grid of Ignite nodes in production? We only want to make use of the data grid (cache) functionality and not the more advanced compute grid functionality.

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Connecting to existing grid

commented by dmitriy setrakyan

You can set the deployment mode to CONTINUOUS in configuration as well. Otherwise, Ignite will automatically undeploy the classes and clear caches whenever the last node leaves (which is very convenient during development).

In production environment I would not recommend using zero deployment simply to avoid any magic, but instead just copy your JAR files into the libs directory of every node. However, you may decide that zero deployment is OK for you in production as well.

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Connecting to existing grid

commented by siyuan he

can you give me an example of how to specify client in 1.0?

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Connecting to existing grid

commented by dmitriy setrakyan

You specify client mode as follows:

Ignition.setClientMode(true);

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss