Search in sources :

Example 1 with ContainerContext

use of org.apache.tez.dag.app.ContainerContext in project tez by apache.

the class TestTaskImpl method setup.

@Before
public void setup() {
    conf = new Configuration();
    conf.setInt(TezConfiguration.TEZ_AM_TASK_MAX_FAILED_ATTEMPTS, 4);
    taskCommunicatorManagerInterface = mock(TaskCommunicatorManagerInterface.class);
    taskHeartbeatHandler = mock(TaskHeartbeatHandler.class);
    credentials = new Credentials();
    clock = new SystemClock();
    locationHint = TaskLocationHint.createTaskLocationHint(null, null);
    appId = ApplicationId.newInstance(System.currentTimeMillis(), 1);
    dagId = TezDAGID.getInstance(appId, 1);
    vertexId = TezVertexID.getInstance(dagId, 1);
    appContext = mock(AppContext.class, RETURNS_DEEP_STUBS);
    when(appContext.getDAGRecoveryData()).thenReturn(null);
    appContext.setDAGRecoveryData(null);
    mockContainerId = mock(ContainerId.class);
    mockContainer = mock(Container.class);
    mockAMContainer = mock(AMContainer.class);
    when(mockAMContainer.getContainer()).thenReturn(mockContainer);
    when(mockContainer.getNodeHttpAddress()).thenReturn("localhost:1234");
    mockNodeId = mock(NodeId.class);
    mockHistoryHandler = mock(HistoryEventHandler.class);
    when(mockContainer.getId()).thenReturn(mockContainerId);
    when(mockContainer.getNodeId()).thenReturn(mockNodeId);
    when(mockAMContainer.getContainer()).thenReturn(mockContainer);
    when(appContext.getAllContainers().get(mockContainerId)).thenReturn(mockAMContainer);
    when(appContext.getHistoryHandler()).thenReturn(mockHistoryHandler);
    taskResource = Resource.newInstance(1024, 1);
    localResources = new HashMap<String, LocalResource>();
    environment = new HashMap<String, String>();
    javaOpts = "";
    leafVertex = false;
    containerContext = new ContainerContext(localResources, credentials, environment, javaOpts);
    Vertex vertex = mock(Vertex.class);
    doReturn(new VertexImpl.VertexConfigImpl(conf)).when(vertex).getVertexConfig();
    eventHandler = new TestEventHandler();
    mockTask = new MockTaskImpl(vertexId, partition, eventHandler, conf, taskCommunicatorManagerInterface, clock, taskHeartbeatHandler, appContext, leafVertex, taskResource, containerContext, vertex);
    mockTaskSpec = mock(TaskSpec.class);
    mockVertex = mock(Vertex.class);
    ServicePluginInfo servicePluginInfo = new ServicePluginInfo().setContainerLauncherName(TezConstants.getTezYarnServicePluginName());
    when(mockVertex.getServicePluginInfo()).thenReturn(servicePluginInfo);
    when(mockVertex.getVertexConfig()).thenReturn(new VertexImpl.VertexConfigImpl(conf));
}
Also used : Vertex(org.apache.tez.dag.app.dag.Vertex) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) SystemClock(org.apache.hadoop.yarn.util.SystemClock) AppContext(org.apache.tez.dag.app.AppContext) TaskSpec(org.apache.tez.runtime.api.impl.TaskSpec) TaskCommunicatorManagerInterface(org.apache.tez.dag.app.TaskCommunicatorManagerInterface) AMContainer(org.apache.tez.dag.app.rm.container.AMContainer) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) AMContainer(org.apache.tez.dag.app.rm.container.AMContainer) Container(org.apache.hadoop.yarn.api.records.Container) HistoryEventHandler(org.apache.tez.dag.history.HistoryEventHandler) ContainerContext(org.apache.tez.dag.app.ContainerContext) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) NodeId(org.apache.hadoop.yarn.api.records.NodeId) TaskHeartbeatHandler(org.apache.tez.dag.app.TaskHeartbeatHandler) Credentials(org.apache.hadoop.security.Credentials) Before(org.junit.Before)

