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

The following examples show how to use io.grpc.StatusRuntimeException#toString() . 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: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 6 votes vote down vote up
@Override
public Response flush(List<String> collectionNames) {
  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new Response(Response.Status.CLIENT_NOT_CONNECTED);
  }

  FlushParam request = FlushParam.newBuilder().addAllCollectionNameArray(collectionNames).build();
  Status response;

  try {
    response = blockingStub.flush(request);

    if (response.getErrorCode() == ErrorCode.SUCCESS) {
      logInfo("Flushed collection {} successfully!", collectionNames);
      return new Response(Response.Status.SUCCESS);
    } else {
      logError("Flush collection {} failed:\n{}", collectionNames, response.toString());
      return new Response(
          Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
    }
  } catch (StatusRuntimeException e) {
    logError("flush RPC failed:\n{}", e.getStatus().toString());
    return new Response(Response.Status.RPC_ERROR, e.toString());
  }
}
 
Example 2
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 6 votes vote down vote up
@Override
public Response compact(String collectionName) {
  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new Response(Response.Status.CLIENT_NOT_CONNECTED);
  }

  CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
  Status response;

  try {
    response = blockingStub.compact(request);

    if (response.getErrorCode() == ErrorCode.SUCCESS) {
      logInfo("Compacted collection `{}` successfully!", collectionName);
      return new Response(Response.Status.SUCCESS);
    } else {
      logError("Compact collection `{}` failed:\n{}", collectionName, response.toString());
      return new Response(
          Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
    }
  } catch (StatusRuntimeException e) {
    logError("compact RPC failed:\n{}", e.getStatus().toString());
    return new Response(Response.Status.RPC_ERROR, e.toString());
  }
}
 
Example 3
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public ListCollectionsResponse listCollections() {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new ListCollectionsResponse(
        new Response(Response.Status.CLIENT_NOT_CONNECTED), new ArrayList<>());
  }

  Command request = Command.newBuilder().setCmd("").build();
  CollectionNameList response;

  try {
    response = blockingStub.showCollections(request);

    if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
      List<String> collectionNames = response.getCollectionNamesList();
      logInfo("Current collections: {}", collectionNames.toString());
      return new ListCollectionsResponse(new Response(Response.Status.SUCCESS), collectionNames);
    } else {
      logError("List collections failed:\n{}", response.getStatus().toString());
      return new ListCollectionsResponse(
          new Response(
              Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
              response.getStatus().getReason()),
          new ArrayList<>());
    }
  } catch (StatusRuntimeException e) {
    logError("listCollections RPC failed:\n{}", e.getStatus().toString());
    return new ListCollectionsResponse(
        new Response(Response.Status.RPC_ERROR, e.toString()), new ArrayList<>());
  }
}
 
Example 4
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Response deleteEntityByID(String collectionName, List<Long> ids) {
  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new Response(Response.Status.CLIENT_NOT_CONNECTED);
  }

  DeleteByIDParam request =
      DeleteByIDParam.newBuilder().setCollectionName(collectionName).addAllIdArray(ids).build();
  Status response;

  try {
    response = blockingStub.deleteByID(request);

    if (response.getErrorCode() == ErrorCode.SUCCESS) {
      logInfo("deleteEntityByID in collection `{}` completed successfully!", collectionName);
      return new Response(Response.Status.SUCCESS);
    } else {
      logError(
          "deleteEntityByID in collection `{}` failed:\n{}", collectionName, response.toString());
      return new Response(
          Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
    }
  } catch (StatusRuntimeException e) {
    logError("deleteEntityByID RPC failed:\n{}", e.getStatus().toString());
    return new Response(Response.Status.RPC_ERROR, e.toString());
  }
}
 
Example 5
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Response getCollectionStats(String collectionName) {
  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new Response(Response.Status.CLIENT_NOT_CONNECTED);
  }

  CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
  io.milvus.grpc.CollectionInfo response;

  try {
    response = blockingStub.showCollectionInfo(request);

    if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
      logInfo("getCollectionStats for `{}` returned successfully!", collectionName);
      return new Response(Response.Status.SUCCESS, response.getJsonInfo());
    } else {
      logError(
          "getCollectionStats for `{}` failed:\n{}",
          collectionName,
          response.getStatus().toString());
      return new Response(
          Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
          response.getStatus().getReason());
    }
  } catch (StatusRuntimeException e) {
    logError("getCollectionStats RPC failed:\n{}", e.getStatus().toString());
    return new Response(Response.Status.RPC_ERROR, e.toString());
  }
}
 
