blob: b47e36012839ecf6820f67baf754d6f8225ca37e [file] [log] [blame]
/**
* 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.mapred;
import java.io.File;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.mapreduce.MRConfig;
import org.apache.hadoop.mapreduce.server.tasktracker.TTConfig;
import org.apache.hadoop.security.Groups;
import org.apache.hadoop.security.UserGroupInformation;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import junit.framework.TestCase;
public class TestLinuxTaskController extends TestCase {
private static int INVALID_TASKCONTROLLER_PERMISSIONS = 24;
private static File testDir = new File(System.getProperty("test.build.data",
"/tmp"), TestLinuxTaskController.class.getName());
private static String taskControllerPath = System
.getProperty(ClusterWithLinuxTaskController.TASKCONTROLLER_PATH);
@Before
protected void setUp() throws Exception {
testDir.mkdirs();
}
@After
protected void tearDown() throws Exception {
FileUtil.fullyDelete(testDir);
}
public static class MyLinuxTaskController extends LinuxTaskController {
String taskControllerExePath = taskControllerPath + "/task-controller";
@Override
protected String getTaskControllerExecutablePath() {
return taskControllerExePath;
}
}
private void validateTaskControllerSetup(TaskController controller,
boolean shouldFail) throws IOException {
if (shouldFail) {
// task controller setup should fail validating permissions.
Throwable th = null;
try {
controller.setup();
} catch (IOException ie) {
th = ie;
}
assertNotNull("No exception during setup", th);
assertTrue("Exception message does not contain exit code"
+ INVALID_TASKCONTROLLER_PERMISSIONS, th.getMessage().contains(
"with exit code " + INVALID_TASKCONTROLLER_PERMISSIONS));
} else {
controller.setup();
}
}
@Test
public void testTaskControllerGroup() throws Exception {
if (!ClusterWithLinuxTaskController.isTaskExecPathPassed()) {
return;
}
// cleanup configuration file.
ClusterWithLinuxTaskController
.getTaskControllerConfFile(taskControllerPath).delete();
Configuration conf = new Configuration();
// create local dirs and set in the conf.
File mapredLocal = new File(testDir, "mapred/local");
mapredLocal.mkdirs();
conf.set(MRConfig.LOCAL_DIR, mapredLocal.toString());
// setup task-controller without setting any group name
TaskController controller = new MyLinuxTaskController();
controller.setConf(conf);
validateTaskControllerSetup(controller, true);
// set an invalid group name for the task controller group
conf.set(TTConfig.TT_GROUP, "invalid");
// write the task-controller's conf file
ClusterWithLinuxTaskController.createTaskControllerConf(taskControllerPath,
conf);
validateTaskControllerSetup(controller, true);
conf.set(TTConfig.TT_GROUP,
ClusterWithLinuxTaskController.taskTrackerSpecialGroup);
// write the task-controller's conf file
ClusterWithLinuxTaskController.createTaskControllerConf(taskControllerPath,
conf);
validateTaskControllerSetup(controller, false);
}
}