Saturday, March 21, 2015

Sample Configuration in Leshan. Through Sthana-core or Local Leshan







**************
\"edu.mit.media.funf.probe.builtin.SimpleLocationProbe\",\n\t                 \"@schedule\": {\"interval\": 60, \"duration\" : 10
- It shows that Client will try finding location probe using mobile hardware after each '60' secs.
- and only for first 10 secs, it will check.
then next call will be made after 60 secs (interval)

How to verify this:
- check in LogCat in Android Studio with filter like 'sthana' or 'funf'
- Register with Leshan and push configuration, check 'connect'/'reconnect'


Sample JSON configuration to Push for all registered clients:

{
   "userPreferedCategorys":[
      {
         "name":"Thai",
         "parentCategory":{
            "name":"FOOD",
            "id":1
         },
         "id":2
      },
      {
         "name":"FOOD",
         "id":1
      }
   ],
   "funfConfiguration":{
      "pipelineConfigJson":"{\"@type\":\"edu.mit.media.funf.pipeline.BasicPipeline\",\n         \"name\":\"default\",\n         \"version\":1,\n         \"data\": [\n\t                 {\"@type\": \"edu.mit.media.funf.probe.builtin.SimpleLocationProbe\",\n\t                 \"@schedule\": {\"interval\": 60, \"duration\" : 10,  \"strict\": true}\n\t                 },\n\t                 {\"@type\": \"edu.mit.media.funf.probe.builtin.AndroidInfoProbe\"\n\t                 },\n\t                 {\"@type\": \"edu.mit.media.funf.probe.builtin.HardwareInfoProbe\"\n\t                 },\n\t                 {\"@type\": \"edu.mit.media.funf.probe.builtin.BluetoothBeaconProbe\",\n\t                 \"@schedule\": {\"interval\": 60, \"duration\" : 20,  \"strict\": true},\n\t                 \"vendorConfig\": [{ \"uuid\" : \"bbbb2222-2222-2222-2222-222222222222\",\"major\":1, \"minor\":2, \"vendorName\": \"estemeto\",\"layout\": {\"m\": \"2-3+0215\",\"i\":[\"4-19\",\"20-21\",\"22-23\"],\"p\": \"24-24\",\"d\": []}}]\n\t                 }\n                ]\n        }"
   }
}

*****************************************************







Monday, March 16, 2015

Sample Notification. It uses new Image server


Deploy WAR for sthana-core server on EC2.

- Hit sthana core server by URL: http://52.1.153.252:8080/sthana-core-1.0/#/clients

- Leshan page with 'Client' shows.
- Enter this server IP into sthana client App > Settings > OK
- It should show mobile client as 'Registered' in Leshan page.
- click on client ID.
- Click on 'Observe' in Device section. (to verify the device)
- Go to Notification section, click 'Write' and jump to sample JSON.


---------------Alternate Local JAR running method if Core server not working------------------

- Run Leshan from D:\sthana\leshan\leshan-standalone\target
with $ Java -java leshan-standalone-0.1.10-SNAPSHOT-jar-with-dependencies.jar

- Hit Leshan server in browser with: http://54.85.77.102:8080/#/clients/
- If leshan throw some error, check 8080 port is free to run on.
--------------------------------------------------------------------------------------------------------------------

Enter Sample notification in Notification section: Change vendor ID always, because limit is set yet for each vendor.

