Skip to content

Commit 27ffec7

Browse files
committed
YARN-8778. Add command line interface to invoke interactive docker shell. Contributed by Eric Yang
1 parent 397f523 commit 27ffec7

File tree

15 files changed

+455
-65
lines changed

15 files changed

+455
-65
lines changed

LICENSE.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,3 +2813,43 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
28132813
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
28142814
License for the specific language governing permissions and limitations under
28152815
the License.
2816+
2817+
--------------------------------------------------------------------------------
2818+
Jline 3.9.0
2819+
The binary distribution of this product bundles these dependencies under the
2820+
following license:
2821+
2822+
Copyright (c) 2002-2018, the original author or authors.
2823+
All rights reserved.
2824+
2825+
http://www.opensource.org/licenses/bsd-license.php
2826+
2827+
Redistribution and use in source and binary forms, with or
2828+
without modification, are permitted provided that the following
2829+
conditions are met:
2830+
2831+
Redistributions of source code must retain the above copyright
2832+
notice, this list of conditions and the following disclaimer.
2833+
2834+
Redistributions in binary form must reproduce the above copyright
2835+
notice, this list of conditions and the following disclaimer
2836+
in the documentation and/or other materials provided with
2837+
the distribution.
2838+
2839+
Neither the name of JLine nor the names of its contributors
2840+
may be used to endorse or promote products derived from this
2841+
software without specific prior written permission.
2842+
2843+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2844+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
2845+
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
2846+
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
2847+
EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
2848+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
2849+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2850+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2851+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2852+
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2853+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
2854+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2855+
OF THE POSSIBILITY OF SUCH DAMAGE.

NOTICE.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,17 @@ which has the following notices:
614614
Expert Group and released to the public domain, as explained at
615615
http://creativecommons.org/publicdomain/zero/1.0/
616616

617-
618617
The source and binary distribution of this product bundles modified version of
619618
github.com/awslabs/aws-js-s3-explorer licensed under Apache 2.0 license
620619
with the following notice:
621620

