Java Code Examples for io.grpc.StatusRuntimeException#printStackTrace()

The following examples show how to use io.grpc.StatusRuntimeException#printStackTrace() . 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: DBClient.java    From spark-data-sources with MIT License 6 votes vote down vote up
public void createTable(String name, Schema schema) throws ExistingTableException {
    CreateTableRequest.Builder builder = CreateTableRequest.newBuilder();
    builder.setName(name);
    TableSchema.Builder schemaBuilder = TableSchema.newBuilder();
    schema.build(schemaBuilder);
    builder.setSchema(schemaBuilder.build());

    CreateTableRequest request = builder.build();
    CreateTableResponse response;
    try {
        response = _blockingStub.createTable(request);
    } catch (StatusRuntimeException e) {
        e.printStackTrace();
        throw e;
    }

    if (!response.getResult()) {
        throw new ExistingTableException(name);
    }
}
 
Example 2
Source File: DBClient.java    From spark-data-sources with MIT License 6 votes vote down vote up
public void createTable(String name, Schema schema, String clusterColumn)
        throws ExistingTableException {
    CreateTableRequest.Builder builder = CreateTableRequest.newBuilder();
    builder.setName(name);
    TableSchema.Builder schemaBuilder = TableSchema.newBuilder();
    schema.build(schemaBuilder);
    builder.setSchema(schemaBuilder.build());
    builder.setClusterColumn(clusterColumn);

    CreateTableRequest request = builder.build();
    CreateTableResponse response;
    try {
        response = _blockingStub.createTable(request);
    } catch (StatusRuntimeException e) {
        e.printStackTrace();
        throw e;
    }

    if (!response.getResult()) {
        throw new ExistingTableException(name);
    }
}
 
Example 3
Source File: DBClient.java    From spark-data-sources with MIT License 6 votes vote down vote up
public synchronized String createTemporaryTable(Schema schema) {
    CreateTemporaryTableRequest.Builder builder = CreateTemporaryTableRequest.newBuilder();
    TableSchema.Builder schemaBuilder = TableSchema.newBuilder();
    schema.build(schemaBuilder);
    builder.setSchema(schemaBuilder.build());

    CreateTemporaryTableRequest request = builder.build();
    CreateTemporaryTableResponse response;
    try {
        response = _blockingStub.createTemporaryTable(request);
    } catch (StatusRuntimeException e) {
        e.printStackTrace();
        throw e;
    }

    return response.getName();
}
 
Example 4
Source File: DBClient.java    From spark-data-sources with MIT License 6 votes vote down vote up
public Schema getTableSchema(String name) throws UnknownTableException {
    GetTableSchemaRequest.Builder builder = GetTableSchemaRequest.newBuilder();
    builder.setName(name);

    GetTableSchemaRequest request = builder.build();
    GetTableSchemaResponse response;
    try {
        response = _blockingStub.getTableSchema(request);
    } catch (StatusRuntimeException e) {
        e.printStackTrace();
        throw e;
    }

    if (response.getResult()) {
        Schema schema = new Schema(response.getSchema());
        return schema;
    } else {
        throw new UnknownTableException(name);
    }
}
 
Example 5
Source File: DBClient.java    From spark-data-sources with MIT License 6 votes vote down vote up
public void bulkInsert(String name, List<Row> rows) throws UnknownTableException
{
    BulkInsertRequest.Builder builder = BulkInsertRequest.newBuilder();
    builder.setName(name);

    List<DataRow> rpcRows = new ArrayList<>();
    for (Row row : rows) {
        DataRow.Builder rowBuilder = DataRow.newBuilder();
        row.build(rowBuilder);
        rpcRows.add(rowBuilder.build());
    }
    builder.addAllRow(rpcRows);

    BulkInsertRequest request = builder.build();
    BulkInsertResponse response;
    try {
        response = _blockingStub.bulkInsert(request);
    } catch (StatusRuntimeException e) {
        e.printStackTrace();
        throw e;
    }

    if (!response.getResult()) {
        throw new UnknownTableException(name);
    }
}
 
Example 6
Source File: DBClient.java    From spark-data-sources with MIT License 6 votes vote down vote up
public synchronized void bulkInsertFromTables(String destination, boolean truncateDestination,
                                              List<String> sourceTables)
        throws UnknownTableException
{
    BulkInsertFromTablesRequest.Builder builder = BulkInsertFromTablesRequest.newBuilder();
    builder.setDestination(destination);
    builder.setTruncateDestination(truncateDestination);
    builder.addAllSource(sourceTables);

    BulkInsertFromTablesRequest request = builder.build();
    BulkInsertFromTablesResponse response;
    try {
        response = _blockingStub.bulkInsertFromTables(request);
    } catch (StatusRuntimeException e) {
        e.printStackTrace();
        throw e;
    }

    if (response.hasUnknown()) {
        throw new UnknownTableException(response.getUnknown());
    }
}
 
