Skip to main content

Posts

mongoDB

MongoDB A cross-platform open-source document-oriented NoSQL database with an Enterprise level distribution that includes additional security and management features. MongoDB is supported and steered by the company MongoDB . What do we mean by NoSQL? The NoSQL database category loosely incorporates all databases which do not have a rigid schema and are not queryable via a structured query language. They are normally designed specifically to scale easily to support very large datasets. What is a document based database? Instead of storing information as a table with a series of records or rows, MongoDB stores data as searchable documents. A document is analogous to the object model in object orientated programming languages. How does MongoDB represent documents? MongoDB uses JSON to represent its documents. JSON is a simple key-value pair textual serialization of an object, for example, a bunch of grapes could be represented as the following JSON string: { Name: "Bunch of...

Spark Tutorial and Cheatsheet

Main resources: Scala Cheat Sheet Reactive Cheat Sheet Spark Cheat sheet Spark Quick start Spark programming guide Spark Streaming : processing real-time data streams Spark SQL and DataFrames : support for structured data and relational queries MLlib : built-in machine learning library GraphX : Spark’s new API for graph processing Scala programming examples: Define a object with main function -- Helloworld. object HelloWorld { def main(args: Array[String]) { println("Hello, world!") } } Execute main function: scala> HelloWorld.main(null) Hello, world! Creating RDDs Parallelized Collections: val data = Array(1, 2, 3, 4, 5) val distData = sc.parallelize(data) External Datasets: val distFile = sc.textFile("data.txt") Above command returns the content of the file: scala> distFile.collect() res16: Array[String] = Array(1,2,3, 4,5,6) SparkContext.wholeTextFiles can return (filename, content). val distFile = sc.wholeTextFiles("/tmp/t...

Making Spray based ReST API publicly / remotely accessible

Recently I developed a demo Spray based ReST API and ran it on Windows. While I was able to access it locally using http://localhost:port/service link, but remotely I was not. I made following two changes to fix the issue: 1. In your application's application.conf file make hostname as 0.0.0.0 - 127.0.0.1 or localhost is foe listening only on the loopback interface. - 0.0.0.0 for listening on all available network interfaces. This works in Java 7 and 8 fine. In Java 6, only IPv4 address works. My application.conf looks like: akka { loglevel = DEBUG event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] } spray.can.server { request-timeout = 10s } service { host = 0.0.0.0 port = 8090 } 2. Open 8090 (or whatever you want to use) port in Windows Firewall: http://windows.microsoft.com/en-gb/windows/open-port-windows-firewall#1TC=windows-7

SecurityException with Bouncy Castle

I am using BouncyCastle library to encrypt the data transfer with Kakfa. While my program run fine from IntelliJ, but when I package a fat JAR and run, it throws following exception: java.lang.SecurityException: JCE cannot authenticate the provider BC at javax.crypto.Cipher.getInstance(Cipher.java:657) at javax.crypto.Cipher.getInstance(Cipher.java:596) at com.xyz.abc.fusioncell.utils.CryptoService$class.decrypt(CryptoService.scala:63) at com.xyz.abc.fusioncell.Boot$.decrypt(Boot.scala:13) at com.xyz.abc.fusioncell.conf.Config$$anonfun$userId$1.apply(Config.scala:28) at com.xyz.abc.fusioncell.conf.Config$$anonfun$userId$1.apply(Config.scala:28) at scala.util.Try$.apply(Try.scala:192) at com.xyz.abc.fusioncell.conf.Config$class.userId(Config.scala:28) at com.xyz.abc.fusioncell.Boot$.userId$lzycompute(Boot.scala:13) at com.xyz.abc.fusioncell.Boot$.userId(Boot.scala:13) at com.xyz.abc.fusioncell.Boot$.main(Boot.scala:24) at com.xyz.abc.fu...

Akka: Printing list of actors

To print the list of actors that are running in the actor system, you can add following scheduler that will print actor path every 10 seconds: import akka.actor.{Actor, ActorIdentity, ActorLogging, ActorRef, Cancellable, Props} class TestActor extends Actor with ActorLogging { private var scheduler: Cancellable = _ @scala.throws[Exception](classOf[Exception]) override def preStart(): Unit = { import scala.concurrent.duration._ scheduler = context.system.scheduler.schedule( initialDelay = 0 seconds, interval = 10 seconds, receiver = self, message = ActorIdentity("", Some(self)) ) } @scala.throws[IOException](classOf[IOException]) override def postStop() = { scheduler.cancel } override def receive = { case ActorIdentity(_, Some(ref)) => log.info(ref.path.toString) } }

Terminating a run or test in Scala Build Tool (SBT)

When running a program or test in SBT, if you want to exit from it (and not from SBT) try adding following lines in your build.sbt file: fork := true To directly add forking in an SBT session, type set fork := true This will not detach and open a new consule from the original sbt console. But, users can kill this separately. The way to do this in Max OS or Windows is to search a Java process with command line having sbt-launch in Activity Monitor / Windows Task Manager, and end it. In Unix, try grepping a process with sbt-launch in a new terminal, and kill it. Command to do that is: kill -9 `ps -h | grep java | grep -v sbt-launch | grep -v grep | awk '{print $1}'` By default, the run or test tasks run in the JVM as sbt. Forking can be used to run these tasks in a child process. By default, a forked process uses the same Java and Scala versions being used for the build and the working directory and JVM options of the current process. SBT documentation page discusse...