Friday, December 11, 2015

Property Manager - Manage your properties in a clean and efficient way


Well, how many times while starting a new project, we have to think of externalizing our properties files (not one but many for DB, Cache, third party integration, environment constant etc ... ). It's again a fresh start every and each time. There isn't a time when we can reuse either the existing framework or existing property management server to externalize that piece of component from our application. Hence our application is always tied to the way we read properties. It might be from the JSON file, XML file or simply the Key Value pair.

Isn't it beautiful (both from DEV n DEVOPS point of view) that if we have multiple projects, we can provide the guys a unified console to manage the properties, irrespective of the project. A Centralized property management server that does this task so that our application, can only focus on doing the task it was being created for.

This is my problem from some years, but dint get much time to create one off the hook but this time i tried it off and it came very well. Congratulations, well now we have something which is very simple to set up and it takes off the headache. The developer only needs to integrate the client and to be provided with the project/env/release version and the library will give him all the properties that he asked the DEVOPS to create for the project (or it can be directly created if the access is granted to use the console by the developer).

Since, DEMO of the application is always important then the explanation, here is the LIVE LINK to the running application on HEROKU.

DEMO: 

LIVE PROPERTY MANAGER

Here is a snapshot of how the UI of the application will look like .



This application is totally based on MONGODB  + EXPRESS with mongoose as the ORM framework and AngularJS as the client side framework. The client UI is an single page application completely being manged by AngularJS and Bootstrap ( Angular UI Bootstrap) components are being used to render the UI. 

CLIENTS: 

Since this is an server side application we need a language specific client to access the properties in your project. Libraries has been created in NODEJS (avaiable as NPM Module) and Java (available as a GITHUB Project will be soon available in MVN Repository).
If the client doesn't exist for your working language, let me know and i am very sure we can created it in a very short span of time.

PROJECT DETAILS: 

GITHUB:   https://github.com/panbhatt/propserver

NODEJS Module :  https://github.com/panbhatt/propserver-node-client
   NPM : npm i propserver-node-client

JAVA :   https://github.com/panbhatt/propserver-java-client

All the API's of the project are being documented property via SWAGGER and can be found in the swagger console available at https://vast-cliffs-8955.herokuapp.com/swagger/ 


All the API's of the project can be tested with the above Swagger API Console. 

I hope it will be helfpul for you. Let me know, in comments how we can improve this project (by email or via GITHUB too.)

Note: There is a project ZUUL available at devnull.org (however the site is down since long) but it is only made for java ( plus a spring client is also there but it lacks little documentation and it is little cumbersome of set it up). It also provides similar features but only Java support. 

Let me know, if you like it. It is free for anyone's use. Just drop me a mail and if there are donations that would be awesome for me to buy a BEER... !!!!!!. 

Friday, November 6, 2015

Nodejs n Java - Using Java code in NodeJS

Being a seasoned java developer, switching to NodeJS and dealing with the way Nodejs works is quite challenging. Plus, what about the work done in the Java, isn't we have to redo all that thing in Nodejs... well, what if i say No... whooooo..how...

NodeJS is too open, and with the NAN library (native abstractions for Node) it does provide a way to use Java libraries and your custom code in NodeJS. Since node  is being developed in C++ there are ways to invoke C++ code in NodeJS, however this kept changing between Node V0.10.x n V0.12.7. I really found it a bit on the higher end of learning curve although its great and fun experience to work with it. However with the complexity, i also decided to try another road. Since it is my bread and butter for quite long time, it seems to be good chance to go back in the old territory and see, how things can be bridged.

Enough talk lets start coding...
I have uploaded all the Java + NodeJS code on my Github repo https://github.com/panbhatt/JavaNodeSample

Basically, we have to use two NPM module "java" which acts as a wrapper across the Java API's and 'node-java-maven' through which we can use any library present under MVN repo... well everything is available under MVN,, isnt???/

