Review Board 1.7.22


SQOOP-918 Sqoop2: Introduce client API and change Sqoop shell to use it

Review Request #9717 - Created March 3, 2013 and submitted

Jarek Cecho
SQOOP-918
Reviewers
Sqoop
sqoop-sqoop2
I've created first simple SqoopClient API and altered shell to use it. I've noticed that there is a lot of duplicate code in the shell, so I've tried to clean it up. The changes are simple, however are spanning across all shell files, thus making this patch bigger than necessary.

This is first implementation of the SqoopClient API. I'm intending to improve it, for example by caching objects that was already received (especially connector info and resource bundles). As this patch is big enough already, I would prefer to finish this functionality in follow up JIRA.
Unit tests seems to be passing and I've tried the changes on real cluster.

Diff revision 1

This is not the most recent revision of the diff. The latest diff is revision 4. See what's changed.

1 2 3 4
1 2 3 4

  1. client/src/main/java/org/apache/sqoop/client/SqoopClient.java: Loading...
  2. client/src/main/java/org/apache/sqoop/client/core/Environment.java: Loading...
  3. client/src/main/java/org/apache/sqoop/client/core/RequestCache.java: Loading...
  4. client/src/main/java/org/apache/sqoop/client/request/ConnectionRequest.java: Loading...
  5. client/src/main/java/org/apache/sqoop/client/request/ConnectorRequest.java: Loading...
  6. client/src/main/java/org/apache/sqoop/client/request/JobRequest.java: Loading...
  7. client/src/main/java/org/apache/sqoop/client/request/SqoopRequests.java: Loading...
  8. client/src/main/java/org/apache/sqoop/client/request/SubmissionRequest.java: Loading...
  9. client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java: Loading...
  10. client/src/main/java/org/apache/sqoop/client/shell/CloneConnectionFunction.java: Loading...
  11. client/src/main/java/org/apache/sqoop/client/shell/CloneJobFunction.java: Loading...
  12. client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java: Loading...
  13. client/src/main/java/org/apache/sqoop/client/shell/CreateConnectionFunction.java: Loading...
  14. client/src/main/java/org/apache/sqoop/client/shell/CreateJobFunction.java: Loading...
  15. client/src/main/java/org/apache/sqoop/client/shell/DeleteCommand.java: Loading...
  16. client/src/main/java/org/apache/sqoop/client/shell/DeleteConnectionFunction.java: Loading...
  17. client/src/main/java/org/apache/sqoop/client/shell/DeleteJobFunction.java: Loading...
  18. client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java: Loading...
  19. client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java: Loading...
  20. client/src/main/java/org/apache/sqoop/client/shell/SetOptionFunction.java: Loading...
This diff has been split across 2 pages: 1 2 >
client/src/main/java/org/apache/sqoop/client/SqoopClient.java
New File

    
   
1
/**

    
   
2
 * Licensed to the Apache Software Foundation (ASF) under one

    
   
3
 * or more contributor license agreements.  See the NOTICE file

    
   
4
 * distributed with this work for additional information

    
   
5
 * regarding copyright ownership.  The ASF licenses this file

    
   
6
 * to you under the Apache License, Version 2.0 (the

    
   
7
 * "License"); you may not use this file except in compliance

    
   
8
 * with the License.  You may obtain a copy of the License at

    
   
9
 *

    
   
10
 *     http://www.apache.org/licenses/LICENSE-2.0

    
   
11
 *

    
   
12
 * Unless required by applicable law or agreed to in writing, software

    
   
13
 * distributed under the License is distributed on an "AS IS" BASIS,

    
   
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

    
   
15
 * See the License for the specific language governing permissions and

    
   
16
 * limitations under the License.

    
   
17
 */

    
   
18
package org.apache.sqoop.client;

    
   
19

   

    
   
20
import org.apache.sqoop.client.request.SqoopRequests;

    
   
21
import org.apache.sqoop.model.MConnection;

    
   
22
import org.apache.sqoop.model.MConnector;

    
   
23
import org.apache.sqoop.model.MFramework;

    
   
24
import org.apache.sqoop.model.MJob;

    
   
25
import org.apache.sqoop.model.MSubmission;

    
   
26
import org.apache.sqoop.validation.Status;

    
   
27

   

    
   
28
import java.util.List;

    
   
29
import java.util.ResourceBundle;

    
   
30

   

    
   
