forked from apache/falcon
/
AbstractFalconClient.java
507 lines (460 loc) · 27.4 KB
/
AbstractFalconClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.falcon.client;
import org.apache.falcon.LifeCycle;
import org.apache.falcon.entity.v0.Entity;
import org.apache.falcon.entity.v0.EntityType;
import org.apache.falcon.resource.APIResult;
import org.apache.falcon.resource.EntityList;
import org.apache.falcon.resource.EntitySummaryResult;
import org.apache.falcon.resource.FeedInstanceResult;
import org.apache.falcon.resource.FeedLookupResult;
import org.apache.falcon.resource.InstanceDependencyResult;
import org.apache.falcon.resource.InstancesResult;
import org.apache.falcon.resource.InstancesSummaryResult;
import org.apache.falcon.resource.LineageGraphResult;
import org.apache.falcon.resource.SchedulableEntityInstanceResult;
import org.apache.falcon.resource.TriageResult;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;
/**
* Abstract Client API to submit and manage Falcon Entities (Cluster, Feed, Process) jobs
* against an Falcon instance.
*/
public abstract class AbstractFalconClient {
//SUSPEND CHECKSTYLE CHECK ParameterNumberCheck
protected static final String FALCON_INSTANCE_ACTION_CLUSTERS = "falcon.instance.action.clusters";
protected static final String FALCON_INSTANCE_SOURCE_CLUSTERS = "falcon.instance.source.clusters";
/**
* Submit a new entity. Entities can be of type feed, process or data end
* points. Entity definitions are validated structurally against schema and
* subsequently for other rules before they are admitted into the system.
* @param entityType Entity type. Valid options are cluster, feed or process.
* @param filePath Path for the entity definition
* @return
* @throws IOException
*/
public abstract APIResult submit(String entityType, String filePath, String doAsUser);
/**
* Schedules an submitted process entity immediately.
* @param entityType Entity type. Valid options are cluster, feed or process.
* @param entityName Name of the entity.
* @param colo Cluster name.
* @return
*/
public abstract APIResult schedule(EntityType entityType, String entityName, String colo, Boolean skipDryRun,
String doAsuser, String properties);
/**
* Delete the specified entity.
* @param entityType Entity type. Valid options are cluster, feed or process.
* @param entityName Name of the entity.
* @param doAsUser Proxy User.
* @return
*/
public abstract APIResult delete(EntityType entityType, String entityName,
String doAsUser);
/**
* Validates the submitted entity.
* @param entityType Entity type. Valid options are cluster, feed or process.
* @param filePath Path for the entity definition to validate.
* @param skipDryRun Dry run.
* @param doAsUser Proxy User.
* @return
\ */
public abstract APIResult validate(String entityType, String filePath, Boolean skipDryRun,
String doAsUser);
/**
* Updates the submitted entity.
* @param entityType Entity type. Valid options are cluster, feed or process.
* @param entityName Name of the entity.
* @param filePath Path for the entity definition to update.
* @param skipDryRun Dry run.
* @param doAsUser Proxy User.
* @return
*/
public abstract APIResult update(String entityType, String entityName, String filePath,
Boolean skipDryRun, String doAsUser);
/**
* Get definition of the entity.
* @param entityType Entity type. Valid options are cluster, feed or process.
* @param entityName Name of the entity.
* @param doAsUser Proxy user.
* @return
*/
public abstract Entity getDefinition(String entityType, String entityName,
String doAsUser);
/**
*
* @param type entity type
* @param entity entity name
* @param start start time
* @param end end time
* @param colo colo name
* @param lifeCycles lifecycle of an entity (for ex : feed has replication,eviction).
* @param filterBy filter operation can be applied to results
* @param orderBy
* @param sortOrder sort order can be asc or desc
* @param offset offset while displaying results
* @param numResults num of Results to output
* @param doAsUser proxy user
* @param allAttempts To get the instances corresponding to each run-id
* @return
*/
public abstract InstancesResult getStatusOfInstances(String type, String entity, String start, String end, String
colo, List<LifeCycle> lifeCycles, String filterBy, String orderBy, String sortOrder, Integer offset, Integer
numResults, String doAsUser, Boolean allAttempts);
/**
* Suspend an entity.
* @param entityType Valid options are feed or process.
* @param entityName Name of the entity.
* @param colo Colo on which the query should be run.
* @param doAsUser proxy user
* @return Status of the entity.
*/
public abstract APIResult suspend(EntityType entityType, String entityName, String colo, String doAsUser);
/**
* Resume a supended entity.
* @param entityType Valid options are feed or process.
* @param entityName Name of the entity.
* @param colo Colo on which the query should be run.
* @param doAsUser proxy user
* @return Result of the resume command.
*/
public abstract APIResult resume(EntityType entityType, String entityName, String colo, String doAsUser);
/**
* Get status of the entity.
* @param entityType Valid options are feed or process.
* @param entityName Name of the entity.
* @param colo Colo on which the query should be run.
* @param doAsUser proxy user
* @param showScheduler whether the call should return the scheduler on which the entity is scheduled.
* @return Status of the entity.
*/
public abstract APIResult getStatus(EntityType entityType, String entityName, String colo, String doAsUser,
boolean showScheduler);
/**
* Submits and schedules an entity.
* @param entityType Valid options are feed or process.
* @param filePath Path for the entity definition
* @param skipDryRun Optional query param, Falcon skips oozie dryrun when value is set to true.
* @param doAsUser proxy user
* @return Result of the submit and schedule command.
*/
public abstract APIResult submitAndSchedule(String entityType, String filePath, Boolean skipDryRun, String doAsUser,
String properties);
/**
* Prepare set of entities the extension has implemented and stage them to a local directory and submit them too.
* @param extensionName extension which is available in the store.
* @param jobName name to be used in all the extension entities' tagging that are built as part of
* loadAndPrepare.
* @param configPath path to extension parameters.
* @return
* @throws FalconCLIException
*/
public abstract APIResult submitExtensionJob(String extensionName, String jobName, String configPath,
String doAsUser);
/**
*
* Get list of the entities.
* We have two filtering parameters for entity tags: "tags" and "tagkeys".
* "tags" does the exact match in key=value fashion, while "tagkeys" finds all the entities with the given key as a
* substring in the tags. This "tagkeys" filter is introduced for the user who doesn't remember the exact tag but
* some keywords in the tag. It also helps users to save the time of typing long tags.
* The returned entities will match all the filtering criteria.
* @param entityType Comma-separated entity types. Can be empty. Valid entity types are cluster, feed or process.
* @param fields <optional param> Fields of entity that the user wants to view, separated by commas.
* Valid options are STATUS, TAGS, PIPELINES, CLUSTERS.
* @param nameSubsequence <optional param> Subsequence of entity name. Not case sensitive.
* The entity name needs to contain all the characters in the subsequence in the same order.
* Example 1: "sample1" will match the entity named "SampleFeed1-2".
* Example 2: "mhs" will match the entity named "New-My-Hourly-Summary".
* @param tagKeywords <optional param> Keywords in tags, separated by comma. Not case sensitive.
* The returned entities will have tags that match all the tag keywords.
* @param filterTags <optional param> Return list of entities that have specified tags, separated by a comma.
* Query will do AND on tag values.
* Example: tags=consumer=consumer@xyz.com,owner=producer@xyz.com
* @param filterBy <optional param> Filter results by list of field:value pairs.
* Example: filterBy=STATUS:RUNNING,PIPELINES:clickLogs
* Supported filter fields are NAME, STATUS, PIPELINES, CLUSTER.
* Query will do an AND among filterBy fields.
* @param orderBy <optional param> Field by which results should be ordered.
* Supports ordering by "name".
* @param sortOrder <optional param> Valid options are "asc" and "desc"
* @param offset <optional param> Show results from the offset, used for pagination. Defaults to 0.
* @param numResults <optional param> Number of results to show per request, used for pagination. Only
* integers > 0 are valid, Default is 10.
* @param doAsUser proxy user
* @return Total number of results and a list of entities.
*/
public abstract EntityList getEntityList(String entityType, String fields, String nameSubsequence, String
tagKeywords, String filterBy, String filterTags, String orderBy, String sortOrder, Integer offset, Integer
numResults, String doAsUser);
/**
* Given an EntityType and cluster, get list of entities along with summary of N recent instances of each entity.
* @param entityType Valid options are feed or process.
* @param cluster Show entities that belong to this cluster.
* @param start <optional param> Show entity summaries from this date. Date format is yyyy-MM-dd'T'HH:mm'Z'.
* By default, it is set to (end - 2 days).
* @param end <optional param> Show entity summary up to this date. Date format is yyyy-MM-dd'T'HH:mm'Z'.
* Default is set to now.
* @param fields <optional param> Fields of entity that the user wants to view, separated by commas.
* Valid options are STATUS, TAGS, PIPELINES.
* @param filterBy <optional param> Filter results by list of field:value pairs.
* Example: filterBy=STATUS:RUNNING,PIPELINES:clickLogs
* Supported filter fields are NAME, STATUS, PIPELINES, CLUSTER.
* Query will do an AND among filterBy fields.
* @param filterTags <optional param> Return list of entities that have specified tags, separated by a comma.
* Query will do AND on tag values.
* Example: tags=consumer=consumer@xyz.com,owner=producer@xyz.com
* @param orderBy <optional param> Field by which results should be ordered.
* Supports ordering by "name".
* @param sortOrder <optional param> Valid options are "asc" and "desc"
* @param offset <optional param> Show results from the offset, used for pagination. Defaults to 0.
* @param numInstances <optional param> Number of results to show per request, used for pagination. Only
* integers > 0 are valid, Default is 10.
* @param numResults <optional param> Number of recent instances to show per entity. Only integers > 0 are
* valid, Default is 7.
* @param doAsUser proxy user
* @return Show entities along with summary of N instances for each entity.
*/
public abstract EntitySummaryResult getEntitySummary(String entityType, String cluster, String start, String end,
String fields, String filterBy, String filterTags, String
orderBy, String sortOrder, Integer offset, Integer
numResults, Integer numInstances, String doAsUser);
/**
* Force updates the entity.
* @param entityType Valid options are feed or process.
* @param entityName Name of the entity.
* @param colo Colo on which the query should be run.
* @param skipDryRun Optional query param, Falcon skips oozie dryrun when value is set to true.
* @param doAsUser proxy user
* @return Result of the validation.
*/
public abstract APIResult touch(String entityType, String entityName, String colo, Boolean skipDryRun,
String doAsUser);
/**
* Kill currently running instance(s) of an entity.
* @param type Valid options are feed or process.
* @param entity name of the entity.
* @param start start time of the instance(s) that you want to refer to
* @param end end time of the instance(s) that you want to refer to
* @param colo Colo on which the query should be run.
* @param lifeCycles <optional param> can be Eviction/Replication(default) for feed and Execution(default) for
* process.
* @param doAsUser proxy user
* @return Result of the kill operation.
* @throws UnsupportedEncodingException
*/
public abstract InstancesResult killInstances(String type, String entity, String start, String end, String colo,
String clusters, String sourceClusters, List<LifeCycle> lifeCycles,
String doAsUser) throws UnsupportedEncodingException;
/**
* Suspend instances of an entity.
* @param type Valid options are feed or process.
* @param entity name of the entity.
* @param start the start time of the instance(s) that you want to refer to
* @param end the end time of the instance(s) that you want to refer to
* @param colo Colo on which the query should be run.
* @param lifeCycles <optional param> can be Eviction/Replication(default) for feed and Execution(default) for
* process.
* @param doAsUser proxy user
* @return Results of the suspend command.
* @throws UnsupportedEncodingException
*/
public abstract InstancesResult suspendInstances(String type, String entity, String start, String end, String colo,
String clusters, String sourceClusters, List<LifeCycle> lifeCycles,
String doAsUser) throws UnsupportedEncodingException;
/**
* Resume suspended instances of an entity.
* @param type Valid options are feed or process.
* @param entity name of the entity.
* @param start start time of the instance(s) that you want to refer to
* @param end the end time of the instance(s) that you want to refer to
* @param colo Colo on which the query should be run.
* @param lifeCycles <optional param> can be Eviction/Replication(default) for feed and Execution(default) for
* process.
* @param doAsUser proxy user
* @return Results of the resume command.
* @throws UnsupportedEncodingException
*/
public abstract InstancesResult resumeInstances(String type, String entity, String start, String end, String colo,
String clusters, String sourceClusters, List<LifeCycle> lifeCycles,
String doAsUser) throws UnsupportedEncodingException;
/**
* Rerun instances of an entity. On issuing a rerun, by default the execution resumes from the last failed node in
* the workflow.
* @param type Valid options are feed or process.
* @param entity name of the entity.
* @param start start is the start time of the instance that you want to refer to
* @param end end is the end time of the instance that you want to refer to
* @param colo Colo on which the query should be run.
* @param lifeCycles <optional param> can be Eviction/Replication(default) for feed and Execution(default) for
* process.
* @param isForced <optional param> can be used to forcefully rerun the entire instance.
* @param doAsUser proxy user
* @return Results of the rerun command.
* @throws IOException
*/
public abstract InstancesResult rerunInstances(String type, String entity, String start, String end,
String filePath, String colo, String clusters,
String sourceClusters, List<LifeCycle> lifeCycles, Boolean isForced,
String doAsUser) throws IOException;
/**
* Get summary of instance/instances of an entity.
* @param type Valid options are cluster, feed or process.
* @param entity Name of the entity.
* @param start <optional param> Show instances from this date. Date format is yyyy-MM-dd'T'HH:mm'Z'.
* By default, it is set to (end - (10 * entityFrequency)).
* @param end <optional param> Show instances up to this date. Date format is yyyy-MM-dd'T'HH:mm'Z'.
* Default is set to now.
* @param colo <optional param> Colo on which the query should be run.
* @param lifeCycles <optional param> Valid lifecycles for feed are Eviction/Replication(default) and for process
* is Execution(default).
* @param filterBy <optional param> Filter results by list of field:value pairs.
* Example1: filterBy=STATUS:RUNNING,CLUSTER:primary-cluster
* Example2: filterBy=Status:RUNNING,Status:KILLED
* Supported filter fields are STATUS, CLUSTER.
* Query will do an AND among filterBy fields.
* @param orderBy <optional param> Field by which results should be ordered.
* Supports ordering by "cluster". Example: orderBy=cluster
* @param sortOrder <optional param> Valid options are "asc" and "desc". Example: sortOrder=asc
* @param doAsUser proxy user
* @return Summary of the instances over the specified time range
*/
public abstract InstancesSummaryResult getSummaryOfInstances(String type, String entity, String start, String end,
String colo, List<LifeCycle> lifeCycles,
String filterBy, String orderBy, String sortOrder,
String doAsUser);
/**
* Get falcon feed instance availability.
* @param type Valid options is feed.
* @param entity Name of the entity.
* @param start <optional param> Show instances from this date. Date format is yyyy-MM-dd'T'HH:mm'Z'.
* By default, it is set to (end - (10 * entityFrequency)).
* @param end <optional param> Show instances up to this date. Date format is yyyy-MM-dd'T'HH:mm'Z'.
* Default is set to now.
* @param colo Colo on which the query should be run.
* @param doAsUser proxy user
* @return Feed instance availability status
*/
public abstract FeedInstanceResult getFeedListing(String type, String entity, String start, String end, String colo,
String doAsUser);
/**
* Get log of a specific instance of an entity.
* @param type Valid options are cluster, feed or process.
* @param entity Name of the entity.
* @param start <optional param> Show instances from this date. Date format is yyyy-MM-dd'T'HH:mm'Z'.
* By default, it is set to (end - (10 * entityFrequency)).
* @param end <optional param> Show instances up to this date. Date format is yyyy-MM-dd'T'HH:mm'Z'.
* Default is set to now.
* @param colo <optional param> Colo on which the query should be run.
* @param runId <optional param> Run Id.
* @param lifeCycles <optional param> Valid lifecycles for feed are Eviction/Replication(default) and for process is
* Execution(default).
* @param filterBy <optional param> Filter results by list of field:value pairs.
* Example: filterBy=STATUS:RUNNING,CLUSTER:primary-cluster
* Supported filter fields are STATUS, CLUSTER, SOURCECLUSTER, STARTEDAFTER.
* Query will do an AND among filterBy fields.
* @param orderBy <optional param> Field by which results should be ordered.
* Supports ordering by "status","startTime","endTime","cluster".
* @param sortOrder <optional param> Valid options are "asc" and "desc"
* @param offset <optional param> Show results from the offset, used for pagination. Defaults to 0.
* @param numResults <optional param> Number of results to show per request, used for pagination. Only integers > 0
* are valid, Default is 10.
* @param doAsUser proxy user
* @return Log of specified instance.
*/
public abstract InstancesResult getLogsOfInstances(String type, String entity, String start, String end,
String colo, String runId, List<LifeCycle> lifeCycles,
String filterBy, String orderBy, String sortOrder,
Integer offset, Integer numResults, String doAsUser);
//RESUME CHECKSTYLE CHECK ParameterNumberCheck
/**
* Get the params passed to the workflow for an instance of feed/process.
* @param type Valid options are cluster, feed or process.
* @param entity Name of the entity.
* @param start should be the nominal time of the instance for which you want the params to be returned
* @param colo <optional param> Colo on which the query should be run.
* @param lifeCycles <optional param> Valid lifecycles for feed are Eviction/Replication(default) and for process is
* Execution(default).
* @param doAsUser proxy user
* @return List of instances currently running.
* @throws UnsupportedEncodingException
*/
public abstract InstancesResult getParamsOfInstance(String type, String entity, String start, String colo,
List<LifeCycle> lifeCycles, String doAsUser) throws
UnsupportedEncodingException;
/**
* Get dependent instances for a particular instance.
* @param entityType Valid options are feed or process.
* @param entityName Name of the entity
* @param instanceTime <mandatory param> time of the given instance
* @param colo Colo on which the query should be run.
* @return Dependent instances for the specified instance
*/
public abstract InstanceDependencyResult getInstanceDependencies(String entityType, String entityName,
String instanceTime, String colo);
/**
* Get version of the falcon server.
* @return Version of the server.
*/
public abstract String getVersion(String doAsUser);
protected InputStream getServletInputStream(String clusters, String sourceClusters, String properties) throws
UnsupportedEncodingException {
InputStream stream;
StringBuilder buffer = new StringBuilder();
if (clusters != null) {
buffer.append(FALCON_INSTANCE_ACTION_CLUSTERS).append('=').append(clusters).append('\n');
}
if (sourceClusters != null) {
buffer.append(FALCON_INSTANCE_SOURCE_CLUSTERS).append('=').append(sourceClusters).append('\n');
}
if (properties != null) {
buffer.append(properties);
}
stream = new ByteArrayInputStream(buffer.toString().getBytes());
return (buffer.length() == 0) ? null : stream;
}
public abstract SchedulableEntityInstanceResult getFeedSlaMissPendingAlerts(String entityType, String entityName,
String start, String end, String colo);
public abstract FeedLookupResult reverseLookUp(String entityType, String path, String doAs);
public abstract EntityList getDependency(String entityType, String entityName, String doAs);
public abstract TriageResult triage(String name, String entityName, String start, String colo);
// SUSPEND CHECKSTYLE CHECK ParameterNumberCheck
public abstract InstancesResult getRunningInstances(String type, String entity, String colo,
List<LifeCycle> lifeCycles,
String filterBy, String orderBy, String sortOrder,
Integer offset, Integer numResults, String doAsUser);
// RESUME CHECKSTYLE CHECK ParameterNumberCheck
public abstract FeedInstanceResult getFeedInstanceListing(String type, String entity, String start, String end,
String colo, String doAsUser);
public abstract int getStatus(String doAsUser);
public abstract String getThreadDump(String doAs);
public abstract LineageGraphResult getEntityLineageGraph(String pipeline, String doAs);
public abstract String getDimensionList(String dimensionType, String cluster, String doAs);
public abstract String getReplicationMetricsDimensionList(String schedEntityType, String schedEntityName,
Integer numResults, String doAs);
public abstract String getDimensionRelations(String dimensionType, String dimensionName, String doAs);
public abstract String getVertex(String id, String doAs);
public abstract String getVertices(String key, String value, String doAs);
public abstract String getVertexEdges(String id, String direction, String doAs);
public abstract String getEdge(String id, String doAs);
}