-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[Fix] logs http basic issue # 9755 #9968
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 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0057b66
# 9755
50a94be
Trigger workflow
d3175f1
Trigger workflow
4160872
# 9755
e84a1e3
# 9755
01e3f21
# 9755
f6d6b82
Merge remote-tracking branch 'upstream/dev' into feature-9755
704d697
Trigger workflow
d62105c
# 9755
0469e63
Merge remote-tracking branch 'upstream/dev' into feature-9755
1fa4063
Code optimization
55f3cbf
Merge remote-tracking branch 'upstream/dev' into feature-9755
013e0ac
Code optimization
63ea988
Code optimization
84e26e9
Code optimization
22cb2be
Update seatunnel-engine/seatunnel-engine-server/src/test/java/org/apa…
wuxiansen 9e6c2ec
import StringUtils
a01750a
Optimize sendGet method
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
217 changes: 217 additions & 0 deletions
217
...ne-server/src/test/java/org/apache/seatunnel/engine/server/rest/RestApiHttpBasicTest.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,217 @@ | ||
| /* | ||
| * 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.engine.server.rest; | ||
|
|
||
| import org.apache.seatunnel.shade.org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import org.apache.seatunnel.engine.common.config.SeaTunnelConfig; | ||
| import org.apache.seatunnel.engine.common.config.server.HttpConfig; | ||
| import org.apache.seatunnel.engine.common.runtime.ExecutionMode; | ||
| import org.apache.seatunnel.engine.common.utils.PassiveCompletableFuture; | ||
| import org.apache.seatunnel.engine.core.dag.logical.LogicalDag; | ||
| import org.apache.seatunnel.engine.core.job.JobImmutableInformation; | ||
| import org.apache.seatunnel.engine.server.AbstractSeaTunnelServerTest; | ||
| import org.apache.seatunnel.engine.server.SeaTunnelServer; | ||
| import org.apache.seatunnel.engine.server.SeaTunnelServerStarter; | ||
| import org.apache.seatunnel.engine.server.TestUtils; | ||
|
|
||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.hazelcast.config.Config; | ||
| import com.hazelcast.internal.serialization.Data; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.net.HttpURLConnection; | ||
| import java.net.URL; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Base64; | ||
| import java.util.Base64.Encoder; | ||
| import java.util.Collections; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_LOGS; | ||
| import static org.apache.seatunnel.engine.server.rest.RestConstant.REST_URL_OVERVIEW; | ||
|
|
||
| /** Test for Rest API with Basic. */ | ||
| class RestApiHttpBasicTest extends AbstractSeaTunnelServerTest { | ||
|
|
||
| private static final int HTTP_PORT = 18081; | ||
| private static final Long JOB_1 = System.currentTimeMillis() + 1L; | ||
| private static final String USER = "admin"; | ||
| private static final String PASS = "admin"; | ||
| private static final String DOMAIN = "http://localhost:" + HTTP_PORT; | ||
|
|
||
| private static final String AUTHORIZATION_HEADER = "Authorization"; | ||
| private static final String BASIC_PREFIX = "Basic "; | ||
|
|
||
| @BeforeAll | ||
| void setUp() { | ||
| String name = this.getClass().getName(); | ||
| Config hazelcastConfig = Config.loadFromString(getHazelcastConfig()); | ||
| hazelcastConfig.setClusterName( | ||
| TestUtils.getClusterName("RestApiServletHttpBasicTest_" + name)); | ||
| SeaTunnelConfig seaTunnelConfig = loadSeaTunnelConfig(); | ||
| seaTunnelConfig.setHazelcastConfig(hazelcastConfig); | ||
| seaTunnelConfig.getEngineConfig().setMode(ExecutionMode.LOCAL); | ||
|
|
||
| HttpConfig httpConfig = seaTunnelConfig.getEngineConfig().getHttpConfig(); | ||
| httpConfig.setEnabled(Boolean.TRUE); | ||
| httpConfig.setPort(HTTP_PORT); | ||
|
|
||
| httpConfig.setEnableBasicAuth(Boolean.TRUE); | ||
| httpConfig.setBasicAuthUsername(USER); | ||
| httpConfig.setBasicAuthPassword(PASS); | ||
|
|
||
| instance = SeaTunnelServerStarter.createHazelcastInstance(seaTunnelConfig); | ||
| nodeEngine = instance.node.nodeEngine; | ||
| server = nodeEngine.getService(SeaTunnelServer.SERVICE_NAME); | ||
| LOGGER = nodeEngine.getLogger(AbstractSeaTunnelServerTest.class); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public void after() { | ||
| // Disable basic auth | ||
| // Because of the ConfigProvider.locateAndGetSeaTunnelConfig() single-case, | ||
| // if you change, other use cases will also change | ||
| // managed via org.apache.seatunnel.engine.common.config.YamlSeaTunnelDomConfigProcessor | ||
| SeaTunnelConfig seaTunnelConfig = loadSeaTunnelConfig(); | ||
| HttpConfig httpConfig = seaTunnelConfig.getEngineConfig().getHttpConfig(); | ||
| httpConfig.setEnableBasicAuth(Boolean.FALSE); | ||
| httpConfig.setBasicAuthUsername(""); | ||
| httpConfig.setBasicAuthPassword(""); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRestApiOverview() throws Exception { | ||
| HttpURLConnection conn = null; | ||
| try { | ||
| URL url = new URL(DOMAIN + REST_URL_OVERVIEW); | ||
| conn = (HttpURLConnection) url.openConnection(); | ||
| setBasicAuth(conn); | ||
|
|
||
| Assertions.assertEquals(200, conn.getResponseCode()); | ||
| Assertions.assertTrue( | ||
| conn.getHeaderFields() | ||
| .get("Content-Type") | ||
| .toString() | ||
| .contains("charset=utf-8")); | ||
| } finally { | ||
| if (conn != null) { | ||
| conn.disconnect(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void testLogRestApiResponseFailure() throws IOException { | ||
| startJob(); | ||
| HttpURLConnection conn = null; | ||
| try { | ||
| URL url = new URL(DOMAIN + REST_URL_LOGS + "?format=JSON"); | ||
| conn = (HttpURLConnection) url.openConnection(); | ||
|
|
||
| Assertions.assertEquals(401, conn.getResponseCode()); | ||
| } finally { | ||
| if (conn != null) { | ||
| conn.disconnect(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void testLogRestApiResponseSuccess() throws IOException { | ||
| startJob(); | ||
| testLogRestApiResponse("JSON"); | ||
| } | ||
|
|
||
| public void setBasicAuth(HttpURLConnection connection) { | ||
| // Basic Auth | ||
| Encoder encoder = Base64.getEncoder(); | ||
| String auth = USER + ":" + PASS; | ||
| String token = encoder.encodeToString(auth.getBytes(StandardCharsets.UTF_8)); | ||
| connection.setRequestProperty(AUTHORIZATION_HEADER, BASIC_PREFIX + token); | ||
| } | ||
|
|
||
| public void testLogRestApiResponse(String format) throws IOException { | ||
| HttpURLConnection conn = null; | ||
| try { | ||
| URL url = new URL(DOMAIN + REST_URL_LOGS + "?format=" + format); | ||
| conn = (HttpURLConnection) url.openConnection(); | ||
| setBasicAuth(conn); | ||
|
|
||
| Assertions.assertEquals(200, conn.getResponseCode()); | ||
| Assertions.assertTrue( | ||
| conn.getHeaderFields() | ||
| .get("Content-Type") | ||
| .toString() | ||
| .contains("charset=utf-8")); | ||
|
|
||
| try (BufferedReader in = | ||
| new BufferedReader(new InputStreamReader(conn.getInputStream()))) { | ||
| // [ { | ||
| // "node" : "localhost:18080", | ||
| // "logLink" : "http://localhost:18080/logs/job-1760939539658.log", | ||
| // "logName" : "job-1760939539658.log" | ||
| // }, { | ||
| // "node" : "localhost:18080", | ||
| // "logLink" : "http://localhost:18080/logs/job-${ctx:ST-JID}.log", | ||
| // "logName" : "job-${ctx:ST-JID}.log" | ||
| // } ] | ||
| String response = in.lines().collect(Collectors.joining()); | ||
| Assertions.assertFalse(StringUtils.isBlank(response)); | ||
| } | ||
|
|
||
| } finally { | ||
| if (conn != null) { | ||
| conn.disconnect(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void startJob() { | ||
| LogicalDag testLogicalDag = | ||
| TestUtils.createTestLogicalPlan( | ||
| "fake_to_console.conf", | ||
| RestApiHttpBasicTest.JOB_1.toString(), | ||
| RestApiHttpBasicTest.JOB_1); | ||
|
|
||
| JobImmutableInformation jobImmutableInformation = | ||
| new JobImmutableInformation( | ||
| RestApiHttpBasicTest.JOB_1, | ||
| "Test", | ||
| nodeEngine.getSerializationService(), | ||
| testLogicalDag, | ||
| Collections.emptyList(), | ||
| Collections.emptyList()); | ||
|
|
||
| Data data = nodeEngine.getSerializationService().toData(jobImmutableInformation); | ||
|
|
||
| PassiveCompletableFuture<Void> voidPassiveCompletableFuture = | ||
| server.getCoordinatorService() | ||
| .submitJob( | ||
| RestApiHttpBasicTest.JOB_1, | ||
| data, | ||
| jobImmutableInformation.isStartWithSavePoint()); | ||
| voidPassiveCompletableFuture.join(); | ||
| } | ||
| } |
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.