622621
AWS JavaScript S3 Explorer
623-
Copyright 2014-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
622+
Copyright 2014-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
623+
624+
The binary distribution of this product bundles binaries of
625+
jline 3.9.0 (https://github.com/jline/jline3)
626+
627+
* LICENSE:
628+
* license/LICENSE.jline3.txt (BSD License)
629+
* HOMEPAGE:
630+
* https://github.com/jline/jline3

hadoop-client-modules/hadoop-client-minicluster/pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,19 @@
788788
<filter>
789789
<artifact>org.eclipse.jetty.websocket:javax-websocket-server-impl</artifact>
790790
<excludes>
791-
<exclude>*</exclude>
791+
<exclude>*/**</exclude>
792+
</excludes>
793+
</filter>
794+
<filter>
795+
<artifact>org.eclipse.jetty.websocket:websocket-client</artifact>
796+
<excludes>
797+
<exclude>*/**</exclude>
798+
</excludes>
799+
</filter>
800+
<filter>
801+
<artifact>org.eclipse.jetty:jetty-io</artifact>
802+
<excludes>
803+
<exclude>*/**</exclude>
792804
</excludes>
793805
</filter>
794806
</filters>

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/main/java/org/apache/hadoop/mapred/ResourceMgrDelegate.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.apache.hadoop.yarn.api.records.QueueUserACLInfo;
7171
import org.apache.hadoop.yarn.api.records.Resource;
7272
import org.apache.hadoop.yarn.api.records.ResourceTypeInfo;
73+
import org.apache.hadoop.yarn.api.records.ShellContainerCommand;
7374
import org.apache.hadoop.yarn.api.records.SignalContainerCommand;
7475
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
7576
import org.apache.hadoop.yarn.api.records.YarnClusterMetrics;
@@ -560,4 +561,10 @@ public Map<String, Set<NodeAttribute>> getNodeToAttributes(
560561
Set<String> hostNames) throws YarnException, IOException {
561562
return client.getNodeToAttributes(hostNames);
562563
}
564+
565+
@Override
566+
public void shellToContainer(ContainerId containerId,
567+
ShellContainerCommand command) throws IOException {
568+
throw new IOException("Operation is not supported.");
569+
}
563570
}

hadoop-project/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<junit.jupiter.version>5.3.1</junit.jupiter.version>
161161
<junit.vintage.version>5.3.1</junit.vintage.version>
162162
<junit.platform.version>1.3.1</junit.platform.version>
163+
<jline.version>3.9.0</jline.version>
163164
</properties>
164165

165166
<dependencyManagement>
@@ -696,6 +697,11 @@
696697
</exclusion>
697698
</exclusions>
698699
</dependency>
700+
<dependency>
701+
<groupId>org.eclipse.jetty.websocket</groupId>
702+
<artifactId>websocket-client</artifactId>
703+
<version>${jetty.version}</version>
704+
</dependency>
699705
<dependency>
700706
<groupId>javax.servlet.jsp</groupId>
701707
<artifactId>jsp-api</artifactId>
@@ -1177,6 +1183,11 @@
11771183
</exclusion>
11781184
</exclusions>
11791185
</dependency>
1186+
<dependency>
1187+
<groupId>org.jline</groupId>
1188+
<artifactId>jline</artifactId>
1189+
<version>${jline.version}</version>
1190+
</dependency>
11801191
<dependency>
11811192
<groupId>org.hsqldb</groupId>
11821193
<artifactId>hsqldb</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.yarn.api.records;
20+
21+
import org.apache.hadoop.classification.InterfaceAudience.Public;
22+
import org.apache.hadoop.classification.InterfaceStability.Evolving;
23+
24+
/**
25+
* Enumeration of various signal container commands.
26+
*/
27+
@Public
28+
@Evolving
29+
public enum ShellContainerCommand {
30+
BASH,
31+
SH
32+
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/service/client/ApiServiceClient.java

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.io.File;
2222
import java.io.IOException;
2323
import java.net.URI;
24-
import java.nio.charset.StandardCharsets;
25-
import java.security.PrivilegedExceptionAction;
2624
import java.text.MessageFormat;
2725
import java.util.List;
2826
import java.util.Map;
@@ -40,13 +38,12 @@
4038
import org.apache.hadoop.fs.FileSystem;
4139
import org.apache.hadoop.fs.Path;
4240
import org.apache.hadoop.security.UserGroupInformation;
43-
import org.apache.hadoop.security.authentication.client.AuthenticationException;
44-
import org.apache.hadoop.security.authentication.util.KerberosUtil;
4541
import org.apache.hadoop.yarn.api.ApplicationConstants;
4642
import org.apache.hadoop.yarn.api.records.ApplicationId;
4743
import org.apache.hadoop.yarn.api.records.ApplicationReport;
4844
import org.apache.hadoop.yarn.client.api.AppAdminClient;
4945
import org.apache.hadoop.yarn.client.api.YarnClient;
46+
import org.apache.hadoop.yarn.client.util.YarnClientUtils;
5047
import org.apache.hadoop.yarn.conf.YarnConfiguration;
5148
import org.apache.hadoop.yarn.exceptions.YarnException;
5249
import org.apache.hadoop.yarn.service.api.records.Component;
@@ -60,11 +57,6 @@
6057
import org.apache.hadoop.yarn.service.utils.ServiceApiUtil;
6158
import org.apache.hadoop.yarn.util.RMHAUtils;
6259
import org.eclipse.jetty.util.UrlEncoded;
63-
import org.ietf.jgss.GSSContext;
64-
import org.ietf.jgss.GSSException;
65-
import org.ietf.jgss.GSSManager;
66-
import org.ietf.jgss.GSSName;
67-
import org.ietf.jgss.Oid;
6860
import org.slf4j.Logger;
6961
import org.slf4j.LoggerFactory;
7062

@@ -92,54 +84,6 @@ public class ApiServiceClient extends AppAdminClient {
9284
super.serviceInit(configuration);
9385
}
9486

95-
/**
96-
* Generate SPNEGO challenge request token.
97-
*
98-
* @param server - hostname to contact
99-
* @throws IOException
100-
* @throws InterruptedException
101-
*/
102-
String generateToken(String server) throws IOException, InterruptedException {
103-
UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
104-
LOG.debug("The user credential is {}", currentUser);
105-
String challenge = currentUser
106-
.doAs(new PrivilegedExceptionAction<String>() {
107-
@Override
108-
public String run() throws Exception {
109-
try {
110-
// This Oid for Kerberos GSS-API mechanism.
111-
Oid mechOid = KerberosUtil.getOidInstance("GSS_KRB5_MECH_OID");
112-
GSSManager manager = GSSManager.getInstance();
113-
// GSS name for server
114-
GSSName serverName = manager.createName("HTTP@" + server,
115-
GSSName.NT_HOSTBASED_SERVICE);
116-
// Create a GSSContext for authentication with the service.
117-
// We're passing client credentials as null since we want them to
118-
// be read from the Subject.
119-
GSSContext gssContext = manager.createContext(
120-
serverName.canonicalize(mechOid), mechOid, null,
121-
GSSContext.DEFAULT_LIFETIME);
122-
gssContext.requestMutualAuth(true);
123-
gssContext.requestCredDeleg(true);
124-
// Establish context
125-
byte[] inToken = new byte[0];
126-
byte[] outToken = gssContext.initSecContext(inToken, 0,
127-
inToken.length);
128-
gssContext.dispose();
129-
// Base64 encoded and stringified token for server
130-
LOG.debug("Got valid challenge for host {}", serverName);
131-
return new String(BASE_64_CODEC.encode(outToken),
132-
StandardCharsets.US_ASCII);
133-
} catch (GSSException | IllegalAccessException
134-
| NoSuchFieldException | ClassNotFoundException e) {
135-
LOG.error("Error: {}", e);
136-
throw new AuthenticationException(e);
137-
}
138-
}
139-
});
140-
return challenge;
141-
}
142-
14387
/**
14488
* Calculate Resource Manager address base on working REST API.
14589
*/
@@ -177,7 +121,7 @@ String getRMWebAddress() {
177121
.resource(sb.toString()).type(MediaType.APPLICATION_JSON);
178122
if (useKerberos) {
179123
String[] server = host.split(":");
180-
String challenge = generateToken(server[0]);
124+
String challenge = YarnClientUtils.generateToken(server[0]);
181125
builder.header(HttpHeaders.AUTHORIZATION, "Negotiate " +
182126
challenge);
183127
LOG.debug("Authorization: Negotiate {}", challenge);
@@ -289,7 +233,7 @@ private Builder getApiClient(String requestPath)
289233
if (conf.get("hadoop.http.authentication.type").equals("kerberos")) {
290234
try {
291235
URI url = new URI(requestPath);
292-
String challenge = generateToken(url.getHost());
236+
String challenge = YarnClientUtils.generateToken(url.getHost());
293237
builder.header(HttpHeaders.AUTHORIZATION, "Negotiate " + challenge);
294238
} catch (Exception e) {
295239
throw new IOException(e);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/client/TestSecureApiServiceClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.hadoop.security.UserGroupInformation;
4242
import org.apache.hadoop.security.SaslRpcServer.QualityOfProtection;
4343
import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
44+
import org.apache.hadoop.yarn.client.util.YarnClientUtils;
4445
import org.apache.log4j.Logger;
4546
import org.eclipse.jetty.server.Server;
4647
import org.eclipse.jetty.server.ServerConnector;
@@ -169,8 +170,7 @@ public void tearDown() throws Exception {
169170
public void testHttpSpnegoChallenge() throws Exception {
170171
UserGroupInformation.loginUserFromKeytab(clientPrincipal, keytabFile
171172
.getCanonicalPath());
172-
asc = new ApiServiceClient();
173-
String challenge = asc.generateToken("localhost");
173+
String challenge = YarnClientUtils.generateToken("localhost");
174174
assertNotNull(challenge);
175175
}
176176

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
<groupId>log4j</groupId>
5555
<artifactId>log4j</artifactId>
5656
</dependency>
57+
<dependency>
58+
<groupId>org.eclipse.jetty.websocket</groupId>
59+
<artifactId>websocket-client</artifactId>
60+
</dependency>
5761

5862
<!-- 'mvn dependency:analyze' fails to detect use of this dependency -->
5963
<dependency>
@@ -127,6 +131,10 @@
127131
<type>test-jar</type>
128132
</dependency>
129133

134+
<dependency>
135+
<groupId>org.jline</groupId>
136+
<artifactId>jline</artifactId>
137+
</dependency>
130138
</dependencies>
131139

132140
<build>

0 commit comments

Comments
 (0)