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


Java LogHandler类代码示例

本文整理汇总了Java中org.apache.twill.api.logging.LogHandler的典型用法代码示例。如果您正苦于以下问题:Java LogHandler类的具体用法?Java LogHandler怎么用?Java LogHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LogHandler类属于org.apache.twill.api.logging包,在下文中一共展示了LogHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: YarnTwillController

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
/**
 * Creates an instance with an existing {@link ApplicationMasterLiveNodeData}.
 */
YarnTwillController(String appName, RunId runId, ZKClient zkClient,
                    final ApplicationMasterLiveNodeData amLiveNodeData, final YarnAppClient yarnAppClient) {
  super(appName, runId, zkClient, amLiveNodeData.getKafkaZKConnect() != null, Collections.<LogHandler>emptyList());
  this.appName = appName;
  this.amLiveNodeData = amLiveNodeData;
  this.startUp = new Callable<ProcessController<YarnApplicationReport>>() {
    @Override
    public ProcessController<YarnApplicationReport> call() throws Exception {
      return yarnAppClient.createProcessController(
        YarnUtils.createApplicationId(amLiveNodeData.getAppIdClusterTime(), amLiveNodeData.getAppId()));
    }
  };
  this.startTimeout = Constants.APPLICATION_MAX_START_SECONDS;
  this.startTimeoutUnit = TimeUnit.SECONDS;
}
 
开发者ID:apache,项目名称:twill,代码行数:19,代码来源:YarnTwillController.java

示例2: testInitFail

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
@Test
public void testInitFail() throws InterruptedException, ExecutionException, TimeoutException {
  TwillRunner runner = getTwillRunner();
  final CountDownLatch logLatch = new CountDownLatch(1);

  // Verify that it receives the exception log entry that thrown when runnable initialize
  LogHandler logVerifyHandler = new LogHandler() {
    @Override
    public void onLog(LogEntry logEntry) {
      if (logEntry.getMessage().endsWith("exited abnormally with state COMPLETE, exit code 10.")) {
        logLatch.countDown();
      }
    }
  };

  TwillController controller = runner
    .prepare(new InitFailRunnable())
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out)))
    .addLogHandler(logVerifyHandler)
    .start();

  controller.awaitTerminated(2, TimeUnit.MINUTES);
  Assert.assertTrue(logLatch.await(10, TimeUnit.SECONDS));
}
 
开发者ID:apache,项目名称:twill,代码行数:25,代码来源:InitializeFailTestRun.java

示例3: maxRetriesRun

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
private void maxRetriesRun(final int instances) throws TimeoutException, ExecutionException {
  TwillRunner runner = getTwillRunner();
  final int maxRetries = 3;
  final AtomicInteger retriesSeen = new AtomicInteger(0);

  ResourceSpecification resource = ResourceSpecification.Builder.with().setVirtualCores(1)
    .setMemory(512, ResourceSpecification.SizeUnit.MEGA).setInstances(instances).build();

  TwillController controller = runner.prepare(new FailingServer(), resource)
    .withMaxRetries(FailingServer.class.getSimpleName(), maxRetries)
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
    .addLogHandler(new LogHandler() {
      @Override
      public void onLog(LogEntry logEntry) {
        if (logEntry.getMessage().contains("retries for instance")) {
          retriesSeen.incrementAndGet();
        }
      }
    })
    .start();

  controller.awaitTerminated(2, TimeUnit.MINUTES);
  Assert.assertEquals(maxRetries * instances, retriesSeen.get());
}
 
开发者ID:apache,项目名称:twill,代码行数:25,代码来源:MaxRetriesTestRun.java

