Showing posts with label MongoDB. Show all posts
Showing posts with label MongoDB. Show all posts

Friday, June 22, 2018

Big Data / Data Analytics Job

Data Analytics job in UK. Big data analytics Jobs
Data Architect   3-7+ years   

Salary : £70000 - £75000 per annum     location : Central London

Posted: 26/06/2018    Job Type : Permanent

Job Ref: 439101143    Skills & Apply ->
Data Scientist   3-7+ years   

Salary : £232 - £298 per day     location : London

Posted: 18/06/2018    Job Type : Temporary

Job Ref: 775109025    Skills & Apply ->

Thursday, August 29, 2013

MongoDB-Hadoop integration and Data processing with Apache Pig. Running pig script with Node.js


I have a weather data in MongoDB database, As a experiment weather data  porting into hadoop environment and processing using Pig.

By using mongodb-hadoop connector, from Pig one can able to read from / write /to mongoDB. once output written into MongoDB from browser user can able to view the result data.

I've created simple web application with MongoDB and Node.js using Express framework. also executing Pig script with in Node.



trades collection data

>  use week6                                      
> db.trades.findOne()
{
 "_id" : ObjectId("51b05fbce3600f7b48448eda"),
 "ticker" : "abcd",
 "time" : ISODate("2012-03-03T04:24:13.003Z"),
 "price" : 110,
 "shares" : 200,
 "ticket" : "z135" // this key used for group in pig script
}



Pig script


root@boss[bin]#vi cntWthr.pig

.....-- MongoDB Java driver
REGISTER  /opt/hadoop-1.1.0/lib/mongo-2.10.1.jar;
-- Core Mongo-Hadoop Library
REGISTER /opt/bigdata/mongo-hadoop/core/target/mongo-hadoop-core_1.1.2-1.1.0.jar;
-- mongo-hadoop pig support
REGISTER /opt/bigdata/mongo-hadoop/pig/target/mongo-hadoop-pig_1.1.2-1.1.0.jar;

trades = LOAD 'mongodb://localhost:27017/week6.trades' using com.mongodb.hadoop.pig.MongoLoader; 
grp = GROUP trades by $0#'ticket';
cnt = FOREACH grp GENERATE group,COUNT(trades);
--dump cnt;
STORE cnt INTO 'mongodb://localhost:27017/mongo_hadoop.yield_historical.outt' USING com.mongodb.hadoop.pig.MongoInsertStorage('group:float,cnt:int', 'group');


in above script

  • LOAD the MongoDB data from week6 database and trades collection.
  • GROUP the loaded data based on the key ticket
  • GENERATE the COUNT for each ticket 
  • Instead of display the result in console or store into hdfs, here I'm STORE back to MongoDB  mongo_hadoop and collection yield_historical.
Node.js 

root@boss[bin]#vi mongoHadoopNode.js


// This script must be run from PIG_HOME/bin and file cntWthr.pig must be exist in same path.
var express = require('express'),     
    app = express(),
    cons = require('consolidate'), 
    mongoClient = require('mongodb').MongoClient,
    Server  = require('mongodb').Server;
// Configuring view template
app.engine('html',cons.swig);
app.set('view engine','html');
app.set('views', __dirname + "/views");
// Running pig script file var spawn = require('child_process').spawn, runPig = spawn('pig',['cntWthr.pig']); // Handling the output runPig.stdout.on('data',function(data){ console.log('stdout : '+data); }); runPig.stderr.on('data',function(data){ console.log('stderr : '+data ); }); app.get('/',function(req,res){ mongoClient.connect('mongodb://localhost:27017/mongo_hadoop',function(err,db) { if(err) throw err; db.collection('yield_historical.outt').findOne({},function(err,doc){ res.render('template',{'Group':doc.group,'Value':doc.val_0}); db.close(); });; }); }); app.get('*',function(req,res){ res.send("Page Not Found !!!! "); }); mongo.open(function(err,mongo){ if(err) throw err; app.listen(8000); console.log("Express server started successfully localhost:8000") });

simple Html page ( view/template.html )

MongoDB-Hadoop integraton and Job processing with PIG 
Group : {{Group}}  Value : {{Value}}

Run node.js 
root@boss[bin]#node mongoHadoopNode.js
Express server started successfully localhost:8000

MongoDB new collection created  under mongo_hadoop database
>  use mongo_hadoop
> db.yield_historical.outt.findOne()
{ "_id" : ObjectId("521f0ebf908dfe1853af7c01"), "group" : "z135", "val_0" : NumberLong(1667) }