Example 6
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Response dropIndex(@Nonnull String collectionName) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new Response(Response.Status.CLIENT_NOT_CONNECTED);
  }

  CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
  Status response;

  try {
    response = blockingStub.dropIndex(request);

    if (response.getErrorCode() == ErrorCode.SUCCESS) {
      logInfo("Dropped index for collection `{}` successfully!", collectionName);
      return new Response(Response.Status.SUCCESS);
    } else {
      logError("Drop index for collection `{}` failed:\n{}", collectionName, response.toString());
      return new Response(
          Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
    }
  } catch (StatusRuntimeException e) {
    logError("dropIndex RPC failed:\n{}", e.getStatus().toString());
    return new Response(Response.Status.RPC_ERROR, e.toString());
  }
}
 
Example 7
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Response loadCollection(@Nonnull String collectionName) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new Response(Response.Status.CLIENT_NOT_CONNECTED);
  }

  CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
  Status response;

  try {
    response = blockingStub.preloadCollection(request);

    if (response.getErrorCode() == ErrorCode.SUCCESS) {
      logInfo("Loaded collection `{}` successfully!", collectionName);
      return new Response(Response.Status.SUCCESS);
    } else {
      logError("Load collection `{}` failed:\n{}", collectionName, response.toString());
      return new Response(
          Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
    }
  } catch (StatusRuntimeException e) {
    logError("loadCollection RPC failed:\n{}", e.getStatus().toString());
    return new Response(Response.Status.RPC_ERROR, e.toString());
  }
}
 
Example 8
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public CountEntitiesResponse countEntities(@Nonnull String collectionName) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new CountEntitiesResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), 0);
  }

  CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
  CollectionRowCount response;

  try {
    response = blockingStub.countCollection(request);

    if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
      long collectionRowCount = response.getCollectionRowCount();
      logInfo("Collection `{}` has {} entities", collectionName, collectionRowCount);
      return new CountEntitiesResponse(new Response(Response.Status.SUCCESS), collectionRowCount);
    } else {
      logError(
          "Get collection `{}` entity count failed:\n{}",
          collectionName,
          response.getStatus().toString());
      return new CountEntitiesResponse(
          new Response(
              Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
              response.getStatus().getReason()),
          0);
    }
  } catch (StatusRuntimeException e) {
    logError("countEntities RPC failed:\n{}", e.getStatus().toString());
    return new CountEntitiesResponse(new Response(Response.Status.RPC_ERROR, e.toString()), 0);
  }
}
 
Example 9
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Response createCollection(@Nonnull CollectionMapping collectionMapping) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new Response(Response.Status.CLIENT_NOT_CONNECTED);
  }

  CollectionSchema request =
      CollectionSchema.newBuilder()
          .setCollectionName(collectionMapping.getCollectionName())
          .setDimension(collectionMapping.getDimension())
          .setIndexFileSize(collectionMapping.getIndexFileSize())
          .setMetricType(collectionMapping.getMetricType().getVal())
          .build();

  Status response;

  try {
    response = blockingStub.createCollection(request);

    if (response.getErrorCode() == ErrorCode.SUCCESS) {
      logInfo("Created collection successfully!\n{}", collectionMapping.toString());
      return new Response(Response.Status.SUCCESS);
    } else if (response.getReason().contentEquals("Collection already exists")) {
      logWarning("Collection `{}` already exists", collectionMapping.getCollectionName());
      return new Response(
          Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
    } else {
      logError(
          "Create collection failed\n{}\n{}", collectionMapping.toString(), response.toString());
      return new Response(
          Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
    }
  } catch (StatusRuntimeException e) {
    logError("createCollection RPC failed:\n{}", e.getStatus().toString());
    return new Response(Response.Status.RPC_ERROR, e.toString());
  }
}
 
Example 10
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Response dropPartition(String collectionName, String tag) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new Response(Response.Status.CLIENT_NOT_CONNECTED);
  }

  PartitionParam request =
      PartitionParam.newBuilder().setCollectionName(collectionName).setTag(tag).build();
  Status response;

  try {
    response = blockingStub.dropPartition(request);

    if (response.getErrorCode() == ErrorCode.SUCCESS) {
      logInfo("Dropped partition `{}` in collection `{}` successfully!", tag, collectionName);
      return new Response(Response.Status.SUCCESS);
    } else {
      logError(
          "Drop partition `{}` in collection `{}` failed:\n{}",
          tag,
          collectionName,
          response.toString());
      return new Response(
          Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
    }
  } catch (StatusRuntimeException e) {
    logError("dropPartition RPC failed:\n{}", e.getStatus().toString());
    return new Response(Response.Status.RPC_ERROR, e.toString());
  }
}
 
