├── .gitignore
├── LICENSE
├── README.md
├── _config.yml
├── chapters
├── .gitignore
├── LICENSE
├── README.md
├── chapter-bigdata-spark
│ ├── ignite-spark-scala
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── scala
│ │ │ └── com
│ │ │ └── blu
│ │ │ └── imdg
│ │ │ └── SparkIgniteTest.scala
│ ├── spark-shell-srcipts
│ │ ├── PutRdd.spark
│ │ └── ReadRdd.spark
│ └── wordcount
│ │ ├── pom.xml
│ │ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── blu
│ │ └── imdg
│ │ └── JavaWordCount.java
├── chapter-bigdata
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── config
│ │ ├── hive
│ │ │ ├── HiveQL.sql
│ │ │ ├── copy-hadoop-directory.sh
│ │ │ ├── create-metastore.sh
│ │ │ ├── hive-ig.sh
│ │ │ └── hive-site.xml
│ │ ├── ignite-inmemory
│ │ │ ├── default-config.xml
│ │ │ └── hadoop.sh
│ │ └── pig
│ │ │ └── piglatin.pig
│ │ ├── input
│ │ ├── movies_data.csv
│ │ ├── movies_with_duplicates.csv
│ │ └── t8.shakespeare.txt
│ │ ├── java
│ │ └── com
│ │ │ └── blu
│ │ │ └── imdg
│ │ │ └── igfs
│ │ │ ├── IngestFileInIGFS.java
│ │ │ └── MapReduceResultReader.java
│ │ ├── resources
│ │ ├── default-config.xml
│ │ ├── log4j.xml
│ │ └── t8.shakespeare.txt
│ │ └── statistics
│ │ └── inmemory.xlsx
├── chapter-caching
│ ├── hibernate
│ │ ├── pom.xml
│ │ ├── scripts
│ │ │ ├── emp-dept.ddl
│ │ │ ├── emp-dept.dml
│ │ │ ├── exc-rate.ddl
│ │ │ └── exc-rate.dml
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── blu
│ │ │ │ └── imdg
│ │ │ │ ├── EmpDaoImpl.java
│ │ │ │ ├── Run.java
│ │ │ │ ├── RunWebService.java
│ │ │ │ ├── dao
│ │ │ │ └── EmpDao.java
│ │ │ │ ├── dto
│ │ │ │ ├── Employee.java
│ │ │ │ └── ExchangeRate.java
│ │ │ │ └── ws
│ │ │ │ └── WebService.java
│ │ │ └── resources
│ │ │ ├── jdbc.properties
│ │ │ └── spring-core.xml
│ ├── mybatis
│ │ ├── pom.xml
│ │ ├── scripts
│ │ │ ├── emp-dept.ddl
│ │ │ └── emp-dept.dml
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── blu
│ │ │ │ └── imdg
│ │ │ │ ├── RunWebService.java
│ │ │ │ ├── WebServices.java
│ │ │ │ ├── dao
│ │ │ │ └── UserServices.java
│ │ │ │ ├── dto
│ │ │ │ └── Employee.java
│ │ │ │ └── mapper
│ │ │ │ └── UserMapper.java
│ │ │ └── resources
│ │ │ ├── com
│ │ │ └── blu
│ │ │ │ └── imdg
│ │ │ │ └── mapper
│ │ │ │ └── UserMapper.xml
│ │ │ ├── jdbc.properties
│ │ │ └── spring-core.xml
│ ├── offheap
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── blu
│ │ │ │ └── imdg
│ │ │ │ └── PutElementstoOffHeap.java
│ │ │ └── resources
│ │ │ ├── spring-offheap-tiered.xml
│ │ │ ├── spring-offheap-values.xml
│ │ │ └── spring-onheap-tiered.xml
│ └── web-session-clustering
│ │ ├── README
│ │ ├── pom.xml
│ │ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── blu
│ │ │ └── imdg
│ │ │ └── wsession
│ │ │ ├── bean
│ │ │ └── Person.java
│ │ │ └── controller
│ │ │ └── WebSessionController.java
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── spring-ignite-cache.xml
│ │ └── webapp
│ │ └── WEB-INF
│ │ ├── spring-servlet.xml
│ │ ├── views
│ │ └── welcome.jsp
│ │ └── web.xml
├── chapter-cep
│ ├── camel
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── blu
│ │ │ │ └── imdg
│ │ │ │ ├── ExampleNodeStartup.java
│ │ │ │ ├── ExamplesUtils.java
│ │ │ │ ├── camel
│ │ │ │ ├── CamelStreamerDirectIngestion.java
│ │ │ │ ├── CamelStreamerMediation.java
│ │ │ │ └── CamelStreamerMediationIngestion.java
│ │ │ │ ├── dto
│ │ │ │ ├── Alert.java
│ │ │ │ ├── Level.java
│ │ │ │ ├── MnpRouting.java
│ │ │ │ └── ServiceStatus.java
│ │ │ │ ├── processor
│ │ │ │ └── RouteProcessor.java
│ │ │ │ ├── query
│ │ │ │ ├── AlertMonitoring.java
│ │ │ │ └── QueryStatus.java
│ │ │ │ └── streamer
│ │ │ │ ├── HealthCheckStreamVisitor.java
│ │ │ │ └── HealthCheckStreamer.java
│ │ │ └── resources
│ │ │ ├── camel.properties
│ │ │ ├── default-config.xml
│ │ │ ├── example-default.xml
│ │ │ ├── example-ignite.xml
│ │ │ ├── ignite-log4j2.xml
│ │ │ └── input.json
│ ├── flume
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── blu
│ │ │ │ └── imdg
│ │ │ │ └── flume
│ │ │ │ ├── Transformer
│ │ │ │ └── FlumeEventTransformer.java
│ │ │ │ ├── config
│ │ │ │ ├── agent.sh
│ │ │ │ ├── demo.properties
│ │ │ │ └── example-ignite.xml
│ │ │ │ └── rpc
│ │ │ │ ├── RpcEventGenerator.java
│ │ │ │ └── RunClient.java
│ │ │ └── resources
│ │ │ └── generator.properties
│ └── storm
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── blu
│ │ │ └── imdg
│ │ │ └── storm
│ │ │ ├── bolts
│ │ │ ├── SpeedLimitBolt.java
│ │ │ ├── SplitSentence.java
│ │ │ └── WordCount.java
│ │ │ ├── spouts
│ │ │ ├── FileSourceSpout.java
│ │ │ └── RandomSentenceSpout.java
│ │ │ └── topology
│ │ │ ├── SpeedViolationTopology.java
│ │ │ └── WordCountTopology.java
│ │ └── resources
│ │ ├── example-ignite.xml
│ │ ├── ignite-storm.properties
│ │ └── source.csv
├── chapter-dist-computing
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── blu
│ │ │ └── imdg
│ │ │ ├── StartCacheNode.java
│ │ │ ├── common
│ │ │ ├── CommonConstants.java
│ │ │ ├── HttpAuditClient.java
│ │ │ ├── HttpAuditEmulator.java
│ │ │ ├── JSEvaluate.java
│ │ │ ├── TestDataGenerator.java
│ │ │ ├── XPathExecutor.java
│ │ │ ├── XsdValidator.java
│ │ │ └── bankData
│ │ │ │ ├── BankDataGenerator.java
│ │ │ │ └── model
│ │ │ │ ├── AccountCacheData.java
│ │ │ │ ├── AccountCacheKey.java
│ │ │ │ ├── AccountData.java
│ │ │ │ ├── AccountKey.java
│ │ │ │ ├── CashBackDictionaryData.java
│ │ │ │ ├── TransactionData.java
│ │ │ │ └── TransactionKey.java
│ │ │ ├── example1
│ │ │ ├── SimpleComputation.java
│ │ │ └── SimpleComputationClosure.java
│ │ │ ├── example10
│ │ │ ├── AsyncBankService.java
│ │ │ ├── AsyncBankServiceImpl.java
│ │ │ ├── TestAsyncMicroServiceMain.java
│ │ │ ├── ZeroMQBroker.java
│ │ │ └── dto
│ │ │ │ ├── ValidateRequest.java
│ │ │ │ └── ValidateResponse.java
│ │ │ ├── example2
│ │ │ └── AsyncComputation.java
│ │ │ ├── example3
│ │ │ ├── ForkJoinComputation.java
│ │ │ ├── ForkJoinJobAdapter.java
│ │ │ └── ValidateMessage.java
│ │ │ ├── example4
│ │ │ ├── ForkJoinComputationExt.java
│ │ │ └── ForkJoinJobAdapterExt.java
│ │ │ ├── example5
│ │ │ ├── ForkJoinWithSessionJobAdapter.java
│ │ │ └── ForkJointWithSessionComputation.java
│ │ │ ├── example6
│ │ │ ├── ForkJoinWithCheckpointComputation.java
│ │ │ └── ForkJoinWithCheckpointJobAdapter.java
│ │ │ ├── example7
│ │ │ ├── DeployClusterSingleton.java
│ │ │ ├── DeployNodeSingleton.java
│ │ │ ├── RunXsdValidationService.java
│ │ │ ├── ServiceManagements.java
│ │ │ ├── TestXsdValidatingService.java
│ │ │ ├── XsdValidatingService.java
│ │ │ └── XsdValidatingServiceImpl.java
│ │ │ ├── example8
│ │ │ └── TestAccountSavingsMain.java
│ │ │ └── example9
│ │ │ ├── BankService.java
│ │ │ ├── BankServiceImpl.java
│ │ │ ├── DeployService.java
│ │ │ ├── LogService.java
│ │ │ ├── LogServiceImpl.java
│ │ │ ├── ServiceHttpClient.java
│ │ │ ├── TestMicroServiceMain.java
│ │ │ └── exception
│ │ │ ├── AccountNotFoundException.java
│ │ │ └── LogServiceException.java
│ │ └── resources
│ │ └── META-INF
│ │ └── org
│ │ └── book
│ │ └── examples
│ │ ├── base-config.xml
│ │ ├── cache-node-config.xml
│ │ ├── data
│ │ ├── sample1.xml
│ │ ├── sample2.xml
│ │ ├── sample3.xml
│ │ ├── validate-schema.xsd
│ │ └── validate-script.js
│ │ └── simple-client-config.xml
├── chapter-installation
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── blu
│ │ │ ├── dto
│ │ │ └── Person.java
│ │ │ └── imdg
│ │ │ ├── HelloIgnite.java
│ │ │ ├── HelloIgniteAsyn.java
│ │ │ └── HelloIgniteSpring.java
│ │ └── resources
│ │ └── default-config.xml
├── chapter-persistence
│ ├── README.md
│ ├── expiry
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── blu
│ │ │ │ └── imdg
│ │ │ │ └── IgniteExpiryExample.java
│ │ │ └── resources
│ │ │ └── default-config.xml
│ ├── persistence-store
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── blu
│ │ │ │ └── imdg
│ │ │ │ ├── CacheStoreSample.java
│ │ │ │ ├── jdbc
│ │ │ │ ├── PostgresDBStore.java
│ │ │ │ └── model
│ │ │ │ │ └── Post.java
│ │ │ │ └── nosql
│ │ │ │ ├── MongoDBStore.java
│ │ │ │ ├── PostRepository.java
│ │ │ │ └── model
│ │ │ │ └── MongoPost.java
│ │ │ └── resources
│ │ │ ├── create-db-scheme.ddl
│ │ │ ├── jdbc.properties
│ │ │ ├── logback.xml
│ │ │ ├── mongo-context.xml
│ │ │ └── postgres-context.xml
│ ├── pom.xml
│ ├── spring-data
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── blu
│ │ │ └── imdg
│ │ │ ├── App.java
│ │ │ ├── model
│ │ │ ├── Breed.java
│ │ │ └── Dog.java
│ │ │ └── repositories
│ │ │ ├── BreedRepository.java
│ │ │ ├── DogRepository.java
│ │ │ └── SpringAppConfig.java
│ ├── sqlqueries
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── blu
│ │ │ │ └── imdg
│ │ │ │ ├── SqlQueryEmployees.java
│ │ │ │ └── model
│ │ │ │ ├── Department.java
│ │ │ │ ├── Employee.java
│ │ │ │ └── EmployeeKey.java
│ │ │ └── resources
│ │ │ ├── create-table.ddl
│ │ │ ├── example-ignite.xml
│ │ │ ├── insert-data.dml
│ │ │ └── logback.xml
│ ├── textquery
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── blu
│ │ │ │ └── imdg
│ │ │ │ ├── TextQueryExample.java
│ │ │ │ └── model
│ │ │ │ └── Company.java
│ │ │ └── resources
│ │ │ ├── USA_NY_email_addresses.csv
│ │ │ ├── example-ignite.xml
│ │ │ └── logback.xml
│ └── transactions
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── blu
│ │ │ └── imdg
│ │ │ └── SimpleTransactions.java
│ │ └── resources
│ │ ├── example-ignite.xml
│ │ └── logback.xml
├── chapters.ipr
└── pom.xml
└── highperfomance-mini.jpg
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### JetBrains template
3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
5 |
6 | # User-specific stuff:
7 | .idea/**
8 | **.iml
9 | **.ipr
10 | # Sensitive or high-churn files:
11 | .idea/dataSources.ids
12 | .idea/dataSources.xml
13 | .idea/dataSources.local.xml
14 | .idea/sqlDataSources.xml
15 | .idea/dynamic.xml
16 | .idea/uiDesigner.xml
17 |
18 | # Gradle:
19 | .idea/gradle.xml
20 | .idea/libraries
21 |
22 | # Mongo Explorer plugin:
23 | .idea/mongoSettings.xml
24 |
25 | ## File-based project format:
26 | *.iws
27 |
28 | ## Plugin-specific files:
29 |
30 | # IntelliJ
31 | /out/
32 |
33 | # mpeltonen/sbt-idea plugin
34 | .idea_modules/
35 |
36 | # JIRA plugin
37 | atlassian-ide-plugin.xml
38 |
39 | # Crashlytics plugin (for Android Studio and IntelliJ)
40 | com_crashlytics_export_strings.xml
41 | crashlytics.properties
42 | crashlytics-build.properties
43 | fabric.properties
44 | ### Maven template
45 | target/
46 | pom.xml.tag
47 | pom.xml.releaseBackup
48 | pom.xml.versionsBackup
49 | pom.xml.next
50 | release.properties
51 | dependency-reduced-pom.xml
52 | buildNumber.properties
53 | .mvn/timing.properties
54 | ### Java template
55 | *.class
56 |
57 | # Mobile Tools for Java (J2ME)
58 | .mtj.tmp/
59 |
60 | # Package Files #
61 | *.jar
62 | *.war
63 | *.ear
64 |
65 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
66 | hs_err_pid*
67 | .idea/
68 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # High performance in-memory data grid with Apache Ignite
2 |
3 | All code samples, scripts and more in-depth examples for the book **High performance in-memory computing with Apache Ignite**.
4 |
5 | [](http://leanpub.com/ignite)
6 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-architect
--------------------------------------------------------------------------------
/chapters/.gitignore:
--------------------------------------------------------------------------------
1 | **.iml
2 | **/target
3 | /chapter-cep-flume/target/
4 | /chapter-cep-flume/chapter-cep-flume.iws
5 | /chapter-cep-storm/.idea/
6 | /chapter-dist-computing/target/
7 | /chapters.ipr
8 | /chapters.iml
9 | /chapters.iws
10 | /chapter-cep/camel/target/
11 | /chapters.ids
12 | /chapter-persistence/expiry/expiry.iml
13 | /chapter-bigdata-spark/wordcount/ignite-spark.iml
14 | /chapter-bigdata-spark/wordcount/wordcount.ipr
15 | /chapter-bigdata-spark/wordcount/wordcount.iws
16 |
--------------------------------------------------------------------------------
/chapters/README.md:
--------------------------------------------------------------------------------
1 | ## Prerequisites
2 | | N | Name | Value |
3 | |---|---------|--------------------------------------------------------------------------------------|
4 | | 1 | JDK | Oracle JDK 8 and above |
5 | | 2 | OS | Linux, MacOS (10.6 and above), Windows XP and above, Windows Server (2008 and above) |
6 | |3 | Ignite version| 1.6 or above |
7 |
8 | > To compile, run the following command:
9 |
10 | > mvn clean install
11 |
--------------------------------------------------------------------------------
/chapters/chapter-bigdata-spark/ignite-spark-scala/src/main/scala/com/blu/imdg/SparkIgniteTest.scala:
--------------------------------------------------------------------------------
1 | package com.blu.imdg
2 |
3 | import org.apache.ignite.configuration._
4 | import org.apache.ignite.spark.{IgniteContext, IgniteRDD}
5 | import org.apache.spark.{SparkConf, SparkContext}
6 |
7 | object RDDProducer extends App {
8 | val conf = new SparkConf().setAppName("SparkIgniteProducer")
9 | val sc = new SparkContext(conf)
10 | val ic = new IgniteContext[Int, Int](sc, () => new IgniteConfiguration())
11 | val sharedRDD: IgniteRDD[Int, Int] = ic.fromCache("IgniteRDD")
12 | sharedRDD.savePairs(sc.parallelize(1 to 1000, 10).map(i => (i, i)))
13 | }
14 |
15 | object RDDConsumer extends App {
16 | val conf = new SparkConf().setAppName("SparkIgniteConsume")
17 | val sc = new SparkContext(conf)
18 | val ic = new IgniteContext[Int, Int](sc, () => new IgniteConfiguration())
19 | val sharedRDD = ic.fromCache("IgniteRDD")
20 | val lessThanTwenty = sharedRDD.filter(_._2 < 20)
21 | println("The count is:::::::::::: "+lessThanTwenty.count())
22 | }
--------------------------------------------------------------------------------
/chapters/chapter-bigdata-spark/spark-shell-srcipts/PutRdd.spark:
--------------------------------------------------------------------------------
1 | import org.apache.ignite.spark._
2 | import org.apache.ignite.configuration._
3 | val ic = new IgniteContext[Int, String](sc, () => new IgniteConfiguration())
4 | val igniteRdd = ic.fromCache("SparkIgniteRDD")
5 | val RDDa = sc.parallelize(List("packt", "leanpub", "oreally", "wiston", "neahua"), 2)
6 | val RDDb = RDDa.map(x => (x.length, x))
7 | igniteRdd.savePairs(RDDb)
--------------------------------------------------------------------------------
/chapters/chapter-bigdata-spark/spark-shell-srcipts/ReadRdd.spark:
--------------------------------------------------------------------------------
1 | import org.apache.ignite.spark._
2 | import org.apache.ignite.configuration._
3 |
4 | val ic = new IgniteContext[Int, String](sc, () => new IgniteConfiguration())
5 | val igniteRdd = ic.fromCache("SparkIgniteRDD")
6 | val res = igniteRdd.foldByKey("")(_ + _).collect
--------------------------------------------------------------------------------
/chapters/chapter-bigdata-spark/wordcount/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 |
6 | com.blu.imdg
7 | chapters
8 | 1.0-SNAPSHOT
9 | ../../parent
10 |
11 | com.blu.imdg
12 | wordcount
13 | 1.0-SNAPSHOT
14 | jar
15 |
16 | wordcount
17 | http://maven.apache.org
18 |
19 |
20 | UTF-8
21 |
22 |
23 |
24 |
25 | junit
26 | junit
27 | 3.8.1
28 | test
29 |
30 |
31 | org.apache.spark
32 | spark-core_2.10
33 | 1.6.0
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/chapters/chapter-bigdata-spark/wordcount/src/main/java/com/blu/imdg/JavaWordCount.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg;
2 |
3 | /**
4 | * Created by shamim on 29/02/16.
5 | */
6 | import scala.Tuple2;
7 | import org.apache.spark.SparkConf;
8 | import org.apache.spark.api.java.JavaPairRDD;
9 | import org.apache.spark.api.java.JavaRDD;
10 | import org.apache.spark.api.java.JavaSparkContext;
11 | import org.apache.spark.api.java.function.FlatMapFunction;
12 | import org.apache.spark.api.java.function.Function2;
13 | import org.apache.spark.api.java.function.PairFunction;
14 |
15 | import java.util.Arrays;
16 | import java.util.List;
17 | import java.util.regex.Pattern;
18 |
19 | /**
20 | * Run in Spark Shell : ./spark-submit --class com.blu.imdg.JavaWordCount --master spark://192.168.1.37:7077 ~/Development/workshop/github/ignite-book-code-samples/chapters/chapter-bigdata-spark/wordcount/target/wordcount-1.0-SNAPSHOT.jar ~/Downloads/CHANGES.txt ~/Downloads/
21 | * */
22 | public final class JavaWordCount {
23 | private static final Pattern SPACE = Pattern.compile(" ");
24 |
25 | public static void main(String[] args) throws Exception {
26 |
27 | if (args.length < 1) {
28 | System.err.println("Usage: JavaWordCount ");
29 | System.exit(1);
30 | }
31 |
32 | SparkConf sparkConf = new SparkConf().setAppName("JavaWordCount");
33 | JavaSparkContext ctx = new JavaSparkContext(sparkConf);
34 | JavaRDD lines = ctx.textFile(args[0], 1);
35 |
36 | JavaRDD words = lines.flatMap(new FlatMapFunction() {
37 | //@Override
38 | public Iterable call(String s) {
39 | return Arrays.asList(SPACE.split(s));
40 | }
41 | });
42 |
43 | JavaPairRDD ones = words.mapToPair(new PairFunction() {
44 | //@Override
45 | public Tuple2 call(String s) {
46 | return new Tuple2(s, 1);
47 | }
48 | });
49 |
50 | JavaPairRDD counts = ones.reduceByKey(new Function2() {
51 | //@Override
52 | public Integer call(Integer i1, Integer i2) {
53 | return i1 + i2;
54 | }
55 | });
56 |
57 | List> output = counts.collect();
58 | for (Tuple2,?> tuple : output) {
59 | System.out.println(tuple._1() + ": " + tuple._2());
60 | }
61 | ctx.stop();
62 | }
63 | }
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/config/hive/HiveQL.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE input (line STRING);
2 | LOAD DATA LOCAL INPATH '/FILE_PATH/t8.shakespeare.txt' OVERWRITE INTO TABLE input;
3 | SELECT word, COUNT(*) FROM input LATERAL VIEW explode(split(line, ' ')) lTable as word GROUP BY word;
4 |
5 | CREATE TABLE IF NOT EXISTS movies
6 | (id STRING,
7 | title STRING,
8 | releasedate STRING,
9 | rating INT,
10 | Publisher STRING)
11 | ROW FORMAT DELIMITED
12 | FIELDS TERMINATED BY ','
13 | STORED AS TEXTFILE;
14 |
15 | LOAD DATA local INPATH '/FILE_PATH/movies_data.csv' OVERWRITE INTO TABLE movies;
16 |
17 | Select releasedate, count(releasedate) from movies m group by m.releasedate;
18 | Select releasedate, count(releasedate) from movies m where rating >3 group by m.releasedate;
19 |
20 | #load data from IGFS
21 | CREATE TABLE igfsinput (line STRING);
22 |
23 | LOAD DATA INPATH '/myDir/myFile' OVERWRITE INTO TABLE igfsinput;
24 |
25 | SELECT word, COUNT(*) FROM igfsinput LATERAL VIEW explode(split(line, ' ')) lTable as word GROUP BY word;
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/config/hive/copy-hadoop-directory.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | cd $HADOOP_HOME/etc
3 | mkdir hadoop-hive
4 | cp ./hadoop/*.* ./hadoop-hive
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/config/hive/create-metastore.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | schematool -initSchema -dbType derby
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/config/hive/hive-ig.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # Specify Hive home directory:
3 | export HIVE_HOME=
4 |
5 | # If you did not set hadoop executable in PATH, specify Hadoop home explicitly:
6 | export HADOOP_HOME=
7 |
8 | # Specify configuration files location:
9 | export HIVE_CONF_DIR=$HADOOP_HOME/etc/hadoop-hive
10 |
11 | # Avoid problem with different 'jline' library in Hadoop:
12 | export HADOOP_USER_CLASSPATH_FIRST=true
13 |
14 | ${HIVE_HOME}/bin/hive "${@}"
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/config/hive/hive-site.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 | hive.rpc.query.plan
9 | true
10 |
11 |
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/config/ignite-inmemory/default-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | 127.0.0.1:47500..47509
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/config/ignite-inmemory/hadoop.sh:
--------------------------------------------------------------------------------
1 | #Setup password less or passphrase less ssh
2 | $ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
3 | $ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
4 | $ chmod 0600 ~/.ssh/authorized_keys
5 |
6 | #Format the HDFS file system
7 | $bin/hdfs namenode -format
8 |
9 | #Start namenode/datanode daemon
10 | $ sbin/start-dfs.sh
11 |
12 | #Create new directories into HDFS
13 | $bin/hdfs dfs -mkdir /user
14 | $bin/hdfs dfs -mkdir /input
15 |
16 | #Insert some files in directory /input
17 | $bin/hdfs dfs -put $HADOOP_HOME/etc/hadoop /input
18 |
19 | #Run the map reduce worcount example
20 | $bin/hadoop jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /input/hadoop output
21 |
22 | #View the output from the HDFS
23 | $bin/hdfs dfs -cat output/*
24 |
25 | #Add shakespeare.txt into HDFS directory wc-input
26 | $bin/hdfs dfs -put /YOUR_PATH_TO_THE_FILE /t8.shakespeare.txt /wc-input
27 |
28 | # run Hadoop wordcount example for Shakespeare work of art
29 | time hadoop jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /wc-input/ output6
30 |
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/config/pig/piglatin.pig:
--------------------------------------------------------------------------------
1 | #Word count example
2 | A = load '/wc-input/t8.shakespeare.txt';
3 | B = foreach A generate flatten(TOKENIZE((chararray)$0)) as word;
4 | C = group B by word;
5 | D = foreach C generate COUNT(B), group;
6 | E = Limit D 10;
7 | Dump E;
8 | # movie
9 | movies = LOAD '/input/hadoop/movies_data.csv' USING PigStorage(',') as (id:int,name:chararray,year:int,rating:double,duration:int);
10 | movies_rating_greater_than_four = FILTER movies BY (float)rating > 4.0;
11 | DUMP movies_rating_greater_than_four;
12 | movie_mummy = FILTER movies by (name matches '.*Mummy.*');
13 | grouped_by_year = group movies by year;
14 | count_by_year = FOREACH grouped_by_year GENERATE group, COUNT(movies);
15 | group_all = GROUP count_by_year ALL;
16 | sum_all = FOREACH group_all GENERATE SUM(count_by_year.$1);
17 | DUMP sum_all;
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/input/movies_with_duplicates.csv:
--------------------------------------------------------------------------------
1 | 1,The Nightmare Before Christmas,1993,3.9,4568
2 | 1,The Nightmare Before Christmas,1993,3.9,4568
3 | 1,The Nightmare Before Christmas,1993,3.9,4568
4 | 2,The Mummy,1932,3.5,4388
5 | 3,Orphans of the Storm,1921,3.2,9062
6 | 4,The Object of Beauty,1991,2.8,6150
7 | 5,Night Tide,1963,2.8,5126
8 | 5,Night Tide,1963,2.8,5126
9 | 5,Night Tide,1963,2.8,5126
10 | 6,One Magic Christmas,1985,3.8,5333
11 | 7,Muriel's Wedding,1994,3.5,6323
12 | 8,Mother's Boys,1994,3.4,5733
13 | 9,Nosferatu: Original Version,1929,3.5,5651
14 | 10,Nick of Time,1995,3.4,5333
15 | 9,Nosferatu: Original Version,1929,3.5,5651
16 |
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/java/com/blu/imdg/igfs/IngestFileInIGFS.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.igfs;
2 |
3 | import com.google.common.io.ByteStreams;
4 | import org.apache.ignite.Ignite;
5 | import org.apache.ignite.IgniteFileSystem;
6 | import org.apache.ignite.Ignition;
7 | import org.apache.ignite.igfs.IgfsPath;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 |
11 | import java.io.IOException;
12 | import java.io.InputStream;
13 | import java.io.OutputStream;
14 | import java.util.Collection;
15 | import java.util.Iterator;
16 |
17 |
18 | /**
19 | * Created by shamim on 06/09/16.
20 | */
21 | public class IngestFileInIGFS {
22 | private final static Logger LOGGER = LoggerFactory.getLogger(IngestFileInIGFS.class);
23 | private final static String IGFS_FS_NAME= "igfs";
24 |
25 | public static void main(String... args) {
26 | if(args.length < 2){
27 | LOGGER.error("Usages [java -jar chapter-hadoop-spark-1.0-SNAPSHOT.jar DIRECTORY_NAME FILE NAME, for example java -jar chapter-hadoop-spark-1.0-SNAPSHOT.jar myDir myFile]");
28 | System.exit(0);
29 | }
30 |
31 | Ignite ignite = Ignition.start("default-config.xml");
32 | Ignition.setClientMode(true);
33 |
34 | Collection fs = ignite.fileSystems();
35 |
36 | for(Iterator ite = fs.iterator();ite.hasNext();){
37 | IgniteFileSystem igniteFileSystem = (IgniteFileSystem) ite.next();
38 |
39 | LOGGER.info("IGFS File System name:" + igniteFileSystem.name());
40 | }
41 |
42 | IgniteFileSystem igfs = ignite.fileSystem(IGFS_FS_NAME);
43 | // Create directory.
44 | IgfsPath dir = new IgfsPath("/" + args[0]);
45 | igfs.mkdirs(dir);
46 |
47 | // Create file and write some data to it.
48 | IgfsPath file = new IgfsPath(dir, args[1]);
49 | // Read the File Shakespeare
50 | InputStream inputStream = IngestFileInIGFS.class.getClassLoader().getResourceAsStream("t8.shakespeare.txt");
51 |
52 | byte[] filesToByte;
53 | try {
54 | filesToByte = ByteStreams.toByteArray(inputStream);
55 | OutputStream out = igfs.create(file, true);
56 |
57 | out.write(filesToByte);
58 | out.close();
59 |
60 | } catch (IOException e) {
61 | LOGGER.error(e.getMessage());
62 | } finally {
63 | try {
64 | inputStream.close();
65 | } catch (IOException e) {
66 | LOGGER.error(e.getMessage());
67 | }
68 | }
69 |
70 | LOGGER.info("Created file path:" + file.toString());
71 |
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/chapters/chapter-bigdata/src/main/statistics/inmemory.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/srecon/ignite-book-code-samples/34eb1453a2a39b96e3bcbdafb5fa89f96018e775/chapters/chapter-bigdata/src/main/statistics/inmemory.xlsx
--------------------------------------------------------------------------------
/chapters/chapter-caching/hibernate/scripts/emp-dept.ddl:
--------------------------------------------------------------------------------
1 | create table dept(
2 | deptno integer,
3 | dname text,
4 | loc text,
5 | constraint pk_dept primary key (deptno)
6 | );
7 |
8 | create table emp(
9 | empno integer,
10 | ename text,
11 | job text,
12 | mgr integer,
13 | hiredate date,
14 | sal integer,
15 | comm integer,
16 | deptno integer,
17 | constraint pk_emp primary key (empno),
18 | constraint fk_deptno foreign key (deptno) references dept (deptno)
19 | );
20 |
21 | CREATE UNIQUE INDEX ename_idx ON emp (ename);
--------------------------------------------------------------------------------
/chapters/chapter-caching/hibernate/scripts/emp-dept.dml:
--------------------------------------------------------------------------------
1 | insert into dept
2 | values(10, 'ACCOUNTING', 'NEW YORK');
3 | insert into dept
4 | values(20, 'RESEARCH', 'DALLAS');
5 | insert into dept
6 | values(30, 'SALES', 'CHICAGO');
7 | insert into dept
8 | values(40, 'OPERATIONS', 'BOSTON');
9 |
10 | insert into emp
11 | values(
12 | 7839, 'KING', 'PRESIDENT', null,
13 | to_date('17-11-1981','dd-mm-yyyy'),
14 | 5000, null, 10
15 | );
16 | insert into emp
17 | values(
18 | 7698, 'BLAKE', 'MANAGER', 7839,
19 | to_date('1-5-1981','dd-mm-yyyy'),
20 | 2850, null, 30
21 | );
22 | insert into emp
23 | values(
24 | 7782, 'CLARK', 'MANAGER', 7839,
25 | to_date('9-6-1981','dd-mm-yyyy'),
26 | 2450, null, 10
27 | );
28 | insert into emp
29 | values(
30 | 7566, 'JONES', 'MANAGER', 7839,
31 | to_date('2-4-1981','dd-mm-yyyy'),
32 | 2975, null, 20
33 | );
34 | insert into emp
35 | values(
36 | 7788, 'SCOTT', 'ANALYST', 7566,
37 | to_date('13-07-87','dd-mm-rr') - 85,
38 | 3000, null, 20
39 | );
40 | insert into emp
41 | values(
42 | 7902, 'FORD', 'ANALYST', 7566,
43 | to_date('3-12-1981','dd-mm-yyyy'),
44 | 3000, null, 20
45 | );
46 | insert into emp
47 | values(
48 | 7369, 'SMITH', 'CLERK', 7902,
49 | to_date('17-12-1980','dd-mm-yyyy'),
50 | 800, null, 20
51 | );
52 | insert into emp
53 | values(
54 | 7499, 'ALLEN', 'SALESMAN', 7698,
55 | to_date('20-2-1981','dd-mm-yyyy'),
56 | 1600, 300, 30
57 | );
58 | insert into emp
59 | values(
60 | 7521, 'WARD', 'SALESMAN', 7698,
61 | to_date('22-2-1981','dd-mm-yyyy'),
62 | 1250, 500, 30
63 | );
64 | insert into emp
65 | values(
66 | 7654, 'MARTIN', 'SALESMAN', 7698,
67 | to_date('28-9-1981','dd-mm-yyyy'),
68 | 1250, 1400, 30
69 | );
70 | insert into emp
71 | values(
72 | 7844, 'TURNER', 'SALESMAN', 7698,
73 | to_date('8-9-1981','dd-mm-yyyy'),
74 | 1500, 0, 30
75 | );
76 | insert into emp
77 | values(
78 | 7876, 'ADAMS', 'CLERK', 7788,
79 | to_date('13-07-87', 'dd-mm-rr') - 51,
80 | 1100, null, 20
81 | );
82 | insert into emp
83 | values(
84 | 7900, 'JAMES', 'CLERK', 7698,
85 | to_date('3-12-1981','dd-mm-yyyy'),
86 | 950, null, 30
87 | );
88 | insert into emp
89 | values(
90 | 7934, 'MILLER', 'CLERK', 7782,
91 | to_date('23-1-1982','dd-mm-yyyy'),
92 | 1300, null, 10
93 | );
94 |
95 |
96 | commit;
--------------------------------------------------------------------------------
/chapters/chapter-caching/hibernate/scripts/exc-rate.ddl:
--------------------------------------------------------------------------------
1 | create table exchangerate(
2 | ratedate date,
3 | usdollar decimal,
4 | euro decimal,
5 | gbp decimal,
6 | region text,
7 | primary key (ratedate, region)
8 | );
--------------------------------------------------------------------------------
/chapters/chapter-caching/hibernate/scripts/exc-rate.dml:
--------------------------------------------------------------------------------
1 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES (
2 | TO_DATE('2015-05-01','YYYY-MM-DD'),69.7,75.9,103.01,'Vladimir');
3 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES (
4 | TO_DATE('2015-05-02','YYYY-MM-DD'),71.7,77.1,102.03,'Tver');
5 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES (
6 | TO_DATE('2015-05-02','YYYY-MM-DD'),71.7,77.1,102.03,'Moscow');
7 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES (
8 | TO_DATE('2015-05-02','YYYY-MM-DD'),71.7,77.1,102.03,'Vladimir');
9 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES (
10 | TO_DATE('2015-05-03','YYYY-MM-DD'),71.9,77.4,101.03,'Tver');
11 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES (
12 | TO_DATE('2015-05-03','YYYY-MM-DD'),70.3,76.1,103.07,'Moscow');
13 | INSERT INTO public.exchangerate (ratedate,usdollar,euro,gbp,region) VALUES (
14 | TO_DATE('2015-05-03','YYYY-MM-DD'),71.1,77.4,101.01,'Vladimir');
15 | commit;
--------------------------------------------------------------------------------
/chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/Run.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg;
2 |
3 | import com.blu.imdg.dao.EmpDao;
4 | import com.blu.imdg.dto.Employee;
5 | import com.blu.imdg.dto.ExchangeRate;
6 | import org.springframework.context.ApplicationContext;
7 | import org.springframework.context.support.ClassPathXmlApplicationContext;
8 |
9 | import java.util.Date;
10 | import java.util.List;
11 |
12 | /**
13 | * Created by shamim on 24/06/16.
14 | */
15 | public class Run {
16 | public static void main(String[] args) {
17 | System.out.println("Hello Hibernate after a long time!!");
18 | ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-core.xml");
19 | EmpDao empDao = (EmpDao) ctx.getBean("empDAO");
20 | //List employee = empDao.getAllEmployees();
21 | //String res = empDao.getExchangeRateByRegion("Moscow");
22 | ExchangeRate e = new ExchangeRate();
23 | e.setRegion("Moscow");
24 | e.setRateDate(new Date(System.currentTimeMillis()));
25 | e.setUsdollar(71.17);
26 | empDao.updateExchange(e);
27 | System.out.println("return size:");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/RunWebService.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg;
2 |
3 | import com.blu.imdg.ws.WebService;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.support.ClassPathXmlApplicationContext;
6 |
7 | import javax.xml.ws.Endpoint;
8 |
9 | /**
10 | * Created by shamim on 24/06/16.
11 | */
12 | public class RunWebService {
13 | public static void main(String[] args) {
14 | ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-core.xml");
15 | WebService service = (WebService) ctx.getBean("serviceBean");
16 |
17 | Endpoint.publish("http://localhost:7001/invokeRules", service);
18 | System.out.println("Server start in Port .. 7001");
19 | }
20 | }
--------------------------------------------------------------------------------
/chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/dao/EmpDao.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.dao;
2 |
3 | import com.blu.imdg.dto.Employee;
4 | import com.blu.imdg.dto.ExchangeRate;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Created by shamim on 24/06/16.
10 | */
11 | public interface EmpDao {
12 | List getAllEmployees ();
13 | void create(Integer empno, String ename, String job, Integer mgr );
14 | List getEmpByName(String ename);
15 | String getExchangeRateByRegion(String region);
16 | void updateExchange(ExchangeRate e);
17 | }
18 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/dto/Employee.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.dto;
2 |
3 |
4 | import org.hibernate.annotations.CacheConcurrencyStrategy;
5 |
6 | import javax.persistence.*;
7 | import java.io.Serializable;
8 | import java.util.Date;
9 | import org.hibernate.annotations.Cache;
10 | import org.hibernate.annotations.CacheConcurrencyStrategy;
11 | /**
12 | * Created by shamim on 23/06/16.
13 | */
14 | @Entity
15 | @Cacheable
16 | @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
17 | @Table( name = "emp" )
18 | public class Employee implements Serializable{
19 | @Id
20 | //@GeneratedValue(strategy = GenerationType.IDENTITY)
21 | @Column(name = "empno")
22 | private Integer empno;
23 | @Column(name = "ename")
24 | private String ename;
25 | @Column(name = "job")
26 | private String job;
27 | @Column(name = "mgr")
28 | private Integer mgr;
29 | @Column(name = "hiredate")
30 | private Date date;
31 | @Column(name = "sal")
32 | private Integer sal;
33 | @Column(name = "deptno")
34 | private Integer deptno;
35 | @Column(name = "comm")
36 | private Integer comm;
37 |
38 | public Employee() {
39 | }
40 |
41 | public Integer getEmpno() {
42 | return empno;
43 | }
44 |
45 | public void setEmpno(Integer empno) {
46 | this.empno = empno;
47 | }
48 |
49 | public String getEname() {
50 | return ename;
51 | }
52 |
53 | public void setEname(String ename) {
54 | this.ename = ename;
55 | }
56 |
57 | public String getJob() {
58 | return job;
59 | }
60 |
61 | public void setJob(String job) {
62 | this.job = job;
63 | }
64 |
65 | public Integer getMgr() {
66 | return mgr;
67 | }
68 |
69 | public void setMgr(Integer mgr) {
70 | this.mgr = mgr;
71 | }
72 |
73 | public Date getDate() {
74 | return date;
75 | }
76 |
77 | public void setDate(Date date) {
78 | this.date = date;
79 | }
80 |
81 | public Integer getSal() {
82 | return sal;
83 | }
84 |
85 | public void setSal(Integer sal) {
86 | this.sal = sal;
87 | }
88 |
89 | public Integer getDeptno() {
90 | return deptno;
91 | }
92 |
93 | public void setDeptno(Integer deptno) {
94 | this.deptno = deptno;
95 | }
96 |
97 | public Integer getComm() {
98 | return comm;
99 | }
100 |
101 | public void setComm(Integer comm) {
102 | this.comm = comm;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/dto/ExchangeRate.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.dto;
2 |
3 | import org.hibernate.annotations.Cache;
4 | import org.hibernate.annotations.CacheConcurrencyStrategy;
5 |
6 | import javax.persistence.*;
7 | import java.util.Date;
8 |
9 | /**
10 | * User: bsha
11 | * Date: 03.07.2016
12 | * Time: 10:29
13 | */
14 | @Entity
15 | @Table( name = "emp" )
16 | public class ExchangeRate {
17 | @Id
18 | @Column(name = "region")
19 | private String region;
20 | @Column(name = "ratedate")
21 | private Date rateDate;
22 | @Column(name = "usdollar")
23 | private double usdollar;
24 | @Column(name = "euro")
25 | private double euro;
26 | @Column(name = "gbp")
27 | private double gbp;
28 |
29 | public ExchangeRate() {
30 | }
31 |
32 | public String getRegion() {
33 | return region;
34 | }
35 |
36 | public void setRegion(String region) {
37 | this.region = region;
38 | }
39 |
40 | public Date getRateDate() {
41 | return rateDate;
42 | }
43 |
44 | public void setRateDate(Date rateDate) {
45 | this.rateDate = rateDate;
46 | }
47 |
48 | public double getUsdollar() {
49 | return usdollar;
50 | }
51 |
52 | public void setUsdollar(double usdollar) {
53 | this.usdollar = usdollar;
54 | }
55 |
56 | public double getEuro() {
57 | return euro;
58 | }
59 |
60 | public void setEuro(double euro) {
61 | this.euro = euro;
62 | }
63 |
64 | public double getGbp() {
65 | return gbp;
66 | }
67 |
68 | public void setGbp(double gbp) {
69 | this.gbp = gbp;
70 | }
71 |
72 | @Override
73 | public boolean equals(Object o) {
74 | if (this == o) return true;
75 | if (o == null || getClass() != o.getClass()) return false;
76 |
77 | ExchangeRate that = (ExchangeRate) o;
78 |
79 | if (!rateDate.equals(that.rateDate)) return false;
80 | if (!region.equals(that.region)) return false;
81 |
82 | return true;
83 | }
84 |
85 | @Override
86 | public int hashCode() {
87 | int result = region.hashCode();
88 | result = 31 * result + rateDate.hashCode();
89 | return result;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/hibernate/src/main/java/com/blu/imdg/ws/WebService.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.ws;
2 |
3 | import com.blu.imdg.dao.EmpDao;
4 | import com.blu.imdg.dto.Employee;
5 | import com.blu.imdg.dto.ExchangeRate;
6 |
7 | import javax.jws.WebMethod;
8 | import java.util.Date;
9 | import java.util.List;
10 |
11 | /**
12 | * Created by shamim on 24/06/16.
13 | */
14 | @javax.jws.WebService(name = "BusinessRulesServices",
15 | serviceName="BusinessRulesServices",
16 | targetNamespace = "http://com.blu.rules/services")
17 | public class WebService {
18 | private EmpDao empDao;
19 |
20 | @WebMethod(exclude = true)
21 | public void setEmpDao(EmpDao empDao) {
22 | this.empDao = empDao;
23 | }
24 | @WebMethod(operationName = "getAllEmploees")
25 | public List getAllEmployees() {
26 | return empDao.getAllEmployees();
27 | }
28 | @WebMethod(operationName = "addEmployee")
29 | public void addEmployee(Integer empno, String ename, String job, Integer mgr ) {
30 | empDao.create(empno, ename, job, mgr);
31 | }
32 | @WebMethod(operationName = "getEmpByName")
33 | public List getEmpByName(String ename) {
34 | return empDao.getEmpByName(ename);
35 | }
36 | @WebMethod(operationName = "getExchangeRateByRegion")
37 | public String getExchangeRateByRegion(String str){
38 | return empDao.getExchangeRateByRegion(str);
39 | }
40 | @WebMethod(operationName = "updateExchangeRate")
41 | public void updateExchangeRate(String region, Date rateDate, double usdollar, double euro, double gbp){
42 | ExchangeRate e = new ExchangeRate();
43 | e.setRegion(region);
44 | e.setUsdollar(usdollar);
45 | e.setEuro(euro);
46 | e.setGbp(gbp);
47 | e.setRateDate(rateDate);
48 |
49 | empDao.updateExchange(e);
50 | }
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/hibernate/src/main/resources/jdbc.properties:
--------------------------------------------------------------------------------
1 | jdbc.driver=org.postgresql.Driver
2 | jdbc.url=jdbc:postgresql://192.168.9.78:5432/trudvsem_db
3 | jdbc.username=postgres
4 | jdbc.password=unix11
5 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/mybatis/scripts/emp-dept.ddl:
--------------------------------------------------------------------------------
1 | create table dept(
2 | deptno integer,
3 | dname text,
4 | loc text,
5 | constraint pk_dept primary key (deptno)
6 | );
7 |
8 | create table emp(
9 | empno integer,
10 | ename text,
11 | job text,
12 | mgr integer,
13 | hiredate date,
14 | sal integer,
15 | comm integer,
16 | deptno integer,
17 | constraint pk_emp primary key (empno),
18 | constraint fk_deptno foreign key (deptno) references dept (deptno)
19 | );
20 |
21 | CREATE UNIQUE INDEX ename_idx ON emp (ename);
--------------------------------------------------------------------------------
/chapters/chapter-caching/mybatis/scripts/emp-dept.dml:
--------------------------------------------------------------------------------
1 | insert into dept
2 | values(10, 'ACCOUNTING', 'NEW YORK');
3 | insert into dept
4 | values(20, 'RESEARCH', 'DALLAS');
5 | insert into dept
6 | values(30, 'SALES', 'CHICAGO');
7 | insert into dept
8 | values(40, 'OPERATIONS', 'BOSTON');
9 |
10 | insert into emp
11 | values(
12 | 7839, 'KING', 'PRESIDENT', null,
13 | to_date('17-11-1981','dd-mm-yyyy'),
14 | 5000, null, 10
15 | );
16 | insert into emp
17 | values(
18 | 7698, 'BLAKE', 'MANAGER', 7839,
19 | to_date('1-5-1981','dd-mm-yyyy'),
20 | 2850, null, 30
21 | );
22 | insert into emp
23 | values(
24 | 7782, 'CLARK', 'MANAGER', 7839,
25 | to_date('9-6-1981','dd-mm-yyyy'),
26 | 2450, null, 10
27 | );
28 | insert into emp
29 | values(
30 | 7566, 'JONES', 'MANAGER', 7839,
31 | to_date('2-4-1981','dd-mm-yyyy'),
32 | 2975, null, 20
33 | );
34 | insert into emp
35 | values(
36 | 7788, 'SCOTT', 'ANALYST', 7566,
37 | to_date('13-07-87','dd-mm-rr') - 85,
38 | 3000, null, 20
39 | );
40 | insert into emp
41 | values(
42 | 7902, 'FORD', 'ANALYST', 7566,
43 | to_date('3-12-1981','dd-mm-yyyy'),
44 | 3000, null, 20
45 | );
46 | insert into emp
47 | values(
48 | 7369, 'SMITH', 'CLERK', 7902,
49 | to_date('17-12-1980','dd-mm-yyyy'),
50 | 800, null, 20
51 | );
52 | insert into emp
53 | values(
54 | 7499, 'ALLEN', 'SALESMAN', 7698,
55 | to_date('20-2-1981','dd-mm-yyyy'),
56 | 1600, 300, 30
57 | );
58 | insert into emp
59 | values(
60 | 7521, 'WARD', 'SALESMAN', 7698,
61 | to_date('22-2-1981','dd-mm-yyyy'),
62 | 1250, 500, 30
63 | );
64 | insert into emp
65 | values(
66 | 7654, 'MARTIN', 'SALESMAN', 7698,
67 | to_date('28-9-1981','dd-mm-yyyy'),
68 | 1250, 1400, 30
69 | );
70 | insert into emp
71 | values(
72 | 7844, 'TURNER', 'SALESMAN', 7698,
73 | to_date('8-9-1981','dd-mm-yyyy'),
74 | 1500, 0, 30
75 | );
76 | insert into emp
77 | values(
78 | 7876, 'ADAMS', 'CLERK', 7788,
79 | to_date('13-07-87', 'dd-mm-rr') - 51,
80 | 1100, null, 20
81 | );
82 | insert into emp
83 | values(
84 | 7900, 'JAMES', 'CLERK', 7698,
85 | to_date('3-12-1981','dd-mm-yyyy'),
86 | 950, null, 30
87 | );
88 | insert into emp
89 | values(
90 | 7934, 'MILLER', 'CLERK', 7782,
91 | to_date('23-1-1982','dd-mm-yyyy'),
92 | 1300, null, 10
93 | );
94 |
95 |
96 | commit;
--------------------------------------------------------------------------------
/chapters/chapter-caching/mybatis/src/main/java/com/blu/imdg/RunWebService.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.ClassPathXmlApplicationContext;
5 |
6 | import javax.xml.ws.Endpoint;
7 |
8 | /**
9 | * Created by shamim on 14/02/16.
10 | */
11 | public class RunWebService {
12 | public static void main(String[] args) {
13 | ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-core.xml");
14 | WebServices services = (WebServices) ctx.getBean("servicesBean");
15 |
16 | Endpoint.publish("http://localhost:7001/invokeRules", services);
17 | System.out.println("Server start in Port .. 7001");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/mybatis/src/main/java/com/blu/imdg/WebServices.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg;
2 |
3 | import com.blu.imdg.dao.UserServices;
4 | import com.blu.imdg.dto.Employee;
5 |
6 | import javax.jws.WebMethod;
7 | import javax.jws.WebService;
8 |
9 | /**
10 | * Created by shamim on 14/02/16.
11 | */
12 | @WebService(name = "BusinessRulesServices",
13 | serviceName="BusinessRulesServices",
14 | targetNamespace = "http://com.blu.rules/services")
15 | public class WebServices {
16 | private UserServices userServices;
17 |
18 | @WebMethod(exclude = true)
19 | public void setDao(UserServices userServices){
20 | this.userServices = userServices;
21 | }
22 |
23 | @WebMethod(operationName = "getEmploee")
24 | public Employee getEmploee (String ename) {return userServices.getEmploee(ename);}
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/mybatis/src/main/java/com/blu/imdg/dao/UserServices.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.dao;
2 |
3 | import com.blu.imdg.dto.Employee;
4 | import com.blu.imdg.mapper.UserMapper;
5 | import org.springframework.cache.annotation.Cacheable;
6 |
7 | /**
8 | * Created by shamim on 16/02/16.
9 | */
10 | public class UserServices {
11 | private UserMapper userMapper;
12 |
13 | public void setUserMapper(UserMapper userMapper) {
14 | this.userMapper = userMapper;
15 | }
16 |
17 | public Employee getEmploee (String ename){return userMapper.getEmploee(ename);}
18 | }
19 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/mybatis/src/main/java/com/blu/imdg/dto/Employee.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.dto;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | /**
7 | * Created by shamim on 23/06/16.
8 | */
9 | public class Employee implements Serializable{
10 | private Integer empno;
11 | private String ename;
12 | private String job;
13 | private Integer mgr;
14 | private Date date;
15 | private Integer sal;
16 | private Integer deptno;
17 |
18 | public Integer getEmpno() {
19 | return empno;
20 | }
21 |
22 | public void setEmpno(Integer empno) {
23 | this.empno = empno;
24 | }
25 |
26 | public String getEname() {
27 | return ename;
28 | }
29 |
30 | public void setEname(String ename) {
31 | this.ename = ename;
32 | }
33 |
34 | public String getJob() {
35 | return job;
36 | }
37 |
38 | public void setJob(String job) {
39 | this.job = job;
40 | }
41 |
42 | public Integer getMgr() {
43 | return mgr;
44 | }
45 |
46 | public void setMgr(Integer mgr) {
47 | this.mgr = mgr;
48 | }
49 |
50 | public Date getDate() {
51 | return date;
52 | }
53 |
54 | public void setDate(Date date) {
55 | this.date = date;
56 | }
57 |
58 | public Integer getSal() {
59 | return sal;
60 | }
61 |
62 | public void setSal(Integer sal) {
63 | this.sal = sal;
64 | }
65 |
66 | public Integer getDeptno() {
67 | return deptno;
68 | }
69 |
70 | public void setDeptno(Integer deptno) {
71 | this.deptno = deptno;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/mybatis/src/main/java/com/blu/imdg/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.mapper;
2 |
3 | import com.blu.imdg.dto.Employee;
4 |
5 | /**
6 | * Created by shamim on 15/02/16.
7 | */
8 | public interface UserMapper {
9 |
10 | Employee getEmploee (String ename);
11 | }
12 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/mybatis/src/main/resources/com/blu/imdg/mapper/UserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/mybatis/src/main/resources/jdbc.properties:
--------------------------------------------------------------------------------
1 | jdbc.driver=org.postgresql.Driver
2 | jdbc.url=jdbc:postgresql://192.168.9.78:5432/trudvsem_db
3 | jdbc.username=postgres
4 | jdbc.password=unix11
5 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/offheap/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.blu.imdg
8 | chapters
9 | 1.0-SNAPSHOT
10 | ../../parent
11 |
12 | com.blu.imdg
13 | offheap
14 | 1.0-SNAPSHOT
15 | offheap
16 | http://maven.apache.org
17 |
18 | UTF-8
19 |
20 |
21 |
22 | org.apache.ignite
23 | ignite-core
24 |
25 |
26 | org.apache.ignite
27 | ignite-spring
28 |
29 |
30 |
31 |
32 |
33 | org.apache.maven.plugins
34 | maven-jar-plugin
35 |
36 |
37 |
38 | com.blu.imdg.PutElementstoOffHeap
39 |
40 |
41 |
42 |
43 |
44 | com.jolira
45 | onejar-maven-plugin
46 | 1.4.4
47 |
48 |
49 |
50 | one-jar
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | onejar-maven-plugin.googlecode.com
61 | http://onejar-maven-plugin.googlecode.com/svn/mavenrepo
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/offheap/src/main/java/com/blu/imdg/PutElementstoOffHeap.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg;
2 |
3 | import org.apache.ignite.Ignite;
4 | import org.apache.ignite.IgniteCache;
5 | import org.apache.ignite.Ignition;
6 | import org.apache.ignite.configuration.IgniteConfiguration;
7 | import org.springframework.context.ApplicationContext;
8 | import org.springframework.context.support.ClassPathXmlApplicationContext;
9 |
10 | /**
11 | * User: bsha
12 | * Date: 03.07.2016
13 | * Time: 17:58
14 | */
15 | public class PutElementstoOffHeap {
16 | public static void main(String[] args) throws Exception{
17 | if(args.length <= 0){
18 | System.out.println("Usages! java -jar .\\target\\chapter-three-offheap-1.0-SNAPSHOT.one-jar.jar spring-offheap-tiered.xml");
19 | System.exit(0);
20 | }
21 | String springCoreFile = args[0];
22 | // Start Ignite cluster
23 | Ignite ignite = Ignition.start(springCoreFile);
24 | // get or create cache
25 | IgniteCache cache = ignite.getOrCreateCache("offheap-cache");
26 | for(int i = 1; i <= 1000; i++){
27 | cache.put(i, Integer.toString(i));
28 | }
29 | for(int i =1; i<=1000;i++){
30 | System.out.println("Cache get:"+ cache.get(i));
31 | }
32 | System.out.println("Wait 10 seconds for statistics");
33 | Thread.sleep(10000);
34 | // statistics
35 | System.out.println("Cache Hits:"+ cache.metrics(ignite.cluster()).getCacheHits());
36 |
37 | System.out.println("Enter crtl-x to quite the application!!!");
38 | Thread.sleep(Integer.MAX_VALUE); // sleep for 20 seconds
39 |
40 | ignite.close();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/web-session-clustering/README:
--------------------------------------------------------------------------------
1 | mvn -Djetty.port=8080 jetty:run
2 |
3 | http://localhost:8080/test-session/putperson?name=shamim&age=38
4 | http://localhost:8081/test-session/getperson?name=shamim
5 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/web-session-clustering/pom.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 | 4.0.0
6 |
7 | com.blu.imdg
8 | chapters
9 | 1.0-SNAPSHOT
10 | ../../parent
11 |
12 | com.blu.imdg
13 | web-session-clustering
14 | war
15 | 1.0.0
16 | web-session-clustering
17 |
18 |
19 | 4.1.0.RELEASE
20 | 1.6.0
21 | UTF-8
22 |
23 |
24 |
25 |
26 | org.springframework
27 | spring-webmvc
28 | ${springframework.version}
29 |
30 |
31 | javax.servlet
32 | javax.servlet-api
33 | 3.1.0
34 |
35 |
36 | javax.servlet.jsp
37 | javax.servlet.jsp-api
38 | 2.3.1
39 |
40 |
41 | javax.servlet
42 | jstl
43 | 1.2
44 |
45 |
46 |
47 | org.apache.ignite
48 | ignite-core
49 |
50 |
51 | org.apache.ignite
52 | ignite-web
53 | ${ignite.version}
54 |
55 |
56 | org.apache.ignite
57 | ignite-log4j
58 |
59 |
60 | org.apache.ignite
61 | ignite-spring
62 |
63 |
64 |
65 | WebSessionClustering
66 |
67 |
68 | org.eclipse.jetty
69 | jetty-maven-plugin
70 | 9.2.11.v20150529
71 |
72 | 10
73 |
74 | /test-session
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/web-session-clustering/src/main/java/com/blu/imdg/wsession/bean/Person.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.wsession.bean;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by shamim on 07/07/16.
7 | */
8 | public class Person implements Serializable{
9 | private String firstName;
10 | private int age;
11 |
12 | public Person(String firstName) {
13 | this.firstName = firstName;
14 | }
15 |
16 | public Person() {
17 | }
18 |
19 | public String getFirstName() {
20 | return firstName;
21 | }
22 |
23 | public void setFirstName(String firstName) {
24 | this.firstName = firstName;
25 | }
26 |
27 | public int getAge() {
28 | return age;
29 | }
30 |
31 | public void setAge(int age) {
32 | this.age = age;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/web-session-clustering/src/main/java/com/blu/imdg/wsession/controller/WebSessionController.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.wsession.controller;
2 |
3 | import com.blu.imdg.wsession.bean.Person;
4 | import org.springframework.context.annotation.Scope;
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.ui.ModelMap;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestMethod;
9 | import org.springframework.web.bind.annotation.SessionAttributes;
10 |
11 | import javax.servlet.http.HttpServletRequest;
12 |
13 | @Controller
14 | @RequestMapping("/")
15 | public class WebSessionController {
16 |
17 | @RequestMapping(value="/putperson", method = RequestMethod.GET)
18 | public String putSession(ModelMap model, HttpServletRequest request) {
19 | model.addAttribute("person", "Add Person to user session");
20 | String fName = request.getParameter("name");
21 | int age = Integer.valueOf(request.getParameter("age"));
22 | Person person = new Person();
23 | person.setFirstName(fName);
24 | person.setAge(age);
25 | // set user session data
26 | request.getSession().setAttribute(fName, person);
27 | // return to the welcome.jsp view
28 | return "welcome";
29 | }
30 |
31 | @RequestMapping(value="/getperson", method = RequestMethod.GET)
32 | public String getSession(ModelMap model, HttpServletRequest request) {
33 | String fName = request.getParameter("name");
34 | // get session data
35 | model.addAttribute("person", request.getSession().getAttribute(fName) != null ? "Age: " + ((Person) request.getSession().getAttribute(fName)).getAge() : " Unknown");
36 | // view welcome.jsp
37 | return "welcome";
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/web-session-clustering/src/main/webapp/WEB-INF/spring-servlet.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | /WEB-INF/views/
19 |
20 |
21 | .jsp
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/web-session-clustering/src/main/webapp/WEB-INF/views/welcome.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2 | pageEncoding="ISO-8859-1"%>
3 |
4 |
5 |
6 |
7 | Web session clustering example
8 |
9 |
10 | Data : ${person}
11 |
12 |
--------------------------------------------------------------------------------
/chapters/chapter-caching/web-session-clustering/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 | Ignite web session clustering example
8 |
9 | org.apache.ignite.startup.servlet.ServletContextListenerStartup
10 |
11 |
12 |
13 | dispatcher
14 |
15 | org.springframework.web.servlet.DispatcherServlet
16 |
17 |
18 | contextConfigLocation
19 |
20 | /WEB-INF/spring-servlet.xml
21 |
22 | 1
23 |
24 |
25 |
26 | dispatcher
27 | /
28 |
29 |
30 |
31 |
32 | IgniteWebSessionsFilter
33 | org.apache.ignite.cache.websession.WebSessionFilter
34 |
35 |
36 | IgniteWebSessionsFilter
37 | /*
38 |
39 |
40 |
41 | IgniteConfigurationFilePath
42 | spring-ignite-cache.xml
43 |
44 |
45 |
46 | IgniteWebSessionsCacheName
47 | session-cache
48 |
49 |
50 | IgniteWebSessionsGridName
51 | session-grid
52 |
53 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/java/com/blu/imdg/ExampleNodeStartup.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.blu.imdg;
19 |
20 | import org.apache.ignite.IgniteException;
21 | import org.apache.ignite.Ignition;
22 |
23 | /**
24 | * Starts up an empty node with example compute configuration.
25 | */
26 | public class ExampleNodeStartup {
27 | /**
28 | * Start up an empty node with example compute configuration.
29 | *
30 | * @param args Command line arguments, none required.
31 | * @throws IgniteException If failed.
32 | */
33 | public static void main(String[] args) throws IgniteException {
34 | // use same ignite configuration
35 | Ignition.start("example-ignite.xml");
36 | }
37 | }
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/java/com/blu/imdg/dto/Alert.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.dto;
2 |
3 | import org.apache.ignite.cache.query.annotations.QuerySqlField;
4 |
5 | /**
6 | * Created by shamim on 05/08/16.
7 | */
8 | public class Alert {
9 | @QuerySqlField(index = true)
10 | private String serviceName;
11 | @QuerySqlField(index = true)
12 | private Level alertLevel;
13 |
14 | public Alert(String serviceName, Level alertLevel) {
15 | this.serviceName = serviceName;
16 | this.alertLevel = alertLevel;
17 | }
18 |
19 | public Level getAlertLevel() {
20 | return alertLevel;
21 | }
22 |
23 | public void setAlertLevel(Level alertLevel) {
24 | this.alertLevel = alertLevel;
25 | }
26 |
27 | @Override
28 | public String toString() {
29 | return "Alert{" +
30 | "serviceName='" + serviceName + '\'' +
31 | ", alertLevel='" + alertLevel + '\'' +
32 | '}';
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/java/com/blu/imdg/dto/Level.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.dto;
2 |
3 | /**
4 | * Created by shamim on 05/08/16.
5 | */
6 | public enum Level {
7 | GREEN,
8 | YELLOW,
9 | RED
10 | }
11 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/java/com/blu/imdg/dto/MnpRouting.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.dto;
2 |
3 | import org.apache.ignite.cache.query.annotations.QuerySqlField;
4 |
5 | /**
6 | * User: bsha
7 | * Date: 07.08.2016
8 | * Time: 15:29
9 | */
10 | public class MnpRouting {
11 | @QuerySqlField(index = true)
12 | private String telephone;
13 | @QuerySqlField(index = true)
14 | private long credit;
15 | @QuerySqlField(index = true)
16 | private String routeTo;
17 |
18 | public String getTelephone() {
19 | return telephone;
20 | }
21 |
22 | public void setTelephone(String telephone) {
23 | this.telephone = telephone;
24 | }
25 |
26 | public long getCredit() {
27 | return credit;
28 | }
29 |
30 | public void setCredit(long credit) {
31 | this.credit = credit;
32 | }
33 |
34 | public String getRouteTo() {
35 | return routeTo;
36 | }
37 |
38 | public void setRouteTo(String routeTo) {
39 | this.routeTo = routeTo;
40 | }
41 |
42 | @Override
43 | public String toString() {
44 | return "Routing {" +
45 | "telephone='" + telephone + '\'' +
46 | ", credit=" + credit +
47 | ", routeTo='" + routeTo + '\'' +
48 | '}';
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/java/com/blu/imdg/dto/ServiceStatus.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.dto;
2 |
3 | import org.apache.ignite.cache.query.annotations.QuerySqlField;
4 |
5 | import java.io.Serializable;
6 |
7 | /**
8 | * Created by shamim on 04/08/16.
9 | */
10 | public class ServiceStatus implements Serializable{
11 | @QuerySqlField(index = true)
12 | private String serviceName;
13 | @QuerySqlField(index = true)
14 | private int statusCode;
15 | @QuerySqlField(index = true)
16 | private long responseTime;
17 | @QuerySqlField(index = true)
18 | private long unavailableCnt;
19 | @QuerySqlField(index = true)
20 | private long healthCheckCnt;
21 |
22 | public ServiceStatus(String name, int statusCode){
23 | this.serviceName = name;
24 | this.statusCode =statusCode;
25 | }
26 |
27 | public String getServiceName() {
28 | return serviceName;
29 | }
30 |
31 | public void setServiceName(String serviceName) {
32 | this.serviceName = serviceName;
33 | }
34 |
35 | public int getStatusCode() {
36 | return statusCode;
37 | }
38 |
39 | public void setStatusCode(int statusCode) {
40 | this.statusCode = statusCode;
41 | }
42 |
43 | public long getResponseTime() {
44 | return responseTime;
45 | }
46 |
47 | public void setResponseTime(long responseTime) {
48 | this.responseTime = responseTime;
49 | }
50 |
51 | public long getUnavailableCnt() {
52 | return unavailableCnt;
53 | }
54 |
55 | public void setUnavailableCnt(long unavailableCnt) {
56 | this.unavailableCnt = unavailableCnt;
57 | }
58 |
59 | public long getHealthCheckCnt() {
60 | return healthCheckCnt;
61 | }
62 |
63 | public void setHealthCheckCnt(long healthCheckCnt) {
64 | this.healthCheckCnt = healthCheckCnt;
65 | }
66 |
67 |
68 | @Override
69 | public String toString() {
70 | return "ServiceStatus{" +
71 | "serviceName='" + serviceName + '\'' +
72 | ", statusCode=" + statusCode +
73 | ", responseTime=" + responseTime +
74 | ", unavailableCnt=" + unavailableCnt +
75 | ", healthCheckCnt=" + healthCheckCnt +
76 | '}';
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/java/com/blu/imdg/processor/RouteProcessor.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.processor;
2 |
3 | import com.blu.imdg.dto.MnpRouting;
4 | import org.apache.camel.Exchange;
5 | import org.apache.camel.Processor;
6 |
7 | /**
8 | * User: bsha
9 | * Date: 07.08.2016
10 | * Time: 19:31
11 | */
12 | public class RouteProcessor implements Processor {
13 | private static final long CREDIT_LIMIT = 100l;
14 | @Override
15 | public void process(Exchange exchange) throws Exception {
16 | System.out.println("Process the bean MnpRouting!");
17 | MnpRouting mnpRouting = (MnpRouting) exchange.getIn().getBody();
18 | if(mnpRouting != null){
19 | // validate phone numbers of format "1234567890"
20 | if (!mnpRouting.getTelephone().matches("\\d{11}") || mnpRouting.getCredit() < CREDIT_LIMIT){
21 | exchange.getOut().setBody("Message doesn't pass validation");
22 | exchange.getOut().setHeader("key", mnpRouting.getTelephone());
23 | } else{
24 | exchange.getOut().setBody(mnpRouting.toString());
25 | exchange.getOut().setHeader("key", mnpRouting.getTelephone());
26 |
27 | }
28 |
29 | }
30 | //System.out.println(mnpRouting);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/java/com/blu/imdg/query/AlertMonitoring.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.query;
2 |
3 | import com.blu.imdg.ExamplesUtils;
4 | import com.blu.imdg.dto.Alert;
5 | import org.apache.ignite.Ignite;
6 | import org.apache.ignite.IgniteCache;
7 | import org.apache.ignite.Ignition;
8 | import org.apache.ignite.cache.query.SqlFieldsQuery;
9 | import org.apache.ignite.configuration.CacheConfiguration;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by shamim on 05/08/16.
15 | */
16 | public class AlertMonitoring {
17 |
18 | private static final String QUERY_RED = "select alertLevel, count(alertLevel) from Alert group by alertLevel";
19 | public static void main(String[] args) throws Exception {
20 | // Mark this cluster member as client.
21 | Ignition.setClientMode(true);
22 |
23 | try (Ignite ignite = Ignition.start("example-ignite.xml")) {
24 | if (!ExamplesUtils.hasServerNodes(ignite))
25 | return;
26 |
27 | CacheConfiguration alert_Cfg = new CacheConfiguration<>("alerts");
28 | IgniteCache instCache = ignite.getOrCreateCache(alert_Cfg);
29 |
30 | SqlFieldsQuery top3qry = new SqlFieldsQuery(QUERY_RED);
31 | while(true){
32 | // Execute queries.
33 | List> top3 = instCache.query(top3qry).getAll();
34 |
35 | System.out.println("Service Health Monitoring");
36 |
37 | ExamplesUtils.printQueryResults(top3);
38 |
39 | Thread.sleep(1000);
40 | }
41 |
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/java/com/blu/imdg/query/QueryStatus.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.query;
2 |
3 | import com.blu.imdg.ExamplesUtils;
4 | import com.blu.imdg.dto.ServiceStatus;
5 | import org.apache.ignite.Ignite;
6 | import org.apache.ignite.IgniteCache;
7 | import org.apache.ignite.Ignition;
8 | import org.apache.ignite.cache.query.SqlFieldsQuery;
9 | import org.apache.ignite.configuration.CacheConfiguration;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by shamim on 04/08/16.
15 | */
16 | public class QueryStatus {
17 | private static final String QUERY_404="SELECT serviceName, statusCode from ServiceStatus where statusCode = 404";
18 | private static final String QUERY_CNT= "select count(*) from ServiceStatus where statusCode = 404";
19 | public static void main(String[] args) throws Exception {
20 | // Mark this cluster member as client.
21 | Ignition.setClientMode(true);
22 |
23 | try (Ignite ignite = Ignition.start("example-ignite.xml")) {
24 | if (!ExamplesUtils.hasServerNodes(ignite))
25 | return;
26 | // query code goes here.
27 | CacheConfiguration healthchecksCfg = new CacheConfiguration<>("healthchecks");
28 | IgniteCache instCache = ignite.getOrCreateCache(healthchecksCfg);
29 | SqlFieldsQuery query = new SqlFieldsQuery(QUERY_404);
30 |
31 | while(true){
32 | // Execute queries.
33 | List> res = instCache.query(query).getAll();
34 |
35 | System.out.println("Service Health check status");
36 |
37 | ExamplesUtils.printQueryResults(res);
38 |
39 | Thread.sleep(1000);
40 | }
41 |
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/java/com/blu/imdg/streamer/HealthCheckStreamer.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.streamer;
2 |
3 | import com.blu.imdg.ExamplesUtils;
4 | import com.blu.imdg.dto.ServiceStatus;
5 | import org.apache.ignite.Ignite;
6 | import org.apache.ignite.IgniteCache;
7 | import org.apache.ignite.IgniteDataStreamer;
8 | import org.apache.ignite.Ignition;
9 | import org.apache.ignite.configuration.CacheConfiguration;
10 |
11 | import javax.cache.configuration.FactoryBuilder;
12 | import javax.cache.expiry.CreatedExpiryPolicy;
13 | import javax.cache.expiry.Duration;
14 | import java.util.Date;
15 | import java.util.Random;
16 |
17 | import static java.util.concurrent.TimeUnit.SECONDS;
18 |
19 | /**
20 | * Created by shamim on 04/08/16.
21 | */
22 | public class HealthCheckStreamer {
23 | private static final Random RAND = new Random();
24 | private static final String[] SERVICE_NAME = new String[] {"GETINN", "GETWEATHER", "GETEXCHANGERATE", "CONVERTCURRENCY", "GETPUBLICSERVICELIST", "SEARCHBRANCHES", "GETNEWSBYTOPICS"};
25 | private static final int[] STATUS_CODE = new int[] {200, 404, 504};
26 |
27 | public static void main(String[] args) throws Exception{
28 | System.out.println("Streamer for service health check!!");
29 | // Mark this cluster member as client.
30 | Ignition.setClientMode(true);
31 | try(Ignite ignite = Ignition.start("example-ignite.xml")){
32 | if(!ExamplesUtils.hasServerNodes(ignite))
33 | return;
34 | // healthcheck cache configuration
35 | CacheConfiguration healthcheck_cfg = new CacheConfiguration<>("healthchecks");
36 | // set window to 5 second
37 | // Note: data will evicts after 5 seconds
38 | //healthcheck_cfg.setExpiryPolicyFactory(FactoryBuilder.factoryOf(new CreatedExpiryPolicy(new Duration(SECONDS, 15))));
39 | // set index
40 | healthcheck_cfg.setIndexedTypes(String.class, ServiceStatus.class);
41 |
42 | IgniteCache healthCheckCache = ignite.getOrCreateCache(healthcheck_cfg);
43 |
44 | try(IgniteDataStreamer healthCheckStreamer = ignite.dataStreamer(healthCheckCache.getName())){
45 | healthCheckStreamer.allowOverwrite(true);
46 |
47 | while(true ){
48 | int idx_service_name = RAND.nextInt(SERVICE_NAME.length);
49 | int idx_code = RAND.nextInt(STATUS_CODE.length);
50 | ServiceStatus serviceStatus = new ServiceStatus(SERVICE_NAME[idx_service_name], STATUS_CODE[idx_code]);
51 |
52 | healthCheckStreamer.addData(SERVICE_NAME[idx_service_name], serviceStatus);
53 | }
54 |
55 | }
56 |
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/resources/camel.properties:
--------------------------------------------------------------------------------
1 | input.file.location=f:\\workshop\\assembla\\ignite-book\\chapters\\chapter-cep\\input?delete=true
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/resources/default-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
25 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/resources/example-ignite.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
23 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/camel/src/main/resources/input.json:
--------------------------------------------------------------------------------
1 | {"telephone" : "89096860917", "credit" : "129", "routeTo" : "MTS"}
--------------------------------------------------------------------------------
/chapters/chapter-cep/flume/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.blu.imdg
8 | chapters
9 | 1.0-SNAPSHOT
10 | ../../parent
11 |
12 | com.blu.imdg
13 | flume
14 | 1.0-SNAPSHOT
15 | flume
16 | http://maven.apache.org
17 |
18 | UTF-8
19 |
20 |
21 |
22 | org.apache.ignite
23 | ignite-core
24 |
25 |
26 | org.apache.ignite
27 | ignite-spring
28 |
29 |
30 | org.apache.ignite
31 | ignite-log4j
32 |
33 |
34 |
35 | org.apache.ignite
36 | ignite-flume
37 |
38 |
39 |
40 |
41 |
42 | org.apache.maven.plugins
43 | maven-compiler-plugin
44 |
45 | 1.7
46 | 1.7
47 |
48 |
49 |
50 | com.jolira
51 | onejar-maven-plugin
52 | 1.4.4
53 |
54 |
55 | run-avro-clinet
56 |
57 | com.blu.imdg.flume.rpc.RunClient
58 | true
59 | onejar
60 | flume-avro-client.jar
61 |
62 |
63 | one-jar
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/flume/src/main/java/com/blu/imdg/flume/Transformer/FlumeEventTransformer.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.flume.Transformer;
2 |
3 | import org.apache.flume.Event;
4 | import org.apache.ignite.stream.flume.EventTransformer;
5 | import org.jetbrains.annotations.Nullable;
6 |
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | /**
12 | * User: bsha
13 | * Date: 10.08.2016
14 | * Time: 23:24
15 | */
16 | public class FlumeEventTransformer implements EventTransformer {
17 | @Nullable
18 | @Override
19 | public Map transform(List list) {
20 | final Map map = new HashMap<>(list.size());
21 | for(Event event : list){
22 | map.putAll(transform(event));
23 | }
24 | return map;
25 | }
26 | /**
27 | * Format event - String:String
28 | * example - transactionId:amount [56102:232], where transactionId is the key and amount is the value
29 | * */
30 | private Map transform(Event event){
31 | final Map map = new HashMap<>();
32 | String eventBody = new String(event.getBody());
33 | if(!eventBody.isEmpty()){
34 | // parse the string by :
35 | String[] tokens = eventBody.split(":");
36 | map.put(tokens[0].trim(), Integer.valueOf(tokens[1].trim()));
37 | }
38 |
39 | return map;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/flume/src/main/java/com/blu/imdg/flume/config/agent.sh:
--------------------------------------------------------------------------------
1 | ./flume-ng agent --conf conf --conf-file /home/user/apache-flume-1.6.0-bin/conf/single-node-demo.properties --name a1 -Dflume.root.logger=INFO,console
2 | #Hadoop and hive in classpath
3 | # add asm-all-4.2 lib
4 | #netcat
5 | nc host port
6 |
7 | #for ignite example
8 | ./flume-ng agent --conf conf --conf-file /home/user/apache-flume-1.6.0-bin/conf/single-node-demo.properties --name a1
--------------------------------------------------------------------------------
/chapters/chapter-cep/flume/src/main/java/com/blu/imdg/flume/config/demo.properties:
--------------------------------------------------------------------------------
1 | # Name the components on this agent
2 | a1.sources = r1
3 | a1.sinks = k1
4 | a1.channels = c1
5 |
6 | # Describe/configure the source
7 | #a1.sources.r1.type = netcat
8 | a1.sources.r1.type = avro
9 | a1.sources.r1.bind = localhost
10 | a1.sources.r1.port = 44444
11 |
12 | # Describe the sink, Sink logger is not need for ignite
13 | #a1.sinks.k1.type = logger
14 |
15 | # Use a channel which buffers events in memory
16 | a1.channels.c1.type = memory
17 | a1.channels.c1.capacity = 1000
18 | a1.channels.c1.transactionCapacity = 100
19 |
20 | # Bind the source and sink to the channel
21 | a1.sources.r1.channels = c1
22 | a1.sinks.k1.channel = c1
23 |
24 | # ignite sink
25 | a1.sinks.k1.type = org.apache.ignite.stream.flume.IgniteSink
26 | a1.sinks.k1.igniteCfg = /home/user/apache-flume-1.6.0-bin/conf/example-ignite.xml
27 | a1.sinks.k1.cacheName = testCache
28 | a1.sinks.k1.eventTransformer = com.blu.imdg.flume.Transformer.FlumeEventTransformer
29 | a1.sinks.k1.batchSize = 100
--------------------------------------------------------------------------------
/chapters/chapter-cep/flume/src/main/java/com/blu/imdg/flume/rpc/RpcEventGenerator.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.flume.rpc;
2 |
3 | import org.apache.flume.Event;
4 | import org.apache.flume.EventDeliveryException;
5 | import org.apache.flume.api.RpcClient;
6 | import org.apache.flume.api.RpcClientFactory;
7 | import org.apache.flume.event.EventBuilder;
8 |
9 | /**
10 | * Created by shamim on 11/08/16.
11 | */
12 | public class RpcEventGenerator {
13 | private org.apache.flume.api.RpcClient rpcClient;
14 | private String hostName;
15 | private int port;
16 |
17 | public RpcEventGenerator(String hostName, int port) {
18 | this.hostName = hostName;
19 | this.port = port;
20 | this.rpcClient = RpcClientFactory.getDefaultInstance(hostName, port);
21 | }
22 |
23 | public void sendData(String data){
24 | Event event = EventBuilder.withBody(data.getBytes());
25 |
26 | try {
27 | rpcClient.append(event);
28 | } catch (EventDeliveryException e) {
29 | e.printStackTrace();
30 | rpcClient.close();
31 | rpcClient = RpcClientFactory.getDefaultInstance(this.hostName, this.port);
32 | }
33 |
34 | }
35 | public void cleanUp(){
36 | if(rpcClient.isActive()){
37 | rpcClient.close();
38 | }
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/flume/src/main/java/com/blu/imdg/flume/rpc/RunClient.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.flume.rpc;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.util.Properties;
6 |
7 | /**
8 | * Created by shamim on 11/08/16.
9 | */
10 | public class RunClient {
11 | private static final String HOST_NAME="flume.agent.host";
12 | private static final String PORT="flume.agent.port";
13 |
14 | public static void main(String[] args) {
15 | System.out.println("RPC client to send data");
16 | // read properties from file
17 | if(getProperties() == null || getProperties().isEmpty()){
18 | System.out.println("Property file is not found or empty");
19 | return;
20 | }
21 |
22 | RpcEventGenerator eventGenerator = new RpcEventGenerator(getProperties().getProperty(HOST_NAME), Integer.valueOf(getProperties().getProperty(PORT)));
23 | // generate some sequence of transactions
24 |
25 | for(int i = 1; i < 100 ; i++){
26 | eventGenerator.sendData("transaction"+i+":"+i);
27 | }
28 | eventGenerator.cleanUp();
29 | }
30 | private static Properties getProperties(){
31 | Properties properties = new Properties();
32 | InputStream ins = RunClient.class.getClassLoader().getResourceAsStream("generator.properties");
33 |
34 | try {
35 | properties.load(ins);
36 | } catch (IOException e) {
37 | e.printStackTrace();
38 | properties = null;
39 | }
40 | return properties;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/flume/src/main/resources/generator.properties:
--------------------------------------------------------------------------------
1 | flume.agent.host=192.168.15.150
2 | flume.agent.port=44444
--------------------------------------------------------------------------------
/chapters/chapter-cep/storm/README.md:
--------------------------------------------------------------------------------
1 | to run the topology, execute
2 |
3 | mvn compile exec:java -Dstorm.topology=com.blu.imdg.storm.topology.SpeedViolationTopology
--------------------------------------------------------------------------------
/chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/bolts/SpeedLimitBolt.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.storm.bolts;
2 |
3 | import backtype.storm.topology.BasicOutputCollector;
4 | import backtype.storm.topology.OutputFieldsDeclarer;
5 | import backtype.storm.topology.base.BaseBasicBolt;
6 | import backtype.storm.tuple.Fields;
7 | import backtype.storm.tuple.Tuple;
8 | import backtype.storm.tuple.Values;
9 | import clojure.lang.IFn;
10 | import org.apache.logging.log4j.LogManager;
11 | import org.apache.logging.log4j.Logger;
12 |
13 | import java.util.TreeMap;
14 |
15 | /**
16 | * Created by shamim on 28/08/16.
17 | */
18 | public class SpeedLimitBolt extends BaseBasicBolt {
19 | // Static field for ignite
20 | private static final String IGNITE_FIELD = "ignite";
21 | private static final int SPEED_THRESHOLD = 120;
22 | //Create logger for this class
23 | private static final Logger LOGGER = LogManager.getLogger(SpeedLimitBolt.class);
24 | @Override
25 | public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
26 | String line = (String)tuple.getValue(0);
27 | if(!line.isEmpty()){
28 | String[] elements = line.split(",");
29 | // we are interested in speed and the car registration number
30 | int speed = Integer.valueOf((elements[1]).trim());
31 | String car = elements[0];
32 | if(speed > SPEED_THRESHOLD){
33 | TreeMap carValue = new TreeMap();
34 | carValue.put(car, speed);
35 | basicOutputCollector.emit(new Values(carValue));
36 | LOGGER.info("Speed violation found:"+ car + " speed:" + speed);
37 | }
38 | }
39 | }
40 |
41 | @Override
42 | public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
43 | outputFieldsDeclarer.declare(new Fields(IGNITE_FIELD));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/bolts/SplitSentence.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.storm.bolts;
2 |
3 | import backtype.storm.topology.BasicOutputCollector;
4 | import backtype.storm.topology.OutputFieldsDeclarer;
5 | import backtype.storm.topology.base.BaseBasicBolt;
6 | import backtype.storm.tuple.Fields;
7 | import backtype.storm.tuple.Tuple;
8 | import backtype.storm.tuple.Values;
9 |
10 | import java.text.BreakIterator;
11 |
12 | /**
13 | * Created by shamim on 24/08/16.
14 | */
15 | public class SplitSentence extends BaseBasicBolt {
16 | //Execute is called to process tuples
17 | @Override
18 | public void execute(Tuple tuple, BasicOutputCollector collector) {
19 | //Get the sentence content from the tuple
20 | String sentence = tuple.getString(0);
21 | //An iterator to get each word
22 | BreakIterator boundary=BreakIterator.getWordInstance();
23 | //Give the iterator the sentence
24 | boundary.setText(sentence);
25 | //Find the beginning first word
26 | int start=boundary.first();
27 | //Iterate over each word and emit it to the output stream
28 | for (int end = boundary.next(); end != BreakIterator.DONE; start=end, end=boundary.next()) {
29 | //get the word
30 | String word=sentence.substring(start,end);
31 | //If a word is whitespace characters, replace it with empty
32 | word=word.replaceAll("\\s+","");
33 | //if it's an actual word, emit it
34 | if (!word.equals("")) {
35 | collector.emit(new Values(word));
36 | }
37 | }
38 | }
39 |
40 | //Declare that emitted tuples will contain a word field
41 | @Override
42 | public void declareOutputFields(OutputFieldsDeclarer declarer) {
43 | declarer.declare(new Fields("word"));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/bolts/WordCount.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.storm.bolts;
2 |
3 | import backtype.storm.topology.BasicOutputCollector;
4 | import backtype.storm.topology.OutputFieldsDeclarer;
5 | import backtype.storm.topology.base.BaseBasicBolt;
6 | import backtype.storm.tuple.Fields;
7 | import backtype.storm.tuple.Tuple;
8 | import backtype.storm.tuple.Values;
9 | import org.apache.logging.log4j.LogManager;
10 | import org.apache.logging.log4j.Logger;
11 |
12 | import java.util.HashMap;
13 | import java.util.Map;
14 | import java.util.TreeMap;
15 |
16 | /**
17 | * Created by shamim on 24/08/16.
18 | */
19 | public class WordCount extends BaseBasicBolt {
20 | // Static field for ignite
21 | private static final String IGNITE_FIELD = "ignite";
22 | //Create logger for this class
23 | private static final Logger logger = LogManager.getLogger(WordCount.class);
24 |
25 | //For holding words and counts
26 | Map counts = new HashMap();
27 |
28 | //execute is called to process tuples
29 | @Override
30 | public void execute(Tuple tuple, BasicOutputCollector collector) {
31 | //Get the word contents from the tuple
32 | String word = tuple.getString(0);
33 | //Have we counted any already?
34 | Integer count = counts.get(word);
35 | if (count == null)
36 | count = 0;
37 | //Increment the count and store it
38 | count++;
39 | counts.put(word, count);
40 | //Emit the word and the current count
41 | //collector.emit(new Values(IGNITE_FIELD, count));
42 | TreeMap words = new TreeMap<>();
43 | words.put(word,count);
44 |
45 | collector.emit(new Values(words));
46 | //Log information
47 | logger.info("Emitting a count of " + count + " for word " + word);
48 | }
49 |
50 | //Declare that we will emit a tuple containing two fields; word and count
51 | @Override
52 | public void declareOutputFields(OutputFieldsDeclarer declarer) {
53 | declarer.declare(new Fields(IGNITE_FIELD));
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/spouts/FileSourceSpout.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.storm.spouts;
2 |
3 | import backtype.storm.spout.SpoutOutputCollector;
4 | import backtype.storm.task.TopologyContext;
5 | import backtype.storm.topology.OutputFieldsDeclarer;
6 | import backtype.storm.topology.base.BaseRichSpout;
7 | import backtype.storm.tuple.Fields;
8 |
9 | import backtype.storm.tuple.Values;
10 | import org.apache.logging.log4j.LogManager;
11 | import org.apache.logging.log4j.Logger;
12 |
13 |
14 | import java.io.*;
15 | import java.net.URISyntaxException;
16 | import java.nio.file.Files;
17 | import java.nio.file.Path;
18 | import java.nio.file.Paths;
19 | import java.util.Map;
20 | import java.util.stream.Stream;
21 |
22 |
23 | /**
24 | * Created by shamim on 28/08/16.
25 | */
26 | public class FileSourceSpout extends BaseRichSpout {
27 | private static final Logger LOGGER = LogManager.getLogger(FileSourceSpout.class);
28 | private SpoutOutputCollector outputCollector;
29 | @Override
30 | public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
31 | this.outputCollector = spoutOutputCollector;
32 | }
33 |
34 | /**
35 | * Read file from classpath to generate source.
36 | * */
37 | @Override
38 | public void nextTuple() {
39 |
40 | try {
41 | Path filePath = Paths.get(this.getClass().getClassLoader().getResource("source.csv").toURI());
42 | try(Stream lines = Files.lines(filePath)){
43 | lines.forEach(line ->{
44 | outputCollector.emit(new Values(line));
45 | });
46 |
47 | } catch(IOException e){
48 | LOGGER.error(e.getMessage());
49 | }
50 |
51 | } catch (URISyntaxException e) {
52 | LOGGER.error(e.getMessage());
53 | }
54 |
55 | }
56 |
57 | @Override
58 | public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
59 | outputFieldsDeclarer.declare(new Fields("trafficLog"));
60 |
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/spouts/RandomSentenceSpout.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.storm.spouts;
2 |
3 | import backtype.storm.spout.SpoutOutputCollector;
4 | import backtype.storm.task.TopologyContext;
5 | import backtype.storm.topology.OutputFieldsDeclarer;
6 | import backtype.storm.topology.base.BaseRichSpout;
7 | import backtype.storm.tuple.Fields;
8 | import backtype.storm.tuple.Values;
9 | import backtype.storm.utils.Utils;
10 |
11 | import java.util.Map;
12 | import java.util.Random;
13 |
14 | /**
15 | * Created by shamim on 24/08/16.
16 | */
17 | public class RandomSentenceSpout extends BaseRichSpout {
18 |
19 | //Collector used to emit output
20 | SpoutOutputCollector _collector;
21 | //Used to generate a random number
22 | Random _rand;
23 |
24 | //Open is called when an instance of the class is created
25 | @Override
26 | public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
27 | //Set the instance collector to the one passed in
28 | _collector = collector;
29 | //For randomness
30 | _rand = new Random();
31 | }
32 |
33 | //Emit data to the stream
34 | @Override
35 | public void nextTuple() {
36 | //Sleep for a bit
37 | Utils.sleep(100);
38 | //The sentences that will be randomly emitted
39 | String[] sentences = new String[]{"the cow jumped over the moon", "an apple a day keeps the doctor away",
40 | "four score and seven years ago", "snow white and the seven dwarfs", "i am at two with nature"};
41 | //Randomly pick a sentence
42 | String sentence = sentences[_rand.nextInt(sentences.length)];
43 | //Emit the sentence
44 | _collector.emit(new Values(sentence));
45 | }
46 |
47 | //Ack is not implemented since this is a basic example
48 | @Override
49 | public void ack(Object id) {
50 | }
51 |
52 | //Fail is not implemented since this is a basic example
53 | @Override
54 | public void fail(Object id) {
55 | }
56 |
57 | //Declare the output fields. In this case, an sentence
58 | @Override
59 | public void declareOutputFields(OutputFieldsDeclarer declarer) {
60 | declarer.declare(new Fields("sentence"));
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/storm/src/main/java/com/blu/imdg/storm/topology/SpeedViolationTopology.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.storm.topology;
2 |
3 | import backtype.storm.Config;
4 | import backtype.storm.LocalCluster;
5 | import backtype.storm.StormSubmitter;
6 | import backtype.storm.topology.TopologyBuilder;
7 | import backtype.storm.tuple.Fields;
8 | import com.blu.imdg.storm.bolts.SpeedLimitBolt;
9 | import com.blu.imdg.storm.bolts.SplitSentence;
10 | import com.blu.imdg.storm.bolts.WordCount;
11 | import com.blu.imdg.storm.spouts.FileSourceSpout;
12 | import com.blu.imdg.storm.spouts.RandomSentenceSpout;
13 | import org.apache.ignite.stream.storm.StormStreamer;
14 |
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 | import java.util.Properties;
18 |
19 | /**
20 | * Created by shamim on 28/08/16.
21 | */
22 | public class SpeedViolationTopology {
23 |
24 | private static final int STORM_EXECUTORS = 2;
25 |
26 | public static void main(String[] args) throws Exception {
27 | if (getProperties() == null || getProperties().isEmpty()) {
28 | System.out.println("Property file is not found or empty");
29 | return;
30 | }
31 | // Ignite Stream Ibolt
32 | final StormStreamer stormStreamer = new StormStreamer<>();
33 |
34 | stormStreamer.setAutoFlushFrequency(10L);
35 | stormStreamer.setAllowOverwrite(true);
36 | stormStreamer.setCacheName(getProperties().getProperty("cache.name"));
37 |
38 | stormStreamer.setIgniteTupleField(getProperties().getProperty("tuple.name"));
39 | stormStreamer.setIgniteConfigFile(getProperties().getProperty("ignite.spring.xml"));
40 |
41 |
42 | TopologyBuilder builder = new TopologyBuilder();
43 |
44 | builder.setSpout("spout", new FileSourceSpout(), 1);
45 | builder.setBolt("limit", new SpeedLimitBolt(), 1).fieldsGrouping("spout", new Fields("trafficLog"));
46 | // set ignite bolt
47 | builder.setBolt("ignite-bolt", stormStreamer, STORM_EXECUTORS).shuffleGrouping("limit");
48 |
49 | Config conf = new Config();
50 | conf.setDebug(false);
51 |
52 | conf.setMaxTaskParallelism(1);
53 | LocalCluster cluster = new LocalCluster();
54 | cluster.submitTopology("speed-violation", conf, builder.createTopology());
55 | Thread.sleep(10000);
56 | cluster.shutdown();
57 |
58 | }
59 |
60 | private static Properties getProperties() {
61 | Properties properties = new Properties();
62 | InputStream ins = SpeedViolationTopology.class.getClassLoader().getResourceAsStream("ignite-storm.properties");
63 |
64 | try {
65 | properties.load(ins);
66 | } catch (IOException e) {
67 | e.printStackTrace();
68 | properties = null;
69 | }
70 | return properties;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/chapters/chapter-cep/storm/src/main/resources/ignite-storm.properties:
--------------------------------------------------------------------------------
1 | cache.name=testCache
2 | tuple.name=ignite
3 | ignite.spring.xml=example-ignite.xml
--------------------------------------------------------------------------------
/chapters/chapter-cep/storm/src/main/resources/source.csv:
--------------------------------------------------------------------------------
1 | AB 123, 160, North city
2 | BC 123, 170, South city
3 | CD 234, 40, South city
4 | DE 123, 40, East city
5 | EF 123, 190, South city
6 | GH 123, 150, West city
7 | XY 123, 110, North city
8 | GF 123, 100, South city
9 | PO 234, 140, South city
10 | XX 123, 110, East city
11 | YY 123, 120, South city
12 | ZQ 123, 100, West city
--------------------------------------------------------------------------------
/chapters/chapter-dist-computing/src/main/java/com/blu/imdg/StartCacheNode.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg;
2 |
3 | import org.apache.ignite.Ignite;
4 | import org.apache.ignite.Ignition;
5 |
6 | import java.io.IOException;
7 |
8 | /**
9 | * Created by mikl on 19.08.16.
10 | */
11 | //mvn exec:java -Dexec.mainClass=com.blu.imdg.StartCacheNode
12 | public class StartCacheNode {
13 | public static void main(String[] args) {
14 | try (Ignite ignite = Ignition.start("org/book/examples/cache-node-config.xml")) {
15 | System.out.println("Presse ENTER to exit!");
16 | System.in.read();
17 | } catch (IOException e) {
18 | e.printStackTrace();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/CommonConstants.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.common;
2 |
3 | /**
4 | * Created by mikl on 23.08.16.
5 | */
6 | public class CommonConstants {
7 | public static final String CLIENT_CONFIG = "org/book/examples/simple-client-config.xml";
8 | }
9 |
--------------------------------------------------------------------------------
/chapters/chapter-dist-computing/src/main/java/com/blu/imdg/common/HttpAuditClient.java:
--------------------------------------------------------------------------------
1 | package com.blu.imdg.common;
2 |
3 | import org.apache.http.client.HttpClient;
4 | import org.apache.http.client.methods.CloseableHttpResponse;
5 | import org.apache.http.client.methods.HttpGet;
6 | import org.apache.http.client.utils.URIBuilder;
7 | import org.apache.http.impl.client.HttpClients;
8 | import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
9 |
10 | import java.io.IOException;
11 | import java.net.URI;
12 | import java.net.URISyntaxException;
13 | import java.util.concurrent.ConcurrentMap;
14 | import java.util.function.Function;
15 |
16 | /**
17 | * Created by mikl on 23.08.16.
18 | */
19 | public class HttpAuditClient {
20 |
21 | public static Boolean sendResult(HttpClient client, Boolean result, String messageId) throws URISyntaxException, IOException {
22 | URI uri = new URIBuilder().setScheme("http").setHost("localhost").setPort(9998).setPath("/audit/log")
23 | .setParameter("msgId", messageId)
24 | .setParameter("validationResult", result.toString())
25 | .build();
26 | HttpGet httpget = new HttpGet(uri);
27 | try (CloseableHttpResponse resp = (CloseableHttpResponse) client.execute(httpget)) {
28 | System.out.println("msg=" + messageId + " result=" + result);
29 | return result;
30 | }
31 | }
32 |
33 | public static HttpClient createHttpClient(ConcurrentMap