Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ OZONE-SITE.XML_hdds.scm.replication.over.replicated.interval=5s
OZONE-SITE.XML_hdds.scm.wait.time.after.safemode.exit=30s
OZONE-SITE.XML_ozone.scm.stale.node.interval=30s
OZONE-SITE.XML_ozone.scm.dead.node.interval=45s
OZONE-SITE.XML_hdds.heartbeat.interval=5s
OZONE-SITE.XML_hdds.container.report.interval=60s
OZONE-SITE.XML_ozone.scm.close.container.wait.duration=5s

Expand Down
1 change: 1 addition & 0 deletions hadoop-ozone/dist/src/main/compose/ozonesecure/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ execute_command_in_container kms hadoop key create ${OZONE_BUCKET_KEY_NAME}

execute_robot_test scm kinit.robot

execute_robot_test scm cli/ozone-insight.robot
execute_robot_test scm basic

execute_robot_test scm security
Expand Down
19 changes: 19 additions & 0 deletions hadoop-ozone/dist/src/main/smoketest/cli/envvars.robot
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,31 @@
*** Settings ***
Documentation Test ozone envvars command
Library BuiltIn
Library OperatingSystem
Resource ../commonlib.robot
Test Timeout 5 minutes
Suite Setup Save Environment
Suite Teardown Restore Environment

*** Variables ***
${OZONE_HOME} /opt/hadoop

*** Keywords ***
Save Environment
${saved} = Get Environment Variables
Set Suite Variable ${SAVED_ENV} ${saved}

Restore Environment
FOR ${key} IN
... HADOOP_HOME HADOOP_CONF_DIR HADOOP_LIBEXEC_DIR
... OZONE_HOME OZONE_CONF_DIR OZONE_LIBEXEC_DIR OZONE_DEPRECATION_WARNING
IF '${key}' in ${SAVED_ENV}
Set Environment Variable ${key} ${SAVED_ENV}[${key}]
ELSE
Run Keyword And Ignore Error Remove Environment Variable ${key}
END
END

*** Test Cases ***
Ignores deprecated vars if new ones are set
Set Environment Variable HADOOP_HOME /usr/local/hadoop
Expand Down
59 changes: 59 additions & 0 deletions hadoop-ozone/dist/src/main/smoketest/cli/ozone-insight.robot
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}
11 changes: 6 additions & 5 deletions hadoop-ozone/insight/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.ozone</groupId>
<artifactId>ozone</artifactId>
<artifactId>hdds-hadoop-dependency-client</artifactId>
<version>2.2.0-SNAPSHOT</version>
<relativePath>../../hadoop-hdds/hadoop-dependency-client</relativePath>
</parent>
<artifactId>ozone-insight</artifactId>
<version>2.2.0-SNAPSHOT</version>
Expand All @@ -35,12 +36,12 @@
<artifactId>picocli</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ozone</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,26 @@

package org.apache.hadoop.ozone.insight;