Example 2 with ContainerContext

use of org.apache.tez.dag.app.ContainerContext in project tez by apache.

the class TestVertexImpl2 method testTaskLoggingOptsPerLogger.

@Test(timeout = 5000)
public void testTaskLoggingOptsPerLogger() {
    Configuration conf = new TezConfiguration();
    conf.set(TezConfiguration.TEZ_TASK_LOG_LEVEL, "DEBUG;org.apache.hadoop.ipc=INFO;org.apache.hadoop.server=INFO");
    LogTestInfoHolder testInfo = new LogTestInfoHolder();
    VertexWrapper vertexWrapper = createVertexWrapperForLogTests(testInfo, conf);
    List<String> expectedCommands = new LinkedList<String>();
    expectedCommands.add("-Dlog4j.configuratorClass=org.apache.tez.common.TezLog4jConfigurator");
    expectedCommands.add("-Dlog4j.configuration=" + TezConstants.TEZ_CONTAINER_LOG4J_PROPERTIES_FILE);
    expectedCommands.add("-D" + YarnConfiguration.YARN_APP_CONTAINER_LOG_DIR + "=" + ApplicationConstants.LOG_DIR_EXPANSION_VAR);
    expectedCommands.add("-D" + TezConstants.TEZ_ROOT_LOGGER_NAME + "=" + "DEBUG" + "," + TezConstants.TEZ_CONTAINER_LOGGER_NAME);
    for (int i = 0; i < testInfo.numTasks; i++) {
        ContainerContext containerContext = vertexWrapper.vertex.getContainerContext(i);
        String javaOpts = containerContext.getJavaOpts();
        assertTrue(javaOpts.contains(testInfo.initialJavaOpts));
        for (String expectedCmd : expectedCommands) {
            assertTrue(javaOpts.contains(expectedCmd));
        }
        Map<String, String> env = containerContext.getEnvironment();
        String val = env.get(testInfo.envKey);
        assertEquals(testInfo.envVal, val);
        String logEnvVal = env.get(TezConstants.TEZ_CONTAINER_LOG_PARAMS);
        assertEquals("org.apache.hadoop.ipc=INFO;org.apache.hadoop.server=INFO", logEnvVal);
    }
}
Also used : ContainerContext(org.apache.tez.dag.app.ContainerContext) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) LinkedList(java.util.LinkedList) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) Test(org.junit.Test)

Example 3 with ContainerContext

use of org.apache.tez.dag.app.ContainerContext in project tez by apache.

the class TestVertexImpl2 method testTaskSpecificLoggingOpts2.

