Search in sources :

Example 1 with PublishResponse

use of com.hedera.mirror.monitor.publish.PublishResponse in project hedera-mirror-node by hashgraph.

the class CompositeSubscriberTest method onPublish.

@Test
void onPublish() {
    PublishResponse publishResponse = PublishResponse.builder().build();
    compositeSubscriber.onPublish(publishResponse);
    verify(mirrorSubscriber1).onPublish(publishResponse);
    verify(mirrorSubscriber2).onPublish(publishResponse);
}
Also used : PublishResponse(com.hedera.mirror.monitor.publish.PublishResponse) Test(org.junit.jupiter.api.Test)

Example 2 with PublishResponse

use of com.hedera.mirror.monitor.publish.PublishResponse in project hedera-mirror-node by hashgraph.

the class RestSubscriber method clientSubscribe.

private Flux<SubscribeResponse> clientSubscribe(RestSubscription subscription) {
    RestSubscriberProperties properties = subscription.getProperties();
    RetryBackoffSpec retrySpec = Retry.backoff(properties.getRetry().getMaxAttempts(), properties.getRetry().getMinBackoff()).maxBackoff(properties.getRetry().getMaxBackoff()).filter(this::shouldRetry).doBeforeRetry(r -> log.debug("Retry attempt #{} after failure: {}", r.totalRetries() + 1, r.failure().getMessage()));
    return subscription.getSink().asFlux().publishOn(Schedulers.parallel()).doFinally(s -> subscription.onComplete()).doOnNext(publishResponse -> log.trace("Querying REST API: {}", publishResponse)).flatMap(publishResponse -> webClient.get().uri("/transactions/{transactionId}", toString(publishResponse.getTransactionId())).retrieve().bodyToMono(MirrorTransaction.class).name("rest").metrics().timeout(properties.getTimeout()).retryWhen(retrySpec).onErrorContinue((t, o) -> subscription.onError(t)).doOnNext(subscription::onNext).map(transaction -> toResponse(subscription, publishResponse, transaction))).take(properties.getLimit(), true).take(properties.getDuration());
}
Also used : TransactionId(com.hedera.hashgraph.sdk.TransactionId) Retry(reactor.util.retry.Retry) SubscribeProperties(com.hedera.mirror.monitor.subscribe.SubscribeProperties) MirrorSubscriber(com.hedera.mirror.monitor.subscribe.MirrorSubscriber) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) Set(java.util.Set) WebClient(org.springframework.web.reactive.function.client.WebClient) RetryBackoffSpec(reactor.util.retry.RetryBackoffSpec) Instant(java.time.Instant) ArrayList(java.util.ArrayList) SecureRandom(java.security.SecureRandom) MirrorTransaction(com.hedera.mirror.monitor.subscribe.rest.response.MirrorTransaction) HttpStatus(org.springframework.http.HttpStatus) Flux(reactor.core.publisher.Flux) PublishResponse(com.hedera.mirror.monitor.publish.PublishResponse) List(java.util.List) Log4j2(lombok.extern.log4j.Log4j2) Schedulers(reactor.core.scheduler.Schedulers) WebClientResponseException(org.springframework.web.reactive.function.client.WebClientResponseException) Named(javax.inject.Named) MonitorProperties(com.hedera.mirror.monitor.MonitorProperties) SubscribeResponse(com.hedera.mirror.monitor.subscribe.SubscribeResponse) RetryBackoffSpec(reactor.util.retry.RetryBackoffSpec)

Example 3 with PublishResponse

use of com.hedera.mirror.monitor.publish.PublishResponse in project hedera-mirror-node by hashgraph.

the class ExpressionConverterImpl method doConvert.