Example 11
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public ListPartitionsResponse listPartitions(String collectionName) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new ListPartitionsResponse(
        new Response(Response.Status.CLIENT_NOT_CONNECTED), new ArrayList<>());
  }

  CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
  PartitionList response;

  try {
    response = blockingStub.showPartitions(request);

    if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
      logInfo(
          "Current partitions of collection {}: {}",
          collectionName,
          response.getPartitionTagArrayList());
      return new ListPartitionsResponse(
          new Response(Response.Status.SUCCESS), response.getPartitionTagArrayList());
    } else {
      logError("List partitions failed:\n{}", response.toString());
      return new ListPartitionsResponse(
          new Response(
              Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
              response.getStatus().getReason()),
          new ArrayList<>());
    }
  } catch (StatusRuntimeException e) {
    logError("listPartitions RPC failed:\n{}", e.getStatus().toString());
    return new ListPartitionsResponse(
        new Response(Response.Status.RPC_ERROR, e.toString()), new ArrayList<>());
  }
}
 
Example 12
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public HasPartitionResponse hasPartition(String collectionName, String tag) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new HasPartitionResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), false);
  }

  PartitionParam request =
      PartitionParam.newBuilder().setCollectionName(collectionName).setTag(tag).build();
  BoolReply response;

  try {
    response = blockingStub.hasPartition(request);

    if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
      logInfo(
          "hasPartition with tag `{}` in `{}` = {}",
          tag,
          collectionName,
          response.getBoolReply());
      return new HasPartitionResponse(
          new Response(Response.Status.SUCCESS), response.getBoolReply());
    } else {
      logError(
          "hasPartition with tag `{}` in `{}` failed:\n{}",
          tag,
          collectionName,
          response.toString());
      return new HasPartitionResponse(
          new Response(
              Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
              response.getStatus().getReason()),
          false);
    }
  } catch (StatusRuntimeException e) {
    logError("hasPartition RPC failed:\n{}", e.getStatus().toString());
    return new HasPartitionResponse(new Response(Response.Status.RPC_ERROR, e.toString()), false);
  }
}
 
Example 13
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Response createPartition(String collectionName, String tag) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new Response(Response.Status.CLIENT_NOT_CONNECTED);
  }

  PartitionParam request =
      PartitionParam.newBuilder().setCollectionName(collectionName).setTag(tag).build();

  Status response;

  try {
    response = blockingStub.createPartition(request);

    if (response.getErrorCode() == ErrorCode.SUCCESS) {
      logInfo("Created partition `{}` in collection `{}` successfully!", tag, collectionName);
      return new Response(Response.Status.SUCCESS);
    } else {
      logError(
          "Create partition `{}` in collection `{}` failed: {}",
          tag,
          collectionName,
          response.toString());
      return new Response(
          Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
    }
  } catch (StatusRuntimeException e) {
    logError("createPartition RPC failed:\n{}", e.getStatus().toString());
    return new Response(Response.Status.RPC_ERROR, e.toString());
  }
}
 
Example 14
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Response createIndex(@Nonnull Index index) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new Response(Response.Status.CLIENT_NOT_CONNECTED);
  }

  KeyValuePair extraParam =
      KeyValuePair.newBuilder().setKey(extraParamKey).setValue(index.getParamsInJson()).build();
  IndexParam request =
      IndexParam.newBuilder()
          .setCollectionName(index.getCollectionName())
          .setIndexType(index.getIndexType().getVal())
          .addExtraParams(extraParam)
          .build();

  Status response;

  try {
    response = blockingStub.createIndex(request);

    if (response.getErrorCode() == ErrorCode.SUCCESS) {
      logInfo("Created index successfully!\n{}", index.toString());
      return new Response(Response.Status.SUCCESS);
    } else {
      logError("Create index failed:\n{}\n{}", index.toString(), response.toString());
      return new Response(
          Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
    }
  } catch (StatusRuntimeException e) {
    logError("createIndex RPC failed:\n{}", e.getStatus().toString());
    return new Response(Response.Status.RPC_ERROR, e.toString());
  }
}
 
