GridGain Community Edition

Expand all | Collapse all

Spring application context resource is not injected in ignite for spark

  • 1.  Spring application context resource is not injected in ignite for spark

     
    Posted 04-08-2020 12:54 PM
    I'm currently testing ignite for spark 8.7.12 in Eclipse.
    I first run 2 Ignite cache instances in a cluster from Eclipse, then load cache from an Oracle db table, which works fine.
    I then run the Spark application with ignite in a separate JVM and get the error 

    20/04/08 13:46:32 [exchange-worker-#38%ImportedCluster%] ERROR GridDhtPartitionsExchangeFuture: Failed to reinitialize local partitions (rebalancing will be stopped): GridDhtPartitionExchangeId [topVer=AffinityTopologyVersion [topVer=11, minorTopVer=0], discoEvt=DiscoveryEvent [evtNode=TcpDiscoveryNode [id=e3ee758e-eee7-4c23-bd1c-f76ec338b1e5, consistentId=e3ee758e-eee7-4c23-bd1c-f76ec338b1e5, addrs=ArrayList [0:0:0:0:0:0:0:1, 10.246.65.233, 127.0.0.1, 192.168.1.139], sockAddrs=HashSet [/0:0:0:0:0:0:0:1:0, /127.0.0.1:0, /192.168.1.139:0, L083DEV003009.ams.bnymellon.net/10.246.65.233:0], discPort=0, order=11, intOrder=0, lastExchangeTime=1586367988733, loc=true, ver=8.7.12#20200211-sha1:e7932313, isClient=true], topVer=11, msgTemplate=null, span=o.a.i.i.processors.tracing.NoopSpan@2d3bc444, nodeId8=e3ee758e, msg=null, type=NODE_JOINED, tstamp=1586367992087], nodeId=e3ee758e, evt=NODE_JOINED]
    class org.apache.ignite.IgniteException: Spring application context resource is not injected.
     at org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory.create(CacheJdbcPojoStoreFactory.java:170)​


    Listed below is the Spark app code in Java
      IgniteSparkSession igniteSession = IgniteSparkSession.builder()
          .appName("Spark Ignite catalog example")
          .master("local")
          .config("spark.executor.instances", "2")    
          .igniteConfig("ImportedCluster-client.xml")
          .getOrCreate();
      igniteSession.catalog().listTables().show();

    The config xml file ImportedCluster-client.xml is located in the resource folder in the Spark (with Ignite) project.

    The error should be generated from the Spark worker thread.  I don't know how the beans in the config xml are injected in the Spark worker threads.

    Please note that I have no problem testing the ignite cache under the same config xml outside of Spark.

    I also have similar problem with a different example using JavaIgniteContext.
    I can't create using the same ignite config xml (same error).
             igniteContext = new JavaIgniteContext<>( sparkContext, "ImportedCluster-client.xml");

    I have to load configuration generated in Java code as follows as the workaround.

            igniteContext = new JavaIgniteContext<>( sparkContext, ()-> {
             try {
              return ClientConfigurationFactory.createConfiguration();
             } catch (Exception e) {
              e.printStackTrace();
              return null;
             }
            });


    Any suggestion is much appreciated.


    ------------------------------
    mtseng
    ------------------------------


  • 2.  RE: Spring application context resource is not injected in ignite for spark

    Posted 04-08-2020 02:05 PM
    Hi,

    Can you please share ImportedCluster-client.xml? I think the issue here is that you don't have data source bean in this file. It's configured in ImportedCluster-server.xml and can be copied from there.



    ------------------------------
    Evgenii Zhuravlev
    Team Lead
    GridGain Systems
    ------------------------------



  • 3.  RE: Spring application context resource is not injected in ignite for spark

     
    Posted 04-08-2020 02:47 PM
      |   view attached
    ​Attached is the xml file generated from Web console via db schema import.

    ------------------------------
    mtseng
    ------------------------------

    Attachment(s)



  • 4.  RE: Spring application context resource is not injected in ignite for spark

    Posted 04-09-2020 08:40 AM

    Hi,

    As I know exists several issues related to IgniteSparkSession class. For example, I found that it can't start the client nodes in separate hosts:

    https://issues.apache.org/jira/browse/IGNITE-12637

    I guess that you faced some kind of the similar issue.

    However, I suggest you to use Ignite data frames instead. They were tested much more and can work in distributed environment. Here you can see the example of how you can write to Ignite (example was taken from https://www.gridgain.com/resources/blog/how-debug-data-loading-spark-ignite):

    String configPath = "client.xml";
    
    SparkConf sparkConf = new SparkConf()
     .setAppName("Example");
    
    SparkSession session = SparkSession.builder()
     .config(sparkConf)
     .getOrCreate();
    
    Dataset < Row > csvDataset = session.read()
     .format("csv")
     .option("sep", ",")
     .option("header", true)
     .load("person.csv");
    
    Dataset < Row > resultDF = csvDataset
     .select("id", "name", "city_id", "company")
     .sort("id")
     .limit(10000);
    
    DataFrameWriter < Row > df = resultDF
     .write()
     .format(IgniteDataFrameSettings.FORMAT_IGNITE())
     .option(IgniteDataFrameSettings.OPTION_CONFIG_FILE(), configPath)
     .option(IgniteDataFrameSettings.OPTION_TABLE(), "Person")
     .option(IgniteDataFrameSettings.OPTION_CREATE_TABLE_PRIMARY_KEY_FIELDS(), "id, city_id")
     .option(IgniteDataFrameSettings.OPTION_CREATE_TABLE_PARAMETERS(), "template=partitioned,backups=1")
     .mode(Append);
    
    df.save();
    
    session.close();

    So you can use here your OracleDB data frame instead of CSV.

    BR,

    Andrei



    ------------------------------
    Andrei Alexsandrov
    Developer
    GridGain
    ------------------------------



  • 5.  RE: Spring application context resource is not injected in ignite for spark

     
    Posted 04-09-2020 09:58 AM
      |   view attached
    Hi Andrei,
    Thanks for the reply.
    Following your suggestion, I try the sample code below to read the dataframe from ignite cache, but still get the same error message.

    It looks like while it tried to load the cache configuration in the spark worker, it failed to create CacheJdbcPojoStore in CacheJdbcPojoStoreFactory.create() due to the following appCtx instance was not injected in Spark worker.
        /** Application context. */
        @SpringApplicationContextResource
        private transient Object appCtx;if (appCtx == null)
                    throw new IgniteException("Spring application context resource is not injected.");

    Please note that the appCtx is injected as expected when running outside of spark worker in my separate test.

    Full eclipse log is attached, and the test code is listed below:

      String configPath = "ImportedCluster-client.xml";
      SparkSession sparkSession = SparkSession.builder().master("local[*]")
        .config("spark.scheduler.mode","FAIR")
        .appName("Dataframe Example")
        .getOrCreate();
    
      Dataset<Row> df = sparkSession.read()
          .format(IgniteDataFrameSettings.FORMAT_IGNITE())                 //Data source 
          .option(IgniteDataFrameSettings.OPTION_TABLE(), "AWR_ENTITY_MAPPING")     //Table to read.
          .option(IgniteDataFrameSettings.OPTION_CONFIG_FILE(), configPath)   //Ignite config.
          .load();
      df.show();
      sparkSession.close();  


    ------------------------------
    mtseng
    ------------------------------

    Attachment(s)