Search in sources :

Example 6 with RetryableException

use of io.cdap.cdap.api.retry.RetryableException in project cdap by caskdata.

the class ProvisionerNotifier method publish.

private void publish(Map<String, String> properties) {
    final StoreRequest storeRequest = StoreRequestBuilder.of(topic).addPayload(GSON.toJson(new Notification(Notification.Type.PROGRAM_STATUS, properties))).build();
    Retries.supplyWithRetries(() -> {
        try {
            messagingService.publish(storeRequest);
        } catch (TopicNotFoundException e) {
            throw new RetryableException(e);
        } catch (IOException | AccessException e) {
            throw Throwables.propagate(e);
        }
        return null;
    }, retryStrategy);
}
Also used : RetryableException(io.cdap.cdap.api.retry.RetryableException) AccessException(io.cdap.cdap.api.security.AccessException) TopicNotFoundException(io.cdap.cdap.api.messaging.TopicNotFoundException) StoreRequest(io.cdap.cdap.messaging.StoreRequest) IOException(java.io.IOException) Notification(io.cdap.cdap.proto.Notification)

Example 7 with RetryableException

use of io.cdap.cdap.api.retry.RetryableException in project cdap by cdapio.

the class ProvisionerNotifier method publish.

private void publish(Map<String, String> properties) {
    final StoreRequest storeRequest = StoreRequestBuilder.of(topic).addPayload(GSON.toJson(new Notification(Notification.Type.PROGRAM_STATUS, properties))).build();
    Retries.supplyWithRetries(() -> {
        try {
            messagingService.publish(storeRequest);
        } catch (TopicNotFoundException e) {
            throw new RetryableException(e);
        } catch (IOException | AccessException e) {
            throw Throwables.propagate(e);
        }
        return null;
    }, retryStrategy);
}
Also used : RetryableException(io.cdap.cdap.api.retry.RetryableException) AccessException(io.cdap.cdap.api.security.AccessException) TopicNotFoundException(io.cdap.cdap.api.messaging.TopicNotFoundException) StoreRequest(io.cdap.cdap.messaging.StoreRequest) IOException(java.io.IOException) Notification(io.cdap.cdap.proto.Notification)

Example 8 with RetryableException

use of io.cdap.cdap.api.retry.RetryableException in project cdap by cdapio.

the class BaseStepExecutor method execute.

@Override
public BootstrapStepResult execute(String label, JsonObject argumentsObj) throws InterruptedException {
    T arguments;
    try {
        arguments = GSON.fromJson(argumentsObj, getArgumentsType());
    } catch (JsonParseException e) {
        LOG.warn("Bootstrap step {} failed because its arguments are malformed: {}", label, e.getMessage());
        return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, String.format("Argument decoding failed. Reason: %s", e.getMessage()));
    }
    try {
        arguments.validate();
    } catch (RuntimeException e) {
        LOG.warn("Bootstrap step {} failed due to invalid arguments: {}", label, e.getMessage());
        return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, e.getMessage());
    }
    try {
        LOG.debug("Executing bootstrap step {}", label);
        Retries.runWithInterruptibleRetries(() -> execute(arguments), getRetryStrategy(), t -> t instanceof RetryableException);
        LOG.debug("Bootstrap step {} completed successfully", label);
        return new BootstrapStepResult(label, BootstrapStepResult.Status.SUCCEEDED);
    } catch (InterruptedException e) {
        throw e;
    } catch (Exception e) {
        LOG.warn("Bootstrap step {} failed to execute", label, e);
        return new BootstrapStepResult(label, BootstrapStepResult.Status.FAILED, e.getMessage());
    }
}
Also used : RetryableException(io.cdap.cdap.api.retry.RetryableException) JsonParseException(com.google.gson.JsonParseException) BootstrapStepResult(io.cdap.cdap.proto.bootstrap.BootstrapStepResult) JsonParseException(com.google.gson.JsonParseException) RetryableException(io.cdap.cdap.api.retry.RetryableException)

Example 9 with RetryableException

use of io.cdap.cdap.api.retry.RetryableException 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 10 with RetryableException

use of io.cdap.cdap.api.retry.RetryableException in project cdap by cdapio.

the class DatasetServiceStore method startUp.

@Override
protected void startUp() throws Exception {
    final DatasetId serviceStoreDatasetInstanceId = NamespaceId.SYSTEM.dataset(Constants.Service.SERVICE_INSTANCE_TABLE_NAME);
    table = Retries.supplyWithRetries(() -> {
        try {
            return DatasetsUtil.getOrCreateDataset(dsFramework, serviceStoreDatasetInstanceId, NoTxKeyValueTable.class.getName(), DatasetProperties.EMPTY, null);
        } catch (Exception e) {
            // Throwing RetryableException here is just to make it retry getting the dataset
            // an exception here usually means there is an hbase problem
            LOG.warn("Error getting service store dataset {}. Will retry after some time: {}", serviceStoreDatasetInstanceId, e.getMessage());
            throw new RetryableException(e);
        }
    }, RetryStrategies.exponentialDelay(1, 30, TimeUnit.SECONDS));
}
Also used : RetryableException(io.cdap.cdap.api.retry.RetryableException) RetryableException(io.cdap.cdap.api.retry.RetryableException) DatasetId(io.cdap.cdap.proto.id.DatasetId)

Aggregations

RetryableException (io.cdap.cdap.api.retry.RetryableException)28 IOException (java.io.IOException)16 RetryStrategy (io.cdap.cdap.common.service.RetryStrategy)6 NotFoundException (io.cdap.cdap.common.NotFoundException)5 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)5 Constants (io.cdap.cdap.common.conf.Constants)4 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)4 HttpResponse (io.cdap.common.http.HttpResponse)4 File (java.io.File)4 HttpURLConnection (java.net.HttpURLConnection)4 Path (java.nio.file.Path)4 ZonedDateTime (java.time.ZonedDateTime)4 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)3 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)3 TopicNotFoundException (io.cdap.cdap.api.messaging.TopicNotFoundException)3 AccessException (io.cdap.cdap.api.security.AccessException)3 InvalidArtifactException (io.cdap.cdap.common.InvalidArtifactException)3 ServiceUnavailableException (io.cdap.cdap.common.ServiceUnavailableException)3 Retries (io.cdap.cdap.common.service.Retries)3 Notification (io.cdap.cdap.proto.Notification)3