enter the IP in browser, which will show the output like
http://localhost:8000

MongoDB-Hadoop integraton and Job processing with PIG
Group : z447 
Value : 834


Tuesday, August 27, 2013

Issues with MongoDB and Hadoop Integration


I just tried create connector for  mongoDB NoSQL with Hadoop 0.21.0

while i'm doing so got few error which is solvable and hadoop-core unresolved dependency which is unsolvable. Then I decided to create connector for Hadoop 1.1.0.

After downloaded from git, did

ERROR 1)


root@boss[mongo-hadoop]# ./sbt package


java.lang.RuntimeException: Hadoop Release '%s' is an invalid/unsupported release.  Valid entries are in 0.21.0
 at scala.sys.package$.error(package.scala:27)
 at MongoHadoopBuild$$anonfun$streamingSettings$6$$anonfun$apply$8.apply(MongoHadoopBuild.scala:176)
 at MongoHadoopBuild$$anonfun$streamingSettings$6$$anonfun$apply$8.apply(MongoHadoopBuild.scala:176)
 at scala.collection.MapLike$class.getOrElse(MapLike.scala:122)
 at scala.collection.immutable.HashMap.getOrElse(HashMap.scala:38)
 at MongoHadoopBuild$$anonfun$streamingSettings$6.apply(MongoHadoopBuild.scala:176)
 at MongoHadoopBuild$$anonfun$streamingSettings$6.apply(MongoHadoopBuild.scala:175)
 at scala.Function1$$anonfun$compose$1.apply(Function1.scala:49)
 at scala.Function1$$anonfun$compose$1.apply(Function1.scala:49)
 at sbt.EvaluateSettings$$anonfun$sbt$EvaluateSettings$$single$1.apply(INode.scala:159)
 at sbt.EvaluateSettings$$anonfun$sbt$EvaluateSettings$$single$1.apply(INode.scala:159)
 at sbt.EvaluateSettings$MixedNode.evaluate0(INode.scala:177)
 at sbt.EvaluateSettings$INode.evaluate(INode.scala:132)
 at sbt.EvaluateSettings$$anonfun$sbt$EvaluateSettings$$submitEvaluate$1.apply$mcV$sp(INode.scala:64)
 at sbt.EvaluateSettings.sbt$EvaluateSettings$$run0(INode.scala:73)
 at sbt.EvaluateSettings$$anon$3.run(INode.scala:69)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:619)
[error] Hadoop Release '%s' is an invalid/unsupported release.  Valid entries are in 0.21.0
[error] Use 'last' for the full log.

SOLUTION
I simply changed in build.sbt
"0.21.0"  to "0.21"



root@boss[mongo-hadoop]#vi build.sbt 
.......
.......
hadoopRelease in ThisBuild := "0.21"


ERROR 2)
then I executed the same

root@boss[mongo-hadoop]# ./sbt package


module not found: org.apache.hadoop#hadoop-core;0.21.0
[warn] ==== local: tried
[warn]   /root/.ivy2/local/org.apache.hadoop/hadoop-core/0.21.0/ivys/ivy.xml
[warn] ==== Simile Repo at MIT: tried
[warn]   http://simile.mit.edu/maven/org/apache/hadoop/hadoop-core/0.21.0/hadoop-core-0.21.0.pom
[warn] ==== Cloudera Repository: tried
[warn]   https://repository.cloudera.com/artifactory/cloudera-repos/org/apache/hadoop/hadoop-core/0.21.0/hadoop-core-0.21.0.pom
[warn] ==== Maven.Org Repository: tried
[warn]   http://repo1.maven.org/maven2/org/apache/hadoop/hadoop-core/0.21.0/hadoop-core-0.21.0.pom
[warn] ==== releases: tried
[warn]   https://oss.sonatype.org/content/repositories/releases/org/apache/hadoop/hadoop-core/0.21.0/hadoop-core-0.21.0.pom
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/org/apache/hadoop/hadoop-core/0.21.0/hadoop-core-0.21.0.pom
[info] Resolving org.specs2#specs2-scalaz-core_2.9.2;6.0.1 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.apache.hadoop#hadoop-core;0.21.0: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
sbt.ResolveException: unresolved dependency: org.apache.hadoop#hadoop-core;0.21.0: not found

SOLUTION

 surfing around web, concluded  issues related to port 443. even after 443 port is opened error remains.

then i gone through all the link, I never find any hadoop-core-0.21.0.jar file.

---

then i tried to create connector for Hadoop version 1.1.0, it was successfully created. you can also download mongoDB connector for Hadoop 1.1 here.

