Tuesday, August 20, 2013

Hadoop implementation(setup) with window 7 using CYGWIN

 I'll just show how to configure Hadoop on a single window in pseudo distributed mode.


Versions used :

1- window 7 with CYGWIN
2- Java (Oracle java-1.6)
3- Hadoop (Apache hadoop-1.0.3)

If you have everything in place, start following the steps shown below to configure Hadoop on your machine :

1) For install cygwin properly follow the link :
3) Extract hadoop 1.0.3 inside cygwin ( c:\cygwin\usr\local\hadoop-1.0.3
4) Now open and edit  hadoop-env.sh using path C:\cygwin\usr\local\hadoop-1.0.3\conf  and change java    path according to environment path(NOTE : Before change in java path first set java path in environment variable)
  export JAVA_HOME=C:\\Java\\jre1.6.0
Than go to cygwin terminal and check:

5)Now ,we ll start with the actual configuration process. Hadoop is configured using a set of configuration files present inside the HADOOP_HOME/conf directory. These are xml files having a set of properties in form of key value pairs.We'll modify the following 3 files for our setup.

Edit in mapred-site
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
 <name>mapred.job.tracker</name>
 <value>localhost:9001</value>
</property>
</configuration>

Edit in hdfs-site
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
 <name>dfs.replication</name>
 <value>1</value>
</property>
 </configuration>

Edit in core-site 
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
 <property>
 <name>fs.default.name</name>
 <value>hdfs://localhost:9000</value>
</property>
</configuration>

save all files and close.

6)To format the filesystem, enter the following command in cygwin:
 bin/hadoop namenode -format


7) Now type command  bin/start-dfs.sh 
8) and than bin/start-mapred.sh
ar in palce of therse command we can type bin/start-all.sh (deprecated)

9) Check logs inside C:\cygwin\usr\local\hadoop-1.0.3\logs

10) After check log findout particular ips than check and get output like that
 if these screen show successfully than we ask hadoop configure properly.

Client bundle using gwt

Paste this : project.gwt.xml
 <inherits name="com.google.gwt.resources.Resources" />

For image ,textfile and pdf

1)create  a folder image in workspace  client folder(with some image) sameas create text folder and paste any .txt file and last create a pdf folder and any pd f paste in folder

2) go to client folder in ide than click new and select client bundle .

3)clientbundle.java

package com.ruchi.bundle.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ClientBundle implements EntryPoint {
/**
 * The message displayed to the user when the server cannot be reached or
 * returns an error.
 */
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";

/**
 * Create a remote service proxy to talk to the server-side Greeting service.
 */

/**
 * This is the entry point method.
 */
public void onModuleLoad() {
  Grid grid = new Grid(5, 5);
        grid.setBorderWidth(1);

        int numRows = grid.getRowCount();
        int numColumns = grid.getColumnCount();
        for (int row = 0; row < numRows; row++)
        {
          for (int col = 0; col < numColumns; col++)
          {
              grid.setWidget(row, col, new Image(Resource.INSTANCE.alpha1()));
            
          }
        }

        RootPanel.get().add(grid);
      //  Window.alert(Resource.INSTANCE.ruchi().getText());
      
        AbsolutePanel abs=new AbsolutePanel();
        abs.setSize("500px","400px");
      
        TextArea myTextArea=new TextArea();
        myTextArea.setSize("400px","300px");
        abs.add(myTextArea);
      
        myTextArea.setText(Resource.INSTANCE.ruchi().getText());
        RootPanel.get().add(abs);
      
        HorizontalPanel hrzz=new HorizontalPanel();
        hrzz.setSize("1000px", "500px");
        Frame f=new Frame(Resource.INSTANCE.taxUpdatesForJune2012Exams().getUrl());
        f.setSize("1000px", "500px");
        hrzz.add(f);
        RootPanel.get().add(hrzz);
      
    }
}


4) Resource.java

package com.ruchi.bundle.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.DataResource;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.resources.client.TextResource;
import com.google.gwt.resources.client.ClientBundle.Source;

public interface Resource extends ClientBundle {
public static final Resource INSTANCE =GWT.create(Resource.class);
@Source("com/ruchi/bundle/images/alpha1.jpg")
ImageResource alpha1();
@Source("com/ruchi/bundle/text/ruchi.txt")
public TextResource ruchi();
@Source("com/ruchi/bundle/pdf/Tax updates for June 2012 Exams.pdf")
DataResource taxUpdatesForJune2012Exams();

@Source("com/ruchi/bundle/images/Back.gif")
ImageResource back();

@Source("com/ruchi/bundle/images/joinus.gif")
ImageResource joinus();

@Source("com/ruchi/bundle/images/next.gif")
ImageResource next();

}

