Skip to content
Open
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
23 changes: 18 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@
<spotbugs-maven-plugin.version>4.9.3.0</spotbugs-maven-plugin.version>
<frontend-maven-plugin.version>1.8.0</frontend-maven-plugin.version>
<guava.version>32.0.1-jre</guava.version>
<hadoop.version>3.4.1</hadoop.version>
<hadoop.version>3.5.0-SNAPSHOT</hadoop.version>
<jdk.tools.version>1.8</jdk.tools.version>
<jersey.version>1.19.4</jersey.version>
<jersey.version>2.46</jersey.version>
<jettison.version>1.5.4</jettison.version>
<jsr305.version>3.0.0</jsr305.version>
<junit.version>4.13.2</junit.version>
<junit.jupiter.version>5.9.3</junit.jupiter.version>
<leveldbjni-all.version>1.8</leveldbjni-all.version>
<lifecycle-mapping.version>1.0.0</lifecycle-mapping.version>
<maven-checkstyle-plugin.version>3.1.1</maven-checkstyle-plugin.version>
Expand Down Expand Up @@ -764,6 +765,18 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
Expand All @@ -780,13 +793,13 @@
<version>${jettison.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- BouncyCastle should be in default scope to make their way to tez.tar.gz since Hadoop 3.4.1 -->
Expand Down
6 changes: 3 additions & 3 deletions tez-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.Set;

import javax.annotation.Nullable;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;

import org.apache.hadoop.classification.InterfaceAudience.Private;
Expand All @@ -52,11 +54,6 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;

import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
Expand Down Expand Up @@ -212,7 +209,7 @@ public DAGStatus waitForCompletionWithStatusUpdates(
@Override
public void close() throws IOException {
if (httpClient != null) {
httpClient.destroy();
httpClient.close();
httpClient = null;
}
if (timelineReaderStrategy != null) {
Expand Down Expand Up @@ -426,26 +423,14 @@ protected Map<String, VertexTaskStats> parseTaskStatsForVertexes()
@VisibleForTesting
protected JSONObject getJsonRootEntity(String url) throws TezException {
try {
WebResource wr = getCachedHttpClient().resource(url);
ClientResponse response = wr.accept(MediaType.APPLICATION_JSON_TYPE)
.type(MediaType.APPLICATION_JSON_TYPE)
.get(ClientResponse.class);

final ClientResponse.Status clientResponseStatus = response.getClientResponseStatus();
if (clientResponseStatus != ClientResponse.Status.OK) {
throw new TezException("Failed to get response from YARN Timeline:" +
" errorCode:" + clientResponseStatus + ", url:" + url);
}

return response.getEntity(JSONObject.class);
} catch (ClientHandlerException e) {
Client client = getCachedHttpClient();
WebTarget target = client.target(url);
String json = target.request(MediaType.APPLICATION_JSON_TYPE)
.accept(MediaType.APPLICATION_JSON_TYPE)
.get(String.class);
return new JSONObject(json);
} catch (Exception e) {
throw new TezException("Error processing response from YARN Timeline", e);
} catch (UniformInterfaceException e) {
throw new TezException("Error accessing content from YARN Timeline - unexpected response", e);
} catch (IllegalArgumentException e) {
throw new TezException("Error accessing content from YARN Timeline - invalid url", e);
} catch (IOException e) {
throw new TezException("Error failed to get http client", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,27 @@
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.GeneralSecurityException;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.authentication.client.AuthenticatedURL;
import org.apache.hadoop.security.authentication.client.Authenticator;
import org.apache.hadoop.security.authentication.client.ConnectionConfigurator;
import org.apache.hadoop.security.ssl.SSLFactory;
import org.apache.tez.common.ReflectionUtils;
import org.apache.tez.dag.api.TezException;

import com.google.common.annotations.VisibleForTesting;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory;
import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
import com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider;

import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -164,7 +160,7 @@ public Client getHttpClient() throws IOException {
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
UserGroupInformation realUgi = ugi.getRealUser();
String doAsUser;
ClientConfig clientConfig = new DefaultClientConfig(JSONRootElementProvider.App.class);
ClientConfig clientConfig = new ClientConfig().register(JacksonFeature.class);
ConnectionConfigurator connectionConfigurator = getNewConnectionConf(useHttps,
connTimeout, sslFactory);

Expand All @@ -181,14 +177,7 @@ public Client getHttpClient() throws IOException {
doAsUser = null;
}

HttpURLConnectionFactory connectionFactory;
try {
connectionFactory = new TokenAuthenticatedURLConnectionFactory(connectionConfigurator, authenticator,
doAsUser);
} catch (TezException e) {
throw new IOException("Fail to create TokenAuthenticatedURLConnectionFactory", e);
}
return new Client(new URLConnectionClientHandler(connectionFactory), clientConfig);
return ClientBuilder.newClient(clientConfig);
}

private static Authenticator getTokenAuthenticator() throws TezException {
Expand All @@ -203,42 +192,6 @@ private static Authenticator getTokenAuthenticator() throws TezException {
return ReflectionUtils.createClazzInstance(authenticatorClazzName);
}

private static class TokenAuthenticatedURLConnectionFactory implements HttpURLConnectionFactory {

private final Authenticator authenticator;
private final ConnectionConfigurator connConfigurator;
private final String doAsUser;
private final AuthenticatedURL.Token token;

public TokenAuthenticatedURLConnectionFactory(ConnectionConfigurator connConfigurator,
Authenticator authenticator,
String doAsUser) throws TezException {
this.connConfigurator = connConfigurator;
this.authenticator = authenticator;
this.doAsUser = doAsUser;
this.token = ReflectionUtils.createClazzInstance(
DELEGATION_TOKEN_AUTHENTICATED_URL_TOKEN_CLASS_NAME, null, null);
}

@Override
public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
try {
AuthenticatedURL authenticatedURL= ReflectionUtils.createClazzInstance(
DELEGATION_TOKEN_AUTHENTICATED_URL_CLAZZ_NAME, new Class[] {
delegationTokenAuthenticatorClazz,
ConnectionConfigurator.class
}, new Object[] {
authenticator,
connConfigurator
});
return ReflectionUtils.invokeMethod(authenticatedURL,
delegationTokenAuthenticateURLOpenConnectionMethod, url, token, doAsUser);
} catch (Exception e) {
throw new IOException(e);
}
}
}

@Override
public void close() {
if (sslFactory != null) {
Expand All @@ -265,31 +218,11 @@ public TimelineReaderPseudoAuthenticatedStrategy(final Configuration conf,

@Override
public Client getHttpClient() {
ClientConfig config = new DefaultClientConfig(JSONRootElementProvider.App.class);
HttpURLConnectionFactory urlFactory = new PseudoAuthenticatedURLConnectionFactory(connectionConf);
return new Client(new URLConnectionClientHandler(urlFactory), config);
ClientConfig config = new ClientConfig().register(JacksonFeature.class);
return ClientBuilder.newClient(config);
}

@VisibleForTesting
protected static class PseudoAuthenticatedURLConnectionFactory implements HttpURLConnectionFactory {
private final ConnectionConfigurator connectionConf;

public PseudoAuthenticatedURLConnectionFactory(ConnectionConfigurator connectionConf) {
this.connectionConf = connectionConf;
}

@Override
public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
String tokenString = (url.getQuery() == null ? "?" : "&") + "user.name=" +
URLEncoder.encode(UserGroupInformation.getCurrentUser().getShortUserName(), "UTF8");

HttpURLConnection httpURLConnection =
(HttpURLConnection) (new URL(url + tokenString)).openConnection();
this.connectionConf.configure(httpURLConnection);

return httpURLConnection;
}
}
// PseudoAuthenticatedURLConnectionFactory removed in Jersey 2 migration

@Override
public void close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@

import static org.mockito.Mockito.mock;

import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.authentication.client.ConnectionConfigurator;
import org.apache.tez.dag.api.TezException;
import org.apache.tez.dag.api.client.TimelineReaderFactory.TimelineReaderPseudoAuthenticatedStrategy;

Expand All @@ -48,15 +43,11 @@ public void testShouldUseTokenDelegationAuthStrategyForHadoop26() throws TezExce
}

@Test(timeout = 5000)
public void testPseudoAuthenticatorConnectionUrlShouldHaveUserName() throws Exception {
ConnectionConfigurator connConf = mock(ConnectionConfigurator.class);
TimelineReaderPseudoAuthenticatedStrategy.PseudoAuthenticatedURLConnectionFactory
connectionFactory = new TimelineReaderPseudoAuthenticatedStrategy
.PseudoAuthenticatedURLConnectionFactory(connConf);
String inputUrl = "http://host:8080/path";
String expectedUrl = inputUrl + "?user.name=" + UserGroupInformation.getCurrentUser().getShortUserName();
HttpURLConnection httpURLConnection = connectionFactory.getHttpURLConnection(new URL(inputUrl));
Assert.assertEquals(expectedUrl, httpURLConnection.getURL().toString());
public void testPseudoStrategyCreatesJersey2Client() {
TimelineReaderPseudoAuthenticatedStrategy strategy =
new TimelineReaderPseudoAuthenticatedStrategy(new Configuration(), false, 1000);
Assert.assertNotNull(strategy.getHttpClient());
strategy.close();
}

}
15 changes: 13 additions & 2 deletions tez-plugins/tez-history-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,19 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
Expand Down
Loading