Example 15
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public HasCollectionResponse hasCollection(@Nonnull String collectionName) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new HasCollectionResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), false);
  }

  CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
  BoolReply response;

  try {
    response = blockingStub.hasCollection(request);

    if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
      logInfo("hasCollection `{}` = {}", collectionName, response.getBoolReply());
      return new HasCollectionResponse(
          new Response(Response.Status.SUCCESS), response.getBoolReply());
    } else {
      logError("hasCollection `{}` failed:\n{}", collectionName, response.toString());
      return new HasCollectionResponse(
          new Response(
              Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
              response.getStatus().getReason()),
          false);
    }
  } catch (StatusRuntimeException e) {
    logError("hasCollection RPC failed:\n{}", e.getStatus().toString());
    return new HasCollectionResponse(
        new Response(Response.Status.RPC_ERROR, e.toString()), false);
  }
}
 
Example 16
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public GetCollectionInfoResponse getCollectionInfo(@Nonnull String collectionName) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new GetCollectionInfoResponse(
        new Response(Response.Status.CLIENT_NOT_CONNECTED), null);
  }

  CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
  CollectionSchema response;

  try {
    response = blockingStub.describeCollection(request);

    if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
      CollectionMapping collectionMapping =
          new CollectionMapping.Builder(response.getCollectionName(), response.getDimension())
              .withIndexFileSize(response.getIndexFileSize())
              .withMetricType(MetricType.valueOf(response.getMetricType()))
              .build();
      logInfo("Get Collection Info `{}` returned:\n{}", collectionName, collectionMapping);
      return new GetCollectionInfoResponse(
          new Response(Response.Status.SUCCESS), collectionMapping);
    } else {
      logError(
          "Get Collection Info `{}` failed:\n{}",
          collectionName,
          response.getStatus().toString());
      return new GetCollectionInfoResponse(
          new Response(
              Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
              response.getStatus().getReason()),
          null);
    }
  } catch (StatusRuntimeException e) {
    logError("getCollectionInfo RPC failed:\n{}", e.getStatus().toString());
    return new GetCollectionInfoResponse(
        new Response(Response.Status.RPC_ERROR, e.toString()), null);
  }
}
 
Example 17
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public InsertResponse insert(@Nonnull InsertParam insertParam) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new InsertResponse(
        new Response(Response.Status.CLIENT_NOT_CONNECTED), new ArrayList<>());
  }

  List<RowRecord> rowRecordList =
      buildRowRecordList(insertParam.getFloatVectors(), insertParam.getBinaryVectors());

  io.milvus.grpc.InsertParam request =
      io.milvus.grpc.InsertParam.newBuilder()
          .setCollectionName(insertParam.getCollectionName())
          .addAllRowRecordArray(rowRecordList)
          .addAllRowIdArray(insertParam.getVectorIds())
          .setPartitionTag(insertParam.getPartitionTag())
          .build();
  VectorIds response;

  try {
    response = blockingStub.insert(request);

    if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
      logInfo(
          "Inserted {} vectors to collection `{}` successfully!",
          response.getVectorIdArrayCount(),
          insertParam.getCollectionName());
      return new InsertResponse(
          new Response(Response.Status.SUCCESS), response.getVectorIdArrayList());
    } else {
      logError("Insert vectors failed:\n{}", response.getStatus().toString());
      return new InsertResponse(
          new Response(
              Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
              response.getStatus().getReason()),
          new ArrayList<>());
    }
  } catch (StatusRuntimeException e) {
    logError("insert RPC failed:\n{}", e.getStatus().toString());
    return new InsertResponse(
        new Response(Response.Status.RPC_ERROR, e.toString()), new ArrayList<>());
  }
}
 
