SlideShare a Scribd company logo
Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India)
Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api
1
Apache Spark™ is a fast and general engine for large-scale data processing, and Couchbase is
in-memory no-sql database. So by connecting these two we can get a lightening fast speed.
In this blog we are focusing on how to make CRUD operations on couchbase
with Spark’s speed.
I am assuming that you have a basic Spark’s installation and couchbase installation on your
system.
So for using Couchbase API’s with RDD’s we need to make a build.sbt file and add this line to
it.
"com.couchbase.client" %% "spark-connector" % "1.1.0"
So basically your build.sbt should look like.
name := "spark-spray-couchbase-example1"
version := "1.0"
scalaVersion := "2.10.4"
organization := "com.MoonLightIT"
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % "1.4.1",
"io.spray" %% "spray-can" % "1.3.3",
"io.spray" %% "spray-routing" % "1.3.3",
"org.apache.spark" %% "spark-sql" % "1.4.1",
"io.spray" %% "spray-testkit" % "1.3.3",
"org.specs2" %% "specs2" % "2.4.7",
"com.couchbase.client" %% "spark-connector" % "1.1.0"
)
assembleArtifact in packageScala := false // We don't need the Scala library,
Spark already includes it
Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India)
Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api
2
mergeStrategy in assembly := {
case m if m.toLowerCase.endsWith("manifest.mf") => MergeStrategy.discard
case m if m.toLowerCase.matches("meta-inf.*.sf$") => MergeStrategy.discard
case "reference.conf" => MergeStrategy.concat
case _ => MergeStrategy.first
}
fork in run := true
Now you can access the Couchbase’s API’s for RDD’s in your code.
So now the next part is making building a service and binding it to the port.
package com.MoonLightIT.sprayservices
import akka.actor.{ActorSystem, Props}
import akka.io.IO
import spray.can.Http
import scala.concurrent.duration.DurationInt
object StartSpark extends App {
// we need an ActorSystem to host our application in
implicit val actorSystem = ActorSystem("spark-services")
implicit val timeout = 30 seconds
// create and start our service actor
val service = actorSystem.actorOf(Props[SparkServices], "spark-services")
// start a new HTTP server on port 8080 with our service actor as the handler
IO(Http) ! Http.Bind(service, "0.0.0.0", port = 8080)
}
Here we are just using the spray server for building the REST Api and binding it to
the 8080 port.
Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India)
Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api
3
Now comes the main part of implementing the couchbase CRUD operation using Spark and
spray. So for performing this we need to set the spark conf so that it may know where to insert
the data.
val sparkConf: SparkConf = new SparkConf().setAppName("couchbase-
spark-spray-starter-kit").setMaster("local")
.set("com.couchbase.nodes",
"127.0.0.1").set("com.couchbase.bucket.userBucket", "")
val sc: SparkContext = new SparkContext(sparkConf)
Here we are giving the node 127.0.0.1 and the bucket name here is userBucket. Using this
configuration we are making the Spark Context(sc).
Now we are going to implement the CRUD operations using the Couchbase’s API for RDD’s.
</pre>
<pre>package com.MoonLightIT.sprayservices
import java.util.UUID
import akka.actor.{Actor, ActorContext}
import com.couchbase.client.java.document.JsonDocument
import com.couchbase.client.java.document.json.JsonObject
import com.couchbase.client.java.query.N1qlQuery
import com.couchbase.client.java.view.ViewQuery
import com.couchbase.spark._
import org.apache.spark.{SparkConf, SparkContext}
import spray.http.StatusCodes._
import spray.http._
import spray.routing.Directive.pimpApply
import spray.routing.HttpService
import scala.util.Try
Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India)
Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api
4
trait SparkService extends HttpService {
val sparkConf: SparkConf = new SparkConf().setAppName("spark-spray-
starter").setMaster("local")
.set("com.couchbase.nodes",
"127.0.0.1").set("com.couchbase.bucket.userBucket", "")
val sc: SparkContext = new SparkContext(sparkConf)
val sparkRoutes =
path("insert" / "name" / Segment / "email" / Segment) { (name: String,
email: String) =>
get {
complete {
val documentId = "user::" + UUID.randomUUID().toString
val jsonObject = JsonObject.create().put("name", name).put("email",
email)
val jsonDocument = JsonDocument.create(documentId, jsonObject)
val savedData = sc.parallelize(Seq(jsonDocument))
val issaved =
Try(savedData.saveToCouchbase()).toOption.fold(false)(x => true)
issaved match {
case true => HttpResponse(OK, s"Data is successfully persisted
with id $documentId")
case false => HttpResponse(InternalServerError, s"Data is not
persisted and something went wrong")
}
}
}
} ~
path("updateViaKV" / "name" / Segment / "email" / Segment / "id" /
Segment) { (name: String, email: String, id: String) =>
get {
complete {
val documentId = id
val jsonObject = JsonObject.create().put("name",
name).put("email", email)
val jsonDocument = JsonDocument.create(documentId, jsonObject)
val savedData = sc.parallelize(Seq(jsonDocument))
val issaved =
Try(savedData.saveToCouchbase()).toOption.fold(false)(x => true)
issaved match {
Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India)
Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api
5
case true => HttpResponse(OK, s"Data is successfully persisted
with id $documentId")
case false => HttpResponse(InternalServerError, s"Data is not
persisted and something went wrong")
}
}
}
} ~
path("getViaKV" / "id" / Segment) { (id: String) =>
get {
complete {
val idAsRDD = sc.parallelize(Seq(id))
val fetchedDocument =
Try(idAsRDD.couchbaseGet[JsonDocument]().map(_.content.toString).collect).toO
ption
fetchedDocument match {
case Some(data) => HttpResponse(OK, data(0))
case None => HttpResponse(InternalServerError, s"Data is not
fetched and something went wrong")
}
}
}
} ~
Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India)
Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api
6
path("getViaView" / "name" / Segment) { (name: String) =>
get {
complete {
val viewRDDData = Try(sc.couchbaseView(ViewQuery.from("userDdoc",
"emailtoName").startKey(name)).collect()).toOption
val emailFetched = viewRDDData.map(_.map(a => a.value.toString))
emailFetched match {
case Some(data) => HttpResponse(OK, data(0))
case None => HttpResponse(InternalServerError, s"Data is not
fetched and something went wrong")
}
}
}
} ~
path("getViaN1Ql" / "name" / Segment) { (name: String) =>
get {
complete {
val n1qlRDD = Try(sc.couchbaseQuery(N1qlQuery.simple(s"SELECT *
FROM `userBucket` WHERE name LIKE '$name%'")).collect()).toOption
val emailFetched = n1qlRDD.map(_.map(a => a.value.toString))
emailFetched match {
case Some(data) => HttpResponse(OK, data(0))
case None => HttpResponse(InternalServerError, s"Data is not
fetched and something went wrong")
}
}
}
}
}
Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India)
Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api
7
class SparkServices extends Actor with SparkService {
def actorRefFactory: ActorContext = context
def receive: Actor.Receive = runRoute(sparkRoutes)
}</pre>
<pre>
The methods saveToCouchbase(), couchbaseGet(), couchbaseView(),couchbaseQuery() are
provided by couchbase so that we can perform the functionality on RDD’s .
This is a basic implementation of how to perform CRUD operation on couchbase using the
Spark.
We can also use the power of N1QL in this too by using the SQLContext, and they are said to be
highly compatible too.

More Related Content

What's hot

AWS Infrastructure as Code - September 2016 Webinar Series
AWS Infrastructure as Code - September 2016 Webinar SeriesAWS Infrastructure as Code - September 2016 Webinar Series
AWS Infrastructure as Code - September 2016 Webinar Series
Amazon Web Services
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0
Oscar Renalias
 
Using OpenStack With Fog
Using OpenStack With FogUsing OpenStack With Fog
Using OpenStack With Fog
Mike Hagedorn
 
Play + scala + reactive mongo
Play + scala + reactive mongoPlay + scala + reactive mongo
Play + scala + reactive mongo
Max Kremer
 
06 integrate elasticsearch
06 integrate elasticsearch06 integrate elasticsearch
06 integrate elasticsearch
Erhwen Kuo
 
Meetup bangalore 9_novupdated
Meetup bangalore 9_novupdatedMeetup bangalore 9_novupdated
Meetup bangalore 9_novupdated
D.Rajesh Kumar
 
(APP306) Using AWS CloudFormation for Deployment and Management at Scale | AW...
(APP306) Using AWS CloudFormation for Deployment and Management at Scale | AW...(APP306) Using AWS CloudFormation for Deployment and Management at Scale | AW...
(APP306) Using AWS CloudFormation for Deployment and Management at Scale | AW...
Amazon Web Services
 
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018
Chris Gillum
 
Drupal 8 + Elasticsearch + Docker
Drupal 8 + Elasticsearch + DockerDrupal 8 + Elasticsearch + Docker
Drupal 8 + Elasticsearch + Docker
Roald Umandal
 
05 integrate redis
05 integrate redis05 integrate redis
05 integrate redis
Erhwen Kuo
 
04 integrate entityframework
04 integrate entityframework04 integrate entityframework
04 integrate entityframework
Erhwen Kuo
 
Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)
Paco de la Cruz
 
10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websites10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websites
oazabir
 
SPSTC - PowerShell - Through the SharePoint Looking Glass
SPSTC - PowerShell - Through the SharePoint Looking GlassSPSTC - PowerShell - Through the SharePoint Looking Glass
SPSTC - PowerShell - Through the SharePoint Looking Glass
Brian Caauwe
 
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
Amazon Web Services
 
03 integrate webapisignalr
03 integrate webapisignalr03 integrate webapisignalr
03 integrate webapisignalr
Erhwen Kuo
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)
Yevgeniy Brikman
 
(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI
Amazon Web Services
 
Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC Applications
Sarvesh Kushwaha
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
Knoldus Inc.
 

What's hot (20)

AWS Infrastructure as Code - September 2016 Webinar Series
AWS Infrastructure as Code - September 2016 Webinar SeriesAWS Infrastructure as Code - September 2016 Webinar Series
AWS Infrastructure as Code - September 2016 Webinar Series
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0
 
Using OpenStack With Fog
Using OpenStack With FogUsing OpenStack With Fog
Using OpenStack With Fog
 
Play + scala + reactive mongo
Play + scala + reactive mongoPlay + scala + reactive mongo
Play + scala + reactive mongo
 
06 integrate elasticsearch
06 integrate elasticsearch06 integrate elasticsearch
06 integrate elasticsearch
 
Meetup bangalore 9_novupdated
Meetup bangalore 9_novupdatedMeetup bangalore 9_novupdated
Meetup bangalore 9_novupdated
 
(APP306) Using AWS CloudFormation for Deployment and Management at Scale | AW...
(APP306) Using AWS CloudFormation for Deployment and Management at Scale | AW...(APP306) Using AWS CloudFormation for Deployment and Management at Scale | AW...
(APP306) Using AWS CloudFormation for Deployment and Management at Scale | AW...
 
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018
Advanced Durable Functions - Serverless Meetup Tokyo - Feb 2018
 
Drupal 8 + Elasticsearch + Docker
Drupal 8 + Elasticsearch + DockerDrupal 8 + Elasticsearch + Docker
Drupal 8 + Elasticsearch + Docker
 
05 integrate redis
05 integrate redis05 integrate redis
05 integrate redis
 
04 integrate entityframework
04 integrate entityframework04 integrate entityframework
04 integrate entityframework
 
Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)
 
10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websites10 performance and scalability secrets of ASP.NET websites
10 performance and scalability secrets of ASP.NET websites
 
SPSTC - PowerShell - Through the SharePoint Looking Glass
SPSTC - PowerShell - Through the SharePoint Looking GlassSPSTC - PowerShell - Through the SharePoint Looking Glass
SPSTC - PowerShell - Through the SharePoint Looking Glass
 
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
AWS re:Invent 2016: The Effective AWS CLI User (DEV402)
 
03 integrate webapisignalr
03 integrate webapisignalr03 integrate webapisignalr
03 integrate webapisignalr
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)
 
(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI
 
Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC Applications
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
 

Similar to Apache spark with akka couchbase code by bhawani

Into The Box | Alexa and ColdBox Api's
Into The Box | Alexa and ColdBox Api'sInto The Box | Alexa and ColdBox Api's
Into The Box | Alexa and ColdBox Api's
Ortus Solutions, Corp
 
A Blueprint for Scala Microservices
A Blueprint for Scala MicroservicesA Blueprint for Scala Microservices
A Blueprint for Scala Microservices
Federico Feroldi
 
Federico Feroldi - Scala microservices
Federico Feroldi - Scala microservicesFederico Feroldi - Scala microservices
Federico Feroldi - Scala microservices
Scala Italy
 
Express node js
Express node jsExpress node js
Express node js
Yashprit Singh
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
Jeetendra singh
 
Quick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase ServerQuick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase Server
Nic Raboy
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
Ramnivas Laddad
 
Lambda Architecture Using SQL
Lambda Architecture Using SQLLambda Architecture Using SQL
Lambda Architecture Using SQL
SATOSHI TAGOMORI
 
2014 09 30_sparkling_water_hands_on
2014 09 30_sparkling_water_hands_on2014 09 30_sparkling_water_hands_on
2014 09 30_sparkling_water_hands_on
Sri Ambati
 
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-AirflowPyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
Chetan Khatri
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Fwdays
 
Just one-shade-of-openstack
Just one-shade-of-openstackJust one-shade-of-openstack
Just one-shade-of-openstack
Roberto Polli
 
Spark
SparkSpark
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
Mindfire Solutions
 
Richard Cole of Amazon Gives Lightning Tallk at BigDataCamp
Richard Cole of Amazon Gives Lightning Tallk at BigDataCampRichard Cole of Amazon Gives Lightning Tallk at BigDataCamp
Richard Cole of Amazon Gives Lightning Tallk at BigDataCamp
BigDataCamp
 
Share point hosted add ins munich
Share point hosted add ins munichShare point hosted add ins munich
Share point hosted add ins munich
Sonja Madsen
 
Let's play with adf 3.0
Let's play with adf 3.0Let's play with adf 3.0
Let's play with adf 3.0
Eugenio Romano
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP Developers
Jeremy Lindblom
 
Sqoop on Spark for Data Ingestion
Sqoop on Spark for Data IngestionSqoop on Spark for Data Ingestion
Sqoop on Spark for Data Ingestion
DataWorks Summit
 
Migrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
Migrate your Existing Express Apps to AWS Lambda and Amazon API GatewayMigrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
Migrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
Amazon Web Services
 

Similar to Apache spark with akka couchbase code by bhawani (20)

Into The Box | Alexa and ColdBox Api's
Into The Box | Alexa and ColdBox Api'sInto The Box | Alexa and ColdBox Api's
Into The Box | Alexa and ColdBox Api's
 
A Blueprint for Scala Microservices
A Blueprint for Scala MicroservicesA Blueprint for Scala Microservices
A Blueprint for Scala Microservices
 
Federico Feroldi - Scala microservices
Federico Feroldi - Scala microservicesFederico Feroldi - Scala microservices
Federico Feroldi - Scala microservices
 
Express node js
Express node jsExpress node js
Express node js
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
Quick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase ServerQuick and Easy Development with Node.js and Couchbase Server
Quick and Easy Development with Node.js and Couchbase Server
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
 
Lambda Architecture Using SQL
Lambda Architecture Using SQLLambda Architecture Using SQL
Lambda Architecture Using SQL
 
2014 09 30_sparkling_water_hands_on
2014 09 30_sparkling_water_hands_on2014 09 30_sparkling_water_hands_on
2014 09 30_sparkling_water_hands_on
 
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-AirflowPyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
 
Just one-shade-of-openstack
Just one-shade-of-openstackJust one-shade-of-openstack
Just one-shade-of-openstack
 
Spark
SparkSpark
Spark
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
 
Richard Cole of Amazon Gives Lightning Tallk at BigDataCamp
Richard Cole of Amazon Gives Lightning Tallk at BigDataCampRichard Cole of Amazon Gives Lightning Tallk at BigDataCamp
Richard Cole of Amazon Gives Lightning Tallk at BigDataCamp
 
Share point hosted add ins munich
Share point hosted add ins munichShare point hosted add ins munich
Share point hosted add ins munich
 
Let's play with adf 3.0
Let's play with adf 3.0Let's play with adf 3.0
Let's play with adf 3.0
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP Developers
 
Sqoop on Spark for Data Ingestion
Sqoop on Spark for Data IngestionSqoop on Spark for Data Ingestion
Sqoop on Spark for Data Ingestion
 
Migrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
Migrate your Existing Express Apps to AWS Lambda and Amazon API GatewayMigrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
Migrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
 

More from Bhawani N Prasad

Understanding Robotic process automation by bhawani nandan prasad
Understanding Robotic process automation by bhawani nandan prasadUnderstanding Robotic process automation by bhawani nandan prasad
Understanding Robotic process automation by bhawani nandan prasad
Bhawani N Prasad
 
Agile overview class for scrum masters
Agile overview class for scrum mastersAgile overview class for scrum masters
Agile overview class for scrum masters
Bhawani N Prasad
 
Product Management
Product ManagementProduct Management
Product Management
Bhawani N Prasad
 
Product Engineering
Product EngineeringProduct Engineering
Product Engineering
Bhawani N Prasad
 
Machine learning computer science by bhawani n prasad
Machine learning computer science by bhawani n prasadMachine learning computer science by bhawani n prasad
Machine learning computer science by bhawani n prasad
Bhawani N Prasad
 
PM conpetency skills
PM conpetency skillsPM conpetency skills
PM conpetency skills
Bhawani N Prasad
 
What we can do in Retail analytics by bhawani nandanprasad
What we can do in Retail analytics by bhawani nandanprasadWhat we can do in Retail analytics by bhawani nandanprasad
What we can do in Retail analytics by bhawani nandanprasad
Bhawani N Prasad
 
Big data analytics bhawani nandan prasad
Big data analytics   bhawani nandan prasadBig data analytics   bhawani nandan prasad
Big data analytics bhawani nandan prasad
Bhawani N Prasad
 
Program management-steps
Program management-stepsProgram management-steps
Program management-steps
Bhawani N Prasad
 
Define enterprise integration strategy by industry leader bhawani nandanprasad
Define enterprise integration strategy by industry leader bhawani nandanprasadDefine enterprise integration strategy by industry leader bhawani nandanprasad
Define enterprise integration strategy by industry leader bhawani nandanprasad
Bhawani N Prasad
 
New IBM Information Server 11.3 - Bhawani Nandan Prasad
New IBM Information Server  11.3 - Bhawani Nandan PrasadNew IBM Information Server  11.3 - Bhawani Nandan Prasad
New IBM Information Server 11.3 - Bhawani Nandan Prasad
Bhawani N Prasad
 
Economic growth inequality across globe by bhawani nandan prasad
Economic growth inequality across globe  by bhawani nandan prasadEconomic growth inequality across globe  by bhawani nandan prasad
Economic growth inequality across globe by bhawani nandan prasad
Bhawani N Prasad
 
Agile lifecycle handbook by bhawani nandan prasad
Agile lifecycle handbook by bhawani nandan prasadAgile lifecycle handbook by bhawani nandan prasad
Agile lifecycle handbook by bhawani nandan prasad
Bhawani N Prasad
 
Agile project management tips and techniques
Agile project management tips and techniquesAgile project management tips and techniques
Agile project management tips and techniques
Bhawani N Prasad
 
Cognos 10 upgrade migrate fixpack by bhawani nandan prasad
Cognos 10 upgrade migrate fixpack by bhawani nandan prasadCognos 10 upgrade migrate fixpack by bhawani nandan prasad
Cognos 10 upgrade migrate fixpack by bhawani nandan prasad
Bhawani N Prasad
 
Software development with scrum methodology bhawani nandan prasad
Software development with scrum methodology   bhawani nandan prasadSoftware development with scrum methodology   bhawani nandan prasad
Software development with scrum methodology bhawani nandan prasad
Bhawani N Prasad
 
Agile formanagers by-bhawaninandanprasad
Agile formanagers by-bhawaninandanprasadAgile formanagers by-bhawaninandanprasad
Agile formanagers by-bhawaninandanprasad
Bhawani N Prasad
 
Dsdm by bhawani nandanprasad
Dsdm by bhawani nandanprasadDsdm by bhawani nandanprasad
Dsdm by bhawani nandanprasad
Bhawani N Prasad
 
Cmmi vs-agile
Cmmi vs-agileCmmi vs-agile
Cmmi vs-agile
Bhawani N Prasad
 
Pdu session challenges in agile
Pdu session   challenges in agilePdu session   challenges in agile
Pdu session challenges in agile
Bhawani N Prasad
 

More from Bhawani N Prasad (20)

Understanding Robotic process automation by bhawani nandan prasad
Understanding Robotic process automation by bhawani nandan prasadUnderstanding Robotic process automation by bhawani nandan prasad
Understanding Robotic process automation by bhawani nandan prasad
 
Agile overview class for scrum masters
Agile overview class for scrum mastersAgile overview class for scrum masters
Agile overview class for scrum masters
 
Product Management
Product ManagementProduct Management
Product Management
 
Product Engineering
Product EngineeringProduct Engineering
Product Engineering
 
Machine learning computer science by bhawani n prasad
Machine learning computer science by bhawani n prasadMachine learning computer science by bhawani n prasad
Machine learning computer science by bhawani n prasad
 
PM conpetency skills
PM conpetency skillsPM conpetency skills
PM conpetency skills
 
What we can do in Retail analytics by bhawani nandanprasad
What we can do in Retail analytics by bhawani nandanprasadWhat we can do in Retail analytics by bhawani nandanprasad
What we can do in Retail analytics by bhawani nandanprasad
 
Big data analytics bhawani nandan prasad
Big data analytics   bhawani nandan prasadBig data analytics   bhawani nandan prasad
Big data analytics bhawani nandan prasad
 
Program management-steps
Program management-stepsProgram management-steps
Program management-steps
 
Define enterprise integration strategy by industry leader bhawani nandanprasad
Define enterprise integration strategy by industry leader bhawani nandanprasadDefine enterprise integration strategy by industry leader bhawani nandanprasad
Define enterprise integration strategy by industry leader bhawani nandanprasad
 
New IBM Information Server 11.3 - Bhawani Nandan Prasad
New IBM Information Server  11.3 - Bhawani Nandan PrasadNew IBM Information Server  11.3 - Bhawani Nandan Prasad
New IBM Information Server 11.3 - Bhawani Nandan Prasad
 
Economic growth inequality across globe by bhawani nandan prasad
Economic growth inequality across globe  by bhawani nandan prasadEconomic growth inequality across globe  by bhawani nandan prasad
Economic growth inequality across globe by bhawani nandan prasad
 
Agile lifecycle handbook by bhawani nandan prasad
Agile lifecycle handbook by bhawani nandan prasadAgile lifecycle handbook by bhawani nandan prasad
Agile lifecycle handbook by bhawani nandan prasad
 
Agile project management tips and techniques
Agile project management tips and techniquesAgile project management tips and techniques
Agile project management tips and techniques
 
Cognos 10 upgrade migrate fixpack by bhawani nandan prasad
Cognos 10 upgrade migrate fixpack by bhawani nandan prasadCognos 10 upgrade migrate fixpack by bhawani nandan prasad
Cognos 10 upgrade migrate fixpack by bhawani nandan prasad
 
Software development with scrum methodology bhawani nandan prasad
Software development with scrum methodology   bhawani nandan prasadSoftware development with scrum methodology   bhawani nandan prasad
Software development with scrum methodology bhawani nandan prasad
 
Agile formanagers by-bhawaninandanprasad
Agile formanagers by-bhawaninandanprasadAgile formanagers by-bhawaninandanprasad
Agile formanagers by-bhawaninandanprasad
 
Dsdm by bhawani nandanprasad
Dsdm by bhawani nandanprasadDsdm by bhawani nandanprasad
Dsdm by bhawani nandanprasad
 
Cmmi vs-agile
Cmmi vs-agileCmmi vs-agile
Cmmi vs-agile
 
Pdu session challenges in agile
Pdu session   challenges in agilePdu session   challenges in agile
Pdu session challenges in agile
 

Recently uploaded

Best Programming Language for Civil Engineers
Best Programming Language for Civil EngineersBest Programming Language for Civil Engineers
Best Programming Language for Civil Engineers
Awais Yaseen
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
Enterprise Wired
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
Larry Smarr
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
huseindihon
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
Andrey Yasko
 
Mitigating the Impact of State Management in Cloud Stream Processing Systems
Mitigating the Impact of State Management in Cloud Stream Processing SystemsMitigating the Impact of State Management in Cloud Stream Processing Systems
Mitigating the Impact of State Management in Cloud Stream Processing Systems
ScyllaDB
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
shanthidl1
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
KAMAL CHOUDHARY
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
Advanced Techniques for Cyber Security Analysis and Anomaly Detection
Advanced Techniques for Cyber Security Analysis and Anomaly DetectionAdvanced Techniques for Cyber Security Analysis and Anomaly Detection
Advanced Techniques for Cyber Security Analysis and Anomaly Detection
Bert Blevins
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
Tatiana Al-Chueyr
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
Aurora Consulting
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
Matthew Sinclair
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
HackersList
 
UiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs ConferenceUiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs Conference
UiPathCommunity
 
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyyActive Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
RaminGhanbari2
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
Emerging Tech
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Chris Swan
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
Lidia A.
 

Recently uploaded (20)

Best Programming Language for Civil Engineers
Best Programming Language for Civil EngineersBest Programming Language for Civil Engineers
Best Programming Language for Civil Engineers
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
 
Comparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdfComparison Table of DiskWarrior Alternatives.pdf
Comparison Table of DiskWarrior Alternatives.pdf
 
Mitigating the Impact of State Management in Cloud Stream Processing Systems
Mitigating the Impact of State Management in Cloud Stream Processing SystemsMitigating the Impact of State Management in Cloud Stream Processing Systems
Mitigating the Impact of State Management in Cloud Stream Processing Systems
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
 
Recent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS InfrastructureRecent Advancements in the NIST-JARVIS Infrastructure
Recent Advancements in the NIST-JARVIS Infrastructure
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
Advanced Techniques for Cyber Security Analysis and Anomaly Detection
Advanced Techniques for Cyber Security Analysis and Anomaly DetectionAdvanced Techniques for Cyber Security Analysis and Anomaly Detection
Advanced Techniques for Cyber Security Analysis and Anomaly Detection
 
Best Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdfBest Practices for Effectively Running dbt in Airflow.pdf
Best Practices for Effectively Running dbt in Airflow.pdf
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
 
20240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 202420240705 QFM024 Irresponsible AI Reading List June 2024
20240705 QFM024 Irresponsible AI Reading List June 2024
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
 
UiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs ConferenceUiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs Conference
 
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyyActive Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
Active Inference is a veryyyyyyyyyyyyyyyyyyyyyyyy
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
 
WPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide DeckWPRiders Company Presentation Slide Deck
WPRiders Company Presentation Slide Deck
 

Apache spark with akka couchbase code by bhawani

  • 1. Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India) Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api 1 Apache Spark™ is a fast and general engine for large-scale data processing, and Couchbase is in-memory no-sql database. So by connecting these two we can get a lightening fast speed. In this blog we are focusing on how to make CRUD operations on couchbase with Spark’s speed. I am assuming that you have a basic Spark’s installation and couchbase installation on your system. So for using Couchbase API’s with RDD’s we need to make a build.sbt file and add this line to it. "com.couchbase.client" %% "spark-connector" % "1.1.0" So basically your build.sbt should look like. name := "spark-spray-couchbase-example1" version := "1.0" scalaVersion := "2.10.4" organization := "com.MoonLightIT" libraryDependencies ++= Seq( "org.apache.spark" %% "spark-core" % "1.4.1", "io.spray" %% "spray-can" % "1.3.3", "io.spray" %% "spray-routing" % "1.3.3", "org.apache.spark" %% "spark-sql" % "1.4.1", "io.spray" %% "spray-testkit" % "1.3.3", "org.specs2" %% "specs2" % "2.4.7", "com.couchbase.client" %% "spark-connector" % "1.1.0" ) assembleArtifact in packageScala := false // We don't need the Scala library, Spark already includes it
  • 2. Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India) Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api 2 mergeStrategy in assembly := { case m if m.toLowerCase.endsWith("manifest.mf") => MergeStrategy.discard case m if m.toLowerCase.matches("meta-inf.*.sf$") => MergeStrategy.discard case "reference.conf" => MergeStrategy.concat case _ => MergeStrategy.first } fork in run := true Now you can access the Couchbase’s API’s for RDD’s in your code. So now the next part is making building a service and binding it to the port. package com.MoonLightIT.sprayservices import akka.actor.{ActorSystem, Props} import akka.io.IO import spray.can.Http import scala.concurrent.duration.DurationInt object StartSpark extends App { // we need an ActorSystem to host our application in implicit val actorSystem = ActorSystem("spark-services") implicit val timeout = 30 seconds // create and start our service actor val service = actorSystem.actorOf(Props[SparkServices], "spark-services") // start a new HTTP server on port 8080 with our service actor as the handler IO(Http) ! Http.Bind(service, "0.0.0.0", port = 8080) } Here we are just using the spray server for building the REST Api and binding it to the 8080 port.
  • 3. Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India) Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api 3 Now comes the main part of implementing the couchbase CRUD operation using Spark and spray. So for performing this we need to set the spark conf so that it may know where to insert the data. val sparkConf: SparkConf = new SparkConf().setAppName("couchbase- spark-spray-starter-kit").setMaster("local") .set("com.couchbase.nodes", "127.0.0.1").set("com.couchbase.bucket.userBucket", "") val sc: SparkContext = new SparkContext(sparkConf) Here we are giving the node 127.0.0.1 and the bucket name here is userBucket. Using this configuration we are making the Spark Context(sc). Now we are going to implement the CRUD operations using the Couchbase’s API for RDD’s. </pre> <pre>package com.MoonLightIT.sprayservices import java.util.UUID import akka.actor.{Actor, ActorContext} import com.couchbase.client.java.document.JsonDocument import com.couchbase.client.java.document.json.JsonObject import com.couchbase.client.java.query.N1qlQuery import com.couchbase.client.java.view.ViewQuery import com.couchbase.spark._ import org.apache.spark.{SparkConf, SparkContext} import spray.http.StatusCodes._ import spray.http._ import spray.routing.Directive.pimpApply import spray.routing.HttpService import scala.util.Try
  • 4. Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India) Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api 4 trait SparkService extends HttpService { val sparkConf: SparkConf = new SparkConf().setAppName("spark-spray- starter").setMaster("local") .set("com.couchbase.nodes", "127.0.0.1").set("com.couchbase.bucket.userBucket", "") val sc: SparkContext = new SparkContext(sparkConf) val sparkRoutes = path("insert" / "name" / Segment / "email" / Segment) { (name: String, email: String) => get { complete { val documentId = "user::" + UUID.randomUUID().toString val jsonObject = JsonObject.create().put("name", name).put("email", email) val jsonDocument = JsonDocument.create(documentId, jsonObject) val savedData = sc.parallelize(Seq(jsonDocument)) val issaved = Try(savedData.saveToCouchbase()).toOption.fold(false)(x => true) issaved match { case true => HttpResponse(OK, s"Data is successfully persisted with id $documentId") case false => HttpResponse(InternalServerError, s"Data is not persisted and something went wrong") } } } } ~ path("updateViaKV" / "name" / Segment / "email" / Segment / "id" / Segment) { (name: String, email: String, id: String) => get { complete { val documentId = id val jsonObject = JsonObject.create().put("name", name).put("email", email) val jsonDocument = JsonDocument.create(documentId, jsonObject) val savedData = sc.parallelize(Seq(jsonDocument)) val issaved = Try(savedData.saveToCouchbase()).toOption.fold(false)(x => true) issaved match {
  • 5. Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India) Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api 5 case true => HttpResponse(OK, s"Data is successfully persisted with id $documentId") case false => HttpResponse(InternalServerError, s"Data is not persisted and something went wrong") } } } } ~ path("getViaKV" / "id" / Segment) { (id: String) => get { complete { val idAsRDD = sc.parallelize(Seq(id)) val fetchedDocument = Try(idAsRDD.couchbaseGet[JsonDocument]().map(_.content.toString).collect).toO ption fetchedDocument match { case Some(data) => HttpResponse(OK, data(0)) case None => HttpResponse(InternalServerError, s"Data is not fetched and something went wrong") } } } } ~
  • 6. Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India) Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api 6 path("getViaView" / "name" / Segment) { (name: String) => get { complete { val viewRDDData = Try(sc.couchbaseView(ViewQuery.from("userDdoc", "emailtoName").startKey(name)).collect()).toOption val emailFetched = viewRDDData.map(_.map(a => a.value.toString)) emailFetched match { case Some(data) => HttpResponse(OK, data(0)) case None => HttpResponse(InternalServerError, s"Data is not fetched and something went wrong") } } } } ~ path("getViaN1Ql" / "name" / Segment) { (name: String) => get { complete { val n1qlRDD = Try(sc.couchbaseQuery(N1qlQuery.simple(s"SELECT * FROM `userBucket` WHERE name LIKE '$name%'")).collect()).toOption val emailFetched = n1qlRDD.map(_.map(a => a.value.toString)) emailFetched match { case Some(data) => HttpResponse(OK, data(0)) case None => HttpResponse(InternalServerError, s"Data is not fetched and something went wrong") } } } } }
  • 7. Bhawani Nandan Prasad – Bhawani_nandan@yahoo.com 0091 – 9717570222 (India) Hadoop Technology Stack SME - Using Spark , Spray and Couchbase for lightening fast REST Api 7 class SparkServices extends Actor with SparkService { def actorRefFactory: ActorContext = context def receive: Actor.Receive = runRoute(sparkRoutes) }</pre> <pre> The methods saveToCouchbase(), couchbaseGet(), couchbaseView(),couchbaseQuery() are provided by couchbase so that we can perform the functionality on RDD’s . This is a basic implementation of how to perform CRUD operation on couchbase using the Spark. We can also use the power of N1QL in this too by using the SQLContext, and they are said to be highly compatible too.