Steps to run the example
1. Clone the repo and do an "npm install" .
2. execute "node index.js" . This file will simply replicate the functionality of NodeMain.java and simply invoke every function present in it. (without argument, with integer argument, with String argument, calling instance n static methods, getting a returned value from the Java program.
3. execute "node maven.js" -> This will replicate the functionality of MavenMain.java (which will be using Apache commons lang ver 3.0)... Open package.json and see the "java" keyword . yes we can specify any java library via this and can load this in our nodejs program before executing any java code.

I have purposely created a lib directory which will contains the custom code that we have written via using Apache Commons Lang and the whole maven project is being included undeer "NodeSample" folder in the Git Repo.

Every Java function, can be called either in an SYNCHRONOUS or Asynchronous manner. Both of the programs have an example of this.

Here are some of the detailed links that will be helpful.

https://github.com/joeferner/node-java    -> Github repo of actual 'java' module
https://github.com/joeferner/node-java-maven -> github Repo of actual 'node-java-maven' module.

I hope this will prove helpful for daily Nodejs programmer or the Java guys who are making a shift to NodejS (like me... ummmm.). Let me know if there is a problem.

Tuesday, July 14, 2015

MongoDB Authentication - My Notes




for setting the authentication:
> use admin
> show collections
  system.indexes
  system.users
> db.createUser({ "user" : "panbhatt" , "pwd" : "*******" , "roles" : [ "readWrite" ]})
OR
db.addUser("panbhatt","internet")   // This is OLD
> db.system.users.find()
 // To Verify that the user has been registered.

now switch to another database
> use logs
> Add the user same as above conditions

use db.dropUser("nameofUser") // to drop an user.

http://blog.amussey.com/post/62809509642/mongodb-installing-and-configuring-authentication

Thursday, October 16, 2014

Shell Script - Short Learning for big future.

From a long time, i wanted to write a summarized view of various features available in shell scripting. Finally after reading 2 books of shell scripting, I am trying to summarized the best features so that it can be completed in minimum amount of time by a developer who wants a quick cheat sheet type of page, where one can find all the daily useful commands & remember it for long time. here is the pointed form of the summary:-

  1. Cat /etc/shells    -> Lists the shells available
  1. echo $SHELL   -> Get current running shell
  2. ps $$   -> gives the PID of the shell running in the system.
  3. type -a ls -> Gives whether ls is external or internal command, with path
  4. Bash Startup Scripts
    a.
    /etc/profile - The systemwide initialization file, executed for login shells
    b.
    $HOME/.bash_profile, $HOME/.bash_login, and $HOME/.profile runs second when a user logs in in that order.
    c.
    $HOME/.bash_logout invoked when you log out.
  5. apt-cache search shell -> To find the list of available shell packages under ubuntu
  6. which bash -> Will give you the full path of shell command (try Whereis -> this will give the location+man location of this command )
  7. vi hello.sh -> Create a new file and write echo "hello world" in it. Execute chmod +x  hello.sh and then execute ./hello.sh to execute the commands under it.
  1. #!/bin/bash -> this is the Shebang tha tis to be used at the first line of every script
  1. Execute a script also via "bash hello.sh"
  1. Debug mode: "bash -xv hello.sh"   or use set -x/+x , -v/+v, -n/+n in script
  1. Env or printenv -> list all the system variables
  1. Find /home -name *.c -> will find all C files under /home
  1. printf "${PATH}\n"   -> Use printf  extensively as like in C.
  1. personName="Pankaj Bhatt"
    echo "Person name is ${personName}
  1. lastName=${variable:-"bhatt"}    -> If variable is empty it will assign value 'bhatt'
  1. Sleep 3  -> Halt the execution of 3 sceonds.
  1. Echo *.conf -> Show all the conf files within current directory
  2. Export -> This command is used to export variables to all child processes
  3. Export -n -> Gives the list of all variables exported to this shell.
  4. Unset varname -> Will unset the value of the variable.
  1. read -p "Enter your name : "name   -> For reading the value in an Variable
  1. Read arguments -t 10 For Timeout input (abort if don’t enter),-s for password
  1. ans=$((x +y ))  -> To Do the mathematical computation for two variables, if either x or y is can't converted to INTEGER it should be used as ZERO.
  1. declare -i num1=10 -> declare an integer variable. (Assigning else results 0)
  1. readonly varName = value -> being used to create a constant OR
    declare -r varname=value
  1. varc=${varName:?Error varName is not defined or is empty} -> To check whether varName is defined or not, otherwise  the remaining string will be used to display the error.
  1. let sum=no1+no2 :- Let command can be used to do mathmatical operations without using $ in front of variables. Or $[ no1 + no2 ] can also be used and results can be assigned to result.
  1. bc comamnd can be used to do mathematical computation. echo "4 * 0.56" | bc
  1. Export JAVA_HOME= /usr/bin/java/jdk   -> This command will treat java_home as env variable going forward.
  1. Whatis ls -> This command gives a short description of the command from man pages.
  1. history -> Command is used to see the history of commands you typed. CTRL-R is used to search the command while typing. ! will execute the command from command history.
  1. !! -> This will execute the last command you typed.
  1. A {} is used to repeat a pattern. E.g. echo file{1,2,3}.txt will print -> file1.txt file2.txt file3.txt
  1. Wildcard (*,?.[..]) supports the above pattern.  E.g. ls *.{c,java}
  1. ls [ab]*.sh -> only lists the file starting with a or b. [a-d]*.sh   -> Only a-d starting filenames.
  1. ls -d */ -> Gives you a list of all the directories present in the current pwd.
  1. Alias -. It list all the alias present in the system.
    1. Alias ls ='ls -lah' -> To create alias for any command
    1. Unalias ls -> to Remove the Alias
      Alias remove with the session, to store them permanently store them in /{HOME}/.bashrc file
  1. STARTUP Scripts
    1. /etc/profile -> Linux wide system properties file. Runs first when a user logs in.
    2. /etc/profile.d -> directly contains all files that Runs SECOND when user logs in.
    3. ${HOME}/.bash_profile -> Runs third when user logs in. Internally this calls .bashrc in HOME directory. Use this for setting anything. Once done type n press "bash" for to refresh the settings placed in .bashrc file.
  1. cat command is being used for seeing the contents on the screen.
  1. PS1 is the variable that holds the command prompt you use. Set it in .bashrc file, via using export PS1=''${HOME}"
  1. CTRL-D is the command, which is being used to come out of the shell.
  1. Setting Shell options:-
    1. set -o -: This will list all the shell configured variables.
    1. set -o variableName :- This will unset a specific variable listed from the above command.
    2. set +o variableName :- This will set a specific variable listed from the above command.
  1. shopt -> to list some of the variables configured for the environment. For setting it use "shopt -s " and for unset -u option
  2. Setting Env Variables :- Modify ~/.bash_rc  and include line EXPORT =""
  3. System Vide Shell Options: in /etc/profile.d directory create a file java.sh (with execute permissions)  and write export java commands in it.E.g. export JAVA_HOME=/usr/lib/java/jdk1.6u50 ;     \n export PATH=$PATH:$JAVA_HOME/bin
  4. test command is being used for checking the file existence or test values
    test -f /bin/bash && echo "File Exists" || echo "File does not exists."      -> It will print File Exists
  5. If [test] CONDITION ->  then  … … …else … … .. -> fi     ( You can also use elif in place of else if  } 
    if [ $myAge -gt 0 ]   -> This is also a valid condiion
  1. Exit status of the command -> Use $? To get the status of the earlier command executed
  1. Connection command e.g.  > Second set of commands will execute only when first is successful
test! -d /tmp/foo && { read-p "Directory /tmp/foo not found. Hit [Enter] to exit..."enter; exit 1; }
|| Operator -> echo "ram here" >> /dev/null || echo "I M Executing"  -> second will only execute on failure of first.
  1. -ge, -eq, lt, -le, -gt, -ne
  2. test -z -> to check that the string is not empty &length is not  zero
  3. File operation with test :  -a : if file exists, -b : if file exists and block special file , -d : is a directory , -e : if file exists, -f : regular file , -s size
  4. Command line arguments: $0, $1, $2, $3, $4 etc.   $*/$@ -> Represents all command line arguments.
  5. Parameters set by shell: $*, $@, $#, $-, $?, $$, $!   , ($? -> Represents the status of the last executed command)
  1. exit N -> Where N represents the code that is being returned for the script execution status code. 0 means success
  1. case $val in \n  "pankaj") echo "got it" ;; \n "abc") echo " This is second change";; \n *) echo "Default Case";;   esac
    The pattern to be matched can contain regular expression characters.
    You can use "
    shopt -s nocasematch" in the script, to ignore case comparison while case matching in SWITCH case.
  2. For $variable in (some kind of list, can be string/numbers etc) \n do \n cmd1;cmd2;cmd3;  done
    C Like for loop also works here.
    for (( i =1; i <=5; i++ ))
  1. While [ $n -eq 0 ] \n do \n cmd1; cmd2; cmd3 ; \n done
    while : \n do cmd1; cmd2; cmd3 \n done ->
    This is an indefinite loop or (while true ) or (while false)
  1. Until [ condition ] \n do \n cmd1; cmd2; cmd3; \n done   -> Reverse of While, until the condition becomes true, it will run.
  1. Select var in list \n do \n cmd1;cmd2;cmd3; \n done
  1. Break is used to come outside of the innermost loop while break N is to come out of the N levels of loops.
  1. continue is also used to keep on going the loop.
  2. $(ls) -> This will execute a command enclose in $() and can assign it results in an variable.
  3. < :- for input, > :- for output , 2> :- error redirection, &> :- use to redirect both output and error to the same place, 2>> Append error log
  4. /dev/null :- All the data written on this is being discarded by the system.
  1. bash -c "cd /home; ls -la"  -> This comman will execute the script script inline as it is being passed to the command.
  1. cat abc.txt > /dev/lp0 -> print the file to the printer.
  1. File Descriptor can be assigned to an input file or to an output file , exec 3< abc.txt  OR exec 3> abc.txt
  2. Enclose multiple commands in single block : { cd /home; ls -la ; dir ; }
  3. Watch -n 5 "ls -la; df -h ;" -> Watch the execution of this command very 2 seconds. Press CTRL-C to come out.
  4. Command & -> To put the command in the background.
  1. Pipes are a way to send the output of one command to another one.  e.g cat abc.txt > grep "ram"
  1. pstree -> This is the command that will be used to display the tree of process with there childs.
  1. pgrep -u pankaj,ram : This is used to list the processes of pankaj & ram user in the system.
  2. pkill is a command to kill the processes that belongs to a group/user.
  3. trap : trap is the command which is being used to trap (any of the SIGTERM signal) and execute a codes based on that.
  4. Functions are being created in shell scripting. Just like in other languages, arguments are being accessible by $0,$1
    Eg.