@Test(timeout = 5000)
public void testTaskSpecificLoggingOpts2() {
    String vertexName = "testvertex";
    String customJavaOpts = "-Xmx128m";
    Configuration conf = new TezConfiguration();
    conf.set(TezConfiguration.TEZ_TASK_LOG_LEVEL, "WARN;org.apache.tez=INFO");
    conf.set(TezConfiguration.TEZ_TASK_SPECIFIC_LAUNCH_CMD_OPTS_LIST, vertexName + "[0,1,2]");
    conf.set(TezConfiguration.TEZ_TASK_SPECIFIC_LOG_LEVEL, "DEBUG");
    conf.set(TezConfiguration.TEZ_TASK_SPECIFIC_LAUNCH_CMD_OPTS, customJavaOpts);
    LogTestInfoHolder testInfo = new LogTestInfoHolder();
    VertexWrapper vertexWrapper = createVertexWrapperForLogTests(testInfo, conf);
    // Expected command opts for regular tasks
    List<String> expectedCommands = new LinkedList<String>();
    expectedCommands.add("-Dlog4j.configuratorClass=org.apache.tez.common.TezLog4jConfigurator");
    expectedCommands.add("-Dlog4j.configuration=" + TezConstants.TEZ_CONTAINER_LOG4J_PROPERTIES_FILE);
    expectedCommands.add("-D" + YarnConfiguration.YARN_APP_CONTAINER_LOG_DIR + "=" + ApplicationConstants.LOG_DIR_EXPANSION_VAR);
    expectedCommands.add("-D" + TezConstants.TEZ_ROOT_LOGGER_NAME + "=" + "WARN" + "," + TezConstants.TEZ_CONTAINER_LOGGER_NAME);
    for (int i = 3; i < testInfo.numTasks; i++) {
        ContainerContext containerContext = vertexWrapper.vertex.getContainerContext(i);
        String javaOpts = containerContext.getJavaOpts();
        assertTrue(javaOpts.contains(testInfo.initialJavaOpts));
        for (String expectedCmd : expectedCommands) {
            assertTrue(javaOpts.contains(expectedCmd));
        }
        Map<String, String> env = containerContext.getEnvironment();
        String val = env.get(testInfo.envKey);
        assertEquals(testInfo.envVal, val);
        String logEnvVal = env.get(TezConstants.TEZ_CONTAINER_LOG_PARAMS);
        assertEquals("org.apache.tez=INFO", logEnvVal);
    }
    // Expected command opts for instrumented tasks.
    expectedCommands = new LinkedList<String>();
    expectedCommands.add("-Dlog4j.configuratorClass=org.apache.tez.common.TezLog4jConfigurator");
    expectedCommands.add("-Dlog4j.configuration=" + TezConstants.TEZ_CONTAINER_LOG4J_PROPERTIES_FILE);
    expectedCommands.add("-D" + YarnConfiguration.YARN_APP_CONTAINER_LOG_DIR + "=" + ApplicationConstants.LOG_DIR_EXPANSION_VAR);
    expectedCommands.add("-D" + TezConstants.TEZ_ROOT_LOGGER_NAME + "=" + "DEBUG" + "," + TezConstants.TEZ_CONTAINER_LOGGER_NAME);
    for (int i = 0; i < 3; i++) {
        ContainerContext containerContext = vertexWrapper.vertex.getContainerContext(i);
        String javaOpts = containerContext.getJavaOpts();
        assertTrue(javaOpts.contains(testInfo.initialJavaOpts));
        for (String expectedCmd : expectedCommands) {
            assertTrue(javaOpts.contains(expectedCmd));
        }
        Map<String, String> env = containerContext.getEnvironment();
        String val = env.get(testInfo.envKey);
        assertEquals(testInfo.envVal, val);
        String logEnvVal = env.get(TezConstants.TEZ_CONTAINER_LOG_PARAMS);
        assertNull(logEnvVal);
    }
}
Also used : ContainerContext(org.apache.tez.dag.app.ContainerContext) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) LinkedList(java.util.LinkedList) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) VertexLocationHint(org.apache.tez.dag.api.VertexLocationHint) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) Test(org.junit.Test)

Example 4 with ContainerContext

use of org.apache.tez.dag.app.ContainerContext in project tez by apache.

the class ContainerContextMatcher method isSuperSet.

@Override
public boolean isSuperSet(Object cs1, Object cs2) {
    checkArguments(cs1, cs2);
    ContainerContext context1 = (ContainerContext) cs1;
    ContainerContext context2 = (ContainerContext) cs2;
    return context1.isSuperSet(context2);
}
Also used : ContainerContext(org.apache.tez.dag.app.ContainerContext)

Example 5 with ContainerContext

use of org.apache.tez.dag.app.ContainerContext in project tez by apache.

the class TestTaskSchedulerManager method testSimpleAllocate.

