Review Board 1.7.22


Sqoop2: Introduce synchronous job submission to Client API

Review Request #10869 - Created April 30, 2013 and updated

Vasanth kumar RJ
SQOOP-985
Reviewers
Sqoop
sqoop-sqoop2
Synchronous job submission to Client API.
Done
client/src/main/java/org/apache/sqoop/client/SqoopClient.java
Revision f9137bb New Change
[20] 14 lines
[+20]
15
 * See the License for the specific language governing permissions and
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
16
 * limitations under the License.
17
 */
17
 */
18
package org.apache.sqoop.client;
18
package org.apache.sqoop.client;
19

    
   
19

   

    
   
20
import org.apache.sqoop.client.core.ClientError;
20
import org.apache.sqoop.client.request.SqoopRequests;
21
import org.apache.sqoop.client.request.SqoopRequests;

    
   
22
import org.apache.sqoop.common.SqoopException;
21
import org.apache.sqoop.json.ConnectorBean;
23
import org.apache.sqoop.json.ConnectorBean;
22
import org.apache.sqoop.json.FrameworkBean;
24
import org.apache.sqoop.json.FrameworkBean;
23
import org.apache.sqoop.json.ValidationBean;
25
import org.apache.sqoop.json.ValidationBean;
24
import org.apache.sqoop.model.FormUtils;
26
import org.apache.sqoop.model.FormUtils;
25
import org.apache.sqoop.model.MConnection;
27
import org.apache.sqoop.model.MConnection;
[+20] [20] 50 lines
[+20] [+] public class SqoopClient {
76
  /**
78
  /**
77
   * Cached framework.
79
   * Cached framework.
78
   */
80
   */
79
  private MFramework framework;
81
  private MFramework framework;
80

    
   
82

   

    
   
83
  /**

    
   
84
   * Status flags used when updating the submission callback status

    
   
85
   */

    
   
86
  private enum SubmissionStatus {

    
   
87
    SUBMITTED,

    
   
88
    UPDATED,

    
   
89
    FINISHED

    
   
90
  };

    
   
91

   
81
  public SqoopClient(String serverUrl) {
92
  public SqoopClient(String serverUrl) {
82
    requests = new SqoopRequests();
93
    requests = new SqoopRequests();
83
    setServerUrl(serverUrl);
94
    setServerUrl(serverUrl);
84
  }
95
  }
85

    
   
96

   
[+20] [20] 266 lines
[+20] [+] public void deleteJob(long jid) {
352
  public MSubmission startSubmission(long jid) {
363
  public MSubmission startSubmission(long jid) {
353
    return requests.createSubmission(jid).getSubmission();
364
    return requests.createSubmission(jid).getSubmission();
354
  }
365
  }
355

    
   
366

   
356
  /**
367
  /**

    
   
368
   * Method used for synchronous job submission.

    
   
369
   * Pass null to callback parameter if submission status is not required and after completion

    
   
370
   * job execution returns MSubmission which contains final status of submission.

    
   
371
   * @param jid - Job ID

    
   
372
   * @param callback - User may set null if submission status is not required, else callback methods invoked

    
   
373
   * @param pollTime - Server poll time

    
   
374
   * @return MSubmission - Final status of job submission

    
   
375
   * @throws InterruptedException

    
   
376
   */

    
   
377
  public MSubmission startSubmission(long jid, SubmissionCallback callback, long pollTime) throws InterruptedException {

    
   
378
    if(pollTime <= 0) {

    
   
379
      throw new SqoopException(ClientError.CLIENT_0008);

    
   
380
    }

    
   
381
    boolean first = true;

    
   
382
    MSubmission submission = requests.createSubmission(jid).getSubmission();

    
   
383
    while(submission.getStatus().isRunning()) {

    
   
384
      if(first) {

    
   
385
        submissionCallback(callback, submission, SubmissionStatus.SUBMITTED);

    
   
386
        first = false;

    
   
387
      } else {

    
   
388
        submissionCallback(callback, submission, SubmissionStatus.UPDATED);

    
   
389
      }

    
   
390
      Thread.sleep(pollTime);

    
   
391
      submission = getSubmissionStatus(jid);

    
   
392
    }

    
   
393
    submissionCallback(callback, submission, SubmissionStatus.FINISHED);

    
   
394
    return submission;

    
   
395
  }

    
   
396

   

    
   
397
  /**

    
   
398
   * Invokes the callback's methods with MSubmission object

    
   
399
   * based on SubmissionStatus. If callback is null, no operation performed.

    
   
400
   * @param callback

    
   
401
   * @param submission

    
   
402
   * @param status

    
   
403
   */

    
   
404
  private void submissionCallback(SubmissionCallback callback,

    
   
405
      MSubmission submission, SubmissionStatus status) {

    
   
406
    if(callback == null) {

    
   
407
      return;

    
   
408
    }

    
   
409
    switch (status) {

    
   
410
    case SUBMITTED:

    
   
411
      callback.submitted(submission);

    
   
412
      break;

    
   
413
    case UPDATED:

    
   
414
      callback.updated(submission);

    
   
415
      break;

    
   
416
    case FINISHED:

    
   
417
      callback.finished(submission);

    
   
418
    }

    
   
419
  }

    
   
420

   

    
   
421
  /**
357
   * Stop job with given id.
422
   * Stop job with given id.
358
   *
423
   *
359
   * @param jid Job id
424
   * @param jid Job id
360
   * @return
425
   * @return
361
   */
426
   */
[+20] [20] 44 lines
client/src/main/java/org/apache/sqoop/client/SubmissionCallback.java
New File
 
client/src/main/java/org/apache/sqoop/client/core/ClientError.java
Revision 179dc55 New Change
 
client/src/main/java/org/apache/sqoop/client/core/Constants.java
Revision a48857e New Change
 
client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java
Revision f68ac11 New Change
 
docs/src/site/sphinx/ClientAPI.rst
Revision a9d39fb New Change
 
  1. client/src/main/java/org/apache/sqoop/client/SqoopClient.java: Loading...
  2. client/src/main/java/org/apache/sqoop/client/SubmissionCallback.java: Loading...
  3. client/src/main/java/org/apache/sqoop/client/core/ClientError.java: Loading...
  4. client/src/main/java/org/apache/sqoop/client/core/Constants.java: Loading...
  5. client/src/main/java/org/apache/sqoop/client/shell/SubmissionStartFunction.java: Loading...
  6. docs/src/site/sphinx/ClientAPI.rst: Loading...