Tuesday, January 7, 2014

Getting started with Netflix Suro


#1 Installing the Git
Per the Linux version use the command to install the Git, below are a few samples:
  • Debian/Ubuntu: apt-get install git
  • RHEL/Fedora: yum install git

#2 Building Suro Server
Create a new directory to clone source code
mkdir netflix
Before cloning make sure HTTPs verification is set to false or else necessary certifcates are in place, I choose a simple strategy, i.e. configured ssl verification to false.
git config --global http.sslVerify false
Clone the source from the git root master branch:
git clone https://github.com/Netflix/suro.git
With this you will have all code available in ./suro folder. 

cd suro
Next step is to build the suro server. I am skipping test cases as well.

 ./gradlew build -x test

#3 Starting Suro server


 ./gradlew installApp
Copy all server libraries at a seprate location
cp -r ~/netflix/suro/suro-server/build/install/suro-server/lib/  ~/netflix/installs/suroserver
Finally start the server using below command:
java -cp "./lib/*"  com.netflix.suro.SuroServer -m conf/routingmap.json -s conf/sink.json 

#4 Checking the system health

To check whether server has started successfully:
http://HOSTNAME:7103/healthcheck
This service should return 200 OK with SuroServer-OK message.

Challenges Faced

#PEER NOT AUTHENTICATED

> Could not resolve com.leansoft:bigqueue:0.7.0. Required by: com.netflix.suro:suro-kafka:0.2.2-thrift-0.7.1 com.netflix.suro:suro-kafka:0.2.2-thrift-0.7.1 > com.netflix.suro:suro-core:0.2.2-thrift-0.7.1 > Could not GET 'https://raw.github.com/bulldog2011/bulldog-repo/master/repo/releases/com/leansoft/bigqueue/0.7.0/bigqueue-0.7.0.pom'. > peer not authenticated
Above was the error which I faced. On further analysis found the issue was because of JAVA_HOME was not set.

# RUNNING SURO ON WINDOWS




Wednesday, January 1, 2014

Happy New Year - 2014

We got up early and plan was all set to go out for a long drive with family to Nageshwar Parshwnath & Susner. 2014 started with cold weather, fog is all over even I was breathing fog out as well.



Saurabh also joined us, we picked him up from his home. He carried a book in his hand, I was wondering, is he going to read during trip? Later found he got that book for me, 'Ageless body & timeless mind', title sounds interesting, the book must be a worth read I thought.

It was chilling and fog has covered all over the place, even our place turned a hill station, it was fun driving in this weather. We took several halts for refreshment, one was near Mahidpur dam. Saw people partying at this place, I too thought of a 'Dal-Bafla' party over here sometime ;)

Aryaa enjoyed company of SVJ, Tim & Timsy story is now one of her favorites now. We took a short cut from Mahidpur to Unhel, and the short cut was too long, it took 2-3 hours to cross 30 km road. Because of this we have to cut short our trip and drop our plan to visit Susner.

Shrine was miraculous, sculptor were beautifully carved, construction was in progress. Lord Parshwnath attractive morph can be realized at the first sight.

Tuesday, December 24, 2013

Functions as Objects

How are functions treated in Scala?
Are functions objects in Scala?

Functions values are treated as objects in Scala.
Any function definition of type A => B is equivalent to type Function1[A,B] and this can be expanded with below definition

trait Function1[A,B]{
   def apply(x: A): B
}

So such traits actually supported by Scala. Function1, Function2,... Function21 in scala package. With such support Scala does support Function definition with 22 parameters.

Anonymous Functions

Expanding the above conversation to see how Anonymous Functions are supported.
For example:

(x: Int) => x * x

when expanded per the above definition below is the structure:

new Function1[Int,Int]{
  def apply(x: Int): Int = x * x  
}

The above definition suggest similar to anonymous class structure provided by Java.

Function Calls

Above discussion provides an understanding of function definition treatment in Scala, but how about function calls. Funtion calls maps to apply method as describe in the structure above.

Lets expand this discussion in terms of below definition which declares an anonymous function and further a call is made to the function:

val f = (x:Int) => x*x
f(2)

val f = new Function1[Int,Int]{
  def apply(x: Int): Int = x * x  
}
f.apply(2)


def f(x: Int): Int = f(x)
out of this (x: Int) => f(x) is treated as anonymous function and expanded by Scala in a similar way discussed above. This translation of a name f is termed as 'eta - expansion' in lamda calculas.

Wednesday, December 18, 2013

Polymorphism in Scala

Is Scala polymorphic? Incase yes, what are the different ways with which this is supported?

Scala being a hybrid of object & functional programming paradigmn, supports polymorphism. Scala support two polymorphism forms:

Subtyping: 

Instances of subclass can be passed to functions instead of declared base class.

Generics:

Functions and classed driven via type parameterization.
  1. Function can be applied to arguments of many types (via generics support at method level)
  2. The type can have instance of many types (via generics support at class level)
Field definition in Scala are special cases of method overriding. They can implement abstract method overriding and traits.

Below are a few highlights in the example:
  1. Cons(val head: Int, val tail: IntList) declares both parameter and field of the class. By declaring this it automatically overrides the abstract definition for head and tail methods.
  2. Generic Type parameter using [T] similar to type definition in Java via <T>
  3. Type parameters are not just limited to classes, but they can be declared at method level as well.
Since Nothing is a subtype of any other type and this is true for T as well. Therefore below syntax is valid and there by this method can be overrided with below definition
def head: Nothing = throw new NoSuchElementException("head.nil")
def tail: Nothing = throw new NoSuchElementException("tail.nil")

Saturday, December 14, 2013

Good Story

Thanks Stephen

Mutter Paneer


This one is not about Scala ;)

Being a weekend thought of preparing something special today. And the very moment heard Mutter wala selling mutter (peas) out side. This reminded me of Mutter-Paneer which SVJ brought yesterday for his evening meal.

Bingo, Why not try Mutter Paneer today!! 

Googled the recipe and stumble upon Nisha Madhulika's site, this details the recipe and that too a Jain version. Followed the steps suggested by her and here it is (on the left) !! 

Comments:
Mumma: She liked it but found it a bit sweet. I haven't added any sugar, looks like peas were sweet.
Shrut: She too find it a less spicy one and bit sweet. But overall it was a nice preparation.
Aryaa: She's the critic, never eat what I prepare.. :(
Me: I liked it, it was delicious. Honest comments.
After eating went to for a nap for 2 hours. Made my day !!

From this experiment, I now believe that such meals can be prepared at home and with better taste then how it is served at restaurants. I am fond of cooking & this experiment has encouraged me.
Now my next goal is to get some Mexican dish prepared at home. I have tasted one such dish at Chipotle and since then I loved it.

Tuesday, December 3, 2013

Operator Overloading in Scala

Does Scala support Operator Overloading?

If I go by below definition then I would say yes it does.
In object-oriented programming, operator overloading—less commonly known as operator ad hoc polymorphism—is a specific case of polymorphism, where different operators have different implementations depending on their arguments. Operator overloading is generally defined by the language, the programmer, or both.
Below is an example which elaborates on how is this supported. I am extending  binary <, unary pre negation (-) and unary post ++ operator for a custom datatype Rational.