ContainerExecutor implements Configurable { public void cleanupBeforeRelaunch(Container container) throws IOException, InterruptedException { if (container.getLocalizedResources() != null) { Map<Path, Path> symLinks = resolveSymLinks( container.getLocalizedResources(), container.getUser()); for (Map.Entry<Path, Path> symLink : symLinks.entrySet()) { LOG.debug("{} deleting {}", container.getContainerId(), symLink.getValue()); deleteAsUser(new DeletionAsUserContext.Builder() .setUser(container.getUser()) .setSubDir(symLink.getValue()) .build()); } } }  @Override void setConf(Configuration conf); @Override Configuration getConf(); abstract void init(Context nmContext); Path localizeClasspathJar(Path jarPath, Path target, String owner); abstract void startLocalizer(LocalizerStartContext ctx); void prepareContainer(ContainerPrepareContext ctx); abstract int launchContainer(ContainerStartContext ctx); abstract int relaunchContainer(ContainerStartContext ctx); abstract boolean signalContainer(ContainerSignalContext ctx); abstract boolean reapContainer(ContainerReapContext ctx); abstract void deleteAsUser(DeletionAsUserContext ctx); abstract void symLink(String target, String symlink); abstract boolean isContainerAlive(ContainerLivenessContext ctx); int reacquireContainer(ContainerReacquisitionContext ctx); void writeLaunchEnv(OutputStream out, Map<String, String> environment,
      Map<Path, List<String>> resources, List<String> command, Path logDir,
      String user, LinkedHashSet<String> nmVars); @VisibleForTesting void writeLaunchEnv(OutputStream out, Map<String, String> environment,
      Map<Path, List<String>> resources, List<String> command, Path logDir,
      String user, String outFilename, LinkedHashSet<String> nmVars); void activateContainer(ContainerId containerId, Path pidFilePath); String[] getIpAndHost(Container container); static String[] getLocalIpAndHost(Container container); void deactivateContainer(ContainerId containerId); void pauseContainer(Container container); void resumeContainer(Container container); void cleanupBeforeRelaunch(Container container); String getProcessId(ContainerId containerID); static final FsPermission TASK_LAUNCH_SCRIPT_PERMISSION; static final String DIRECTORY_CONTENTS; }
@Test public void testCleanupBeforeLaunch() throws Exception { Container container = mock(Container.class); java.nio.file.Path linkName = Paths.get("target/linkName"); java.nio.file.Path target = Paths.get("target"); FileUtils.deleteQuietly(linkName.toFile()); Files.createSymbolicLink(linkName.toAbsolutePath(), target.toAbsolutePath()); Map<Path, List<String>> localResources = new HashMap<>(); localResources.put(new Path(target.toFile().getAbsolutePath()), Lists.newArrayList(linkName.toFile().getAbsolutePath())); when(container.getLocalizedResources()) .thenReturn(localResources); when(container.getUser()).thenReturn(System.getProperty("user.name")); containerExecutor.cleanupBeforeRelaunch(container); Assert.assertTrue(!Files.exists(linkName)); }