Hi Prashant, I was able to reproduce the issue. It happens because TestMapper knows all about hadoop and CreateCache doesn't. So I believe TestMapper has the following dependency:
Do you have this dependency? : <dependency> <groupId>org.apache.ignite</groupId> <artifactId>ignite-hadoop</artifactId> <version>2.0.0</version> </dependency> Try to exclude it. This dependency says to Ignite that the whole cluster works with hadoop and each node has hadoop classes, but in you case CreateCache doesn't have hadoop classes in class path. So you should exclude ignite-hadoop from dependencies or add all hadoop related classes to CreateCache class path. Thanks, Mikhail. 2017-06-02 8:37 GMT+03:00 Prashant312 <p.ve...@crif.com>: > Hello Michael, > > Thanks for writing, We are just using Core Java to start the Ignite > instance > and fetch value from that Ignite instance through mapper. > Below are the 3 class file which we have used. > > Createcache is used to put data. > > Startignite is called from setup method of maaper. > > Inside testmapper we are starting Ignite from setup method and > trying to > get values in map method, which is returning NULL. > > PS - Without mapper class if we try to access the cache value from other > Java Program we are able to do so. > > Waiting for your positive reply. > ------------------- > > package ignite; > > > import java.util.Arrays; > > import javax.cache.configuration.Factory; > > import org.apache.ignite.Ignite; > import org.apache.ignite.IgniteCache; > import org.apache.ignite.Ignition; > import org.apache.ignite.cache.CacheAtomicityMode; > import org.apache.ignite.cache.CacheMode; > import org.apache.ignite.configuration.CacheConfiguration; > import org.apache.ignite.configuration.IgniteConfiguration; > import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; > import > org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; > import org.apache.poi.hssf.record.formula.functions.Minute; > > > public class CreateCache { > > public static IgniteCache<String, String> igniteCache=null; > > > public static void main(String[] args) { > > > /*TcpDiscoverySpi spi = new TcpDiscoverySpi(); > > TcpDiscoveryVmIpFinder ipFinder = new > TcpDiscoveryVmIpFinder(); > ipFinder.setAddresses(Arrays.asList("10.10.10.138", > "10.10.10.138:47500..47509")); > spi.setIpFinder(ipFinder); > > IgniteConfiguration cfg = new IgniteConfiguration(); > > // Override default discovery SPI. > cfg.setDiscoverySpi(spi);*/ > //Ignition.setClientMode(false); > Ignite ignite = Ignition.start(); > > > CacheConfiguration<String, String> cacheConfig=new > CacheConfiguration<String, String>(); > > cacheConfig.setBackups(1); > > cacheConfig.setName("matchCache"); > cacheConfig.setAtomicityMode(CacheAtomicityMode.ATOMIC); > cacheConfig.setCacheMode(CacheMode.REPLICATED); > > igniteCache=ignite.getOrCreateCache(cacheConfig); > > igniteCache.put("100", "abc"); > //igniteCache. > > System.out.println("Done....cache"); > } > > public static Object getCacheData(String key){ > > if(igniteCache!=null){ > return igniteCache.get(key); > } > return key; > } > > } > ------------------------------------------------------- > package ignite; > > import java.util.Arrays; > import java.util.Properties; > > import org.apache.ignite.Ignite; > import org.apache.ignite.IgniteCache; > import org.apache.ignite.IgniteSystemProperties; > import org.apache.ignite.Ignition; > import org.apache.ignite.cache.CacheAtomicityMode; > import org.apache.ignite.cache.CacheMode; > import org.apache.ignite.configuration.CacheConfiguration; > import org.apache.ignite.configuration.IgniteConfiguration; > import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; > import > org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; > import static > org.apache.ignite.IgniteSystemProperties.IGNITE_REST_START_ON_CLIENT; > > > public class StartIgnite { > > public static IgniteCache<String, String> igniteCache=null; > > public static void startIgnite(){ > > > Ignition.setClientMode(true); > /*TcpDiscoverySpi spi = new TcpDiscoverySpi(); > > TcpDiscoveryVmIpFinder ipFinder = new > TcpDiscoveryVmIpFinder(); > > // Set initial IP addresses. > // Note that you can optionally specify a port or a port > range. > ipFinder.setAddresses(Arrays.asList("127.0.0.1", > "127.0.0.1:47500..47509")); > > spi.setIpFinder(ipFinder);*/ > > TcpDiscoverySpi spi = new TcpDiscoverySpi(); > TcpDiscoveryVmIpFinder ipFinder = new > TcpDiscoveryVmIpFinder(); > ipFinder.setAddresses(Arrays.asList("127.0.0.1", > "127.0.0.1:47500..47509")); > spi.setIpFinder(ipFinder); > System.out.println(ipFinder); > > IgniteConfiguration cfg = new IgniteConfiguration(); > > cfg.setDiscoverySpi(spi); > > Ignite ignite = Ignition.start(cfg); > > CacheConfiguration<String, String> cacheConfig=new > CacheConfiguration<String, String>(); > cacheConfig.setName("matchCache"); > //cacheConfig. > //cacheConfig.s > cacheConfig.setAtomicityMode(CacheAtomicityMode.ATOMIC); > igniteCache=ignite.getOrCreateCache(cacheConfig); > System.out.println("cache name is "+ > igniteCache.getName()); > > } > > public static void stopIgnite(){ > Ignition.stop(true); > } > > public static String getCacheData(String id){ > > return igniteCache.get(id); > } > > public static void main(String[] args) { > > startIgnite(); > //System.out.println(Cache.getCacheData(CacheConstants. > CLEANSING_TOKENS)); > > String obj=igniteCache.get("200"); > String obj2=igniteCache.get("100"); > System.out.println(obj); > System.out.println(obj2); > > stopIgnite(); > > } > > } > --------------------------------------------------------------- > package mapper; > > import java.io.IOException; > > import org.apache.hadoop.conf.Configuration; > import org.apache.hadoop.fs.Path; > import org.apache.hadoop.io.IntWritable; > import org.apache.hadoop.io.LongWritable; > import org.apache.hadoop.io.Text; > import org.apache.hadoop.mapreduce.Job; > import org.apache.hadoop.mapreduce.Mapper; > import org.apache.hadoop.mapreduce.Reducer; > import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; > import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; > import ignite.StartIgnite; > > public class TestMapper { > > public static void main(String[] args) throws Exception > > { > Configuration c = new Configuration(); > Path input = new Path(args[0]); > Path output = new Path(args[1]); > Job j = new Job(c, "wordcount"); > j.setJarByClass(TestMapper.class); > j.setMapperClass(MapForWordCount.class); > j.setReducerClass(ReduceForWordCount.class); > j.setOutputKeyClass(Text.class); > j.setOutputValueClass(IntWritable.class); > FileInputFormat.addInputPath(j, input); > FileOutputFormat.setOutputPath(j, output); > System.exit(j.waitForCompletion(true) ? 0 : 1); > > } > > public static class MapForWordCount extends Mapper<LongWritable, > Text, > Text, IntWritable> { > > boolean flag=false; > > > @Override > protected void setup(Context context) throws IOException, > InterruptedException { > System.out.println("setup called"); > StartIgnite.startIgnite(); > System.out.println("Ignite started "); > } > > @Override > protected void cleanup(Context context) throws IOException, > InterruptedException { > System.out.println("Cleanup called"); > StartIgnite.stopIgnite(); > } > > public void map(LongWritable key, Text value, Context con) > throws > IOException, InterruptedException > > { > System.out.println("in map"); > String obj=StartIgnite.getCacheData("100"); > System.out.println(obj); > String line = value.toString(); > > String[] words = line.split(" "); > > for (String word : words){ > Text outputKey = new > Text(word.toUpperCase().trim()); > IntWritable outputValue = new > IntWritable(1); > con.write(outputKey, outputValue); > } > } > } > public static class ReduceForWordCount extends Reducer<Text, > IntWritable, > Text, IntWritable> > > { > > public void reduce(Text word, Iterable<IntWritable> > values, Context con) > throws IOException, InterruptedException > > { > int sum = 0; > for (IntWritable value : values){ > sum += value.get(); > } > con.write(word, new IntWritable(sum)); > } > } > } > ------------------------------------------------------- > > Mikhail wrote > > Hi Prashant, > > > > Could you please provide more details about your configuration? > > Maybe you can send a test case that will show the issue? > > > > PS you email didn't get to mail list, because looks like you haven't > > subscribed to the list. > > Please subscribe to the list before sending further emails. > > > > Thanks, > > Mikhail. > > > Mikhail wrote > > Hi Prashant, > > > > Could you please provide more details about your configuration? > > Maybe you can send a test case that will show the issue? > > > > PS you email didn't get to mail list, because looks like you haven't > > subscribed to the list. > > Please subscribe to the list before sending further emails. > > > > Thanks, > > Mikhail. > > > Mikhail wrote > > Hi Prashant, > > > > Could you please provide more details about your configuration? > > Maybe you can send a test case that will show the issue? > > > > PS you email didn't get to mail list, because looks like you haven't > > subscribed to the list. > > Please subscribe to the list before sending further emails. > > > > Thanks, > > Mikhail. > > > Mikhail wrote > > Hi Prashant, > > > > Could you please provide more details about your configuration? > > Maybe you can send a test case that will show the issue? > > > > PS you email didn't get to mail list, because looks like you haven't > > subscribed to the list. > > Please subscribe to the list before sending further emails. > > > > Thanks, > > Mikhail. > > > Mikhail wrote > > Hi Prashant, > > > > Could you please provide more details about your configuration? > > Maybe you can send a test case that will show the issue? > > > > PS you email didn't get to mail list, because looks like you haven't > > subscribed to the list. > > Please subscribe to the list before sending further emails. > > > > Thanks, > > Mikhail. > > > Mikhail wrote > > Hi Prashant, > > > > Could you please provide more details about your configuration? > > Maybe you can send a test case that will show the issue? > > > > PS you email didn't get to mail list, because looks like you haven't > > subscribed to the list. > > Please subscribe to the list before sending further emails. > > > > Thanks, > > Mikhail. > > > > > > -- > View this message in context: http://apache-ignite-users. > 70518.x6.nabble.com/Ignite-Cache-returning-Null-value- > from-Mapper-tp13158p13332.html > Sent from the Apache Ignite Users mailing list archive at Nabble.com. >