use of io.cdap.cdap.internal.app.runtime.monitor.RuntimeClient in project cdap by cdapio.
the class RuntimeServiceMainTest method createProgramStateWriter.
/**
* Creates a {@link ProgramStateWriter} that writes to {@link RuntimeClient} directly.
*
* @param injector the injector for creating the {@link RuntimeClient}
* @param programRunId the {@link ProgramRunId} for the program state change
* @return a {@link ProgramStateWriter}
*/
private ProgramStateWriter createProgramStateWriter(Injector injector, ProgramRunId programRunId) {
RuntimeClient runtimeClient = injector.getInstance(RuntimeClient.class);
// We write to the record event directly to skip the app-fabric to process it
// This is because we don't follow the normal event flow here for testing
TopicId topicId = NamespaceId.SYSTEM.topic(injector.getInstance(CConfiguration.class).get(Constants.AppFabric.PROGRAM_STATUS_RECORD_EVENT_TOPIC));
RetryStrategy retryStrategy = RetryStrategies.timeLimit(5, TimeUnit.SECONDS, RetryStrategies.fixDelay(200, TimeUnit.MILLISECONDS));
return new MessagingProgramStateWriter((notificationType, properties) -> {
Notification notification = new Notification(notificationType, properties);
try {
Retries.callWithRetries((Retries.Callable<Void, Exception>) () -> {
runtimeClient.sendMessages(programRunId, topicId, Collections.singleton(createMessage(notification)).iterator());
return null;
}, retryStrategy, t -> t instanceof IOException || t instanceof RetryableException);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
use of io.cdap.cdap.internal.app.runtime.monitor.RuntimeClient in project cdap by cdapio.
the class SparkRuntimeUtils method uploadEventLogs.
/**
* Uploads the spark event logs through the runtime service.
*/
private static void uploadEventLogs(File eventLogDir, SparkRuntimeContext runtimeContext) throws IOException {
ProgramRunId programRunId = runtimeContext.getProgramRunId();
// Find the event file to upload. There should only be one for the current application.
File eventFile = Optional.ofNullable(eventLogDir.listFiles()).map(Arrays::stream).flatMap(Stream::findFirst).orElse(null);
if (eventFile == null) {
// This shouldn't happen. If it does for some reason, just log and return.
LOG.warn("Cannot find event logs file in {} for program run {}", eventLogDir, programRunId);
return;
}
RuntimeClient runtimeClient = new RuntimeClient(runtimeContext.getCConfiguration(), runtimeContext.getRemoteClientFactory());
Retries.runWithRetries(() -> runtimeClient.uploadSparkEventLogs(programRunId, eventFile), RetryStrategies.fromConfiguration(runtimeContext.getCConfiguration(), "spark."));
LOG.debug("Uploaded event logs file {} for program run {}", eventFile, programRunId);
}
use of io.cdap.cdap.internal.app.runtime.monitor.RuntimeClient in project cdap by caskdata.
the class RuntimeServiceMainTest method createProgramStateWriter.
/**
* Creates a {@link ProgramStateWriter} that writes to {@link RuntimeClient} directly.
*
* @param injector the injector for creating the {@link RuntimeClient}
* @param programRunId the {@link ProgramRunId} for the program state change
* @return a {@link ProgramStateWriter}
*/
private ProgramStateWriter createProgramStateWriter(Injector injector, ProgramRunId programRunId) {
RuntimeClient runtimeClient = injector.getInstance(RuntimeClient.class);
// We write to the record event directly to skip the app-fabric to process it
// This is because we don't follow the normal event flow here for testing
TopicId topicId = NamespaceId.SYSTEM.topic(injector.getInstance(CConfiguration.class).get(Constants.AppFabric.PROGRAM_STATUS_RECORD_EVENT_TOPIC));
RetryStrategy retryStrategy = RetryStrategies.timeLimit(5, TimeUnit.SECONDS, RetryStrategies.fixDelay(200, TimeUnit.MILLISECONDS));
return new MessagingProgramStateWriter((notificationType, properties) -> {
Notification notification = new Notification(notificationType, properties);
try {
Retries.callWithRetries((Retries.Callable<Void, Exception>) () -> {
runtimeClient.sendMessages(programRunId, topicId, Collections.singleton(createMessage(notification)).iterator());
return null;
}, retryStrategy, t -> t instanceof IOException || t instanceof RetryableException);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
use of io.cdap.cdap.internal.app.runtime.monitor.RuntimeClient in project cdap by caskdata.
the class SparkRuntimeUtils method uploadEventLogs.
/**
* Uploads the spark event logs through the runtime service.
*/
private static void uploadEventLogs(File eventLogDir, SparkRuntimeContext runtimeContext) throws IOException {
ProgramRunId programRunId = runtimeContext.getProgramRunId();
// Find the event file to upload. There should only be one for the current application.
File eventFile = Optional.ofNullable(eventLogDir.listFiles()).map(Arrays::stream).flatMap(Stream::findFirst).orElse(null);
if (eventFile == null) {
// This shouldn't happen. If it does for some reason, just log and return.
LOG.warn("Cannot find event logs file in {} for program run {}", eventLogDir, programRunId);
return;
}
RuntimeClient runtimeClient = new RuntimeClient(runtimeContext.getCConfiguration(), runtimeContext.getRemoteClientFactory());
Retries.runWithRetries(() -> runtimeClient.uploadSparkEventLogs(programRunId, eventFile), RetryStrategies.fromConfiguration(runtimeContext.getCConfiguration(), "spark."));
LOG.debug("Uploaded event logs file {} for program run {}", eventFile, programRunId);
}
Aggregations