Search in sources :

Example 1 with ContainerRetryContext

use of org.apache.hadoop.yarn.api.records.ContainerRetryContext in project hadoop by apache.

the class ContainerImpl method configureRetryContext.

private static ContainerRetryContext configureRetryContext(Configuration conf, ContainerLaunchContext launchContext, ContainerId containerId) {
    ContainerRetryContext context;
    if (launchContext != null && launchContext.getContainerRetryContext() != null) {
        context = launchContext.getContainerRetryContext();
    } else {
        context = ContainerRetryContext.NEVER_RETRY_CONTEXT;
    }
    int minimumRestartInterval = conf.getInt(YarnConfiguration.NM_CONTAINER_RETRY_MINIMUM_INTERVAL_MS, YarnConfiguration.DEFAULT_NM_CONTAINER_RETRY_MINIMUM_INTERVAL_MS);
    if (context.getRetryPolicy() != ContainerRetryPolicy.NEVER_RETRY && context.getRetryInterval() < minimumRestartInterval) {
        LOG.info("Set restart interval to minimum value " + minimumRestartInterval + "ms for container " + containerId);
        context.setRetryInterval(minimumRestartInterval);
    }
    return context;
}
Also used : ContainerRetryContext(org.apache.hadoop.yarn.api.records.ContainerRetryContext)

Example 2 with ContainerRetryContext

use of org.apache.hadoop.yarn.api.records.ContainerRetryContext in project hadoop by apache.

the class TestContainer method testContainerRetry.

@Test
public void testContainerRetry() throws Exception {
    ContainerRetryContext containerRetryContext1 = ContainerRetryContext.newInstance(ContainerRetryPolicy.NEVER_RETRY, null, 3, 0);
    testContainerRetry(containerRetryContext1, 2, 0);
    ContainerRetryContext containerRetryContext2 = ContainerRetryContext.newInstance(ContainerRetryPolicy.RETRY_ON_ALL_ERRORS, null, 3, 0);
    testContainerRetry(containerRetryContext2, 2, 3);
    ContainerRetryContext containerRetryContext3 = ContainerRetryContext.newInstance(ContainerRetryPolicy.RETRY_ON_ALL_ERRORS, null, 3, 0);
    // If exit code is 0, it will not retry
    testContainerRetry(containerRetryContext3, 0, 0);
    ContainerRetryContext containerRetryContext4 = ContainerRetryContext.newInstance(ContainerRetryPolicy.RETRY_ON_SPECIFIC_ERROR_CODES, null, 3, 0);
    testContainerRetry(containerRetryContext4, 2, 0);
    HashSet<Integer> errorCodes = new HashSet<>();
    errorCodes.add(2);
    errorCodes.add(6);
    ContainerRetryContext containerRetryContext5 = ContainerRetryContext.newInstance(ContainerRetryPolicy.RETRY_ON_SPECIFIC_ERROR_CODES, errorCodes, 3, 0);
    testContainerRetry(containerRetryContext5, 2, 3);
    HashSet<Integer> errorCodes2 = new HashSet<>();
    errorCodes.add(143);
    ContainerRetryContext containerRetryContext6 = ContainerRetryContext.newInstance(ContainerRetryPolicy.RETRY_ON_SPECIFIC_ERROR_CODES, errorCodes2, 3, 0);
    // If exit code is 143(SIGTERM), it will not retry even it is in errorCodes.
    testContainerRetry(containerRetryContext6, 143, 0);
}
Also used : ContainerRetryContext(org.apache.hadoop.yarn.api.records.ContainerRetryContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ContainerRetryContext

use of org.apache.hadoop.yarn.api.records.ContainerRetryContext in project hadoop by apache.

the class TestContainer method testContainerRestartInterval.

@Test
public void testContainerRestartInterval() throws IOException {
    conf.setInt(YarnConfiguration.NM_CONTAINER_RETRY_MINIMUM_INTERVAL_MS, 2000);
    ContainerRetryContext containerRetryContext1 = ContainerRetryContext.newInstance(ContainerRetryPolicy.NEVER_RETRY, null, 3, 0);
    testContainerRestartInterval(containerRetryContext1, 0);
    ContainerRetryContext containerRetryContext2 = ContainerRetryContext.newInstance(ContainerRetryPolicy.RETRY_ON_ALL_ERRORS, null, 3, 0);
    testContainerRestartInterval(containerRetryContext2, 2000);
    ContainerRetryContext containerRetryContext3 = ContainerRetryContext.newInstance(ContainerRetryPolicy.RETRY_ON_ALL_ERRORS, null, 3, 4000);
    testContainerRestartInterval(containerRetryContext3, 4000);
}
Also used : ContainerRetryContext(org.apache.hadoop.yarn.api.records.ContainerRetryContext) Test(org.junit.Test)

Example 4 with ContainerRetryContext

use of org.apache.hadoop.yarn.api.records.ContainerRetryContext in project hadoop by apache.

the class TestContainerManager method prepareContainerLaunchContext.

private ContainerLaunchContext prepareContainerLaunchContext(File scriptFile, String destFName, boolean putBadFile, int numRetries) {
    ContainerLaunchContext containerLaunchContext = recordFactory.newRecordInstance(ContainerLaunchContext.class);
    URL resourceAlpha = null;
    if (putBadFile) {
        File fileToDelete = new File(tmpDir, "fileToDelete").getAbsoluteFile();
        resourceAlpha = URL.fromPath(localFS.makeQualified(new Path(fileToDelete.getAbsolutePath())));
        fileToDelete.delete();
    } else {
        resourceAlpha = URL.fromPath(localFS.makeQualified(new Path(scriptFile.getAbsolutePath())));
    }
    LocalResource rsrcAlpha = recordFactory.newRecordInstance(LocalResource.class);
    rsrcAlpha.setResource(resourceAlpha);
    rsrcAlpha.setSize(-1);
    rsrcAlpha.setVisibility(LocalResourceVisibility.APPLICATION);
    rsrcAlpha.setType(LocalResourceType.FILE);
    rsrcAlpha.setTimestamp(scriptFile.lastModified());
    Map<String, LocalResource> localResources = new HashMap<>();
    localResources.put(destFName, rsrcAlpha);
    containerLaunchContext.setLocalResources(localResources);
    ContainerRetryContext containerRetryContext = ContainerRetryContext.newInstance(ContainerRetryPolicy.RETRY_ON_SPECIFIC_ERROR_CODES, new HashSet<>(Arrays.asList(Integer.valueOf(111))), numRetries, 0);
    containerLaunchContext.setContainerRetryContext(containerRetryContext);
    List<String> commands = Arrays.asList(Shell.getRunScriptCommand(scriptFile));
    containerLaunchContext.setCommands(commands);
    return containerLaunchContext;
}
Also used : Path(org.apache.hadoop.fs.Path) HashMap(java.util.HashMap) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) File(java.io.File) URL(org.apache.hadoop.yarn.api.records.URL) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) ContainerRetryContext(org.apache.hadoop.yarn.api.records.ContainerRetryContext)

Aggregations

ContainerRetryContext (org.apache.hadoop.yarn.api.records.ContainerRetryContext)4 Test (org.junit.Test)2 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Path (org.apache.hadoop.fs.Path)1 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)1 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)1 URL (org.apache.hadoop.yarn.api.records.URL)1