import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HTTPS_ADDRESS_KEY;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HTTPS_BIND_PORT_DEFAULT;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HTTP_ADDRESS_KEY;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HTTP_BIND_HOST_DEFAULT;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HTTP_BIND_PORT_DEFAULT;
import static org.apache.hadoop.hdds.server.http.HttpServer2.HTTPS_SCHEME;
import static org.apache.hadoop.hdds.server.http.HttpServer2.HTTP_SCHEME;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HTTPS_ADDRESS_KEY;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HTTPS_BIND_PORT_DEFAULT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HTTP_ADDRESS_KEY;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HTTP_BIND_HOST_DEFAULT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_HTTP_BIND_PORT_DEFAULT;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.ozone.insight.Component.Type;
import org.apache.hadoop.hdds.server.http.HttpConfig;
import org.apache.hadoop.ozone.insight.datanode.DatanodeDispatcherInsight;
import org.apache.hadoop.ozone.insight.datanode.RatisInsight;
import org.apache.hadoop.ozone.insight.om.KeyManagerInsight;
Expand Down Expand Up @@ -62,25 +75,85 @@ public InsightPoint getInsight(OzoneConfiguration configuration,
* Utility to get the host base on a component.
*/
public String getHost(OzoneConfiguration conf, Component component) {
HttpConfig.Policy policy = HttpConfig.getHttpPolicy(conf);
String protocol = policy.isHttpsEnabled() ? HTTPS_SCHEME : HTTP_SCHEME;

if (component.getHostname() != null) {
return "http://" + component.getHostname() + ":" + component.getPort();
} else if (component.getName() == Type.SCM) {
Optional<String> scmHost =
HddsUtils.getHostNameFromConfigKeys(conf,
ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_ADDRESS_KEY,
ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY);

return "http://" + scmHost.get() + ":9876";
} else if (component.getName() == Type.OM) {
Optional<String> omHost =
HddsUtils.getHostNameFromConfigKeys(conf,
OMConfigKeys.OZONE_OM_ADDRESS_KEY);
return "http://" + omHost.get() + ":9874";
} else {
return protocol + "://" + component.getHostname() + ":" + component.getPort();
}

String address = getComponentAddress(conf, component.getName(), policy);
return protocol + "://" + address;
}

/**
* Get the component address based on HTTP policy.
*/
private String getComponentAddress(OzoneConfiguration conf,
Component.Type componentType, HttpConfig.Policy policy) {
boolean isHttpsEnabled = policy.isHttpsEnabled();
String address;

switch (componentType) {
case SCM:
if (isHttpsEnabled) {
address = conf.get(OZONE_SCM_HTTPS_ADDRESS_KEY, OZONE_SCM_HTTP_BIND_HOST_DEFAULT + ":" +
OZONE_SCM_HTTPS_BIND_PORT_DEFAULT);
} else {
address = conf.get(OZONE_SCM_HTTP_ADDRESS_KEY, OZONE_SCM_HTTP_BIND_HOST_DEFAULT + ":" +
OZONE_SCM_HTTP_BIND_PORT_DEFAULT);
}

// Fallback to RPC hostname
if (getHostOnly(address).equals(OZONE_SCM_HTTP_BIND_HOST_DEFAULT)) {
Optional<String> scmHost = HddsUtils.getHostNameFromConfigKeys(conf,
ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_ADDRESS_KEY,
ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY);
if (scmHost.isPresent()) {
return scmHost.get() + ":" + getPort(address);
}
}
return address;

case OM:
if (isHttpsEnabled) {
address = conf.get(OZONE_OM_HTTPS_ADDRESS_KEY, OZONE_OM_HTTP_BIND_HOST_DEFAULT + ":" +
OZONE_OM_HTTPS_BIND_PORT_DEFAULT);
} else {
address = conf.get(OZONE_OM_HTTP_ADDRESS_KEY, OZONE_OM_HTTP_BIND_HOST_DEFAULT + ":" +
OZONE_OM_HTTP_BIND_PORT_DEFAULT);
}

// Fallback to RPC hostname
if (getHostOnly(address).equals(OZONE_OM_HTTP_BIND_HOST_DEFAULT)) {
Optional<String> omHost = HddsUtils.getHostNameFromConfigKeys(conf,
OMConfigKeys.OZONE_OM_ADDRESS_KEY);
if (omHost.isPresent()) {
return omHost.get() + ":" + getPort(address);
}
}
return address;

default:
throw new IllegalArgumentException(
"Component type is not supported: " + component.getName());
"Component type is not supported: " + componentType);
}
}

/**
* Extract hostname from address string.
* e.g. Input: "0.0.0.0:9876" -> Output: "0.0.0.0"
*/
private String getHostOnly(String address) {
return address.split(":", 2)[0];
}

/**
* Extract port from address string.
* e.g. Input: "0.0.0.0:9876" -> Output: "9876"
*/
private String getPort(String address) {
return address.split(":", 2)[1];
}

public Map<String, InsightPoint> createInsightPoints(
Expand Down
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));
}
}

Loading