use of io.cdap.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class LogHttpHandler method getRunIdLogs.
@GET
@Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/runs/{run-id}/logs")
public void getRunIdLogs(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId, @PathParam("run-id") String runId, @QueryParam("start") @DefaultValue("-1") long fromTimeSecsParam, @QueryParam("stop") @DefaultValue("-1") long toTimeSecsParam, @QueryParam("escape") @DefaultValue("true") boolean escape, @QueryParam("filter") @DefaultValue("") String filterStr, @QueryParam("format") @DefaultValue("text") String format, @QueryParam("suppress") List<String> suppress) throws Exception {
ensureVisibilityOnProgram(namespaceId, appId, programType, programId);
ProgramType type = ProgramType.valueOfCategoryName(programType);
ProgramRunId programRunId = new ProgramRunId(namespaceId, appId, type, programId, runId);
RunRecordDetail runRecord = getRunRecordMeta(programRunId);
LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(programRunId, runRecord.getSystemArgs());
doGetLogs(logReader, responder, loggingContext, fromTimeSecsParam, toTimeSecsParam, escape, filterStr, runRecord, format, suppress);
}
use of io.cdap.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class TestFileLogging method testGetLogNext.
@Test
public void testGetLogNext() throws Exception {
LoggingContext loggingContext = new WorkerLoggingContext("TFL_NS_1", "APP_1", "WORKER_1", "RUN1", "INSTANCE1");
FileLogReader logReader = injector.getInstance(FileLogReader.class);
LoggingTester tester = new LoggingTester();
tester.testGetNext(logReader, loggingContext);
}
use of io.cdap.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class TestKafkaLogging method testGetNext.
@Test
public void testGetNext() throws Exception {
// Check with null runId and null instanceId
LoggingContext loggingContext = new WorkerLoggingContext("TKL_NS_1", "APP_1", "FLOW_1", "RUN1", "INSTANCE1");
KafkaLogReader logReader = KAFKA_TESTER.getInjector().getInstance(KafkaLogReader.class);
LoggingTester tester = new LoggingTester();
tester.testGetNext(logReader, loggingContext);
}
use of io.cdap.cdap.common.logging.LoggingContext in project cdap by cdapio.
the class RemoteExecutionService method shouldRetry.
@Override
protected boolean shouldRetry(Exception ex) {
LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(programRunId, null);
Cancellable cancellable = LoggingContextAccessor.setLoggingContext(loggingContext);
try {
OUTAGE_LOGGER.warn("Exception raised when monitoring program run {}", programRunId, ex);
try {
// If the program is not running, abort retry
if (!processController.isRunning()) {
LOG.debug("Program {} is not running", programRunId, ex);
// Always emit an error state. If this is indeed a normal stop, there should be a completion state
// in the TMS before this one, in which this one will get ignored by the
programStateWriter.error(programRunId, new IllegalStateException("Program terminated " + programRunId, ex));
return false;
}
} catch (Exception e) {
OUTAGE_LOGGER.warn("Failed to check if the remote process is still running for program {}", programRunId, e);
}
return true;
} finally {
cancellable.cancel();
}
}
use of io.cdap.cdap.common.logging.LoggingContext in project cdap by cdapio.
the class ProvisioningService method callWithProgramLogging.
/**
* Calls the {@link Callable} with the logging context set to the program run's context.
* Anything logged within the runnable will be treated as if they were logs in the program run.
*
* @param programRunId the program run to log as
* @param systemArgs system arguments for the run
* @param callable the {@link Callable} to call
* @return the value returned by the {@link Callable#call()} method
* @throws Exception if the {@link Callable#call()} method thrown an exception
*/
private <V> V callWithProgramLogging(ProgramRunId programRunId, Map<String, String> systemArgs, Callable<V> callable) throws Exception {
LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(programRunId, systemArgs);
Cancellable cancellable = LoggingContextAccessor.setLoggingContext(loggingContext);
try {
return callable.call();
} finally {
cancellable.cancel();
}
}
Aggregations