Skip to content

Commit c08d4c8

Browse files
committed
HADOOP-10280. Add files missed in previous checkin.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1581533 13f79535-47bb-0310-9956-ffa450edef68
1 parent 73357d5 commit c08d4c8

File tree

4 files changed

+196
-0
lines changed

4 files changed

+196
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.ipc;
20+
21+
import org.apache.hadoop.classification.InterfaceAudience;
22+
23+
/**
24+
* The IdentityProvider creates identities for each schedulable
25+
* by extracting fields and returning an identity string.
26+
*
27+
* Implementers will be able to change how schedulers treat
28+
* Schedulables.
29+
*/
30+
@InterfaceAudience.Private
31+
public interface IdentityProvider {
32+
/**
33+
* Return the string used for scheduling.
34+
* @param obj the schedulable to use.
35+
* @return string identity, or null if no identity could be made.
36+
*/
37+
public String makeIdentity(Schedulable obj);
38+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.ipc;
20+
21+
import java.nio.ByteBuffer;
22+
23+
import org.apache.hadoop.classification.InterfaceAudience;
24+
import org.apache.hadoop.security.UserGroupInformation;
25+
import org.apache.hadoop.io.Writable;
26+
27+
/**
28+
* Interface which allows extracting information necessary to
29+
* create schedulable identity strings.
30+
*/
31+
@InterfaceAudience.Private
32+
public interface Schedulable {
33+
public UserGroupInformation getUserGroupInformation();
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.ipc;
20+
21+
import org.apache.hadoop.security.UserGroupInformation;
22+
23+
/**
24+
* The UserIdentityProvider creates uses the username as the
25+
* identity. All jobs launched by a user will be grouped together.
26+
*/
27+
public class UserIdentityProvider implements IdentityProvider {
28+
public String makeIdentity(Schedulable obj) {
29+
UserGroupInformation ugi = obj.getUserGroupInformation();
30+
if (ugi == null) {
31+
return null;
32+
}
33+
34+
return ugi.getUserName();
35+
}
36+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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.ipc;
20+
21+
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assert.assertFalse;
23+
import static org.junit.Assert.assertNotNull;
24+
import static org.junit.Assert.assertNull;
25+
import static org.junit.Assert.assertTrue;
26+
import static org.junit.Assert.fail;
27+
28+
import org.junit.Assert;
29+
import org.junit.Assume;
30+
import org.junit.Test;
31+
import org.junit.Before;
32+
import org.junit.After;
33+
34+
import java.util.List;
35+
import java.io.IOException;
36+
import java.nio.ByteBuffer;
37+
38+
import org.apache.hadoop.classification.InterfaceAudience;
39+
import org.apache.hadoop.security.UserGroupInformation;
40+
import org.apache.hadoop.io.Writable;
41+
42+
import org.apache.hadoop.fs.CommonConfigurationKeys;
43+
import org.apache.hadoop.conf.Configuration;
44+
45+
public class TestIdentityProviders {
46+
public class FakeSchedulable implements Schedulable {
47+
public FakeSchedulable() {
48+
}
49+
50+
public UserGroupInformation getUserGroupInformation() {
51+
try {
52+
return UserGroupInformation.getCurrentUser();
53+
} catch (IOException e) {
54+
return null;
55+
}
56+
}
57+
58+
}
59+
60+
@Test
61+
public void testPluggableIdentityProvider() {
62+
Configuration conf = new Configuration();
63+
conf.set(CommonConfigurationKeys.IPC_CALLQUEUE_IDENTITY_PROVIDER_KEY,
64+
"org.apache.hadoop.ipc.UserIdentityProvider");
65+
66+
List<IdentityProvider> providers = conf.getInstances(
67+
CommonConfigurationKeys.IPC_CALLQUEUE_IDENTITY_PROVIDER_KEY,
68+
IdentityProvider.class);
69+
70+
assertTrue(providers.size() == 1);
71+
72+
IdentityProvider ip = providers.get(0);
73+
assertNotNull(ip);
74+
assertEquals(ip.getClass(), UserIdentityProvider.class);
75+
}
76+
77+
@Test
78+
public void testUserIdentityProvider() throws IOException {
79+
UserIdentityProvider uip = new UserIdentityProvider();
80+
String identity = uip.makeIdentity(new FakeSchedulable());
81+
82+
// Get our username
83+
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
84+
String username = ugi.getUserName();
85+
86+
assertEquals(username, identity);
87+
}
88+
}

0 commit comments

Comments
 (0)