Search in sources :

Example 1 with EntityNotFoundException

use of com.hedera.mirror.grpc.exception.EntityNotFoundException in project hedera-mirror-node by hashgraph.

the class ProtoUtilTest method toStatusRuntimeException.

@Test
void toStatusRuntimeException() {
    var entityId = EntityId.of(1L, EntityType.ACCOUNT);
    var message = "boom";
    assertException(Exceptions.failWithOverflow(message), Status.DEADLINE_EXCEEDED, OVERFLOW_ERROR);
    assertException(new ConstraintViolationException(message, null), Status.INVALID_ARGUMENT, message);
    assertException(new IllegalArgumentException(message), Status.INVALID_ARGUMENT, message);
    assertException(new InvalidEntityException(message), Status.INVALID_ARGUMENT, message);
    assertException(new EntityNotFoundException(entityId), Status.NOT_FOUND, "Account 0.0.1 does not exist");
    assertException(new NonTransientDataAccessResourceException(message), Status.UNAVAILABLE, DB_ERROR);
    assertException(new QueryTimeoutException(message), Status.RESOURCE_EXHAUSTED, DB_ERROR);
    assertException(new TimeoutException(message), Status.RESOURCE_EXHAUSTED, DB_ERROR);
    assertException(new RuntimeException(message), Status.UNKNOWN, UNKNOWN_ERROR);
}
Also used : QueryTimeoutException(org.springframework.dao.QueryTimeoutException) NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) StatusRuntimeException(io.grpc.StatusRuntimeException) ConstraintViolationException(javax.validation.ConstraintViolationException) EntityNotFoundException(com.hedera.mirror.grpc.exception.EntityNotFoundException) InvalidEntityException(com.hedera.mirror.common.exception.InvalidEntityException) QueryTimeoutException(org.springframework.dao.QueryTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with EntityNotFoundException

use of com.hedera.mirror.grpc.exception.EntityNotFoundException in project hedera-mirror-node by hashgraph.

the class NetworkServiceImpl method getNodes.

@Override
public Flux<AddressBookEntry> getNodes(AddressBookFilter filter) {
    var fileId = filter.getFileId();
    if (!VALID_FILE_IDS.contains(fileId)) {
        throw new IllegalArgumentException(INVALID_FILE_ID);
    }
    long timestamp = addressBookRepository.findLatestTimestamp(fileId.getId()).orElseThrow(() -> new EntityNotFoundException(fileId));
    var context = new AddressBookContext(timestamp);
    return Flux.defer(() -> page(context)).repeatWhen(Repeat.onlyIf(c -> !context.isComplete()).randomBackoff(addressBookProperties.getMinPageDelay(), addressBookProperties.getMaxPageDelay()).jitter(Jitter.random()).withBackoffScheduler(Schedulers.parallel())).take(filter.getLimit() > 0 ? filter.getLimit() : Long.MAX_VALUE).name("addressBook").metrics().doOnNext(context::onNext).doOnSubscribe(s -> log.info("Querying for address book: {}", filter)).doOnComplete(() -> log.info("Retrieved {} nodes from the address book", context.getCount()));
}
Also used : Validated(org.springframework.validation.annotation.Validated) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Jitter(reactor.retry.Jitter) AtomicReference(java.util.concurrent.atomic.AtomicReference) Repeat(reactor.retry.Repeat) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) EntityType(com.hedera.mirror.common.domain.entity.EntityType) AddressBookEntryRepository(com.hedera.mirror.grpc.repository.AddressBookEntryRepository) Value(lombok.Value) EntityNotFoundException(com.hedera.mirror.grpc.exception.EntityNotFoundException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Flux(reactor.core.publisher.Flux) Log4j2(lombok.extern.log4j.Log4j2) AddressBookRepository(com.hedera.mirror.grpc.repository.AddressBookRepository) Schedulers(reactor.core.scheduler.Schedulers) Named(javax.inject.Named) AddressBookFilter(com.hedera.mirror.grpc.domain.AddressBookFilter) EntityNotFoundException(com.hedera.mirror.grpc.exception.EntityNotFoundException)

Aggregations

EntityNotFoundException (com.hedera.mirror.grpc.exception.EntityNotFoundException)2 AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)1 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1 InvalidEntityException (com.hedera.mirror.common.exception.InvalidEntityException)1 AddressBookFilter (com.hedera.mirror.grpc.domain.AddressBookFilter)1 AddressBookEntryRepository (com.hedera.mirror.grpc.repository.AddressBookEntryRepository)1 AddressBookRepository (com.hedera.mirror.grpc.repository.AddressBookRepository)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 Collection (java.util.Collection)1 Set (java.util.Set)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Named (javax.inject.Named)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Value (lombok.Value)1 Log4j2 (lombok.extern.log4j.Log4j2)1