Search in sources :

Example 1 with RuntimeClient

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);
        }
    });
}
Also used : RuntimeClient(io.cdap.cdap.internal.app.runtime.monitor.RuntimeClient) RetryableException(io.cdap.cdap.api.retry.RetryableException) Retries(io.cdap.cdap.common.service.Retries) TopicId(io.cdap.cdap.proto.id.TopicId) IOException(java.io.IOException) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) RetryStrategy(io.cdap.cdap.common.service.RetryStrategy) Notification(io.cdap.cdap.proto.Notification) RetryableException(io.cdap.cdap.api.retry.RetryableException) IOException(java.io.IOException)

Example 2 with RuntimeClient

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);
}
Also used : RuntimeClient(io.cdap.cdap.internal.app.runtime.monitor.RuntimeClient) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Arrays(java.util.Arrays) File(java.io.File)

Example 3 with RuntimeClient

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);
        }
    });
}
Also used : RuntimeClient(io.cdap.cdap.internal.app.runtime.monitor.RuntimeClient) RetryableException(io.cdap.cdap.api.retry.RetryableException) Retries(io.cdap.cdap.common.service.Retries) TopicId(io.cdap.cdap.proto.id.TopicId) IOException(java.io.IOException) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) RetryStrategy(io.cdap.cdap.common.service.RetryStrategy) Notification(io.cdap.cdap.proto.Notification) RetryableException(io.cdap.cdap.api.retry.RetryableException) IOException(java.io.IOException)

Example 4 with RuntimeClient

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);
}
Also used : RuntimeClient(io.cdap.cdap.internal.app.runtime.monitor.RuntimeClient) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Arrays(java.util.Arrays) File(java.io.File)

Aggregations

RuntimeClient (io.cdap.cdap.internal.app.runtime.monitor.RuntimeClient)4 RetryableException (io.cdap.cdap.api.retry.RetryableException)2 Retries (io.cdap.cdap.common.service.Retries)2 RetryStrategy (io.cdap.cdap.common.service.RetryStrategy)2 MessagingProgramStateWriter (io.cdap.cdap.internal.app.program.MessagingProgramStateWriter)2 Notification (io.cdap.cdap.proto.Notification)2 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)2 TopicId (io.cdap.cdap.proto.id.TopicId)2 File (java.io.File)2 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2