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);
}
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);
}
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());
}
}
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);
}
});
}
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));
}
Aggregations