Example 7
Source File: DBClient.java    From spark-data-sources with MIT License 5 votes vote down vote up
public List<Split> getSplits(String table, int count) throws UnknownTableException {
    GetSplitsRequest.Builder builder = GetSplitsRequest.newBuilder();
    builder.setName(table);

    if (count != 0) {
        builder.setCount(count);
    }

    GetSplitsRequest request = builder.build();
    GetSplitsResponse response;
    try {
        response = _blockingStub.getSplits(request);
    } catch (StatusRuntimeException e) {
        e.printStackTrace();
        throw e;
    }

    if (response.getResult()) {
        List<Split> splits = new ArrayList<>();
        List<edb.rpc.Split> rpcSplits = response.getSplitsList();
        for (edb.rpc.Split rpcSplit : rpcSplits) {
            byte[] splitBytes = rpcSplit.getOpaque().toByteArray();
            Split split = Split.deserialize(splitBytes);
            splits.add(split);
        }
        return splits;
    } else {
        throw new UnknownTableException(table);
    }
}
 
Example 8
Source File: CottontailWrapper.java    From cineast with MIT License 5 votes vote down vote up
public synchronized void dropEntityBlocking(Entity entity) {
  final CottonDDLBlockingStub stub = CottonDDLGrpc.newBlockingStub(this.channel);
  try {
    stub.dropEntity(entity);
  } catch (StatusRuntimeException e) {
    if (e.getStatus().getCode() == Status.NOT_FOUND.getCode()) {
      LOGGER.debug("entity {} was not dropped because it does not exist", entity.getName());
    } else {
      e.printStackTrace();
    }
  }
}
 
Example 9
Source File: CottontailWrapper.java    From cineast with MIT License 5 votes vote down vote up
public synchronized void createIndexBlocking(CreateIndexMessage createMessage) {
  final CottonDDLBlockingStub stub = CottonDDLGrpc.newBlockingStub(this.channel);
  try {
    stub.createIndex(createMessage);
  } catch (StatusRuntimeException e) {
    if (e.getStatus().getCode() == Status.ALREADY_EXISTS.getCode()) {
      LOGGER.warn("Index on {}.{} was not created because it already exists", createMessage.getIndex().getEntity().getName(), createMessage.getColumnsList().toString());
      return;
    }
    e.printStackTrace();
  }
}
 
Example 10
Source File: TestTool.java    From startup-os with Apache License 2.0 5 votes vote down vote up
public DiffFilesResponse getDiffFiles(String workspace, long diffNumber) {
  DiffFilesRequest request =
      DiffFilesRequest.newBuilder().setWorkspace(workspace).setDiffId(diffNumber).build();
  try {
    return blockingStub.getDiffFiles(request);
  } catch (StatusRuntimeException e) {
    e.printStackTrace();
    return null;
  }
}
 
Example 11
Source File: TestTool.java    From startup-os with Apache License 2.0 5 votes vote down vote up
private TextDiffResponse getTextDiff(File leftFile, File rightFile) {
  final TextDiffRequest request =
      TextDiffRequest.newBuilder().setLeftFile(leftFile).setRightFile(rightFile).build();
  try {
    return blockingStub.getTextDiff(request);
  } catch (StatusRuntimeException e) {
    e.printStackTrace();
    return null;
  }
}
 
Example 12
Source File: TestTool.java    From startup-os with Apache License 2.0 5 votes vote down vote up
private void createDiff(Diff diff) {
  final CreateDiffRequest request = CreateDiffRequest.newBuilder().setDiff(diff).build();
  try {
    blockingStub.createDiff(request);
  } catch (StatusRuntimeException e) {
    e.printStackTrace();
  }
}
 
Example 13
Source File: TestTool.java    From startup-os with Apache License 2.0 5 votes vote down vote up
private String getFile(String name) {
  final FileRequest request = FileRequest.newBuilder().setFilename(name).build();
  try {
    return blockingStub.getFile(request).getContent();
  } catch (StatusRuntimeException e) {
    e.printStackTrace();
    return null;
  }
}
 
Example 14
Source File: LocalHttpGatewayGrpcClient.java    From startup-os with Apache License 2.0 5 votes vote down vote up
public void postAuthData(String projectId, String apiKey, String jwtToken, String refreshToken) {
  final AuthDataRequest request =
      AuthDataRequest.newBuilder()
          .setProjectId(projectId)
          .setApiKey(apiKey)
          .setJwtToken(jwtToken)
          .setRefreshToken(refreshToken)
          .build();
  try {
    authBlockingStub.postAuthData(request);
  } catch (StatusRuntimeException e) {
    e.printStackTrace();
  }
}
 