31
/**

    
   
32
 * Sqoop client API.

    
   
33
 *

    
   
34
 * High level Sqoop client API to communicate with Sqoop server.

    
   
35
 */

    
   
36
public class SqoopClient {

    
   
37

   

    
   
38
  private SqoopRequests requests;

    
   
39

   

    
   
40
  public SqoopClient(String serverUrl) {

    
   
41
    requests = new SqoopRequests();

    
   
42
    requests.setServerUrl(serverUrl);

    
   
43
  }

    
   
44

   

    
   
45
  /**

    
   
46
   * Set new server URL.

    
   
47
   *

    
   
48
   * @param serverUrl Server URL

    
   
49
   */

    
   
50
  public void setServerUrl(String serverUrl) {

    
   
51
    requests.setServerUrl(serverUrl);

    
   
52
  }

    
   
53

   

    
   
54
  /**

    
   
55
   * Get connector with given id.

    
   
56
   *

    
   
57
   * @param cid Connector id.

    
   
58
   * @return

    
   
59
   */

    
   
60
  public MConnector getConnector(long cid) {

    
   
61
    return requests.readConnector(cid).getConnectors().get(0);

    
   
62
  }

    
   
63

   

    
   
64
  /**

    
   
65
   * Get list of all connectors.

    
   
66
   *

    
   
67
   * @return

    
   
68
   */

    
   
69
  public List<MConnector> getConnectors() {

    
   
70
    return requests.readConnector(null).getConnectors();

    
   
71
  }

    
   
72

   

    
   
73
  /**

    
   
74
   * Get resouce bundle for given connector.

    
   
75
   *

    
   
76
   * @param cid Connector id.

    
   
77
   * @return

    
   
78
   */

    
   
79
  public ResourceBundle getResourceBundle(long cid) {

    
   
80
    return requests.readConnector(cid).getResourceBundles().get(cid);

    
   
81
  }

    
   
82

   

    
   
83
  /**

    
   
84
   * Return framework metadata.

    
   
85
   *

    
   
86
   * @return

    
   
87
   */

    
   
88
  public MFramework getFramework() {

    
   
89
    return requests.readFramework().getFramework();

    
   
90
  }

    
   
91

   

    
   
92
  /**

    
   
93
   * Return framework bundle.

    
   
94
   *

    
   
95
   * @return

    
   
96
   */

    
   
97
  public ResourceBundle getFrameworkResourceBundle() {

    
   
98
    return requests.readFramework().getResourceBundle();

    
   
99
  }

    
   
100

   

    
   
101
  /**

    
   
102
   * Create new connection object for given connector.

    
   
103
   *

    
   
104
   * @param cid Connector id

    
   
105
   * @return

    
   
106
   */

    
   
107
  public MConnection newConnection(long cid) {

    
   
108
    return new MConnection(

    
   
109
      cid,

    
   
110
      getConnector(cid).getConnectionForms(),

    
   
111
      getFramework().getConnectionForms()

    
   
112
    );

    
   
113
  }

    
   
114

   

    
   
115
  /**

    
   
116
   * Retrieve connection with given id.

    
   
117
   *

    
   
118
   * @param xid Connnection id

    
   
119
   * @return

    
   
120
   */

    
   
121
  public MConnection getConnection(long xid) {

    
   
122
    return requests.readConnection(xid).getConnections().get(0);

    
   
123
  }

    
   
124

   

    
   
125
  /**

    
   
126
   * Retrieve list of all connections.

    
   
127
   *

    
   
128
   * @return

    
   
129
   */

    
   
130
  public List<MConnection> getConnections() {

    
   
131
    return requests.readConnection(null).getConnections();

    
   
132
  }

    
   
133

   

    
   
134
  /**

    
   
135
   * Create the connection on server.

    
   
136
   *

    
   
137
   * @param connection Connection that should be created

    
   
138
   * @return

    
   
139
   */

    
   
140
  public Status createConnection(MConnection connection) {

    
   
141
    return requests.createConnectionApplyValidations(connection);

    
   
142
  }

    
   
143

   

    
   
144
  /**

    
   
145
   * Update connection on the server.

    
   
146
   *

    
   
147
   * @param connection Connection that should be updated

    
   
148
   * @return

    
   
149
   */

    
   
150
  public Status updateConnection(MConnection connection) {

    
   
151
    return requests.updateConnectionApplyValidations(connection);

    
   
152
  }

    
   
153

   

    
   
154
  /**

    
   
155
   * Delete connection with given id.

    
   
156
   *

    
   
157
   * @param xid Connection id

    
   
158
   */

    
   
159
  public void deleteConnection(long xid) {

    
   
160
    requests.deleteConnection(xid);

    
   
161
  }

    
   
162

   

    
   
163
  /**

    
   
164
   * Create new job of given type and for given connection.

    
   
165
   *

    
   
166
   * @param xid Connection id

    
   
167
   * @param type Job type

    
   
168
   * @return

    
   
169
   */

    
   
170
  public MJob newJob(long xid, MJob.Type type) {

    
   
171
    MConnection connection = getConnection(xid);

    
   
172

   

    
   
173
    return new MJob(

    
   
174
      connection.getConnectorId(),

    
   
175
      connection.getPersistenceId(),

    
   
176
      type,

    
   
177
      getConnector(connection.getConnectorId()).getJobForms(type),

    
   
178
      getFramework().getJobForms(type)

    
   
179
    );

    
   
180
  }

    
   
181

   

    
   
182
  /**

    
   
183
   * Retrieve job for given id.

    
   
184
   *

    
   
185
   * @param jid Job id

    
   
186
   * @return

    
   
187
   */

    
   
188
  public MJob getJob(long jid) {

    
   
189
    return requests.readJob(jid).getJobs().get(0);

    
   
190
  }

    
   
191

   

    
   
192
  /**

    
   
193
   * Retrieve list of all jobs.

    
   
194
   *

    
   
195
   * @return

    
   
196
   */

    
   
197
  public List<MJob> getJobs() {

    
   
198
    return requests.readJob(null).getJobs();

    
   
199
  }

    
   
200

   

    
   
201
  /**

    
   
202
   * Create job on server.

    
   
203
   *

    
   
204
   * @param job Job that should be created

    
   
205
   * @return

    
   
206
   */

    
   
207
  public Status createJob(MJob job) {

    
   
208
    return requests.createJobApplyValidations(job);

    
   
209
  }

    
   
210

   

    
   
211
  /**

    
   
212
   * Update job on server.

    
   
213
   * @param job Job that should be updated

    
   
214
   * @return

    
   
215
   */

    
   
216
  public Status updateJob(MJob job) {

    
   
217
    return requests.updateJobApplyValidations(job);

    
   
218
  }

    
   
219

   

    
   
220
  /**

    
   
221
   * Delete job with given id.

    
   
222
   *

    
   
223
   * @param jid Job id

    
   
224
   */

    
   
225
  public void deleteJob(long jid) {

    
   
226
    requests.deleteJob(jid);

    
   
227
  }

    
   
228

   

    
   
229
  /**

    
   
230
   * Start job with given id.

    
   
231
   *

    
   
232
   * @param jid Job id

    
   
233
   * @return

    
   
234
   */

    
   
235
  public MSubmission startSubmission(long jid) {

    
   
236
    return requests.createSubmission(jid).getSubmission();

    
   
237
  }

    
   
238

   

    
   
239
  /**

    
   
240
   * Stop job with given id.

    
   
241
   *

    
   
242
   * @param jid Job id

    
   
243
   * @return

    
   
244
   */

    
   
245
  public MSubmission stopSubmission(long jid) {

    
   
246
    return requests.deleteSubmission(jid).getSubmission();

    
   
247
  }

    
   
248

   

    
   
249
  /**

    
   
250
   * Get status for given job id.

    
   
251
   *

    
   
252
   * @param jid Job id

    
   
253
   * @return

    
   
254
   */

    
   
255
  public MSubmission statusSubmission(long jid) {

    
   
256
    return requests.readSubmission(jid).getSubmission();

    
   
257
  }

    
   
258
}
client/src/main/java/org/apache/sqoop/client/core/Environment.java
Revision 5d1af26a0e8f96c11c7ef7d8fcfd0013db5ccce6 New Change
 