private synchronized String doConvert(Expression expression) {
    if (expressions.containsKey(expression)) {
        return expressions.get(expression);
    }
    try {
        log.debug("Processing expression {}", expression);
        ExpressionType type = expression.getType();
        Class<? extends TransactionSupplier<?>> supplierClass = type.getTransactionType().getSupplier();
        TransactionSupplier<?> transactionSupplier = supplierClass.getConstructor().newInstance();
        if (transactionSupplier instanceof AdminKeyable) {
            AdminKeyable adminKeyable = (AdminKeyable) transactionSupplier;
            PrivateKey privateKey = PrivateKey.fromString(monitorProperties.getOperator().getPrivateKey());
            adminKeyable.setAdminKey(privateKey.getPublicKey().toString());
        }
        if (transactionSupplier instanceof TokenCreateTransactionSupplier) {
            TokenCreateTransactionSupplier tokenSupplier = (TokenCreateTransactionSupplier) transactionSupplier;
            tokenSupplier.setTreasuryAccountId(monitorProperties.getOperator().getAccountId());
            if (type == ExpressionType.NFT) {
                tokenSupplier.setType(TokenType.NON_FUNGIBLE_UNIQUE);
            }
        }
        // if ScheduleCreate set the properties to the inner scheduledTransactionProperties
        if (transactionSupplier instanceof ScheduleCreateTransactionSupplier) {
            var scheduleCreateTransactionSupplier = (ScheduleCreateTransactionSupplier) transactionSupplier;
            scheduleCreateTransactionSupplier.setOperatorAccountId(monitorProperties.getOperator().getAccountId());
            scheduleCreateTransactionSupplier.setPayerAccount(monitorProperties.getOperator().getAccountId());
        }
        PublishScenarioProperties publishScenarioProperties = new PublishScenarioProperties();
        publishScenarioProperties.setName(expression.toString());
        publishScenarioProperties.setTimeout(Duration.ofSeconds(30L));
        publishScenarioProperties.setType(type.getTransactionType());
        PublishScenario scenario = new PublishScenario(publishScenarioProperties);
        // We use explicit retry instead of the SDK retry since we need to regenerate the transaction to
        // avoid transaction expired errors
        Retry retrySpec = Retry.backoff(Long.MAX_VALUE, Duration.ofSeconds(1L)).maxBackoff(Duration.ofSeconds(8L)).doBeforeRetry(r -> log.warn("Retry attempt #{} after failure: {}", r.totalRetries() + 1, r.failure().getMessage()));
        return Mono.defer(() -> transactionPublisher.publish(PublishRequest.builder().receipt(true).scenario(scenario).timestamp(Instant.now()).transaction(transactionSupplier.get().setMaxAttempts(1).setTransactionMemo(scenario.getMemo())).build())).retryWhen(retrySpec).map(PublishResponse::getReceipt).map(type.getIdExtractor()::apply).doOnSuccess(id -> log.info("Created {} entity {}", type, id)).toFuture().join();
    } catch (Exception e) {
        log.error("Error converting expression {}:", expression, e);
        throw new RuntimeException(e);
    }
}
Also used : TokenCreateTransactionSupplier(com.hedera.mirror.monitor.publish.transaction.token.TokenCreateTransactionSupplier) PublishResponse(com.hedera.mirror.monitor.publish.PublishResponse) PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) PublishScenarioProperties(com.hedera.mirror.monitor.publish.PublishScenarioProperties) AdminKeyable(com.hedera.mirror.monitor.publish.transaction.AdminKeyable) ScheduleCreateTransactionSupplier(com.hedera.mirror.monitor.publish.transaction.schedule.ScheduleCreateTransactionSupplier) Retry(reactor.util.retry.Retry) PublishScenario(com.hedera.mirror.monitor.publish.PublishScenario)

Aggregations

PublishResponse (com.hedera.mirror.monitor.publish.PublishResponse)3 Retry (reactor.util.retry.Retry)2 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 TransactionId (com.hedera.hashgraph.sdk.TransactionId)1 MonitorProperties (com.hedera.mirror.monitor.MonitorProperties)1 PublishScenario (com.hedera.mirror.monitor.publish.PublishScenario)1 PublishScenarioProperties (com.hedera.mirror.monitor.publish.PublishScenarioProperties)1 AdminKeyable (com.hedera.mirror.monitor.publish.transaction.AdminKeyable)1 ScheduleCreateTransactionSupplier (com.hedera.mirror.monitor.publish.transaction.schedule.ScheduleCreateTransactionSupplier)1 TokenCreateTransactionSupplier (com.hedera.mirror.monitor.publish.transaction.token.TokenCreateTransactionSupplier)1 MirrorSubscriber (com.hedera.mirror.monitor.subscribe.MirrorSubscriber)1 SubscribeProperties (com.hedera.mirror.monitor.subscribe.SubscribeProperties)1 SubscribeResponse (com.hedera.mirror.monitor.subscribe.SubscribeResponse)1 MirrorTransaction (com.hedera.mirror.monitor.subscribe.rest.response.MirrorTransaction)1 SecureRandom (java.security.SecureRandom)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Set (java.util.Set)1