Example 15
Source File: LocalHttpGatewayGrpcClient.java    From startup-os with Apache License 2.0 5 votes vote down vote up
public String getFile(String name) {
  final FileRequest request = FileRequest.newBuilder().setFilename(name).build();
  try {
    return codeReviewBlockingStub.getFile(request).getContent();
  } catch (StatusRuntimeException e) {
    e.printStackTrace();
    return null;
  }
}
 
Example 16
Source File: DBClient.java    From spark-data-sources with MIT License 5 votes vote down vote up
public String ping(String id) {
    PingRequest.Builder builder = PingRequest.newBuilder();
    builder.setId(id);

    PingRequest request = builder.build();
    PingResponse response;
    try {
        response = _blockingStub.ping(request);
    } catch (StatusRuntimeException e) {
        e.printStackTrace();
        return null;
    }

    return response.getId();
}
 
Example 17
Source File: DBClient.java    From spark-data-sources with MIT License 5 votes vote down vote up
public List<Row> getAllRows(String name, Split split, List<String> columns) throws UnknownTableException {
    GetAllRowsRequest.Builder builder = GetAllRowsRequest.newBuilder();
    builder.setName(name);

    if (split != null) {
        edb.rpc.Split.Builder splitBuilder = edb.rpc.Split.newBuilder();
        splitBuilder.setOpaque(ByteString.copyFrom(split.serialize()));
        builder.setSplit(splitBuilder.build());
    }

    if (columns != null) {
        builder.addAllColumns(columns);
    }

    GetAllRowsRequest request = builder.build();
    GetAllRowsResponse response;
    try {
        response = _blockingStub.getAllRows(request);
    } catch (StatusRuntimeException e) {
        e.printStackTrace();
        throw e;
    }

    if (response.getResult()) {
        List<Row> rows = new ArrayList<>();
        List<DataRow> rpcRows = response.getRowList();
        for (DataRow rpcRow : rpcRows) {
            rows.add(new Row(rpcRow));
        }
        return rows;
    } else {
        throw new UnknownTableException(name);
    }
}
 
Example 18
Source File: DBClient.java    From spark-data-sources with MIT License 5 votes vote down vote up
public List<String> listTables() {
    ListTablesRequest.Builder builder = ListTablesRequest.newBuilder();

    ListTablesRequest request = builder.build();
    ListTablesResponse response;
    try {
        response = _blockingStub.listTables(request);
    } catch (StatusRuntimeException e) {
        e.printStackTrace();
        return null;
    }

    return response.getTableNamesList();
}
 
Example 19
Source File: CommitTest.java    From modeldb with Apache License 2.0 4 votes vote down vote up
@Test
public void deleteCommitHasHeadOfTwoBranchesTest()
    throws ModelDBException, NoSuchAlgorithmException {
  LOGGER.info("branch test start................................");

  VersioningServiceBlockingStub versioningServiceBlockingStub =
      VersioningServiceGrpc.newBlockingStub(channel);

  long id = createRepository(versioningServiceBlockingStub, NAME);
  GetBranchRequest getBranchRequest =
      GetBranchRequest.newBuilder()
          .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build())
          .setBranch(ModelDBConstants.MASTER_BRANCH)
          .build();
  GetBranchRequest.Response getBranchResponse =
      versioningServiceBlockingStub.getBranch(getBranchRequest);

  CreateCommitRequest createCommitRequest =
      getCreateCommitRequest(id, 111, getBranchResponse.getCommit(), Blob.ContentCase.DATASET);

  CreateCommitRequest.Response commitResponse =
      versioningServiceBlockingStub.createCommit(createCommitRequest);
  Commit commit1 = commitResponse.getCommit();

  createCommitRequest =
      getCreateCommitRequest(id, 111, getBranchResponse.getCommit(), Blob.ContentCase.DATASET);

  commitResponse = versioningServiceBlockingStub.createCommit(createCommitRequest);
  Commit commit2 = commitResponse.getCommit();

  List<Commit> commitShaList = new LinkedList<>();
  commitShaList.add(commit2);
  commitShaList.add(commit1);

  String branchName1 = "branch-commits-label-1";
  SetBranchRequest setBranchRequest =
      SetBranchRequest.newBuilder()
          .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build())
          .setBranch(branchName1)
          .setCommitSha(commit1.getCommitSha())
          .build();
  versioningServiceBlockingStub.setBranch(setBranchRequest);

  String branchName2 = "branch-commits-label-2";
  setBranchRequest =
      SetBranchRequest.newBuilder()
          .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build())
          .setBranch(branchName2)
          .setCommitSha(commit1.getCommitSha())
          .build();
  versioningServiceBlockingStub.setBranch(setBranchRequest);

  DeleteCommitRequest deleteCommitRequest =
      DeleteCommitRequest.newBuilder()
          .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build())
          .setCommitSha(commit1.getCommitSha())
          .build();
  try {
    versioningServiceBlockingStub.deleteCommit(deleteCommitRequest);
    fail();
  } catch (StatusRuntimeException e) {
    Assert.assertEquals(Code.FAILED_PRECONDITION, e.getStatus().getCode());
    e.printStackTrace();
  }

  DeleteRepositoryRequest deleteRepository =
      DeleteRepositoryRequest.newBuilder()
          .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id))
          .build();
  DeleteRepositoryRequest.Response deleteResult =
      versioningServiceBlockingStub.deleteRepository(deleteRepository);
  Assert.assertTrue(deleteResult.getStatus());

  LOGGER.info("Branch test end................................");
}
 