{
   "vendorId":2,
   "contentTitle":"Welcome Shedd Aquarium",
   "contentText":"Welcome Shedd Aquarium",
   "smallIconPath":"http://ec2-52-0-157-177.compute-1.amazonaws.com/unsafe/300x200/http://64.17.140.53/wp-content/uploads/2014/01/shedd-aquarium.jpg",
   "largeIconPath":"http://ec2-52-0-157-177.compute-1.amazonaws.com/unsafe/300x200/https://totravelornot.files.wordpress.com/2013/12/012.jpg",
   "vendorPhone":"3129392438",
   "vendorLocation":{
      "name":"1200",
      "street":"South Lake Shore Drive",
      "city":"Chicago",
      "zip":"60605",
      "state":"IL",
      "country":"USA",
      "coordinates":{
         "latitude":41.8678,
         "longitude":-87.6139
      },
      "distance":0,
      "id":2
   },
   "product":{
      "upc":"999999",
      "name":"Chicago CityPASS ",
      "modelNumber":"",
      "manufacturere":"",
      "longProductDescription":"Chicago CityPASS includes priority entry to Shedd Aquarium",
      "shortDescription":"Chicago CityPASS includes priority entry to Shedd Aquarium",
      "deals":[
         {
            "dealName":"Save 50% off Chicago’s 5 best attractions",
            "dealImage":"Deal Image",
            "promoCode":"e74d77f5-0a29-4325-bf35-770b3fe7b274",
            "id":2
         },
         {
            "dealName":"Save 50% off Chicago’s 5 best attractions",
            "dealImage":"Deal Image",
            "promoCode":"e74d77f5-0a29-4325-bf35-770b3fe7b274",
            "id":2
         }
      ],
      "categories":[
         {
            "name":"Recreation",
            "subCategories":[

            ],
            "id":2
         }
      ],
      "images":[
         {
            "imageFilePath":"http://ec2-52-0-157-177.compute-1.amazonaws.com/unsafe/300x200/http://famouswonders.com/wp-content/uploads/2013/09/Shedd-Aquarium.jpg",
            "imageType":"PNG",
            "imageView":"LEFT",
            "id":3
         },
         {
            "imageFilePath":"http://ec2-52-0-157-177.compute-1.amazonaws.com/unsafe/300x200/http://www.danleysoundlabs.com/danley/wp-content/uploads/2012/07/shedd-aquarium.jpg",
            "imageType":"JPEG",
            "imageView":"FRONT",
            "id":4
         }
      ],
      "id":2
   }
}





Configuring Ubuntu with the Desktop Environment and VNC Server





Now you can install the desktop packages and remote desktop (VNC) server by entering (or copying and pasting) the following commands one at a time:
sudo apt-get update
sudo apt-get install ubuntu-desktop
sudo apt-get install vnc4server

Now, to configure the VNC server enter vncserver, which will then prompt you to create a password. Once created, entervncserver -kill :1 to stop the server.

