Java Code Examples for io.grpc.Status.Code#NOT_FOUND
The following examples show how to use
io.grpc.Status.Code#NOT_FOUND .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KvClient.java From kvstore with Apache License 2.0 | 6 votes |
/** * Retrieves the value of a random key. */ private void doRetrieve(KeyValueServiceBlockingStub stub) { ByteString key = knownKeys.getRandomKey(); try { RetrieveResponse res = stub.retrieve(RetrieveRequest.newBuilder() .setKey(key) .build()); if (res.getValue().size() < 1) { throw new RuntimeException("Invalid response"); } } catch (StatusRuntimeException e) { if (e.getStatus().getCode() == Code.NOT_FOUND) { knownKeys.remove(key); logger.log(Level.INFO, "Key not found", e); } else { throw e; } } }
Example 2
Source File: EnvironmentAccessChecker.java From cloudbreak with Apache License 2.0 | 6 votes |
public EnvironmentAccessRights hasAccess(String memberCrn, Optional<String> requestId) { requireNonNull(memberCrn, "memberCrn is null"); requireNonNull(requestId, "requestId is null"); try { List<Boolean> hasRights = grpcUmsClient.hasRights(INTERNAL_ACTOR_CRN, memberCrn, rightChecks, requestId); return new EnvironmentAccessRights(hasRights.get(0), hasRights.get(1)); } catch (StatusRuntimeException e) { // NOT_FOUND errors indicate that a user/machineUser has been deleted after we have // retrieved the list of users/machineUsers from the UMS. Treat these users as if // they do not have the right to access this environment and belong to no groups. if (e.getStatus().getCode() == Code.NOT_FOUND) { LOGGER.warn("Member CRN {} not found in UMS. Treating as if member has no rights to environment {}: {}", memberCrn, environmentCrn, e.getLocalizedMessage()); return new EnvironmentAccessRights(false, false); } else { throw e; } } }
Example 3
Source File: VirtualGroupService.java From cloudbreak with Apache License 2.0 | 6 votes |
private String createOrGetVirtualGroup(String accountId, String environmentCrn, String right) { String virtualGroup = ""; try { virtualGroup = grpcUmsClient.getWorkloadAdministrationGroupName(INTERNAL_ACTOR_CRN, accountId, MDCUtils.getRequestId(), right, environmentCrn); } catch (StatusRuntimeException ex) { if (Code.NOT_FOUND != ex.getStatus().getCode()) { throw ex; } } if (StringUtils.isEmpty(virtualGroup)) { virtualGroup = grpcUmsClient.setWorkloadAdministrationGroupName(INTERNAL_ACTOR_CRN, accountId, MDCUtils.getRequestId(), right, environmentCrn); LOGGER.info("{} workloadAdministrationGroup is created for {} right on {} environment", virtualGroup, right, environmentCrn); } else { LOGGER.info("{} workloadAdministrationGroup is used for {} right on {} environment", virtualGroup, right, environmentCrn); } return virtualGroup; }
Example 4
Source File: RepositoryDAORdbImpl.java From modeldb with Apache License 2.0 | 6 votes |
@Override public DeleteBranchRequest.Response deleteBranch(DeleteBranchRequest request) throws ModelDBException { try (Session session = ModelDBHibernateUtil.getSessionFactory().openSession()) { RepositoryEntity repository = getRepositoryById(session, request.getRepositoryId(), true); BranchEntity branchEntity = session.get( BranchEntity.class, new BranchEntity.BranchId(request.getBranch(), repository.getId())); if (branchEntity == null) { throw new ModelDBException( ModelDBConstants.BRANCH_NOT_FOUND + request.getBranch(), Code.NOT_FOUND); } session.beginTransaction(); session.delete(branchEntity); session.getTransaction().commit(); return DeleteBranchRequest.Response.newBuilder().build(); } catch (Exception ex) { if (ModelDBUtils.needToRetry(ex)) { return deleteBranch(request); } else { throw ex; } } }
Example 5
Source File: RepositoryDAORdbImpl.java From modeldb with Apache License 2.0 | 6 votes |
private void saveBranch( Session session, String commitSHA, String branch, RepositoryEntity repository) throws ModelDBException { boolean exists = VersioningUtils.commitRepositoryMappingExists(session, commitSHA, repository.getId()); if (!exists) { throw new ModelDBException( "Commit_hash and repository_id mapping not found for repository " + repository.getId() + " and commit " + commitSHA, Code.NOT_FOUND); } Query query = session.createQuery(CHECK_BRANCH_IN_REPOSITORY_HQL); query.setParameter("repositoryId", repository.getId()); query.setParameter("branch", branch); BranchEntity branchEntity = (BranchEntity) query.uniqueResult(); if (branchEntity != null) { if (branchEntity.getCommit_hash().equals(commitSHA)) return; session.delete(branchEntity); } branchEntity = new BranchEntity(repository.getId(), commitSHA, branch); session.save(branchEntity); }
Example 6
Source File: RepositoryDAORdbImpl.java From modeldb with Apache License 2.0 | 6 votes |
@Override public DeleteTagRequest.Response deleteTag(DeleteTagRequest request) throws ModelDBException { try (Session session = ModelDBHibernateUtil.getSessionFactory().openSession()) { RepositoryEntity repository = getRepositoryById(session, request.getRepositoryId(), true); TagsEntity tagsEntity = session.get(TagsEntity.class, new TagsEntity.TagId(request.getTag(), repository.getId())); if (tagsEntity == null) { throw new ModelDBException("Tag not found " + request.getTag(), Code.NOT_FOUND); } session.beginTransaction(); session.delete(tagsEntity); session.getTransaction().commit(); return DeleteTagRequest.Response.newBuilder().build(); } catch (Exception ex) { if (ModelDBUtils.needToRetry(ex)) { return deleteTag(request); } else { throw ex; } } }
Example 7
Source File: RepositoryDAORdbImpl.java From modeldb with Apache License 2.0 | 6 votes |
@Override public GetTagRequest.Response getTag(GetTagRequest request) throws ModelDBException { try (Session session = ModelDBHibernateUtil.getSessionFactory().openSession()) { RepositoryEntity repository = getRepositoryById(session, request.getRepositoryId()); Query query = session.createQuery(GET_TAG_HQL); query.setParameter("repositoryId", repository.getId()); query.setParameter("tag", request.getTag()); TagsEntity tagsEntity = (TagsEntity) query.uniqueResult(); if (tagsEntity == null) { throw new ModelDBException("Tag not found " + request.getTag(), Code.NOT_FOUND); } CommitEntity commitEntity = session.get(CommitEntity.class, tagsEntity.getCommit_hash()); return GetTagRequest.Response.newBuilder().setCommit(commitEntity.toCommitProto()).build(); } catch (Exception ex) { if (ModelDBUtils.needToRetry(ex)) { return getTag(request); } else { throw ex; } } }
Example 8
Source File: BigtableServiceImpl.java From beam with Apache License 2.0 | 6 votes |
@Override public boolean tableExists(String tableId) throws IOException { try (BigtableSession session = new BigtableSession(options)) { GetTableRequest getTable = GetTableRequest.newBuilder() .setName(options.getInstanceName().toTableNameStr(tableId)) .build(); session.getTableAdminClient().getTable(getTable); return true; } catch (StatusRuntimeException e) { if (e.getStatus().getCode() == Code.NOT_FOUND) { return false; } String message = String.format( "Error checking whether table %s (BigtableOptions %s) exists", tableId, options); LOG.error(message, e); throw new IOException(message, e); } }
Example 9
Source File: StubWriteOutputStream.java From bazel-buildfarm with Apache License 2.0 | 6 votes |
@Override public QueryWriteStatusResponse get() { if (wasReset) { return resetResponse; } try { QueryWriteStatusResponse response = bsBlockingStub .get() .queryWriteStatus( QueryWriteStatusRequest.newBuilder() .setResourceName(resourceName) .build()); if (response.getComplete()) { writeFuture.set(response.getCommittedSize()); } return response; } catch (StatusRuntimeException e) { Status status = Status.fromThrowable(e); if (status.getCode() == Code.UNIMPLEMENTED || status.getCode() == Code.NOT_FOUND) { return resetResponse; } throw e; } }
Example 10
Source File: GrpcActionCache.java From bazel-buildfarm with Apache License 2.0 | 6 votes |
@Override public ActionResult get(ActionKey actionKey) { try { return actionCacheBlockingStub .get() .getActionResult( GetActionResultRequest.newBuilder() .setInstanceName(instanceName) .setActionDigest(actionKey.getDigest()) .build()); } catch (StatusRuntimeException e) { Status status = Status.fromThrowable(e); if (status.getCode() == Code.NOT_FOUND) { return null; } throw e; } }
Example 11
Source File: KvClient.java From kvstore with Apache License 2.0 | 6 votes |
/** * Updates a random key with a random value. */ private void doUpdate(KeyValueServiceBlockingStub stub) { ByteString key = knownKeys.getRandomKey(); try { UpdateResponse res = stub.update(UpdateRequest.newBuilder() .setKey(key) .setValue(randomBytes(MEAN_VALUE_SIZE)) .build()); if (!res.equals(UpdateResponse.getDefaultInstance())) { throw new RuntimeException("Invalid response"); } } catch (StatusRuntimeException e) { if (e.getStatus().getCode() == Code.NOT_FOUND) { knownKeys.remove(key); logger.log(Level.INFO, "Key not found", e); } else { throw e; } } }
Example 12
Source File: RepositoryDAORdbImpl.java From modeldb with Apache License 2.0 | 5 votes |
@Override public SetTagRequest.Response setTag(SetTagRequest request) throws ModelDBException { try (Session session = ModelDBHibernateUtil.getSessionFactory().openSession()) { RepositoryEntity repository = getRepositoryById(session, request.getRepositoryId(), true); boolean exists = VersioningUtils.commitRepositoryMappingExists( session, request.getCommitSha(), repository.getId()); if (!exists) { throw new ModelDBException( "Commit_hash and repository_id mapping not found for repository " + repository.getId() + " commit " + " request.getCommitSha()", Code.NOT_FOUND); } Query query = session.createQuery(GET_TAG_HQL); query.setParameter("repositoryId", repository.getId()); query.setParameter("tag", request.getTag()); TagsEntity tagsEntity = (TagsEntity) query.uniqueResult(); if (tagsEntity != null) { throw new ModelDBException("Tag '" + request.getTag() + "' already exists", Code.NOT_FOUND); } tagsEntity = new TagsEntity(repository.getId(), request.getCommitSha(), request.getTag()); session.beginTransaction(); session.save(tagsEntity); session.getTransaction().commit(); return SetTagRequest.Response.newBuilder().build(); } catch (Exception ex) { if (ModelDBUtils.needToRetry(ex)) { return setTag(request); } else { throw ex; } } }
Example 13
Source File: ByteStreamService.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
ServerCallStreamObserver<ReadResponse> onErrorLogReadObserver( String name, long offset, ServerCallStreamObserver<ReadResponse> delegate) { return new UniformDelegateServerCallStreamObserver<ReadResponse>(delegate) { long responseCount = 0; long responseBytes = 0; @Override public void onNext(ReadResponse response) { delegate.onNext(response); responseCount++; responseBytes += response.getData().size(); } @Override public void onError(Throwable t) { Status status = Status.fromThrowable(t); if (status.getCode() != Code.NOT_FOUND) { java.util.logging.Level level = Level.SEVERE; if (responseCount > 0 && status.getCode() == Code.DEADLINE_EXCEEDED || status.getCode() == Code.CANCELLED) { level = Level.WARNING; } String message = format("error reading %s at offset %d", name, offset); if (responseCount > 0) { message += format(" after %d responses and %d bytes of content", responseCount, responseBytes); } logger.log(level, message, t); } delegate.onError(t); } @Override public void onCompleted() { delegate.onCompleted(); } }; }
Example 14
Source File: RepositoryDAORdbImpl.java From modeldb with Apache License 2.0 | 5 votes |
@Override public BranchEntity getBranchEntity(Session session, Long repoId, String branchName) throws ModelDBException { Query query = session.createQuery(CHECK_BRANCH_IN_REPOSITORY_HQL); query.setParameter("repositoryId", repoId); query.setParameter("branch", branchName); BranchEntity branchEntity = (BranchEntity) query.uniqueResult(); if (branchEntity == null) { throw new ModelDBException(ModelDBConstants.BRANCH_NOT_FOUND, Code.NOT_FOUND); } return branchEntity; }
Example 15
Source File: RemoteInputStreamFactory.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
private InputStream fetchBlobFromRemoteWorker( Digest blobDigest, Deque<String> workers, long offset, long deadlineAfter, TimeUnit deadlineAfterUnits, RequestMetadata requestMetadata) throws IOException, InterruptedException { String worker = workers.removeFirst(); try { Instance instance = workerStub(worker); InputStream input = instance.newBlobInput( blobDigest, offset, deadlineAfter, deadlineAfterUnits, requestMetadata); // ensure that if the blob cannot be fetched, that we throw here input.available(); if (Thread.interrupted()) { throw new InterruptedException(); } return input; } catch (StatusRuntimeException e) { Status st = Status.fromThrowable(e); if (st.getCode() == Code.UNAVAILABLE || st.getCode() == Code.UNIMPLEMENTED) { // for now, leave this up to schedulers onUnavailable.accept(worker, e, "getBlob(" + DigestUtil.toString(blobDigest) + ")"); } else if (st.getCode() == Code.NOT_FOUND) { // ignore this, the worker will update the backplane eventually } else if (st.getCode() != Code.DEADLINE_EXCEEDED && SHARD_IS_RETRIABLE.test(st)) { // why not, always workers.addLast(worker); } else if (st.getCode() == Code.CANCELLED) { throw new InterruptedException(); } else { throw e; } } throw new NoSuchFileException(DigestUtil.toString(blobDigest)); }
Example 16
Source File: CommitDAORdbImpl.java From modeldb with Apache License 2.0 | 5 votes |
@Override public CommitEntity getCommitEntity( Session session, String commitHash, RepositoryFunction getRepositoryFunction) throws ModelDBException { RepositoryEntity repositoryEntity = getRepositoryFunction.apply(session); boolean exists = VersioningUtils.commitRepositoryMappingExists( session, commitHash, repositoryEntity.getId()); if (!exists) { throw new ModelDBException("Commit_hash and repository_id mapping not found", Code.NOT_FOUND); } return session.load(CommitEntity.class, commitHash); }
Example 17
Source File: EtcdLeaseClient.java From etcd-java with Apache License 2.0 | 4 votes |
private static boolean isNotFound(Throwable t) { return GrpcClient.codeFromThrowable(t) == Code.NOT_FOUND; }