Example 20
Source File: CommitTest.java    From modeldb with Apache License 2.0 4 votes vote down vote up
@Test
public void getCommitComponentTest() {
  LOGGER.info("Get commit component test start................................");

  VersioningServiceBlockingStub versioningServiceBlockingStub =
      VersioningServiceGrpc.newBlockingStub(channel);

  long id = createRepository(versioningServiceBlockingStub, RepositoryTest.NAME);

  GetBranchRequest getBranchRequest =
      GetBranchRequest.newBuilder()
          .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build())
          .setBranch(ModelDBConstants.MASTER_BRANCH)
          .build();
  GetBranchRequest.Response getBranchResponse =
      versioningServiceBlockingStub.getBranch(getBranchRequest);

  String path = "/protos/proto/public/versioning/versioning.proto";
  List<String> location = new ArrayList<>();
  location.add("modeldb");
  location.add("environment");
  location.add("train");
  Blob blob = getDatasetBlobFromPath(path);

  Commit.Builder commitBuilder =
      Commit.newBuilder()
          .setMessage("this is the test commit message")
          .setDateCreated(Calendar.getInstance().getTimeInMillis())
          .addParentShas(getBranchResponse.getCommit().getCommitSha());
  if (app.getAuthServerHost() != null && app.getAuthServerPort() != null) {
    commitBuilder.setAuthor(authClientInterceptor.getClient1Email());
  }

  CreateCommitRequest createCommitRequest =
      CreateCommitRequest.newBuilder()
          .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build())
          .setCommit(commitBuilder.build())
          .addBlobs(BlobExpanded.newBuilder().setBlob(blob).addAllLocation(location).build())
          .build();

  CreateCommitRequest.Response commitResponse =
      versioningServiceBlockingStub.createCommit(createCommitRequest);

  GetCommitComponentRequest getCommitBlobRequest =
      GetCommitComponentRequest.newBuilder()
          .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build())
          .setCommitSha(commitResponse.getCommit().getCommitSha())
          .addAllLocation(location)
          .build();
  GetCommitComponentRequest.Response getCommitBlobResponse =
      versioningServiceBlockingStub.getCommitComponent(getCommitBlobRequest);
  assertEquals(
      "Blob path not match with expected blob path",
      path,
      getCommitBlobResponse.getBlob().getDataset().getPath().getComponents(0).getPath());

  location.add("xyz");
  getCommitBlobRequest =
      GetCommitComponentRequest.newBuilder()
          .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build())
          .setCommitSha(commitResponse.getCommit().getCommitSha())
          .addAllLocation(location)
          .build();
  try {
    versioningServiceBlockingStub.getCommitComponent(getCommitBlobRequest);
    Assert.fail();
  } catch (StatusRuntimeException e) {
    Assert.assertEquals(Code.NOT_FOUND, e.getStatus().getCode());
    e.printStackTrace();
  }

  DeleteCommitRequest deleteCommitRequest =
      DeleteCommitRequest.newBuilder()
          .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build())
          .setCommitSha(commitResponse.getCommit().getCommitSha())
          .build();
  versioningServiceBlockingStub.deleteCommit(deleteCommitRequest);

  DeleteRepositoryRequest deleteRepository =
      DeleteRepositoryRequest.newBuilder()
          .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id))
          .build();
  DeleteRepositoryRequest.Response deleteResult =
      versioningServiceBlockingStub.deleteRepository(deleteRepository);
  Assert.assertTrue(deleteResult.getStatus());

  LOGGER.info("Get commit blob test end................................");
}