Fetch system time using gwt

SYSTEM TIME 

package com.client;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.shared.FieldVerifier;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class systemtime implements EntryPoint {
  
  
  private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {

      
      Date date = new Date();
      int Month = date.getMonth();
      int Day = date.getDate();
      int Year = date.getYear();
      int Hour = date.getHours();
      int min = date.getMinutes();
      int sec = date.getSeconds();
      int tz = date.getTimezoneOffset();
      int UnixTimeStamp = (int) (date.getTime() * .001);

      //get unix time stamp example (seconds)
      Long lTimeStamp = date.getTime(); //time in milleseconds since the epoch
      int iTimeStamp = (int) (lTimeStamp * .001); //(Cast) to Int from Long, Seconds since epoch
      String sTimeStamp = Integer.toString(iTimeStamp); //seconds to string

      //get the gmt date - will show tz offset in string in browser, not eclipse debug window
      String TheDate = date.toString();

      //render date to root panel in gwt
      Label label = new Label(TheDate);
      RootPanel.get().add(label);
      
      
  }
}

Creating toolbar and fetch image

tlbrbtnChemisrty = new ToolbarButton("CHEMISRTY DIAGRAMS\r\n");
       tlbrbtnChemisrty.addListener(new ButtonListenerAdapter() {
            @Override
            public void onClick(com.gwtext.client.widgets.Button button, EventObject e) {
            
                chem=new Toolbar();
                
                
                chem.setAutoWidth(false);
                absolutePanel_1.add(chem, 15, 132);
                
                chem.setSize("850px", "35px");

                 textBoxchem = new TextBox();
                    absolutePanel.add(textBoxchem, 74, 128);
                 periodic=new ToolbarButton();
                
                 periodic.setText("View Periodic Table");
                 periodic.setTooltip("Periodic Table");
                 periodic.setCls("a");
                 periodic.setToggleGroup("");
                 periodic.setIcon("");
                    chem.addButton(periodic);
                    periodic.setSize("34px", "35px");
                    periodic.addListener(new ButtonListenerAdapter() {
                        @Override
                        public void onClick(com.gwtext.client.widgets.Button button, EventObject e) {
                        
                             funperiodic();
                            
                            
                        
                        }
                    });


                    insertimage=new ToolbarButton();
                    insertimage.setText("Insert image");
                    insertimage.setTooltip("insert image");
                    insertimage.setToggleGroup("");
                    insertimage.setIcon("");

                    chem.addButton(insertimage);
                    insertimage.setCls("italic:hover");
                    insertimage.addListener(new ButtonListenerAdapter() {
                        @Override
                        public void onClick(com.gwtext.client.widgets.Button button, EventObject e) {
                        
                        
                            sschem=textBoxchem.getText();
                            System.out.println(sschem);
                            
                        
                            
                         s1chem=richTextArea.getText();
                         fun(sschem);
                        
                                flagchem=true;

                        }
                    });

                    getimage=new ToolbarButton();
                    getimage.setText("Get image");
                    getimage.setTooltip("Get image");
                    getimage.setToggleGroup("");
                    getimage.setIcon("");
                    chem.addButton(getimage);
                    getimage.setCls("under:hover");

                    getimage.addListener(new ButtonListenerAdapter() {
                        @Override
                        public void onClick(com.gwtext.client.widgets.Button button, EventObject e) {
                        
                            if(flagchem==true)
                             {

                                 richTextArea.getExtendedFormatter().insertImage("http://localhost:8082/image2.php?name="+sschem+"");
                        
                             }
                            
                            
                        
                        }
                    });

                    
                    panel.add(absolutePanel,84,267);
            }
        });

        toolbar.addButton(tlbrbtnChemisrty);
        toolbar.addSeparator();