示例4: AbstractTwillController

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
public AbstractTwillController(String appName, RunId runId, ZKClient zkClient, boolean logCollectionEnabled,
                               Iterable<LogHandler> logHandlers) {
  super(runId, zkClient);
  this.appName = appName;
  this.runId = runId;
  this.logHandlers = new ConcurrentLinkedQueue<>();

  // When addressing TWILL-147, need to check if the given ZKClient is
  // actually used by the Kafka used for log collection
  if (logCollectionEnabled) {
    this.kafkaClient = new ZKKafkaClientService(ZKClients.namespace(zkClient, "/" + runId.getId() + "/kafka"));
    Iterables.addAll(this.logHandlers, logHandlers);
  } else {
    this.kafkaClient = null;
    if (!Iterables.isEmpty(logHandlers)) {
      LOG.warn("Log collection is disabled for application {} with runId {}. " +
                 "Adding log handler won't get any logs.", appName, runId);
    }
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:21,代码来源:AbstractTwillController.java

示例5: addLogHandler

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
@Override
public final synchronized void addLogHandler(LogHandler handler) {
  if (kafkaClient == null) {
    LOG.warn("Log collection is disabled for application {} with runId {}. " +
               "Adding log handler won't get any logs.", appName, runId);
    return;
  }

  logHandlers.add(handler);
  if (logHandlers.size() == 1) {
    kafkaClient.startAndWait();
    logCancellable = kafkaClient.getConsumer().prepare()
      .addFromBeginning(Constants.LOG_TOPIC, 0)
      .consume(new LogMessageCallback(logHandlers));
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:17,代码来源:AbstractTwillController.java

示例6: prepare

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
@Override
public TwillPreparer prepare(TwillApplication application) {
  Preconditions.checkState(isRunning(), "Service not start. Please call start() first.");
  final TwillSpecification twillSpec = application.configure();
  final String appName = twillSpec.getName();

  return new YarnTwillPreparer(yarnConfig, twillSpec, yarnAppClient, zkClientService, locationFactory, jvmOptions,
                               new YarnTwillControllerFactory() {
    @Override
    public YarnTwillController create(RunId runId, Iterable<LogHandler> logHandlers,
                                      Callable<ProcessController<YarnApplicationReport>> startUp) {
      ZKClient zkClient = ZKClients.namespace(zkClientService, "/" + appName);
      YarnTwillController controller = listenController(new YarnTwillController(appName, runId, zkClient,
                                                                                logHandlers, startUp));
      synchronized (YarnTwillRunnerService.this) {
        Preconditions.checkArgument(!controllers.contains(appName, runId),
                                    "Application %s with runId %s is already running.", appName, runId);
        controllers.put(appName, runId, controller);
      }
      return controller;
    }
  });
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:24,代码来源:YarnTwillRunnerService.java

示例7: testDisableLogCollection

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
@Test
public void testDisableLogCollection() throws Exception {
  final AtomicBoolean logReceived = new AtomicBoolean();

  // Start the LogRunnable by turning off log collection
  TwillRunner runner = getTwillRunner();
  TwillController controller = runner.prepare(new LogRunnable())
    .withConfiguration(Collections.singletonMap(Configs.Keys.LOG_COLLECTION_ENABLED, "false"))
    .addLogHandler(new LogHandler() {
      @Override
      public void onLog(LogEntry logEntry) {
        logReceived.set(true);
      }
    })
    .start();

  // Make sure the runnable gets executed
  try {
    final CountDownLatch latch = new CountDownLatch(1);
    controller.discoverService("log").watchChanges(new ServiceDiscovered.ChangeListener() {
      @Override
      public void onChange(ServiceDiscovered serviceDiscovered) {
        if (Iterables.size(serviceDiscovered) == 1) {
          latch.countDown();
        }
      }
    }, Threads.SAME_THREAD_EXECUTOR);
    Assert.assertTrue(latch.await(120, TimeUnit.SECONDS));
  } finally {
    controller.terminate().get(120, TimeUnit.SECONDS);
  }

  // Should receive no log
  Assert.assertFalse("Not expecting logs collected", logReceived.get());
}
 
开发者ID:apache,项目名称:twill,代码行数:36,代码来源:LogHandlerTestRun.java

示例8: invokeHandlers

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
private void invokeHandlers(LogEntry entry) {
  for (LogHandler handler : logHandlers) {
    try {
      handler.onLog(entry);
    } catch (Throwable t) {
      LOG.warn("Exception while calling LogHandler {}", handler, t);
    }
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:10,代码来源:AbstractTwillController.java

示例9: getController

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
private TwillController getController(ZKClient zkClient, String appName, RunId runId) {
  AbstractTwillController controller = new AbstractTwillController(appName, runId,
                                                                   zkClient, false, ImmutableList.<LogHandler>of()) {

    @Override
    public void kill() {
      // No-op
    }

    @Override
    protected void instanceNodeUpdated(NodeData nodeData) {
      // No-op
    }

    @Override
    protected void instanceNodeFailed(Throwable cause) {
      // Shutdown if the instance node goes away
      if (cause instanceof KeeperException.NoNodeException) {
        forceShutDown();
      }
    }

    @Override
    public ResourceReport getResourceReport() {
      return null;
    }
  };
  controller.startAndWait();
  return controller;
}
 
开发者ID:apache,项目名称:twill,代码行数:31,代码来源:ControllerTest.java

示例10: AbstractTwillController

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
public AbstractTwillController(RunId runId, ZKClient zkClient, Iterable<LogHandler> logHandlers) {
  super(runId, zkClient);
  this.logHandlers = new ConcurrentLinkedQueue<LogHandler>();
  this.kafkaClient = new ZKKafkaClientService(ZKClients.namespace(zkClient, "/" + runId.getId() + "/kafka"));
  this.discoveryServiceClient = new ZKDiscoveryService(zkClient);
  Iterables.addAll(this.logHandlers, logHandlers);
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:8,代码来源:AbstractTwillController.java

示例11: addLogHandler

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
@Override
public final synchronized void addLogHandler(LogHandler handler) {
  logHandlers.add(handler);
  if (logHandlers.size() == 1) {
    kafkaClient.startAndWait();
    logCancellable = kafkaClient.getConsumer().prepare()
      .addFromBeginning(Constants.LOG_TOPIC, 0)
      .consume(new LogMessageCallback(logHandlers));
  }
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:11,代码来源:AbstractTwillController.java

示例12: getController

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
private TwillController getController(ZKClient zkClient, RunId runId) {
  TwillController controller = new AbstractTwillController(runId, zkClient, ImmutableList.<LogHandler>of()) {

    @Override
    public void kill() {
      // No-op
    }

    @Override
    protected void instanceNodeUpdated(NodeData nodeData) {
      // No-op
    }

    @Override
    protected void instanceNodeFailed(Throwable cause) {
      // Shutdown if the instance node goes away
      if (cause instanceof KeeperException.NoNodeException) {
        forceShutDown();
      }
    }

    @Override
    public ResourceReport getResourceReport() {
      return null;
    }
  };
  controller.startAndWait();
  return controller;
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:30,代码来源:ControllerTest.java

示例13: addLogHandler

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
@Override
public TwillPreparer addLogHandler(LogHandler handler) {
  logHandlers.add(handler);
  return this;
}
 
开发者ID:apache,项目名称:twill,代码行数:6,代码来源:YarnTwillPreparer.java

示例14: create

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
YarnTwillController create(RunId runId, boolean logCollectionEnabled, Iterable<LogHandler> logHandlers,
Callable<ProcessController<YarnApplicationReport>> startUp,
long startTimeout, TimeUnit startTimeoutUnit);
 
开发者ID:apache,项目名称:twill,代码行数:4,代码来源:YarnTwillControllerFactory.java

示例15: testLogHandler

import org.apache.twill.api.logging.LogHandler; //导入依赖的package包/类
@Test
public void testLogHandler() throws ExecutionException, InterruptedException, TimeoutException {
  final CountDownLatch latch = new CountDownLatch(3);
  final Queue<LogThrowable> throwables = new ConcurrentLinkedQueue<LogThrowable>();
  final Queue<String> runnables = new ConcurrentLinkedQueue<String>();

  LogHandler logHandler = new LogHandler() {
    @Override
    public void onLog(LogEntry logEntry) {
      // Would expect logs from AM and the runnable.
      if (logEntry.getSourceClassName().contains("LogHandlerTestRun")) {
        runnables.add(logEntry.getRunnableName());
      }
      // Runnable name for AM should be null
      if (logEntry.getSourceClassName().contains("ApplicationMasterService")) {
        Assert.assertNull(logEntry.getRunnableName());
      }
      if (logEntry.getMessage().startsWith("Starting runnable " + LogRunnable.class.getSimpleName())) {
        latch.countDown();
      } else if (logEntry.getMessage().equals("Running")) {
        latch.countDown();
      } else if (logEntry.getMessage().equals("Got exception") && logEntry.getThrowable() != null) {
        throwables.add(logEntry.getThrowable());
        latch.countDown();
      }
    }
  };

  TwillRunner runner = getTwillRunner();
  TwillController controller = runner.prepare(new LogRunnable())
                                     .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
                                     .addLogHandler(logHandler)
                                     .start();

  try {
    Assert.assertTrue(latch.await(100, TimeUnit.SECONDS));
  } finally {
    controller.terminate().get(120, TimeUnit.SECONDS);
  }

  // Verify the runnable names
  Assert.assertEquals(2, runnables.size());
  Assert.assertArrayEquals(new String[] {"LogRunnable", "LogRunnable"}, runnables.toArray());

  // Verify the log throwable
  Assert.assertEquals(1, throwables.size());

  LogThrowable t = throwables.poll();
  Assert.assertEquals(RuntimeException.class.getName(), t.getClassName());
  Assert.assertNotNull(t.getCause());
  Assert.assertEquals(5, t.getStackTraces().length);

  t = t.getCause();
  Assert.assertEquals(Exception.class.getName(), t.getClassName());
  Assert.assertEquals("Exception", t.getMessage());
}
 
开发者ID:apache,项目名称:twill,代码行数:57,代码来源:LogHandlerTestRun.java


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