2

I am using sqoop client. And don't know by which URL I have to initialize the SqoopClient Object. I am running horton Sandbox which is preconfigured with everything. I dont know it is having sqoop server running or not. And If it is running then I dnt know the port. And If it is not running how can I run it in Sandbox.

I am reading tutorial given at this page: http://devslogics.blogspot.in/2013/09/sqoop-java-client.html

This two lines is the focus to initialize with url.

  String url = "http://192.168.56.102:12000/sqoop/"; 
  SqoopClient client = new SqoopClient(url);

Here is my complete code -

//Here I am using a table Persons, with columns PersonID and LastName
import org.apache.sqoop.client.SqoopClient;
import org.apache.sqoop.model.MConnection;
import org.apache.sqoop.model.MConnectionForms;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MJobForms;
import org.apache.sqoop.model.MSubmission;
import org.apache.sqoop.validation.Status;

/**
 * @author  devan
 * @date 19-Sep-2013
 * @mail msdevanms@gmail.com
 */

public class SqoopImport {
 public static void main(String[] args) {


  String connectionString = "jdbc:mysql://localhost:3316/dw_db";
  String username = "openmrs";
  String password = "ePM2zeKZOzrL";
  String schemaName = "dw_db";
  String tableName = "dw_table";
  String columns = "locale,name"; //comma seperated column names
  String partitionColumn = "locale";
  String outputDirectory = "/output/Persons";
  String url = "http://192.168.56.102:12000/sqoop/";


  SqoopClient client = new SqoopClient(url);
  //client.setServerUrl(newUrl);
  //Dummy connection object
  MConnection newCon = client.newConnection(1);

  //Get connection and framework forms. Set name for connection
  MConnectionForms conForms = newCon.getConnectorPart();
  MConnectionForms frameworkForms = newCon.getFrameworkPart();
  newCon.setName("MyConnection");

  //Set connection forms values
  conForms.getStringInput("connection.connectionString").setValue(connectionString);
  conForms.getStringInput("connection.jdbcDriver").setValue("com.mysql.jdbc.Driver");
  conForms.getStringInput("connection.username").setValue(username);
  conForms.getStringInput("connection.password").setValue(password);

  frameworkForms.getIntegerInput("security.maxConnections").setValue(0);

  Status status  = client.createConnection(newCon);
  if(status.canProceed()) {
   System.out.println("Created. New Connection ID : " +newCon.getPersistenceId());
  } else {
   System.out.println("Check for status and forms error ");
  }

  //Creating dummy job object
  MJob newjob = client.newJob(newCon.getPersistenceId(), org.apache.sqoop.model.MJob.Type.IMPORT);
  MJobForms connectorForm = newjob.getConnectorPart();
  MJobForms frameworkForm = newjob.getFrameworkPart();

  newjob.setName("ImportJob");
  //Database configuration
  connectorForm.getStringInput("table.schemaName").setValue(schemaName);
  //Input either table name or sql
  connectorForm.getStringInput("table.tableName").setValue(tableName);
  //connectorForm.getStringInput("table.sql").setValue("select id,name from table where ${CONDITIONS}");


  connectorForm.getStringInput("table.columns").setValue(columns);
  connectorForm.getStringInput("table.partitionColumn").setValue(partitionColumn);

  //Set boundary value only if required
  //connectorForm.getStringInput("table.boundaryQuery").setValue("");

  //Output configurations
  frameworkForm.getEnumInput("output.storageType").setValue("HDFS");
  frameworkForm.getEnumInput("output.outputFormat").setValue("TEXT_FILE");//Other option: SEQUENCE_FILE / TEXT_FILE
  frameworkForm.getStringInput("output.outputDirectory").setValue(outputDirectory);
  //Job resources
  frameworkForm.getIntegerInput("throttling.extractors").setValue(1);
  frameworkForm.getIntegerInput("throttling.loaders").setValue(1);

  status = client.createJob(newjob);
  if(status.canProceed()) {
   System.out.println("New Job ID: "+ newjob.getPersistenceId());
  } else {
   System.out.println("Check for status and forms error ");
  }
  //Now Submit the Job
  MSubmission submission = client.startSubmission(newjob.getPersistenceId());
  System.out.println("Status : " + submission.getStatus());

 }


}
vineetv2821993
  • 927
  • 12
  • 25
  • i have similar issue. i know sqoop is running in my node. i'm able to perform import and export via command line util. however when i try to do the same via Sqoop Java Client API i have trouble in creating new connection. MConnection newCon = new SqoopClient("http://sanbox.hortonworks.com:12000/sqopp").newConnection(1); – buttowski Jan 19 '17 at 21:22
  • i'm getting this exception during execution. Caused by: com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect at org.apache.sqoop.client.request.Request$ServerExceptionFilter.handle(Request.java:85) ..at org.apache.sqoop.client.request.Request.get(Request.java:62) ..at org.apache.sqoop.client.SqoopClient.retrieveConnector(SqoopClient.java:140) ...getConnector(SqoopClient.java:130) ~[sqoop-client-1.99.2.jar:1.99.2] ...newConnection(SqoopClient.java:225) ~[sqoop-client-1.99.2.jar:1.99.2] – buttowski Jan 19 '17 at 21:26

2 Answers2

0

For checking list of services running on any linux machine,please try the following one:

netstat -tulpn

This will list all the services.

To get a particular service or port,you can grep port name with this command.

For example:netstat -tulpn | grep 8080

To list all running services

netstat -tulpn | grep LISTEN

Hope,this will be helpful

saipm
  • 89
  • 4
0

Running in server mode option is not available for Sqoop1. It is only available for Sqoop2. Make sure that you are using Sqoop2.

See this link to know how start the sqoop server

IThinkSo
  • 74
  • 4