Next, configure the VNC xstartup file so you'll see the desktop when connecting via VNC. Enter vim .vnc/xstartup.
Then hit the Insert key, scroll around the text file with the keyboard arrows, and delete the pound (#) sign from the beginning of the two lines under the line that says "Uncomment the following two lines for normal desktop." And on the second line add "sh" so the line reads exec sh /etc/X11/xinit/xinitrc. When you're done, hit Ctrl + C on the keyboard, type :wq and hit Enter.
Now you can start the VNC server again by entering vncserver. And remember, you must enter this again at every reboot if you want VNC access, or consider configuring it to automatically run at startup.

Connecting to the Ubuntu Instance via VNC

Now that you have Ubuntu set up, you need to install a VNC client (like TightVNC) on your local machine, and when connecting enter the following address:
127.0.0.1:9000
When connecting via that address you must first connect to the server via SSH (like with PuTTY) and then connect with the VNC client.
If you prefer to connect directly to your Ubuntu instance via VNC rather than having to SSH into it first, you can use the Public DNS address (from the AWS Instances page of your instance) followed by a colon and the number one, such as ec2-184-169-226-14.us-west-1.compute.amazonaws.com:1.
Or you could even create an elastic IP and associate it with your Ubuntu instance, which you could then use (also with the colon and 1) to connect via VNC. But remember when connecting directly via VNC, it isn't as secure and you must open port 5901 up on the firewall via the Security Groups page.

Connect using: ec2-184-169-226-14.us-west-1.compute.amazonaws.com:1

PostgreSQL install and creating DB in ubuntu


https://help.ubuntu.com/community/PostgreSQL

Installation

To install use the command line and type:
 sudo apt-get install postgresql postgresql-contrib
This will install the latest version available in your Ubuntu release and the commonly used add-ons for it.
See "External Links" below for options for getting newer releases.

Installing PostGIS, procedural languages, client interfaces, etc

Additional packages contain procedural language runtimes, add-ons like PostGIS, language client interfaces like psycopg2 for Python, etc. You can get a listing with:
 apt-cache search postgres

Administration

pgAdmin III is a handy GUI for PostgreSQL, it is essential to beginners. To install it, type at the command line:
 sudo apt-get install pgadmin3
You may also use the Synaptic package manager from the System>Administration menu to install these packages.

Basic Server Setup

To start off, we need to change the PostgreSQL postgres user password; we will not be able to access the server otherwise. As the “postgres” Linux user, we will execute the psql command.
In a terminal, type:
sudo -u postgres psql postgres
Set a password for the "postgres" database role using the command:
\password postgres
and give your password when prompted. The password text will be hidden from the console for security purposes.
Type Control+D to exit the posgreSQL prompt.

Create database

To create the first database, which we will call "mydb", simply type:
sudo -u postgres createdb mydb

Using pgAdmin III GUI

To get an idea of what PostgreSQL can do, you may start by firing up a graphical client. In a terminal type :
 pgadmin3
You will be presented with the pgAdmin III interface. Click on the "Add a connection to a server" button (top left). In the new dialog, enter the address 127.0.0.1 (Local host is default, so it can be left out.), a description of the server, the default database ("mydb" in the example above), your username ("postgres") and your password. One more step is required in order to allow pgAdmin III to connect to the server, and that is to edit pg_hba.conf file and change the authentication method from peer to md5 (Will not work if you have not set the password.):
sudo nano /etc/postgresql/9.3/main/pg_hba.conf
and change the line 
# Database administrative login by Unix domain socket
local   all             all                                peer
to
# Database administrative login by Unix domain socket
local   all             all                     md5

***************OR
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all  127.0.0.1/32  md5
# IPv6 local connections:
host all all ::1/128 md5
*****************

Now you should reload the server configuration changes and connect pgAdmin III to your PostgreSQL database server.
sudo /etc/init.d/postgresql reload
With this GUI you may start creating and managing databases, query the database, execute SQl etc.
----------------------------------------------------------------------

Check whether Postgres is running or not !


ubuntu@ip-172-31-48-240:~$ service postgresql status
9.3/main (port 5432): online

Restarting PostgreSQL Server

To start PostgreSQL server, run:

sudo -u postgres /etc/init.d/postgresql (or /etc/init.d/postgresql8) stop/start

Sunday, March 15, 2015

Deployment of sthana server on EC2



Deployment of Sthana-vendor on EC2.
(We should have EC2 instance should be ready/running with all packages. Check: EC2 setup)

Sthana-vendor:

  1. From your machine, build a WAR from the code.
  2. windows machines, cd to from D:\sthana\sthana\src\sthana\sthana-vendor
  3. $gradle build
  4. check war file under D:\sthana\sthana\src\sthana\sthana-vendor\build\libs [there should be war file available if build is successful]
  5. Hit URL: http://<serverIP>:8080/manager/html [in my case http://52.0.157.177:8080/manager/html] Enter <user username="sthana" password="S*****!***" which can be found on tomcat-users.xml
  6. To deploy another version of WAR, Stop > Undeploy in section /sthana-vendor-1.0 OR if you are deploying 1st time then simply select WAR.
  7. Select WAR file to upload > Upload
  8. To connect with putty: ubuntu@52.0.157.177 with ppk key [set ppk in Connection > SSH > Auth]
Check health of server : http://52.0.157.177:8080/sthana-vendor-1.0/health

~/leshan/leshan-standalone$ java -jar target/leshan-stan-*-SNAPSHOT-jar-with-dependencies.jar
--------------------------------

Sthana-core:

  1. From your machine, build a WAR from the code.
  2. windows machines, cd to from build war from D:\sthana\sthana\src\sthana\sthana-core
  3. $gradle build
  4. check war file under D:\sthana\sthana\src\sthana\sthana-core\build\libs [there should be war file available if build is successful]
  5. Hit URL: http://<serverIP>:8080/manager/html [in my case http://54.88.185.161:8080/manager/html] Enter <user username="sthana" password="S*****!***" which can be found on tomcat-users.xml
  6. To deploy another version of WAR, Stop > Undeploy in section /sthana-core-1.0 OR if you are deploying 1st time then simply select WAR.
  7. Select WAR file to upload > Upload
  8. To connect with putty: ubuntu@54.88.185.161 with ppk key [set ppk in Connection > SSH > Auth]
Check health of server : http://52.0.157.177:8080/sthana-core-1.0/health


~/leshan/leshan-standalone$ java -jar target/leshan-stan-*-SNAPSHOT-jar-with-dependencies.jar

How to make New Instance on Amazon- EC2

How to make New Instance on Amazon- EC2:

1. Hit URL:  http://aws.amazon.com/console/
2. 'Sign in to console' and if you have login Id, Login to it.
3. Go to EC2.
4. Select Instances at left hand side and follow steps.

  • click on launch instance.
  • Step 1: Choose an Amazon Machine Image (AMI). Select Ubuntu Server 14.04 LTS (HVM), SSD Volume Type - ami-9a562df2
  • Step 2: Choose an Instance Type. Select General Purpose.
  • Click on Review Instance Launch button.
  • Step 7: Review Instance Launch,  Edit Security Group.
  • Select an existing security group and select 'default' Group. (default VPC security group)
  • Click Launch to assign a key pair to your instance and complete the launch process
  • Select Existing key pair (i have selected imageS) or create new pair.
5. Launch Instances.
     


Deployment Tomcat/Webserver on EC2

Deploy server on EC2:

1. Preliminary Note

This tutorial is based on Ubuntu 14.04 server, so you should set up a basic Ubuntu 14.04 server installation before you continue with this tutorial. The system should have a static IP address. I use 192.168.0.100 as my IP address in this tutorial and server1.example.com as the hostname.

[to know how to create instance on EC2, go to: HERE]

2. Installation

To start the installation of Tomcat we need to first install java-1.7.0-openjdk, we will install it as follows:
apt-get install default-jdk

Check the version of java as follows:
java -version

root@server1:~# java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.1) (7u65-2.5.1-4ubuntu1~0.14.04.2)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
root@server1:~#
Proceeding further we need some essential packages:
apt-get install unzip wget

Now we will download the latest Tomcat version from its home page and install it as:
cd /opt
wget http://ftp.nluug.nl/internet/apache/tomcat/tomcat-8/v8.0.9/bin/apache-tomcat-8.0.9.zip
unzip apache-tomcat-8.0.9.zip
mv apache-tomcat-8.0.9 tomcat

Configure .bashrc:
vi ~/.bashrc

[...]
export JAVA_HOME=/usr/lib/jvm/default-java/
export CATALINA_HOME=/opt/tomcat/
Restart the bash, to make the changes affective as:
. ~/.bashrc

Again before starting Tomcat service, we will provide executable permissions to following files:
chmod +x $CATALINA_HOME/bin/startup.sh
chmod +x $CATALINA_HOME/bin/shutdown.sh
chmod +x $CATALINA_HOME/bin/catalina.sh

Now we need to start Tomcat service by using:
$CATALINA_HOME/bin/startup.sh

root@server1:~# $CATALINA_HOME/bin/startup.sh
Using CATALINA_BASE:   /opt/tomcat/
Using CATALINA_HOME:   /opt/tomcat/
Using CATALINA_TMPDIR: /opt/tomcat//temp
Using JRE_HOME:        /usr/lib/jvm/default-java/
Using CLASSPATH:       /opt/tomcat//bin/bootstrap.jar:/opt/tomcat//bin/tomcat-juli.jar
Tomcat started.
root@server1:~#
It will start the Tomcat server, we can also check by using:
netstat -an | grep 8080

[root@server1 ~]# netstat -an | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN  
[root@server1 ~]#
Now we need to setup the user account. Finally we need to create user accounts to secure and access admin/manager pages. Edit conf/tomcat-users.xml file in your editor and paste inside <tomcat-users> </tomcat-users> tags
vi  $CATALINA_HOME/conf/tomcat-users.xml


[...]
<!--
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  <!.. ..> that surrounds them.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
-->
 <role rolename="manager-gui"/>
 <role rolename="manager-script"/>
 <role rolename="manager-jmx"/>
 <role rolename="manager-status"/>
 <role rolename="admin-gui"/>
 <role rolename="admin-script"/>
 <user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>
</tomcat-users>
In above configuration I have used username=admin and password=admin, you can make the changes as per your choice. Then we need to stop/start the Tomcat service
cd $CATALINA_HOME
./bin/catalina.sh stop

[root@server1 tomcat]# ./bin/catalina.sh stop
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
[root@server1 tomcat]#
Then start the service:
./bin/catalina.sh start

[root@server1 tomcat]# ./bin/catalina.sh start
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@server1 tomcat]#
Now access the page for login at http://192.68.0.100:8080

-----------------------------------------------------------------------------------

  • To Start server: <Tomcat Root>/bin>startup.sh
  • To Stop server: <Tomcat Root>/bin>shutdown.sh