-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ingestion) Inject pipeline_name into recipes at runtime (#6833)
- Loading branch information
1 parent
4cba09e
commit 2ef2ad0
Showing
7 changed files
with
80 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
37 changes: 37 additions & 0 deletions
37
metadata-utils/src/main/java/com/linkedin/metadata/utils/IngestionUtils.java
This file contains 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,37 @@ | ||
package com.linkedin.metadata.utils; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
|
||
public class IngestionUtils { | ||
|
||
private static final String PIPELINE_NAME = "pipeline_name"; | ||
|
||
private IngestionUtils() { | ||
} | ||
|
||
/** | ||
* Injects a pipeline_name into a recipe if there isn't a pipeline_name already there. | ||
* The pipeline_name will be the urn of the ingestion source. | ||
* | ||
* @param pipelineName the new pipeline name in the recipe. | ||
* @return a modified recipe JSON string | ||
*/ | ||
public static String injectPipelineName(@Nonnull String originalJson, @Nonnull final String pipelineName) { | ||
try { | ||
final JSONObject jsonRecipe = new JSONObject(originalJson); | ||
boolean hasPipelineName = jsonRecipe.has(PIPELINE_NAME) && jsonRecipe.get(PIPELINE_NAME) != null && !jsonRecipe.get(PIPELINE_NAME).equals(""); | ||
|
||
if (!hasPipelineName) { | ||
jsonRecipe.put(PIPELINE_NAME, pipelineName); | ||
return jsonRecipe.toString(); | ||
} | ||
} catch (JSONException e) { | ||
throw new IllegalArgumentException("Failed to create execution request: Invalid recipe json provided.", e); | ||
} | ||
return originalJson; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
metadata-utils/src/test/java/com/linkedin/metadata/utils/IngestionUtilsTest.java
This file contains 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,29 @@ | ||
package com.linkedin.metadata.utils; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
public class IngestionUtilsTest { | ||
|
||
private final String ingestionSourceUrn = "urn:li:ingestionSource:12345"; | ||
|
||
@Test | ||
public void injectPipelineNameWhenThere() { | ||
String recipe = "{\"source\":{\"type\":\"snowflake\",\"config\":{\"stateful_ingestion\":{\"enabled\":true}}},\"pipeline_name\":\"test\"}"; | ||
|
||
assertEquals(recipe, IngestionUtils.injectPipelineName(recipe, ingestionSourceUrn)); | ||
} | ||
|
||
@Test | ||
public void injectPipelineNameWhenNotThere() { | ||
String recipe = "{\"source\":{\"type\":\"snowflake\",\"config\":{\"stateful_ingestion\":{\"enabled\":true}}}}"; | ||
recipe = IngestionUtils.injectPipelineName(recipe, ingestionSourceUrn); | ||
|
||
assertEquals( | ||
recipe, | ||
"{\"source\":{\"type\":\"snowflake\",\"config\":{\"stateful_ingestion\":{\"enabled\":true}}},\"pipeline_name\":\"urn:li:ingestionSource:12345\"}" | ||
); | ||
} | ||
} |