myFun()
{
echo "Hello, how things are" $1
}

echo "start calling the function"
myFun Argument1
Any outside variable defined within the Function will change its value. To declare any local variable within function use "local nm=$1"
return command can be used to return a value from the function, if no value is being specified hen last command status will be returned.
We can write all the functions in a single script and then can include then file in our main script. E.g. if we have functions.sh at home directory then include it via ". /home/pankaj/functions.sh" . Then you can call every function present in that file. Or another way is to use the source command e.g. "source /home/pankaj/functions.sh".
you can use '&' operator to execute a function in the background. (just like a normal shell command).
  1. Subshells are the shells within which your script runs within a shell. You need to EXPORT every variable/function that is defined in the main shell to get it accessed by the Subshell.
  1. exec command can be used to replace this shell with specified program without swapping to a new subshell or process.
  1. . (dot) command is used to run the script in the current shell, so that any parameters that are defined in the mains shell should be accessible, otherwise they wont be accessible to the script running under a subshell.
  2. Compond command is a way to encapsulating multiple commands under a single umbrella. All commands will be executed and generate there output
  3. You can also display dialog boxes while running your script. For this "sudo apt-get install dialog" and then you can use it in script
    E.g.
    dialog --title "hello world" --msgbox "Hello World 6 20"
  4. The tty command is used to display the name of device file attached with the terminal. Or (file connected with standard input).
  1. Colored output can be print on the console. E.g. echo -e "\e[1;31m This is red text \e[0m"
  2. For every process in the system you can get the list of environment varialbles by  cat /proc/{PID}/environ
  3. Get Length of a variable via "length=${#varName}
  4. Tee command is used to get the data from the last command to store the output in an file and also show it to the screen
    E.g.
    echo "Ram teri ganga maili" | tee out.txt -> will store the contents in out.txt as well as it store it to the file.
  5. /dev/stdout -> refers to the standard output and /dev/stdin -> Refers to the keyboard, /dev/stderr -> To screen, /dev/null -> discard all
  6. You can also create  a array in shell scripts via arry_Name=("ram","shyam"); arry_Name[0]=100; echo ${arry_Name[$index]}
    To print all values of an Array Use . ${arry_Name[*]} or ${arry_Name[@]}
    An associate array is being used to use the STRING as the INDEX in the array. e.g. declare -A arry_Name
  1. sleep 30 : is a a command that is being used to sleep fo r specific of time.
  1. xargs command can be used to take input from STDIN n convert it to the parameters passed to  another command.
  2. tr is the command which is used for Translating
  1. Md5sum is the command to calculate the md5 of all the filenames that are present in the md5sum command.  Same as sha1sum.
  1. Md5deep & sha1deep is used to calculate the md5 n sha1 of the complete directory.  (similarly base64 is also there)
  1. Sort command is also being used to sort multiple filenames. Uniq is also used with sort to generate unique file name.
  2. Mktemp is a command to create a temp file in the /tmp directory. Use (-d) to create a temp directory.
  1. split command is used to break a file in multiple chunks. E.g. split -b 100k data.file  :It will break the chunks in 100K.
  1. Csplit is an extended command of split that is used to split files based upon certain conditions (like presence of text etc).
  2. rename is the command which is used to rename the files from one to anther and you can use WILDCARD character.
  3. /usr/share/dict directory contain the dictionary. Aspell is the command used to find any word there.
  4. dd is a command available through which you can generate large size files like 100M etc.
  1. /dev/zero is a special character device, which infinitely returns the zero byte (\0).
  1. comm is a command available through which we can generate the differences between two files.
  1. Chmod is the command which is used the change the file permissions for user/groups/others
    E.g.
    chmod u=rwx g=rw o=r filename
  2. chown command is use to change the ownership of the files. The format is : chown user.group filename
  3. /etc/resolv.conf is the file that contains the list of DNS Servers.
  4. chattr is the command which is used to make the file immutable. E.g. chattr +I fileName  (you even can't delete it, use -I to reverse this).
  1. touch command is used to create the new file or modify the timestamp of the file to the current timestamp.
  1. Symbolic  links are being created by  "ln -s  targetFileName  symbolic_link_name"
  1. File command is being used to tell the type of file. E.g "file abc.sh"
  1. Loopback files can be used to create a file system out of a single file. You can mount the file at a specific mount point.  See details in the LINUX shell Scripting Cookbook for details. Page no 124. You can also create the partition inside loopback images and mount it separately. You can also mount ISO files as loopback files.
  1. /dev/zero is a file which will always contain zero, if you read from it.
  1. cdrecord command is used to create an ISO into a CD-ROM.
  1. Diff command is used to find the difference between two files/directories. A host of options are there, through which you can customize the output.
  2. pushd and popd commands are being used to push a specific directory to the stack and then do a CD into it automatically. Dirs is the command that can be used to find the appropriate number of directories in the stack.
  3. wc is the command which is used to count the number of lines/words/characters from a text file.
  4. tree is the command use to print the complete tree of the complete file system. It does not come bydefault, you have to use it.
  5. Grep is the command used to search a test across multiple files. E.g. grep "pattern" file1 file2. egrep is just an extended version of grep command with extended regular expresstions. Its same as "grep -E" Option. -o option is used to print only that line which match the pattern. "-c" is used to count. "-n" prints the line number.  "-R" recursively search over a directory. "-I" ignoring the case. Use  "-e" if there are multiple patterns to match with.  "--include" option is being used to match the files that needs to be included in the search. --include *.{c,cpp} . "--exclude" is used for exclusion of files. "-q" is being used for quiet output, then you can use return status of the command to check whether there are any matches or not.
  6. cut is the command which is used to cut the text in a columnar fashion.
  1. sed is being used for text replacements. E.g. sed 's/pattern/replace_string/' file. Use -I option to save the changes int eh file after replacements.  Awk is used for advanced text processing.
  1. wget is a command which is used to download a file from the internet.
  1. Lynx is a command available through which you can get the TEXT content of  a webpage.
  2. Curl command used to hit a web page/API and get response. "--cookie" option is used to specify cookies. --cookie "user=ram;a=b". -H is being used to specify headers. curl -H "Host: www.slynux.org" -H "Accept-language: en" URL. -I/-head option to show only response headers.
  3. tar -cvf output.tar file1 file2 file3 file4 file5  -> To compress all the files in an tar file
    tar -xf output.tar  -C /path/to/extractdirectory -> To uncompress all the files.
  4. gzip is used to zip a file while gunzip is used to unzip the files. Similarly zip/unzip (-r is being used for recursively).
  5. rsync is the command to keep in sync two files/directories E.g. rsync -av /opt/jboss/data slynux@192.168.0.6:/home/backups/data
  1. To add a scheduler in linux, add a CRON expression based entry in CRONTAB file
  1. Ifconfig is the command used to show the network interfaces. This command is used to set the static IP address on a specific network interface. ifconfig wlan0 192.168.0.80 netmask 255.255.255.0. To automatically get the IP from the DHCP use "dhclient eth0"
  2. Route, host, nslookup , traceroute ( show all hops to the destination).
  3. lsof -I & netstat are being used for port analysis.
  4. Df (disk free)/ du (disk usage) . du -a directory : lists size of all files and then of complete directory. Du -c : shows all count sum of all files.         --exclude is used to exclude some file/directory for there usage calculation.
  1. time command can be used to measure the amount of time taken by the command. E.g. "time ls -la" . In addtion, this command can be used to find exit status, number of signals received, number of context switches made etc.
  1. Users Details: who/w/users/last/

  1. logrotate is the command which is useful to configure the log rotation of various files in any directory of the file system. The configuration directory for every process is in /etc/logrotate.d
  2. Fsck is the comman for file system scan. E.g. fsck /dev/sdb0. /etc/fstab is the file containing all the file systems.
  3. Wall is a command which is used to write a message to all the terminals of all the users who are logged in the system.
  4. Gathering system information:  hostname/uname -n/uname -a/ uname -r/uname -m
  5. cat /proc/cpuinfo; cat /proc/meminfo/ , cat /proc/partitions; use lshw to get the info about complete file system.

Thursday, September 25, 2014

Docker Summarized Overview - 5 mins food for Geeks

Docker:
From a long time, i was quite fascinated by the way docker works and unfortunately i dint get a part of it, why the hell it can't run with windows directly (without installing boot2docker). This really challenges me to learn it from upside down and i embark my Journey to a great component called LXC in Linux. Believe me, you would understand DOCKER very easily if you know how LXC worked. Finally, i got to know DOCKER is just a way of managing your dockers in a better manner with some cherries on the cake like repository etc.

Here are my summarized notes, that anyone can learn from. I tried to keep them crisp and short. It is for just giving DOCKER a try and at least have a spoonfull of the dish.

Docker installation:
$ sudo apt-get update
$ sudo apt
-get install docker.io
$ sudo ln
-sf /usr/bin/docker.io /usr/local/bin/docker
$ sudo sed
-i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io


Sudo docker search ubuntu  -> search for keyword docker
Sodu docker pull ubuntu -> to Pull all ubuntu images from Docker
Sudo docker images -> show the list of all images
sudo docker run -i -t ubuntu /bin/bash  -> running  the bash sheel correctly

# Start a new container
JOB=$(sudo docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done")
-> After above command, the container will start and u have to press Ctrl-C to come out of it and then have to you docker ps  to see it is running.
# Stop the container
docker stop $JOB
# Start the container
docker start $JOB
# Restart the container
docker restart $JOB
# SIGKILL a container
docker kill $JOB
# Remove a container
docker stop $JOB # Container must be stopped to remove it
docker rm $JOB

Installation of Shipyard. ->
Installation of apache/nginx ->
  1. sudo docker run -i -t -p 80:80 ubuntu /bin/bash  
    NOw you will be entered in the shell. Press CTRL-P & CTRL-Q aftewards to come out of the shell
  2. Sudo docker ps
    THis will list the container ID of the process
  1. Sudo docker attach 3edaace90360  
    This will take you to the shell.
  2. Sudo apt-get update
    As the image you have download is older one, so you will need to update the package list.
  3. sudo apt-get install apache2
    This will install the apache on the system.
  4. Sudo service apache2 start
  5. Sudo apt-get install curl
  6. Curl http://localhost 
    It will show the complete  Apache Page.

 sudo docker commit 3edaace90360 panbhatt/pankaj_ubuntu_apache
This will store all the changes in that container by this name
Sudo docker images
It will list the image that is just created with the name same.
Sudo docker login
This will prompt for the docker username and password.
sudo docker push panbhatt/ubuntu-apache
This will push the image to the docker repository
Sudo docker inspect 3edaace90360
This will list the complete setting of the container (e.g. the network ports being exposed).
sudo docker port  3edaace90360 80
This will show whether the port 80 is being used by the container or not

You can also establish the LINKING Between the server, see section 2.3.1 of Docker documentation

Networking
sudo apt-get install bridge-utils   (to install brtcl on ubuntu)
Sudo brctl show  (see networking for Ubuntu, how docker establish the DOCKER brdige)
Sudo ifconfig docker0 -> To see the details of the bridge. The set of IP addres to be given to continers
You can also control the list of IP addresses need to be given to the docker.  2.4 section
Docker can also provide a functionality to allow communication between the various contains, by using   -icc parameter which can be set true/false in the bridge configuration.

Pipework project is an great work at Github to connect multiple  containers

You can always make sure that your containers are running with process managers like systemD, upstart & supervisor . Check docker documentation for 2.5 for this.

Shared director or VOLUME is the best way to share the directories from one container to another, (even if the source container is not working at all).
You can also mount a HOST directory to an container too. This will allow it to use any available configuration or properties directory to the host system.

DockerFile
  1. Touch Dockerfile
  2. Write the following contents, see documentation for greater detail.
     
# DOCKER-VERSION 1.0.1
FROM ubuntu:14.10

RUN sudo apt-get update

RUN sudo apt-get install -y nginx

RUN sudo apt-get install -y curl

RUN sudo service nginx restart

EXPOSE 80

  1. Build the image by running the following command
    sudo docker build -t panbhatt/ubuntu_nginx_df .
    if it says -> "
    Successfully built fc09cc5af0c5"
    use "sudo docker images" to see your name of this VM is there.
  2. Now Run this image:
    sudo docker run -i -p 8000:80  -t panbhatt/ubuntu_nginx_df /bin/bash
    Now attach yourself to this and enjoy.


Wednesday, July 16, 2014

Java Currency Detail via Locale and Currency Code

Sometimes, while developing our API's we need to give the currency details while formatting a currency. The details of the currency are like what Symbol to use, did we have a separator, what is the number of decimal places, should we place the symbol before or after the formatted number.

This can easily be achieved by using Java API's rather then storing it in the database. Here is the java code that generates all these details. It would be very much helpful if we want to return this information in the API related to currency.

// Source Code

            Locale locale = new Locale("ja", "JP");
            Currency currency = Currency.getInstance("JPY");
            boolean bPre = false;
            int ndx = -1;
            double price = 12345.67;
           
            DecimalFormatSymbols df = DecimalFormatSymbols.getInstance(locale)  ;
            df.setCurrency(currency);
            NumberFormat nF = NumberFormat.getCurrencyInstance(locale);
            nF.setCurrency(currency);
            System.out.println("CURRENCY SYMBOL   = " + df.getCurrencySymbol());
            System.out.println("DECIMAL SEPARATOR = " + df.getDecimalSeparator());
            System.out.println("GROUP SEPARATOR   = " + df.getGroupingSeparator());
            System.out.println("CURRENCY CODE     = " + df.getInternationalCurrencySymbol());
            System.out.println("DECIMAL PLACE     = " + nF.getMaximumFractionDigits());
            String sLP = ((DecimalFormat) nF).toLocalizedPattern();
            ndx = sLP.indexOf('\u00A4');  // currency sign
           
            if (ndx > 0) {
                bPre = false;
            } else {
                bPre = true;
            }
           
            System.out.println("CURRENCY PLACE BEFORE    = " + bPre);
            System.out.println("FORMATTED CURRENCY: " + nF.format(price));

// Output
//For vi_VN Locale and VND currency code.

CURRENCY SYMBOL   = đ
DECIMAL SEPARATOR = ,
GROUP SEPARATOR   = .
CURRENCY CODE     = VND
DECIMAL PLACE     = 0
CURRENCY PLACE BEFORE    = false
FORMATTER CURRENCY: 12.346 đ

// For India Locale    hi_IN and INR Currency Code
CURRENCY SYMBOL   = रू
DECIMAL SEPARATOR = .
GROUP SEPARATOR   = ,
CURRENCY CODE     = INR
DECIMAL PLACE     = 2
CURRENCY PLACE BEFORE    = trueFORMATTED CURRENCY: रू १२,३४५.६७

// For JAPAN Locale    ja_JP and JPY Currency Code
CURRENCY SYMBOL   =
DECIMAL SEPARATOR = .
GROUP SEPARATOR   = ,
CURRENCY CODE     = JPY
DECIMAL PLACE     = 0
CURRENCY PLACE BEFORE    = true

FORMATTED CURRENCY: 12,346