-
Notifications
You must be signed in to change notification settings - Fork 56
[b/402028795] Oozie connector #793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
63f2d8e
Oozie connector added
vladislav-sidorovich 0ac8294
add missing files
vladislav-sidorovich b5717d8
add unit tests for Oozie task and connector
vladislav-sidorovich 03de34f
rename oozie jobs csv file
vladislav-sidorovich d33e4fc
make method static
vladislav-sidorovich 3a67ae1
adjust unit-test for oozie jobs
vladislav-sidorovich 9afa2f4
rename logger
vladislav-sidorovich 900a143
add url parameter for oozie
vladislav-sidorovich b8889cf
add auth support for Oozie client
vladislav-sidorovich 41935e3
uncomment build tasks
vladislav-sidorovich 60a8461
user timestamps without timezones to fetch jobs
vladislav-sidorovich e5f0262
add more tests for oozie
vladislav-sidorovich 477e8e3
code review polishing
vladislav-sidorovich 63d234d
regenerate lockfile
vladislav-sidorovich 4e38003
exclide some logger libs
vladislav-sidorovich 13e4188
reconfigure logger libs
vladislav-sidorovich db13e68
remove simple logger
vladislav-sidorovich c6292a7
Merge branch 'main' into feature/oozie-connector
vladislav-sidorovich 22c1eb6
fix git merge
vladislav-sidorovich 06d852f
rename variables and reformat code
vladislav-sidorovich 209a598
configure logging for apache commons beanutils
vladislav-sidorovich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
...gle/edwmigration/dumper/application/dumper/connector/hadoop/oozie/OozieClientFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2022-2025 Google LLC | ||
* Copyright 2013-2021 CompilerWorks | ||
* | ||
* Licensed 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 com.google.edwmigration.dumper.application.dumper.connector.hadoop.oozie; | ||
|
||
import static org.apache.oozie.cli.OozieCLI.ENV_OOZIE_URL; | ||
import static org.apache.oozie.cli.OozieCLI.OOZIE_RETRY_COUNT; | ||
import static org.apache.oozie.cli.OozieCLI.WS_HEADER_PREFIX; | ||
|
||
import java.util.Map; | ||
import org.apache.oozie.cli.OozieCLI; | ||
import org.apache.oozie.cli.OozieCLIException; | ||
import org.apache.oozie.client.AuthOozieClient; | ||
import org.apache.oozie.client.OozieClient; | ||
import org.apache.oozie.client.XOozieClient; | ||
|
||
/** | ||
* Factory does initialization of Oozie client in a similar but simplified way compare to {@link | ||
* OozieCLI#main(String[])}. | ||
*/ | ||
public class OozieClientFactory { | ||
public static XOozieClient createXOozieClient() throws OozieCLIException { | ||
String oozieUrl = getOozieUrl(); | ||
// String authOption = getAuthOption(commandLine); | ||
XOozieClient wc = new AuthOozieClient(oozieUrl, null); | ||
|
||
addHeaders(wc); | ||
setRetryCount(wc); | ||
return wc; | ||
} | ||
|
||
protected static String getOozieUrl() { | ||
String url = null; // commandLine.getOptionValue(OOZIE_OPTION); | ||
if (url == null) { | ||
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
url = System.getenv(ENV_OOZIE_URL); | ||
if (url == null) { | ||
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new IllegalArgumentException( | ||
"Oozie URL is not available neither in command option or in the environment"); | ||
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
return url; | ||
} | ||
|
||
protected static void addHeaders(OozieClient wc) { | ||
// String username = commandLine.getOptionValue(USERNAME); | ||
// String password = commandLine.getOptionValue(PASSWORD); | ||
// if (username != null && password != null) { | ||
// String encoded = Base64.getEncoder().encodeToString((username + ':' + password).getBytes( | ||
// StandardCharsets.UTF_8)); | ||
// wc.setHeader("Authorization", "Basic " + encoded); | ||
// } | ||
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) { | ||
String key = (String) entry.getKey(); | ||
if (key.startsWith(WS_HEADER_PREFIX)) { | ||
String header = key.substring(WS_HEADER_PREFIX.length()); | ||
System.out.println("Header added to Oozie client: " + header); | ||
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
wc.setHeader(header, (String) entry.getValue()); | ||
} | ||
} | ||
} | ||
|
||
protected static void setRetryCount(OozieClient wc) { | ||
String retryCount = System.getProperty(OOZIE_RETRY_COUNT); | ||
if (retryCount != null && !retryCount.isEmpty()) { | ||
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try { | ||
int retry = Integer.parseInt(retryCount.trim()); | ||
wc.setRetryCount(retry); | ||
} catch (Exception ex) { | ||
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
System.err.println( | ||
"Unable to parse the retry settings. May be not an integer [" + retryCount + "]"); | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
.../google/edwmigration/dumper/application/dumper/connector/hadoop/oozie/OozieConnector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2022-2025 Google LLC | ||
* Copyright 2013-2021 CompilerWorks | ||
* | ||
* Licensed 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 com.google.edwmigration.dumper.application.dumper.connector.hadoop.oozie; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.google.edwmigration.dumper.application.dumper.ConnectorArguments; | ||
import com.google.edwmigration.dumper.application.dumper.annotations.RespectsInput; | ||
import com.google.edwmigration.dumper.application.dumper.connector.AbstractConnector; | ||
import com.google.edwmigration.dumper.application.dumper.connector.Connector; | ||
import com.google.edwmigration.dumper.application.dumper.connector.MetadataConnector; | ||
import com.google.edwmigration.dumper.application.dumper.handle.Handle; | ||
import com.google.edwmigration.dumper.application.dumper.task.DumpMetadataTask; | ||
import com.google.edwmigration.dumper.application.dumper.task.FormatTask; | ||
import com.google.edwmigration.dumper.application.dumper.task.Task; | ||
import com.google.edwmigration.dumper.application.dumper.utils.ArchiveNameUtil; | ||
import com.google.edwmigration.dumper.plugin.ext.jdk.annotation.Description; | ||
import java.time.Clock; | ||
import java.util.List; | ||
import javax.annotation.Nonnull; | ||
import org.apache.oozie.client.XOozieClient; | ||
|
||
@AutoService(Connector.class) | ||
@Description("Dumps Jobs history from Oozie.") | ||
@RespectsInput(order = 100, arg = ConnectorArguments.OPT_URI, description = "Oozie URL.") | ||
public class OozieConnector extends AbstractConnector implements MetadataConnector { | ||
public static final String FORMAT_NAME = "oozie.dump.zip"; | ||
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public OozieConnector() { | ||
super("oozie"); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getDefaultFileName(boolean isAssessment, Clock clock) { | ||
return ArchiveNameUtil.getFileNameWithTimestamp(getName(), clock); | ||
} | ||
|
||
@Override | ||
public void addTasksTo(@Nonnull List<? super Task<?>> out, @Nonnull ConnectorArguments arguments) | ||
throws Exception { | ||
out.add(new DumpMetadataTask(arguments, FORMAT_NAME)); | ||
out.add(new FormatTask(FORMAT_NAME)); | ||
out.add(new OozieJobsTask(93)); | ||
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Handle open(@Nonnull ConnectorArguments arguments) throws Exception { | ||
XOozieClient xOozieClient = OozieClientFactory.createXOozieClient(); | ||
return new OozieHandle(xOozieClient); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...com/google/edwmigration/dumper/application/dumper/connector/hadoop/oozie/OozieHandle.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2022-2025 Google LLC | ||
* Copyright 2013-2021 CompilerWorks | ||
* | ||
* Licensed 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 com.google.edwmigration.dumper.application.dumper.connector.hadoop.oozie; | ||
|
||
import com.google.edwmigration.dumper.application.dumper.handle.Handle; | ||
import java.io.IOException; | ||
import org.apache.oozie.client.XOozieClient; | ||
|
||
public class OozieHandle implements Handle { | ||
private final XOozieClient oozieClient; | ||
|
||
public OozieHandle(XOozieClient oozieClient) { | ||
this.oozieClient = oozieClient; | ||
} | ||
|
||
public XOozieClient getOozieClient() { | ||
return oozieClient; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException {} | ||
} |
117 changes: 117 additions & 0 deletions
117
...m/google/edwmigration/dumper/application/dumper/connector/hadoop/oozie/OozieJobsTask.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright 2022-2025 Google LLC | ||
* Copyright 2013-2021 CompilerWorks | ||
* | ||
* Licensed 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 com.google.edwmigration.dumper.application.dumper.connector.hadoop.oozie; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static java.time.LocalDateTime.ofInstant; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.io.ByteSink; | ||
import com.google.edwmigration.dumper.application.dumper.handle.Handle; | ||
import com.google.edwmigration.dumper.application.dumper.task.AbstractTask; | ||
import com.google.edwmigration.dumper.application.dumper.task.TaskRunContext; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Date; | ||
import java.util.List; | ||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
import org.apache.commons.beanutils.PropertyUtils; | ||
import org.apache.commons.csv.CSVFormat; | ||
import org.apache.commons.csv.CSVPrinter; | ||
import org.apache.oozie.client.WorkflowJob; | ||
import org.apache.oozie.client.XOozieClient; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class OozieJobsTask extends AbstractTask<Void> { | ||
private static final Logger LOG = LoggerFactory.getLogger(OozieJobsTask.class); | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
private final int maxDaysToFetch; | ||
|
||
public OozieJobsTask(int maxDaysToFetch) { | ||
super("oozie_jobs.csv"); | ||
Preconditions.checkArgument( | ||
maxDaysToFetch >= 1, | ||
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
String.format("Amount of days must be a positive number. Got %d.", maxDaysToFetch)); | ||
|
||
this.maxDaysToFetch = maxDaysToFetch; | ||
} | ||
|
||
// todo jobs params in filter | ||
// FILTER_NAMES.add(OozieClient.FILTER_CREATED_TIME_START); | ||
// FILTER_NAMES.add(OozieClient.FILTER_CREATED_TIME_END); | ||
@CheckForNull | ||
@Override | ||
protected Void doRun(TaskRunContext context, @Nonnull ByteSink sink, @Nonnull Handle handle) | ||
throws Exception { | ||
final LocalDateTime now = LocalDateTime.now(); // todo fix for unit test | ||
final CSVFormat csvFormat = newCsvFormatForClass(WorkflowJob.class); | ||
final ImmutableList<String> csvHeader = ImmutableList.copyOf(csvFormat.getHeader()); | ||
|
||
try (CSVPrinter printer = csvFormat.print(sink.asCharSink(UTF_8).openBufferedStream())) { | ||
XOozieClient oozieClient = ((OozieHandle) handle).getOozieClient(); | ||
final int batchSize = 1_000; | ||
int offset = 0; | ||
LocalDateTime lastJobEndDate = now; | ||
|
||
LOG.info("Start fetch Oozie jobs for last {}d starts from {}", maxDaysToFetch, now); | ||
|
||
while (ChronoUnit.DAYS.between(now, lastJobEndDate) < maxDaysToFetch) { | ||
List<WorkflowJob> jobsInfo = oozieClient.getJobsInfo(null, offset, batchSize); | ||
sayuzbas-google marked this conversation as resolved.
Show resolved
Hide resolved
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (WorkflowJob workflowJob : jobsInfo) { | ||
Object[] record = toCSVRecord(workflowJob, csvHeader); | ||
printer.printRecord(record); | ||
} | ||
|
||
if (jobsInfo.isEmpty()) { | ||
break; | ||
} | ||
|
||
WorkflowJob lastJob = jobsInfo.get(jobsInfo.size() - 1); | ||
sayuzbas-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (lastJob.getEndTime() == null) { | ||
break; | ||
} | ||
lastJobEndDate = ofInstant(lastJob.getEndTime().toInstant(), ZoneId.systemDefault()); | ||
offset += jobsInfo.size(); | ||
} | ||
|
||
printer.println(); | ||
} | ||
return null; | ||
} | ||
|
||
private Object[] toCSVRecord(WorkflowJob job, ImmutableList<String> header) throws Exception { | ||
vladislav-sidorovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Object[] record = new Object[header.size()]; | ||
for (int i = 0; i < header.size(); i++) { | ||
record[i] = PropertyUtils.getProperty(job, header.get(i)); | ||
if (record[i] != null && record[i] instanceof Date) { | ||
// avoid date formats complexity and use milliseconds | ||
record[i] = ((Date) record[i]).getTime(); | ||
} | ||
if (record[i] != null && record[i] instanceof List) { | ||
// write Actions arrays as json string in csv | ||
record[i] = objectMapper.writeValueAsString(record[i]); | ||
} | ||
} | ||
return record; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.