Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update configure index test and clean up control plane client #63

Merged
merged 6 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/integration/java/io/pinecone/helpers/IndexManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ public class IndexManager {
private static PineconeClientConfig config;

public static PineconeConnection createIndexIfNotExistsDataPlane(int dimension, String indexType) throws IOException, InterruptedException {
config = new PineconeClientConfig().withApiKey(System.getenv("PINECONE_API_KEY")).withEnvironment(System.getenv("PINECONE_ENVIRONMENT"));
PineconeIndexOperationClient controlPlaneClient = new PineconeIndexOperationClient(config);
String apiKey = System.getenv("PINECONE_API_KEY");
String environment = System.getenv("PINECONE_ENVIRONMENT");
config = new PineconeClientConfig().withApiKey(apiKey).withEnvironment(environment);
PineconeControlPlaneClient controlPlaneClient = new PineconeControlPlaneClient(apiKey);
IndexList indexList = controlPlaneClient.listIndexes();

String indexName = findIndexWithDimensionAndType(indexList, dimension, controlPlaneClient, indexType);
if (indexName.isEmpty()) indexName = createNewIndex(controlPlaneClient, indexType, dimension);

// Do not proceed until the newly created index is ready
isIndexReady(indexName, controlPlaneClient);
// ToDo: Update the constructor by removing dependency on PineconeClientConfig
PineconeClient dataPlaneClient = new PineconeClient(config);
String host = controlPlaneClient.describeIndex(indexName).getHost();

Expand All @@ -29,22 +32,22 @@ public static PineconeConnection createIndexIfNotExistsDataPlane(int dimension,
.withConnectionUrl("https://" + host));
}

public static String createIndexIfNotExistsControlPlane(PineconeIndexOperationClient controlPlaneClient, int dimension, String indexType) throws IOException, InterruptedException {
public static String createIndexIfNotExistsControlPlane(PineconeControlPlaneClient controlPlaneClient, int dimension, String indexType) throws IOException, InterruptedException {
IndexList indexList = controlPlaneClient.listIndexes();
String indexName = findIndexWithDimensionAndType(indexList, dimension, controlPlaneClient, indexType);

return (indexName.isEmpty()) ? createNewIndex(controlPlaneClient, indexType, dimension) : indexName;
}

private static String findIndexWithDimensionAndType(IndexList indexList, int dimension, PineconeIndexOperationClient controlPlaneClient, String indexType)
private static String findIndexWithDimensionAndType(IndexList indexList, int dimension, PineconeControlPlaneClient controlPlaneClient, String indexType)
throws InterruptedException {
int i = 0;
List<IndexModel> indexModels = indexList.getIndexes();
while (i < indexModels.size()) {
IndexModel indexModel = isIndexReady(indexModels.get(i).getName(), controlPlaneClient);
// ToDo: add pod type support
if (indexModel.getDimension() == dimension
&& ((indexType.equalsIgnoreCase(IndexModelSpec.SERIALIZED_NAME_POD) && indexModel.getSpec().getPod() != null && indexModel.getSpec().getPod().getPodType().equalsIgnoreCase("p1.x1"))
&& ((indexType.equalsIgnoreCase(IndexModelSpec.SERIALIZED_NAME_POD) && indexModel.getSpec().getPod() != null && indexModel.getSpec().getPod().getReplicas() == 1 && indexModel.getSpec().getPod().getPodType().equalsIgnoreCase("p1.x1"))
|| (indexType.equalsIgnoreCase(IndexModelSpec.SERIALIZED_NAME_SERVERLESS)))) {
return indexModel.getName();
}
Expand All @@ -53,7 +56,7 @@ private static String findIndexWithDimensionAndType(IndexList indexList, int dim
return "";
}

private static String createNewIndex(PineconeIndexOperationClient controlPlaneClient, String indexType, int dimension) throws IOException {
private static String createNewIndex(PineconeControlPlaneClient controlPlaneClient, String indexType, int dimension) throws IOException {
String indexName = RandomStringBuilder.build("index-name", 8);
String environment = System.getenv("PINECONE_ENVIRONMENT");
CreateIndexRequestSpec createIndexRequestSpec;
Expand All @@ -76,7 +79,7 @@ private static String createNewIndex(PineconeIndexOperationClient controlPlaneCl
return indexName;
}

public static IndexModel isIndexReady(String indexName, PineconeIndexOperationClient controlPlaneClient)
public static IndexModel isIndexReady(String indexName, PineconeControlPlaneClient controlPlaneClient)
throws InterruptedException {
final IndexModel[] indexModels = new IndexModel[1];
assertWithRetry(() -> {
Expand Down
Loading
Loading