I'm working with MongoDB + Hadoop  with Pig. will update any issues or example work flow.
 

---

working with MongoDB + Hadoop with Pig, followed  Treasury Yield Calculation example from here.

1) mongoimport of .json data
2) downloaded piggybank-0.3-amzn jar from s3://elasticmapreduce/libs/pig/0.3/piggybank-0.3-amzn.jar

while I'm executing

grunt> REGISTER /opt/bigdata/mongo-hadoop/piggybank-0.3-amzn.jar  
...... 
   grunt> date_tenyear = foreach  raw generate UnixToISO($0#'_id'), $0#'bc10Year';

have got below error


ERROR 1070: Could not resolve org.apache.pig.piggybank.evaluation.datetime.convert.UnixToISO using imports: [, org.apache.pig.builtin., org.apache.pig.impl.builtin.]

then I went through piggybank-0.3-amzn.jar, I've never seen any method like UnixToISO().

this time I registered pigybank.jar from $PIG_HOME/ contrib/piggybank/java


grunt> REGISTER /opt/bigdata/pig-0.10.0/contrib/piggybank/java/piggybank.jar;
....

after this all the steps from earlier said example worked,  can able to read/write  MongoDB through Pig.






Wednesday, June 19, 2013

Changing the defalult dbpath in mongoDB & Use existing database in newer version of mongo server

I was working in mongoDB 2.2,  Recently installed mongoDB 2.4 & it's default location is /var/lib/mongodb.

I was used /data/db as a default path in mongoDB 2.2, after I installed 2.4, I thought of using existing database which I created using 2.2.

Instead of backup & restore or import & export  I just change the dbpath in /etc/mongodb.conf.

here simple step to re-configuring the default dbpath and

1) stop the mongoDB server
root@boss[bin]#/etc/init.d/mongodb stop 
 Stopping database: mongodb.

 2) Open a file & change dbpath to desired location
root@boss[bin]#vi /etc/mongodb.conf
.....
.....
#dbpath=/var/lib/mongodb
dbpath=/data/db
.....
.....

3) restart the mongoDB
root@boss[bin]#/etc/init.d/mongodb strat 
root@boss[bin]#tail -f /var/log/mongodb/mongodb.log  
***** SERVER RESTARTED *****

Tue Jun 18 15:32:41.170 [initandlisten] MongoDB starting : pid=20270 port=27017 dbpath=/data/db 32-bit host=boss
Tue Jun 18 15:32:41.170 [initandlisten] 
Tue Jun 18 15:32:41.170 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Tue Jun 18 15:32:41.170 [initandlisten] **       32 bit builds are limited to less than 2GB of data (or less with --journal).
Tue Jun 18 15:32:41.170 [initandlisten] **       Note that journaling defaults to off for 32 bit and is currently off.
Tue Jun 18 15:32:41.170 [initandlisten] **       See http://dochub.mongodb.org/core/32bit
Tue Jun 18 15:32:41.170 [initandlisten] 
Tue Jun 18 15:32:41.170 [initandlisten] db version v2.4.4
Tue Jun 18 15:32:41.170 [initandlisten] git version: 4ec1fb96702c9d4c57b1e06dd34eb73a16e407d2
Tue Jun 18 15:32:41.170 [initandlisten] build info: Linux bs-linux32.10gen.cc 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49
Tue Jun 18 15:32:41.170 [initandlisten] allocator: system
Tue Jun 18 15:32:41.170 [initandlisten] options: { config: "/etc/mongodb.conf", dbpath: "/data/db", logappend: "true", logpath: "/var/log/mongodb/mongodb.log" }
Tue Jun 18 15:32:41.170 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Tue Jun 18 15:32:41.170 dbexit: 
Tue Jun 18 15:32:41.170 [initandlisten] shutdown: going to close listening sockets...
Tue Jun 18 15:32:41.170 [initandlisten] shutdown: going to flush diaglog...
Tue Jun 18 15:32:41.170 [initandlisten] shutdown: going to close sockets...
Tue Jun 18 15:32:41.170 [initandlisten] shutdown: waiting for fs preallocator...
Tue Jun 18 15:32:41.170 [initandlisten] shutdown: closing all files...
Tue Jun 18 15:32:41.171 [initandlisten] closeAllFiles() finished
Tue Jun 18 15:32:41.171 [initandlisten] shutdown: removing fs lock...
Tue Jun 18 15:32:41.171 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Tue Jun 18 15:32:41.171 dbexit: really exiting now
its failed to start, have checked log file in (/var/log/mongodb/mongodb.log)got above error.