client/src/main/java/org/apache/sqoop/client/core/RequestCache.java
Revision 808b9f15d52ba9d3620e094a3640b6a93e2b0848 New Change
 
client/src/main/java/org/apache/sqoop/client/request/ConnectionRequest.java
Revision f1e4d685eb0466e916ede21e23f6766f6b263c27 New Change
 
client/src/main/java/org/apache/sqoop/client/request/ConnectorRequest.java
Revision 9ea9d5db91cb28337ef4b6d997af9d0cd0ef7781 New Change
 
client/src/main/java/org/apache/sqoop/client/request/JobRequest.java
Revision c2449f5106e2918b5e5068ff41733def68180804 New Change
 
client/src/main/java/org/apache/sqoop/client/request/SqoopRequests.java
New File
 
client/src/main/java/org/apache/sqoop/client/request/SubmissionRequest.java
Revision 60dcbb29cb75106c58d4de29a6160c1976bc4d67 New Change
 
client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java
Revision abec66b4bdcd10bfe6a7b62e421a131083359b5e New Change
 
client/src/main/java/org/apache/sqoop/client/shell/CloneConnectionFunction.java
Revision 9d6c39627fc7c244adfc6a23a0d6470ab834ee9e New Change
 
client/src/main/java/org/apache/sqoop/client/shell/CloneJobFunction.java
Revision d06f05113cee801e0d956aa2f07f12f6bf748c46 New Change
 
