-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][Seatunnel-web]Add support to configure placeholder with def…
…ault value in the job config. (#208)
- Loading branch information
1 parent
94d8a39
commit 70e526a
Showing
12 changed files
with
276 additions
and
176 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
120 changes: 120 additions & 0 deletions
120
...nnel-server/seatunnel-app/src/test/java/org/apache/seatunnel/app/utils/JobUtilsTests.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,120 @@ | ||
/* | ||
* 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.seatunnel.app.utils; | ||
|
||
import org.apache.seatunnel.shade.com.typesafe.config.Config; | ||
import org.apache.seatunnel.shade.com.typesafe.config.ConfigFactory; | ||
|
||
import org.apache.seatunnel.app.domain.request.job.JobExecParam; | ||
import org.apache.seatunnel.server.common.SeatunnelException; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class JobUtilsTests { | ||
|
||
@Test | ||
public void testReplaceJobConfigPlaceholders_AllJobConfigPlaceholdersReplaced() { | ||
String jobConfigContent = | ||
"job.mode=${jobModeParam:BATCH}\ncheckpoint.interval=30\njob.name=${jobNameParam}"; | ||
Map<String, String> paramValues = new HashMap<>(); | ||
paramValues.put("jobModeParam", "STREAMING"); | ||
paramValues.put("jobNameParam", "newJob"); | ||
JobExecParam jobExecParam = getJobExecParam(paramValues); | ||
|
||
String expected = "job.mode=STREAMING\ncheckpoint.interval=30\njob.name=newJob"; | ||
String actual = JobUtils.replaceJobConfigPlaceholders(jobConfigContent, jobExecParam); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void testReplaceJobConfigPlaceholders_JobConfig_PlaceholdersRepeat() { | ||
String jobConfigContent = | ||
"job.mode=${jobModeParam:BATCH}\ncheckpoint.interval=30\njob.name=${jobModeParam}"; | ||
Map<String, String> paramValues = new HashMap<>(); | ||
paramValues.put("jobModeParam", "STREAMING"); | ||
JobExecParam jobExecParam = getJobExecParam(paramValues); | ||
|
||
String expected = "job.mode=STREAMING\ncheckpoint.interval=30\njob.name=STREAMING"; | ||
String actual = JobUtils.replaceJobConfigPlaceholders(jobConfigContent, jobExecParam); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void testReplaceJobConfigPlaceholdersUsed() { | ||
String jobConfigContent = | ||
"job.mode=${jobModeParam:BATCH}\ncheckpoint.interval=30\njob.name=${jobNameParam:DefaultJob}"; | ||
Map<String, String> paramValues = new HashMap<>(); | ||
paramValues.put("jobModeParam", "STREAMING"); | ||
JobExecParam jobExecParam = getJobExecParam(paramValues); | ||
|
||
String expected = "job.mode=STREAMING\ncheckpoint.interval=30\njob.name=DefaultJob"; | ||
String actual = JobUtils.replaceJobConfigPlaceholders(jobConfigContent, jobExecParam); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void testReplaceJobConfigPlaceholders_NoDefaultValueThrowsException() { | ||
String jobConfigContent = | ||
"job.mode=${jobModeParam}\ncheckpoint.interval=30\njob.name=${jobNameParam}"; | ||
Map<String, String> paramValues = new HashMap<>(); | ||
paramValues.put("jobModeParam", "STREAMING"); | ||
JobExecParam jobExecParam = getJobExecParam(paramValues); | ||
|
||
assertThrows( | ||
SeatunnelException.class, | ||
() -> { | ||
JobUtils.replaceJobConfigPlaceholders(jobConfigContent, jobExecParam); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testReplaceJobConfigPlaceholders_NoJobConfigPlaceholders() { | ||
String jobConfigContent = "job.mode=STREAMING\ncheckpoint.interval=30\njob.name=newJob"; | ||
Map<String, String> paramValues = new HashMap<>(); | ||
JobExecParam jobExecParam = getJobExecParam(paramValues); | ||
|
||
String expected = "job.mode=STREAMING\ncheckpoint.interval=30\njob.name=newJob"; | ||
String actual = JobUtils.replaceJobConfigPlaceholders(jobConfigContent, jobExecParam); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void testParseConfigWithPlaceHolders() { | ||
String transformConfig = | ||
"{\"log.print.data\":\"true\",\"log.print.delay.ms\":\"${logPrintDelayMs:100}\"}"; | ||
Config config = ConfigFactory.parseString(transformConfig); | ||
assertNotNull(config); | ||
} | ||
|
||
private static @NotNull JobExecParam getJobExecParam(Map<String, String> paramValues) { | ||
JobExecParam jobExecParam = new JobExecParam(); | ||
jobExecParam.setPlaceholderValues(paramValues); | ||
return jobExecParam; | ||
} | ||
} |
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
Oops, something went wrong.