Skip to content

Commit

Permalink
YARN-9801. SchedConfCli does not work wiwith https mode. Contributed …
Browse files Browse the repository at this point in the history
…by Prabhu Joseph
  • Loading branch information
sunilgovind committed Oct 1, 2019
1 parent 425a6c8 commit 99cd757
Showing 1 changed file with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory;
import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.MissingArgumentException;
Expand All @@ -31,6 +33,8 @@
import org.apache.hadoop.classification.InterfaceStability.Unstable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.security.authentication.client.AuthenticatedURL;
import org.apache.hadoop.security.ssl.SSLFactory;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
Expand All @@ -41,6 +45,9 @@

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -156,7 +163,12 @@ public int run(String[] args) throws Exception {
@VisibleForTesting
int formatSchedulerConf(String webAppAddress, WebResource resource)
throws Exception {
Client webServiceClient = Client.create();
Configuration conf = getConf();
SSLFactory clientSslFactory = null;
if (YarnConfiguration.useHttps(conf)) {
clientSslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
}
Client webServiceClient = createWebServiceClient(clientSslFactory);
ClientResponse response = null;
resource = (resource != null) ? resource :
webServiceClient.resource(webAppAddress);
Expand Down Expand Up @@ -194,14 +206,24 @@ int formatSchedulerConf(String webAppAddress, WebResource resource)
if (response != null) {
response.close();
}
webServiceClient.destroy();
if (webServiceClient != null) {
webServiceClient.destroy();
}
if (clientSslFactory != null) {
clientSslFactory.destroy();
}
}
}

@VisibleForTesting
int updateSchedulerConfOnRMNode(String webAppAddress,
SchedConfUpdateInfo updateInfo) throws Exception {
Client webServiceClient = Client.create();
Configuration conf = getConf();
SSLFactory clientSslFactory = null;
if (YarnConfiguration.useHttps(conf)) {
clientSslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
}
Client webServiceClient = createWebServiceClient(clientSslFactory);
ClientResponse response = null;
WebResource resource = webServiceClient.resource(webAppAddress);

Expand Down Expand Up @@ -236,10 +258,42 @@ int updateSchedulerConfOnRMNode(String webAppAddress,
if (response != null) {
response.close();
}
webServiceClient.destroy();
if (webServiceClient != null) {
webServiceClient.destroy();
}
if (clientSslFactory != null) {
clientSslFactory.destroy();
}
}
}

private Client createWebServiceClient(SSLFactory clientSslFactory) {
Client webServiceClient = new Client(new URLConnectionClientHandler(
new HttpURLConnectionFactory() {
@Override
public HttpURLConnection getHttpURLConnection(URL url)
throws IOException {
AuthenticatedURL.Token token = new AuthenticatedURL.Token();
AuthenticatedURL aUrl;
HttpURLConnection conn = null;
try {
if (clientSslFactory != null) {
clientSslFactory.init();
aUrl = new AuthenticatedURL(null, clientSslFactory);
} else {
aUrl = new AuthenticatedURL();
}
conn = aUrl.openConnection(url, token);
} catch (Exception e) {
throw new IOException(e);
}
return conn;
}
}));
webServiceClient.setChunkedEncodingSize(null);
return webServiceClient;
}


@VisibleForTesting
void addQueues(String args, SchedConfUpdateInfo updateInfo) {
Expand Down

0 comments on commit 99cd757

Please sign in to comment.