client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java
Revision f4872d2822859739d0bf86c32d349190905d52ad New Change
 
client/src/main/java/org/apache/sqoop/client/shell/CreateConnectionFunction.java
Revision 2c750d337a34a6e2c08f524dfa61a3c287f385d1 New Change
 
client/src/main/java/org/apache/sqoop/client/shell/CreateJobFunction.java
Revision 1f01cc75b5be572385c8ad3c6c20e33903e88fd6 New Change
 
client/src/main/java/org/apache/sqoop/client/shell/DeleteCommand.java
Revision 38b2fdade23a046e6f4e5c5fcfb823d88181db02 New Change
 
client/src/main/java/org/apache/sqoop/client/shell/DeleteConnectionFunction.java
Revision 154acc7382335773f65569c045d7a4dff02eb728 New Change
 
client/src/main/java/org/apache/sqoop/client/shell/DeleteJobFunction.java
Revision 9d6c53e7fcf4e43753c20668697bdfb25168b927 New Change
 
client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java
Revision e14f738d5fd77ed7f7ec913cae2456aa4edd2123 New Change
 
client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java
Revision 6c17e2515c6c034feb6569b6f8b40e53504b6412 New Change
 
client/src/main/java/org/apache/sqoop/client/shell/SetOptionFunction.java
Revision 5d5e9e7570e432c2e8c00c656153a2f1c09bb14c New Change
 
  1. client/src/main/java/org/apache/sqoop/client/SqoopClient.java: Loading...
  2. client/src/main/java/org/apache/sqoop/client/core/Environment.java: Loading...
  3. client/src/main/java/org/apache/sqoop/client/core/RequestCache.java: Loading...
  4. client/src/main/java/org/apache/sqoop/client/request/ConnectionRequest.java: Loading...
  5. client/src/main/java/org/apache/sqoop/client/request/ConnectorRequest.java: Loading...
  6. client/src/main/java/org/apache/sqoop/client/request/JobRequest.java: Loading...
  7. client/src/main/java/org/apache/sqoop/client/request/SqoopRequests.java: Loading...
  8. client/src/main/java/org/apache/sqoop/client/request/SubmissionRequest.java: Loading...
  9. client/src/main/java/org/apache/sqoop/client/shell/CloneCommand.java: Loading...
  10. client/src/main/java/org/apache/sqoop/client/shell/CloneConnectionFunction.java: Loading...
  11. client/src/main/java/org/apache/sqoop/client/shell/CloneJobFunction.java: Loading...
  12. client/src/main/java/org/apache/sqoop/client/shell/CreateCommand.java: Loading...
  13. client/src/main/java/org/apache/sqoop/client/shell/CreateConnectionFunction.java: Loading...
  14. client/src/main/java/org/apache/sqoop/client/shell/CreateJobFunction.java: Loading...
  15. client/src/main/java/org/apache/sqoop/client/shell/DeleteCommand.java: Loading...
  16. client/src/main/java/org/apache/sqoop/client/shell/DeleteConnectionFunction.java: Loading...
  17. client/src/main/java/org/apache/sqoop/client/shell/DeleteJobFunction.java: Loading...
  18. client/src/main/java/org/apache/sqoop/client/shell/HelpCommand.java: Loading...
  19. client/src/main/java/org/apache/sqoop/client/shell/SetCommand.java: Loading...
  20. client/src/main/java/org/apache/sqoop/client/shell/SetOptionFunction.java: Loading...
This diff has been split across 2 pages: 1 2 >