then I changed the owner & permission of /data/db as like mongoDB 2.4 default path /var/lib/mongodb/ 

4) get the owner & access details
root@boss[bin]#ls -l /var/lib/mongodb/
total 32808
-rw------- 1 mongodb nogroup 16777216 Jun 18 15:33 local.0
-rw------- 1 mongodb nogroup 16777216 Jun 18 15:33 local.ns
-rwxr-xr-x 1 mongodb mongodb        0 Jun 18 15:40 mongod.lock

 5)change the owner in new path (i.e /data/db )
root@boss[bin]#chown -R mongodb:nogroup /data/db
root@boss[bin]#chown mongodb:mongodb /data/db/mongod.lock
then I restart the mongodb by /etc/init.d/mongo start ( step 3 ). this time server started successfully.
starting  mongoDB

root@boss[bin]#/etc/init.d/mongodb strat 
 Starting database: mongodb. 

6) Running mongo
root@boss[bin]#mongo 
MongoDB shell version: 2.4.4
connecting to: test
> db 
test
>show dbs 
admin 0.0625GB
local 0.03125GB
rs 0.0625GB
snps1 0.0625GB
test 0.0625GB
week4 0.0625GB
week5 0.0625GB
week6 0.999755859375GB

by using mongo2.4 can able to access the all database which was created using mongo2.2.

without dump & restore / import & export the old database created using mongoDB 2.2 can be readily accessible by newer version of mongodb 2.4 by simply changing / configuring  the dbpath attribute in /etc/mongodb.conf

Tuesday, June 18, 2013

Install mongoDB on BOSS GNU/Linux


This post will help you out installing NoSQL mongoDB on BOSS GNU/Linux ( Debian-based Linux distribution ).  
BOSS version 4.0 & 5.0
latest version of mongoDB (2.4)
1) Import GPG key

root@boss[bin]#apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
 10gen package authenticated and it so require GPG key.

2) Create mongoDB 10gen package 

root@boss[bin]#echo 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.list
above command will create the file which contain  package location latest version of mongoDB.

 3) Updates the package lists from a server
 
root@boss[bin]#sudo apt-get update
re-synchronize the package index files from their sources.
it may throw error, if the GPG key not imported properly

.......
.......
: GPG error: http://downloads-distro.mongodb.org dist Release: 
 The following signatures couldn't be verified because the public key is not available: 
 NO_PUBKEY 9ECBEC467F0CEB10

note : in our BOSS version 4.0 & 5.0 , mongoDB successfully installed and running even if the key not imported properly.

4) Installing mongoDB
root@boss[bin]#sudo apt-get install mongodb-10gen
 latest version of mongoDB automatically installed.