Converting Text into array and creating Combined image(Text + image)

  
               public String path(String text,String id) {
         
                String query;

                BufferedImage image;
                OutputStream targetFile1;
                //Image image1;
                byte[] buf=new byte[1024];


                byte[] fileBytes;
                ResultSet rs;
                int i;
                char a[]=text.toCharArray();  
                int t= text.length();
                System.out.println("i is"+t);
                float x=t/40;
                double value=Math.ceil(x);
                int val=(int)value;
                String [] str=new String[val+1];
                int len=0;
                int k=0,j;
                char [] temp={' '};
                StringBuffer strbuf;
                
                
                
                for( i=1;i<=val;i++)
                {
                    //System.out.println("print value"+i);
                   for(j=40*(i-1);j<t;j++)
                   {
                
                if(j==40*i)
                {
                    for( k=40*i;k>40*(i-1);k--)
                    {
                        
                        
                        
                        if(a[k]==(char)(32))
                        {
                            
                            //System.out.println("k is"+k);
                            
                            break;
                        }
                    }
                    //System.out.println("len  is........"+len);
                    strbuf =new StringBuffer();
                    for(int l=len;l<k;l++)
                    {

                        //System.out.println("print"+a[l]);
   
                          strbuf.append(a[l]);
          
                    }
                    //System.out.println("a39 is..."+a[39]);
                    //System.out.println("a39 is"+a[40]);
                    //System.out.println("print stringbuffer"+strbuf); 
                       
                len=k;
                
                
                       String s=new String();
                    s=strbuf.toString();
                       //System.out.println("print karo"+s);
                        str[i-1]=s;
                        //System.out.println(str[i-1]+"check");
                    
                    strbuf=null;
                    break;
                    
                
                }
            
                
                
                   }   
                   
                //System.out.println(j+"welcome to all");
                }
                
                
               strbuf =new StringBuffer();
                System.out.println("what is val-1"+val);
                for(int last=k;last<t;last++)
                {
                    strbuf.append(a[last]);
                    //System.out.print("ye h ........"+a[last]);
                }

                   String s=new String();
                s=strbuf.toString();
                   System.out.println("print karo"+s);
                    str[val]=s;
                    
                    //System.out.println(str[i-1]+"check");
                
                strbuf=null;

                for(int extra=0;extra<=val;extra++)
                {
                    System.out.println("hello ji kya hua "+str[extra]+"\n");
                }
                
                try
                {

                    connect();
                        query = "select image from save1";


                        rs= st.executeQuery(query);
                        if (rs.next())
                       {
                            System.out.println("hello");
                                 fileBytes = rs.getBytes("image");
                                 OutputStream targetFile=  
                                 new FileOutputStream(
                                      "d://flex.JPG");

                                 targetFile.write(fileBytes);
                                 targetFile.close();
                       }        
                       
                }
                catch (Exception e)
                {
                        e.printStackTrace();
                }


        //String totallen=text;

                try
                {

                    BufferedImage imagefinal = ImageIO.read(new File("d://flex.jpg"));
                                
                //    int w = Math.max(image.getWidth(), overlay.getWidth());
                    //int h = Math.max(image.getHeight(), overlay.getHeight());
                    
                    BufferedImage combined = new BufferedImage(500, 800, BufferedImage.TYPE_INT_ARGB);
                    
                    
                    //combined.setRGB(40,30,30);
                    
                    
                    Graphics g = combined.getGraphics();
                    
                    Font font = new Font("Serif", Font.PLAIN, 24);
                       g.setFont(font);
                       g.setColor(Color.black);
                       
                       g.drawImage(imagefinal, 20, 20, null);
                       int faltu=20;
                for(int m=0;m<=val;m++)
                {

                    g.drawString(str[m], 20, 150+m*faltu);

                }
                    
                    //g.drawImage(overlay, 40, 40, null);// Save as 

                   ImageIO.write(combined, "PNG", new File("d://final.jpg")); 

                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }

                         int len1;
                    String query1;
                  
                    PreparedStatement pstmt;
                    try
                   
                    {
                        connect();
                            File file = new File("d://final.jpg");
                            FileInputStream fis = new FileInputStream(file);
                           
                            len1 = (int)file.length();

                            query1 = ("insert into last VALUES(?,?)");
                            pstmt = con.prepareStatement(query1);
                            pstmt.setString(1,id);
                            
                            // Method used to insert a stream of bytes
                            pstmt.setBinaryStream(2, fis, len1); 
                            pstmt.executeUpdate();

                    }

                    catch (Exception e)
                    {
                            e.printStackTrace();
                    }
           
                  //sending
               
                 int len1;
                    String query1;
                  
                    PreparedStatement pstmt;
                    try
                   
                    {
                        connect();
                            File file = new File("d://final.jpg");
                            FileInputStream fis = new FileInputStream(file);
                           
                            len1 = (int)file.length();

                            query1 = ("insert into last VALUES(?,?)");
                            pstmt = con.prepareStatement(query1);
                            pstmt.setString(1,id);
                            
                            // Method used to insert a stream of bytes
                            pstmt.setBinaryStream(2, fis, len1); 
                            pstmt.executeUpdate();

                    }

                    catch (Exception e)
                    {
                            e.printStackTrace();
                    }

                return null;
 
            }