Search in sources :

Example 1 with PublishScenario

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

the class RestSubscriberTest method setup.

@BeforeEach
void setup() {
    MonitorProperties monitorProperties = new MonitorProperties();
    monitorProperties.setMirrorNode(new MirrorNodeProperties());
    monitorProperties.getMirrorNode().getRest().setHost("127.0.0.1");
    restSubscriberProperties = new RestSubscriberProperties();
    restSubscriberProperties.setLimit(3L);
    restSubscriberProperties.setName("test");
    restSubscriberProperties.getRetry().setMaxAttempts(2L);
    restSubscriberProperties.getRetry().setMinBackoff(Duration.ofNanos(1L));
    restSubscriberProperties.getRetry().setMaxBackoff(Duration.ofNanos(2L));
    PublishScenarioProperties publishScenarioProperties = new PublishScenarioProperties();
    publishScenarioProperties.setName(SCENARIO);
    publishScenarioProperties.setType(TransactionType.CONSENSUS_SUBMIT_MESSAGE);
    publishScenario = new PublishScenario(publishScenarioProperties);
    subscribeProperties = new SubscribeProperties();
    subscribeProperties.getRest().put(restSubscriberProperties.getName(), restSubscriberProperties);
    WebClient.Builder builder = WebClient.builder().exchangeFunction(exchangeFunction);
    restSubscriber = new RestSubscriber(monitorProperties, subscribeProperties, builder);
}
Also used : SubscribeProperties(com.hedera.mirror.monitor.subscribe.SubscribeProperties) PublishScenarioProperties(com.hedera.mirror.monitor.publish.PublishScenarioProperties) MirrorNodeProperties(com.hedera.mirror.monitor.MirrorNodeProperties) WebClient(org.springframework.web.reactive.function.client.WebClient) MonitorProperties(com.hedera.mirror.monitor.MonitorProperties) PublishScenario(com.hedera.mirror.monitor.publish.PublishScenario) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with PublishScenario

use of com.hedera.mirror.monitor.publish.PublishScenario 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

PublishScenario (com.hedera.mirror.monitor.publish.PublishScenario)2 PublishScenarioProperties (com.hedera.mirror.monitor.publish.PublishScenarioProperties)2 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 MirrorNodeProperties (com.hedera.mirror.monitor.MirrorNodeProperties)1 MonitorProperties (com.hedera.mirror.monitor.MonitorProperties)1 PublishResponse (com.hedera.mirror.monitor.publish.PublishResponse)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 SubscribeProperties (com.hedera.mirror.monitor.subscribe.SubscribeProperties)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 WebClient (org.springframework.web.reactive.function.client.WebClient)1 Retry (reactor.util.retry.Retry)1