Example 18
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public GetIndexInfoResponse getIndexInfo(@Nonnull String collectionName) {

  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new GetIndexInfoResponse(new Response(Response.Status.CLIENT_NOT_CONNECTED), null);
  }

  CollectionName request = CollectionName.newBuilder().setCollectionName(collectionName).build();
  IndexParam response;

  try {
    response = blockingStub.describeIndex(request);

    if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
      String extraParam = "";
      for (KeyValuePair kv : response.getExtraParamsList()) {
        if (kv.getKey().contentEquals(extraParamKey)) {
          extraParam = kv.getValue();
        }
      }
      Index index =
          new Index.Builder(
                  response.getCollectionName(), IndexType.valueOf(response.getIndexType()))
              .withParamsInJson(extraParam)
              .build();
      logInfo(
          "Get index info for collection `{}` returned:\n{}", collectionName, index.toString());
      return new GetIndexInfoResponse(new Response(Response.Status.SUCCESS), index);
    } else {
      logError(
          "Get index info for collection `{}` failed:\n{}",
          collectionName,
          response.getStatus().toString());
      return new GetIndexInfoResponse(
          new Response(
              Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
              response.getStatus().getReason()),
          null);
    }
  } catch (StatusRuntimeException e) {
    logError("getIndexInfo RPC failed:\n{}", e.getStatus().toString());
    return new GetIndexInfoResponse(new Response(Response.Status.RPC_ERROR, e.toString()), null);
  }
}
 
Example 19
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public GetEntityByIDResponse getEntityByID(String collectionName, List<Long> ids) {
  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new GetEntityByIDResponse(
        new Response(Response.Status.CLIENT_NOT_CONNECTED), new ArrayList<>(), null);
  }

  VectorsIdentity request =
      VectorsIdentity.newBuilder().setCollectionName(collectionName).addAllIdArray(ids).build();
  VectorsData response;

  try {
    response = blockingStub.getVectorsByID(request);

    if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {

      logInfo("getEntityByID in collection `{}` returned successfully!", collectionName);

      List<List<Float>> floatVectors = new ArrayList<>();
      List<ByteBuffer> binaryVectors = new ArrayList<>();
      for (int i = 0; i < ids.size(); i++) {
        floatVectors.add(response.getVectorsData(i).getFloatDataList());
        binaryVectors.add(response.getVectorsData(i).getBinaryData().asReadOnlyByteBuffer());
      }
      return new GetEntityByIDResponse(
          new Response(Response.Status.SUCCESS), floatVectors, binaryVectors);

    } else {
      logError(
          "getEntityByID in collection `{}` failed:\n{}",
          collectionName,
          response.getStatus().toString());
      return new GetEntityByIDResponse(
          new Response(
              Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
              response.getStatus().getReason()),
          new ArrayList<>(),
          null);
    }
  } catch (StatusRuntimeException e) {
    logError("getEntityByID RPC failed:\n{}", e.getStatus().toString());
    return new GetEntityByIDResponse(
        new Response(Response.Status.RPC_ERROR, e.toString()), new ArrayList<>(), null);
  }
}
 
Example 20
Source File: MilvusGrpcClient.java    From milvus-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public ListIDInSegmentResponse listIDInSegment(String collectionName, String segmentName) {
  if (!channelIsReadyOrIdle()) {
    logWarning("You are not connected to Milvus server");
    return new ListIDInSegmentResponse(
        new Response(Response.Status.CLIENT_NOT_CONNECTED), new ArrayList<>());
  }

  GetVectorIDsParam request =
      GetVectorIDsParam.newBuilder()
          .setCollectionName(collectionName)
          .setSegmentName(segmentName)
          .build();
  VectorIds response;

  try {
    response = blockingStub.getVectorIDs(request);

    if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {

      logInfo(
          "listIDInSegment in collection `{}`, segment `{}` returned successfully!",
          collectionName,
          segmentName);
      return new ListIDInSegmentResponse(
          new Response(Response.Status.SUCCESS), response.getVectorIdArrayList());
    } else {
      logError(
          "listIDInSegment in collection `{}`, segment `{}` failed:\n{}",
          collectionName,
          segmentName,
          response.getStatus().toString());
      return new ListIDInSegmentResponse(
          new Response(
              Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
              response.getStatus().getReason()),
          new ArrayList<>());
    }
  } catch (StatusRuntimeException e) {
    logError("listIDInSegment RPC failed:\n{}", e.getStatus().toString());
    return new ListIDInSegmentResponse(
        new Response(Response.Status.RPC_ERROR, e.toString()), new ArrayList<>());
  }
}