2017-12-12 7 views
0

Java에서 MR2 작업이 있습니다. 컨테이너 내부에서 컨테이너 제거를 감지하고 처리 할 수 ​​있습니까? 내가YARN이 컨테이너를 죽일 때를 감지합니다.

Runtime.getRuntime().addShutdownHook(new Hooker(this)); 

과 같은 코드를 사용하려고하지만, 발견 된 후커 클래스 인스턴스의 로그가 없습니다했습니다. 아마도이 컨테이너에 자바 힙 덤프를 가져올 수 있습니까?

킬 이유는 다음과 같은 코드를 사용, 그것을 위해 자식 프로세스를 사용하여 실 킬을 감지하는 필터를 추가 할 수 있습니다

Container [pid=35696,containerID=container_1509737408754_96482_01_000384] is running beyond physical memory limits. 
Current usage: 2.0 GB of 2 GB physical memory used; 3.6 GB of 4.2 GB virtual memory used. Killing container. Dump of the process-tree for container_1509737408754_96482_01_000384 : |- PID PPID PGRPID SESSID CMD_NAME USER_MODE_TIME(MILLIS) SYSTEM_TIME(MILLIS) VMEM_USAGE(BYTES) RSSMEM_USAGE(PAGES) FULL_CMD_LINE |- 35696 35694 35696 35696 (bash) 

감사

답변

0

입니다.

public class YarnLog { 
// 
public static void getYarnLog(String appid) throws IOException { 
    BufferedReader br = null; 
    try { 
     Process p = Runtime.getRuntime().exec(String.format("yarn logs -applicationId %s", appid)); 
     br = new BufferedReader(new InputStreamReader(p.getInputStream())); 
     String line; 
     while((line = br.readLine()) != null) { 
      System.out.println(line); 
     } 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } finally { 
     if(br != null) { 
      br.close(); 
     } 
    } 
} 

}

+0

나는 작업이 실패하지 후, 매퍼 내부 이벤트를 감지해야합니다 의미한다. – realfreeman

관련 문제