@Test(timeout = 5000)
public void testSimpleAllocate() throws Exception {
    Configuration conf = new Configuration(false);
    schedulerHandler.init(conf);
    schedulerHandler.start();
    TaskAttemptImpl mockTaskAttempt = mock(TaskAttemptImpl.class);
    TezTaskAttemptID mockAttemptId = mock(TezTaskAttemptID.class);
    when(mockAttemptId.getId()).thenReturn(0);
    when(mockTaskAttempt.getID()).thenReturn(mockAttemptId);
    Resource resource = Resource.newInstance(1024, 1);
    ContainerContext containerContext = new ContainerContext(new HashMap<String, LocalResource>(), new Credentials(), new HashMap<String, String>(), "");
    int priority = 10;
    TaskLocationHint locHint = TaskLocationHint.createTaskLocationHint(new HashSet<String>(), null);
    ContainerId mockCId = mock(ContainerId.class);
    Container container = mock(Container.class);
    when(container.getId()).thenReturn(mockCId);
    AMContainer mockAMContainer = mock(AMContainer.class);
    when(mockAMContainer.getContainerId()).thenReturn(mockCId);
    when(mockAMContainer.getState()).thenReturn(AMContainerState.IDLE);
    when(mockAMContainerMap.get(mockCId)).thenReturn(mockAMContainer);
    AMSchedulerEventTALaunchRequest lr = new AMSchedulerEventTALaunchRequest(mockAttemptId, resource, null, mockTaskAttempt, locHint, priority, containerContext, 0, 0, 0);
    schedulerHandler.taskAllocated(0, mockTaskAttempt, lr, container);
    assertEquals(1, mockEventHandler.events.size());
    assertTrue(mockEventHandler.events.get(0) instanceof AMContainerEventAssignTA);
    AMContainerEventAssignTA assignEvent = (AMContainerEventAssignTA) mockEventHandler.events.get(0);
    assertEquals(priority, assignEvent.getPriority());
    assertEquals(mockAttemptId, assignEvent.getTaskAttemptId());
}
Also used : AMContainerEventAssignTA(org.apache.tez.dag.app.rm.container.AMContainerEventAssignTA) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) Resource(org.apache.hadoop.yarn.api.records.Resource) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) TaskAttemptImpl(org.apache.tez.dag.app.dag.impl.TaskAttemptImpl) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) AMContainer(org.apache.tez.dag.app.rm.container.AMContainer) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) ContainerContext(org.apache.tez.dag.app.ContainerContext) AMContainer(org.apache.tez.dag.app.rm.container.AMContainer) Container(org.apache.hadoop.yarn.api.records.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) Credentials(org.apache.hadoop.security.Credentials) TezTaskAttemptID(org.apache.tez.dag.records.TezTaskAttemptID) DagInfoImplForTest(org.apache.tez.dag.helpers.DagInfoImplForTest) Test(org.junit.Test)

Aggregations

ContainerContext (org.apache.tez.dag.app.ContainerContext)9 Configuration (org.apache.hadoop.conf.Configuration)6 TezConfiguration (org.apache.tez.dag.api.TezConfiguration)6 TaskLocationHint (org.apache.tez.dag.api.TaskLocationHint)5 Test (org.junit.Test)5 LinkedList (java.util.LinkedList)4 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)4 VertexLocationHint (org.apache.tez.dag.api.VertexLocationHint)4 Credentials (org.apache.hadoop.security.Credentials)2 Container (org.apache.hadoop.yarn.api.records.Container)2 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)2 AMContainer (org.apache.tez.dag.app.rm.container.AMContainer)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 NodeId (org.apache.hadoop.yarn.api.records.NodeId)1 Resource (org.apache.hadoop.yarn.api.records.Resource)1 SystemClock (org.apache.hadoop.yarn.util.SystemClock)1 AppContext (org.apache.tez.dag.app.AppContext)1 TaskCommunicatorManagerInterface (org.apache.tez.dag.app.TaskCommunicatorManagerInterface)1 TaskHeartbeatHandler (org.apache.tez.dag.app.TaskHeartbeatHandler)1