-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-13883. Support HTTPS with ozone insight command #9285
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
231496e
HDDS-13883. Support HTTPS with ozone insight command
sarvekshayr b7478b5
Checked HTTPS connection and added robot tests
sarvekshayr e6d482a
Robot test in unsecure failed due to no cleanup after envvars.robot
sarvekshayr a827a5b
Reduced timeout by setting heartbeat interval
sarvekshayr 356c833
Update pom.xml
sarvekshayr 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 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
59 changes: 59 additions & 0 deletions
59
hadoop-ozone/dist/src/main/smoketest/cli/ozone-insight.robot
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,59 @@ | ||
| # 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. | ||
|
|
||
| *** Settings *** | ||
| Documentation Test ozone insight command with HTTP/HTTPS and SPNEGO | ||
| Library BuiltIn | ||
| Resource ../lib/os.robot | ||
| Resource ../commonlib.robot | ||
| Suite Setup Kinit test user testuser testuser.keytab | ||
| Test Timeout 5 minutes | ||
|
|
||
| *** Keywords *** | ||
| Should Not Have Connection Errors | ||
| [Arguments] ${output} | ||
| Should Not Contain ${output} Connection Refused | ||
| Should Not Contain ${output} UnknownHostException | ||
| Should Not Contain ${output} Authentication Failed | ||
| Should Not Contain ${output} 0.0.0.0 | ||
|
|
||
| *** Test Cases *** | ||
| List Insight Points | ||
| ${output} = Execute ozone insight list | ||
| Should Contain ${output} scm.node-manager | ||
| Should Contain ${output} om.key-manager | ||
| Should Contain ${output} datanode.dispatcher | ||
|
|
||
| Test SCM Metrics Retrieval | ||
| ${output} = Execute ozone insight metrics scm.node-manager | ||
|
|
||
| Should Contain ${output} Metrics for `scm.node-manager` | ||
| Should Contain ${output} Node counters | ||
| Should Contain ${output} HB processing stats | ||
| Should Not Have Connection Errors ${output} | ||
|
|
||
| Test OM Metrics Retrieval | ||
| ${output} = Execute ozone insight metrics om.key-manager | ||
|
|
||
| Should Contain ${output} Metrics for `om.key-manager` | ||
| Should Contain ${output} Key related metrics | ||
| Should Contain ${output} Key operation stats | ||
| Should Not Have Connection Errors ${output} | ||
|
|
||
| Test SCM Log Streaming | ||
| ${output} = Execute And Ignore Error timeout 10 ozone insight log scm.node-manager 2>&1 || true | ||
|
|
||
| Should Contain Any ${output} [SCM] SCMNodeManager | ||
| Should Not Have Connection Errors ${output} |
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
118 changes: 118 additions & 0 deletions
118
hadoop-ozone/insight/src/main/java/org/apache/hadoop/ozone/insight/InsightHttpUtils.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,118 @@ | ||
| /* | ||
| * 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.hadoop.ozone.insight; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.InputStreamReader; | ||
| import java.net.ConnectException; | ||
| import java.net.HttpURLConnection; | ||
| import java.net.URL; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.stream.Collectors; | ||
| import javax.security.sasl.AuthenticationException; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdfs.web.URLConnectionFactory; | ||
| import org.apache.hadoop.ozone.OzoneConfigKeys; | ||
|
|
||
| /** | ||
| * Utility class for making HTTP/HTTPS calls with SPNEGO authentication support. | ||
| */ | ||
| public final class InsightHttpUtils { | ||
|
|
||
| private InsightHttpUtils() { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Check if SPNEGO authentication is enabled. | ||
| */ | ||
| public static boolean isSpnegoEnabled(OzoneConfiguration conf) { | ||
| String authType = conf.get(OzoneConfigKeys.OZONE_HTTP_SECURITY_ENABLED_KEY, | ||
| String.valueOf(OzoneConfigKeys.OZONE_HTTP_SECURITY_ENABLED_DEFAULT)); | ||
| return "kerberos".equalsIgnoreCase(authType) || "true".equalsIgnoreCase(authType); | ||
| } | ||
|
|
||
| /** | ||
| * Make an HTTP/HTTPS call with SPNEGO authentication support. | ||
| * | ||
| * @param url The URL to connect to | ||
| * @param conf The Ozone configuration | ||
| * @return HttpURLConnection or null if connection failed | ||
| * @throws IOException if connection fails | ||
| */ | ||
| public static HttpURLConnection openConnection(String url, OzoneConfiguration conf) throws IOException { | ||
| try { | ||
| final URLConnectionFactory connectionFactory = | ||
| URLConnectionFactory.newDefaultURLConnectionFactory(conf); | ||
|
|
||
| boolean isSpnegoEnabled = isSpnegoEnabled(conf); | ||
|
|
||
| return (HttpURLConnection) | ||
| connectionFactory.openConnection(new URL(url), isSpnegoEnabled); | ||
| } catch (ConnectException ex) { | ||
| System.err.println("Connection Refused: " + url); | ||
| return null; | ||
| } catch (AuthenticationException authEx) { | ||
| System.err.println("Authentication Failed. Please make sure you " + | ||
| "have logged in with kinit or disable Ozone security settings."); | ||
| return null; | ||
| } catch (Exception ex) { | ||
| throw new IOException("Failed to connect to " + url, ex); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Read the response from an HttpURLConnection as a String. | ||
| */ | ||
| public static String readResponse(HttpURLConnection httpURLConnection) throws IOException { | ||
| if (httpURLConnection == null) { | ||
| return null; | ||
| } | ||
|
|
||
| int responseCode = httpURLConnection.getResponseCode(); | ||
| if (responseCode != HttpURLConnection.HTTP_OK) { | ||
| throw new IOException("HTTP " + responseCode + ": " + httpURLConnection.getResponseMessage()); | ||
| } | ||
|
|
||
| try (InputStream inputStream = httpURLConnection.getInputStream(); | ||
| InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); | ||
| BufferedReader bufferedReader = new BufferedReader(reader)) { | ||
| return bufferedReader.lines().collect(Collectors.joining("\n")); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Read response as a stream of lines (for streaming endpoints like /logstream). | ||
| */ | ||
| public static BufferedReader getResponseReader(HttpURLConnection httpURLConnection) throws IOException { | ||
| if (httpURLConnection == null) { | ||
| return null; | ||
| } | ||
|
|
||
| int responseCode = httpURLConnection.getResponseCode(); | ||
| if (responseCode != HttpURLConnection.HTTP_OK) { | ||
| throw new IOException("HTTP " + responseCode + ": " + httpURLConnection.getResponseMessage()); | ||
| } | ||
|
|
||
| return new BufferedReader(new InputStreamReader( | ||
| httpURLConnection.getInputStream(), StandardCharsets.UTF_8)); | ||
| } | ||
| } | ||
|
|
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.