当前位置: 首页>>代码示例>>Java>>正文


Java ProcessIdFileReader.getProcessId方法代码示例

本文整理汇总了Java中org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader.getProcessId方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessIdFileReader.getProcessId方法的具体用法?Java ProcessIdFileReader.getProcessId怎么用?Java ProcessIdFileReader.getProcessId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader的用法示例。


在下文中一共展示了ProcessIdFileReader.getProcessId方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getContainerPid

import org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader; //导入方法依赖的package包/类
/**
 * Loop through for a time-bounded interval waiting to
 * read the process id from a file generated by a running process.
 * @param pidFilePath File from which to read the process id
 * @return Process ID
 * @throws Exception
 */
private String getContainerPid(Path pidFilePath) throws Exception {
  String containerIdStr = 
      ConverterUtils.toString(container.getContainerId());
  String processId = null;
  LOG.debug("Accessing pid for container " + containerIdStr
      + " from pid file " + pidFilePath);
  int sleepCounter = 0;
  final int sleepInterval = 100;

  // loop waiting for pid file to show up 
  // until our timer expires in which case we admit defeat
  while (true) {
    processId = ProcessIdFileReader.getProcessId(pidFilePath);
    if (processId != null) {
      LOG.debug("Got pid " + processId + " for container "
          + containerIdStr);
      break;
    }
    else if ((sleepCounter*sleepInterval) > maxKillWaitTime) {
      LOG.info("Could not get pid for " + containerIdStr
      		+ ". Waited for " + maxKillWaitTime + " ms.");
      break;
    }
    else {
      ++sleepCounter;
      Thread.sleep(sleepInterval);
    }
  }
  return processId;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:38,代码来源:ContainerLaunch.java

示例2: getProcessId

import org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader; //导入方法依赖的package包/类
/**
 * Get the process-identifier for the container
 * 
 * @param containerID
 * @return the processid of the container if it has already launched,
 *         otherwise return null
 */
public String getProcessId(ContainerId containerID) {
  String pid = null;
  Path pidFile = pidFiles.get(containerID);
  if (pidFile == null) {
    // This container isn't even launched yet.
    return pid;
  }
  try {
    pid = ProcessIdFileReader.getProcessId(pidFile);
  } catch (IOException e) {
    LOG.error("Got exception reading pid from pid-file " + pidFile, e);
  }
  return pid;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:ContainerExecutor.java

示例3: testNullPath

import org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader; //导入方法依赖的package包/类
@Test (timeout = 30000)
public void testNullPath() {
  String pid = null;
  try {
    pid = ProcessIdFileReader.getProcessId(null);
    fail("Expected an error to be thrown for null path");
  } catch (Exception e) {
    // expected
  }
  assert(pid == null);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:12,代码来源:TestProcessIdFileReader.java

示例4: testSimpleGet

import org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader; //导入方法依赖的package包/类
@Test (timeout = 30000)
public void testSimpleGet() throws IOException {
  String rootDir = new File(System.getProperty(
      "test.build.data", "/tmp")).getAbsolutePath();
  File testFile = null;
  String expectedProcessId = Shell.WINDOWS ?
    "container_1353742680940_0002_01_000001" :
    "56789";
  
  try {
    testFile = new File(rootDir, "temp.txt");
    PrintWriter fileWriter = new PrintWriter(testFile);
    fileWriter.println(expectedProcessId);
    fileWriter.close();      
    String processId = null; 
                
    processId = ProcessIdFileReader.getProcessId(
        new Path(rootDir + Path.SEPARATOR + "temp.txt"));
    Assert.assertEquals(expectedProcessId, processId);      
    
  } finally {
    if (testFile != null
        && testFile.exists()) {
      testFile.delete();
    }
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:28,代码来源:TestProcessIdFileReader.java

示例5: testComplexGet

import org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader; //导入方法依赖的package包/类
@Test (timeout = 30000)
public void testComplexGet() throws IOException {
  String rootDir = new File(System.getProperty(
      "test.build.data", "/tmp")).getAbsolutePath();
  File testFile = null;
  String processIdInFile = Shell.WINDOWS ?
    " container_1353742680940_0002_01_000001 " :
    " 23 ";
  String expectedProcessId = processIdInFile.trim();
  try {
    testFile = new File(rootDir, "temp.txt");
    PrintWriter fileWriter = new PrintWriter(testFile);
    fileWriter.println("   ");
    fileWriter.println("");
    fileWriter.println("abc");
    fileWriter.println("-123");
    fileWriter.println("-123 ");
    fileWriter.println(processIdInFile);
    fileWriter.println("6236");
    fileWriter.close();      
    String processId = null; 
                
    processId = ProcessIdFileReader.getProcessId(
        new Path(rootDir + Path.SEPARATOR + "temp.txt"));
    Assert.assertEquals(expectedProcessId, processId);
    
  } finally {
    if (testFile != null
        && testFile.exists()) {
      testFile.delete();
    }
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:34,代码来源:TestProcessIdFileReader.java

示例6: getContainerPid

import org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader; //导入方法依赖的package包/类
/**
 * Loop through for a time-bounded interval waiting to
 * read the process id from a file generated by a running process.
 * @param pidFilePath File from which to read the process id
 * @return Process ID
 * @throws Exception
 */
private String getContainerPid(Path pidFilePath) throws Exception {
  String containerIdStr = 
      ConverterUtils.toString(container.getContainerId());
  String processId = null;
  LOG.debug("Accessing pid for container " + containerIdStr
      + " from pid file " + pidFilePath);
  int sleepCounter = 0;
  final int sleepInterval = 100;

  // loop waiting for pid file to show up 
  // until either the completed flag is set which means something bad 
  // happened or our timer expires in which case we admit defeat
  while (!completed.get()) {
    processId = ProcessIdFileReader.getProcessId(pidFilePath);
    if (processId != null) {
      LOG.debug("Got pid " + processId + " for container "
          + containerIdStr);
      break;
    }
    else if ((sleepCounter*sleepInterval) > maxKillWaitTime) {
      LOG.info("Could not get pid for " + containerIdStr
      		+ ". Waited for " + maxKillWaitTime + " ms.");
      break;
    }
    else {
      ++sleepCounter;
      Thread.sleep(sleepInterval);
    }
  }
  return processId;
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:39,代码来源:ContainerLaunch.java

示例7: getContainerPid

import org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader; //导入方法依赖的package包/类
/**
 * Loop through for a time-bounded interval waiting to
 * read the process id from a file generated by a running process.
 * @param pidFilePath File from which to read the process id
 * @return Process ID
 * @throws Exception
 */
private String getContainerPid(Path pidFilePath) throws Exception {
  String containerIdStr = 
      container.getContainerId().toString();
  String processId = null;
  LOG.debug("Accessing pid for container " + containerIdStr
      + " from pid file " + pidFilePath);
  int sleepCounter = 0;
  final int sleepInterval = 100;

  // loop waiting for pid file to show up 
  // until our timer expires in which case we admit defeat
  while (true) {
    processId = ProcessIdFileReader.getProcessId(pidFilePath);
    if (processId != null) {
      LOG.debug("Got pid " + processId + " for container "
          + containerIdStr);
      break;
    }
    else if ((sleepCounter*sleepInterval) > maxKillWaitTime) {
      LOG.info("Could not get pid for " + containerIdStr
      		+ ". Waited for " + maxKillWaitTime + " ms.");
      break;
    }
    else {
      ++sleepCounter;
      Thread.sleep(sleepInterval);
    }
  }
  return processId;
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:38,代码来源:ContainerLaunch.java

示例8: reacquireContainer

import org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader; //导入方法依赖的package包/类
/**
 * Recover an already existing container. This is a blocking call and returns
 * only when the container exits.  Note that the container must have been
 * activated prior to this call.
 * @param ctx encapsulates information necessary to reacquire container
 * @return The exit code of the pre-existing container
 * @throws IOException
 * @throws InterruptedException 
 */
public int reacquireContainer(ContainerReacquisitionContext ctx)
    throws IOException, InterruptedException {
  Container container = ctx.getContainer();
  String user = ctx.getUser();
  ContainerId containerId = ctx.getContainerId();


  Path pidPath = getPidFilePath(containerId);
  if (pidPath == null) {
    LOG.warn(containerId + " is not active, returning terminated error");
    return ExitCode.TERMINATED.getExitCode();
  }

  String pid = null;
  pid = ProcessIdFileReader.getProcessId(pidPath);
  if (pid == null) {
    throw new IOException("Unable to determine pid for " + containerId);
  }

  LOG.info("Reacquiring " + containerId + " with pid " + pid);
  ContainerLivenessContext livenessContext = new ContainerLivenessContext
      .Builder()
      .setContainer(container)
      .setUser(user)
      .setPid(pid)
      .build();
  while(isContainerAlive(livenessContext)) {
    Thread.sleep(1000);
  }

  // wait for exit code file to appear
  String exitCodeFile = ContainerLaunch.getExitCodeFile(pidPath.toString());
  File file = new File(exitCodeFile);
  final int sleepMsec = 100;
  int msecLeft = 2000;
  while (!file.exists() && msecLeft >= 0) {
    if (!isContainerActive(containerId)) {
      LOG.info(containerId + " was deactivated");
      return ExitCode.TERMINATED.getExitCode();
    }
    
    Thread.sleep(sleepMsec);
    
    msecLeft -= sleepMsec;
  }
  if (msecLeft < 0) {
    throw new IOException("Timeout while waiting for exit code from "
        + containerId);
  }

  try {
    return Integer.parseInt(FileUtils.readFileToString(file).trim());
  } catch (NumberFormatException e) {
    throw new IOException("Error parsing exit code from pid " + pid, e);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:66,代码来源:ContainerExecutor.java

示例9: reacquireContainer

import org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader; //导入方法依赖的package包/类
/**
 * Recover an already existing container. This is a blocking call and returns
 * only when the container exits.  Note that the container must have been
 * activated prior to this call.
 * @param user the user of the container
 * @param containerId The ID of the container to reacquire
 * @return The exit code of the pre-existing container
 * @throws IOException
 * @throws InterruptedException 
 */
public int reacquireContainer(String user, ContainerId containerId)
    throws IOException, InterruptedException {
  Path pidPath = getPidFilePath(containerId);
  if (pidPath == null) {
    LOG.warn(containerId + " is not active, returning terminated error");
    return ExitCode.TERMINATED.getExitCode();
  }

  String pid = null;
  pid = ProcessIdFileReader.getProcessId(pidPath);
  if (pid == null) {
    throw new IOException("Unable to determine pid for " + containerId);
  }

  LOG.info("Reacquiring " + containerId + " with pid " + pid);
  while(isContainerProcessAlive(user, pid)) {
    Thread.sleep(1000);
  }

  // wait for exit code file to appear
  String exitCodeFile = ContainerLaunch.getExitCodeFile(pidPath.toString());
  File file = new File(exitCodeFile);
  final int sleepMsec = 100;
  int msecLeft = 2000;
  while (!file.exists() && msecLeft >= 0) {
    if (!isContainerActive(containerId)) {
      LOG.info(containerId + " was deactivated");
      return ExitCode.TERMINATED.getExitCode();
    }
    
    Thread.sleep(sleepMsec);
    
    msecLeft -= sleepMsec;
  }
  if (msecLeft < 0) {
    throw new IOException("Timeout while waiting for exit code from "
        + containerId);
  }

  try {
    return Integer.parseInt(FileUtils.readFileToString(file).trim());
  } catch (NumberFormatException e) {
    throw new IOException("Error parsing exit code from pid " + pid, e);
  }
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:56,代码来源:ContainerExecutor.java


注:本文中的org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader.getProcessId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。