....
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run `apt-get -f install' to correct these:
The following packages have unmet dependencies:
  libboost-dev: Depends: libboost1.49-dev but it is not installable
  mongodb: Depends: mongodb-dev but it is not going to be installed
           Depends: mongodb-server (>= 1:2.4.1-2) but it is not going to be installed
  mongodb-10gen: Conflicts: mongodb but 1:2.4.3-1 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
 4.1) Install any dependencies that your previous installs missed.
in our above command, installation not succeed because of missing dependencies mongodb-dev & mongodb-server. issue the blow command to install those depends.  
root@boss[bin]#apt-get -f install 
.......
.......
Install these packages without verification [y/N]? y
Get:1 http://downloads-distro.mongodb.org dist/10gen mongodb-10gen 2.4.4 [86.8MB]
Fetched 86.8MB in 18s (4,718kB/s)                                                                      
Selecting previously deselected package mongodb-10gen.
(Reading database ... 154044 files and directories currently installed.)
Unpacking mongodb-10gen (from .../mongodb-10gen_2.4.4_i386.deb) ...
Processing triggers for man-db ...
Setting up mongodb-10gen (2.4.4) ...
insserv: warning: script 'K01postgresql-9.0' missing LSB tags and overrides
insserv: warning: script 'K01EnterpriseDBApachePhp' missing LSB tags and overrides
insserv: warning: script 'postgresql-9.0' missing LSB tags and overrides
insserv: warning: script 'EnterpriseDBApachePhp' missing LSB tags and overrides
Starting database: mongodb.
 by issuing above command mongoDB server installed & started successfully.

5) Know the location of config file

root@boss[bin]#ps -ef | grep mongo
mongodb  14603     1  0 10:53 ?        00:00:00 /usr/bin/mongod --config /etc/mongodb.conf
root     14655 18627  0 10:54 pts/3    00:00:00 grep mongo
also use 
5.1)Get the running instance of mongoDB

root@boss[bin]#ps -A | grep mongo 
 14603 ?        00:00:00 mongod
 5.2) Get the binary executable location of mongoDB

root@boss[bin]#whereis mongo 
 mongo: /usr/bin/mongo /usr/share/man/man1/mongo.1.gz

 by issuing above command we can come to know, the 
  1. mongo server running on PID 14603
  2. All binary file available under /usr/bin directory.
  3. config file under /etc/mongodb.conf
6) Controlling mangoDB
starting  mongoDB
root@boss[bin]#/etc/init.d/mongodb strat 
 Starting database: mongodb.
get the status
root@boss[bin]#/etc/init.d/mongodb status 
 Checking status of database: mongodb running..
stopping mongoDB
root@boss[bin]#/etc/init.d/mongodb stop 
 Stopping database: mongodb.
7) Running mongo

root@boss[bin]#mongo 
MongoDB shell version: 2.4.4
connecting to: test
> db 
test
>
 by default its connecting test  database.
command "db" will return the current connected database, you can switch to any database by "use dbname"

note : here I logged in as root user, use sudo if you logged in an other then root user.
BOSS - Bharat Operating System Solution.

Friday, June 14, 2013

List the active connection/user in PostgreSQl,MySQL & mongoDB

As a DBA have to ensure number of active connection in database & which query consuming longer time to execute.

In PostgreSQL we can query from "pg_stat_activity" to know the status of the each connection.

when I was working in mongoDB(no-SQL) , wanted  to monitor the client  who currently accessing my server & the list active of operation.

here simple comparison,  how we to get  number of  active client (remote / local i.e different user ) connected to databases ( PostgreSQL,MySQL and mongoDB ) server.


PostgreSQL
----------------

select* from pg_stat_activity
postgres=# select datname, usename, application_name, client_addr,client_port,query_start,current_query from pg_stat_activity
 +------+---------+------------------------------+-------+---------+------+-------+------------------+
|datname  |usename   | application_name         | client_addr  | client_port | query_start 
+------+---------+------------------------------+-------+---------+------+-------+------------------+
template1 | postgres | pgAdmin III - Browser    | 127.0.0.1    |       56019 | 2013-06-14 19:52:52.775344+05:30
 SAAS     | postgres | psql                     | 192.168.1.10 |       58776 | 2013-06-14 19:58:33.084661+05:30
 koha     | postgres | pgAdmin III - Browser    | 192.168.0.2  |       56020 | 2013-06-14 19:52:52.729838+05:30
 pis      | postgres | pgAdmin III - Query Tool | 127.0.0.1    |       56022 | 2013-06-14 19:56:21.729744+05:30-
   - It display the list of active user/client ip address and query details.

Mysql
----------


show processlist; 
mysql> show processlist;
+------+---------+------------------------------+-------+---------+------+-------+------------------+
| Id   | User    | Host                         | db    | Command | Time | State | Info             |
+------+---------+------------------------------+-------+---------+------+-------+------------------+
| 3832 | root    | localhost                    | mysql | Query   |    0 | NULL  | show processlist |
| 3834 | erbnext | localhost                    | NULL  | Sleep   | 2524 |       | NULL             |
| 3837 | root    | solaimurugan.chennai.in:36125| koha  | Sleep   |    3 |       | NULL             |
+------+---------+------------------------------+-------+---------+------+-------+------------------+
3 rows in set (0.00 sec) 

it states that 3 active connections, 2 from localhost & 1 from client solaimurugan.chennai.in & it connects database mysql & koha.


mongoDB
------------



db.currentOp(true)
root@boss[bin]#./mongo  
MongoDB shell version: 2.2.3
-----------------------------------------------------------------------------------------------------------------------
db.currentOp(true).inprog.forEach(function(d){if(d.client && d.client!="0.0.0.0:0")printjson(d.client)})
----------------------------------------------------------------------------------------------------------------------
"solaimurugan.chennai.in:56231"
"127.0.0.1:49563" 
"192.168.31.101:50132" 
-------------------------------------------------------------------------------------------------------------------------------------

 mongoDB also has command to view total number of current connection & available connection to be established by client


db.serverStatus()

root@boss[bin]#./mongo  
MongoDB shell version: 2.2.3
-----------------------------------------------------------------------------------------------------------------------
db.serverStatus().connections
-----------------------------------------------------------------------------------------------------------------------------
{ "current" : 3, "available" : 816 }
------------------------------------------------------------------------------------------------------------------------------


Labels