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


Java LogWriter.close方法代码示例

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


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

示例1: serviceStart

import org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat.LogWriter; //导入方法依赖的package包/类
@Override
public void serviceStart() throws Exception {
  try {
    // Get user's FileSystem credentials
    final UserGroupInformation userUgi = UserGroupInformation
        .createRemoteUser(user);

    createAppDir(user, applicationId, userUgi, conf,
        remoteNodeTmpLogFileForApp);

    Path remoteNodeLogFileForApp = getRemoteNodeLogFileForApp(conf,
        remoteNodeTmpLogFileForApp,
        ConverterUtils.toApplicationId(applicationId), user);
    LogWriter writer = new LogWriter(conf, remoteNodeLogFileForApp, userUgi);
    List<ContainerId> containers = getAllContainers(applicationId, conf);
    LOG.info("Starting Log aggregation for containers : " + containers);
    String[] hpcLogDir = HPCConfiguration.getHPCLogDirs(conf);
    List<String> logDirs = Arrays.asList(hpcLogDir);
    for (ContainerId containerId : containers) {
      LogKey logKey = new LogKey(containerId);
      LogValue logValue = new LogValue(logDirs, containerId,
          userUgi.getShortUserName());
      writer.append(logKey, logValue);
    }
    writer.close();
    LOG.info("Log aggregation has completed.");

    // Remove the log files from local dir's
    delete(applicationId, hpcLogDir);

    // Clean up container work dirs
    delete(applicationId, HPCConfiguration.getHPCLocalDirs(conf));

  } catch (Throwable e) {
    throw new RuntimeException("Failed to complete aggregation on "
        + hostName + "for application " + applicationId, e);
  }
  super.serviceStart();
}
 
开发者ID:intel-hpdd,项目名称:scheduling-connector-for-hadoop,代码行数:40,代码来源:HPCLogAggregateHandler.java

示例2: writeSrcFileAndALog

import org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat.LogWriter; //导入方法依赖的package包/类
private void writeSrcFileAndALog(Path srcFilePath, String fileName, final long length,
    Path remoteAppLogFile, Path srcFileRoot, ContainerId testContainerId)
    throws Exception {
  File dir = new File(srcFilePath.toString());
  if (!dir.exists()) {
    if (!dir.mkdirs()) {
      throw new IOException("Unable to create directory : " + dir);
    }
  }

  File outputFile = new File(new File(srcFilePath.toString()), fileName);
  FileOutputStream os = new FileOutputStream(outputFile);
  final OutputStreamWriter osw = new OutputStreamWriter(os, "UTF8");
  final int ch = filler;

  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  LogWriter logWriter = new LogWriter(conf, remoteAppLogFile, ugi);

  LogKey logKey = new LogKey(testContainerId);
  LogValue logValue =
      spy(new LogValue(Collections.singletonList(srcFileRoot.toString()),
          testContainerId, ugi.getShortUserName()));

  final CountDownLatch latch = new CountDownLatch(1);

  Thread t = new Thread() {
    public void run() {
      try {
        for(int i=0; i < length/3; i++) {
            osw.write(ch);
        }

        latch.countDown();

        for(int i=0; i < (2*length)/3; i++) {
          osw.write(ch);
        }
        osw.close();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  };
  t.start();

  //Wait till the osw is partially written
  //aggregation starts once the ows has completed 1/3rd of its work
  latch.await();

  //Aggregate The Logs
  logWriter.append(logKey, logValue);
  logWriter.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:55,代码来源:TestAggregatedLogFormat.java

示例3: testReadAcontainerLogs1

import org.apache.hadoop.yarn.logaggregation.AggregatedLogFormat.LogWriter; //导入方法依赖的package包/类
@Test
public void testReadAcontainerLogs1() throws Exception {
  Configuration conf = new Configuration();
  File workDir = new File(testWorkDir, "testReadAcontainerLogs1");
  Path remoteAppLogFile =
      new Path(workDir.getAbsolutePath(), "aggregatedLogFile");
  Path srcFileRoot = new Path(workDir.getAbsolutePath(), "srcFiles");
  ContainerId testContainerId = TestContainerId.newContainerId(1, 1, 1, 1);
  Path t =
      new Path(srcFileRoot, testContainerId.getApplicationAttemptId()
          .getApplicationId().toString());
  Path srcFilePath = new Path(t, testContainerId.toString());

  int numChars = 80000;

  writeSrcFile(srcFilePath, "stdout", numChars);

  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  LogWriter logWriter = new LogWriter(conf, remoteAppLogFile, ugi);

  LogKey logKey = new LogKey(testContainerId);
  LogValue logValue =
      new LogValue(Collections.singletonList(srcFileRoot.toString()),
          testContainerId, ugi.getShortUserName());

  logWriter.append(logKey, logValue);
  logWriter.close();

  // make sure permission are correct on the file
  FileStatus fsStatus =  fs.getFileStatus(remoteAppLogFile);
  Assert.assertEquals("permissions on log aggregation file are wrong",  
    FsPermission.createImmutable((short) 0640), fsStatus.getPermission()); 

  LogReader logReader = new LogReader(conf, remoteAppLogFile);
  LogKey rLogKey = new LogKey();
  DataInputStream dis = logReader.next(rLogKey);
  Writer writer = new StringWriter();
  LogReader.readAcontainerLogs(dis, writer);
  
  String s = writer.toString();
  int expectedLength =
      "\n\nLogType:stdout".length() + ("\nLogLength:" + numChars).length()
          + "\nLog Contents:\n".length() + numChars;
  Assert.assertTrue("LogType not matched", s.contains("LogType:stdout"));
  Assert.assertTrue("LogLength not matched", s.contains("LogLength:" + numChars));
  Assert.assertTrue("Log Contents not matched", s.contains("Log Contents"));
  
  StringBuilder sb = new StringBuilder();
  for (int i = 0 ; i < numChars ; i++) {
    sb.append(filler);
  }
  String expectedContent = sb.toString();
  Assert.assertTrue("Log content incorrect", s.contains(expectedContent));
  
  Assert.assertEquals(expectedLength, s.length());
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre2,代码行数:57,代码来源:TestAggregatedLogFormat.java


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